Skip to contentSkip to conversation

Call scsi_host_busy() after the SCSI host has been added

PATCH Superseded Bart Van Assche 2 participants 7 messages Jan 7 – Jan 8

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

cover Call scsi_host_busy() after the SCSI host has been added

Hi Martin,

The UFS driver is the only SCSI driver I know of that may call scsi_host_busy() before the SCSI host has been added. Hence this patch series that modifies the UFS driver such that scsi_host_busy() is only called after the SCSI host has been added. Additionally, commit a0b7780602b1 ("scsi: core: Fix a regression triggered by scsi_host_busy()") is reverted because all scsi_host_busy() calls now happen after the corresponding SCSI host has been added.

Please consider this patch series for the next merge window.

Thanks,

Bart.

Bart Van Assche (2):
ufs: core: Only call scsi_host_busy() after the SCSI host has been
added
scsi: core: Revert "Fix a regression triggered by scsi_host_busy()"

 drivers/scsi/hosts.c      | 6 +++---
 drivers/ufs/core/ufshcd.c | 6 ++++--
 2 files changed, 7 insertions(+), 5 deletions(-)
author reviewer
#1 lore raw

PATCH 1/2 ufs: core: Only call scsi_host_busy() after the SCSI host has been added

scsi_host_busy() iterates over the host tag set. The host tag set is initialized by scsi_mq_setup_tags(). The latter function is called by scsi_add_host(). Hence only call scsi_host_busy() after the SCSI host has been added. This patch prepares for reverting commit a0b7780602b1 ("scsi: core: Fix a regression triggered by scsi_host_busy()").

---
 drivers/ufs/core/ufshcd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +4 -2
