mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Ziheng Wei <zihengw03@163.com>
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	linux-kernel@vger.kernel.org, kernel test robot <lkp@intel.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] parport: do not re-enable interrupts in parport_claim()
Date: Wed, 18 Nov 2026 08:04:32 +0100	[thread overview]
Message-ID: <2026111838-snowshoe-latch-1c25@gregkh> (raw)
In-Reply-To: <20261116130930.1629208-1-zihengw03@163.com>

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@intel.com>

this tool found this bug?

And testing on real hardware would be best.

thanks,

greg k-h

      reply	other threads:[~2026-11-18  7:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 13:09 Ziheng Wei
2026-11-18  7:04 ` Greg Kroah-Hartman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026111838-snowshoe-latch-1c25@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=sudipm.mukherjee@gmail.com \
    --cc=zihengw03@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®