All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] cobalt: Fix handling of invalid thread affinities during hardening
@ 2021-07-05 10:41 Jan Kiszka
  0 siblings, 0 replies; only message in thread
From: Jan Kiszka @ 2021-07-05 10:41 UTC (permalink / raw)
  To: Xenomai

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-05 10:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 10:41 [PATCH v2] cobalt: Fix handling of invalid thread affinities during hardening Jan Kiszka

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.