From patchwork Mon Apr 1 16:10:52 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: 10880221 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 057F9139A for ; Mon, 1 Apr 2019 16:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E45EB25D99 for ; Mon, 1 Apr 2019 16:11:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBD702881B; Mon, 1 Apr 2019 16:11:01 +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 60BD725D99 for ; Mon, 1 Apr 2019 16:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728007AbfDAQK4 (ORCPT ); Mon, 1 Apr 2019 12:10:56 -0400 Received: from mail-eopbgr740127.outbound.protection.outlook.com ([40.107.74.127]:40704 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727023AbfDAQK4 (ORCPT ); Mon, 1 Apr 2019 12:10:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=testarcselector01; d=microsoft.com; cv=none; b=rHygVZ/VZeG75smzU6sCj3xysthcotefzEXoEk3Gj2Kh9YPIWm3+Qjg9BUKiakBYCk6/RTn9jicO3Or1fvKcMf03w7RbxWgfXxt/9rc+JDHjgvrkBlvbUcULtkRhluqY36fbVpGkAoqKzdEoC1kzK4N3uqd64SYRlf1CTLDqp7Y= 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=/4F1lwCpacHq/ZrOXLD7u4JskYkfYFZZrewB0SzPDHs=; b=fBzBqXOoho0xRJeDoUs7xlT+HKHEf9uGVMMVH/TDS8AbgiWaiMrVOYMONaSPXhHxVmCShV+UupBDG8RI2PZTdh863EIQ9I+Oj/5WoDLTkmri6cSHkwUWY7DeFiJnf45gAeu5/Cl22XfSM8R/P8L//yqYmQvIUg6navEcO224o0A= 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=/4F1lwCpacHq/ZrOXLD7u4JskYkfYFZZrewB0SzPDHs=; b=O1SKSWhkXjFW+KiUnUOAnbNY7ss+lMmdc3fVAQRs+KyGa1KDJtbBLRY2zhViFf53rXIkSgDBiCdg4utuKBgBciPR5y8zqPWY1eRR5NTdC1vfDNhUCSbea2wOL3K26FnSACIKokPsybYrbpjuhMRBt9S2rwpcHyBUD547UtGJDak= Received: from BN6PR21MB0466.namprd21.prod.outlook.com (10.172.111.144) by BN6PR21MB0849.namprd21.prod.outlook.com (10.173.205.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.2; Mon, 1 Apr 2019 16:10:52 +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; Mon, 1 Apr 2019 16:10:52 +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 v2 1/1] scsi: storvsc: Fix calculation of sub-channel count Thread-Topic: [PATCH v2 1/1] scsi: storvsc: Fix calculation of sub-channel count Thread-Index: AQHU6KV6UQald53dlUasls9Rw8AeYw== Date: Mon, 1 Apr 2019 16:10:52 +0000 Message-ID: <1554134985-8671-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: MWHPR22CA0019.namprd22.prod.outlook.com (2603:10b6:300:ef::29) 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.147.136] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6bdbca7d-087a-4c72-bd7e-08d6b6bc9cc3 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:BN6PR21MB0849; x-ms-traffictypediagnostic: BN6PR21MB0849: 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: 0994F5E0C5 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(346002)(396003)(136003)(39860400002)(199004)(189003)(14444005)(81166006)(106356001)(476003)(478600001)(305945005)(6506007)(486006)(6486002)(2616005)(256004)(68736007)(99286004)(50226002)(52116002)(66066001)(26005)(1511001)(102836004)(386003)(7736002)(3846002)(6116002)(2906002)(86362001)(10290500003)(6512007)(2201001)(4720700003)(186003)(71190400001)(71200400001)(36756003)(6436002)(2501003)(10090500001)(8676002)(4326008)(8936002)(110136005)(316002)(5660300002)(53936002)(81156014)(97736004)(105586002)(107886003)(86612001)(25786009)(22452003)(14454004);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR21MB0849;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: Fh83anACCCre7mn45mPUC3a2jyy2l7gfUU+0S0bsCEkZt3zlhRnyLj3JnpFYKK1LzWzQnkbN5AnTn+qOgxy5ffJvR1EH5aOFdfgFuxH02P/Bmn47lV9LXsShARJB0nWy2KHmsU2f1yy63uRgeXSBoC9Nin6XuRLeGAcZwe7PKzt9m16cxW6KW1iSnYhody59IbTcCuqf9p6Geh/9kEg2Is/cKmOjJWBHQrRfg8Vx0WYz9P+K6VjqLeIuEFDGlzEywmP4yf2mYq6ycfyubSLZxQjuqWhBhPP2lC5lfDubyqc7PpzcvmhhpT+mkMW8aBQIR3JwkYdzAL0Wjiv0HUGbGhUqGFv8tNeP06sdjBf1DGQcbXJ0YpQK5Vy9vCmev708tpEX4pmH3o+937jEiCK5zSiZnhTHIPpSYZois4cHWKc= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6bdbca7d-087a-4c72-bd7e-08d6b6bc9cc3 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Apr 2019 16:10:52.3657 (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: BN6PR21MB0849 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 Reviewed-by: Long Li --- Changes in v2: * Put num_online_cpus() inline and eliminate num_cpus local variable [Vitaly Kuznetsov] --- drivers/scsi/storvsc_drv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 84380ba..e186743 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -668,13 +668,22 @@ static void handle_multichannel_storage(struct hv_device *device, int max_chns) { struct device *dev = &device->device; struct storvsc_device *stor_device; - int num_cpus = num_online_cpus(); int num_sc; struct storvsc_cmd_request *request; 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((int)(num_online_cpus() - 1), max_chns); + if (!num_sc) + return; + stor_device = get_out_stor_device(device); if (!stor_device) return;