Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1444690pxj; Fri, 21 May 2021 14:37:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO7XrUHfgw2FEfb9zVoGCR5fYBxu1F5QxxNOx8ldUXManvpRKVrtD3BwuzbRDxhVoYdUW/ X-Received: by 2002:a05:6638:14ce:: with SMTP id l14mr6968946jak.90.1621633071864; Fri, 21 May 2021 14:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621633071; cv=none; d=google.com; s=arc-20160816; b=EhBoNP1geunuWXFv/5hprCj8uDspMXcu6quexKnC5SUCUykhgUIYnbrg2K/4jzXbL/ t/U9S0WmmoimUOp6yeCEeukwfdIY6I1FUVzRvaYYBwRuI8CcqFr2UiMJn8G2CbszMeRK IgjKmGwRKzQgnkj6uRKPDqL8GDqh7EQngExOlvV4t9Nhh7mXHvHJ3JIz1gsnYUioWlcB pOLcjFxwdVdWXPPO1Odbk5rBPxmeoYotms4Wg+/d8Horvniwj1vGqi0woJqu2RzX5LJY TN8WLrJflv90hmCIvHph++0Wmuananm+u9Lm9gcOS11Te1wOuAcDFIUbiPgB7/dH3WOL jSSA== 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:dkim-filter; bh=FE5Ro4/Df02Yj2Nr/OVNSwT2t3v7nd7g7yirN11+GkI=; b=VJ9+ReyiB0jWXFN/WdvUYM4ckgRS+DK04I75SUy8qaxShqI8sE//dI/VSnwJfzF0uy UkoVGnPMHRAOUtQltxF1NRK7Vu4JYCdEsXyudSOWMeCI40Da1ArnqWP7i/KXnErnbeQ/ OL5pXEEr0Zl6CUOoVz1obJMjDa4cnF8m03N5VZt01PUP/4SSE+LlrmrF1K/2Cc2pAWpC fEOCiSQJZh5a8n//Jc3gTaK5oT0KMAM+j/bMwbzxUy5KalCDi9JMtt/Q4GFO/37ytXpY CDfATlUNPAzXerwKiRoGR2JNyDrzvNCLsNemQzohcdKBIPXkEadd/hr1LxxEnTu7u4ge 82kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2021042801 header.b=SEujZ2h6; 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=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t188si5631190jaa.52.2021.05.21.14.37.38; Fri, 21 May 2021 14:37:51 -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=@zytor.com header.s=2021042801 header.b=SEujZ2h6; 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=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229507AbhEUVi1 (ORCPT + 99 others); Fri, 21 May 2021 17:38:27 -0400 Received: from terminus.zytor.com ([198.137.202.136]:45213 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbhEUVi1 (ORCPT ); Fri, 21 May 2021 17:38:27 -0400 Received: from tazenda.hos.anvin.org ([IPv6:2601:646:8602:8be0:7285:c2ff:fefb:fd4]) (authenticated bits=0) by mail.zytor.com (8.16.1/8.15.2) with ESMTPSA id 14LLagD2290060 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Fri, 21 May 2021 14:36:43 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 14LLagD2290060 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2021042801; t=1621633003; bh=FE5Ro4/Df02Yj2Nr/OVNSwT2t3v7nd7g7yirN11+GkI=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=SEujZ2h6Qg34/Roxk6uljZzzeWP6YXqdswfVkOb1vlNlRUaAvYj5vbQGUYSEu1PlM ePPGcLv5KfcUgo2MI8cHLDlcHr9KpupXvwsNzKLQI3Exi9POPiSICFqVvcafOoctfK o27ClV7lS+v8F3uEiHMZftm74NSdEn0LDgI6YqqHk+9MQFuuLMxqYlSWmPjA7l46/h sbOT36G+tVe5vfp1ZWxjGlRXcUxB+fLLmQzpCqnGTAPmfAfnS4Cg0GVDQu1YHWt3Lq 4OwAbhoYGUNZpR6g49vCxm6UW2NXF6t1u5NJubVDd6GGRsVI3dGnRpkNNoInhcpwLu VSqzWMWOMC0eQ== Subject: Re: [PATCH v4 6/6] x86/syscall: use int everywhere for system call numbers To: Thomas Gleixner , Ingo Molnar , Andy Lutomirski , Borislav Petkov Cc: Linux Kernel Mailing List References: <20210518191303.4135296-1-hpa@zytor.com> <20210518191303.4135296-7-hpa@zytor.com> <87zgwpbxby.ffs@nanos.tec.linutronix.de> From: "H. Peter Anvin" Message-ID: Date: Fri, 21 May 2021 14:36:37 -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: <87zgwpbxby.ffs@nanos.tec.linutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/20/21 1:53 AM, Thomas Gleixner wrote: > On Tue, May 18 2021 at 12:13, H. Peter Anvin wrote: >> +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. > > How is that actually improving the generated code? > > unsigned long: > > 104: 48 81 fa bf 01 00 00 cmp $0x1bf,%rdx > 10b: 48 19 c0 sbb %rax,%rax > 10e: 48 21 c2 and %rax,%rdx > 111: 48 89 df mov %rbx,%rdi > 114: 48 8b 04 d5 00 00 00 mov 0x0(,%rdx,8),%rax > 11b: 00 > 11c: e8 00 00 00 00 callq 121 > > unsigned int: > > f1: 48 81 fa bf 01 00 00 cmp $0x1bf,%rdx > f8: 48 19 d2 sbb %rdx,%rdx > fb: 21 d0 and %edx,%eax > fd: 48 89 df mov %rbx,%rdi > 100: 48 8b 04 c5 00 00 00 mov 0x0(,%rax,8),%rax > 107: 00 > 108: e8 00 00 00 00 callq 10d > > Text size increases with that unsigned long cast. > > I must be missing something. > "unsigned long" gave slightly better code than "int", but as you correctly point out here, "unsigned int" is even better. Thanks for catching that. -hpa