[PATCH] parport: do not re-enable interrupts in parport_claim()

From: Ziheng Wei

Date: Mon Nov 16 2026 - 08:10:02 EST


parport_claim() takes port->cad_lock with write_lock_irqsave() and holds
it until the end of the function. When the device that gets the port
was queued on the wait list (sleeping in parport_claim_or_block(), or
having a wakeup callback), parport_claim() takes it off the list under
port->waitlist_lock using spin_lock_irq() and spin_unlock_irq(). This
usually runs in the context of the previous owner, when
parport_release() hands the port over. spin_unlock_irq() enables local
interrupts unconditionally, so the rest of the cad_lock section (setting
port->cad, daisy chain selection and ->restore_state()) runs with
interrupts enabled while cad_lock is held for writing.

parport_irq_handler() takes read_lock(&port->cad_lock) for every
interrupt on the port's line, including shared PCI INTx lines, since
parport_pc and parport_serial request the IRQ with IRQF_SHARED. If
such an interrupt arrives on the same CPU inside that window, the
handler spins on the lock held by the code it interrupted and the CPU
locks up. The early unlock also turns interrupts back on behind the
back of callers that hold their own spinlock with interrupts disabled,
such as imm_wakeup()/imm_pb_claim() and ppa_wakeup()/ppa_pb_claim(),
which call parport_claim() under spin_lock_irqsave(&arbitration_lock).

Reproduced on v7.3.1 (share.c is unchanged in mainline) in QEMU with the
emulated ISA parallel port (parport_pc, IRQ 7 from ACPI PnP), as a user
in the lp group with two ppdev openers: one holds the port, the other
blocks in PPCLAIM, and the holder closes its fd. Lockdep reports:

WARNING: inconsistent lock state
inconsistent {IN-HARDIRQ-R} -> {HARDIRQ-ON-W} usage.
...
_raw_spin_unlock_irq+0x28/0x80
parport_claim+0x692/0xc80 [parport]
parport_release+0x5c0/0x7c0 [parport]
pp_release+0x37c/0x980 [ppdev]

and CONFIG_DEBUG_IRQFLAGS adds "raw_local_irq_restore() called with IRQs
enabled" for the final write_unlock_irqrestore(). When the closing task
runs on the CPU that handles IRQ 7, that CPU spins forever in
parport_irq_handler() -> _raw_read_lock(), on top of
parport_pc_restore_state() running with interrupts enabled. QEMU
raises the port interrupt on the control register write in
->restore_state(), so there the hang happens every time. On real
hardware the interrupt has to arrive inside a window of a few
microseconds; I have not tested real hardware. With this patch the
same test runs clean and the port interrupt is still delivered.

Interrupts are already disabled at this point, so use spin_lock() and
spin_unlock(), as the "blocked" path in the same function already does.
waitlist_lock is never taken from hardirq context.

Found by LLM-assisted static analysis.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/r/202608091622.jlJn0jOj-lkp@xxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---

Notes:
The changelog was drafted with an AI assistant from my analysis;
I have reviewed the code, the fix and the text.

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