Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1957477imn; Mon, 1 Aug 2022 06:17:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR5sYRj3oSnXzhvVc1/YJR3bFGH8OFpJ5lYHM2ELFW3Sjcc/L6+wxFPAgxQHjskdNixCTMmB X-Received: by 2002:a17:902:a516:b0:16d:4379:f34a with SMTP id s22-20020a170902a51600b0016d4379f34amr16298949plq.26.1659359848189; Mon, 01 Aug 2022 06:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659359848; cv=none; d=google.com; s=arc-20160816; b=xeYA1qVa+D7/TVe3Rct1klvYyl74+wNSL8Nf6/kI4MBOA9yqZvpOmjSH1M8UQ2JAyL O4dwUGf5PdiCGMIBXj0ACdV63P6O0bovnDeZNGci8g1o3VfFWkf3fx6F7IP7lUBQJUv4 UFqzlD1leojQJYN11XkQO9PoEiHN6fh6hzR7ybJfrIZy/I2Lj/+d5o9Be7SjqO9Z6MSm YsvjieI1yhLXQYH4xCLkDBOC6TbyDLsSLfADPgGJNVzyvmO72DxVmc1IZBaJkDNOVNI3 WGwDbdSsf34MeIW2r0n/y1tbYadp9fehky07OV8YXIp92dR012GTpnhXIeY3vU2N7scC I/4Q== 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=mqiQq1RHhwy1t6CzWXRAXShzHxmc2OgflOZBYDAUO2Q=; b=U9YYOLzbjAojKKWfP6ukQuj0326k0fY1TXIio5cKa+B/EVaPZTVSbagf0rbc0eIkbI g1QAI+UVdutPWwHAw8v7PjdMYqASDx3yOFqrWyiaocBC/MYNVFh8yvELxyPKhr3jHnCC dRU8sd53vlXVsOG3x57MRXYUfhdDc39XN38QPT7kArq+v6fQSiQHDrsHky4IV8KC4r7w 7HbcPOGXETuuqMb0j/YoR8jBo87LkgKQDY2eB/gjDdHyfzixugztb54sg7B9qhm9wWTb OcgDzH0ycv+xQLPcakvL4T4J+syfkpx5vaqnM8ZSe6LgbxoMrkKz90N6/sKYq5EZR57Z mhLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KMXQexf8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6391c8000000b0041bb39443d8si8630875pge.95.2022.08.01.06.17.13; Mon, 01 Aug 2022 06:17:28 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KMXQexf8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231880AbiHALwL (ORCPT + 99 others); Mon, 1 Aug 2022 07:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231859AbiHALvd (ORCPT ); Mon, 1 Aug 2022 07:51:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9FD3E77E; Mon, 1 Aug 2022 04:49:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 26F78B8116B; Mon, 1 Aug 2022 11:49:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 474BFC433D6; Mon, 1 Aug 2022 11:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354566; bh=vYtUgWJOtyovVyFdms+tN1lBrNToWs07uk+ePG6BBiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMXQexf8eWrclj8piMd3UjUfNR31rbM2WMkEDecaD9UQgwvKB8iPRWzI755Jrj239 oowqym1S/kef426lt7jPV48R01UtUIftG6mukKEMBmHNYNzwp/eEhETpiy3WSYANmH N8H/SMHhTfdEs/BhsLRkHC47DKBA4t7kjLRjsb3U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hannes Reinecke , Sumit Saxena , Kashyap Desai , Bart Van Assche , Ewan Milne , Long Li , John Garry , "chenxiang (M)" , Ming Lei , "Martin K. Petersen" , Yu Kuai Subject: [PATCH 5.4 34/34] scsi: core: Fix race between handling STS_RESOURCE and completion Date: Mon, 1 Aug 2022 13:47:14 +0200 Message-Id: <20220801114129.332434263@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114128.025615151@linuxfoundation.org> References: <20220801114128.025615151@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Ming Lei commit 673235f915318ced5d7ec4b2bfd8cb909e6a4a55 upstream. When queuing I/O request to LLD, STS_RESOURCE may be returned because: - Host is in recovery or blocked - Target queue throttling or target is blocked - LLD rejection In these scenarios BLK_STS_DEV_RESOURCE is returned to the block layer to avoid an unnecessary re-run of the queue. However, all of the requests queued to this SCSI device may complete immediately after reading 'sdev->device_busy' and BLK_STS_DEV_RESOURCE is returned to block layer. In that case the current I/O won't get a chance to get queued since it is invisible at that time for both scsi_run_queue_async() and blk-mq's RESTART. Fix the issue by not returning BLK_STS_DEV_RESOURCE in this situation. Link: https://lore.kernel.org/r/20201202100419.525144-1-ming.lei@redhat.com Fixes: 86ff7c2a80cd ("blk-mq: introduce BLK_STS_DEV_RESOURCE") Cc: Hannes Reinecke Cc: Sumit Saxena Cc: Kashyap Desai Cc: Bart Van Assche Cc: Ewan Milne Cc: Long Li Reported-by: John Garry Tested-by: "chenxiang (M)" Signed-off-by: Ming Lei Signed-off-by: Martin K. Petersen Signed-off-by: Yu Kuai Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/scsi_lib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1719,8 +1719,7 @@ out_put_budget: case BLK_STS_OK: break; case BLK_STS_RESOURCE: - if (atomic_read(&sdev->device_busy) || - scsi_device_blocked(sdev)) + if (scsi_device_blocked(sdev)) ret = BLK_STS_DEV_RESOURCE; break; default: