* [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish()
@ 2022-04-02 14:21 Philippe Gerum
2022-04-02 14:21 ` [PATCH 2/4] ARM: dovetail: fix up arch_dovetail_switch_finish() signature Philippe Gerum
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Philippe Gerum @ 2022-04-02 14:21 UTC (permalink / raw)
To: xenomai
From: Philippe Gerum <rpm@xenomai.org>
The out-of-band switch tail code may need the thread-info work bits to
reinstate the current context appropriately, pass them to
arch_dovetail_switch_finish().
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
kernel/sched/core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a1159a263894..75b506bb60bb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -10902,6 +10902,7 @@ int dovetail_leave_inband(void)
{
struct task_struct *p = current;
struct irq_pipeline_data *pd;
+ unsigned int ti_work;
unsigned long flags;
preempt_disable();
@@ -10930,7 +10931,8 @@ int dovetail_leave_inband(void)
* architecture-specific fixups (e.g. fpu context reload).
*/
if (likely(__schedule(SM_NONE))) {
- arch_dovetail_switch_finish(false);
+ ti_work = READ_ONCE(current_thread_info()->flags);
+ arch_dovetail_switch_finish(false, ti_work);
return 0;
}
@@ -10987,6 +10989,7 @@ bool dovetail_context_switch(struct dovetail_altsched_context *out,
struct task_struct *next, *prev, *last;
struct mm_struct *prev_mm, *next_mm;
bool inband_tail = false;
+ unsigned long ti_work;
WARN_ON_ONCE(dovetail_debug() && on_pipeline_entry());
@@ -11108,7 +11111,8 @@ bool dovetail_context_switch(struct dovetail_altsched_context *out,
lockdep_write_irqs_state(lockdep_irqs);
}
- arch_dovetail_switch_finish(leave_inband);
+ ti_work = READ_ONCE(current_thread_info()->flags);
+ arch_dovetail_switch_finish(leave_inband, ti_work);
/*
* inband_tail is true whenever we are finalizing a transition
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] ARM: dovetail: fix up arch_dovetail_switch_finish() signature
2022-04-02 14:21 [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Philippe Gerum
@ 2022-04-02 14:21 ` Philippe Gerum
2022-04-02 14:21 ` [PATCH 3/4] arm64: " Philippe Gerum
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Philippe Gerum @ 2022-04-02 14:21 UTC (permalink / raw)
To: xenomai
From: Philippe Gerum <rpm@xenomai.org>
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
arch/arm/include/asm/dovetail.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/dovetail.h b/arch/arm/include/asm/dovetail.h
index 8f3a09391d06..ff754ff4d2db 100644
--- a/arch/arm/include/asm/dovetail.h
+++ b/arch/arm/include/asm/dovetail.h
@@ -25,7 +25,8 @@ static inline void arch_dovetail_exec_prepare(void)
static inline void arch_dovetail_switch_prepare(bool leave_inband)
{ }
-static inline void arch_dovetail_switch_finish(bool enter_inband)
+static inline void arch_dovetail_switch_finish(bool enter_inband,
+ unsigned int ti_work)
{ }
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] arm64: dovetail: fix up arch_dovetail_switch_finish() signature
2022-04-02 14:21 [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Philippe Gerum
2022-04-02 14:21 ` [PATCH 2/4] ARM: dovetail: fix up arch_dovetail_switch_finish() signature Philippe Gerum
@ 2022-04-02 14:21 ` Philippe Gerum
2022-04-02 14:21 ` [PATCH 4/4] x86: dovetail: reinstate I/O bitmap on out-of-band user entry Philippe Gerum
2022-04-02 19:18 ` [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Richard Weinberger
3 siblings, 0 replies; 6+ messages in thread
From: Philippe Gerum @ 2022-04-02 14:21 UTC (permalink / raw)
To: xenomai
From: Philippe Gerum <rpm@xenomai.org>
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
arch/arm64/include/asm/dovetail.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/dovetail.h b/arch/arm64/include/asm/dovetail.h
index 668679399406..f1c6605972cf 100644
--- a/arch/arm64/include/asm/dovetail.h
+++ b/arch/arm64/include/asm/dovetail.h
@@ -27,7 +27,8 @@ static inline void arch_dovetail_exec_prepare(void)
static inline void arch_dovetail_switch_prepare(bool leave_inband)
{ }
-static inline void arch_dovetail_switch_finish(bool enter_inband)
+static inline void arch_dovetail_switch_finish(bool enter_inband,
+ unsigned int ti_work)
{
fpsimd_restore_current_oob();
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] x86: dovetail: reinstate I/O bitmap on out-of-band user entry
2022-04-02 14:21 [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Philippe Gerum
2022-04-02 14:21 ` [PATCH 2/4] ARM: dovetail: fix up arch_dovetail_switch_finish() signature Philippe Gerum
2022-04-02 14:21 ` [PATCH 3/4] arm64: " Philippe Gerum
@ 2022-04-02 14:21 ` Philippe Gerum
2022-04-02 19:18 ` [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Richard Weinberger
3 siblings, 0 replies; 6+ messages in thread
From: Philippe Gerum @ 2022-04-02 14:21 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 current task is about to
re-enter user mode on the out-of-band stage, along with reloading the
fpu context if need be.
This fixes an application crash observed when a user code would rely
on iopl() to raise the current I/O permissions, which would then
relinquish the CPU to a task invalidating them, before the initial
task eventually resumes in user mode on the out-of-band stage
(typically seen during an in-band -> out-of-band stage switch).
See https://xenomai.org/pipermail/xenomai/2022-March/047451.html.
Reported-by: Richard Weinberger <richard.weinberger@gmail.com>
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
arch/x86/include/asm/dovetail.h | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/dovetail.h b/arch/x86/include/asm/dovetail.h
index 9cf811fe98ba..0e0f93cb53d0 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)
{
@@ -23,13 +24,17 @@ void arch_dovetail_switch_prepare(bool leave_inband)
}
static inline
-void arch_dovetail_switch_finish(bool enter_inband)
+void arch_dovetail_switch_finish(bool enter_inband, unsigned int ti_work)
{
- if (enter_inband)
+ 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_IO_BITMAP))
+ tss_update_io_bitmap();
+ 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] 6+ messages in thread
* Re: [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish()
2022-04-02 14:21 [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Philippe Gerum
` (2 preceding siblings ...)
2022-04-02 14:21 ` [PATCH 4/4] x86: dovetail: reinstate I/O bitmap on out-of-band user entry Philippe Gerum
@ 2022-04-02 19:18 ` Richard Weinberger
2022-04-03 14:40 ` Philippe Gerum
3 siblings, 1 reply; 6+ messages in thread
From: Richard Weinberger @ 2022-04-02 19:18 UTC (permalink / raw)
To: Philippe Gerum; +Cc: Xenomai
On Sat, Apr 2, 2022 at 4:23 PM Philippe Gerum via Xenomai
<xenomai@xenomai.org> wrote:
> - arch_dovetail_switch_finish(leave_inband);
> + ti_work = READ_ONCE(current_thread_info()->flags);
> + arch_dovetail_switch_finish(leave_inband, ti_work);
Why are you passing ti_work as parameter? AFAIU you can
use current_thread_info()->flags directly in arch_dovetail_switch_finish().
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish()
2022-04-02 19:18 ` [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Richard Weinberger
@ 2022-04-03 14:40 ` Philippe Gerum
0 siblings, 0 replies; 6+ messages in thread
From: Philippe Gerum @ 2022-04-03 14:40 UTC (permalink / raw)
To: Richard Weinberger; +Cc: Xenomai
Richard Weinberger <richard.weinberger@gmail.com> writes:
> On Sat, Apr 2, 2022 at 4:23 PM Philippe Gerum via Xenomai
> <xenomai@xenomai.org> wrote:
>
>> - arch_dovetail_switch_finish(leave_inband);
>> + ti_work = READ_ONCE(current_thread_info()->flags);
>> + arch_dovetail_switch_finish(leave_inband, ti_work);
>
> Why are you passing ti_work as parameter? AFAIU you can
> use current_thread_info()->flags directly in arch_dovetail_switch_finish().
Agreed, this affects the signature of arch_dovetail_switch_finish() for
no good reason. Besides, this patch is missing a case (task resuming
after oob -> inband transition). v2 follows (tested ok here).
--
Philippe.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-04-03 14:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-02 14:21 [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Philippe Gerum
2022-04-02 14:21 ` [PATCH 2/4] ARM: dovetail: fix up arch_dovetail_switch_finish() signature Philippe Gerum
2022-04-02 14:21 ` [PATCH 3/4] arm64: " Philippe Gerum
2022-04-02 14:21 ` [PATCH 4/4] x86: dovetail: reinstate I/O bitmap on out-of-band user entry Philippe Gerum
2022-04-02 19:18 ` [PATCH 1/4] sched: dovetail: pass thread-info bits to arch_dovetail_switch_finish() Richard Weinberger
2022-04-03 14:40 ` 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.