Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp431702yba; Wed, 15 May 2019 04:01:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCdNEEU8SV17RhFpR4dLDorjkGsJ5hdxqtvvyMTFZvmJfjZ0YqsgeTvaVhMN2TCjRrxh/H X-Received: by 2002:a17:902:2808:: with SMTP id e8mr16526299plb.244.1557918085483; Wed, 15 May 2019 04:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557918085; cv=none; d=google.com; s=arc-20160816; b=LbihuMOfZjLdvOvElOpQNc+kfwKY3owfzvKhe0960z1ztyDr1AeOpE05M9tfJG1P2D JFbeXZExzHDFxiVVRsLYPA5K6J5pmCgDUXb0gJk2W1gAMk8oi6LfiEGY0C67Q85qKqoj h4MQ3bU5OwZooWJumJ8gUHWvwHarfeEvpQ8c/mP3Um9Q2SdCbnuH2+WSESqULbXLIUAG wMBrZOsfHDEKXAioaB3wiZ/QxKogGizMHwEXNJbKy/tz6kCI1sUo9cOltcEz7xtXXsnb VKqs09F3bmRMnS3tZDg0ayjqv6LVn92Rcl4WQ7Y3x6t6sz2gn3nsI9+4I3XwltxPEoSD xngQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r0qnaMq83r30LMQVrR9RX4SlfOAGG5sbFNdMad0cV30=; b=a1DN2B6vUqq9Ma0jhGi8RWuahTqWIIUTVdsW2qo1bSETDS7+c8TjYcpfDLNShwc7Xz NxG5OFAvr612uq6W5c3S1L13QKp+THv9MLXl21eH1bOpFjbdA/uWPi6L7fNdPaayE3PV 4oX2WjKZc/AJYFC86O4PmUKMKlkHKYzKhk321tduw5clbkldQws4TogNGc6gFSa6ejCt R6SgRGIear1dzgOPhOlLcaLN4ZUYQrXXcx1hVmztv+RowAicCbGnlmtpPVzwsNjMFNqk Km31uPtAc9iLFW2zZ7T4F24c6EkpXZX7cUi0cNf2XtNp7Eb6R4pGlWGp4UDYPZUe5kUY QgSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JWEa4yJA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si1486823plt.394.2019.05.15.04.01.10; Wed, 15 May 2019 04:01:25 -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=JWEa4yJA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727160AbfEOK73 (ORCPT + 99 others); Wed, 15 May 2019 06:59:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727153AbfEOK7Z (ORCPT ); Wed, 15 May 2019 06:59:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD0662166E; Wed, 15 May 2019 10:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557917965; bh=Rigk2BP1vhzhrGcwtIj8zm7+kw/wq++uhMPtlRGgHN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWEa4yJAU+x8hHsPqhP2FyuYZ72mDyTLm3DS6abLuy1ZySc0nxAJDgdIO2a/yODU0 v1/+CoSeGYv6RH9A4zJqfoLkMNViO2yVSX1qiUASbviWST8jYebvjjhia1y60IeVQ7 ec7Au3o4cq4XopBTv166en+eYBeVG6nqoTBKqJzQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Kelley , Vitaly Kuznetsov , Long Li , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 3.18 42/86] scsi: storvsc: Fix calculation of sub-channel count Date: Wed, 15 May 2019 12:55:19 +0200 Message-Id: <20190515090650.899536539@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090642.339346723@linuxfoundation.org> References: <20190515090642.339346723@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 --- 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 96c6e75bbfe6..bc29b571e3fb 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -788,13 +788,22 @@ static void handle_sc_creation(struct vmbus_channel *new_sc) static void handle_multichannel_storage(struct hv_device *device, int max_chns) { 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.20.1