[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e43577cf-ab35-1de2-818a-ccc2e2fb99b8@zytor.com>
Date: Fri, 21 May 2021 14:36:37 -0700
From: "H. Peter Anvin" <hpa@...or.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Andy Lutomirski <luto@...nel.org>,
Borislav Petkov <bp@...en8.de>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 6/6] x86/syscall: use int everywhere for system call
numbers
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 <do_syscall_64+0x41>
>
> 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 <do_syscall_64+0x3d>
>
> 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
Powered by blists - more mailing lists