drivers/memstick/core/memstick.c | 1 - drivers/memstick/host/rtsx_usb_ms.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
The existing memstick core patch: commit 62c59a8786e6 ("memstick: Skip
allocating card when removing host") sets host->removing in
memstick_remove_host(),but still exists a critical time window where
memstick_check can run after host->eject is set but before removing is set.
In the rtsx_usb_ms driver, the problematic sequence is:
rtsx_usb_ms_drv_remove: memstick_check:
host->eject = true
cancel_work_sync(handle_req) if(!host->removing)
... memstick_alloc_card()
memstick_set_rw_addr()
memstick_new_req()
rtsx_usb_ms_request()
if(!host->eject)
skip schedule_work
wait_for_completion()
memstick_remove_host: [blocks indefinitely]
host->removing = true
flush_workqueue()
[block]
1. rtsx_usb_ms_drv_remove sets host->eject = true
2. cancel_work_sync(&host->handle_req) runs
3. memstick_check work may be executed here <-- danger window
4. memstick_remove_host sets removing = 1
During this window (step 3), memstick_check calls memstick_alloc_card,
which may indefinitely waiting for mrq_complete completion that will
never occur because rtsx_usb_ms_request sees eject=true and skips
scheduling work, memstick_set_rw_addr waits forever for completion.
This causes a deadlock when memstick_remove_host tries to flush_workqueue,
waiting for memstick_check to complete, while memstick_check is blocked
waiting for mrq_complete completion.
Fix this by setting removing=true at the start of rtsx_usb_ms_drv_remove,
before any work cancellation. This ensures memstick_check will see the
removing flag immediately and exit early, avoiding the deadlock.
Fixes: 62c59a8786e6 ("memstick: Skip allocating card when removing host")
Signed-off-by: Jiayi Li <lijiayi@kylinos.cn>
---
drivers/memstick/core/memstick.c | 1 -
drivers/memstick/host/rtsx_usb_ms.c | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 043b9ec756ff..95e65f4958f2 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -555,7 +555,6 @@ EXPORT_SYMBOL(memstick_add_host);
*/
void memstick_remove_host(struct memstick_host *host)
{
- host->removing = 1;
flush_workqueue(workqueue);
mutex_lock(&host->lock);
if (host->card)
diff --git a/drivers/memstick/host/rtsx_usb_ms.c b/drivers/memstick/host/rtsx_usb_ms.c
index 3878136227e4..5b5e9354fb2e 100644
--- a/drivers/memstick/host/rtsx_usb_ms.c
+++ b/drivers/memstick/host/rtsx_usb_ms.c
@@ -812,6 +812,7 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev)
int err;
host->eject = true;
+ msh->removing = true;
cancel_work_sync(&host->handle_req);
cancel_delayed_work_sync(&host->poll_card);
--
2.47.1
On Fri, Aug 01, 2025 at 05:44:59PM +0800, Jiayi Li wrote: > The existing memstick core patch: commit 62c59a8786e6 ("memstick: Skip > allocating card when removing host") sets host->removing in > memstick_remove_host(),but still exists a critical time window where > memstick_check can run after host->eject is set but before removing is set. > > In the rtsx_usb_ms driver, the problematic sequence is: > > rtsx_usb_ms_drv_remove: memstick_check: > host->eject = true > cancel_work_sync(handle_req) if(!host->removing) > ... memstick_alloc_card() > memstick_set_rw_addr() > memstick_new_req() > rtsx_usb_ms_request() > if(!host->eject) > skip schedule_work > wait_for_completion() > memstick_remove_host: [blocks indefinitely] > host->removing = true > flush_workqueue() > [block] > > 1. rtsx_usb_ms_drv_remove sets host->eject = true > 2. cancel_work_sync(&host->handle_req) runs > 3. memstick_check work may be executed here <-- danger window > 4. memstick_remove_host sets removing = 1 > > During this window (step 3), memstick_check calls memstick_alloc_card, > which may indefinitely waiting for mrq_complete completion that will > never occur because rtsx_usb_ms_request sees eject=true and skips > scheduling work, memstick_set_rw_addr waits forever for completion. > > This causes a deadlock when memstick_remove_host tries to flush_workqueue, > waiting for memstick_check to complete, while memstick_check is blocked > waiting for mrq_complete completion. > > Fix this by setting removing=true at the start of rtsx_usb_ms_drv_remove, > before any work cancellation. This ensures memstick_check will see the > removing flag immediately and exit early, avoiding the deadlock. > > Fixes: 62c59a8786e6 ("memstick: Skip allocating card when removing host") > Signed-off-by: Jiayi Li <lijiayi@kylinos.cn> > --- > drivers/memstick/core/memstick.c | 1 - > drivers/memstick/host/rtsx_usb_ms.c | 1 + > 2 files changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c > index 043b9ec756ff..95e65f4958f2 100644 > --- a/drivers/memstick/core/memstick.c > +++ b/drivers/memstick/core/memstick.c > @@ -555,7 +555,6 @@ EXPORT_SYMBOL(memstick_add_host); > */ > void memstick_remove_host(struct memstick_host *host) > { > - host->removing = 1; > flush_workqueue(workqueue); > mutex_lock(&host->lock); > if (host->card) > diff --git a/drivers/memstick/host/rtsx_usb_ms.c b/drivers/memstick/host/rtsx_usb_ms.c > index 3878136227e4..5b5e9354fb2e 100644 > --- a/drivers/memstick/host/rtsx_usb_ms.c > +++ b/drivers/memstick/host/rtsx_usb_ms.c > @@ -812,6 +812,7 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev) > int err; > > host->eject = true; > + msh->removing = true; > cancel_work_sync(&host->handle_req); > cancel_delayed_work_sync(&host->poll_card); > > -- > 2.47.1 > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot
© 2016 - 2025 Red Hat, Inc.