All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86: dovetail: reinstate I/O bitmap on user entry
@ 2022-04-03 14:43 Philippe Gerum
  2022-04-03 16:32 ` Richard Weinberger
  0 siblings, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2022-04-03 14:43 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

We have to fix up the TSS with the proper I/O bitmap settings in
arch_dovetail_switch_finish() when the incoming Dovetail-enabled task
is about to re-enter user mode.

This fixes an application crash observed when such a task would rely
on iopl() to raise its I/O permissions then block, relinquishing the
CPU to another task invalidating them, before the former eventually
resumes in user mode.

See https://xenomai.org/pipermail/xenomai/2022-March/047451.html.

Reported-by: Richard Weinberger <richard.weinberger@gmail.com>
Tested-by: Richard Weinberger <richard.weinberger@gmail.com>
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 arch/x86/include/asm/dovetail.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/dovetail.h b/arch/x86/include/asm/dovetail.h
index 9cf811fe98ba..940726f16f2e 100644
--- a/arch/x86/include/asm/dovetail.h
+++ b/arch/x86/include/asm/dovetail.h
@@ -9,6 +9,7 @@
 #if !defined(__ASSEMBLY__) && defined(CONFIG_DOVETAIL)
 
 #include <asm/fpu/api.h>
+#include <asm/io_bitmap.h>
 
 static inline void arch_dovetail_exec_prepare(void)
 {
@@ -25,11 +26,18 @@ void arch_dovetail_switch_prepare(bool leave_inband)
 static inline
 void arch_dovetail_switch_finish(bool enter_inband)
 {
-	if (enter_inband)
+	unsigned int ti_work = READ_ONCE(current_thread_info()->flags);
+
+	if (unlikely(ti_work & _TIF_IO_BITMAP))
+		tss_update_io_bitmap();
+
+	if (enter_inband) {
 		fpu__resume_inband();
-	else if (!(current->flags & PF_KTHREAD) &&
-		test_thread_flag(TIF_NEED_FPU_LOAD))
-		switch_fpu_return();
+	} else {
+		  if (unlikely(ti_work & _TIF_NEED_FPU_LOAD &&
+				  !(current->flags & PF_KTHREAD)))
+			  switch_fpu_return();
+	}
 }
 
 #endif
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-04-06 10:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-03 14:43 [PATCH v2] x86: dovetail: reinstate I/O bitmap on user entry Philippe Gerum
2022-04-03 16:32 ` Richard Weinberger
2022-04-03 17:49   ` Philippe Gerum
2022-04-03 19:41     ` Florian Bezdeka
2022-04-03 19:59       ` Richard Weinberger
2022-04-04  9:29     ` Richard Weinberger
2022-04-04 16:22       ` Philippe Gerum
2022-04-04 17:48         ` Richard Weinberger
2022-04-06  9:13         ` Wolfgang Denk
2022-04-06  9:21           ` Jan Kiszka
2022-04-06 10:14             ` Philippe Gerum

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.