* [PATCH 1/1] scsi: Fix racing between dev init and dev reset
@ 2022-03-03 7:55 Alice Chao
2022-03-03 7:55 ` Alice Chao
0 siblings, 1 reply; 3+ messages in thread
From: Alice Chao @ 2022-03-03 7:55 UTC (permalink / raw)
To: jejb, martin.petersen, matthias.bgg, linux-scsi, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: stanley.chu, peter.wang, chun-hung.wu, alice.chao, jonathan.hsu,
powen.kao, cc.chou, chaotian.jing, jiajie.hao, qilin.tan,
lin.gui, yanxu.wei, wsd_upstream
Device reset thread uses kobject_uevent_env() to get kobj.parent
after scsi_evt_emit(), and it races with device init thread which
calls device_add() to create kobj.parent before kobject_uevent_env().
Device reset call trace:
fill_kobj_path
kobject_get_path
kobject_uevent_env
scsi_evt_emit <- add wait_event()
scsi_evt_thread
Device init call trace:
fill_kobj_path
kobject_get_path
kobject_uevent_env
device_add <- create kobj.parent
scsi_target_add
scsi_sysfs_add_sdev
scsi_add_lun
scsi_probe_and_add_lun
These two jobs are scheduled asynchronously, we can't guaranteed that
kobj.parent will be created in device init thread before device reset
thread calls kobj_get_path().
To resolve the racing issue between device init thread and device
reset thread, we use wait_event() in scsi_evt_emit() to wait for
device_add() to complete the creation of kobj.parent.
Signed-off-by: Alice Chao <alice.chao@mediatek.com>
---
drivers/scsi/scsi_lib.c | 1 +
drivers/scsi/scsi_scan.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 0a70aa763a96..abf9a71ed77c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2461,6 +2461,7 @@ static void scsi_evt_emit(struct scsi_device *sdev, struct scsi_event *evt)
break;
case SDEV_EVT_POWER_ON_RESET_OCCURRED:
envp[idx++] = "SDEV_UA=POWER_ON_RESET_OCCURRED";
+ wait_event(sdev->host->host_wait, sdev->sdev_gendev.kobj.parent != NULL);
break;
default:
/* do nothing */
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index f4e6c68ac99e..431f229ac435 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1904,6 +1904,7 @@ static void do_scsi_scan_host(struct Scsi_Host *shost)
} else {
scsi_scan_host_selected(shost, SCAN_WILD_CARD, SCAN_WILD_CARD,
SCAN_WILD_CARD, 0);
+ wake_up(&shost->host_wait);
}
}
--
2.18.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] scsi: Fix racing between dev init and dev reset
2022-03-03 7:55 [PATCH 1/1] scsi: Fix racing between dev init and dev reset Alice Chao
@ 2022-03-03 7:55 ` Alice Chao
2022-03-03 22:58 ` Miles Chen
0 siblings, 1 reply; 3+ messages in thread
From: Alice Chao @ 2022-03-03 7:55 UTC (permalink / raw)
To: jejb, martin.petersen, matthias.bgg, linux-scsi, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: stanley.chu, peter.wang, chun-hung.wu, alice.chao, jonathan.hsu,
powen.kao, cc.chou, chaotian.jing, jiajie.hao, qilin.tan,
lin.gui, yanxu.wei, wsd_upstream
Device reset thread uses kobject_uevent_env() to get kobj.parent
after scsi_evt_emit(), and it races with device init thread which
calls device_add() to create kobj.parent before kobject_uevent_env().
Device reset call trace:
fill_kobj_path
kobject_get_path
kobject_uevent_env
scsi_evt_emit <- add wait_event()
scsi_evt_thread
Device init call trace:
fill_kobj_path
kobject_get_path
kobject_uevent_env
device_add <- create kobj.parent
scsi_target_add
scsi_sysfs_add_sdev
scsi_add_lun
scsi_probe_and_add_lun
These two jobs are scheduled asynchronously, we can't guaranteed that
kobj.parent will be created in device init thread before device reset
thread calls kobj_get_path().
To resolve the racing issue between device init thread and device
reset thread, we use wait_event() in scsi_evt_emit() to wait for
device_add() to complete the creation of kobj.parent.
Signed-off-by: Alice Chao <alice.chao@mediatek.com>
Change-Id: I2848cf054186739d3a125a0635dbed5539557e64
---
drivers/scsi/scsi_lib.c | 1 +
drivers/scsi/scsi_scan.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 0a70aa763a96..abf9a71ed77c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2461,6 +2461,7 @@ static void scsi_evt_emit(struct scsi_device *sdev, struct scsi_event *evt)
break;
case SDEV_EVT_POWER_ON_RESET_OCCURRED:
envp[idx++] = "SDEV_UA=POWER_ON_RESET_OCCURRED";
+ wait_event(sdev->host->host_wait, sdev->sdev_gendev.kobj.parent != NULL);
break;
default:
/* do nothing */
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index f4e6c68ac99e..431f229ac435 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1904,6 +1904,7 @@ static void do_scsi_scan_host(struct Scsi_Host *shost)
} else {
scsi_scan_host_selected(shost, SCAN_WILD_CARD, SCAN_WILD_CARD,
SCAN_WILD_CARD, 0);
+ wake_up(&shost->host_wait);
}
}
--
2.18.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] scsi: Fix racing between dev init and dev reset
2022-03-03 7:55 ` Alice Chao
@ 2022-03-03 22:58 ` Miles Chen
0 siblings, 0 replies; 3+ messages in thread
From: Miles Chen @ 2022-03-03 22:58 UTC (permalink / raw)
To: alice.chao
Cc: cc.chou, chaotian.jing, chun-hung.wu, jejb, jiajie.hao,
jonathan.hsu, lin.gui, linux-arm-kernel, linux-kernel,
linux-mediatek, linux-scsi, martin.petersen, matthias.bgg,
peter.wang, powen.kao, qilin.tan, stanley.chu, wsd_upstream,
yanxu.wei
Hi Alice,
> Device reset thread uses kobject_uevent_env() to get kobj.parent
> after scsi_evt_emit(), and it races with device init thread which
> calls device_add() to create kobj.parent before kobject_uevent_env().
>
> Device reset call trace:
> fill_kobj_path
> kobject_get_path
> kobject_uevent_env
> scsi_evt_emit <- add wait_event()
> scsi_evt_thread
>
> Device init call trace:
> fill_kobj_path
> kobject_get_path
> kobject_uevent_env
> device_add <- create kobj.parent
> scsi_target_add
> scsi_sysfs_add_sdev
> scsi_add_lun
> scsi_probe_and_add_lun
>
> These two jobs are scheduled asynchronously, we can't guaranteed that
> kobj.parent will be created in device init thread before device reset
> thread calls kobj_get_path().
>
> To resolve the racing issue between device init thread and device
> reset thread, we use wait_event() in scsi_evt_emit() to wait for
> device_add() to complete the creation of kobj.parent.
>
> Signed-off-by: Alice Chao <alice.chao@mediatek.com>
> Change-Id: I2848cf054186739d3a125a0635dbed5539557e64
please remove Change-Id here
thanks,
Miles
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-03 22:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-03 7:55 [PATCH 1/1] scsi: Fix racing between dev init and dev reset Alice Chao
2022-03-03 7:55 ` Alice Chao
2022-03-03 22:58 ` Miles Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®