Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp664751yba; Wed, 24 Apr 2019 07:41:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxN2oQftcGU0PTIlhLzwVtiRYA13pnywVY2C3/h8tg4mbJYqWtoBxcY6do96lJNhnIOgcrn X-Received: by 2002:a63:f809:: with SMTP id n9mr30372364pgh.201.1556116880138; Wed, 24 Apr 2019 07:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556116880; cv=none; d=google.com; s=arc-20160816; b=XzStOperk4QPWg91MSz+WbO7A/eQms/ykpOuH+G8jpbsNZbe6jr1mstpTzVo811CcX FD5CWIKiPLYrZq4kqBBnrsGh1CJB2OJ8JddFMLFjH2+nEv16lQurC2J5SNB23a362+C7 GIwzdUrNABpqOrTlHfFo9uFQnteK2KF/I6ppzeRfeaMzy/lAMLN8n5jOVAtB5sFFgWXx W1VOH0Yirab1cxiR6iFUgKrlqB2iqEgu+YLCFNJ7l8P+f+pXgpHnwRWtL4EDErBPeSKW IQUo1xcmJdv+UgaPgj7nqrlpYVkYbEH75ZbqTrVlqp2Onub8e7irOk4Z+erVn78SoTBe bHsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gwRXh0yKavN6EaJjAp2/fVI/AYwN82G1s/ZplU6Jmog=; b=u0tveWLdfDpuX8IVxKwx9LQFsUXurrtI29x0cx1S7uXYj7C+YEV8kpDWD/UgtTl8Im F2WSpldgEsndUaeP78jwRzCVeZx2hwkBDzV+ENOoGaoBEiL+L3EAMuXZiq6tR/7nZF53 xx7R7LOaO1aBpBtI3LhtmvZZTc0dnhX+9RF1KoiErI1eTIpCtSIPzvAQ26rOV1KEp9tg 01bjoJymYsCDRdUMeJRjQPutMmH++vQwu0W2h9YE5YmjBR/h+ZcrLbwbaY3rznkTyFw7 iEFlsJBYpefd/UIOhG7lMQYtuEuMkbm6rwQYYFalJpJUAzspWWNsLFE98pUAYXUZT7md bFLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MgxwBNT7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z25si17274961pgv.442.2019.04.24.07.41.04; Wed, 24 Apr 2019 07:41:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MgxwBNT7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731378AbfDXOiP (ORCPT + 99 others); Wed, 24 Apr 2019 10:38:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731373AbfDXOf0 (ORCPT ); Wed, 24 Apr 2019 10:35:26 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3C1732089F; Wed, 24 Apr 2019 14:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556116525; bh=Kr4HRyn20O0VZf8EZV5GdHULHpUgLNQCfIEkhfnw34Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MgxwBNT7sAmacU/UckN2KipYpgTzPjH2VXXStGUITTu9uJs6mYXrLT7REvA0imz6G q2CBo6i865gGfREidpe6iGd9kIc959SvmcNzWHMgeQi5oztY13ZUTJ8AZvuoT1swig yr7OODkS6QNFdqYalUO91/k6otZItNfny4qJ4rpI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Kelley , "Martin K . Petersen" , Sasha Levin , linux-hyperv@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 42/66] scsi: storvsc: Fix calculation of sub-channel count Date: Wed, 24 Apr 2019 10:33:16 -0400 Message-Id: <20190424143341.27665-42-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190424143341.27665-1-sashal@kernel.org> References: <20190424143341.27665-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Kelley [ Upstream commit 382e06d11e075a40b4094b6ef809f8d4bcc7ab2a ] 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 Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin (Microsoft) --- 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 84380bae20f1..e186743033f4 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; -- 2.19.1