From: Peter Zijlstra <peterz@infradead.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Boqun Feng <boqun.feng@gmail.com>,
linux-kernel@vger.kernel.org, Will Deacon <will@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
Nicholas Piggin <npiggin@gmail.com>,
Andy Lutomirski <luto@amacapital.net>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RFC PATCH 2/3] sched: membarrier: cover kthread_use_mm (v3)
Date: Wed, 7 Oct 2020 17:07:04 +0200 [thread overview]
Message-ID: <20201007150704.GH2628@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200924172508.8724-3-mathieu.desnoyers@efficios.com>
On Thu, Sep 24, 2020 at 01:25:07PM -0400, Mathieu Desnoyers wrote:
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 2d95dc3f4644..bab6f4f2809f 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3736,6 +3736,8 @@ context_switch(struct rq *rq, struct task_struct *prev,
> */
> arch_start_context_switch(prev);
>
> + membarrier_switch_mm(rq, prev->mm, next->mm);
> +
> /*
> * kernel -> kernel lazy + transfer active
> * user -> kernel lazy + mmgrab() active
> @@ -3752,7 +3754,6 @@ context_switch(struct rq *rq, struct task_struct *prev,
> else
> prev->active_mm = NULL;
> } else { // to user
> - membarrier_switch_mm(rq, prev->active_mm, next->mm);
> /*
> * sys_membarrier() requires an smp_mb() between setting
> * rq->curr / membarrier_switch_mm() and returning to userspace.
I was thinking... do we need the above, when:
> diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c
> index 8bc8b8a888b7..e5246580201b 100644
> --- a/kernel/sched/membarrier.c
> +++ b/kernel/sched/membarrier.c
> @@ -112,13 +112,9 @@ static int membarrier_global_expedited(void)
> MEMBARRIER_STATE_GLOBAL_EXPEDITED))
> continue;
>
> - /*
> - * Skip the CPU if it runs a kernel thread. The scheduler
> - * leaves the prior task mm in place as an optimization when
> - * scheduling a kthread.
> - */
> + /* Skip the CPU if it runs the idle thread. */
> p = rcu_dereference(cpu_rq(cpu)->curr);
> - if (p->flags & PF_KTHREAD)
We retain this in the form:
if ((p->flags & PF_KTHREAD) && !p-mm)
continue;
> + if (is_idle_task(p))
> continue;
>
> __cpumask_set_cpu(cpu, tmpmask);
Specifically, we only care about kthreads when they're between
kthread_use_mm() / kthread_unuse_mm(), and in that case they will have
updated state already.
It's too late in the day to be sure about the memory ordering though;
but if we see !->mm, they'll do/have-done switch_mm() which implies
sufficient barriers().
Hmm?
next prev parent reply other threads:[~2020-10-07 15:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 17:25 [RFC PATCH 0/3] Membarrier updates Mathieu Desnoyers
2020-09-24 17:25 ` [RFC PATCH 1/3] sched: fix exit_mm vs membarrier (v3) Mathieu Desnoyers
2020-10-07 14:29 ` Peter Zijlstra
2020-10-07 14:57 ` Mathieu Desnoyers
2020-10-07 15:09 ` Peter Zijlstra
2020-09-24 17:25 ` [RFC PATCH 2/3] sched: membarrier: cover kthread_use_mm (v3) Mathieu Desnoyers
2020-10-02 8:33 ` [sched] bdfcae1140: will-it-scale.per_thread_ops -37.0% regression kernel test robot
2020-10-07 14:50 ` Mathieu Desnoyers
2020-10-20 3:24 ` [LKP] " Xing Zhengjun
2020-10-20 13:14 ` Mathieu Desnoyers
2020-10-22 1:54 ` Xing Zhengjun
2020-10-22 13:19 ` Mathieu Desnoyers
2020-10-23 5:37 ` Xing Zhengjun
2020-10-23 12:34 ` Mathieu Desnoyers
2020-10-07 15:07 ` Peter Zijlstra [this message]
2020-10-07 15:39 ` [RFC PATCH 2/3] sched: membarrier: cover kthread_use_mm (v3) Mathieu Desnoyers
2020-10-07 16:08 ` Peter Zijlstra
2020-10-07 16:11 ` Mathieu Desnoyers
2020-09-24 17:25 ` [RFC PATCH 3/3] sched: membarrier: document memory ordering scenarios Mathieu Desnoyers
2020-09-29 17:16 ` [RFC PATCH 0/3] Membarrier updates Mathieu Desnoyers
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=20201007150704.GH2628@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mathieu.desnoyers@efficios.com \
--cc=npiggin@gmail.com \
--cc=paulmck@kernel.org \
--cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox