From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Mikael Pettersson <mikpelinux@gmail.com>,
Mikael Pettersson <mikpe@it.uu.se>, Arnd Bergmann <arnd@arndb.de>,
Peter Zijlstra <peterz@infradead.org>,
Nick Desaulniers <ndesaulniers@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Darren Hart <dvhart@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Martin <Dave.Martin@arm.com>,
Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 2/2] ARM: futex: make futex_detect_cmpxchg more reliable
Date: Fri, 8 Mar 2019 10:56:58 +0000 [thread overview]
Message-ID: <20190308105658.y6ctbfggheavwxs4@shell.armlinux.org.uk> (raw)
In-Reply-To: <CAKv+Gu-4bcnVc_v_syaUFXfbyPeo_LGuh7waWQojdGTSS6TeEw@mail.gmail.com>
On Fri, Mar 08, 2019 at 11:16:47AM +0100, Ard Biesheuvel wrote:
> Compiling the following code
>
> """
> #include <stdio.h>
>
> 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
next prev parent reply other threads:[~2019-03-08 10:57 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-07 9:14 [PATCH 1/2] futex: mark futex_detect_cmpxchg() as 'noinline' Arnd Bergmann
2019-03-07 9:14 ` [PATCH 2/2] ARM: futex: make futex_detect_cmpxchg more reliable Arnd Bergmann
2019-03-07 19:39 ` Nick Desaulniers
2019-03-07 23:48 ` Russell King - ARM Linux admin
2019-03-08 0:04 ` Nick Desaulniers
2019-03-08 9:54 ` Russell King - ARM Linux admin
2019-03-08 8:57 ` Ard Biesheuvel
2019-03-08 9:53 ` Russell King - ARM Linux admin
2019-03-08 10:08 ` Ard Biesheuvel
2019-03-08 10:16 ` Ard Biesheuvel
2019-03-08 10:56 ` Russell King - ARM Linux admin [this message]
2019-03-08 10:34 ` Russell King - ARM Linux admin
2019-03-08 10:45 ` Ard Biesheuvel
2019-03-08 10:58 ` Russell King - ARM Linux admin
2019-03-08 11:55 ` Ard Biesheuvel
2019-03-11 14:34 ` Arnd Bergmann
2019-03-11 14:36 ` Ard Biesheuvel
2019-03-11 16:29 ` Arnd Bergmann
2019-03-11 16:36 ` Ard Biesheuvel
2019-03-11 20:58 ` Arnd Bergmann
2019-03-08 11:55 ` Dave Martin
2019-03-07 17:19 ` [PATCH 1/2] futex: mark futex_detect_cmpxchg() as 'noinline' Joe Perches
2019-03-07 17:25 ` Russell King - ARM Linux admin
2019-03-07 17:42 ` Joe Perches
2019-03-07 18:07 ` Russell King - ARM Linux admin
2019-03-07 18:12 ` Nick Desaulniers
2019-03-07 18:21 ` Nathan Chancellor
2019-03-07 22:24 ` Arnd Bergmann
2020-12-12 12:26 ` Marco Elver
2020-12-12 20:01 ` Thomas Gleixner
2020-12-14 10:22 ` Marco Elver
2020-12-14 13:15 ` Arnd Bergmann
2020-12-15 6:09 ` Guo Ren
2020-12-15 11:26 ` Arnd Bergmann
2020-12-15 19:38 ` Sam Ravnborg
2020-12-15 23:24 ` Arnd Bergmann
2020-12-17 15:32 ` Andreas Larsson
2020-12-17 16:43 ` Arnd Bergmann
2020-12-18 11:08 ` Andreas Larsson
2020-12-17 20:03 ` Sam Ravnborg
2020-12-16 10:07 ` David Laight
2020-12-16 11:40 ` Peter Zijlstra
2020-12-20 15:44 ` Guo Ren
2020-12-20 17:49 ` Arnd Bergmann
2020-12-21 2:58 ` Guo Ren
2021-07-22 20:05 ` Nathan Chancellor
2021-10-25 13:52 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190308105658.y6ctbfggheavwxs4@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=Dave.Martin@arm.com \
--cc=ard.biesheuvel@linaro.org \
--cc=arnd@arndb.de \
--cc=dvhart@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikpe@it.uu.se \
--cc=mikpelinux@gmail.com \
--cc=mingo@redhat.com \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®