Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-02 Thread Serge Guelton
On Thu, Dec 02, 2021 at 02:44:42PM +, Peter Maydell wrote: > On Wed, 1 Dec 2021 at 17:19, Stefan Hajnoczi wrote: > > > > Compiler optimizations can cache TLS values across coroutine yield > > points, resulting in stale values from the previous thread when a > > coroutine is re-entered by a new

Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-02 Thread Florian Weimer
* Peter Maydell: > On Thu, 2 Dec 2021 at 14:44, Peter Maydell wrote: >> My compiler-developer colleagues present the following case where >> 'noinline' is not sufficient for the compiler to definitely >> use different values of the address-of-the-TLS-var across an >> intervening function call: >>

Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-02 Thread Peter Maydell
On Wed, 1 Dec 2021 at 17:19, Stefan Hajnoczi wrote: > > Compiler optimizations can cache TLS values across coroutine yield > points, resulting in stale values from the previous thread when a > coroutine is re-entered by a new thread. > > Serge Guelton developed an __attribute__((noinline)) wrapper

Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-02 Thread Peter Maydell
On Thu, 2 Dec 2021 at 14:44, Peter Maydell wrote: > My compiler-developer colleagues present the following case where > 'noinline' is not sufficient for the compiler to definitely > use different values of the address-of-the-TLS-var across an > intervening function call: > > __thread int i; > >

Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-02 Thread Stefan Hajnoczi
On Wed, Dec 01, 2021 at 07:24:33PM +0100, Florian Weimer wrote: > * Stefan Hajnoczi: > > > +#elif defined(__x86_64__) > > +#define QEMU_CO_TLS_ADDR(ret, var) \ > > +asm volatile("rdfsbase %0\n\t" \ > > + "lea "#var"@tpof

Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-01 Thread Florian Weimer
* Stefan Hajnoczi: > +#elif defined(__x86_64__) > +#define QEMU_CO_TLS_ADDR(ret, var) \ > +asm volatile("rdfsbase %0\n\t" \ > + "lea "#var"@tpoff(%0), %0" : "=r"(ret)) > +#endif RDFSBASE needs quite recent kernels. I t

[RFC v2 1/4] tls: add macros for coroutine-safe TLS variables

2021-12-01 Thread Stefan Hajnoczi
Compiler optimizations can cache TLS values across coroutine yield points, resulting in stale values from the previous thread when a coroutine is re-entered by a new thread. Serge Guelton developed an __attribute__((noinline)) wrapper and tested it with clang and gcc. I formatted his idea accordin