* [PATCH v2] parport: do not re-enable interrupts in parport_claim()
@ 2026-11-18 7:58 Ziheng Wei
2026-11-18 8:09 ` Greg Kroah-Hartman
2026-11-18 8:11 ` Greg Kroah-Hartman
0 siblings, 2 replies; 5+ messages in thread
From: Ziheng Wei @ 2026-11-18 7:58 UTC (permalink / raw)
To: Sudip Mukherjee, Greg Kroah-Hartman; +Cc: linux-kernel, stable
When the claiming device was on the wait list, parport_claim() takes
it off the list with spin_lock_irq()/spin_unlock_irq() while it holds
cad_lock with interrupts disabled:
parport_claim()
|
| write_lock_irqsave(&port->cad_lock) <- IRQs off, cad_lock held
| spin_lock_irq(&port->waitlist_lock)
| spin_unlock_irq(&port->waitlist_lock) <- IRQs on too early
|
+---- port interrupt on this CPU ----+
| |
| v
| parport_irq_handler()
| read_lock(&port->cad_lock)
| spins forever: cad_lock is held
| by the code it interrupted
|
| write_unlock_irqrestore(&port->cad_lock) <- never reached
Interrupts are already disabled here, so use spin_lock()/spin_unlock(),
like the "blocked" path in the same function.
Found by LLM-assisted static analysis.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
Notes:
v2: shorter changelog; drop the kernel test robot tags.
The bug was found by the static analysis above. The kernel test robot
had sent a smatch warning for the same code to oe-kbuild only, which I
found afterwards and credited in v1:
https://lore.kernel.org/r/202608091622.jlJn0jOj-lkp@intel.com/
Tested in QEMU (parport_pc) with two ppdev users, one waiting in
PPCLAIM while the other releases the port: lockdep warns without this
patch and is quiet with it. I have no parallel port hardware.
On real hardware this needs two users of the same port and a port
interrupt within a few microseconds of the hand-over, so it is
unlikely to be hit; lockdep reports it whenever the path runs.
The changelog was drafted with an AI assistant and reviewed by me.
drivers/parport/share.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index eb0977ca1..d1b9f17d1 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -999,7 +999,7 @@ int parport_claim(struct pardevice *dev)
dev->waiting = 0;
/* Take ourselves out of the wait list again. */
- spin_lock_irq(&port->waitlist_lock);
+ spin_lock(&port->waitlist_lock);
if (dev->waitprev)
dev->waitprev->waitnext = dev->waitnext;
else
@@ -1008,7 +1008,7 @@ int parport_claim(struct pardevice *dev)
dev->waitnext->waitprev = dev->waitprev;
else
port->waittail = dev->waitprev;
- spin_unlock_irq(&port->waitlist_lock);
+ spin_unlock(&port->waitlist_lock);
dev->waitprev = dev->waitnext = NULL;
}
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] parport: do not re-enable interrupts in parport_claim()
2026-11-18 7:58 [PATCH v2] parport: do not re-enable interrupts in parport_claim() Ziheng Wei
@ 2026-11-18 8:09 ` Greg Kroah-Hartman
2026-11-18 8:11 ` Greg Kroah-Hartman
1 sibling, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-18 8:09 UTC (permalink / raw)
To: Ziheng Wei; +Cc: Sudip Mukherjee, linux-kernel, stable
On Wed, Nov 18, 2026 at 03:58:16PM +0800, Ziheng Wei wrote:
> When the claiming device was on the wait list, parport_claim() takes
> it off the list with spin_lock_irq()/spin_unlock_irq() while it holds
> cad_lock with interrupts disabled:
>
> parport_claim()
> |
> | write_lock_irqsave(&port->cad_lock) <- IRQs off, cad_lock held
> | spin_lock_irq(&port->waitlist_lock)
> | spin_unlock_irq(&port->waitlist_lock) <- IRQs on too early
> |
> +---- port interrupt on this CPU ----+
> | |
> | v
> | parport_irq_handler()
> | read_lock(&port->cad_lock)
> | spins forever: cad_lock is held
> | by the code it interrupted
> |
> | write_unlock_irqrestore(&port->cad_lock) <- never reached
>
> Interrupts are already disabled here, so use spin_lock()/spin_unlock(),
> like the "blocked" path in the same function.
>
> Found by LLM-assisted static analysis.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
So, this isn't a real issue given that no one has actually noticed it in
20+ years?
> Cc: stable@vger.kernel.org
> Signed-off-by: Ziheng Wei <zihengw03@163.com>
> ---
>
> Notes:
> v2: shorter changelog; drop the kernel test robot tags.
>
> The bug was found by the static analysis above. The kernel test robot
> had sent a smatch warning for the same code to oe-kbuild only, which I
> found afterwards and credited in v1:
> https://lore.kernel.org/r/202608091622.jlJn0jOj-lkp@intel.com/
>
> Tested in QEMU (parport_pc) with two ppdev users, one waiting in
> PPCLAIM while the other releases the port: lockdep warns without this
> patch and is quiet with it. I have no parallel port hardware.
Then maybe this isn't a real issue?
> On real hardware this needs two users of the same port and a port
> interrupt within a few microseconds of the hand-over, so it is
> unlikely to be hit; lockdep reports it whenever the path runs.
parport devices should not be used by 2 users at once. If you do so,
you get to keep the broken pieces :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] parport: do not re-enable interrupts in parport_claim()
2026-11-18 7:58 [PATCH v2] parport: do not re-enable interrupts in parport_claim() Ziheng Wei
2026-11-18 8:09 ` Greg Kroah-Hartman
@ 2026-11-18 8:11 ` Greg Kroah-Hartman
2026-11-18 8:48 ` Ziheng Wei
1 sibling, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-18 8:11 UTC (permalink / raw)
To: Ziheng Wei; +Cc: Sudip Mukherjee, linux-kernel, stable
Wait, your subject makes no sense.
On Wed, Nov 18, 2026 at 03:58:16PM +0800, Ziheng Wei wrote:
> When the claiming device was on the wait list, parport_claim() takes
> it off the list with spin_lock_irq()/spin_unlock_irq() while it holds
> cad_lock with interrupts disabled:
>
> parport_claim()
> |
> | write_lock_irqsave(&port->cad_lock) <- IRQs off, cad_lock held
> | spin_lock_irq(&port->waitlist_lock)
> | spin_unlock_irq(&port->waitlist_lock) <- IRQs on too early
but that's not why spin_lock/unlock_irq() is being called, it's because
this lock could be held _during_ an irq path, right?
Are you saying that this lock is never held in irq context?
> |
> +---- port interrupt on this CPU ----+
> | |
> | v
> | parport_irq_handler()
> | read_lock(&port->cad_lock)
> | spins forever: cad_lock is held
> | by the code it interrupted
> |
> | write_unlock_irqrestore(&port->cad_lock) <- never reached
Ok, but again, you have to look at the lock itself, is the
waitlist_lock() ever held in irq context?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] parport: do not re-enable interrupts in parport_claim()
2026-11-18 8:11 ` Greg Kroah-Hartman
@ 2026-11-18 8:48 ` Ziheng Wei
2026-11-18 9:25 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Ziheng Wei @ 2026-11-18 8:48 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Sudip Mukherjee, linux-kernel, stable
On Wed, Nov 18, 2026 at 09:11:37AM +0100, Greg Kroah-Hartman wrote:
> Are you saying that this lock is never held in irq context?
No, it can be taken in hardirq. One path is lp_console_write() ->
parport_release() -> parport_claim() for a waiting device, as the
console write callback may run in interrupt context.
The invariant that matters is that every user disables local
interrupts before taking waitlist_lock: parport_unregister_device()
uses spin_lock_irq(), and both wait list paths in parport_claim() run
under write_lock_irqsave(&port->cad_lock). Plain spin_lock() is
therefore safe there, even for a hardirq caller.
The old spin_unlock_irq() is the problem: it turns interrupts back on
while cad_lock is still write-held, and for a hardirq caller it does
so inside the interrupt handler. The "blocked" path in the same
function already uses plain spin_lock().
In your other mail you wrote:
> So, this isn't a real issue given that no one has actually noticed it
> in 20+ years?
...
> parport devices should not be used by 2 users at once. If you do so,
> you get to keep the broken pieces :)
Sorry, "two users" was unclear: I meant two parport drivers taking
turns through the wait list, not simultaneous use, which is what the
wait list is there for. The race is rare and was found by code
review, not from a user report. I still think the change is worth
having, as it is small and fixes the interrupt state, but I will leave
that decision to you. I am happy to drop it, or to resend with a
clearer subject and without the stable tag.
Thanks,
Ziheng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] parport: do not re-enable interrupts in parport_claim()
2026-11-18 8:48 ` Ziheng Wei
@ 2026-11-18 9:25 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-18 9:25 UTC (permalink / raw)
To: Ziheng Wei; +Cc: Sudip Mukherjee, linux-kernel, stable
On Wed, Nov 18, 2026 at 04:48:18PM +0800, Ziheng Wei wrote:
> On Wed, Nov 18, 2026 at 09:11:37AM +0100, Greg Kroah-Hartman wrote:
> > Are you saying that this lock is never held in irq context?
>
> No, it can be taken in hardirq. One path is lp_console_write() ->
> parport_release() -> parport_claim() for a waiting device, as the
> console write callback may run in interrupt context.
Then your change will break things?
> The invariant that matters is that every user disables local
> interrupts before taking waitlist_lock: parport_unregister_device()
> uses spin_lock_irq(), and both wait list paths in parport_claim() run
> under write_lock_irqsave(&port->cad_lock). Plain spin_lock() is
> therefore safe there, even for a hardirq caller.
That feels wrong, don't you think?
> The old spin_unlock_irq() is the problem: it turns interrupts back on
> while cad_lock is still write-held, and for a hardirq caller it does
> so inside the interrupt handler. The "blocked" path in the same
> function already uses plain spin_lock().
Ok, so the larger problem is that we have 2 locks where we should have
just one?
> In your other mail you wrote:
>
> > So, this isn't a real issue given that no one has actually noticed it
> > in 20+ years?
> ...
> > parport devices should not be used by 2 users at once. If you do so,
> > you get to keep the broken pieces :)
>
> Sorry, "two users" was unclear: I meant two parport drivers taking
> turns through the wait list, not simultaneous use, which is what the
> wait list is there for. The race is rare and was found by code
> review, not from a user report. I still think the change is worth
> having, as it is small and fixes the interrupt state, but I will leave
> that decision to you. I am happy to drop it, or to resend with a
> clearer subject and without the stable tag.
If no real user ever hits this (who has parport devices anymore?) then I
would not recomment changing this.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 9:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 7:58 [PATCH v2] parport: do not re-enable interrupts in parport_claim() Ziheng Wei
2026-11-18 8:09 ` Greg Kroah-Hartman
2026-11-18 8:11 ` Greg Kroah-Hartman
2026-11-18 8:48 ` Ziheng Wei
2026-11-18 9:25 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox