Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5814532imb; Fri, 8 Mar 2019 03:00:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyG/WogBOjbWglw1x2AKGItmuN5g+CmNZ+TnJPzeSWyFiweV9b1X64DChY1Y6rj+YFV3l5i X-Received: by 2002:a63:1ce:: with SMTP id 197mr15994236pgb.47.1552042813049; Fri, 08 Mar 2019 03:00:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552042813; cv=none; d=google.com; s=arc-20160816; b=nNS3dQjVPcKSCTGETY4yxwQ/IAsIyDXGAqe+7qE7Y4Fk/wOheZ8URM2nkV9zfQ+5I7 SWl12SCoxdnbH+UgNfUmV9d5rogHkQ0s2o9rjyOKByPfSAS+bchG0LyyLE6e8BPbrWSJ Okw9eJNkpRHnPWO/cOrLLIgzydbjSGDkAWBnFTmMukypDyBDQu8ujPskxW3C05NCHBVS huGTxcwD/f5dJRVruRX/s1k/tO1W8gVG560+HjLrZ0/KSN/LHqIxM/X2kzwm/dgZx5nR BeEHKOWGSCdP1W3ZSdwHqpKzfde2rYCEIPzakq0v+t8nA8q7AD2UyeS3J58Rp7yYmz+r n+CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hrliJgZSHEqg0C+vJCT2WhttKwSy9xwOOLnILNV2vOQ=; b=l73PZnxVYWax2QZlaH6J88uRYdgY28oIpih4mhvfEPKLD1ozrMl8b4zS1icRd1pOaQ Q4K0422usTGQqToIqVJXQo2d0fdiWFp61z53NwlWit2wheToMFYbfSI3ugIDzpeJgYkW OXoL2LGEu3pomBIKIrICpY86K99wgrU9sDQgTsIIhHacb+c5hEavXgrbpEOM8YyZxqHG rrOIvJc1EekvHUjSsYa0TIXXG4UZN4uWE3xdn094uKacO3CsqiRJAwHMv3JnMk466y8f vZXe5l6bfLfH9HkK1JyIEL21ed9GyX4NLzfEpvXayrXbgd2VaT2kIooTOksGSNlch3mu Ohxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=jlNUbOfO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z33si7173844plb.411.2019.03.08.02.59.57; Fri, 08 Mar 2019 03:00:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=jlNUbOfO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbfCHK5O (ORCPT + 99 others); Fri, 8 Mar 2019 05:57:14 -0500 Received: from pandora.armlinux.org.uk ([78.32.30.218]:34298 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbfCHK5N (ORCPT ); Fri, 8 Mar 2019 05:57:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hrliJgZSHEqg0C+vJCT2WhttKwSy9xwOOLnILNV2vOQ=; b=jlNUbOfOmJqVZynxd0YWPJdNk nhZIPGREt0fQLiNqqKyajpEFZNm81ffanEaLnb2mOXdrM610XEi1XdIR2tCA/N2KJy/paXV8N0o08 mmYx6OANvjnIoQme9C0UQW5+/AqDrqD40kryyCe4N+hZasqC9Jg7/WLp17G4Oo4oWGdcFgOPGMj0L P5iY1vEvzlK9QlCHg36kBFayMbxCMxR+aLcDbumBAdQlYvhW3YigMUDWb95EUtiOEXI5AYjMMpX4E N68edhxxa8/95Iq6ihyKbyXY4NfmshxOMEXYNewFS3jK6rHiZb1cAVTALlwB/FYrFZVwqUE+Ny/4X IjHOdGciA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:51664) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1h2DBY-0003Np-4s; Fri, 08 Mar 2019 10:57:04 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.89) (envelope-from ) id 1h2DBS-0005ht-N7; Fri, 08 Mar 2019 10:56:58 +0000 Date: Fri, 8 Mar 2019 10:56:58 +0000 From: Russell King - ARM Linux admin To: Ard Biesheuvel Cc: Mikael Pettersson , Mikael Pettersson , Arnd Bergmann , Peter Zijlstra , Nick Desaulniers , LKML , Ingo Molnar , Darren Hart , Thomas Gleixner , Dave Martin , Linux ARM Subject: Re: [PATCH 2/2] ARM: futex: make futex_detect_cmpxchg more reliable Message-ID: <20190308105658.y6ctbfggheavwxs4@shell.armlinux.org.uk> References: <20190307091514.2489338-1-arnd@arndb.de> <20190307091514.2489338-2-arnd@arndb.de> <20190307234850.nsbpkfcit3lnmytu@shell.armlinux.org.uk> <20190308095308.hjjrzdp4fzbbtnnv@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 08, 2019 at 11:16:47AM +0100, Ard Biesheuvel wrote: > Compiling the following code > > """ > #include > > static void foo(void *a, int b) > { > asm("str %0, [%1]" :: "r"(a), "r"(b)); > } > > int main(void) > { > foo(NULL, 0); > } > """ > > with GCC 6.3 (at -O2) gives me > > .arch armv7-a > .eabi_attribute 28, 1 > .eabi_attribute 20, 1 > .eabi_attribute 21, 1 > .eabi_attribute 23, 3 > .eabi_attribute 24, 1 > .eabi_attribute 25, 1 > .eabi_attribute 26, 2 > .eabi_attribute 30, 2 > .eabi_attribute 34, 1 > .eabi_attribute 18, 4 > .file "futex.c" > .section .text.startup,"ax",%progbits > .align 1 > .p2align 2,,3 > .global main > .syntax unified > .thumb > .thumb_func > .fpu vfpv3-d16 > .type main, %function > main: > @ args = 0, pretend = 0, frame = 0 > @ frame_needed = 0, uses_anonymous_args = 0 > @ link register save eliminated. > movs r0, #0 > .syntax unified > @ 6 "/tmp/futex.c" 1 > str r0, [r0] > @ 0 "" 2 > .thumb > .syntax unified > bx lr > .size main, .-main > .ident "GCC: (Debian 6.3.0-18) 6.3.0 20170516" > .section .note.GNU-stack,"",%progbits > > and so GCC definitely behaves similar in this regard. Let's take this further - a volatile is required for these cases to avoid gcc eliminating the asm() due to the output not being used: #define NULL ((void *)0) static void foo(void *a, int b) { asm volatile("str %1, [%0]" : "=&r" (a) : "0" (a), "r" (b)); } int main(void) { foo(NULL, 0); } produces: mov r3, #0 mov r2, r3 str r2, [r2] which looks to me to be incorrect to the GCC manual - the '&' on the output operand should mean that it does not conflict with other input operands, but clearly 'r2' has ended up being 'b' as well. I suspect this is a bug, or if not, is completely counter-intuitive from the description in the GCC manual. Using "+r" (a) : "r" (b) also results in: mov r3, #0 str r3, [r3] It seems that only using "+&r" (a) : "r" (b) avoids a and b being in the same register, but I question whether we are stepping into undefined compiler behaviour with that. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up