All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Xenomai <xenomai@xenomai.org>
Subject: [PATCH v2] cobalt: Fix handling of invalid thread affinities during hardening
Date: Mon, 5 Jul 2021 12:41:59 +0200	[thread overview]
Message-ID: <d1e6b053-b6b6-42a5-fdd1-0aa8c2eed7d7@siemens.com> (raw)

From: Jan Kiszka <jan.kiszka@siemens.com>

The I-pipe implementation was lucky in its approach to not wake up the
RT thread in case the non-RT part migrated to an unsupported CPU. For
unclear reasons, the scheduled cancellation made it to the thread and
avoided any lockup. On dovetail, this fails.

So switch both implemenations to the safer pattern of actually
completing the migration, using the previous affinity of the thread. It
will still be canceled right after that, now also over dovetail.

As cobalt_affinity_ok's return value becomes irrelevant, refactor this
function to cobalt_adjust_affinity without and return code.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Changes in v2:
 - fix !SMP wrapper name

 kernel/cobalt/dovetail/kevents.c | 6 ++++--
 kernel/cobalt/ipipe/kevents.c    | 6 ++++--
 kernel/cobalt/posix/process.c    | 8 +++-----
 kernel/cobalt/posix/process.h    | 4 ++--
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/cobalt/dovetail/kevents.c b/kernel/cobalt/dovetail/kevents.c
index 3fbb5e6d64..648929756c 100644
--- a/kernel/cobalt/dovetail/kevents.c
+++ b/kernel/cobalt/dovetail/kevents.c
@@ -307,8 +307,10 @@ void resume_oob_task(struct task_struct *p) /* inband, oob stage stalled */
 	 * relax_thread/harden_thread handlers.
 	 */
 	xnthread_run_handler_stack(thread, harden_thread);
-	if (cobalt_affinity_ok(p))
-		xnthread_resume(thread, XNRELAX);
+
+	cobalt_adjust_affinity(p);
+
+	xnthread_resume(thread, XNRELAX);
 
 	/*
 	 * In case we migrated independently of the user return notifier, clear
diff --git a/kernel/cobalt/ipipe/kevents.c b/kernel/cobalt/ipipe/kevents.c
index 40ad93f398..9bb0204d9f 100644
--- a/kernel/cobalt/ipipe/kevents.c
+++ b/kernel/cobalt/ipipe/kevents.c
@@ -171,8 +171,10 @@ void ipipe_migration_hook(struct task_struct *p) /* hw IRQs off */
 	 * relax_thread/harden_thread handlers.
 	 */
 	xnthread_run_handler_stack(thread, harden_thread);
-	if (cobalt_affinity_ok(p))
-		xnthread_resume(thread, XNRELAX);
+
+	cobalt_adjust_affinity(p);
+
+	xnthread_resume(thread, XNRELAX);
 
 	/*
 	 * In case we migrated independently of the user return notifier, clear
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index aa384155a1..1f059ad830 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -773,7 +773,7 @@ int cobalt_handle_setaffinity_event(struct task_struct *task)
 }
 
 #ifdef CONFIG_SMP
-bool cobalt_affinity_ok(struct task_struct *task) /* nklocked, IRQs off */
+void cobalt_adjust_affinity(struct task_struct *task) /* nklocked, IRQs off */
 {
 	struct xnthread *thread = xnthread_from_task(task);
 	struct xnsched *sched;
@@ -812,12 +812,12 @@ bool cobalt_affinity_ok(struct task_struct *task) /* nklocked, IRQs off */
 		 * in xnthread_harden().
 		 */
 		xnthread_set_info(thread, XNCANCELD);
-		return false;
+		return;
 	}
 
 	sched = xnsched_struct(cpu);
 	if (sched == thread->sched)
-		return true;
+		return;
 
 	/*
 	 * The current thread moved to a supported real-time CPU,
@@ -829,8 +829,6 @@ bool cobalt_affinity_ok(struct task_struct *task) /* nklocked, IRQs off */
 
 	xnthread_run_handler_stack(thread, move_thread, cpu);
 	xnthread_migrate_passive(thread, sched);
-
-	return true;
 }
 #endif /* CONFIG_SMP */
 
diff --git a/kernel/cobalt/posix/process.h b/kernel/cobalt/posix/process.h
index 45964ae57a..279707a680 100644
--- a/kernel/cobalt/posix/process.h
+++ b/kernel/cobalt/posix/process.h
@@ -164,9 +164,9 @@ extern struct xnthread_personality cobalt_personality;
 int cobalt_handle_setaffinity_event(struct task_struct *task);
 
 #ifdef CONFIG_SMP
-bool cobalt_affinity_ok(struct task_struct *task);
+void cobalt_adjust_affinity(struct task_struct *task);
 #else
-#define cobalt_affinity_ok(task)	(true)
+static inline void cobalt_adjust_affinity(struct task_struct *task) { }
 #endif
 
 int cobalt_handle_taskexit_event(struct task_struct *task);
-- 
2.26.2


                 reply	other threads:[~2021-07-05 10:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=d1e6b053-b6b6-42a5-fdd1-0aa8c2eed7d7@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=xenomai@xenomai.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.