From patchwork Thu Sep 6 20:37:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xuewei Zhang X-Patchwork-Id: 10591031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B60405A4 for ; Thu, 6 Sep 2018 20:37:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A48CE2AE84 for ; Thu, 6 Sep 2018 20:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 986A32B0BB; Thu, 6 Sep 2018 20:37:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 472F62AF89 for ; Thu, 6 Sep 2018 20:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729993AbeIGBOn (ORCPT ); Thu, 6 Sep 2018 21:14:43 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:43414 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbeIGBOn (ORCPT ); Thu, 6 Sep 2018 21:14:43 -0400 Received: by mail-qk1-f201.google.com with SMTP id u22-v6so8849123qkk.10 for ; Thu, 06 Sep 2018 13:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=F4chAjNYxSfMSSc0lr53i2hjb0o+Jf+wxUQuT0zFpdI=; b=CeUYkJLrs98VkrUJJaAF2mVnPx7yjTsMEiwDjOwKzhC+umm0xoFayxqavXs9s1HhGq x4Os69sLsAPNYD9elS8/9wrzl9HVTAPLPnCc/N+heUgTI4PIlTzqFmEVDbNuS2XyXLku 3Y4IDWX+HExKbwu3dI4jc6h+kt4MjX1cIwvg6047anaYylqSmThqnitC7k8NMpZjgjPT mSq8Oo8RZeIWptaJM4nhFVp6mzFNyE/9oEzQlnQ5UxBTZVt4qb+VnfrEj0706hzbGWJB m6dxfVzGQY9c+VocHpn7CTBWKqSU2WCUvkm6FaShslfQnDPaYsaS7cmAzj81Db7zUD4S cUYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=F4chAjNYxSfMSSc0lr53i2hjb0o+Jf+wxUQuT0zFpdI=; b=dlFCPll4jN0GpKGdHOt3kTXt+o4Vq1x+MOXIQC8YlHyiO5HI3xB0QDeOEon1vaIqvt NIHD4+Q36igEuWK+xfSbq7RbBANCKtkkzAg6XjV1ZyThD4qyTlix+1I1tjhqAfWLqLhW 8gGDUjUIFyxUP5sHzW+4XZv0urlBM3Mp2cBDqe5R0MIaoClFv8PrMBGC/55ViiZzeyA1 5crY/j9UPwYEmbCYn29PvBi25L90agT5nKA3jgY2ncwpZw6viW2YzixkVAEwAbsMTenI /FlzEOoB3+xamv/Yffws02LZE6F9W886b5JFrAABT8bPU2bOOWFtkSxe7lGbyQqykRAS EUUg== X-Gm-Message-State: APzg51C69h17FmphyOLj9SKgW3H2kAnhrwD7UvvazSaJK8Vcv308VnxV GqWVGFW4D/etKwXPqHNgt65SD1qu/ruL X-Google-Smtp-Source: ANB0VdbwMnI00Sd2pHSwyf4yBysxT+PyslcII8ttoBU5wZuT2u6Vh1Q01m7npU1Wkj73ZVxAOde4+nloEvZh X-Received: by 2002:a37:a1d7:: with SMTP id k206-v6mr1500275qke.54.1536266252412; Thu, 06 Sep 2018 13:37:32 -0700 (PDT) Date: Thu, 6 Sep 2018 13:37:19 -0700 Message-Id: <20180906203719.209399-1-xueweiz@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.rc2.392.g5ba43deb5a-goog Subject: [PATCH] scsi: sd: Contribute to randomness when running rotational device From: Xuewei Zhang To: "James E . J . Bottomley" , "Martin K . Petersen" , Ming Lei , Hannes Reinecke , Christoph Hellwig Cc: Paolo Bonzini , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Aditya Kali , tytso@mit.edu, Guenter Roeck , maze@google.com, Xuewei Zhang Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently a scsi device won't contribute to kernel randomness when it uses blk-mq. Since we commonly use scsi on rotational device with blk-mq, it make sense to keep contributing to kernel randomness in these cases. This is especially important for virtual machines. commit b5b6e8c8d3b4 ("scsi: virtio_scsi: fix IO hang caused by automatic irq vector affinity") made all virtio-scsi device to use blk-mq, which does not contribute to randomness today. So for a virtual machine only having virtio-scsi disk (which is common), it will simple stop getting randomness from its disks in today's implementation. With this patch, if the above VM has rotational virtio-scsi device, then it can still benefit from the entropy generated from the disk. Reported-by: Xuewei Zhang Signed-off-by: Xuewei Zhang Reviewed-by: Bart Van Assche Reviewed-by: Ming Lei Reviewed-by: Maciej Żenczykowski --- drivers/scsi/sd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b79b366a94f7..5e4f10d28065 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2959,6 +2959,9 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) if (rot == 1) { blk_queue_flag_set(QUEUE_FLAG_NONROT, q); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q); + } else { + blk_queue_flag_clear(QUEUE_FLAG_NONROT, q); + blk_queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q); } if (sdkp->device->type == TYPE_ZBC) {