From mboxrd@z Thu Jan 1 00:00:00 1970 From: Will Deacon Subject: Re: [PATCH 1/1] futex: remove duplicated code Date: Mon, 15 May 2017 14:16:45 +0100 Message-ID: <20170515131644.GA3605@arm.com> References: <20170515130742.18357-1-jslaby@suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20170515130742.18357-1-jslaby@suse.cz> Sender: linux-hexagon-owner@vger.kernel.org To: Jiri Slaby Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Catalin Marinas , Richard Kuo , Tony Luck , Fenghua Yu , Michal Simek , Ralf Baechle , Jonas Bonn , Stefan Kristiansson , Stafford Horne , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , Martin Schwidefsky List-Id: linux-arch.vger.kernel.org Hi Jiri, On Mon, May 15, 2017 at 03:07:42PM +0200, Jiri Slaby wrote: > There is code duplicated over all architecture's headers for > futex_atomic_op_inuser. Namely op decoding, access_ok check for uaddr, > and comparison of the result. > > Remove this duplication and leave up to the arches only the needed > assembly which is now in arch_futex_atomic_op_inuser. > > Note that s390 removed access_ok check in d12a29703 ("s390/uaccess: > remove pointless access_ok() checks") as access_ok there returns true. > We introduce it back to the helper for the sake of simplicity (it gets > optimized away anyway). Whilst I think this is a good idea, the code in question actually results in undefined behaviour per the C spec and is reported by UBSAN. See my patch fixing arm64 here (which I'd forgotten about): https://www.spinics.net/lists/linux-arch/msg38564.html But, as stated in the thread above, I think we should go a step further and remove FUTEX_OP_{OR,ANDN,XOR,OPARG_SHIFT} altogether. They don't appear to be used by userspace, and this whole thing is a total mess. Any thoughts? Will From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com ([217.140.101.70]:52314 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933240AbdEONQs (ORCPT ); Mon, 15 May 2017 09:16:48 -0400 Date: Mon, 15 May 2017 14:16:45 +0100 From: Will Deacon Subject: Re: [PATCH 1/1] futex: remove duplicated code Message-ID: <20170515131644.GA3605@arm.com> References: <20170515130742.18357-1-jslaby@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170515130742.18357-1-jslaby@suse.cz> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Jiri Slaby Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Catalin Marinas , Richard Kuo , Tony Luck , Fenghua Yu , Michal Simek , Ralf Baechle , Jonas Bonn , Stefan Kristiansson , Stafford Horne , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , Martin Schwidefsky , Yoshinori Sato , Rich Felker , "David S. Miller" , Ingo Molnar , "H. Peter Anvin" , Chris Zankel , Max Filippov , Arnd Bergmann , x86@kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@linux-mips.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-arch@vger.kernel.org Message-ID: <20170515131645.h5vxGl1SErUwWv1aMtsMiC_P31yW39kvY6SPw13kUVI@z> Hi Jiri, On Mon, May 15, 2017 at 03:07:42PM +0200, Jiri Slaby wrote: > There is code duplicated over all architecture's headers for > futex_atomic_op_inuser. Namely op decoding, access_ok check for uaddr, > and comparison of the result. > > Remove this duplication and leave up to the arches only the needed > assembly which is now in arch_futex_atomic_op_inuser. > > Note that s390 removed access_ok check in d12a29703 ("s390/uaccess: > remove pointless access_ok() checks") as access_ok there returns true. > We introduce it back to the helper for the sake of simplicity (it gets > optimized away anyway). Whilst I think this is a good idea, the code in question actually results in undefined behaviour per the C spec and is reported by UBSAN. See my patch fixing arm64 here (which I'd forgotten about): https://www.spinics.net/lists/linux-arch/msg38564.html But, as stated in the thread above, I think we should go a step further and remove FUTEX_OP_{OR,ANDN,XOR,OPARG_SHIFT} altogether. They don't appear to be used by userspace, and this whole thing is a total mess. Any thoughts? Will