Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1732563

Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number when CONFIG_X86_X32=y

From "Dmitry V. Levin" <ldv@altlinux.org>
Newsgroups linux.kernel
Subject Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number when CONFIG_X86_X32=y
Date 2017-09-14 22:30 +0200
Message-ID <upIVP-1fS-15@gated-at.bofh.it> (permalink)
References <up2jU-7sR-3@gated-at.bofh.it> <upj1n-1ns-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wed, Sep 13, 2017 at 06:49:21PM +0200, Oleg Nesterov wrote:
> On 09/13, Dmitry V. Levin wrote:
> >
> > Before this change, CONFIG_X86_X32=y fastpath behaviour was different
> > from slowpath:
> 
> and even with this change they differ if CONFIG_X86_X32=n?

No, I don't think so.

> do_syscall_64() does "nr & __SYSCALL_MASK" unconditionally,

yes

> this clears the upper bits, no?

Why?  As "nr" is of type "unsigned long" and __SYSCALL_MASK is either
(~(__X32_SYSCALL_BIT)) or (~0), that is, an integer with the sign bit set,
in "nr & __SYSCALL_MASK" expression __SYSCALL_MASK is sign-extended
to unsigned long.  When __SYSCALL_MASK is defined to (~0),
"nr & __SYSCALL_MASK" is optimized to "nr" at compilation time:

$ echo 'unsigned long foo(unsigned long nr) { return nr & (~0); }' |
  gcc -Wall -O2 -xc -S -o - - |
  sed -n '/cfi_/,/cfi_/p'
	.cfi_startproc
	movq	%rdi, %rax
	ret
	.cfi_endproc

> And why __SYSCALL_MASK is not "unsigned long" ? IOW, why do we want to silently
> ignore the upper bits in $rax ?

__SYSCALL_MASK is "int" but it is being sign-extended to unsigned long in all
(two) places of arch/x86/entry/common.c where it is used.

> Or I am totally confused?

The thing looks like it was designed to confuse people.


-- 
ldv

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] x86/asm/64: do not clear high 32 bits of syscall number when  CONFIG_X86_X32=y "Dmitry V. Levin" <ldv@altlinux.org> - 2017-09-13 01:00 +0200
  Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y Oleg Nesterov <oleg@redhat.com> - 2017-09-13 18:50 +0200
    Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y Eugene Syromyatnikov <evgsyr@gmail.com> - 2017-09-14 21:50 +0200
      Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y "Dmitry V. Levin" <ldv@altlinux.org> - 2017-09-14 22:30 +0200
    Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y "Dmitry V. Levin" <ldv@altlinux.org> - 2017-09-14 22:30 +0200
      Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y Oleg Nesterov <oleg@redhat.com> - 2017-09-15 18:20 +0200
  Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y Andy Lutomirski <luto@kernel.org> - 2017-09-14 23:10 +0200
    Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y "Dmitry V. Levin" <ldv@altlinux.org> - 2017-09-14 23:40 +0200
      Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y Andy Lutomirski <luto@kernel.org> - 2017-09-14 23:50 +0200
        Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y Ingo Molnar <mingo@kernel.org> - 2017-09-15 07:40 +0200
          Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number when CONFIG_X86_X32=y hpa@zytor.com - 2017-09-15 08:00 +0200
            Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number  when CONFIG_X86_X32=y "Dmitry V. Levin" <ldv@altlinux.org> - 2017-09-17 18:50 +0200
          Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number when CONFIG_X86_X32=y hpa@zytor.com - 2017-09-15 08:00 +0200

csiph-web