* [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP
@ 2026-11-12 7:35 Jan Kiszka
2026-12-03 9:22 ` Florian Bezdeka
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2026-11-12 7:35 UTC (permalink / raw)
To: Philippe Gerum, Florian Bezdeka, Xenomai
From: Jan Kiszka <jan.kiszka@siemens.com>
exc_general_protection() runs the user mode fixups before notifying
the companion core about the trap, so they run on the oob stage when
an oob thread takes the #GP. Two of them cannot run from there:
- fixup_umip_exception() takes mm->context.ldt_usr_sem, a sleeping
lock, to emulate SLDT. If the result cannot be written to a memory
operand, e.g. because it lies outside of the user address range,
which copy_to_user() rejects without faulting, the emulation sends
SIGSEGV via force_sig_fault(), taking the in-band siglock. The core
is never told about the trap, the thread returns to user mode on
the oob stage and re-executes the instruction. If the write faults
instead, the core gets notified about the nested page fault rather
than the #GP.
- emulate_vsyscall_gp(), which handles vsyscalls on CPUs with LASS,
runs the seccomp filters, sends signals and invokes the gettimeofday,
time and getcpu syscall handlers. gettimeofday reads the timekeeper
under its seqcount, whose in-band writer may have been preempted by
the oob stage on the same CPU, so the reader may spin forever.
Without LASS, vsyscalls trap via #PF, and do_user_addr_fault() already
notifies the core before emulating them.
Notify the core before the UMIP and vsyscall emulations. A thread
using these instructions or vsyscalls from the oob stage is now
demoted, as for any other trap requiring in-band handling.
The vDSO fixup only redirects the register frame and stays ahead of
the notification. So does the iopl fixup, which turns CLI/STI into
NOPs for tasks which called iopl(3): notifying first would demote such
a thread on every CLI/STI it executes.
Assisted-by: opencode:Opus-5.5
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
New day, new LLM patch. The reasoning about what could go wrong from OOB
while emulating makes sense to me. I'm also not seeing any regressions
that could be caused by migrating earlier, enforcing inband - no
legitimate OOB call path should have taken this route so far.
arch/x86/kernel/traps.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index a082670f0e1f8..26a30aa31960d 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -1030,14 +1030,22 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection)
if (fixup_vdso_exception(regs, X86_TRAP_GP, error_code, 0))
goto exit;
- if (fixup_umip_exception(regs))
+ /*
+ * Dovetail: the UMIP and vsyscall emulations may take
+ * sleeping locks, run syscalls and send signals, which
+ * the oob stage cannot do. Have the companion core
+ * demote the current context first, like
+ * do_user_addr_fault() does before emulating a
+ * vsyscall in the #PF path.
+ */
+ if (!mark_trap_entry(X86_TRAP_GP, regs))
goto exit;
- if (emulate_vsyscall_gp(regs))
- goto exit;
+ if (fixup_umip_exception(regs))
+ goto mark_exit;
- if (!mark_trap_entry(X86_TRAP_GP, regs))
- goto exit;
+ if (emulate_vsyscall_gp(regs))
+ goto mark_exit;
gp_user_force_sig_segv(regs, X86_TRAP_GP, error_code, desc);
goto mark_exit;
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP
2026-11-12 7:35 [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP Jan Kiszka
@ 2026-12-03 9:22 ` Florian Bezdeka
2026-12-03 9:51 ` Philippe Gerum
0 siblings, 1 reply; 3+ messages in thread
From: Florian Bezdeka @ 2026-12-03 9:22 UTC (permalink / raw)
To: Philippe Gerum; +Cc: Jan Kiszka, Xenomai
On Thu, 2026-11-12 at 08:35 +0100, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> exc_general_protection() runs the user mode fixups before notifying
> the companion core about the trap, so they run on the oob stage when
> an oob thread takes the #GP. Two of them cannot run from there:
>
> - fixup_umip_exception() takes mm->context.ldt_usr_sem, a sleeping
> lock, to emulate SLDT. If the result cannot be written to a memory
> operand, e.g. because it lies outside of the user address range,
> which copy_to_user() rejects without faulting, the emulation sends
> SIGSEGV via force_sig_fault(), taking the in-band siglock. The core
> is never told about the trap, the thread returns to user mode on
> the oob stage and re-executes the instruction. If the write faults
> instead, the core gets notified about the nested page fault rather
> than the #GP.
>
> - emulate_vsyscall_gp(), which handles vsyscalls on CPUs with LASS,
> runs the seccomp filters, sends signals and invokes the gettimeofday,
> time and getcpu syscall handlers. gettimeofday reads the timekeeper
> under its seqcount, whose in-band writer may have been preempted by
> the oob stage on the same CPU, so the reader may spin forever.
>
> Without LASS, vsyscalls trap via #PF, and do_user_addr_fault() already
> notifies the core before emulating them.
>
> Notify the core before the UMIP and vsyscall emulations. A thread
> using these instructions or vsyscalls from the oob stage is now
> demoted, as for any other trap requiring in-band handling.
>
> The vDSO fixup only redirects the register frame and stays ahead of
> the notification. So does the iopl fixup, which turns CLI/STI into
> NOPs for tasks which called iopl(3): notifying first would demote such
> a thread on every CLI/STI it executes.
>
> Assisted-by: opencode:Opus-5.5
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>
> New day, new LLM patch. The reasoning about what could go wrong from OOB
> while emulating makes sense to me. I'm also not seeing any regressions
> that could be caused by migrating earlier, enforcing inband - no
> legitimate OOB call path should have taken this route so far.
>
> arch/x86/kernel/traps.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> index a082670f0e1f8..26a30aa31960d 100644
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -1030,14 +1030,22 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection)
> if (fixup_vdso_exception(regs, X86_TRAP_GP, error_code, 0))
> goto exit;
>
> - if (fixup_umip_exception(regs))
> + /*
> + * Dovetail: the UMIP and vsyscall emulations may take
> + * sleeping locks, run syscalls and send signals, which
> + * the oob stage cannot do. Have the companion core
> + * demote the current context first, like
> + * do_user_addr_fault() does before emulating a
> + * vsyscall in the #PF path.
> + */
> + if (!mark_trap_entry(X86_TRAP_GP, regs))
> goto exit;
>
> - if (emulate_vsyscall_gp(regs))
> - goto exit;
> + if (fixup_umip_exception(regs))
> + goto mark_exit;
>
> - if (!mark_trap_entry(X86_TRAP_GP, regs))
> - goto exit;
> + if (emulate_vsyscall_gp(regs))
> + goto mark_exit;
>
> gp_user_force_sig_segv(regs, X86_TRAP_GP, error_code, desc);
> goto mark_exit;
> --
> 2.47.3
Philippe, this one is still not applied. Any concerns / feedback?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP
2026-12-03 9:22 ` Florian Bezdeka
@ 2026-12-03 9:51 ` Philippe Gerum
0 siblings, 0 replies; 3+ messages in thread
From: Philippe Gerum @ 2026-12-03 9:51 UTC (permalink / raw)
To: Florian Bezdeka; +Cc: Jan Kiszka, Xenomai
Florian Bezdeka <florian.bezdeka@siemens.com> writes:
> On Thu, 2026-11-12 at 08:35 +0100, Jan Kiszka wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> exc_general_protection() runs the user mode fixups before notifying
>> the companion core about the trap, so they run on the oob stage when
>> an oob thread takes the #GP. Two of them cannot run from there:
>>
>> - fixup_umip_exception() takes mm->context.ldt_usr_sem, a sleeping
>> lock, to emulate SLDT. If the result cannot be written to a memory
>> operand, e.g. because it lies outside of the user address range,
>> which copy_to_user() rejects without faulting, the emulation sends
>> SIGSEGV via force_sig_fault(), taking the in-band siglock. The core
>> is never told about the trap, the thread returns to user mode on
>> the oob stage and re-executes the instruction. If the write faults
>> instead, the core gets notified about the nested page fault rather
>> than the #GP.
>>
>> - emulate_vsyscall_gp(), which handles vsyscalls on CPUs with LASS,
>> runs the seccomp filters, sends signals and invokes the gettimeofday,
>> time and getcpu syscall handlers. gettimeofday reads the timekeeper
>> under its seqcount, whose in-band writer may have been preempted by
>> the oob stage on the same CPU, so the reader may spin forever.
>>
>> Without LASS, vsyscalls trap via #PF, and do_user_addr_fault() already
>> notifies the core before emulating them.
>>
>> Notify the core before the UMIP and vsyscall emulations. A thread
>> using these instructions or vsyscalls from the oob stage is now
>> demoted, as for any other trap requiring in-band handling.
>>
>> The vDSO fixup only redirects the register frame and stays ahead of
>> the notification. So does the iopl fixup, which turns CLI/STI into
>> NOPs for tasks which called iopl(3): notifying first would demote such
>> a thread on every CLI/STI it executes.
>>
>> Assisted-by: opencode:Opus-5.5
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>
>> New day, new LLM patch. The reasoning about what could go wrong from OOB
>> while emulating makes sense to me. I'm also not seeing any regressions
>> that could be caused by migrating earlier, enforcing inband - no
>> legitimate OOB call path should have taken this route so far.
>>
>> arch/x86/kernel/traps.c | 18 +++++++++++++-----
>> 1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
>> index a082670f0e1f8..26a30aa31960d 100644
>> --- a/arch/x86/kernel/traps.c
>> +++ b/arch/x86/kernel/traps.c
>> @@ -1030,14 +1030,22 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection)
>> if (fixup_vdso_exception(regs, X86_TRAP_GP, error_code, 0))
>> goto exit;
>>
>> - if (fixup_umip_exception(regs))
>> + /*
>> + * Dovetail: the UMIP and vsyscall emulations may take
>> + * sleeping locks, run syscalls and send signals, which
>> + * the oob stage cannot do. Have the companion core
>> + * demote the current context first, like
>> + * do_user_addr_fault() does before emulating a
>> + * vsyscall in the #PF path.
>> + */
>> + if (!mark_trap_entry(X86_TRAP_GP, regs))
>> goto exit;
>>
>> - if (emulate_vsyscall_gp(regs))
>> - goto exit;
>> + if (fixup_umip_exception(regs))
>> + goto mark_exit;
>>
>> - if (!mark_trap_entry(X86_TRAP_GP, regs))
>> - goto exit;
>> + if (emulate_vsyscall_gp(regs))
>> + goto mark_exit;
>>
>> gp_user_force_sig_segv(regs, X86_TRAP_GP, error_code, desc);
>> goto mark_exit;
>> --
>> 2.47.3
>
> Philippe, this one is still not applied. Any concerns / feedback?
Not yet, testing.
--
Philippe.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 9:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 7:35 [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP Jan Kiszka
2026-12-03 9:22 ` Florian Bezdeka
2026-12-03 9:51 ` 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.