Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751435AbdIMQta (ORCPT ); Wed, 13 Sep 2017 12:49:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55208 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751106AbdIMQtY (ORCPT ); Wed, 13 Sep 2017 12:49:24 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1C23B5F7A9 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Wed, 13 Sep 2017 18:49:21 +0200 From: Oleg Nesterov To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Andy Lutomirski , Eugene Syromyatnikov , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/asm/64: do not clear high 32 bits of syscall number when CONFIG_X86_X32=y Message-ID: <20170913164921.GA14063@redhat.com> References: <20170912225756.GA19364@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170912225756.GA19364@altlinux.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 13 Sep 2017 16:49:24 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1758 Lines: 62 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? do_syscall_64() does "nr & __SYSCALL_MASK" unconditionally, this clears the upper bits, no? And why __SYSCALL_MASK is not "unsigned long" ? IOW, why do we want to silently ignore the upper bits in $rax ? Or I am totally confused? Oleg. > $ gcc -xc -Wall -O2 - <<'EOF' > #include > #include > int main(void) { > unsigned long nr = ~0xffffffffUL | __NR_exit; > return !!syscall(nr, 42, 1, 2, 3, 4, 5); > } > EOF > $ ./a.out; echo \$?=$? > $?=42 > $ strace -enone ./a.out > syscall_18446744069414584380(0x2a, 0x1, 0x2, 0x3, 0x4, 0x5) = -1 (errno 38) > +++ exited with 1 +++ > > This change syncs CONFIG_X86_X32=y fastpath behaviour with the case > when CONFIG_X86_X32 is not enabled. > > Fixes: fca460f95e92 ("x32: Handle the x32 system call flag") > Cc: stable@vger.kernel.org > Signed-off-by: Dmitry V. Levin > --- > arch/x86/entry/entry_64.S | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > index 4916725..3bab6af 100644 > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -185,12 +185,10 @@ entry_SYSCALL_64_fastpath: > */ > TRACE_IRQS_ON > ENABLE_INTERRUPTS(CLBR_NONE) > -#if __SYSCALL_MASK == ~0 > - cmpq $__NR_syscall_max, %rax > -#else > - andl $__SYSCALL_MASK, %eax > - cmpl $__NR_syscall_max, %eax > +#if __SYSCALL_MASK != ~0 > + andq $__SYSCALL_MASK, %rax > #endif > + cmpq $__NR_syscall_max, %rax > ja 1f /* return -ENOSYS (already in pt_regs->ax) */ > movq %r10, %rcx > > -- > ldv