Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1633309rwd; Mon, 15 May 2023 00:18:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mx0TM1d978/y3E2yScuZn/LKx7gdL/JBfqqA43uBhDPfSFfxiP4oU3kqQJhCGj7SF0dps X-Received: by 2002:a05:6a00:1703:b0:644:c365:50d5 with SMTP id h3-20020a056a00170300b00644c36550d5mr40580266pfc.6.1684135084417; Mon, 15 May 2023 00:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684135084; cv=none; d=google.com; s=arc-20160816; b=G0az8EFzypcUZ/6eKklWFp3aHJE12pssCz93/C1bE0Jqs9G/iuoZsBu1Wgu6r8iNeU pJlZcQN4FD81tGBZgGtl6U9OcC4p7otMJYqUn0Jr1ngCt1MM24mEeo6FmKnFKTCzsEkR ij2bTFMAgYuuyS6kyk7IpCRHaZuY2Y107oCq/iuBqJ7K0rIyfUFzSKOmCyGjlBFF+s06 BMVx1OQQeZoFvg7lIGnIzU25qqTfmnYT37hJcvmVI23btfruNAfTqIyBSQL+2L48BIbh XCFiLzDXlTg7+qnb3vMBFqUmnkfWGomv23c+0sMaXTciPuLXuwbpwflAwcd7HZ6CyApM g2Rg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=w7ItN863d/AT2HHuhBYIWX9tW505qk6o+bc2NSJbcs8=; b=e9ShSCJ8ZP+4gi2EA224WpU64+u4y61LGUqct2Nlk2c7jpRVAN4CdEnUxFCb37GNzc IlgYLHjjQgREC3g3vHs36zrIV3dtTuPAoEyl+crbQJRWgfxCZDSJmwdb8DQaTFa3ul7G X2cPvAvkvCuwN5NXrmvBKvDlJYJNJZPpkVjJnZjM4RDR94myBgNORkvNf3gHOCRQz52S QQj8eGnNuaWLvLVNnq3HUmNqoZjrzh/9Bn4wck+F7zlQwH3TZiR4q/iHFRCQfvofPPTg QxKNvgIM3xNoIo/vppJbOIJWyjzC/TBJ9vlKSI2WMHPlt+0mPYziIMQERHnB1DqE5TU5 2iFg== 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 d2-20020a633602000000b0050bfa82c23bsi14922068pga.230.2023.05.15.00.17.52; Mon, 15 May 2023 00:18:04 -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 S240414AbjEOHC0 (ORCPT + 99 others); Mon, 15 May 2023 03:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239651AbjEOHCQ (ORCPT ); Mon, 15 May 2023 03:02:16 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F66E12B; Mon, 15 May 2023 00:02:14 -0700 (PDT) Received: from kwepemm600012.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QKVYs02dJzqSJx; Mon, 15 May 2023 14:57:52 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 15 May 2023 15:02:10 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Ming Lei , , CC: , , Wenchao Hao Subject: [PATCH 1/2] Revert "scsi: core: Do not increase scsi_device's iorequest_cnt if dispatch failed" Date: Mon, 15 May 2023 15:01:55 +0800 Message-ID: <20230515070156.1790181-2-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230515070156.1790181-1-haowenchao2@huawei.com> References: <20230515070156.1790181-1-haowenchao2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600012.china.huawei.com (7.193.23.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 the "atomic_inc(&cmd->device->iorequest_cnt)" in scsi_queue_rq() would causes kernel panic, because cmd->device may be freed after returning from scsi_dispatch_cmd(). This reverts commit cfee29ffb45b1c9798011b19d454637d1b0fe87d. Signed-off-by: Wenchao Hao Reported-by: Ming Lei Closes:https://lore.kernel.org/linux-scsi/8e0f2d31-e6ff-ec4a-3974-450560ad49c5@huawei.com/T/#t --- drivers/scsi/scsi_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index b7c569a42aa4..03964b26f3f2 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1463,6 +1463,8 @@ static int scsi_dispatch_cmd(struct scsi_cmnd *cmd) struct Scsi_Host *host = cmd->device->host; int rtn = 0; + atomic_inc(&cmd->device->iorequest_cnt); + /* check if the device is still usable */ if (unlikely(cmd->device->sdev_state == SDEV_DEL)) { /* in SDEV_DEL we error all commands. DID_NO_CONNECT @@ -1761,7 +1763,6 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, goto out_dec_host_busy; } - atomic_inc(&cmd->device->iorequest_cnt); return BLK_STS_OK; out_dec_host_busy: -- 2.32.0