Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp643667pxb; Mon, 25 Oct 2021 15:41:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIgEZTUSYjlr7BUnsiW0p7OvmBsUsVwkgusA1L1Jp4mpgaZ65yXEC5liteqFjiuzp2TuPn X-Received: by 2002:a05:6a00:2181:b0:44d:c18d:7af9 with SMTP id h1-20020a056a00218100b0044dc18d7af9mr22077648pfi.16.1635201717394; Mon, 25 Oct 2021 15:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635201717; cv=none; d=google.com; s=arc-20160816; b=RMMvOe82JBXkFVy/dOTrfwq6avEix61j4amn9MYwgOimX7AVta1sqaX3va7t8+Z0py HijD7Hp8mHlOhlGMFfQZME5zBoU4gJ7dqUY4FDAnkcsZdlR16I8rku/i65GQUkbjGVp9 fqsNHdBvqOho/SG7V7NgfmwOQJU0IGuDp53jSVESz39B0UUqBqei0N5SPLeBPCSwzJo/ UairOeqYwyvtXxNFRCYu1YgqzaxNnU8lQTbkCpEZ0gQcvaMmTp+3dS5BQMePAX3SCj8w WbP2DHurZeKYfOKg52kvBl2lPdwHD2gZNdk0hWZb8zJC7+00QGVpqCWcghETt2ny74zh 11qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VdKtMlHotUjEJQfzeTM2EwIp6sHQzMeQm/gym5Ze/YA=; b=RPKZmP7Phu1Z2R9aEByYEhgrcn86rWgVJgg6Jb+H2HFcrqw2WpGpc9ILT5kM7Jti1b ZZRE0YkoRY1giPmity568Le/o6JknJ8MBuzFCrOBAGj4bjhyHkaalHcmBzN2bDZbLPcY jkm9iVepSmApWx5e6nCPgbL1+hKhEFEZCjTJXPLswffb36ja3+HEVZ2kG5VRcfoJOJuA eBQKYW79pxlXr37BYopffqn+tyFAWOZ9wG83td2sigFP4V+OPIrAZ8yAO9zQgGkpT1uH v04bBU+Ehf2yFRzu+UEee+lABd8TzxFtWv5wu9105trVnv12tK1Q/pn5wCYs5o2/cV99 w41A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=18tGzMPz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j5si6710102plk.143.2021.10.25.15.41.44; Mon, 25 Oct 2021 15:41:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=18tGzMPz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235332AbhJYT1l (ORCPT + 99 others); Mon, 25 Oct 2021 15:27:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:43016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234878AbhJYTZ0 (ORCPT ); Mon, 25 Oct 2021 15:25:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 486366108B; Mon, 25 Oct 2021 19:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635189765; bh=qTL/thuFkDL43ARggOaRfeIFbZ/h+0f+5NaGoq5Ii90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=18tGzMPzUeOU3gScpmEowaIbsj4oEZtNK/BmysnaALaFtCx03+EOxzk88hppYfv2l TdQIIcGxv8cTkoT9/rI90CJ3GxZ7kuPUXVWmZKE+bbngDlltgWoYG2RDHQT5fpHnod CcvagPV/saiykJEmv52pBoPVuK1RVJ5MUCj8iNx0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haiyang Zhang , Ming Lei , John Garry , Dexuan Cui , "Martin K. Petersen" Subject: [PATCH 4.14 26/30] scsi: core: Fix shost->cmd_per_lun calculation in scsi_add_host_with_dma() Date: Mon, 25 Oct 2021 21:14:46 +0200 Message-Id: <20211025190928.633444809@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190922.089277904@linuxfoundation.org> References: <20211025190922.089277904@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui commit 50b6cb3516365cb69753b006be2b61c966b70588 upstream. After commit ea2f0f77538c ("scsi: core: Cap scsi_host cmd_per_lun at can_queue"), a 416-CPU VM running on Hyper-V hangs during boot because the hv_storvsc driver sets scsi_driver.can_queue to an integer value that exceeds SHRT_MAX, and hence scsi_add_host_with_dma() sets shost->cmd_per_lun to a negative "short" value. Use min_t(int, ...) to work around the issue. Link: https://lore.kernel.org/r/20211008043546.6006-1-decui@microsoft.com Fixes: ea2f0f77538c ("scsi: core: Cap scsi_host cmd_per_lun at can_queue") Cc: stable@vger.kernel.org Reviewed-by: Haiyang Zhang Reviewed-by: Ming Lei Reviewed-by: John Garry Signed-off-by: Dexuan Cui Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/hosts.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -213,7 +213,8 @@ int scsi_add_host_with_dma(struct Scsi_H goto fail; } - shost->cmd_per_lun = min_t(short, shost->cmd_per_lun, + /* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */ + shost->cmd_per_lun = min_t(int, shost->cmd_per_lun, shost->can_queue); error = scsi_init_sense_cache(shost);