diff mbox series

rcu: Add a warnings in sync_sched_exp_online_cleanup()

Message ID 20220621012412.2724457-1-qiang1.zhang@intel.com (mailing list archive)
State New, archived
Headers show
Series rcu: Add a warnings in sync_sched_exp_online_cleanup() | expand

Commit Message

Zqiang June 21, 2022, 1:24 a.m. UTC
Currently, the sync_sched_exp_online_cleanup() is invoked in
cpuhp per-cpu kthreads when CPU is going online, so the CPU id
obtained by get_cpu() should always be equal to the CPU id of
the passed parameter, that is to say, the smp_call_function_single()
never be invoked, if be invoked, there may be problem with cpu-hotplug,
this commit add WARN_ON_ONCE() to remind everyone.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
 kernel/rcu/tree_exp.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Zqiang June 22, 2022, 11:43 p.m. UTC | #1
Add Cc 

Currently, the sync_sched_exp_online_cleanup() is invoked in
cpuhp per-cpu kthreads when CPU is going online, so the CPU id
obtained by get_cpu() should always be equal to the CPU id of
the passed parameter, that is to say, the smp_call_function_single()
never be invoked, if be invoked, there may be problem with cpu-hotplug,
this commit add WARN_ON_ONCE() to remind everyone.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
 kernel/rcu/tree_exp.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
index be667583a554..ae8dcfd4486c 100644
--- a/kernel/rcu/tree_exp.h
+++ b/kernel/rcu/tree_exp.h
@@ -865,6 +865,8 @@ static void sync_sched_exp_online_cleanup(int cpu)
 		put_cpu();
 		return;
 	}
+
+	WARN_ON_ONCE(my_cpu != cpu);
 	/* Quiescent state needed on some other CPU, send IPI. */
 	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
 	put_cpu();
Paul E. McKenney June 27, 2022, 9:16 p.m. UTC | #2
On Wed, Jun 22, 2022 at 11:43:26PM +0000, Zhang, Qiang1 wrote:
> 
> Add Cc 
> 
> Currently, the sync_sched_exp_online_cleanup() is invoked in
> cpuhp per-cpu kthreads when CPU is going online, so the CPU id
> obtained by get_cpu() should always be equal to the CPU id of
> the passed parameter, that is to say, the smp_call_function_single()
> never be invoked, if be invoked, there may be problem with cpu-hotplug,
> this commit add WARN_ON_ONCE() to remind everyone.
> 
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> ---
>  kernel/rcu/tree_exp.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
> index be667583a554..ae8dcfd4486c 100644
> --- a/kernel/rcu/tree_exp.h
> +++ b/kernel/rcu/tree_exp.h
> @@ -865,6 +865,8 @@ static void sync_sched_exp_online_cleanup(int cpu)
>  		put_cpu();
>  		return;
>  	}
> +
> +	WARN_ON_ONCE(my_cpu != cpu);

If we are going to add this sort of warning, why not instead add it
to rcutree_online_cpu()?

The reason the warning has not been present is the prospect of concurrent
onlining at boot time, which might have rcutree_online_cpu() invoked
from CPU 0 for multiple CPUs at boot.  However, the for_each_online_cpu()
loop has recently been removed from rcu_init().

But I would like to hear what others think.  Would such a warning
significantly help debugging?

							Thanx, Paul

>  	/* Quiescent state needed on some other CPU, send IPI. */
>  	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
>  	put_cpu();
> -- 
> 2.25.1
>
Zqiang June 28, 2022, 12:31 a.m. UTC | #3
> 
> Add Cc 
> 
> Currently, the sync_sched_exp_online_cleanup() is invoked in
> cpuhp per-cpu kthreads when CPU is going online, so the CPU id
> obtained by get_cpu() should always be equal to the CPU id of
> the passed parameter, that is to say, the smp_call_function_single()
> never be invoked, if be invoked, there may be problem with cpu-hotplug,
> this commit add WARN_ON_ONCE() to remind everyone.
> 
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> ---
>  kernel/rcu/tree_exp.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
> index be667583a554..ae8dcfd4486c 100644
> --- a/kernel/rcu/tree_exp.h
> +++ b/kernel/rcu/tree_exp.h
> @@ -865,6 +865,8 @@ static void sync_sched_exp_online_cleanup(int cpu)
>  		put_cpu();
>  		return;
>  	}
> +
> +	WARN_ON_ONCE(my_cpu != cpu);

