mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Andy Lutomirski <luto@kernel.org>, Xin Li <xin@zytor.com>
Cc: Yi Lai <yi1.lai@intel.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.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>,
	the arch/x86 maintainers <x86@kernel.org>,
	Khan Shuah <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: Fri, 3 Apr 2026 10:32:37 -0700	[thread overview]
Message-ID: <9e27aab2-7975-4f5f-b952-90e30be26caa@zytor.com> (raw)
In-Reply-To: <bd0caa85-f92c-4c06-ba8a-0b3a80f00f5b@app.fastmail.com>

On 2026-04-02 06:21, Andy Lutomirski wrote:
> 
> I don't really agree.  For quite a few years now, we've tried to make the exit path uniform, and we have this logic in syscall_64:
> 
>         /* SYSRET requires RCX == RIP and R11 == EFLAGS */
>         if (unlikely(regs->cx != regs->ip || regs->r11 != regs->flags))
>                 return false;  <-- fall back to IRET
> 
> and this is not just an aesthetic thing -- it allows us to have deliver signals and implement things like sigreturn without needing to track extra flag bits that mean "well, actually, we're in the syscall *code* but we're not returning from a syscall any more".  We had that a long time ago, and it was extremely difficult to understand and maintain.
> 
> So, on current kernels and kernels going back, I dunno, 10 years (I didn't try to dig out the git history, but I did write much of this code...), the semantics have been that we return to usermode in a state that matches pt_regs as precisely as we can arrange.  For the one case where we have a very longstanding divergence between entry and exit regs, we have orig_ax.
> 
> So it would be at least a fairly large maintainability regression to make the non-FRED SYSCALL behavior modify rcx and/or r11 on exit.
> 
> Now we have FRED.  Sure, it would be nice to remember the entry RCX and R11, but if we want to avoid the footgun where the effect of SYSCALL is different on FRED and non-FRED hardware, then we need the context after entry completes to have regs->rcx == regs->rip and regs->rcx == regs->flags (or perhaps RCX and R11 differently poisoned, but that seems a bit silly).
> 
> If we really want to have the option to fish the original rcx and r11 out from somewhere or perhaps to have extra-bonus-efficient many-parameter syscalls (I'm not sure why), then we could add orig_rcx and orig_r11.  Or we could invent a time machine and fix SYSCALL when it first came out.
> 

I certainly see what you're saying. I still don't like the idea of clobbering
registers "just because" for this reason and more...

	-hpa


  reply	other threads:[~2026-04-03 18:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26  9:44 Yi Lai
2026-03-26 22:06 ` Andy Lutomirski
2026-03-27 12:33   ` Peter Zijlstra
2026-03-31  2:21     ` Lai, Yi
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 [this message]
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=9e27aab2-7975-4f5f-b952-90e30be26caa@zytor.com \
    --to=hpa@zytor.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.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@intel.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

all inboxes | Powered by JetHome®