Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp404637pxp; Wed, 16 Mar 2022 08:09:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0PijLOWV2ZIDKh7lbOVtZ0EH2e6L0jiRNaZBU1jNFHb38VU2YzubK+vOMyWFPVumIl4A7 X-Received: by 2002:a17:902:9b92:b0:153:99b1:1e94 with SMTP id y18-20020a1709029b9200b0015399b11e94mr183064plp.2.1647443376058; Wed, 16 Mar 2022 08:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647443376; cv=none; d=google.com; s=arc-20160816; b=T6OY+AF+q/Nh5VdBb9Yj6CZDsRgTukx1wKQWBZSSlF0v+fwG1smNpVx2SmHWUJxB6C v5OXCsQPrBJu63yCdCFDAi3zFLR/jyzlN9vB7XvLerpNz9fuk13/7BqdG7EX2Ka267jJ FU0RhX/Ndg7+2Y0TIeeeMUsGMPHST6U5CVay1XKa1Y2kze1EPCpLuqgb3ij5faiE+Bjf UbHWMoAyWd5f5NnEqLfxy0tY0JiMFavBeITT+70/Ha4YFJcLSENKuoF02qZA0m7WbxfN VNcDF6B8h55KE4CbIoJkbqM7IuunhYi1gcw9qRx+gCWVJMwg0z9uB3acFptEfHbaXMSC bxsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=XbA1+k5BWgNAe2noecnnNUrZrFJ3M84Ec5RROtiMJ0c=; b=RZIt4Hpf6Oba8GMvI+REDXSuZKy5jofuuaXAmduzXo+E9paCpdYxmP3Bwv73+tmVod l2MjLVqL0fTjmK73TGLX2k+0i2Uec/0y4Zt0S5x40DUTekr+XVgyIlR71MNTBfoDlO3E f3enzOD2QcJmNku6MaKXBnXkTkkBZvO9pV1ID+2+hbqx4ytTw+TyVOkkKf745WpfJ+vz UsGHYt3IjC9DiZaQfMpy44KO7XBRPdXa60dzckwBvc/W46IoT8F0NYjmu3lcZLokQcSh PmyTKViGuTa47dUmA6XIATMXkRIx3zSesxw2k69eVElbxtxCi8dRYEx/L07LI1ufQlyk MCEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a170902b94b00b0014f40ac475bsi1837878pls.387.2022.03.16.08.09.16; Wed, 16 Mar 2022 08:09:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354974AbiCPJvf (ORCPT + 99 others); Wed, 16 Mar 2022 05:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241720AbiCPJve (ORCPT ); Wed, 16 Mar 2022 05:51:34 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE701606D5; Wed, 16 Mar 2022 02:50:19 -0700 (PDT) Received: from fraeml702-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4KJQT84XtZz67MtS; Wed, 16 Mar 2022 17:48:44 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml702-chm.china.huawei.com (10.206.15.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Wed, 16 Mar 2022 10:50:17 +0100 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 16 Mar 2022 09:50:14 +0000 From: John Garry To: , CC: , , , , , , , , John Garry Subject: [PATCH v2] scsi: core: Fix sbitmap depth in scsi_realloc_sdev_budget_map() Date: Wed, 16 Mar 2022 17:44:30 +0800 Message-ID: <1647423870-143867-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. Fixes: edb854a3680b ("scsi: core: Reallocate device's budget map on queue depth change") Signed-off-by: John Garry Reviewed-by: Ming Lei --- Changes since v1 (apart from sending as a separate patch): - Add fixes and RB tag (thanks) - mention in commit message why we don't init sbitmap at queue depth diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index f4e6c68ac99e..2ef78083f1ef 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.26.2