Thread (4 messages) 4 messages, 3 authors, 2025-09-16

Re: [PATCH v2] rcu: Remove redundant rcu_read_lock/unlock() in spin_lock critical sections

From: Waiman Long <hidden>
Date: 2025-09-15 14:13:36
Also in: cgroups, intel-gfx, linux-acpi, linux-fsdevel, linux-nfs, linux-rt-devel, linux-s390, linux-security-module, lkml

On 9/15/25 9:47 AM, pengdonglin wrote:
From: pengdonglin <redacted>

Per Documentation/RCU/rcu_dereference.rst [1], since Linux 4.20's RCU
consolidation [2][3], RCU read-side critical sections include:
   - Explicit rcu_read_lock()
   - BH/interrupt/preemption-disabling regions
   - Spinlock critical sections (including CONFIG_PREEMPT_RT kernels [4])

Thus, explicit rcu_read_lock()/unlock() calls within spin_lock*() regions are redundant.
This patch removes them, simplifying locking semantics while preserving RCU protection.

[1] https://elixir.bootlin.com/linux/v6.17-rc5/source/Documentation/RCU/rcu_dereference.rst#L407
[2] https://lore.kernel.org/lkml/20180829222021.GA29944@linux.vnet.ibm.com/ (local)
[3] https://lwn.net/Articles/777036/
[4] https://lore.kernel.org/lkml/6435833a-bdcb-4114-b29d-28b7f436d47d@paulmck-laptop/ (local)

Cc: Waiman Long <longman@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Hillf Danton <redacted>
Cc: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: pengdonglin <redacted>
Signed-off-by: pengdonglin <redacted>
---
Changes in v2:
   - Clarified commit message to prevent accidental backport to older kernels
   - Added lockdep_is_held() to avoid false positives
---
  drivers/acpi/apei/ghes.c                        | 2 --
  drivers/gpu/drm/i915/gt/intel_ring_submission.c | 2 --
  drivers/net/amt.c                               | 8 --------
  drivers/net/bonding/bond_3ad.c                  | 2 --
  drivers/net/wireless/ath/ath9k/xmit.c           | 2 --
  drivers/s390/crypto/pkey_base.c                 | 3 ---
  fs/aio.c                                        | 6 ++----
  fs/nfs/callback_proc.c                          | 2 --
  fs/nfs/nfs4state.c                              | 2 --
  fs/nfs/pnfs.c                                   | 9 ---------
  fs/nfs/pnfs_dev.c                               | 4 ----
  ipc/msg.c                                       | 1 -
  ipc/sem.c                                       | 1 -
  ipc/shm.c                                       | 1 -
  ipc/util.c                                      | 2 --
  kernel/cgroup/cgroup.c                          | 2 --
  kernel/cgroup/cpuset.c                          | 6 ------
  kernel/cgroup/debug.c                           | 4 ----
  net/mac80211/cfg.c                              | 2 --
  net/mac80211/debugfs.c                          | 2 --
  net/mac80211/debugfs_netdev.c                   | 2 --
  net/mac80211/debugfs_sta.c                      | 2 --
  net/mac80211/sta_info.c                         | 2 --
  net/ncsi/ncsi-manage.c                          | 2 --
  security/yama/yama_lsm.c                        | 4 ----
  25 files changed, 2 insertions(+), 73 deletions(-)
  ...
quoted hunk ↗ jump to hunk
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 27adb04df675..9b7e8e8e9411 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -4073,7 +4073,6 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
  	struct cpuset *cs;
  
  	spin_lock_irqsave(&callback_lock, flags);
-	rcu_read_lock();
  
  	cs = task_cs(tsk);
  	if (cs != &top_cpuset)
@@ -4095,7 +4094,6 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
  			cpumask_copy(pmask, possible_mask);
  	}
  
-	rcu_read_unlock();
  	spin_unlock_irqrestore(&callback_lock, flags);
  }
  
@@ -4168,9 +4166,7 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
  	unsigned long flags;
  
  	spin_lock_irqsave(&callback_lock, flags);
-	rcu_read_lock();
  	guarantee_online_mems(task_cs(tsk), &mask);
-	rcu_read_unlock();
  	spin_unlock_irqrestore(&callback_lock, flags);
  
  	return mask;
@@ -4265,10 +4261,8 @@ bool cpuset_current_node_allowed(int node, gfp_t gfp_mask)
  	/* Not hardwall and node outside mems_allowed: scan up cpusets */
  	spin_lock_irqsave(&callback_lock, flags);
  
-	rcu_read_lock();
  	cs = nearest_hardwall_ancestor(task_cs(current));
  	allowed = node_isset(node, cs->mems_allowed);
-	rcu_read_unlock();
  
  	spin_unlock_irqrestore(&callback_lock, flags);
  	return allowed;
For cpuset,

Acked-by: Waiman Long <longman@redhat.com>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help