Skip to content

Commit e4a0569

Browse files
James Bottomleymartinkpetersen
authored andcommitted
scsi: sd: fix entropy gathering for most rotational disks
The problem is that the default for MQ is not to gather entropy, whereas the default for the legacy queue was always to gather it. The original attempt to fix entropy gathering for rotational disks under MQ added an else branch in sd_read_block_characteristics(). Unfortunately, the entire check isn't reached if the device has no characteristics VPD page. Since this page was only introduced in SBC-3 and its optional anyway, most less expensive rotational disks don't have one, meaning they all stopped gathering entropy when we made MQ the default. In a wholly unrelated change, openssl and openssh won't function until the random number generator is initialised, meaning lots of people have been seeing large delays before they could log into systems with default MQ kernels due to this lack of entropy, because it now can take tens of minutes to initialise the kernel random number generator. The fix is to set the non-rotational and add-randomness flags unconditionally early on in the disk initialization path, so they can be reset only if the device actually reports being non-rotational via the VPD page. Reported-by: Mikael Pettersson <mikpelinux@gmail.com> Fixes: 83e32a5 ("scsi: sd: Contribute to randomness when running rotational device") Cc: stable@vger.kernel.org Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Reviewed-by: Jens Axboe <axboe@kernel.dk> Reviewed-by: Xuewei Zhang <xueweiz@google.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent bb61b84 commit e4a0569

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/scsi/sd.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,9 +2951,6 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp)
29512951
if (rot == 1) {
29522952
blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
29532953
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
2954-
} else {
2955-
blk_queue_flag_clear(QUEUE_FLAG_NONROT, q);
2956-
blk_queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);
29572954
}
29582955

29592956
if (sdkp->device->type == TYPE_ZBC) {
@@ -3090,6 +3087,15 @@ static int sd_revalidate_disk(struct gendisk *disk)
30903087
if (sdkp->media_present) {
30913088
sd_read_capacity(sdkp, buffer);
30923089

3090+
/*
3091+
* set the default to rotational. All non-rotational devices
3092+
* support the block characteristics VPD page, which will
3093+
* cause this to be updated correctly and any device which
3094+
* doesn't support it should be treated as rotational.
3095+
*/
3096+
blk_queue_flag_clear(QUEUE_FLAG_NONROT, q);
3097+
blk_queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);
3098+
30933099
if (scsi_device_supports_vpd(sdp)) {
30943100
sd_read_block_provisioning(sdkp);
30953101
sd_read_block_limits(sdkp);

0 commit comments

Comments
 (0)