Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1444917pxj; Sat, 15 May 2021 15:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWtvZPP2varB0YzxuOmA8E8mCrOhpKGWafH0Cf5dDHXgo9/89vRvZPcCArIEyRNqiljXFx X-Received: by 2002:a5d:8516:: with SMTP id q22mr40103482ion.173.1621117284639; Sat, 15 May 2021 15:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621117284; cv=none; d=google.com; s=arc-20160816; b=NebEE64pvUASsIMWOnSDsIp+JHwShewuTBWMauazfzKrPZoC0A/140/+Ogc0TkZy9i oiQfOVinbpbT2CHgx43rE+4PMHWh8d68uFx6P3PZy4EDso04u3rQB/AUyFbdqrNWegcU ftCq600hpIa/eiq0aPvpjsFne66h+3ZCLjH28Qj276/swqImgZOYYftX1VPy7bljENDk BpqhCXCJmPr4eDaBZ6GlXlXCQ9ZQkMcwnbx8FEV9VpPZZCZ6Ao0773yuxzQMsYoy5pGt fb4CxoYRxrD8lF2lHklOSFog/lAcMmMDc1VaHyPjNTSiMnFST286TzvQsYyjTYu1r1T4 mZQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=IiiAUseyWtVNyRxBuCJ4Bf/z+6nmKMLAWItTQfaS3Tk=; b=uZg/0ni5RpwSt84hxN4Gdf9sl8K0LQuXy/ShUk3Da76y2OPxw1nGzPQE0Hbj/YxwyK IZGxH08xDjnhVcyPzIn0qKo0d6PBWVEUPHgqyV7DAyNK6LCfS2o+sJPnW56wHeCcRjGK PwD5XQaD/SA2b4lTfE+jCEOmJkYLh03x1J9JatJKWXIhatxrZwzkvV+xLmO1EyuYmQxN AtHTloDFrGoemGmJ979oZmbdxUT6QNaBd5fgizWpPU8EpmHw7wR8o7kXVZQco2Nc71CZ bmHJapRSqVG6UANzWgmTj9z/Y2iDBg3j+i60Zo702KMd6pCR3iY4IyYfcQrf0PH6kfD9 wjPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rcsJSHoY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j11si12253889ila.145.2021.05.15.15.21.12; Sat, 15 May 2021 15:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rcsJSHoY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232831AbhEOPi0 (ORCPT + 99 others); Sat, 15 May 2021 11:38:26 -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.