From: Frederic Weisbecker <frederic@kernel.org>
To: "Zhang, Qiang1" <qiang1.zhang@intel.com>
Cc: "paulmck@kernel.org" <paulmck@kernel.org>,
"joel@joelfernandes.org" <joel@joelfernandes.org>,
"rcu@vger.kernel.org" <rcu@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rcu: Avoid invalid wakeup for rcuc kthreads in RCU_KTHREAD_OFFCPU status
Date: Wed, 16 Nov 2022 16:01:30 +0100 [thread overview]
Message-ID: <20221116150130.GD816333@lothringen> (raw)
In-Reply-To: <PH0PR11MB5880FD7499114743BCE3E5A3DA079@PH0PR11MB5880.namprd11.prod.outlook.com>
On Wed, Nov 16, 2022 at 02:07:28PM +0000, Zhang, Qiang1 wrote:
> On Tue, Nov 15, 2022 at 09:19:26PM +0800, Zqiang wrote:
> >And more important! On unpark time RCU_KTHREAD_OFFCPU isn't cleared. Only the
> >rcuc kthread does it, and after your patch it couldn't be awaken to perform
> >that, unless rcuc is lucky enough to have rcu_data.rcu_cpu_has_work = 1
> >by the time it unparks and that isn't guaranteed. So rcuc may sleep forever.
>
> Thanks for review, yes I should register an unpark function to clear RCU_KTHREAD_OFFCPU.
> Is the following modification more appropriate?
>
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 3ccad468887e..a2248af0ccda 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -2375,7 +2375,8 @@ static void rcu_wake_cond(struct task_struct *t, int status)
> * If the thread is yielding, only wake it when this
> * is invoked from idle
> */
> - if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)))
> + if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)) &&
> + status != RCU_KTHREAD_OFFCPU)
> wake_up_process(t);
> }
>
> @@ -2407,7 +2408,14 @@ static void invoke_rcu_core(void)
>
> static void rcu_cpu_kthread_park(unsigned int cpu)
> {
> - per_cpu(rcu_data.rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
> + WARN_ON_ONCE(cpu != smp_processor_id());
> + __this_cpu_write(rcu_data.rcu_cpu_kthread_status, RCU_KTHREAD_OFFCPU);
> +}
> +
> +static void rcu_cpu_kthread_unpark(unsigned int cpu)
> +{
> + WARN_ON_ONCE(cpu != smp_processor_id());
> + __this_cpu_write(rcu_data.rcu_cpu_kthread_status, RCU_KTHREAD_ONCPU);
> }
>
> static int rcu_cpu_kthread_should_run(unsigned int cpu)
> @@ -2460,6 +2468,7 @@ static struct smp_hotplug_thread rcu_cpu_thread_spec = {
> .thread_comm = "rcuc/%u",
> .setup = rcu_cpu_kthread_setup,
> .park = rcu_cpu_kthread_park,
> + .unpark = rcu_cpu_kthread_unpark,
Well, personally I don't think it's worth the burden because wake_up_process()
already does an early exit if it's not dealing with a TASK_[UN]INTERRUPTIBLE task and
the window is so short and rare that it doesn't look like a good candidate for
extra optimization;
Thanks.
next prev parent reply other threads:[~2022-11-16 15:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 13:19 [PATCH] rcu: Avoid invalid wakeup for rcuc kthreads in RCU_KTHREAD_OFFCPU status Zqiang
2022-11-16 12:47 ` Frederic Weisbecker
2022-11-16 14:07 ` Zhang, Qiang1
2022-11-16 15:01 ` Frederic Weisbecker [this message]
2022-11-16 23:23 ` Zhang, Qiang1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221116150130.GD816333@lothringen \
--to=frederic@kernel.org \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang1.zhang@intel.com \
--cc=rcu@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.