From: Andy Lutomirski <luto@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 4/4] x86/syscall: use int everywhere for system call numbers
Date: Sat, 15 May 2021 08:37:12 -0700 [thread overview]
Message-ID: <f2e4c3c3-08c3-eae1-803a-aa85d7e75ca0@kernel.org> (raw)
In-Reply-To: <20210515011015.2707542-5-hpa@zytor.com>
On 5/14/21 6:10 PM, H. Peter Anvin wrote:
> From: "H. Peter Anvin (Intel)" <hpa@zytor.com>
>
> System call numbers are defined as int, so use int everywhere for
> system call numbers. This patch is strictly a cleanup; it should not
> change anything user visible; all ABI changes have been done in the
> preceeding patches.
>
> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
> ---
> arch/x86/entry/common.c | 93 ++++++++++++++++++++++++----------
> arch/x86/include/asm/syscall.h | 2 +-
> 2 files changed, 66 insertions(+), 29 deletions(-)
>
> diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
> index f51bc17262db..714804f0970c 100644
> --- a/arch/x86/entry/common.c
> +++ b/arch/x86/entry/common.c
> @@ -36,49 +36,87 @@
> #include <asm/irq_stack.h>
>
> #ifdef CONFIG_X86_64
> -__visible noinstr void do_syscall_64(struct pt_regs *regs, unsigned long nr)
> +
> +static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr)
> +{
> + /*
> + * Convert negative numbers to very high and thus out of range
> + * numbers for comparisons. Use unsigned long to slightly
> + * improve the array_index_nospec() generated code.
> + */
> + unsigned long unr = nr;
> +
> + if (likely(unr < NR_syscalls)) {
> + unr = array_index_nospec(unr, NR_syscalls);
> + regs->ax = sys_call_table[unr](regs);
> + return true;
> + }
> + return false;
> +}
How much do you like micro-optimization? You could be silly^Wclever and
add a new syscall handler:
long skip_syscall(struct pt_regs *regs)
{
return regs->ax;
}
and prepend this to the syscall tables -- it would be a sort-of-real
syscall -1. Then the call sequence becomes:
int adjusted_nr = nr + 1 (or nr - x32bit + 1);
if (likely(nr < NR_adjusted_syscalls)) {
unr = array_index_nospec...;
regs->ax = sys_call_table[unr](regs); /* might be a no-op! */
} else {
regs->ax = -ENOSYS;
}
which removes a branch from the fast path.
next prev parent reply other threads:[~2021-05-15 15:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-15 1:10 [RFC v3 PATCH 0/4] x86/syscall: use int for x86-64 system calls H. Peter Anvin
2021-05-15 1:10 ` [PATCH v3 1/4] x86/syscall: sign-extend system calls on entry to int H. Peter Anvin
2021-05-16 7:48 ` Ingo Molnar
2021-05-17 20:23 ` H. Peter Anvin
2021-05-15 1:10 ` [PATCH v3 2/4] x86/syscall: update and extend selftest syscall_numbering_64 H. Peter Anvin
2021-05-16 7:52 ` Ingo Molnar
2021-05-18 0:26 ` H. Peter Anvin
2021-05-18 15:04 ` H. Peter Anvin
2021-05-15 1:10 ` [PATCH v3 3/4] x86/syscall: treat out of range and gap system calls the same H. Peter Anvin
2021-05-15 1:10 ` [PATCH v3 4/4] x86/syscall: use int everywhere for system call numbers H. Peter Anvin
2021-05-15 15:37 ` Andy Lutomirski [this message]
2021-05-15 17:41 ` H. Peter Anvin
2021-05-15 17:42 ` H. Peter Anvin
[not found] ` <2ebf1bac-93c1-4b7f-add4-4ede3c149b52@www.fastmail.com>
2021-05-15 21:07 ` 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=f2e4c3c3-08c3-eae1-803a-aa85d7e75ca0@kernel.org \
--to=luto@kernel.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/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