Skip to contentSkip to conversation

scsi: ufs: Fix the polling implementation

PATCH Superseded Bart Van Assche 1 participant 2 messages Nov 14, 2022 – Nov 15, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

PATCH 1/1 scsi: ufs: Fix the polling implementation

Certain code in the block layer assumes that requests submitted on a polling queue (HCTX_TYPE_POLL) are completed in thread context. Hence this patch that modifies ufshcd_poll() such that only requests are completed for the hardware queue that is being examined instead of all hardware queues. The block layer code that makes this assumption is the bio caching code. From block/bio.c:

If REQ_ALLOC_CACHE is set, the final put of the bio MUST be done from process context, not hard/soft IRQ.

The REQ_ALLOC_CACHE flag is set for polled I/O (REQ_POLLED) since kernel v5.15. See also commit be4d234d7aeb ("bio: add allocation cache abstraction").

Fixes eaab9b573054 ("scsi: ufs: Implement polling support")
---
 drivers/ufs/core/ufshcd.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/ufs/core/ufshcd.c +13 -0
index 05925939af35..f80d09aea669 100644
@@ -5430,6 +5430,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
 	struct ufs_hba *hba = shost_priv(shost);
 	unsigned long completed_reqs, flags;
 	u32 tr_doorbell;
+	int tag;
 
 	spin_lock_irqsave(&hba->outstanding_lock, flags);
 	tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
@@ -5437,6 +5438,18 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
 	WARN_ONCE(completed_reqs & ~hba->outstanding_reqs,
 		  "completed: %#lx; outstanding: %#lx\n", completed_reqs,
 		  hba->outstanding_reqs);
+	for_each_set_bit(tag, &completed_reqs, hba->nutrs) {
+		struct ufshcd_lrb *lrbp = &hba->lrb[tag];
+
+		if (lrbp->cmd) {
+			struct request *rq = scsi_cmd_to_rq(lrbp->cmd);
+			u32 unique_tag = blk_mq_unique_tag(rq);
+			u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
+
+			if (hwq != queue_num)
+				__clear_bit(tag, &completed_reqs);
+		}
+	}
 	hba->outstanding_reqs &= ~completed_reqs;
 	spin_unlock_irqrestore(&hba->outstanding_lock, flags);
 
author reviewer
#1 lore raw
Quoted 7 lines · Bart Van Assche

Certain code in the block layer assumes that requests submitted on a polling queue (HCTX_TYPE_POLL) are completed in thread context. Hence this patch that modifies ufshcd_poll() such that only requests are completed for the hardware queue that is being examined instead of all hardware queues. The block layer code that makes this assumption is the bio caching code. From block/bio.c:

Quoted 6 lines

If REQ_ALLOC_CACHE is set, the final put of the bio MUST be done from process context, not hard/soft IRQ.

The REQ_ALLOC_CACHE flag is set for polled I/O (REQ_POLLED) since kernel v5.15. See also commit be4d234d7aeb ("bio: add allocation cache abstraction").

Please drop this patch - I plan to send an improved version later.

Bart.