Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751480AbdINUVR (ORCPT ); Thu, 14 Sep 2017 16:21:17 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:59456 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751330AbdINUVQ (ORCPT ); Thu, 14 Sep 2017 16:21:16 -0400 Date: Thu, 14 Sep 2017 23:21:14 +0300 From: "Dmitry V. Levin" To: Oleg Nesterov Cc: 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: <20170914202114.GA16764@altlinux.org> Mail-Followup-To: Oleg Nesterov , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Andy Lutomirski , Eugene Syromyatnikov , linux-kernel@vger.kernel.org References: <20170912225756.GA19364@altlinux.org> <20170913164921.GA14063@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline In-Reply-To: <20170913164921.GA14063@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2306 Lines: 73 --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=3Dy fastpath behaviour was different > > from slowpath: >=20 > and even with this change they differ if CONFIG_X86_X32=3Dn? 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 si= lently > ignore the upper bits in $rax ? __SYSCALL_MASK is "int" but it is being sign-extended to unsigned long in a= ll (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. --=20 ldv --IJpNTDwzlM2Ie8A6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJZuuS6AAoJEAVFT+BVnCUIkvYP/2Jmx0b43VAHiu0cxhpWU6RT J1jpMwTNOxaZ0APB7tRZBg1KLsr9lmE3tADEHIYjoyelCygUgb97WmMBrJpF/q9X b3lMAAawK81l6aLKmgoNxHJwUDiqawXCZ/7cFeGL9syZEdX5uduVAja0AKt5Qnz9 rQOas+7PMLOJAVSdsND4UgjW1rlobU06tiNTFJBS7Z4aIgKaav4TdmICbxA5qpWt lOK6hWYPmlb7pjzGMtONhU9XMl/L4Xr9ky3ttsbk0lv2+DbEtUweSohlSx9Wknve QlhbvJCOZ5ryHHnq6kvQO235kxm+SSKkWV2+P7wKc6V7Prfax/Lwl/hS8SWafp++ KON0F86+p8zn7RuR5lb0XesUi+DKVXmDbuUwU+lDxPfTVcTCcfLPSRyCr1HqC+VE F2vVD1JrPYxKOV/ClWDCk+YlRjdyc9zR2v+zso2+uUU7ob1jGpg5HGK077VOOAzM VjPYPeOBXfYhig4A90y+/CwkKN0lfE4z3aBGwkLukOWs/Prjkg+viy0O4w25wKlG vYKrE1bC8/HjxWbXRapZ1BYJBXbqO2vj1lLUrBUnFB8UuyEiFnv9grkEJCYRbBOj WCWyF5Qggrr2+6VFC0/+1N/dK/QOKgVheA/pKdyGOb8DXLJCcnOXn5TEL5nCs9aF hhDZPEwx7cNY1mASD0LB =9HAw -----END PGP SIGNATURE----- --IJpNTDwzlM2Ie8A6--