Skip to content

Commit b277da0

Browse files
snitmaxboe
authored andcommitted
block: disable entropy contributions for nonrot devices
Clear QUEUE_FLAG_ADD_RANDOM in all block drivers that set QUEUE_FLAG_NONROT. Historically, all block devices have automatically made entropy contributions. But as previously stated in commit e2e1a14 ("block: add sysfs knob for turning off disk entropy contributions"): - On SSD disks, the completion times aren't as random as they are for rotational drives. So it's questionable whether they should contribute to the random pool in the first place. - Calling add_disk_randomness() has a lot of overhead. There are more reliable sources for randomness than non-rotational block devices. From a security perspective it is better to err on the side of caution than to allow entropy contributions from unreliable "random" sources. Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 7b7b7f7 commit b277da0

14 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎drivers/block/mtip32xx/mtip32xx.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,6 +3952,7 @@ static int mtip_block_initialize(struct driver_data *dd)
39523952

39533953
/* Set device limits. */
39543954
set_bit(QUEUE_FLAG_NONROT, &dd->queue->queue_flags);
3955+
clear_bit(QUEUE_FLAG_ADD_RANDOM, &dd->queue->queue_flags);
39553956
blk_queue_max_segments(dd->queue, MTIP_MAX_SG);
39563957
blk_queue_physical_block_size(dd->queue, 4096);
39573958
blk_queue_max_hw_sectors(dd->queue, 0xffff);

‎drivers/block/nbd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ static int __init nbd_init(void)
847847
* Tell the block layer that we are not a rotational device
848848
*/
849849
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, disk->queue);
850+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, disk->queue);
850851
disk->queue->limits.discard_granularity = 512;
851852
disk->queue->limits.max_discard_sectors = UINT_MAX;
852853
disk->queue->limits.discard_zeroes_data = 0;

‎drivers/block/null_blk.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ static int null_add_dev(void)
507507

508508
nullb->q->queuedata = nullb;
509509
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, nullb->q);
510+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, nullb->q);
510511

511512
disk = nullb->disk = alloc_disk_node(1, home_node);
512513
if (!disk)

‎drivers/block/nvme-core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,7 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
19161916
ns->queue->queue_flags = QUEUE_FLAG_DEFAULT;
19171917
queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, ns->queue);
19181918
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, ns->queue);
1919+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, ns->queue);
19191920
blk_queue_make_request(ns->queue, nvme_make_request);
19201921
ns->dev = dev;
19211922
ns->queue->queuedata = ns;

‎drivers/block/rsxx/dev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)
307307
blk_queue_physical_block_size(card->queue, RSXX_HW_BLK_SIZE);
308308

309309
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, card->queue);
310+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, card->queue);
310311
if (rsxx_discard_supported(card)) {
311312
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, card->queue);
312313
blk_queue_max_discard_sectors(card->queue,

‎drivers/block/skd_main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,6 +4426,7 @@ static int skd_cons_disk(struct skd_device *skdev)
44264426
q->limits.discard_zeroes_data = 1;
44274427
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
44284428
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
4429+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, q);
44294430

44304431
spin_lock_irqsave(&skdev->lock, flags);
44314432
pr_debug("%s:%s:%d stopping %s queue\n",

‎drivers/block/zram/zram_drv.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ static int create_device(struct zram *zram, int device_id)
925925
set_capacity(zram->disk, 0);
926926
/* zram devices sort of resembles non-rotational disks */
927927
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
928+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, zram->disk->queue);
928929
/*
929930
* To ensure that we always get PAGE_SIZE aligned
930931
* and n*PAGE_SIZED sized I/O requests.

‎drivers/ide/ide-disk.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,10 @@ static void ide_disk_setup(ide_drive_t *drive)
685685
printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
686686
queue_max_sectors(q) / 2);
687687

688-
if (ata_id_is_ssd(id))
688+
if (ata_id_is_ssd(id)) {
689689
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
690+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, q);
691+
}
690692

691693
/* calculate drive capacity, and select LBA if possible */
692694
ide_disk_get_capacity(drive);

‎drivers/md/bcache/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
842842
q->limits.logical_block_size = block_size;
843843
q->limits.physical_block_size = block_size;
844844
set_bit(QUEUE_FLAG_NONROT, &d->disk->queue->queue_flags);
845+
clear_bit(QUEUE_FLAG_ADD_RANDOM, &d->disk->queue->queue_flags);
845846
set_bit(QUEUE_FLAG_DISCARD, &d->disk->queue->queue_flags);
846847

847848
blk_queue_flush(q, REQ_FLUSH|REQ_FUA);

‎drivers/mmc/card/queue.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
210210

211211
blk_queue_prep_rq(mq->queue, mmc_prep_request);
212212
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
213+
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, mq->queue);
213214
if (mmc_can_erase(card))
214215
mmc_queue_setup_discard(mq->queue, card);
215216

0 commit comments

Comments
 (0)