Commit 1bec5152 authored by Alexander Viro's avatar Alexander Viro Committed by James Bottomley

[PATCH] randomness made per-disk

	* per-major array eliminated, every disk is a separate source of
randomness
parent 288ed82d
......@@ -3014,7 +3014,7 @@ static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
complete(Command->Completion);
Command->Completion = NULL;
}
add_blkdev_randomness(DAC960_MAJOR + Controller->ControllerNumber);
add_disk_randomness(Controller->disks[Command->LogicalDriveNumber]);
}
else if ((CommandStatus == DAC960_V1_IrrecoverableDataError ||
CommandStatus == DAC960_V1_BadDataEncountered) &&
......@@ -4120,7 +4120,7 @@ static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
complete(Command->Completion);
Command->Completion = NULL;
}
add_blkdev_randomness(DAC960_MAJOR + Controller->ControllerNumber);
add_disk_randomness(Controller->disks[Command->LogicalDriveNumber]);
}
else if (Command->V2.RequestSense.SenseKey
== DAC960_SenseKey_MediumError &&
......
......@@ -2297,7 +2297,7 @@ static inline void end_request(struct request *req, int uptodate)
{
if (end_that_request_first(req, uptodate, current_count_sectors))
return;
add_blkdev_randomness(MAJOR_NR);
add_disk_randomness(req->rq_disk);
floppy_off((int)req->rq_disk->private_data);
blkdev_dequeue_request(req);
end_that_request_last(req);
......
......@@ -289,6 +289,7 @@ EXPORT_SYMBOL(disk_devclass);
static void disk_release(struct device *dev)
{
struct gendisk *disk = dev->driver_data;
kfree(disk->random);
kfree(disk->part);
kfree(disk);
}
......@@ -316,6 +317,7 @@ struct gendisk *alloc_disk(int minors)
disk->disk_dev.driver_data = disk;
device_initialize(&disk->disk_dev);
}
rand_initialize_disk(disk);
return disk;
}
......
......@@ -253,6 +253,7 @@
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/workqueue.h>
#include <linux/genhd.h>
#include <asm/processor.h>
#include <asm/uaccess.h>
......@@ -718,7 +719,6 @@ static struct timer_rand_state keyboard_timer_state;
static struct timer_rand_state mouse_timer_state;
static struct timer_rand_state extract_timer_state;
static struct timer_rand_state *irq_timer_state[NR_IRQS];
static struct timer_rand_state *blkdev_timer_state[MAX_BLKDEV];
/*
* This function adds entropy to the entropy "pool" by using timing
......@@ -812,18 +812,12 @@ void add_interrupt_randomness(int irq)
add_timer_randomness(irq_timer_state[irq], 0x100+irq);
}
void add_blkdev_randomness(int major)
void add_disk_randomness(struct gendisk *disk)
{
if (major >= MAX_BLKDEV)
if (!disk || !disk->random)
return;
if (blkdev_timer_state[major] == 0) {
rand_initialize_blkdev(major, GFP_ATOMIC);
if (blkdev_timer_state[major] == 0)
return;
}
add_timer_randomness(blkdev_timer_state[major], 0x200+major);
/* first major is 1, so we get >= 0x200 here */
add_timer_randomness(disk->random, 0x100+MKDEV(disk->major, disk->first_minor));
}
/******************************************************************
......@@ -1447,8 +1441,6 @@ void __init rand_initialize(void)
#endif
for (i = 0; i < NR_IRQS; i++)
irq_timer_state[i] = NULL;
for (i = 0; i < MAX_BLKDEV; i++)
blkdev_timer_state[i] = NULL;
memset(&keyboard_timer_state, 0, sizeof(struct timer_rand_state));
memset(&mouse_timer_state, 0, sizeof(struct timer_rand_state));
memset(&extract_timer_state, 0, sizeof(struct timer_rand_state));
......@@ -1472,26 +1464,22 @@ void rand_initialize_irq(int irq)
irq_timer_state[irq] = state;
}
}
void rand_initialize_blkdev(int major, int mode)
void rand_initialize_disk(struct gendisk *disk)
{
struct timer_rand_state *state;
if (major >= MAX_BLKDEV || blkdev_timer_state[major])
return;
/*
* If kmalloc returns null, we just won't use that entropy
* source.
*/
state = kmalloc(sizeof(struct timer_rand_state), mode);
state = kmalloc(sizeof(struct timer_rand_state), GFP_KERNEL);
if (state) {
memset(state, 0, sizeof(struct timer_rand_state));
blkdev_timer_state[major] = state;
disk->random = state;
}
}
static ssize_t
random_read(struct file * file, char * buf, size_t nbytes, loff_t *ppos)
{
......@@ -2309,7 +2297,7 @@ __u32 check_tcp_syn_cookie(__u32 cookie, __u32 saddr, __u32 daddr, __u16 sport,
EXPORT_SYMBOL(add_keyboard_randomness);
EXPORT_SYMBOL(add_mouse_randomness);
EXPORT_SYMBOL(add_interrupt_randomness);
EXPORT_SYMBOL(add_blkdev_randomness);
EXPORT_SYMBOL(add_disk_randomness);
EXPORT_SYMBOL(batch_entropy_store);
EXPORT_SYMBOL(generate_random_uuid);
......@@ -406,7 +406,7 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
}
if (!end_that_request_first(rq, uptodate, nr_sectors)) {
add_blkdev_randomness(major(rq->rq_dev));
add_disk_randomness(rq->rq_disk);
if (!blk_rq_tagged(rq))
blkdev_dequeue_request(rq);
else
......
......@@ -1496,7 +1496,7 @@ dasd_end_request(struct request *req, int uptodate)
{
if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
BUG();
add_blkdev_randomness(major(req->rq_dev));
add_disk_randomness(req->rq_disk);
end_that_request_last(req);
return;
}
......
......@@ -357,7 +357,7 @@ static Scsi_Cmnd *__scsi_end_request(Scsi_Cmnd * SCpnt,
return SCpnt;
}
add_blkdev_randomness(major(req->rq_dev));
add_disk_randomness(req->rq_disk);
spin_lock_irqsave(q->queue_lock, flags);
......
......@@ -8,7 +8,8 @@
#include <linux/compiler.h>
extern void set_device_ro(kdev_t dev,int flag);
extern void add_blkdev_randomness(int major);
extern void add_disk_randomness(struct gendisk *disk);
extern void rand_initialize_disk(struct gendisk *disk);
#ifdef CONFIG_BLK_DEV_RAM
......@@ -62,7 +63,7 @@ static inline void end_request(struct request *req, int uptodate)
if (end_that_request_first(req, uptodate, req->hard_cur_sectors))
return;
add_blkdev_randomness(major(req->rq_dev));
add_disk_randomness(req->rq_disk);
blkdev_dequeue_request(req);
end_that_request_last(req);
}
......
......@@ -93,6 +93,9 @@ struct gendisk {
struct device *driverfs_dev;
struct device disk_dev;
struct timer_rand_state *random;
unsigned sync_io; /* RAID */
unsigned reads, writes;
unsigned rio, wio;
......
......@@ -44,14 +44,12 @@ struct rand_pool_info {
extern void rand_initialize(void);
extern void rand_initialize_irq(int irq);
extern void rand_initialize_blkdev(int irq, int mode);
extern void batch_entropy_store(u32 a, u32 b, int num);
extern void add_keyboard_randomness(unsigned char scancode);
extern void add_mouse_randomness(__u32 mouse_data);
extern void add_interrupt_randomness(int irq);
extern void add_blkdev_randomness(int major);
extern void get_random_bytes(void *buf, int nbytes);
void generate_random_uuid(unsigned char uuid_out[16]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment