mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aniket Gattani <aniketgattani@google.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	 "Paul E . McKenney" <paulmck@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,  Ben Segall <bsegall@google.com>,
	Josh Don <joshdon@google.com>,
	linux-kernel@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	Aniket Gattani <aniketgattani@google.com>
Subject: [PATCH v3 2/3] sched/membarrier: Modernize membarrier_global_expedited with cleanup guards
Date: Sun,  3 May 2026 21:22:04 +0000	[thread overview]
Message-ID: <20260503212205.3714217-3-aniketgattani@google.com> (raw)
In-Reply-To: <20260503212205.3714217-1-aniketgattani@google.com>

Replace explicit lock/unlock and free calls with scoped guards and
automatic cleanup constructs.

Signed-off-by: Aniket Gattani <aniketgattani@google.com>
---
 kernel/sched/membarrier.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c
index 3d88e900a17f..12b68a77630a 100644
--- a/kernel/sched/membarrier.c
+++ b/kernel/sched/membarrier.c
@@ -267,23 +267,19 @@ void membarrier_update_current_mm(struct mm_struct *next_mm)
 
 static int membarrier_global_expedited(void)
 {
+	cpumask_var_t __free(free_cpumask_var) tmpmask = CPUMASK_VAR_NULL;
 	int cpu;
-	cpumask_var_t tmpmask;
 
 	if (num_online_cpus() == 1)
 		return 0;
 
-	/*
-	 * Matches memory barriers after rq->curr modification in
-	 * scheduler.
-	 */
-	smp_mb();	/* system call entry is not a mb. */
-
 	if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
 		return -ENOMEM;
 
+	guard(mb)();
 	SERIALIZE_IPI();
-	cpus_read_lock();
+	guard(cpus_read_lock)();
+
 	rcu_read_lock();
 	for_each_online_cpu(cpu) {
 		struct task_struct *p;
@@ -319,15 +315,6 @@ static int membarrier_global_expedited(void)
 	smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
 	preempt_enable();
 
-	free_cpumask_var(tmpmask);
-	cpus_read_unlock();
-
-	/*
-	 * Memory barrier on the caller thread _after_ we finished
-	 * waiting for the last IPI. Matches memory barriers before
-	 * rq->curr modification in scheduler.
-	 */
-	smp_mb();	/* exit from system call is not a mb */
 	return 0;
 }
 
-- 
2.54.0.545.g6539524ca2-goog


  parent reply	other threads:[~2026-05-03 21:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-03 21:22 [PATCH v3 0/3] sched/membarrier: Use per-CPU mutexes for targeted commands Aniket Gattani
2026-05-03 21:22 ` [PATCH v3 1/3] " Aniket Gattani
2026-05-05 10:55   ` [tip: locking/core] " tip-bot2 for Aniket Gattani
2026-05-03 21:22 ` Aniket Gattani [this message]
2026-05-05 10:55   ` [tip: locking/core] sched/membarrier: Modernize membarrier_global_expedited with cleanup guards tip-bot2 for Aniket Gattani
2026-05-03 21:22 ` [PATCH v3 3/3] selftests/membarrier: Add rseq stress test for CFS throttle interactions Aniket Gattani
2026-05-05 10:55   ` [tip: locking/core] " tip-bot2 for Aniket Gattani

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=20260503212205.3714217-3-aniketgattani@google.com \
    --to=aniketgattani@google.com \
    --cc=bsegall@google.com \
    --cc=joshdon@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    /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®