From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Breno Leitao <leitao@debian.org>,
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>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
kernel-team@meta.com, Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH RFC] x86/syscall: Dispatch via sys_call_table when Spectre v2 and BHI are off
Date: Thu, 5 Nov 2026 11:56:21 +0100 [thread overview]
Message-ID: <20261105105621.GN1813469@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAHk-=wjg-mre6diNHCTYUtc=X26462GGxgJMw8cE20Wh1-5qBQ@mail.gmail.com>
On Fri, Oct 30, 2026 at 08:56:12AM -1000, Linus Torvalds wrote:
> On Thu, 29 Oct 2026 at 02:30, Breno Leitao <leitao@debian.org> wrote:
> >
> > With "x86_64/entry: Unconditionally use -fno-jump-table", x64_sys_call()
> > becomes a compare tree on every x86_64 build, so system call dispatch is
> > the same whether the mitigations are disabled at boot or at build time,
> > which is basically my end goal.
>
> You're basically saying "with that patch, both cases do equally badly
> whether disabled at boot or build time".
>
> That's not a good end goal. You want both cases to do equally *well*.
>
> I do wonder if we could do computed jumps. It would be lovely if we
> could basically do something like
>
> # syscall number in %rax
> leaq table(%rax,%rax,4),%rax
> jmp *%rax
> table:
> jmp syscall0
> jmp syscall1
> jmp syscall2
> ....
>
> and avoid any indirect memory lookup or indirect branches (outside of
> the one computed one). And no extra call/ret frame.
>
> It's possible that the branch prediction hardware hates those kinds of
> very dense jmp patterns, though. I don't know.
>
> We could have a single static jump that picks between this one and the
> "conditional branch tree" version, as in your patch at the beginning
> of the thread.
The thinking here being that you would still not actually load any value
from the sys_call_table and keep it all in code?
As Andrew already pointed out, this required ENDBR (yes 4 bytes) in
addition to the JMP.d32 (5 bytes). But when building with kCFI that
would require even more.
Notably, you do not want the syscall dispatch to be a kCFI evasion
gadget.
The kCFI landing pad would basically add another 16 bytes on top of
those earlier 9 bytes, at which point you might as well round up and use
32 bytes per entry.
At which point one has to ask the obvious question on whether this is
actually better than just keeping the sys_call_table and syscall
functions as is.
That is; do we want to go back to unconditionally doing:
nr = array_index_nospec(nr, NR_syscalls);
regs->ax = sys_call_table[nr](regs);
Yes, this will turn into retpoline for old hardware, get patched back
into regular indirect call on recent hardware, and will get kCFI/FineIBT
crud on for 'free' when your build swings that way.
It does mean syscall hijack through sys_call_table[] is a thing again,
but it will be the fastest option on modern chips and automagically
'scale' with the mitigation options selected.
OTOH there are still million upon millions of that old stuff out there
in data centers :/
prev parent reply other threads:[~2026-11-05 10:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 10:27 Breno Leitao
2026-10-29 10:49 ` Peter Zijlstra
2026-10-29 12:30 ` Breno Leitao
2026-10-29 12:39 ` Peter Zijlstra
2026-10-30 5:38 ` Borislav Petkov
2026-10-30 12:11 ` Breno Leitao
2026-10-30 18:34 ` Borislav Petkov
2026-10-30 18:56 ` Linus Torvalds
2026-10-30 19:03 ` H. Peter Anvin
2026-11-02 18:49 ` Breno Leitao
2026-11-02 20:02 ` Linus Torvalds
2026-11-02 20:06 ` Andrew Cooper
2026-11-02 20:11 ` Linus Torvalds
2026-11-05 9:40 ` David Laight
2026-11-05 10:56 ` Peter Zijlstra [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=20261105105621.GN1813469@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=justinstitt@google.com \
--cc=keescook@chromium.org \
--cc=kernel-team@meta.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=tglx@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/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®