All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Florian Bezdeka <florian.bezdeka@siemens.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,  Xenomai <xenomai@lists.linux.dev>
Subject: Re: [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP
Date: Thu, 03 Dec 2026 10:51:11 +0100	[thread overview]
Message-ID: <874icun14g.fsf@xenomai.org> (raw)
In-Reply-To: <dc3b56a9780a3ca402b8e835e8e3b3cccf09314b.camel@siemens.com> (Florian Bezdeka's message of "Thu, 03 Dec 2026 10:22:51 +0100")

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.

      reply	other threads:[~2026-12-03  9:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874icun14g.fsf@xenomai.org \
    --to=rpm@xenomai.org \
    --cc=florian.bezdeka@siemens.com \
    --cc=jan.kiszka@siemens.com \
    --cc=xenomai@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.