index 562d8cffc6f6..69630677b23f 100644
@@ -283,7 +283,8 @@ static bool ufshcd_has_pending_tasks(struct ufs_hba *hba)
 
 static bool ufshcd_is_ufs_dev_busy(struct ufs_hba *hba)
 {
-	return scsi_host_busy(hba->host) || ufshcd_has_pending_tasks(hba);
+	return (hba->scsi_host_added && scsi_host_busy(hba->host)) ||
+		ufshcd_has_pending_tasks(hba);
 }
 
 static const struct ufs_dev_quirk ufs_fixups[] = {
@@ -678,7 +679,8 @@ static void ufshcd_print_host_state(struct ufs_hba *hba)
 
 	dev_err(hba->dev, "UFS Host state=%d\n", hba->ufshcd_state);
 	dev_err(hba->dev, "%d outstanding reqs, tasks=0x%lx\n",
-		scsi_host_busy(hba->host), hba->outstanding_tasks);
+		hba->scsi_host_added ? scsi_host_busy(hba->host) : 0,
+		hba->outstanding_tasks);
 	dev_err(hba->dev, "saved_err=0x%x, saved_uic_err=0x%x\n",
 		hba->saved_err, hba->saved_uic_err);
 	dev_err(hba->dev, "Device power mode=%d, UIC link state=%d\n",
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ufs: core: Only call scsi_host_busy() after the SCSI host has been added

Quoted 7 lines · Bart Van Assche

scsi_host_busy() iterates over the host tag set. The host tag set is initialized by scsi_mq_setup_tags(). The latter function is called by scsi_add_host(). Hence only call scsi_host_busy() after the SCSI host has been added. This patch prepares for reverting commit a0b7780602b1 ("scsi: core: Fix a regression triggered by scsi_host_busy()").

author reviewer
#3 lore raw

PATCH 2/2 scsi: core: Revert "Fix a regression triggered by scsi_host_busy()"

In reply to Bart Van Assche

Revert commit a0b7780602b1 ("scsi: core: Fix a regression triggered by scsi_host_busy()") because all scsi_host_busy() calls now happen after the corresponding SCSI host has been added.

---
 drivers/scsi/hosts.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/hosts.c +3 -3
index 196479cbfe6e..f1dd71a2d89d 100644
@@ -626,9 +626,9 @@ int scsi_host_busy(struct Scsi_Host *shost)
 {
 	int cnt = 0;
 
-	if (shost->tag_set.ops)
-		blk_mq_tagset_busy_iter(&shost->tag_set,
-					scsi_host_check_in_flight, &cnt);
+	WARN_ON_ONCE(!shost->tag_set.ops);
+	blk_mq_tagset_busy_iter(&shost->tag_set,
+				scsi_host_check_in_flight, &cnt);
 	return cnt;
 }
 EXPORT_SYMBOL(scsi_host_busy);
#4 lore raw

Re: [PATCH 2/2] scsi: core: Revert "Fix a regression triggered by scsi_host_busy()"

Quoted 14 lines · Bart Van Assche

Revert commit a0b7780602b1 ("scsi: core: Fix a regression triggered by scsi_host_busy()") because all scsi_host_busy() calls now happen after the corresponding SCSI host has been added.

---
  drivers/scsi/hosts.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/hosts.c +0 -0
index 196479cbfe6e..f1dd71a2d89d 100644

drivers/scsi/hosts.c int scsi_host_busy(struct Scsi_Host *shost) · line 629

Quoted 7 lines
drivers/scsi/hosts.c +1 -3
@@ -626,9 +626,9 @@ int scsi_host_busy(struct Scsi_Host *shost)
  {
  	int cnt = 0;
 
-	if (shost->tag_set.ops)
-		blk_mq_tagset_busy_iter(&shost->tag_set,
-					scsi_host_check_in_flight, &cnt);
+	WARN_ON_ONCE(!shost->tag_set.ops);

If shost->tag_set.ops == NULL, then we will detect it like before, right? If so, I don't think that it is required.

Quoted 5 lines
drivers/scsi/hosts.c +2 -0
+	blk_mq_tagset_busy_iter(&shost->tag_set,
+				scsi_host_check_in_flight, &cnt);
  	return cnt;
  }
  EXPORT_SYMBOL(scsi_host_busy);
author reviewer
#5 lore raw

Re: [PATCH 2/2] scsi: core: Revert "Fix a regression triggered by scsi_host_busy()"

Quoted 10 lines · John Garry
Quoted 9 lines · Bart Van Assche

Revert commit a0b7780602b1 ("scsi: core: Fix a regression triggered by scsi_host_busy()") because all scsi_host_busy() calls now happen after the corresponding SCSI host has been added.

---
  drivers/scsi/hosts.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 13 lines

drivers/scsi/hosts.c int scsi_host_busy(struct Scsi_Host *shost) · line 628

Quoted 11 lines
drivers/scsi/hosts.c +1 -3
index 196479cbfe6e..f1dd71a2d89d 100644
@@ -626,9 +626,9 @@ int scsi_host_busy(struct Scsi_Host *shost)
   {
       int cnt = 0;
-    if (shost->tag_set.ops)
-        blk_mq_tagset_busy_iter(&shost->tag_set,
-                    scsi_host_check_in_flight, &cnt);
+    WARN_ON_ONCE(!shost->tag_set.ops);

If shost->tag_set.ops == NULL, then we will detect it like before, right? If so, I don't think that it is required.

There may be drivers left that I overlooked and that call scsi_host_busy() before the SCSI host has been added. Emitting a kernel warning is more user-friendly than letting users figure out why blk_mq_tagset_busy_iter() crashes.

Thanks,

Bart.

#6 lore raw

Re: [PATCH 2/2] scsi: core: Revert "Fix a regression triggered by scsi_host_busy()"

Quoted 15 lines · Bart Van Assche
Quoted 14 lines

drivers/scsi/hosts.c int scsi_host_busy(struct Scsi_Host *shost) · line 628

Quoted 12 lines
drivers/scsi/hosts.c +1 -3
index 196479cbfe6e..f1dd71a2d89d 100644
@@ -626,9 +626,9 @@ int scsi_host_busy(struct Scsi_Host *shost)
   {
       int cnt = 0;
-    if (shost->tag_set.ops)
-        blk_mq_tagset_busy_iter(&shost->tag_set,
-                    scsi_host_check_in_flight, &cnt);
+    WARN_ON_ONCE(!shost->tag_set.ops);

If shost->tag_set.ops == NULL, then we will detect it like before, right? If so, I don't think that it is required.

Quoted 4 lines

There may be drivers left that I overlooked and that call scsi_host_busy() before the SCSI host has been added. Emitting a kernel warning is more user-friendly than letting users figure out why blk_mq_tagset_busy_iter() crashes.

I bodged the code to create the crash, and got this stackframe:

[    0.471149] scsi_debug:sdebug_driver_probe: scsi_debug: trim
poll_queues to 0. poll_q/nr_hw = (0/1)
[    0.471965] BUG: unable to handle page fault for address: ffff8c36386ca000
[    0.472120] #PF: supervisor write access in kernel mode
...
[    0.472120] PKRU: 55555554
[    0.472120] Call Trace:
[    0.472120]  <TASK>
[    0.472120]  blk_mq_tagset_busy_iter+0x31/0xb0
[    0.472120]  scsi_host_busy+0x37/0x60
[    0.472120]  sdebug_driver_probe+0x3db/0x420

So not too difficult to know where the problem is being triggered. Furthermore, just checking !shost->tag_set.ops does not help so much in debugging. Better would be to add a message in the WARN, like "shost not added yet ...". Finally, having the WARN does not stop the crash, and just swamps the console.

Anyway, I would not bother with the WARN at all. I would just add a comment for scsi_host_busy() saying that the shost must be added before being called.

Thanks,
John