All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mayank Rungta" <mrungta@google.com>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [PATCH v3 2/5] genirq: Implement synchronous disable_nmi()
Date: Thu, 03 Sep 2026 02:11:12 +0000	[thread overview]
Message-ID: <20260903021113.2F7AC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-2-f3999362a9ea@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] disable_nmi() fails to guarantee synchronous completion of running NMI handlers, violating its primary design goal.

Pre-existing issues:
- [High] __synchronize_hardirq() unconditionally enables interrupts upon unlocking, violating synchronize_hardirq() IRQ context safety.
--

commit 462b11bbb02ba75caa68818b765707ca5b10454d
Author: Mayank Rungta <mrungta@google.com>

genirq: Implement synchronous disable_nmi()
    
This commit introduces disable_nmi() to synchronously disable an NMI line,
guaranteeing any running instances of the NMI handler have completed before
returning. It implements this by wrapping disable_irq().

> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index a9973b61163ae..009633b5b6544 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -767,6 +767,21 @@ void disable_nmi_nosync(unsigned int irq)
>  	disable_irq_nosync(irq);
>  }
>  
> +/**
> + * disable_nmi - disable an nmi and wait for any pending handlers
> + * @irq: Interrupt to disable
> + *
> + * Disable the selected interrupt line. Disables and enables are nested.
> + *
> + * The interrupt to disable must have been requested through request_nmi.
> + * This function ensures existing instances of the NMI handler have
> + * completed before returning.
> + */
> +void disable_nmi(unsigned int irq)
> +{
> +	disable_irq(irq);

[Severity: High]
Does this correctly guarantee synchronous completion of running NMI handlers?

This function wraps disable_irq(), which uses synchronize_irq() to wait for
completion. synchronize_irq() checks the IRQD_IRQ_INPROGRESS software flag
and the IRQCHIP_STATE_ACTIVE hardware state. 

However, NMIs handled by functions like handle_fasteoi_nmi() bypass standard
event handling and never set IRQD_IRQ_INPROGRESS:

kernel/irq/chip.c:handle_fasteoi_nmi() {
    ...
    res = action->handler(irq, action->dev_id);
    ...
}

If the irqchip doesn't support reading the active state, or if the NMI is
pending but not yet active, synchronize_irq() returns immediately. The
target CPU then processes the NMI, and since handle_fasteoi_nmi() does not
check IRQD_IRQ_DISABLED, the handler blindly executes after disable_nmi()
has returned. Can this lead to use-after-free or crashes when drivers rely
on disable_nmi() before freeing resources?

[Severity: High]
This isn't a bug introduced by this patch, but __synchronize_hardirq() is
called by synchronize_irq(), which is triggered by this code. There is a
pre-existing locking violation with how it handles locking:

kernel/irq/manage.c:__synchronize_hardirq() {
    ...
    guard(raw_spinlock_irqsave)(&desc->lock);
    ...
}

The guard is defined in include/linux/spinlock.h:

DEFINE_LOCK_GUARD_1(raw_spinlock_irqsave, raw_spinlock_t,
                    raw_spin_lock_irq_disable(_T->lock),
                    raw_spin_unlock_irq_enable(_T->lock))

This defines the guard to use raw_spin_unlock_irq_enable(), which does not
restore previously saved flags but unconditionally enables interrupts.

If a caller invokes synchronize_hardirq() (or another function using this
guard) from an IRQ handler where local interrupts are currently disabled,
it unconditionally re-enables local interrupts upon unlocking rather than
restoring the previously saved IRQ state. Could this lead to unexpected
nested interrupts or deadlocks?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com?part=2

  reply	other threads:[~2026-09-03  2:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  1:54 [PATCH v3 0/5] watchdog: qcom: Support NMI pretimeout warnings Mayank Rungta
2026-09-03  1:54 ` [PATCH v3 1/5] genirq: Synchronize in-flight handlers during NMI teardown Mayank Rungta
2026-09-03  2:06   ` sashiko-bot
2026-09-04  9:17   ` Thomas Gleixner
2026-09-04 13:40     ` Marc Zyngier
2026-09-04 14:34       ` Doug Anderson
2026-09-04 14:57         ` Marc Zyngier
2026-09-04 14:59           ` Doug Anderson
2026-09-04 15:11       ` Thomas Gleixner
2026-09-04 15:26         ` Doug Anderson
2026-09-03  1:54 ` [PATCH v3 2/5] genirq: Implement synchronous disable_nmi() Mayank Rungta
2026-09-03  2:11   ` sashiko-bot [this message]
2026-09-03  1:54 ` [PATCH v3 3/5] genirq: Export NMI APIs Mayank Rungta
2026-09-04  9:29   ` Thomas Gleixner
2026-09-04 14:07     ` Doug Anderson
2026-09-04 15:05       ` Thomas Gleixner
2026-09-05  1:52         ` Mayank Rungta
2026-09-03  1:54 ` [PATCH v3 4/5] watchdog: pretimeout: Protect governor access with RCU for NMI safety Mayank Rungta
2026-09-03  1:54 ` [PATCH v3 5/5] watchdog: qcom: Register pretimeout interrupt as NMI Mayank Rungta
2026-09-03  2:25   ` sashiko-bot
2026-09-03  8:18   ` Konrad Dybcio
2026-09-03 20:58     ` Mayank Rungta
2026-09-04  7:37       ` Konrad Dybcio
2026-09-04 14:37       ` Doug Anderson
2026-09-05  1:24         ` Mayank Rungta

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=20260903021113.2F7AC1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=mrungta@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.