From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: linux-rt-users <linux-rt-users@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
Scott Wood <swood@redhat.com>
Subject: [PATCH RT] sched: migrate_enable: Busy loop until the migration request is completed
Date: Thu, 12 Dec 2019 12:27:17 +0100 [thread overview]
Message-ID: <20191212112717.2tzoqbe3xeknoyvs@linutronix.de> (raw)
If user task changes the CPU affinity mask of a running task it will
dispatch migration request if the current CPU is no longer allowed. This
might happen shortly before a task enters a migrate_disable() section.
Upon leaving the migrate_disable() section, the task will notice that
the current CPU is no longer allowed and will will dispatch its own
migration request to move it off the current CPU.
While invoking __schedule() the first migration request will be
processed and the task returns on the "new" CPU with "arg.done = 0". Its
own migration request will be processed shortly after and will result in
memory corruption if the stack memory, designed for request, was used
otherwise in the meantime.
Spin until the migration request has been processed if it was accepted.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/sched/core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8bea013b2baf5..5c7be96ca68c4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8227,7 +8227,7 @@ void migrate_enable(void)
WARN_ON(smp_processor_id() != cpu);
if (!is_cpu_allowed(p, cpu)) {
- struct migration_arg arg = { p };
+ struct migration_arg arg = { .task = p };
struct cpu_stop_work work;
struct rq_flags rf;
@@ -8239,7 +8239,10 @@ void migrate_enable(void)
stop_one_cpu_nowait(task_cpu(p), migration_cpu_stop,
&arg, &work);
__schedule(true);
- WARN_ON_ONCE(!arg.done && !work.disabled);
+ if (!work.disabled) {
+ while (!arg.done)
+ cpu_relax();
+ }
}
out:
--
2.24.0
next reply other threads:[~2019-12-12 11:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-12 11:27 Sebastian Andrzej Siewior [this message]
2019-12-13 6:44 ` [PATCH RT] sched: migrate_enable: Busy loop until the migration request is completed Scott Wood
2019-12-13 8:14 ` Sebastian Andrzej Siewior
2020-01-22 21:13 ` Scott Wood
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=20191212112717.2tzoqbe3xeknoyvs@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=swood@redhat.com \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).