From: "Lai, Yi" <yi1.lai@intel.com>
To: Peter Zijlstra <peterz@infradead.org>, Xin Li <xin@zytor.com>
Cc: Andy Lutomirski <luto@kernel.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andrew Cooper <andrew.cooper3@citrix.com>, Xin Li <xin@zytor.com>,
the arch/x86 maintainers <x86@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>, Shuah Khan <shuah@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-kselftest@vger.kernel.org, yi1.lai@linux.intel.com
Subject: Re: [PATCH v3] selftests/x86: Fix sysret_rip assertion failure on FRED systems
Date: Tue, 31 Mar 2026 10:21:34 +0800 [thread overview]
Message-ID: <acsvrv0gCwTI9rWI@ly-workstation> (raw)
In-Reply-To: <20260327123315.GR2872@noisy.programming.kicks-ass.net>
On Fri, Mar 27, 2026 at 01:33:15PM +0100, Peter Zijlstra wrote:
> On Thu, Mar 26, 2026 at 03:06:05PM -0700, Andy Lutomirski wrote:
> >
> >
> > On Thu, Mar 26, 2026, at 2:44 AM, Yi Lai wrote:
> > > The existing 'sysret_rip' selftest asserts that 'regs->r11 ==
> > > regs->flags'. This check relies on the behavior of the SYSCALL
> > > instruction on legacy x86_64, which saves 'RFLAGS' into 'R11'.
> > >
> > > However, on systems with FRED (Flexible Return and Event Delivery)
> > > enabled, instead of using registers, all state is saved onto the stack.
> > > Consequently, 'R11' retains its userspace value, causing the assertion
> > > to fail.
> > >
> > > Fix this by detecting if FRED is enabled and skipping the register
> > > assertion in that case. The detection is done by checking if the RPL
> > > bits of the GS selector are preserved after a hardware exception.
> > > IDT (via IRET) clears the RPL bits of NULL selectors, while FRED (via
> > > ERETU) preserves them.
> > >
> >
> > I don't really like this. I think we have two credible choices:
> >
> > 1. Define the Linux ABI to be that, on FRED systems, SYSCALL preserves
> > R11 and RCX on entry and exit. And update the test to actually test
> > this.
> >
> > 2. Define the Linux ABI to be what it has been for quite a few years:
> > SYSCALL entry copies RFLAGS to R11 and RIP to RCX and SYSCALL exit
> > preserves all registers.
> >
> > I'm in favor of #2. People love making new programming languages and
> > runtimes and inline asm and, these days, vibe coded crap. And it's
> > *easier* to emit a SYSCALL and forget to tell the compiler / code
> > generator that RCX and R11 are clobbered than it is to remember that
> > they're clobbered. And it's easy to test on FRED (well, not really,
> > but it hopefully will be some day) and it's easy to publish one's
> > code, and then everyone is a bit screwed when the resulting program
> > crashes sometimes on non-FRED systems. And it will be miserable to
> > debug.
> >
> > (It's *really* *really* easy to screw this up in a way that sort of
> > works even on non-FRED: RCX and R11 are usually clobbered across
> > function calls, so one can get into a situation in which one's
> > generated code usually doesn't require that SYSCALL preserve one of
> > these registers until an inlining decision changes or some code gets
> > reordered, and then it will start failing. And making the failure
> > depend on hardware details is just nasty.
> >
> > So I think we should add the ~2 lines of code to fix the SYSCALL entry
> > on FRED to match non-FRED.
>
> Yes; I'm afraid I have to concur. Preserving the clobber on entry for
> FRED systems is by far the safest choice.
>
> Aside from this selftest, fancy debuggers and anything that can transfer
> userspace state between machines might be 'surprised'.
Thanks Andy and Peter.
Indeed, making the selftest branch on FRED vs. non-FRED behavior
is not a good practice. The selftest should validate ABI consistency.
I agree with Andy's option #2, so this should be fixed in the FRED
syscall entry implementation.
Li Xin, does this direction look right to you? I can assit with
validation and keep the selftest aligned with the agreed ABI.
Regards,
Yi Lai
next prev parent reply other threads:[~2026-03-31 2:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 9:44 [PATCH v3] selftests/x86: Fix sysret_rip assertion failure on FRED systems Yi Lai
2026-03-26 22:06 ` Andy Lutomirski
2026-03-27 12:33 ` Peter Zijlstra
2026-03-31 2:21 ` Lai, Yi [this message]
2026-03-31 6:03 ` Xin Li
2026-04-01 1:59 ` Xin Li
2026-04-01 2:48 ` H. Peter Anvin
2026-04-01 14:36 ` Xin Li
2026-04-01 17:54 ` H. Peter Anvin
2026-04-02 13:21 ` Andy Lutomirski
2026-04-03 17:32 ` H. Peter Anvin
-- strict thread matches above, loose matches on Subject: below --
2026-04-01 14:59 Xin Li
2026-04-01 15:18 ` H. Peter Anvin
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=acsvrv0gCwTI9rWI@ly-workstation \
--to=yi1.lai@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
--cc=yi1.lai@linux.intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox