Message ID | CAELBRWJje2JapKVdECxwMu8LCwVnVPd2qyb+ZL79Gjk-ZQJN6w@mail.gmail.com |
---|---|
State | Not Applicable |
Delegated to: | Stefano Babic |
Headers | show |
Series | [U-Boot] imx: get_ticks in syscounter.c get miscompiled by GCC 6 | expand |
Hi, On Tue, 6 Mar 2018 15:06:08 +0900 Yasushi SHOJI wrote: > Hi, > > It seems to me that both GCC 6.3 and 6.4 mis-compiles > s/mis-compiles/optimizes/ Without the 'volatile' attribute the compiler is entitled to move the asm code around or optimize it out. So, your patch is the correct fix independent from the gcc version used. > arch/arm/mach-imx/syscounter.c. > > I'm attaching two files, bad.txt is the original syscounter.c and > good.txt is the one > with the following patch. > > diff --git a/arch/arm/mach-imx/syscounter.c b/arch/arm/mach-imx/syscounter.c > index 9290918dca..30ed0109a2 100644 > --- a/arch/arm/mach-imx/syscounter.c > +++ b/arch/arm/mach-imx/syscounter.c > @@ -82,7 +82,7 @@ unsigned long long get_ticks(void) > { > unsigned long long now; > > - asm("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now)); > + asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now)); > > gd->arch.tbl = (unsigned long)(now & 0xffffffff); > gd->arch.tbu = (unsigned long)(now >> 32); > Lothar Waßmann
On Tue, Mar 6, 2018 at 9:31 AM, Lothar Waßmann <LW@karo-electronics.de> wrote: > Without the 'volatile' attribute the compiler is entitled to move the > asm code around or optimize it out. > So, your patch is the correct fix independent from the gcc version > used. Yes, but then it would be better to fix all the places where asm is used without volatile.
Hi, On Tue, Mar 6, 2018 at 10:11 PM, Fabio Estevam <festevam@gmail.com> wrote: > On Tue, Mar 6, 2018 at 9:31 AM, Lothar Waßmann <LW@karo-electronics.de> wrote: > >> Without the 'volatile' attribute the compiler is entitled to move the >> asm code around or optimize it out. >> So, your patch is the correct fix independent from the gcc version >> used. > > Yes, but then it would be better to fix all the places where asm is > used without volatile. That'd be a quite big patch. A quick grep shows me that there is over 100 asm() without volatile. git grep -e '\basm *(' | grep -v -e volatile -e nop | wc -l 153 Do you guys really want to put volatile on all of these now? We are at rc4 and Tom is planing to cut the release March 12th. I'm attaching a tentative patch to fix only syscounter.c. If it looks good, I'l resend it by git-send-email. Best,
Hi Yasushi , On Wed, Mar 7, 2018 at 2:57 AM, Yasushi SHOJI <yasushi.shoji@gmail.com> wrote: > Do you guys really want to put volatile on all of these now? > We are at rc4 and Tom is planing to cut the release > March 12th. This can be done at a later step. > I'm attaching a tentative patch to fix only syscounter.c. > If it looks good, I'l resend it by git-send-email. Patch looks good. Make sure to add your Signed-off-by line, then you can send it via git send-email. Thanks
On Wed, Mar 07, 2018 at 10:42:44AM -0300, Fabio Estevam wrote: > Hi Yasushi , > > On Wed, Mar 7, 2018 at 2:57 AM, Yasushi SHOJI <yasushi.shoji@gmail.com> wrote: > > > Do you guys really want to put volatile on all of these now? > > We are at rc4 and Tom is planing to cut the release > > March 12th. > > This can be done at a later step. Yes. And it should be a little bit manual too. For example, using your regex (thanks!) I see we have some powerpc code that's doing asm("eieio") and that should be eieio() (which is in turn an asm volatile ...), as well as some sync;isync or just sync/isync that should be sync();isync(); or similar. And people that know x86 might have some useful comments there too. > > I'm attaching a tentative patch to fix only syscounter.c. > > If it looks good, I'l resend it by git-send-email. > > Patch looks good. Make sure to add your Signed-off-by line, then you > can send it via git send-email. Yes please, thanks!
Hi, On Wed, Mar 7, 2018 at 11:27 PM, Tom Rini <trini@konsulko.com> wrote: > On Wed, Mar 07, 2018 at 10:42:44AM -0300, Fabio Estevam wrote: >> Patch looks good. Make sure to add your Signed-off-by line, then you >> can send it via git send-email. > > Yes please, thanks! I've sent it to you with my signed-of-by. thanks,
diff --git a/arch/arm/mach-imx/syscounter.c b/arch/arm/mach-imx/syscounter.c index 9290918dca..30ed0109a2 100644 --- a/arch/arm/mach-imx/syscounter.c +++ b/arch/arm/mach-imx/syscounter.c @@ -82,7 +82,7 @@ unsigned long long get_ticks(void) { unsigned long long now; - asm("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now)); + asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now)); gd->arch.tbl = (unsigned long)(now & 0xffffffff); gd->arch.tbu = (unsigned long)(now >> 32);