BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Boqun Feng" <boqun@kernel.org>
Cc: ojeda@kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v3 07/13] locking: Switch to _irq_{disable,enable}() variants in cleanup guards
Date: Fri, 05 Jun 2026 05:57:14 +0000	[thread overview]
Message-ID: <20260605055714.BDF1A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260605054128.5925-8-boqun@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Switching `guard(raw_spinlock_irqsave)` and `guard(spinlock_irqsave)` to use `_irq_disable()` variants breaks NMI-safety and will trigger WARN splats and potential `preempt_count` corruption when used in NMI context.
--

commit 545c01b2eb680702b0d892d04382c1e8bb27b35f
Author: Boqun Feng <boqun@kernel.org>

locking: Switch to _irq_{disable,enable}() variants in cleanup guards

This commit modifies various irq disabling guards to use the
_irq_{disable,enable}() primitives instead of their previous variants.

Link: https://patch.msgid.link/20260121223933.1568682-17-lyude@redhat.com

> diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
> index 3d405cc4c1218..799a8f7d27418 100644
> --- a/include/linux/spinlock.h
> +++ b/include/linux/spinlock.h

[ ... ]

> @@ -592,14 +592,13 @@ DECLARE_LOCK_GUARD_1_ATTRS(raw_spinlock_bh_try, __acquires(_T), __releases(*(raw
>  #define class_raw_spinlock_bh_try_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(raw_spinlock_bh_try, _T)
>  
>  DEFINE_LOCK_GUARD_1(raw_spinlock_irqsave, raw_spinlock_t,
> -		    raw_spin_lock_irqsave(_T->lock, _T->flags),
> -		    raw_spin_unlock_irqrestore(_T->lock, _T->flags),
> -		    unsigned long flags)
> +		    raw_spin_lock_irq_disable(_T->lock),
> +		    raw_spin_unlock_irq_enable(_T->lock))

[Severity: High]
Does this change break NMI-safety for users of guard(raw_spinlock_irqsave)?

The raw_spin_lock_irqsave primitive relies exclusively on CPU-local hardware
flag saving, which makes it safe for use in any context, including NMIs.

By switching to raw_spin_lock_irq_disable, this completely bypasses local
flags saving and relies on local_interrupt_disable() under the hood.

Because local_interrupt_disable() manipulates the task's preempt_count via
hardirq_disable_enter(), it isn't safe in NMI context and will trigger a
WARN_ON_ONCE(in_nmi()) splat and potential preempt_count corruption.

>  DECLARE_LOCK_GUARD_1_ATTRS(raw_spinlock_irqsave, __acquires(_T), __releases(*(raw_spinlock_t **)_T))
>  #define class_raw_spinlock_irqsave_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(raw_spinlock_irqsave, _T)

[ ... ]

> @@ -640,14 +639,13 @@ DECLARE_LOCK_GUARD_1_ATTRS(spinlock_bh_try, __acquires(_T), __releases(*(spinloc
>  #define class_spinlock_bh_try_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(spinlock_bh_try, _T)
>  
>  DEFINE_LOCK_GUARD_1(spinlock_irqsave, spinlock_t,
> -		    spin_lock_irqsave(_T->lock, _T->flags),
> -		    spin_unlock_irqrestore(_T->lock, _T->flags),
> -		    unsigned long flags)
> +		    spin_lock_irq_disable(_T->lock),
> +		    spin_unlock_irq_enable(_T->lock))

[Severity: High]
Will this also cause preempt_count corruption and WARN splats in NMI context
for guard(spinlock_irqsave)?

Similar to the raw_spinlock_irqsave change above, moving away from the true
irqsave mechanism violates the contract that irqsave constructs are entirely
context-agnostic.

>  DECLARE_LOCK_GUARD_1_ATTRS(spinlock_irqsave, __acquires(_T), __releases(*(spinlock_t **)_T))
>  #define class_spinlock_irqsave_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(spinlock_irqsave, _T)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260605054128.5925-1-boqun@kernel.org?part=7

  reply	other threads:[~2026-06-05  5:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05  5:41 [PATCH v3 00/13] Refcounted interrupt disable and SpinLockIrq for rust (Part 1) Boqun Feng
2026-06-05  5:41 ` [PATCH v3 01/13] preempt: Track NMI nesting to separate per-CPU counter Boqun Feng
2026-06-05  5:59   ` sashiko-bot
2026-06-05  5:41 ` [PATCH v3 02/13] preempt: Introduce HARDIRQ_DISABLE_BITS Boqun Feng
2026-06-05  6:01   ` sashiko-bot
2026-06-05  5:41 ` [PATCH v3 03/13] preempt: Introduce __preempt_count_{sub, add}_return() Boqun Feng
2026-06-05  5:59   ` sashiko-bot
2026-06-05  6:30   ` bot+bpf-ci
2026-06-05  6:45     ` Boqun Feng
2026-06-05  5:41 ` [PATCH v3 04/13] openrisc: Include <linux/cpumask.h> in smp.h Boqun Feng
2026-06-05  5:41 ` [PATCH v3 05/13] irq & spin_lock: Add counted interrupt disabling/enabling Boqun Feng
2026-06-05  6:01   ` sashiko-bot
2026-06-05  6:27     ` Boqun Feng
2026-06-05  6:30   ` bot+bpf-ci
2026-06-05  6:40     ` Boqun Feng
2026-06-05  5:41 ` [PATCH v3 06/13] irq: Add KUnit test for refcounted interrupt enable/disable Boqun Feng
2026-06-05  5:53   ` sashiko-bot
2026-06-05  5:41 ` [PATCH v3 07/13] locking: Switch to _irq_{disable,enable}() variants in cleanup guards Boqun Feng
2026-06-05  5:57   ` sashiko-bot [this message]
2026-06-05  5:41 ` [PATCH v3 08/13] sched: Remove the unused preempt_offset parameter of __cant_sleep() Boqun Feng
2026-06-05  5:41 ` [PATCH v3 09/13] sched: Avoid signed comparison of preempt_count() in __cant_migrate() Boqun Feng
2026-06-05  5:41 ` [PATCH v3 10/13] preempt: Introduce HAS_SEPARATE_PREEMPT_RESCHED_BITS Boqun Feng
2026-06-05  5:59   ` sashiko-bot
2026-06-05  6:30   ` bot+bpf-ci
2026-06-05  5:41 ` [PATCH v3 11/13] arm64: sched/preempt: Enable HAS_SEPARATE_PREEMPT_RESCHED_BITS Boqun Feng
2026-06-05  5:41 ` [PATCH v3 12/13] s390/preempt: " Boqun Feng
2026-06-05  5:41 ` [PATCH v3 13/13] irq: Optimize reschedule check in local_interrupt_enable() Boqun Feng
2026-06-05  6:04   ` sashiko-bot

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=20260605055714.BDF1A1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=boqun@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox