From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8AA238B12D; Sat, 17 Oct 2026 16:06:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792253183; cv=none; b=IeWauTgVBSIxwW0TvV4kxKJbD0zm1wvH7atyvnHhyMskvA+DOGAZqMhXO+tPVUdKPLh0tH7XfnVZayjOz0qQ4u8SOgyCEdqwiQ1+E+efaTJLY09N9UR/zkJ7UZmNul+8+HgkA1hN8Ad8q7kJWFSvmWcX/bhWO45YCGH8176D+oo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792253183; c=relaxed/simple; bh=alRRBwp5HA6ywkaof1RV3T3Rwb5GTFkONvO/tVzgZ50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jMM1bkIia07EcohABGJfj3XXfHmfJytzhnWpiyVV+E/CMVC/F92t18s1Jl1vRRDkRxnfVXh7y4xAEFpYX4h7kVHIS1+ObsjQG7rpUW/tzSAVkwJCv+7U7Ng6sqP6f8821OelCkpIA3KqSdX581/faz2wDw8uHBcLVV9DIC9Ju4k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xePlKMSC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xePlKMSC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10CA21F000C4; Sat, 17 Oct 2026 16:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792253182; bh=8fs/9ZTU0Y4y1WADi5xP7wQuO/pyKuB3rublpvk1MsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xePlKMSCF1VZYwQU5tM7BugRRKrSTCJY4pjYrSt+LdEomK7iBHEcGtcvXsWqXn2Hk 9Ee/9RhtNYqj86j86SwNks5zbmkKImittsqp1PnOFjNvQonTSQ0qEe8gfFJuhzCSSl JqG4R8A7jtRtH9D6xtput92h9VVYts950VnZyNPs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bart Van Assche , Stanley Jhu , Peter Wang , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 6.12 037/869] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ Date: Sat, 17 Oct 2026 17:47:58 +0200 Message-ID: <20261017160037.966124688@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160036.979869304@linuxfoundation.org> References: <20261017160036.979869304@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stanley Jhu [ Upstream commit 469fa055664bfd8717b087a80d59c03055789c17 ] In MCQ mode, ufshcd_mcq_compl_pending_transfer() uses blk_mq_tagset_busy_iter() to iterate over busy requests during error recovery and host reset. However, both iterator callbacks perform whole-queue operations redundantly for each visited request: - force_compl == true: ufshcd_mcq_force_compl_one() calls ufshcd_mcq_compl_all_cqes_lock() on every busy request, sweeping the entire completion ring (hwq->max_entries slots) once per active request under spin_lock_irqsave even though the first sweep already cleared all completion entries. - force_compl == false: ufshcd_mcq_compl_one() acquires cq_lock and polls CQTPy over MMIO via ufshcd_mcq_poll_cqe_lock() for every busy request without doing any per-request work. Sweep or poll each hardware queue (hba->uhq[i]) once at the start of ufshcd_mcq_compl_pending_transfer(). When force_compl is true, run blk_mq_tagset_busy_iter() afterward to complete residual in-flight requests with DID_REQUEUE, and remove the now-unused ufshcd_mcq_compl_one() callback. Fixes: ab248643d3d6 ("scsi: ufs: core: Add error handling for MCQ mode") Cc: stable@vger.kernel.org Reviewed-by: Bart Van Assche Signed-off-by: Stanley Jhu Reviewed-by: Peter Wang Link: https://patch.msgid.link/20260928035816.1294326-3-stanleyjhu@google.com Signed-off-by: Martin K. Petersen (Oracle) [ sashal: adapted blk_mq_tagset_busy_iter() callback changes to the existing tag-based completion loop ] Signed-off-by: Sasha Levin --- drivers/ufs/core/ufshcd.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 22f4f5f08e74a..9c2f407da28a1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5685,7 +5685,17 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, struct ufshcd_lrb *lrbp; struct scsi_cmnd *cmd; unsigned long flags; - int tag; + int tag, i; + + for (i = 0; i < hba->nr_hw_queues; i++) { + if (force_compl) + ufshcd_mcq_compl_all_cqes_lock(hba, &hba->uhq[i]); + else + ufshcd_mcq_poll_cqe_lock(hba, &hba->uhq[i]); + } + + if (!force_compl) + return; for (tag = 0; tag < hba->nutrs; tag++) { lrbp = &hba->lrb[tag]; @@ -5698,22 +5708,17 @@ static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, if (!hwq) continue; - if (force_compl) { - ufshcd_mcq_compl_all_cqes_lock(hba, hwq); - /* - * For those cmds of which the cqes are not present - * in the cq, complete them explicitly. - */ - spin_lock_irqsave(&hwq->cq_lock, flags); - if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { - set_host_byte(cmd, DID_REQUEUE); - ufshcd_release_scsi_cmd(hba, lrbp); - scsi_done(cmd); - } - spin_unlock_irqrestore(&hwq->cq_lock, flags); - } else { - ufshcd_mcq_poll_cqe_lock(hba, hwq); + /* + * For those cmds of which the cqes are not present + * in the cq, complete them explicitly. + */ + spin_lock_irqsave(&hwq->cq_lock, flags); + if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { + set_host_byte(cmd, DID_REQUEUE); + ufshcd_release_scsi_cmd(hba, lrbp); + scsi_done(cmd); } + spin_unlock_irqrestore(&hwq->cq_lock, flags); } } -- 2.53.0