>If we are going to add this sort of warning, why not instead add it
>to rcutree_online_cpu()?
>
>The reason the warning has not been present is the prospect of concurrent
>onlining at boot time, which might have rcutree_online_cpu() invoked
>from CPU 0 for multiple CPUs at boot.  However, the for_each_online_cpu()
>loop has recently been removed from rcu_init().

The rcutree_online_cpu() is always invoked in per-cpu cpuhp kthreads, 
and even if it is called directly through the for_each_online_cpu() loop in
rcu_init(), since the rcu_init() takes precedence over smp initialization,
only the CPU0 is online at this time, still only called on CPU0.

Thanks
Zqiang

>
>But I would like to hear what others think.  Would such a warning
>significantly help debugging?
>
>							Thanx, Paul
>
>  	/* Quiescent state needed on some other CPU, send IPI. */
>  	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
>  	put_cpu();
> -- 
> 2.25.1
>
Paul E. McKenney June 28, 2022, 12:40 a.m. UTC | #4
On Tue, Jun 28, 2022 at 12:31:12AM +0000, Zhang, Qiang1 wrote:
> > 
> > Add Cc 
> > 
> > Currently, the sync_sched_exp_online_cleanup() is invoked in
> > cpuhp per-cpu kthreads when CPU is going online, so the CPU id
> > obtained by get_cpu() should always be equal to the CPU id of
> > the passed parameter, that is to say, the smp_call_function_single()
> > never be invoked, if be invoked, there may be problem with cpu-hotplug,
> > this commit add WARN_ON_ONCE() to remind everyone.
> > 
> > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > ---
> >  kernel/rcu/tree_exp.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
> > index be667583a554..ae8dcfd4486c 100644
> > --- a/kernel/rcu/tree_exp.h
> > +++ b/kernel/rcu/tree_exp.h
> > @@ -865,6 +865,8 @@ static void sync_sched_exp_online_cleanup(int cpu)
> >  		put_cpu();
> >  		return;
> >  	}
> > +
> > +	WARN_ON_ONCE(my_cpu != cpu);
> 
> >If we are going to add this sort of warning, why not instead add it
> >to rcutree_online_cpu()?
> >
> >The reason the warning has not been present is the prospect of concurrent
> >onlining at boot time, which might have rcutree_online_cpu() invoked
> >from CPU 0 for multiple CPUs at boot.  However, the for_each_online_cpu()
> >loop has recently been removed from rcu_init().
> 
> The rcutree_online_cpu() is always invoked in per-cpu cpuhp kthreads, 
> and even if it is called directly through the for_each_online_cpu() loop in
> rcu_init(), since the rcu_init() takes precedence over smp initialization,
> only the CPU0 is online at this time, still only called on CPU0.

And sync_sched_exp_online_cleanup() is only ever invoked from
rcutree_online_cpu(), correct?

							Thanx, Paul

> Thanks
> Zqiang
> 
> >
> >But I would like to hear what others think.  Would such a warning
> >significantly help debugging?
> >
> >							Thanx, Paul
> >
> >  	/* Quiescent state needed on some other CPU, send IPI. */
> >  	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
> >  	put_cpu();
> > -- 
> > 2.25.1
> >
Zqiang June 28, 2022, 12:45 a.m. UTC | #5
On Tue, Jun 28, 2022 at 12:31:12AM +0000, Zhang, Qiang1 wrote:
> > 
> > Add Cc 
> > 
> > Currently, the sync_sched_exp_online_cleanup() is invoked in
> > cpuhp per-cpu kthreads when CPU is going online, so the CPU id
> > obtained by get_cpu() should always be equal to the CPU id of
> > the passed parameter, that is to say, the smp_call_function_single()
> > never be invoked, if be invoked, there may be problem with cpu-hotplug,
> > this commit add WARN_ON_ONCE() to remind everyone.
> > 
> > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > ---
> >  kernel/rcu/tree_exp.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
> > index be667583a554..ae8dcfd4486c 100644
> > --- a/kernel/rcu/tree_exp.h
> > +++ b/kernel/rcu/tree_exp.h
> > @@ -865,6 +865,8 @@ static void sync_sched_exp_online_cleanup(int cpu)
> >  		put_cpu();
> >  		return;
> >  	}
> > +
> > +	WARN_ON_ONCE(my_cpu != cpu);
> 
> >If we are going to add this sort of warning, why not instead add it
> >to rcutree_online_cpu()?
> >
> >The reason the warning has not been present is the prospect of concurrent
> >onlining at boot time, which might have rcutree_online_cpu() invoked
> >from CPU 0 for multiple CPUs at boot.  However, the for_each_online_cpu()
> >loop has recently been removed from rcu_init().
> 
> The rcutree_online_cpu() is always invoked in per-cpu cpuhp kthreads, 
> and even if it is called directly through the for_each_online_cpu() loop in
> rcu_init(), since the rcu_init() takes precedence over smp initialization,
> only the CPU0 is online at this time, still only called on CPU0.
>
>And sync_sched_exp_online_cleanup() is only ever invoked from
>rcutree_online_cpu(), correct?

