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

From: Greg Kroah-Hartman

Date: Wed Nov 18 2026 - 02:04:40 EST


On Mon, Nov 16, 2026 at 09:09:30PM +0800, Ziheng Wei wrote:
> 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.

This is a wall of LLM-generated text. Please make this sane and
concise.

> 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>

this tool found this bug?

And testing on real hardware would be best.

thanks,

greg k-h