From: Boqun Feng <boqun.feng@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Peter Zijlstra <peterz@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH] rseq: Protect event mask against membarrier IPI
Date: Wed, 13 Aug 2025 09:11:19 -0700 [thread overview]
Message-ID: <aJy5Jxf_c8RG7qvU@tardis-2.local> (raw)
In-Reply-To: <87o6sj6z95.ffs@tglx>
On Wed, Aug 13, 2025 at 05:02:30PM +0200, Thomas Gleixner wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
> Date: Tue, 12 Aug 2025 16:34:43 +0200
>
> rseq_need_restart() reads and clears task::rseq_event_mask with preemption
> disabled to guard against the scheduler.
>
> But membarrier() uses an IPI and sets the PREEMPT bit in the event mask
> from the IPI, which leaves that RMW operation unprotected.
>
> Use guard(irq) if CONFIG_MEMBARRIER is enabled to fix that.
>
> Fixes: 2a36ab717e8f ("rseq/membarrier: Add MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ")
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Boqun Feng <boqun.feng@gmail.com>
> Cc: stable@vger.kernel.org
Seems reasonable to me.
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> ---
> include/linux/rseq.h | 11 ++++++++---
> kernel/rseq.c | 10 +++++-----
> 2 files changed, 13 insertions(+), 8 deletions(-)
>
> --- a/include/linux/rseq.h
> +++ b/include/linux/rseq.h
> @@ -7,6 +7,12 @@
> #include <linux/preempt.h>
> #include <linux/sched.h>
>
> +#ifdef CONFIG_MEMBARRIER
> +# define RSEQ_EVENT_GUARD irq
> +#else
> +# define RSEQ_EVENT_GUARD preempt
> +#endif
> +
> /*
> * Map the event mask on the user-space ABI enum rseq_cs_flags
> * for direct mask checks.
> @@ -41,9 +47,8 @@ static inline void rseq_handle_notify_re
> static inline void rseq_signal_deliver(struct ksignal *ksig,
> struct pt_regs *regs)
> {
> - preempt_disable();
> - __set_bit(RSEQ_EVENT_SIGNAL_BIT, ¤t->rseq_event_mask);
> - preempt_enable();
> + scoped_guard(RSEQ_EVENT_GUARD)
> + __set_bit(RSEQ_EVENT_SIGNAL_BIT, ¤t->rseq_event_mask);
> rseq_handle_notify_resume(ksig, regs);
> }
>
> --- a/kernel/rseq.c
> +++ b/kernel/rseq.c
> @@ -342,12 +342,12 @@ static int rseq_need_restart(struct task
>
> /*
> * Load and clear event mask atomically with respect to
> - * scheduler preemption.
> + * scheduler preemption and membarrier IPIs.
> */
> - preempt_disable();
> - event_mask = t->rseq_event_mask;
> - t->rseq_event_mask = 0;
> - preempt_enable();
> + scoped_guard(RSEQ_EVENT_GUARD) {
> + event_mask = t->rseq_event_mask;
> + t->rseq_event_mask = 0;
> + }
>
> return !!event_mask;
> }
next prev parent reply other threads:[~2025-08-13 16:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 15:02 Thomas Gleixner
2025-08-13 16:11 ` Boqun Feng [this message]
2025-08-13 16:14 ` Mathieu Desnoyers
2025-08-20 13:23 ` Mathieu Desnoyers
2025-08-23 12:31 ` Thomas Gleixner
2025-08-25 14:13 ` Mathieu Desnoyers
2025-09-13 17:57 ` [tip: core/rseq] " tip-bot2 for Thomas Gleixner
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=aJy5Jxf_c8RG7qvU@tardis-2.local \
--to=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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®