From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.70.183.196 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796291481; b=df1K+yBT5i4WUVHrmBFXDEpnlJreH4ze9kRwcI8RVMvzkA2Xnk+Nj7hGBJLsrwxwUwiS YkI4fA471qllxDAdibaAJie+QnxjE9J62bQxzGUWndkr6ZuzNn7EA8g7xlE9uSxBihQ3w NSJlpmVbhYOsMWyrBYq2THO2V+yzwDW5EAWr4BqMiTcH3YOAJ6gSLva7T18RZVtbaw3Rd dmdxJqKiXDHbWmYfGakRMossholmIWwIXhj4oOpNDcb+mTRTUArph8jPbC64Ax5MjK1Ro qVS7lMqDVju1RPGvyEJuLiaIoZFWG1BJwmJ3bUo0ckP7KdalHDD2lObzeb1EG8t7DOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291481; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To: References:User-Agent:Date:Message-ID:MIME-Version:Content-Type: X-GND-Sasl:X-GND-Score:X-GND-Cause:X-GND-State; bh=YNTugMeRsSySYgVQjjjjXNbuML2QAbtEODLJA9PXstk=; b=t/v1gJYZhH3UlUfTIjcnkihktSX9bTQ8S/G6qHvXZZY5ISD66yjGHPpKS/rxnh3NRtVk HqhpNEuegoNGBASySXz5bvBGd7SMC41Ofdfn8bRgk7/q9orF9vuTY4olziuNwsStQwvux 4P7/4nGDiefQrV9LXAc+ifanRvefD65w29J1YOHN+7q+NgLZxwMJ8o7KE+qgPFD8UoCZQ fc8SOdw5QtAd2/9JADSJ5K33gYZqQCs2Yf5oKdaDlTuCa6bkS/FiEhI737vLjYP8Z/ezN kOeUcMtjRmGihBxMdgYV/4pMCXcMvP7WmglYIYCyeERQKFLQt56bKJ2p9nHRjk6QROQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=xenomai.org; spf=pass smtp.mailfrom=xenomai.org; dkim=pass header.d=xenomai.org header.i=@xenomai.org header.a=rsa-sha256 header.s=gm1 header.b=eT04dlpj; arc=none smtp.remote-ip=217.70.183.196 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5BBD606A32D for ; Thu, 3 Dec 2026 09:51:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A5BBD606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xenomai.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xenomai.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=xenomai.org header.i=@xenomai.org header.a=rsa-sha256 header.s=gm1 header.b=eT04dlpj Received: by mail.gandi.net (Postfix) with ESMTPSA id C67463EC03; Thu, 3 Dec 2026 09:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xenomai.org; s=gm1; t=1796291472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YNTugMeRsSySYgVQjjjjXNbuML2QAbtEODLJA9PXstk=; b=eT04dlpjQTjM8BR5m5RkgNoW2OPD/kOWFvFc9OOlLuRSExnv3fsijK4HoYrB39nh3nCC8F GRfcmqSp7sciO/PaT2Y95D2kBBM909BsJBDvWfGmwJPUDkWWHhTc/r9WROA/CmiwBqTzdF aGhtaY/hoG87/4R+rQIOhPvwcr3CSOSmFvBdEdzKVPnGeCGFfZxreKt3yXeOAb54D7CkJd G0BoMv0omhmKCpYOIQKTHxtynMWuhNxURoyjCx/EXAjvBl8S8/xVA22JQU3G3ESJjAwrMq pW7n7G1j7twAVgS9oT7CIOf7Ejbmedvpo52thuCj1aSbX3ekfBlHQIrakZ1sLA== From: Philippe Gerum To: Florian Bezdeka Cc: Jan Kiszka , Xenomai Subject: Re: [dovetail][PATCH] x86: dovetail: Notify the core before emulating UMIP and vsyscalls on #GP In-Reply-To: (Florian Bezdeka's message of "Thu, 03 Dec 2026 10:22:51 +0100") References: User-Agent: mu4e 1.12.12; emacs 30.2 Date: Thu, 03 Dec 2026 10:51:11 +0100 Message-ID: <874icun14g.fsf@xenomai.org> X-Mailing-List: xenomai@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: rpm@xenomai.org X-GND-Score: -100 X-GND-Cause: dmFkZTGs8E7TauPt8Q7RRgFCchNN5OwMDxZry/VwipUePCWK+76dKlMv0KpzZ/cDiGTW8p1yjBAT3+cPc2ng4/quI196MbPUqWcngV/nBEHBCj4fzviB7j7penCBxeBWK0Rk4TryewLIfCv/L1BngwXnN8ZurXJ71K8okoNqPzGSzDi5mz3WHiPbIenTJfpT3KCAhmfzM25LSkJQ/6MkQZdQ7rJWyoeYIvYxx8oZ6k4ERs7Pe8ewtiY+XDDFYmJ087XZEUPfC/+maT3AtEb3Vw+hahwmOrdK/FSLUgrQwG/5+la12y3/X6hqWhGJtKWfSGPkm9tx2sGqFXBHDsfGytV39ZYcZGT8Q2M1S9CzvLk/Mu4AUvs+SZ3d4pGIXoAbnpQ/CmUKuux2dv7udoxGVXWwdyv0wWHnRbk2jkQxhHodjYI/+npyjDkAevbyUPWFR1WHgdXyB4nOYqX91QYXynWlT8nJ+OAcIm3u1/rfHowOcXgg3jpDgqeFsg4nzBpBSdZHpx583qX4yYkuEY/gloE73yTKnUS68Rsnxmu1AJGpV6QmEC4o0LKKHtOBoSIGgHcPw6ZcTO5WEF6R5/Ko76SvcZG/vBRVuqSg0HlBO/+iFiHMJioSNPz7rKn03hb5IhI9qIziHsqB98RajZ9h4/V9IMtxhjBUcBFj0luTj7P0kwayrg X-GND-State: clean Florian Bezdeka writes: > On Thu, 2026-11-12 at 08:35 +0100, Jan Kiszka wrote: >> From: Jan Kiszka >> >> 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 >> --- >> >> 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.