From: sashiko-bot@kernel.org
To: "Boqun Feng" <boqun@kernel.org>
Cc: ojeda@kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v3 13/13] irq: Optimize reschedule check in local_interrupt_enable()
Date: Fri, 05 Jun 2026 06:04:18 +0000 [thread overview]
Message-ID: <20260605060418.94F861F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260605054128.5925-14-boqun@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Data race in `__preempt_count_add_return` causes lost wakeups on ARM64
--
commit c3bbe9e483f96a8dad6049a0192dc87491aed263
Author: Boqun Feng <boqun@kernel.org>
irq: Optimize reschedule check in local_interrupt_enable()
This patch optimizes local_interrupt_enable() by avoiding a re-read of
the preempt count. It modifies __preempt_count_{add,sub}_return() to
return unsigned long, allowing it to capture and return the
PREEMPT_NEED_RESCHED bit for reschedule checks.
> diff --git a/arch/arm64/include/asm/preempt.h b/arch/arm64/include/asm/preempt.h
> index 0dd8221d1bef7..e9f597d874134 100644
> --- a/arch/arm64/include/asm/preempt.h
> +++ b/arch/arm64/include/asm/preempt.h
[ ... ]
> @@ -55,20 +55,20 @@ static inline void __preempt_count_sub(int val)
> WRITE_ONCE(current_thread_info()->preempt.count, pc);
> }
>
> -static inline int __preempt_count_add_return(int val)
> +static inline unsigned long __preempt_count_add_return(int val)
> {
> - u32 pc = READ_ONCE(current_thread_info()->preempt.count);
> + u64 pc = READ_ONCE(current_thread_info()->preempt_count);
> pc += val;
> - WRITE_ONCE(current_thread_info()->preempt.count, pc);
[Severity: High]
Does this code introduce a regression where the need_resched flag can be
clobbered, resulting in a lost wakeup?
On ARM64, the 64-bit preempt_count union contains both the 32-bit count and
the 32-bit need_resched flag. Changing this to a non-atomic 64-bit read and
write seems like it might race with hardware interrupts.
For instance, when local_interrupt_disable() runs, it calls into
__preempt_count_add_return() via hardirq_disable_enter() before actually
disabling hardware interrupts:
include/linux/interrupt_rc.h:local_interrupt_disable() {
...
new_count = hardirq_disable_enter();
if (!new_count) {
...
raw_local_irq_save(flags);
}
Because hardware interrupts are still fully enabled during this operation, if
an interrupt fires exactly between the 64-bit READ_ONCE() and WRITE_ONCE(),
and the handler wakes up a task (updating need_resched), wouldn't this
WRITE_ONCE() restore the stale need_resched value and lose the wakeup?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260605054128.5925-1-boqun@kernel.org?part=13
prev parent reply other threads:[~2026-06-05 6:04 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
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 [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=20260605060418.94F861F00893@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 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.