Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4143312pxb; Mon, 27 Sep 2021 10:15:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWkuKPHb5rCip5GPN/ExtLdJr5Nnm+MwC95QVonIDGe4GR7/83ya/QJSGnnUoQLQG8l+8k X-Received: by 2002:a62:1ad6:0:b0:440:3aef:46b7 with SMTP id a205-20020a621ad6000000b004403aef46b7mr767599pfa.86.1632762936550; Mon, 27 Sep 2021 10:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632762936; cv=none; d=google.com; s=arc-20160816; b=y7sCRo0NicIEa8sZrvvTHqi3jiAGYSxudkAWPjQigkKeyOUdgz078brDPI7VjgPaIg 2Jt5Q8DIWSfW11Z5r6gq4AXVJsSauL7efdV69FNysqvMi4pcTDmeHIXg6dMXYUGh2Zcw Qr+hTEjzuKCdtiGDUiyvsoBPN8yI4bOj2fuAsJWmfxa/+XJ3g5muv7ggLZLFZUB2pXlz 7FSyfBHEH/KvREEKQ6e9Wmb914RQBpS2uvRdPZ/aAGvhkxeZyKTt0he74EsKhhITM2Da 6i5vk8pAsFuQBVieZu8YpVjuO3Dr0djX5eVcKh0uqsH0yqc+t7mtyzV7SVhTIQzMebqK j3Wg== 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=5L8iLRwMC7NK0SZnEn00yWugpRyAtTOLkHmXWfAHg6o=; b=1BEX4CPKiTtBJrmPzS7b1tzK3p7Z998Xi/N6JL5xL5iaezvUJtxr9udz200JtzhX80 4+i05+tvVu1jYirk5gO2QiatQ7FH8JG6vmT7ehblv4p4jRHjJd3ibzjWGL9lBmf4tG+S keyDVNj1cU6IERnwZQD33JLPUOIlIB62qBOJV3oyQ1B1bahUF/BqkKTJPpd6Yv8lAve7 0KnJ27O+eFfJc8gpKc89krNKp/VOhO3jqvPzlP/8OmHvSn8iplmIbHbv/NlTPADI86lw 2v7QN0LaACSd1y8WBsXY+DUrPbkWdrkg2XXshCF3uzNLDOZ//XCR3Avt7jNF5RlmFDFa WtNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r9u6wGdl; 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 ke3si110579pjb.99.2021.09.27.10.15.23; Mon, 27 Sep 2021 10:15:36 -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=r9u6wGdl; 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 S236592AbhI0RQN (ORCPT + 99 others); Mon, 27 Sep 2021 13:16:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:56622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237097AbhI0RNy (ORCPT ); Mon, 27 Sep 2021 13:13:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 251E461359; Mon, 27 Sep 2021 17:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762577; bh=90F7pgzjpGfA4Ynkzh6hB7JZRZI6X9FSvMKkP8xolWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r9u6wGdllJ66FxdBv8xuJyEIKYhXa9clXT4T4fctrRZE5TvYAjUxYDuVwj1jkiqRw xTHL09Mv5QGL3YG2asv1rhR2d37ulUDksf/cZFftm0RK7n2snX3DRqTOZBRABelPct CAiir+jyJ7lTKMykCYn2CbFIal7LR3Cpk3qn4zoM= 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.10 076/103] blk-mq: avoid to iterate over stale request Date: Mon, 27 Sep 2021 19:02:48 +0200 Message-Id: <20210927170228.399680974@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170225.702078779@linuxfoundation.org> References: <20210927170225.702078779@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 c4f2f6c123ae..16ad9e656610 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -207,7 +207,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