mmc: vub300: fix sleeping function call from invalid context in vub300_inactivity_timer_expired
PATCH 1/1 mmc: vub300: fix sleeping function call from invalid context in vub300_inactivity_timer_expired
Currently, the function vub300_inactivity_timer_expired, which gets called in a softirq context, calls a sleeping function in the following call chain:
vub300_inactivity_timer_expired -> kref_put -> vub300_delete -> mmc_free_host -> cancel_delayed_work_sync -> __cancel_work_sync -> might_sleep -> BUG
Fix this by replacing kref_put(&vub300->kref, vub300_delete) with vub300_queue_dead_work(vub300), which does the same thing, but in a workqueue context.
--- drivers/mmc/host/vub300.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/vub300.c +1 -1
@@ -744,7 +744,7 @@ static void vub300_inactivity_timer_expired(struct timer_list *t)struct vub300_mmc_host *vub300 =timer_container_of (vub300, t, inactivity_timer);if (!vub300->interface) { -kref_put (&vub300->kref, vub300_delete); +vub300_queue_dead_work (vub300); }else if (vub300->cmd) {mod_timer (&vub300->inactivity_timer, jiffies +HZ ); }else {
Signature · 1 line
2.55.0
[ +CC: Geert ]
Quoted 8 lines · Jakov Novak
Currently, the function
vub300_inactivity_timer_expired, which gets called in a softirq context, calls a sleeping function in the following call chain:
vub300_inactivity_timer_expired->kref_put->vub300_delete->mmc_free_host->cancel_delayed_work_sync->__cancel_work_sync->might_sleep-> BUG
Quoted 5 lines
Fix this by replacing
kref_put(&vub300->kref, vub300_delete)withvub300_queue_dead_work(vub300), which does the same thing, but in a workqueue context.Fixes 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")
This isn't the commit that introduced the issue. The blocking call in mmc_free_host() was added by commit 1036f69e2513 ("mmc: core: Cancel delayed work before releasing host") in 2023.
I didn't look at this in any detail, but having that call in mmc_free_host() (e.g. rather than in mmc_remove_host()) looks wrong so perhaps the fix really lies in MMC core.
Quoted 1 line
Reported-and-tested-by [email protected]
Not sure if syzbot has started suggesting this tag, but this should be two separate tags.
Quoted 11 lines
Signed-off-by Jakov Novak <[email protected]>--- drivers/mmc/host/vub300.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mmc/host/vub300.c +0
-0
drivers/mmc/host/vub300.c static void vub300_inactivity_timer_expired(struct timer_list *t) · line 750
Quoted 8 lines
drivers/mmc/host/vub300.c +1
-1@@ -744,7 +744,7 @@ static void vub300_inactivity_timer_expired(struct timer_list *t)struct vub300_mmc_host *vub300 =timer_container_of (vub300, t, inactivity_timer);if (!vub300->interface) { -kref_put (&vub300->kref, vub300_delete); +vub300_queue_dead_work (vub300); }else if (vub300->cmd) {mod_timer (&vub300->inactivity_timer, jiffies +HZ ); }else {
Johan
Quoted 3 lines · Johan Hovold
I didn't look at this in any detail, but having that call in
mmc_free_host()(e.g. rather than inmmc_remove_host()) looks wrong so perhaps the fix really lies in MMC core.
syzbot has an AI-generated patch at
https://lkml.kernel.org/r/[email protected] .
Please check.
Quoted 4 lines
syzbot has an AI-generated patch at
https://lkml.kernel.org/r/[email protected] .Please check.
I checked the AI-generated patch and it just uses the deadworkqueue in a new function. That is the same thing I am doing except that I'm using the vub300_queue_dead_work function instead of writing some new code that does the same thing.
The real question is whether mmc_free_host should be allowed to invoke the sleep function or not. Geert needs to elaborate on that since he added this change in 1036f69e2513 ("mmc: core: Cancel delayed work before releasing host").
Hi Jakov,
Quoted 9 lines · Jakov Novak
Quoted 4 lines
syzbot has an AI-generated patch at
https://lkml.kernel.org/r/[email protected] .Please check.
I checked the AI-generated patch and it just uses the deadworkqueue in a new function. That is the same thing I am doing except that I'm using the
vub300_queue_dead_workfunction instead of writing some new code that does the same thing.
Quoted 4 lines
The real question is whether
mmc_free_hostshould be allowed to invoke the sleep function or not. Geert needs to elaborate on that since he added this change in1036f69e2513("mmc: core: Cancel delayed work before releasing host").
Why would this not be allowed?
This is just in the driver remove or probe error path.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Johan,
Quoted 15 lines · Johan Hovold
Quoted 8 lines · Jakov Novak
Currently, the function
vub300_inactivity_timer_expired, which gets called in a softirq context, calls a sleeping function in the following call chain:
vub300_inactivity_timer_expired->kref_put->vub300_delete->mmc_free_host->cancel_delayed_work_sync->__cancel_work_sync->might_sleep-> BUGQuoted 5 lines
Fix this by replacing
kref_put(&vub300->kref, vub300_delete)withvub300_queue_dead_work(vub300), which does the same thing, but in a workqueue context.Fixes 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")
Quoted 7 lines
This isn't the commit that introduced the issue. The blocking call in
mmc_free_host()was added by commit1036f69e2513("mmc: core: Cancel delayed work before releasing host") in 2023.I didn't look at this in any detail, but having that call in
mmc_free_host()(e.g. rather than inmmc_remove_host()) looks wrong so perhaps the fix really lies in MMC core.
mmc_remove_host() can only be called after a sucessful probe, while commit 1036f69e2513 fixed an issue where the last probe step failed with -EPROBE_DEFER.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Geert,
Quoted 22 lines · Geert Uytterhoeven
Hi Johan,
Quoted 19 lines · Johan Hovold
Quoted 8 lines · Jakov Novak
Currently, the function
vub300_inactivity_timer_expired, which gets called in a softirq context, calls a sleeping function in the following call chain:
vub300_inactivity_timer_expired->kref_put->vub300_delete->mmc_free_host->cancel_delayed_work_sync->__cancel_work_sync->might_sleep-> BUGQuoted 5 lines
Fix this by replacing
kref_put(&vub300->kref, vub300_delete)withvub300_queue_dead_work(vub300), which does the same thing, but in a workqueue context.Fixes 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")This isn't the commit that introduced the issue. The blocking call in
mmc_free_host()was added by commit1036f69e2513("mmc: core: Cancel delayed work before releasing host") in 2023.
Quoted 7 lines
Quoted 3 lines
I didn't look at this in any detail, but having that call in
mmc_free_host()(e.g. rather than inmmc_remove_host()) looks wrong so perhaps the fix really lies in MMC core.
mmc_remove_host()can only be called after a sucessful probe, while commit1036f69e2513fixed an issue where the last probe step failed with -EPROBE_DEFER.
Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
Johan
Hi Johan,
Quoted 25 lines · Johan Hovold
Quoted 24 lines · Geert Uytterhoeven
Quoted 22 lines · Johan Hovold
Quoted 8 lines · Jakov Novak
Currently, the function
vub300_inactivity_timer_expired, which gets called in a softirq context, calls a sleeping function in the following call chain:
vub300_inactivity_timer_expired->kref_put->vub300_delete->mmc_free_host->cancel_delayed_work_sync->__cancel_work_sync->might_sleep-> BUGQuoted 5 lines
Fix this by replacing
kref_put(&vub300->kref, vub300_delete)withvub300_queue_dead_work(vub300), which does the same thing, but in a workqueue context.Fixes 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")This isn't the commit that introduced the issue. The blocking call in
mmc_free_host()was added by commit1036f69e2513("mmc: core: Cancel delayed work before releasing host") in 2023.I didn't look at this in any detail, but having that call in
mmc_free_host()(e.g. rather than inmmc_remove_host()) looks wrong so perhaps the fix really lies in MMC core.
Quoted 6 lines
Quoted 3 lines
mmc_remove_host()can only be called after a sucessful probe, while commit1036f69e2513fixed an issue where the last probe step failed with -EPROBE_DEFER.Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
I would like to defer that question to the TMIO experts.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 28 lines · Geert Uytterhoeven
Hi Johan,
Quoted 25 lines · Johan Hovold
Quoted 24 lines · Geert Uytterhoeven
Quoted 22 lines · Johan Hovold
Quoted 8 lines · Jakov Novak
Currently, the function
vub300_inactivity_timer_expired, which gets called in a softirq context, calls a sleeping function in the following call chain:
vub300_inactivity_timer_expired->kref_put->vub300_delete->mmc_free_host->cancel_delayed_work_sync->__cancel_work_sync->might_sleep-> BUGQuoted 5 lines
Fix this by replacing
kref_put(&vub300->kref, vub300_delete)withvub300_queue_dead_work(vub300), which does the same thing, but in a workqueue context.Fixes 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")This isn't the commit that introduced the issue. The blocking call in
mmc_free_host()was added by commit1036f69e2513("mmc: core: Cancel delayed work before releasing host") in 2023.I didn't look at this in any detail, but having that call in
mmc_free_host()(e.g. rather than inmmc_remove_host()) looks wrong so perhaps the fix really lies in MMC core.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
mmc_remove_host()can only be called after a sucessful probe, while commit1036f69e2513fixed an issue where the last probe step failed with -EPROBE_DEFER.Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
I would like to defer that question to the TMIO experts.
Are they on CC?
Ulf, perhaps you can take a look at this? It seems wrong to enable interrupts and trigger rescans before the host controller has been set up and registered.
Johan
Hi Johan,
Quoted 8 lines · Johan Hovold
Quoted 5 lines · Geert Uytterhoeven
Quoted 2 lines · Johan Hovold
Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
I would like to defer that question to the TMIO experts.
Are they on CC?
Ulf was from the beginning; I had added Wolfram in my previous email.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 11 lines · Geert Uytterhoeven
Quoted 8 lines · Johan Hovold
Quoted 5 lines · Geert Uytterhoeven
Quoted 2 lines · Johan Hovold
Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
I would like to defer that question to the TMIO experts.
Are they on CC?
Ulf was from the beginning; I had added Wolfram in my previous email.
Thanks for clarifying.
Johan
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
I would like to defer that question to the TMIO experts.
From a high level view, independently of TMIO/SDHI...
Quoted 5 lines
Are they on CC?
Ulf, perhaps you can take a look at this? It seems wrong to enable interrupts and trigger rescans before the host controller has been set up and registered.
... it is always a good practice to enable irqs only when the device is fully set up. From a glimpse, this seems to be the case here as well.
It needs serious testing, though. SDHI is a complex, organically grown mass of code. There might be subtle side effects. It should still be worth it IMO. I can put it on my todo list, but no promises...
Quoted 14 lines · Wolfram Sang
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Sure, but should you be scheduling rescan work before all resources have been set up and the host has been registered?
I would like to defer that question to the TMIO experts.
From a high level view, independently of TMIO/SDHI...
Quoted 5 lines
Are they on CC?
Ulf, perhaps you can take a look at this? It seems wrong to enable interrupts and trigger rescans before the host controller has been set up and registered.
Quoted 6 lines
... it is always a good practice to enable irqs only when the device is fully set up. From a glimpse, this seems to be the case here as well.
It needs serious testing, though. SDHI is a complex, organically grown mass of code. There might be subtle side effects. It should still be worth it IMO. I can put it on my todo list, but no promises...
Thanks for taking a look. I guess we should fix this inconsistency in MMC core eventually, but that the vub300 needs to be reworked to handle this quirk in the mean time.
If only to stop the flood of LLM generated fixes to the syzbot report...
Johan
Hi Johan,
Quoted 3 lines
Thanks for taking a look. I guess we should fix this inconsistency in MMC core eventually, but that the vub300 needs to be reworked to handle this quirk in the mean time.
Should I send a v2 based on my first patch with the Reported-by, Tested-by and Fixes tags fixed or is there something else I missed?
Best,
Jakov
Quoted 6 lines · Jakov Novak
Quoted 3 lines
Thanks for taking a look. I guess we should fix this inconsistency in MMC core eventually, but that the vub300 needs to be reworked to handle this quirk in the mean time.
Should I send a v2 based on my first patch with the Reported-by, Tested-by and Fixes tags fixed or is there something else I missed?
It seems we don't need to worry about this driver anymore:
https://lore.kernel.org/lkml/[email protected]/
Johan