Skip to contentSkip to conversation

cobalt/posix/process: Sync on thread-hosted irq_work items before exiting

PATCH New Jan Kiszka 1 participant 1 message Oct 8, 2024

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 cobalt/posix/process: Sync on thread-hosted irq_work items before exiting

From: Jan Kiszka <[email protected]>

Better safe than sorry: Due to migrations, there could theoretically still be signal or relaxation work pending on different CPU. To avoid reaping the carpet underneath of them, sync on all per-thread work_irq items when a former RT thread is terminating.

Backport of a1029bef54ff78bc01795032aee5bdec7c86fe41, only addressing dovetail due to lacking sync support of I-pipe.

---
 include/cobalt/kernel/dovetail/pipeline/inband_work.h | 3 +++
 include/cobalt/kernel/ipipe/pipeline/inband_work.h    | 3 +++
 kernel/cobalt/posix/process.c                         | 5 +++++
 3 files changed, 11 insertions(+)
include/cobalt/kernel/dovetail/pipeline/inband_work.h +3 -0
index af3d70fc69..826785e437 100644
@@ -25,4 +25,7 @@ struct pipeline_inband_work {
 #define pipeline_post_inband_work(__work)				\
 			irq_work_queue(&(__work)->inband_work.work)
 
+#define pipeline_sync_inband_work(__work)				\
+			irq_work_sync(&(__work)->inband_work.work)
+
 #endif /* !_COBALT_KERNEL_DOVETAIL_INBAND_WORK_H */
include/cobalt/kernel/ipipe/pipeline/inband_work.h +3 -0
index 12ef07b00a..03e5f97e4a 100644
@@ -29,4 +29,7 @@ struct pipeline_inband_work {
 #define pipeline_post_inband_work(__work)	\
 	ipipe_post_work_root(__work, inband_work.work)
 
+/* unsafe, but I-pipe provided no equivalent */
+#define pipeline_sync_inband_work(__work)	do {} while(0)
+
 #endif /* !_COBALT_KERNEL_IPIPE_INBAND_WORK_H */
kernel/cobalt/posix/process.c +5 -0
index 935007f821..d789c4cdd9 100644
@@ -838,6 +838,7 @@ static void __handle_taskexit_event(struct task_struct *p)
 {
 	struct cobalt_ppd *sys_ppd;
 	struct xnthread *thread;
+	unsigned int n;
 	spl_t s;
 
 	/*
@@ -861,6 +862,10 @@ static void __handle_taskexit_event(struct task_struct *p)
 
 	xnthread_run_handler_stack(thread, exit_thread);
 
+	for (n = 0; n < XNTHREAD_MAX_SIGNALS; n++)
+		pipeline_sync_inband_work(&thread->sigarray[n]);
+	pipeline_sync_inband_work(&thread->relax_work);
+
 	if (xnthread_test_state(thread, XNUSER)) {
 		cobalt_umm_free(&cobalt_kernel_ppd.umm, thread->u_window);
 		thread->u_window = NULL;
Signature · 1 line
2.43.0