From patchwork Sun Mar 31 23:57:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 10878915 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 4EAB51575 for ; Sun, 31 Mar 2019 23:57:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 245D128849 for ; Sun, 31 Mar 2019 23:57:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2EA628867; Sun, 31 Mar 2019 23:57:32 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 8034928849 for ; Sun, 31 Mar 2019 23:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731510AbfCaX5c (ORCPT ); Sun, 31 Mar 2019 19:57:32 -0400 Received: from mail-eopbgr710099.outbound.protection.outlook.com ([40.107.71.99]:47840 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731335AbfCaX5b (ORCPT ); Sun, 31 Mar 2019 19:57:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=testarcselector01; d=microsoft.com; cv=none; b=mvom5AFeaqclhQ7r2pe+kAz89TjPqZAHvPV4YmnVUs1bj8+zuXf3GOwXIB8t93RelLAQ1fSavwO64KZMMFOU9vH6geLuVCNgEXCFORdHLc8Tdp+RaFPG/WJrnWXIXhxU5HcR4wW33TVOewOhjYmqG9hicpC+SJU8JsFh9y4rZ7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=testarcselector01; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gJ8HB+j+P3z2raSVOy1thiADYKs9qTQ3klK6hIxoEz8=; b=qUDnV/k8NGJiq2YtLnV0r37EdupdXz0gv7ti6VQUgT4gMpq5Je+74RxX/IQQmRs6+MmE8EppDpgOwXdwSDSkmwTdnsAmoQtJh2xMre9IyOacJF2Vw65EI8OGBxF/MFiQ2S14n0j9f8lb6VW00gXZn9rRNbO8reZhQP8t4Gh6dpY= ARC-Authentication-Results: i=1; test.office365.com 1;dmarc=none action=none header.from=microsoft.com;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gJ8HB+j+P3z2raSVOy1thiADYKs9qTQ3klK6hIxoEz8=; b=ek9ECAfxgYCWB5ZrBM1Mf3igpkHyirNuj5K+9OamMNdd0Pb3l4YQ5XZ4ngfkaFDB+a2E+9B3k9/5G4tckjzAX8mq/TQlqC62TP5NMRkjpb4ltN+txcqsBr2qHjulmjH10K+zsbkRdQUicC4AaGYhbAxzEeKHuSXy+vOUC6UzyAs= Received: from BN6PR21MB0466.namprd21.prod.outlook.com (10.172.111.144) by BN6PR21MB0276.namprd21.prod.outlook.com (10.173.203.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.2; Sun, 31 Mar 2019 23:57:28 +0000 Received: from BN6PR21MB0466.namprd21.prod.outlook.com ([fe80::f458:691d:54a:b05c]) by BN6PR21MB0466.namprd21.prod.outlook.com ([fe80::f458:691d:54a:b05c%14]) with mapi id 15.20.1771.002; Sun, 31 Mar 2019 23:57:28 +0000 From: Michael Kelley To: KY Srinivasan , "martin.petersen@oracle.com" , Long Li , "James.Bottomley@hansenpartnership.com" , "emilne@redhat.com" , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-scsi@vger.kernel.org" CC: Michael Kelley Subject: [PATCH 1/1] scsi: storvsc: Fix calculation of sub-channel count Thread-Topic: [PATCH 1/1] scsi: storvsc: Fix calculation of sub-channel count Thread-Index: AQHU6B1/IlcHzsnAWkK0ZsVGotIa4g== Date: Sun, 31 Mar 2019 23:57:28 +0000 Message-ID: <1554076559-14873-1-git-send-email-mikelley@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR1301CA0011.namprd13.prod.outlook.com (2603:10b6:301:29::24) To BN6PR21MB0466.namprd21.prod.outlook.com (2603:10b6:404:b2::16) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [131.107.159.136] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 36ebd018-5ef5-4600-7fbf-08d6b634a153 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600139)(711020)(4605104)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:BN6PR21MB0276; x-ms-traffictypediagnostic: BN6PR21MB0276: authentication-results: spf=none (sender IP is ) smtp.mailfrom=mikelley@microsoft.com; x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0993689CD1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(39860400002)(376002)(396003)(136003)(199004)(189003)(5660300002)(4326008)(3846002)(66066001)(6512007)(186003)(476003)(36756003)(6116002)(68736007)(8936002)(305945005)(6486002)(4720700003)(81166006)(81156014)(8676002)(486006)(7736002)(1511001)(6436002)(2616005)(2501003)(50226002)(25786009)(386003)(26005)(10290500003)(10090500001)(14454004)(6506007)(99286004)(53936002)(105586002)(106356001)(478600001)(71190400001)(71200400001)(52116002)(14444005)(256004)(2201001)(86362001)(86612001)(316002)(22452003)(110136005)(102836004)(107886003)(2906002)(97736004);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR21MB0276;H:BN6PR21MB0466.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: avrEKth1A+Ij3VY7cSDjIzQKvYZ67009u8+7UuhdnxDCEVrDevcP7uEbu/PrkOOk98B8pbWlurG0UIydDwyBP5INTGQXsw4oAp6arW7GtMlCvmf18p1pDlLI25+o8XDqlAsg1onDP6oeolNGSuuYf1oj0+Jqoxp5IlkV46HOl81+sXDU83nvf3MFyvJAfH0wygT0WPkrWpD65uzevG08HLICGgww9H9gvvXGRD3oemX0huza8sTFF5F0yyGCu/a9RsSq8XWwzYlI6Qd/2BzfH53rDDood/nvaJZr4zl1nnf0e9wwfCr2RRNsthh3tiQDw5LTSHIV41QpL3urNmySkiGy9ZTsfRMuVcfDME2W1LZlxv4EpyIWQY0SL7dSxDArkKR/nNoTf2sdmWYC5NUBqySiZ+JFUIO90Z5BAH8WP9k= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36ebd018-5ef5-4600-7fbf-08d6b634a153 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Mar 2019 23:57:28.4515 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR21MB0276 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 When the number of sub-channels offered by Hyper-V is >= the number of CPUs in the VM, calculate the correct number of sub-channels. The current code produces one too many. This scenario arises only when the number of CPUs is artificially restricted (for example, with maxcpus= on the kernel boot line), because Hyper-V normally offers a sub-channel count < number of CPUs. While the current code doesn't break, the extra sub-channel is unbalanced across the CPUs (for example, a total of 5 channels on a VM with 4 CPUs). Signed-off-by: Michael Kelley Reviewed-by: Vitaly Kuznetsov --- drivers/scsi/storvsc_drv.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 84380ba..fbaa11a 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -674,7 +674,17 @@ static void handle_multichannel_storage(struct hv_device *device, int max_chns) struct vstor_packet *vstor_packet; int ret, t; - num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns); + /* + * If the number of CPUs is artificially restricted, such as + * with maxcpus=1 on the kernel boot line, Hyper-V could offer + * sub-channels >= the number of CPUs. These sub-channels + * should not be created. The primary channel is already created + * and assigned to one CPU, so check against # CPUs - 1. + */ + num_sc = min((num_cpus - 1), max_chns); + if (!num_sc) + return; + stor_device = get_out_stor_device(device); if (!stor_device) return;