Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4155139pxb; Mon, 27 Sep 2021 10:30:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA8oU6ho6APHrsrtd1HlxMPdtOSGTMMLE6NLdEf0b66CrcRhx6sauxNrY6ULRU/ZQZTIo/ X-Received: by 2002:a17:90a:1a02:: with SMTP id 2mr322086pjk.6.1632763838680; Mon, 27 Sep 2021 10:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632763838; cv=none; d=google.com; s=arc-20160816; b=KrG0sEcLjVn5SWzmvexx8JitnYWJiPrmQlK5SS1lrLOS+J2LH5dwIvfB87b77r66oo Ac9CjdEZCuD7EYthw1akeYV/ZTJFo+NFeDD0D8o/sImRNtfqhdRCv0WrkZQaOaEC7VTO qoEFh24iUb30ogFHr0ajjlL7AY2+4z7Nphsei0jFQ1RAEBh4ICfoC/j/vGHe8ofD0A0S z0fLJYDmjRIoxP0WNRvACfLx4ajAdmvOfmzDiALsky7en2Mgz7otURKKJ5gkj/PixjC7 qa/PyssEgNSgoEPCmak40Hcv0dGVrSfrPojuaBSC1ekO8RTGp+qdVKHlVZtjpvM9cr3t tlqg== 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=kGI/q/m6ZhZ6+QL4pmdcc2baQvWVfggLQTFIps+/xKg=; b=Wa/pV1hhztQXVFm9mViFS0KbDfe7DS4pqn3fGAzw+Xy9qCfD3JhIG2WTDL5xH8vctG TnOIzxkr3s0loWUSv0hEz7kq6Xt7CaOn8wV2kG8ysH5Wh0dpkgCdYoQAHwiYn6w/XqBS /4HCBmV1PY0it45Ns6aWDQq0Y3Su9Rr4Sx8+BLJIGW1CDsHehCF4+cEVrW2+Nk9QFLJp /HcuXVeDeLqDaYFIe4W38gFormJ865SxZ7UXA5Q90cRTQt76JGeA+PDywVVLXZc1TGYF pLAqsIXxnxYWai7g87kw8BJxak6PW7fUK0sTrsbZgTSvv+6kLEBEjMrQvoBJdOi+DL1s 756A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fcUqNdN5; 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 d6si21381503pgm.332.2021.09.27.10.30.21; Mon, 27 Sep 2021 10:30:38 -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=fcUqNdN5; 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 S237486AbhI0RbN (ORCPT + 99 others); Mon, 27 Sep 2021 13:31:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:43622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238105AbhI0R0E (ORCPT ); Mon, 27 Sep 2021 13:26:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32D19611C7; Mon, 27 Sep 2021 17:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762976; bh=YwW3Vl+aWLWc/1UTMI7y3brIlWl/0Pf8DMSaAiBM3ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fcUqNdN5pm3YrdI1K7m+jj0Lla3h1Z2n/aTc3N6Lr0BR/TyFLYe8cMAG/zpG3U+T6 dC5KcSVuf/BWmBFhKzn8sLswrMgiqCBBK9aIPS56hBbBEaebaUxG2/qwsbIWTxgson FuORMh3HW7pNH1gDVpMolPrl2imG4D+0eTstvN6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K. Petersen" , luojiaxing , Ming Lei , Jens Axboe , Sasha Levin Subject: [PATCH 5.14 120/162] blk-mq: avoid to iterate over stale request Date: Mon, 27 Sep 2021 19:02:46 +0200 Message-Id: <20210927170237.603016788@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170233.453060397@linuxfoundation.org> References: <20210927170233.453060397@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: Ming Lei [ Upstream commit 67f3b2f822b7e71cfc9b42dbd9f3144fa2933e0b ] blk-mq can't run allocating driver tag and updating ->rqs[tag] atomically, meantime blk-mq doesn't clear ->rqs[tag] after the driver tag is released. So there is chance to iterating over one stale request just after the tag is allocated and before updating ->rqs[tag]. scsi_host_busy_iter() calls scsi_host_check_in_flight() to count scsi in-flight requests after scsi host is blocked, so no new scsi command can be marked as SCMD_STATE_INFLIGHT. However, driver tag allocation still can be run by blk-mq core. One request is marked as SCMD_STATE_INFLIGHT, but this request may have been kept in another slot of ->rqs[], meantime the slot can be allocated out but ->rqs[] isn't updated yet. Then this in-flight request is counted twice as SCMD_STATE_INFLIGHT. This way causes trouble in handling scsi error. Fixes the issue by not iterating over stale request. Cc: linux-scsi@vger.kernel.org Cc: "Martin K. Petersen" Reported-by: luojiaxing Signed-off-by: Ming Lei Link: https://lore.kernel.org/r/20210906065003.439019-1-ming.lei@redhat.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-mq-tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index 86f87346232a..ff5caeb82542 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -208,7 +208,7 @@ static struct request *blk_mq_find_and_get_req(struct blk_mq_tags *tags, spin_lock_irqsave(&tags->lock, flags); rq = tags->rqs[bitnr]; - if (!rq || !refcount_inc_not_zero(&rq->ref)) + if (!rq || rq->tag != bitnr || !refcount_inc_not_zero(&rq->ref)) rq = NULL; spin_unlock_irqrestore(&tags->lock, flags); return rq; -- 2.33.0