]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cgroup: Remove redundant rcu_read_lock/unlock() in spin_lock
authorpengdonglin <pengdonglin@xiaomi.com>
Tue, 16 Sep 2025 04:47:29 +0000 (12:47 +0800)
committerTejun Heo <tj@kernel.org>
Tue, 16 Sep 2025 18:36:14 +0000 (08:36 -1000)
Since commit a8bb74acd8efe ("rcu: Consolidate RCU-sched update-side function definitions")
there is no difference between rcu_read_lock(), rcu_read_lock_bh() and
rcu_read_lock_sched() in terms of RCU read section and the relevant grace
period. That means that spin_lock(), which implies rcu_read_lock_sched(),
also implies rcu_read_lock().

There is no need no explicitly start a RCU read section if one has already
been started implicitly by spin_lock().

Simplify the code and remove the inner rcu_read_lock() invocation.

Cc: Tejun Heo <tj@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Waiman Long <longman@redhat.com>
Signed-off-by: pengdonglin <pengdonglin@xiaomi.com>
Signed-off-by: pengdonglin <dolinux.peng@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c
kernel/cgroup/debug.c

index fed701df1167078cf2ef38967c0d8457b47e6d17..dcf8dc9f6343cb850cd799342407ed918a01611d 100644 (file)
@@ -3025,14 +3025,12 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
 
        /* look up all src csets */
        spin_lock_irq(&css_set_lock);
-       rcu_read_lock();
        task = leader;
        do {
                cgroup_migrate_add_src(task_css_set(task), dst_cgrp, &mgctx);
                if (!threadgroup)
                        break;
        } while_each_thread(leader, task);
-       rcu_read_unlock();
        spin_unlock_irq(&css_set_lock);
 
        /* prepare dst csets and commit */
index 80aa3f027ac3b1a5592d7b272f23efb35a8b0b3a..81ea38dd6f9d27cac8c95a4c568e840e3b0fb988 100644 (file)
@@ -49,7 +49,6 @@ static int current_css_set_read(struct seq_file *seq, void *v)
                return -ENODEV;
 
        spin_lock_irq(&css_set_lock);
-       rcu_read_lock();
        cset = task_css_set(current);
        refcnt = refcount_read(&cset->refcount);
        seq_printf(seq, "css_set %pK %d", cset, refcnt);
@@ -67,7 +66,6 @@ static int current_css_set_read(struct seq_file *seq, void *v)
                seq_printf(seq, "%2d: %-4s\t- %p[%d]\n", ss->id, ss->name,
                          css, css->id);
        }
-       rcu_read_unlock();
        spin_unlock_irq(&css_set_lock);
        cgroup_kn_unlock(of->kn);
        return 0;
@@ -95,7 +93,6 @@ static int current_css_set_cg_links_read(struct seq_file *seq, void *v)
                return -ENOMEM;
 
        spin_lock_irq(&css_set_lock);
-       rcu_read_lock();
        cset = task_css_set(current);
        list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
                struct cgroup *c = link->cgrp;
@@ -104,7 +101,6 @@ static int current_css_set_cg_links_read(struct seq_file *seq, void *v)
                seq_printf(seq, "Root %d group %s\n",
                           c->root->hierarchy_id, name_buf);
        }
-       rcu_read_unlock();
        spin_unlock_irq(&css_set_lock);
        kfree(name_buf);
        return 0;