[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5050b43687c84515a49b345174a98822@AcuMS.aculab.com>
Date: Thu, 10 Sep 2020 12:26:53 +0000
From: David Laight <David.Laight@...LAB.COM>
To: David Laight <David.Laight@...LAB.COM>,
'Christophe Leroy' <christophe.leroy@...roup.eu>,
'Linus Torvalds' <torvalds@...ux-foundation.org>,
Segher Boessenkool <segher@...nel.crashing.org>
CC: linux-arch <linux-arch@...r.kernel.org>,
Kees Cook <keescook@...omium.org>,
the arch/x86 maintainers <x86@...nel.org>,
"Nick Desaulniers" <ndesaulniers@...gle.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Alexey Dobriyan <adobriyan@...il.com>,
"Luis Chamberlain" <mcgrof@...nel.org>,
Al Viro <viro@...iv.linux.org.uk>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
linuxppc-dev <linuxppc-dev@...ts.ozlabs.org>,
Christoph Hellwig <hch@....de>
Subject: RE: remove the last set_fs() in common code, and remove it for x86
and powerpc v3
From: David Laight
> Sent: 10 September 2020 10:26
...
> > > I had an 'interesting' idea.
> > >
> > > Can you use a local asm register variable as an input and output to
> > > an 'asm volatile goto' statement?
> > >
> > > Well you can - but is it guaranteed to work :-)
> > >
> >
> > With gcc at least it should work according to
> > https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html
> >
> > They even explicitely tell: "The only supported use for this feature is
> > to specify registers for input and output operands when calling Extended
> > asm "
>
> A quick test isn't good....
>
> int bar(char *z)
> {
> __label__ label;
> register int eax asm ("eax") = 6;
> asm volatile goto (" mov $1, %%eax" ::: "eax" : label);
> label:
> return eax;
> }
>
> 0000000000000040 <bar>:
> 40: b8 01 00 00 00 mov $0x1,%eax
> 45: b8 06 00 00 00 mov $0x6,%eax
> 4a: c3 retq
>
> although adding:
> asm volatile ("" : "+r" (eax));
> either side of the 'asm volatile goto' does fix it.
Actually this is pretty sound:
__label__ label;
register int eax asm ("eax");
// Ensure eax can't be reloaded from anywhere
// In particular it can't be reloaded after the asm goto line
asm volatile ("" : "=r" (eax));
// Provided gcc doesn't save eax here...
asm volatile goto ("xxxxx" ::: "eax" : label);
// ... and reload the saved value here.
// The input value here will be that modified by the 'asm goto'.
// Since this modifies eax it can't be moved before the 'asm goto'.
asm volatile ("" : "+r" (eax));
// So here eax must contain the value set by the "xxxxx" instructions.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists