From: David Laight <david.laight.linux@gmail.com>
To: Yi Lai <yi1.lai@intel.com>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, hpa@zytor.com, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftests/x86: Fix sysret_rip assertion failure on FRED systems
Date: Tue, 24 Mar 2026 11:08:56 +0000 [thread overview]
Message-ID: <20260324110856.5e9e9c76@pumpkin> (raw)
In-Reply-To: <20260320063301.489599-1-yi1.lai@intel.com>
On Fri, 20 Mar 2026 14:33:01 +0800
Yi Lai <yi1.lai@intel.com> 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 FRED support via CPUID (Leaf 0x7, Subleaf 0x1, EAX
> bit 17) and skipping the register assertion if FRED is present.
For the selftest can't you just allow for R11 being unchanged?
That would be much simpler.
It isn't as though the test is doing much more than checking that
R11 is corrupted by being overwritten by EFLAGS.
David
>
> Signed-off-by: Yi Lai <yi1.lai@intel.com>
> ---
> tools/testing/selftests/x86/sysret_rip.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/x86/sysret_rip.c b/tools/testing/selftests/x86/sysret_rip.c
> index 2e423a335e1c..0228d6174d5b 100644
> --- a/tools/testing/selftests/x86/sysret_rip.c
> +++ b/tools/testing/selftests/x86/sysret_rip.c
> @@ -21,6 +21,7 @@
> #include <sys/user.h>
> #include <sys/mman.h>
> #include <assert.h>
> +#include <cpuid.h>
>
> #include "helpers.h"
>
> @@ -64,9 +65,18 @@ static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
> ctx->uc_mcontext.gregs[REG_RIP] = rip;
> ctx->uc_mcontext.gregs[REG_RCX] = rip;
>
> - /* R11 and EFLAGS should already match. */
> - assert(ctx->uc_mcontext.gregs[REG_EFL] ==
> - ctx->uc_mcontext.gregs[REG_R11]);
> + /*
> + * SYSCALL works differently on FRED, it does not save RIP and RFLAGS
> + * to RCX and R11.
> + */
> + unsigned int eax, ebx, ecx, edx;
> +
> + __cpuid_count(0x7, 0x1, eax, ebx, ecx, edx);
> + if (!(eax & (1 << 17))) {
> + /* R11 and EFLAGS should already match. */
> + assert(ctx->uc_mcontext.gregs[REG_EFL] ==
> + ctx->uc_mcontext.gregs[REG_R11]);
> + }
>
> sethandler(SIGSEGV, sigsegv_for_sigreturn_test, SA_RESETHAND);
> }
next prev parent reply other threads:[~2026-03-24 11:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 6:33 [PATCH] selftests/x86: Fix sysret_rip assertion failure on FRED systems Yi Lai
2026-03-20 14:31 ` Dave Hansen
2026-03-20 15:47 ` Andrew Cooper
2026-03-20 15:50 ` Dave Hansen
2026-03-22 6:13 ` Xin Li
2026-03-23 6:06 ` Lai, Yi
2026-03-23 16:19 ` Xin Li
2026-03-23 19:11 ` H. Peter Anvin
2026-03-23 19:17 ` Andrew Cooper
2026-03-23 20:27 ` H. Peter Anvin
2026-03-24 14:08 ` Andrew Cooper
2026-03-24 14:33 ` H. Peter Anvin
2026-03-24 14:46 ` Andrew Cooper
2026-03-24 15:16 ` H. Peter Anvin
2026-03-22 20:08 ` H. Peter Anvin
2026-03-23 5:55 ` Lai, Yi
2026-03-23 16:39 ` Andrew Cooper
2026-03-24 1:28 ` Lai, Yi
2026-03-24 11:08 ` David Laight [this message]
2026-03-24 14:31 ` 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=20260324110856.5e9e9c76@pumpkin \
--to=david.laight.linux@gmail.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=mingo@redhat.com \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=yi1.lai@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