From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-73.mta0.migadu.com [91.218.175.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEEE3175A9D for ; Fri, 4 Sep 2026 08:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788510657; cv=none; b=IY0dc3StJ0RhJWRKgjPAGRzQVGKBjCRnqQEKA9GC139SFz0hDPYlP85jMmqe+n14lm5PROIR31S4V7ggwFyGXkljyT2fEih16TpPHzTF845p1+hyJgP53Wmlj8drHl0IFcXVlbmK1Af2IAp+B2krcB59/6IooEWsq3ixbkQgkOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788510657; c=relaxed/simple; bh=Xdvx2Irb+Gsb4geE+bHqC5XEtHWE1pIygMMtMXvfW5U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sZ7PzSf+LhdmlpazfH1hyQkaUNixSZCuGT3XFJelAowJrDuHjcSD9EsoCqLrBub3hx6AM30h7rnEKJ4LWIzKdfKq9gRh+XRAeXme8OeOg3Hpl0bKGSkTSTC8D1jpPHAOkN1wmkCUDyZNm0OkdViJtzkh0WOUtInxR8U06KsjiJQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=TxPiXNfQ; arc=none smtp.client-ip=91.218.175.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="TxPiXNfQ" X-Envelope-To: linux-pm@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Xdvx2Irb+Gsb4geE+bHqC5XEtHWE1pIygMMtMXvfW5U=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1788510653; v=1; x=1789115453; b=TxPiXNfQbb+rrsZcs5+Z2cURhWExczwoUfE4ju8SYtvJvIRAX4cpJow4ku6fWYedYwvgmHdL pbeVX4eBiJBV2+eRij+sAuS20qeK7jr3kOG+/iUSBGOvI2m3VZlHQ5K2JexZrE2x+amVXdABoFy kvc8HlOQdB7kwVbX5hwYuQpo= X-Envelope-To: linux-pm@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id d7ceea79dbc23d11; Fri, 04 Sep 2026 08:30:53 +0000 X-Mizu-Trace-ID: d7ceea79dbc23d11 X-Migadu-Flow: FLOW_OUT From: Ye Liu To: Thomas Gleixner , Peter Zijlstra , "Rafael J. Wysocki" , Andrew Morton , Ingo Molnar , Will Deacon , Boqun Feng , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Juri Lelli , Vincent Guittot , Steven Rostedt , Masami Hiramatsu , Josh Poimboeuf Cc: Ye Liu , Pavel Machek , Lance Yang , Petr Mladek , Waiman Long , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Mark Rutland , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rcu@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 5/8] kernel: convert process/thread iterators to for_each_*_rcu Date: Fri, 4 Sep 2026 16:29:57 +0800 Message-Id: <20260904083001.553587-6-ye.liu@linux.dev> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260904083001.553587-1-ye.liu@linux.dev> References: <20260904083001.553587-1-ye.liu@linux.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ye Liu Replace the manual rcu_read_lock()/rcu_read_unlock() and guard(rcu) pairs combined with for_each_process(), for_each_thread() and for_each_process_thread() loops across kernel/ with the for_each_*_rcu() macros. No functional change. Signed-off-by: Ye Liu --- kernel/cpu.c | 4 +--- kernel/freezer.c | 4 +--- kernel/hung_task.c | 7 ++----- kernel/locking/lockdep.c | 4 +--- kernel/rcu/update.c | 4 +--- kernel/sched/core.c | 3 +-- kernel/sched/debug.c | 4 +--- kernel/trace/fgraph.c | 8 ++------ kernel/unwind/deferred.c | 3 +-- 9 files changed, 11 insertions(+), 30 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index b3c8553d7bd6..bc70fd21561a 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1254,8 +1254,7 @@ void clear_tasks_mm_cpumask(int cpu) * full-fledged tasklist_lock. */ WARN_ON(cpu_online(cpu)); - rcu_read_lock(); - for_each_process(p) { + for_each_process_rcu(p) { struct task_struct *t; /* @@ -1268,7 +1267,6 @@ void clear_tasks_mm_cpumask(int cpu) arch_clear_mm_cpumask_cpu(cpu, t->mm); task_unlock(t); } - rcu_read_unlock(); } /* Take this CPU down. */ diff --git a/kernel/freezer.c b/kernel/freezer.c index a76bf957fb32..a27b2382fda9 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -217,11 +217,9 @@ void thaw_process(struct task_struct *p) { struct task_struct *t; - rcu_read_lock(); - for_each_thread(p, t) { + for_each_thread_rcu(p, t) { __thaw_task(t); } - rcu_read_unlock(); } /** diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 6fcc94ce4ca9..76871f78497f 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -315,8 +315,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) return; this_round_count = 0; - rcu_read_lock(); - for_each_process_thread(g, t) { + for_each_process_thread_rcu(g, t) { if (!max_count--) goto unlock; if (time_after(jiffies, last_break + HUNG_TASK_LOCK_BREAK)) { @@ -337,9 +336,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) hung_task_info(t, timeout, this_round_count); } } - unlock: - rcu_read_unlock(); - +unlock: if (!this_round_count) return; diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index c56a7f91d72e..9c3dce0f0c4b 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -6834,15 +6834,13 @@ void debug_show_all_locks(void) } pr_warn("\nShowing all locks held in the system:\n"); - rcu_read_lock(); - for_each_process_thread(g, p) { + for_each_process_thread_rcu(g, p) { if (!p->lockdep_depth) continue; lockdep_print_held_locks(p); touch_nmi_watchdog(); touch_all_softlockup_watchdogs(); } - rcu_read_unlock(); pr_warn("\n"); pr_warn("=============================================\n\n"); diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c index 2a778b8ab4ad..c48a84a0da82 100644 --- a/kernel/rcu/update.c +++ b/kernel/rcu/update.c @@ -548,15 +548,13 @@ void synchronize_rcu_trivial_preempt(void) struct task_struct *t; smp_mb(); // Order prior accesses before grace-period start. - rcu_read_lock(); // Protect task list. - for_each_process_thread(g, t) { + for_each_process_thread_rcu(g, t) { if (t == current) continue; // Don't deadlock on ourselves! // Order later rcu_read_lock() on other tasks after QS. while (smp_load_acquire(&t->rcu_trivial_preempt_nesting)) continue; } - rcu_read_unlock(); } EXPORT_SYMBOL_GPL(synchronize_rcu_trivial_preempt); #endif // #if IS_ENABLED(CONFIG_TRIVIAL_PREEMPT_RCU) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0697ed0f1c3d..a41cdd2ff02f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2005,8 +2005,7 @@ static void uclamp_sync_util_min_rt_default(void) smp_mb__after_spinlock(); read_unlock(&tasklist_lock); - guard(rcu)(); - for_each_process_thread(g, p) + for_each_process_thread_rcu(g, p) uclamp_update_util_min_rt_default(p); } diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 72236db67983..8f37b1a7adfe 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -1029,14 +1029,12 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu) #endif "\n"); - rcu_read_lock(); - for_each_process_thread(g, p) { + for_each_process_thread_rcu(g, p) { if (task_cpu(p) != rq_cpu) continue; print_task(m, rq, p); } - rcu_read_unlock(); } void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 40d373d65f9b..e522433ec8a5 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1057,11 +1057,10 @@ static int alloc_retstack_tasklist(unsigned long **ret_stack_list) } } - rcu_read_lock(); - for_each_process_thread(g, t) { + for_each_process_thread_rcu(g, t) { if (start == end) { ret = -EAGAIN; - goto unlock; + goto free; } if (t->ret_stack == NULL) { @@ -1074,9 +1073,6 @@ static int alloc_retstack_tasklist(unsigned long **ret_stack_list) t->ret_stack = ret_stack_list[start++]; } } - -unlock: - rcu_read_unlock(); free: for (i = start; i < end; i++) kmem_cache_free(fgraph_stack_cachep, ret_stack_list[i]); diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c index 5bea47314254..61fe2d4727ce 100644 --- a/kernel/unwind/deferred.c +++ b/kernel/unwind/deferred.c @@ -319,9 +319,8 @@ void unwind_deferred_cancel(struct unwind_work *work) synchronize_srcu(&unwind_srcu); - guard(rcu)(); /* Clear this bit from all threads */ - for_each_process_thread(g, t) { + for_each_process_thread_rcu(g, t) { atomic_long_andnot(BIT(bit), &t->unwind_info.unwind_mask); if (t->unwind_info.cache) -- 2.25.1