Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp767680pxb; Tue, 12 Apr 2022 12:57:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBRFyGVhiL9Tsm27Fjkr/jnl+pKvxQfkZt6LajeMkvD0ZPrMs2yQVJOzOo08Bknyhl3jXT X-Received: by 2002:a17:902:8ec9:b0:14f:11f7:db77 with SMTP id x9-20020a1709028ec900b0014f11f7db77mr39092630plo.136.1649793438518; Tue, 12 Apr 2022 12:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649793438; cv=none; d=google.com; s=arc-20160816; b=tuTwaH2sffaMIuZr5IsxkWG5lx/R+ccuOWbHwATsvDLEuMgOdnVgsJNFmvt044xYkz Idn+Z6yRjay2p/T9GzrFgNOeaCigfPwdDz8U90QPk2JI+UxjpKqNrw56x13QBQCYzYPh c60aSSf5FJFgDtpRU975CojOO9/DKtzk9SufVANE5XoHO76gzy+dMfVkHKyl8vdN0BSZ 8VA65a3JQNn1MgUy3Ifv4WR84gwZJEm8dlceeyH5FEMi1aScN5O3uPoy18/QfcV6qeVy zvUHV4ViBPqOTzA8ZDQbSeUQIME0CY3686HEoINJNIIGcAjY8C/VqWQE3pG213IQ0NX4 q3CA== 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=MLXGYQyElBh3WaLwrfLMswwpLx6NNK4sbshL7vJUo34=; b=oDMbYjetAxUvNYm3PQVzVWm/LbvbA+bmnLrg43e1IB0RxI/pqvT9sR19m6/k1sOBXB 18LLhb/AKd9fKtem3hPSHdbpSkxmEqOFri1RLBPHk7nFBVp4nD4w8JGsl3RfUA4VWTe6 h2cBg15RPCOERDSDXcxlsrVHEnelBGWNnD2Z0GjHByLQPJ0av6IOQ7xqfLXNZIoH1I6H V2XIIK4pTUkGGyDyoONwSxoGsBiM27rKBmlW3+2QSHtRttRkSUWkr1VxO+WyD7d/xL3a KmQ1FdXNDXxXwSLvw4JMosUqm1uiJ4QlX8fVwolk1uKlVJ35M+ZF8o0/2g0U0mAXmaF0 dc/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bLTrcL+N; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s10-20020a056a00194a00b00505ad6b7610si8752275pfk.63.2022.04.12.12.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 12:57:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bLTrcL+N; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D30870F6D; Tue, 12 Apr 2022 12:50:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354132AbiDLI0j (ORCPT + 99 others); Tue, 12 Apr 2022 04:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353669AbiDLHZv (ORCPT ); Tue, 12 Apr 2022 03:25:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82BBA10FDF; Tue, 12 Apr 2022 00:03:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1DE0F60B65; Tue, 12 Apr 2022 07:03:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26091C385A6; Tue, 12 Apr 2022 07:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649747000; bh=QoSKt1QfGOxXJk45hbuvdVdVfyISsG2D2JIrfiPHx8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bLTrcL+NZBjJjN6ZEWtXDRATb3CkF4O5+uGW7opb07UJp2qSjtmy1imTfWUJchNM4 VkjRFip49Um2/jTlZ95nybCy4binClzn3t1cuv59gatLlUR0ay2aVJZCHMvc08aVVH 6TQT1Nj+15hsNCE0JSfxi8/uDsQbKKuAEpIPlV88= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Ming Lei , Bart Van Assche , John Garry , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.16 157/285] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map() Date: Tue, 12 Apr 2022 08:30:14 +0200 Message-Id: <20220412062948.203087039@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062943.670770901@linuxfoundation.org> References: <20220412062943.670770901@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry [ Upstream commit eaba83b5b8506bbc9ee7ca2f10aeab3fff3719e7 ] In commit edb854a3680b ("scsi: core: Reallocate device's budget map on queue depth change"), the sbitmap for the device budget map may be reallocated after the slave device depth is configured. When the sbitmap is reallocated we use the result from scsi_device_max_queue_depth() for the sbitmap size, but don't resize to match the actual device queue depth. Fix by resizing the sbitmap after reallocating the budget sbitmap. We do this instead of init'ing the sbitmap to the device queue depth as the user may want to change the queue depth later via sysfs or other. Link: https://lore.kernel.org/r/1647423870-143867-1-git-send-email-john.garry@huawei.com Fixes: edb854a3680b ("scsi: core: Reallocate device's budget map on queue depth change") Tested-by: Damien Le Moal Reviewed-by: Ming Lei Reviewed-by: Bart Van Assche Signed-off-by: John Garry Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi_scan.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index d0ce723299bf..6bc0f5f511e1 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -223,6 +223,8 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev, int ret; struct sbitmap sb_backup; + depth = min_t(unsigned int, depth, scsi_device_max_queue_depth(sdev)); + /* * realloc if new shift is calculated, which is caused by setting * up one new default queue depth after calling ->slave_configure @@ -245,6 +247,9 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev, scsi_device_max_queue_depth(sdev), new_shift, GFP_KERNEL, sdev->request_queue->node, false, true); + if (!ret) + sbitmap_resize(&sdev->budget_map, depth); + if (need_free) { if (ret) sdev->budget_map = sb_backup; -- 2.35.1