Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2572978yba; Mon, 6 May 2019 08:11:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZv+pxf5Y2b2QpG0unfDokQ2FomtXZIjHSqpQ3450p5Ed6X0dbDLfSALbWjmhokWegol8g X-Received: by 2002:a17:902:7883:: with SMTP id q3mr32671644pll.60.1557155476932; Mon, 06 May 2019 08:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155476; cv=none; d=google.com; s=arc-20160816; b=F9MnHIPumQmDNvMbGlq0U9Z3r2p5s4xAmHwibouJCsuPGadEmJf00wuNiS50aZ0jpG Fdfu6DFLinW+OUxYyD0zLjOill/V2TxkqdBs6HwEdXVfpaqI8X9CqV+k0LxF8WX9pFtO CrqvJeEh9WObczcV6QSH1nsqheLTmUhkCS0W8D6aqIq7J+6NttdY2MIYsypNpoEtv4b8 mJaapO3sTbks2U2pQrnsYhaijhBv2IT2jeq5Kv/GJrPmR3clZ8urCpDvrtIsEoPr0NyA HThHA7LAqfO/jnceyGP2z5atP/zxT/Y2ANKYDaHdMzT0vvyG595cxN5Lg1JZpBvBmGIC fslg== 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=VsXcaNCi1NF1CrDyutGc6qp+gaZgImfO7SjF7+tfJEQ=; b=Fmy5gH/9PQi7pW4nglAWw5fhpdcMF4KHAlmINksL6re2LI3haTZsH5fxJnR5REfynj Rc7niAueAod3aO3UZpkRZVy80U/2+5jQKovzXe7aYClHHz1ktMTVATbT5npSCCnHd9YA Deqp/6K3seaYD9+x3yNyRs1/JQjyvMI3i9AVv6NdJjLlYMwKNG4diFwnu7/vwNdlRo3y UiSSnnUC9BpqgEWS2f1B+OTjs9V2YNv5PcyVzuutgpfhQFcLx30LdLcXHpEamr9TXro+ rvrg6uVv+gubPohXriLqW+hbWz3VsOB9BaYJaR0yPDoFP0SDQByDsR8eEA19fRnISPzo 4ZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FGKZVMUN; 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 22si12691691pgm.134.2019.05.06.08.11.00; Mon, 06 May 2019 08:11:16 -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=FGKZVMUN; 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 S1727128AbfEFOgQ (ORCPT + 99 others); Mon, 6 May 2019 10:36:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:56526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbfEFOgO (ORCPT ); Mon, 6 May 2019 10:36:14 -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 D2401204EC; Mon, 6 May 2019 14:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153373; bh=LxzFWw3LldBNN96O7zHupf961vJFiKBQee29drPGHdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGKZVMUNLc7pg7mBSLKbvqrnLOWv4jhQBdv3dUUp3plg/ooyRrinpZkM/Xabto5gr ko6E2ueIhD27Y7t0uifATLCoBs2dt8A3dLTFW9gPbc6NTRDOZJyy/WItpiZePo2vxS 1i5qqxlL4mh8QZj/0KhJnxNUovSr3RnCi4g3XKJk= 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 (Microsoft)" Subject: [PATCH 5.0 064/122] scsi: storvsc: Fix calculation of sub-channel count Date: Mon, 6 May 2019 16:32:02 +0200 Message-Id: <20190506143100.713256282@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@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 (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.20.1