From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CD7C433B4 for ; Sat, 15 May 2021 15:37:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 768A3613CE for ; Sat, 15 May 2021 15:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbhEOPi1 (ORCPT ); Sat, 15 May 2021 11:38:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:35236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbhEOPi0 (ORCPT ); Sat, 15 May 2021 11:38:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3103B613BB; Sat, 15 May 2021 15:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621093033; bh=8/QO4u/vqn1utbmDvC5Dk0J1P3vf4/FSXWmJ911+OJ8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=rcsJSHoYxUwZio9OcKWQ+EVRvxCL3JBJ5GQjnjzNLLpl3UOc6YTQzT40uo0rbDTkL KB1q1ZrJnvceAEhqPzS5rv2eHyypHCusjbTOS2rmPDdwlRpbEjZubQLlKBrVcVzr9s 8M1BzdOH54UkYt+BgO9m3eXACRlbZNdOBl4gWaEpop6rd8nCxW8BqZdf3LXVdZ2Kvd McDBYa8MHVFaVFIHR4nrIjpaGJr9fRGyqfNPRWSA7GLqBV0gr3rh6gqfV1opJenDDS XH47PC0FvS2xNPVJz8LSSDGW7EXzZQavm/c0NQdXfg/g1cFE0Gartst6hCJCNSUco+ p4kIo8XecVbkg== Subject: Re: [PATCH v3 4/4] x86/syscall: use int everywhere for system call numbers To: "H. Peter Anvin" , Ingo Molnar , Thomas Gleixner , Borislav Petkov Cc: Linux Kernel Mailing List References: <20210515011015.2707542-1-hpa@zytor.com> <20210515011015.2707542-5-hpa@zytor.com> From: Andy Lutomirski Message-ID: Date: Sat, 15 May 2021 08:37:12 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210515011015.2707542-5-hpa@zytor.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/14/21 6:10 PM, H. Peter Anvin wrote: > From: "H. Peter Anvin (Intel)" > > 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) > --- > 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 > > #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.