block: disable entropy contributions from nonrot devices
Subsystems (9)
PATCH 1/1 block: disable entropy contributions from nonrot devices
Introduce queue_flags_set_nonrot_clear_add_random() and convert all block drivers that set QUEUE_FLAG_NONROT over to using it instead.
Historically, all block devices have automatically made entropy contributions. But as previously stated in commit e2e1a148 ("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.
--- drivers/block/mtip32xx/mtip32xx.c | 2 +- drivers/block/nbd.c | 2 +- drivers/block/null_blk.c | 2 +- drivers/block/nvme-core.c | 2 +- drivers/block/rsxx/dev.c | 2 +- drivers/block/skd_main.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/ide/ide-disk.c | 2 +- drivers/md/bcache/super.c | 2 +- drivers/mmc/card/queue.c | 2 +- drivers/mtd/mtd_blkdevs.c | 2 +- drivers/s390/block/scm_blk.c | 2 +- drivers/s390/block/xpram.c | 2 +- drivers/scsi/sd.c | 2 +- include/linux/blkdev.h | 6 ++++++ 15 files changed, 20 insertions(+), 14 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
@@ -3950,7 +3950,7 @@ skip_create_disk: goto start_service_thread;/* Set device limits. */ -set_bit (QUEUE_FLAG_NONROT , &dd->queue->queue_flags); +queue_flags_set_nonrot_clear_add_random (dd->queue);blk_queue_max_segments (dd->queue,MTIP_MAX_SG );blk_queue_physical_block_size (dd->queue,4096 );blk_queue_max_hw_sectors (dd->queue,0xffff );
drivers/block/nbd.c +1 -1
@@ -846,7 +846,7 @@ static int __init nbd_init(void)/* * Tell the block layer that we are not a rotational device */ -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , disk->queue); +queue_flags_set_nonrot_clear_add_random (disk->queue); disk->queue->limits.discard_granularity =512 ; disk->queue->limits.max_discard_sectors =UINT_MAX ; disk->queue->limits.discard_zeroes_data =0 ;
drivers/block/null_blk.c +1 -1
@@ -517,7 +517,7 @@ static int null_add_dev(void) } nullb->q->queuedata = nullb; -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , nullb->q); +queue_flags_set_nonrot_clear_add_random (nullb->q); disk = nullb->disk =alloc_disk_node (1 , home_node);if (!disk) {
drivers/block/nvme-core.c +1 -1
@@ -1915,7 +1915,7 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid, goto out_free_ns; ns->queue->queue_flags =QUEUE_FLAG_DEFAULT ;queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , ns->queue); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , ns->queue); +queue_flags_set_nonrot_clear_add_random (ns->queue);blk_queue_make_request (ns->queue, nvme_make_request); ns->dev = dev; ns->queue->queuedata = ns;
drivers/block/rsxx/dev.c +1 -1
@@ -306,7 +306,7 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)blk_queue_max_hw_sectors (card->queue, blkdev_max_hw_sectors);blk_queue_physical_block_size (card->queue,RSXX_HW_BLK_SIZE ); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , card->queue); +queue_flags_set_nonrot_clear_add_random (card->queue);if (rsxx_discard_supported (card)) {queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , card->queue); blk_queue_max_discard_sectors(card->queue,
drivers/block/skd_main.c +1 -1
@@ -4425,7 +4425,7 @@ static int skd_cons_disk(struct skd_device *skdev) q->limits.max_discard_sectors =UINT_MAX >>9 ; q->limits.discard_zeroes_data =1 ;queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +queue_flags_set_nonrot_clear_add_random (q);spin_lock_irqsave (&skdev->lock, flags); pr_debug("%s:%s:%d stopping %s queue\n",
drivers/block/zram/zram_drv.c +1 -1
@@ -928,7 +928,7 @@ static int create_device(struct zram *zram, int device_id)/* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ set_capacity (zram->disk,0 );/* zram devices sort of resembles non-rotational disks */ -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , zram->disk->queue); +queue_flags_set_nonrot_clear_add_random (zram->disk->queue);/* * To ensure that we always get PAGE_SIZE aligned * and n*PAGE_SIZED sized I/O requests.
drivers/ide/ide-disk.c +1 -1
@@ -686,7 +686,7 @@ static void ide_disk_setup(ide_drive_t *drive) queue_max_sectors(q) / 2);if (ata_id_is_ssd (id)) -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +queue_flags_set_nonrot_clear_add_random (q);/* calculate drive capacity, and select LBA if possible */ ide_disk_get_capacity (drive);
drivers/md/bcache/super.c +1 -1
@@ -841,8 +841,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, q->limits.io_min = block_size; q->limits.logical_block_size = block_size; q->limits.physical_block_size = block_size; -set_bit (QUEUE_FLAG_NONROT , &d->disk->queue->queue_flags);set_bit (QUEUE_FLAG_DISCARD , &d->disk->queue->queue_flags); +queue_flags_set_nonrot_clear_add_random (d->disk->queue);blk_queue_flush (q,REQ_FLUSH |REQ_FUA );
drivers/mmc/card/queue.c +1 -1
@@ -209,7 +209,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, mq->queue->queuedata = mq;blk_queue_prep_rq (mq->queue, mmc_prep_request); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , mq->queue); +queue_flags_set_nonrot_clear_add_random (mq->queue);if (mmc_can_erase (card))mmc_queue_setup_discard (mq->queue, card);
drivers/mtd/mtd_blkdevs.c +1 -1
@@ -416,7 +416,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) new->rq->queuedata = new;blk_queue_logical_block_size (new->rq, tr->blksize); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , new->rq); +queue_flags_set_nonrot_clear_add_random (new->rq);if (tr->discard) {queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , new->rq);
drivers/s390/block/scm_blk.c +1 -1
@@ -385,7 +385,7 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)blk_queue_logical_block_size (rq,1 <<12 );blk_queue_max_hw_sectors (rq, nr_max_blk <<3 );/* 8 * 512 = blk_size */ blk_queue_max_segments (rq, nr_max_blk); -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , rq); +queue_flags_set_nonrot_clear_add_random (rq);scm_blk_dev_cluster_setup (bdev); bdev->gendisk =alloc_disk (SCM_NR_PARTS );
drivers/s390/block/xpram.c +1 -1
@@ -345,7 +345,7 @@ static int __init xpram_setup_blkdev(void)put_disk (xpram_disks[i]); goto out; } -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , xpram_queues[i]); +queue_flags_set_nonrot_clear_add_random (xpram_queues[i]);blk_queue_make_request (xpram_queues[i], xpram_make_request);blk_queue_logical_block_size (xpram_queues[i],4096 ); }
drivers/scsi/sd.c +1 -1
@@ -2661,7 +2661,7 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) rot =get_unaligned_be16 (&buffer[4 ]);if (rot ==1 ) -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , sdkp->disk->queue); +queue_flags_set_nonrot_clear_add_random (sdkp->disk->queue); out:kfree (buffer);
include/linux/blkdev.h +6 -0
@@ -585,6 +585,12 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)__clear_bit (flag, &q->queue_flags); } +static inline void queue_flags_set_nonrot_clear_add_random (struct request_queue *q) +{ +queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q); +} +#define blk_queue_tagged (q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)#define blk_queue_stopped (q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)#define blk_queue_dying (q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
Signature · 1 line
1.7.4.4
Quoted 21 lines
-----Original Message-----
From: [email protected] [mailto:linux-kernel- [email protected]] On Behalf Of Mike Snitzer
Sent: Thursday, 02 October, 2014 7:11 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] block: disable entropy contributions from nonrot devicesIntroduce
queue_flags_set_nonrot_clear_add_random()and convert all block drivers that setQUEUE_FLAG_NONROTover to using it instead.Historically, all block devices have automatically made entropy contributions. But as previously stated in commit
e2e1a148("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.
- Callingadd_disk_randomness()has a lot of overhead.
Quoted 4 lines
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.
blk-mq defaults to off (QUEUE_FLAG_MQ_DEFAULT does not include QUEUE_FLAG_ADD_RANDOM).
Even when it's off in block layer completion processing, all interrupts, storage or not, are forced to contribute during hardirq processing. I've seen this add 3-12 us latency blips every 64 interrupts (when the "fast_mix" code runs out of bits).
Example of fast_mix only taking 0.071 us:
(from ftrace function_graph)
8) | handle_irq_event() {
8) | handle_irq_event_percpu() {
8) | do_hpsa_intr_msi [hpsa]() {
8) 0.060 us | SA5_performant_completed [hpsa]();
8) 0.397 us | }
8) 0.071 us | add_interrupt_randomness();
8) 0.071 us | note_interrupt();
8) 1.495 us | }
8) 0.045 us | _raw_spin_lock();
8) 2.165 us | }Example of the 64th bit taking 3.814 us:
8) | handle_irq_event() {
8) | handle_irq_event_percpu() {
...
8) | add_interrupt_randomness() {
8) | __mix_pool_bytes() {
8) 0.312 us | _mix_pool_bytes();
8) 0.688 us | }
8) | credit_entropy_bits() {
8) | __wake_up() {
8) 0.070 us | _raw_spin_lock_irqsave();
8) 0.050 us | __wake_up_common();
8) 0.056 us | _raw_spin_unlock_irqrestore();
8) 1.448 us | }
8) 0.048 us | kill_fasync();
8) 2.313 us | }
8) 3.814 us | }---
Rob Elliott HP Server Storage
Jens Axboe
maintainerQuoted 26 lines · Robert (Server Storage)
Quoted 21 lines
-----Original Message-----
From: [email protected] [mailto:linux-kernel- [email protected]] On Behalf Of Mike Snitzer
Sent: Thursday, 02 October, 2014 7:11 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] block: disable entropy contributions from nonrot devicesIntroduce
queue_flags_set_nonrot_clear_add_random()and convert all block drivers that setQUEUE_FLAG_NONROTover to using it instead.Historically, all block devices have automatically made entropy contributions. But as previously stated in commit
e2e1a148("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.
- Callingadd_disk_randomness()has a lot of overhead.Quoted 4 lines
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.
Quoted 7 lines
blk-mq defaults to off (
QUEUE_FLAG_MQ_DEFAULTdoes not includeQUEUE_FLAG_ADD_RANDOM).Even when it's off in block layer completion processing, all interrupts, storage or not, are forced to contribute during hardirq processing. I've seen this add 3-12 us latency blips every 64 interrupts (when the "
fast_mix" code runs out of bits).
Yeah, it's a well known problem, and just as large (or larger) as the request completion randomness. It has significant performance implications, as your trace also shows. I'm pretty sure I complained about this 2-3 years ago (or longer), yet it's still poor.
I'd be fine with having an irq registration flag that says "don't contribute to randomness", on the grounds of more predictable irq latencies one these devices not adding any real entropy to the pool. But the suboptimal mixing should really be fixed.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 11 lines · Mike Snitzer
Introduce
queue_flags_set_nonrot_clear_add_random()and convert all block drivers that setQUEUE_FLAG_NONROTover to using it instead.Historically, all block devices have automatically made entropy contributions. But as previously stated in commit
e2e1a148("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.
- Callingadd_disk_randomness()has a lot of overhead.
Quoted 4 lines
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.
Don't add a special function for this, just use the flag clear/set functions for both.
Signature · 1 line
Jens Axboe
PATCH v2 1/1 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 e2e1a148 ("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.
--- drivers/block/mtip32xx/mtip32xx.c | 1 + drivers/block/nbd.c | 1 + drivers/block/null_blk.c | 1 + drivers/block/nvme-core.c | 1 + drivers/block/rsxx/dev.c | 1 + drivers/block/skd_main.c | 1 + drivers/block/zram/zram_drv.c | 1 + drivers/ide/ide-disk.c | 4 +++- drivers/md/bcache/super.c | 1 + drivers/mmc/card/queue.c | 1 + drivers/mtd/mtd_blkdevs.c | 1 + drivers/s390/block/scm_blk.c | 1 + drivers/s390/block/xpram.c | 1 + drivers/scsi/sd.c | 4 +++- 14 files changed, 18 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +1 -0
@@ -3951,6 +3951,7 @@ skip_create_disk:/* Set device limits. */ set_bit (QUEUE_FLAG_NONROT , &dd->queue->queue_flags); +clear_bit (QUEUE_FLAG_ADD_RANDOM , &dd->queue->queue_flags);blk_queue_max_segments (dd->queue,MTIP_MAX_SG );blk_queue_physical_block_size (dd->queue,4096 );blk_queue_max_hw_sectors (dd->queue,0xffff );
drivers/block/nbd.c +1 -0
@@ -847,6 +847,7 @@ static int __init nbd_init(void)* Tell the block layer that we are not a rotational device */ queue_flag_set_unlocked (QUEUE_FLAG_NONROT , disk->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , disk->queue); disk->queue->limits.discard_granularity =512 ; disk->queue->limits.max_discard_sectors =UINT_MAX ; disk->queue->limits.discard_zeroes_data =0 ;
drivers/block/null_blk.c +1 -0
@@ -518,6 +518,7 @@ static int null_add_dev(void) nullb->q->queuedata = nullb;queue_flag_set_unlocked (QUEUE_FLAG_NONROT , nullb->q); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , nullb->q); disk = nullb->disk =alloc_disk_node (1 , home_node);if (!disk) {
drivers/block/nvme-core.c +1 -0
@@ -1916,6 +1916,7 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid, ns->queue->queue_flags =QUEUE_FLAG_DEFAULT ;queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , ns->queue);queue_flag_set_unlocked (QUEUE_FLAG_NONROT , ns->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , ns->queue);blk_queue_make_request (ns->queue, nvme_make_request); ns->dev = dev; ns->queue->queuedata = ns;
drivers/block/rsxx/dev.c +1 -0
@@ -307,6 +307,7 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)blk_queue_physical_block_size (card->queue,RSXX_HW_BLK_SIZE );queue_flag_set_unlocked (QUEUE_FLAG_NONROT , card->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , card->queue);if (rsxx_discard_supported (card)) {queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , card->queue); blk_queue_max_discard_sectors(card->queue,
drivers/block/skd_main.c +1 -0
@@ -4426,6 +4426,7 @@ static int skd_cons_disk(struct skd_device *skdev) q->limits.discard_zeroes_data =1 ;queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , q);queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q);spin_lock_irqsave (&skdev->lock, flags); pr_debug("%s:%s:%d stopping %s queue\n",
drivers/block/zram/zram_drv.c +1 -0
@@ -929,6 +929,7 @@ static int create_device(struct zram *zram, int device_id)set_capacity (zram->disk,0 );/* zram devices sort of resembles non-rotational disks */ queue_flag_set_unlocked (QUEUE_FLAG_NONROT , zram->disk->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , zram->disk->queue);/* * To ensure that we always get PAGE_SIZE aligned * and n*PAGE_SIZED sized I/O requests.
drivers/ide/ide-disk.c +3 -1
@@ -685,8 +685,10 @@ static void ide_disk_setup(ide_drive_t *drive)printk (KERN_INFO "%s: max request size: %dKiB\n" , drive->name,queue_max_sectors (q) /2 ); -if (ata_id_is_ssd (id)) +if (ata_id_is_ssd (id)) {queue_flag_set_unlocked (QUEUE_FLAG_NONROT , q); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , q); + }/* calculate drive capacity, and select LBA if possible */ ide_disk_get_capacity (drive);
drivers/md/bcache/super.c +1 -0
@@ -842,6 +842,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, q->limits.logical_block_size = block_size; q->limits.physical_block_size = block_size;set_bit (QUEUE_FLAG_NONROT , &d->disk->queue->queue_flags); +clear_bit (QUEUE_FLAG_ADD_RANDOM , &d->disk->queue->queue_flags);set_bit (QUEUE_FLAG_DISCARD , &d->disk->queue->queue_flags);blk_queue_flush (q,REQ_FLUSH |REQ_FUA );
drivers/mmc/card/queue.c +1 -0
@@ -210,6 +210,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,blk_queue_prep_rq (mq->queue, mmc_prep_request);queue_flag_set_unlocked (QUEUE_FLAG_NONROT , mq->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , mq->queue);if (mmc_can_erase (card))mmc_queue_setup_discard (mq->queue, card);
drivers/mtd/mtd_blkdevs.c +1 -0
@@ -417,6 +417,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)blk_queue_logical_block_size (new->rq, tr->blksize);queue_flag_set_unlocked (QUEUE_FLAG_NONROT , new->rq); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , new->rq);if (tr->discard) {queue_flag_set_unlocked (QUEUE_FLAG_DISCARD , new->rq);
drivers/s390/block/scm_blk.c +1 -0
@@ -386,6 +386,7 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)blk_queue_max_hw_sectors (rq, nr_max_blk <<3 );/* 8 * 512 = blk_size */ blk_queue_max_segments (rq, nr_max_blk);queue_flag_set_unlocked (QUEUE_FLAG_NONROT , rq); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , rq);scm_blk_dev_cluster_setup (bdev); bdev->gendisk =alloc_disk (SCM_NR_PARTS );
drivers/s390/block/xpram.c +1 -0
@@ -346,6 +346,7 @@ static int __init xpram_setup_blkdev(void) goto out; }queue_flag_set_unlocked (QUEUE_FLAG_NONROT , xpram_queues[i]); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , xpram_queues[i]);blk_queue_make_request (xpram_queues[i], xpram_make_request);blk_queue_logical_block_size (xpram_queues[i],4096 ); }
drivers/scsi/sd.c +3 -1
@@ -2660,8 +2660,10 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) rot =get_unaligned_be16 (&buffer[4 ]); -if (rot ==1 ) +if (rot ==1 ) {queue_flag_set_unlocked (QUEUE_FLAG_NONROT , sdkp->disk->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , sdkp->disk->queue); + } out:kfree (buffer);
Signature · 1 line
1.7.4.4