Yes, currently the sync_sched_exp_online_cleanup() is only invoked from sync_sched_exp_online_cleanup().

>
>							Thanx, Paul

> Thanks
> Zqiang
> 
> >
> >But I would like to hear what others think.  Would such a warning
> >significantly help debugging?
> >
> >							Thanx, Paul
> >
> >  	/* Quiescent state needed on some other CPU, send IPI. */
> >  	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
> >  	put_cpu();
> > -- 
> > 2.25.1
> >
Zqiang June 28, 2022, 1:52 a.m. UTC | #6
On Tue, Jun 28, 2022 at 12:31:12AM +0000, Zhang, Qiang1 wrote:
> > 
> > Add Cc 
> > 
> > Currently, the sync_sched_exp_online_cleanup() is invoked in
> > cpuhp per-cpu kthreads when CPU is going online, so the CPU id
> > obtained by get_cpu() should always be equal to the CPU id of
> > the passed parameter, that is to say, the smp_call_function_single()
> > never be invoked, if be invoked, there may be problem with cpu-hotplug,
> > this commit add WARN_ON_ONCE() to remind everyone.
> > 
> > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > ---
> >  kernel/rcu/tree_exp.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
> > index be667583a554..ae8dcfd4486c 100644
> > --- a/kernel/rcu/tree_exp.h
> > +++ b/kernel/rcu/tree_exp.h
> > @@ -865,6 +865,8 @@ static void sync_sched_exp_online_cleanup(int cpu)
> >  		put_cpu();
> >  		return;
> >  	}
> > +
> > +	WARN_ON_ONCE(my_cpu != cpu);
> 
> >If we are going to add this sort of warning, why not instead add it
> >to rcutree_online_cpu()?
> >
> >The reason the warning has not been present is the prospect of concurrent
> >onlining at boot time, which might have rcutree_online_cpu() invoked
> >from CPU 0 for multiple CPUs at boot.  However, the for_each_online_cpu()
> >loop has recently been removed from rcu_init().
> 
> The rcutree_online_cpu() is always invoked in per-cpu cpuhp kthreads, 
> and even if it is called directly through the for_each_online_cpu() loop in
> rcu_init(), since the rcu_init() takes precedence over smp initialization,
> only the CPU0 is online at this time, still only called on CPU0.
>
>And sync_sched_exp_online_cleanup() is only ever invoked from
>rcutree_online_cpu(), correct?
>

Yes, currently the sync_sched_exp_online_cleanup() is only invoked from rcutree_online_cpu ().
(Sorry, wrong wording in previous email.)

Thanks
Zqiang

>
>							Thanx, Paul

> Thanks
> Zqiang
> 
> >
> >But I would like to hear what others think.  Would such a warning
> >significantly help debugging?
> >
> >							Thanx, Paul
> >
> >  	/* Quiescent state needed on some other CPU, send IPI. */
> >  	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
> >  	put_cpu();
> > -- 
> > 2.25.1
> >
diff mbox series

Patch

diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
index be667583a554..ae8dcfd4486c 100644
--- a/kernel/rcu/tree_exp.h
+++ b/kernel/rcu/tree_exp.h
@@ -865,6 +865,8 @@  static void sync_sched_exp_online_cleanup(int cpu)
 		put_cpu();
 		return;
 	}
+
+	WARN_ON_ONCE(my_cpu != cpu);
 	/* Quiescent state needed on some other CPU, send IPI. */
 	ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
 	put_cpu();