cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup/cpuset: Fix "suspicious RCU usage" lockdep warning
@ 2022-02-03  3:31 Waiman Long
  2022-02-03 15:23 ` Phil Auld
       [not found] ` <20220203033103.773030-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Waiman Long @ 2022-02-03  3:31 UTC (permalink / raw)
  To: Tejun Heo, Zefan Li, Johannes Weiner
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Phil Auld, Waiman Long

It was found that a "suspicious RCU usage" lockdep warning was issued
with the rcu_read_lock() call in update_sibling_cpumasks().  It is
because the update_cpumasks_hier() function may sleep. So we have
to release the RCU lock, call update_cpumasks_hier() and reacquire
it afterward.

Also add a percpu_rwsem_assert_held() in update_sibling_cpumasks()
instead of stating that in the comment.

Fixes: 4716909cc5c5 ("cpuset: Track cpusets that use parent's effective_cpus")
Signed-off-by: Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 kernel/cgroup/cpuset.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index dc653ab26e50..b147acece984 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1522,10 +1522,15 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
 	struct cpuset *sibling;
 	struct cgroup_subsys_state *pos_css;
 
+	percpu_rwsem_assert_held(&cpuset_rwsem);
+
 	/*
 	 * Check all its siblings and call update_cpumasks_hier()
 	 * if their use_parent_ecpus flag is set in order for them
 	 * to use the right effective_cpus value.
+	 *
+	 * The update_cpumasks_hier() function may sleep. So we have to
+	 * release the RCU read lock before calling it.
 	 */
 	rcu_read_lock();
 	cpuset_for_each_child(sibling, pos_css, parent) {
@@ -1533,8 +1538,13 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
 			continue;
 		if (!sibling->use_parent_ecpus)
 			continue;
+		if (!css_tryget_online(&sibling->css))
+			continue;
 
+		rcu_read_unlock();
 		update_cpumasks_hier(sibling, tmp);
+		rcu_read_lock();
+		css_put(&sibling->css);
 	}
 	rcu_read_unlock();
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup/cpuset: Fix "suspicious RCU usage" lockdep warning
  2022-02-03  3:31 [PATCH] cgroup/cpuset: Fix "suspicious RCU usage" lockdep warning Waiman Long
@ 2022-02-03 15:23 ` Phil Auld
       [not found] ` <20220203033103.773030-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Phil Auld @ 2022-02-03 15:23 UTC (permalink / raw)
  To: Waiman Long; +Cc: Tejun Heo, Zefan Li, Johannes Weiner, cgroups, linux-kernel

On Wed, Feb 02, 2022 at 10:31:03PM -0500 Waiman Long wrote:
> It was found that a "suspicious RCU usage" lockdep warning was issued
> with the rcu_read_lock() call in update_sibling_cpumasks().  It is
> because the update_cpumasks_hier() function may sleep. So we have
> to release the RCU lock, call update_cpumasks_hier() and reacquire
> it afterward.
> 
> Also add a percpu_rwsem_assert_held() in update_sibling_cpumasks()
> instead of stating that in the comment.
> 
> Fixes: 4716909cc5c5 ("cpuset: Track cpusets that use parent's effective_cpus")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  kernel/cgroup/cpuset.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index dc653ab26e50..b147acece984 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1522,10 +1522,15 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
>  	struct cpuset *sibling;
>  	struct cgroup_subsys_state *pos_css;
>  
> +	percpu_rwsem_assert_held(&cpuset_rwsem);
> +
>  	/*
>  	 * Check all its siblings and call update_cpumasks_hier()
>  	 * if their use_parent_ecpus flag is set in order for them
>  	 * to use the right effective_cpus value.
> +	 *
> +	 * The update_cpumasks_hier() function may sleep. So we have to
> +	 * release the RCU read lock before calling it.
>  	 */
>  	rcu_read_lock();
>  	cpuset_for_each_child(sibling, pos_css, parent) {
> @@ -1533,8 +1538,13 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
>  			continue;
>  		if (!sibling->use_parent_ecpus)
>  			continue;
> +		if (!css_tryget_online(&sibling->css))
> +			continue;
>  
> +		rcu_read_unlock();
>  		update_cpumasks_hier(sibling, tmp);
> +		rcu_read_lock();
> +		css_put(&sibling->css);
>  	}
>  	rcu_read_unlock();
>  }
> -- 
> 2.27.0
> 

This looks good. Thanks Waiman.

Tested-by: Phil Auld <pauld@redhat.com>
Reviewed-by: Phil Auld <pauld@redhat.com>


Cheers,
Phil
-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup/cpuset: Fix "suspicious RCU usage" lockdep warning
       [not found] ` <20220203033103.773030-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2022-02-03 16:06   ` Tejun Heo
  0 siblings, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2022-02-03 16:06 UTC (permalink / raw)
  To: Waiman Long
  Cc: Zefan Li, Johannes Weiner, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Phil Auld

On Wed, Feb 02, 2022 at 10:31:03PM -0500, Waiman Long wrote:
> It was found that a "suspicious RCU usage" lockdep warning was issued
> with the rcu_read_lock() call in update_sibling_cpumasks().  It is
> because the update_cpumasks_hier() function may sleep. So we have
> to release the RCU lock, call update_cpumasks_hier() and reacquire
> it afterward.
> 
> Also add a percpu_rwsem_assert_held() in update_sibling_cpumasks()
> instead of stating that in the comment.
> 
> Fixes: 4716909cc5c5 ("cpuset: Track cpusets that use parent's effective_cpus")
> Signed-off-by: Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Applied to cgroup/for-5.17-fixes.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-03 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-03  3:31 [PATCH] cgroup/cpuset: Fix "suspicious RCU usage" lockdep warning Waiman Long
2022-02-03 15:23 ` Phil Auld
     [not found] ` <20220203033103.773030-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-02-03 16:06   ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).