On Mon, Feb 21, 2022 at 03:16:22PM +0000, Peter Maydell wrote: > On Mon, 21 Feb 2022 at 14:29, Stefan Hajnoczi <stefa...@redhat.com> 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 and tested > > it with clang and gcc. I formatted his idea according to QEMU's coding > > style and wrote documentation. > > The commit message says "attribute noinline" but the code > opts for "attribute noinline plus asm-volatile barrier": > > > +/* > > + * To stop the compiler from caching TLS values we define accessor > > functions > > + * with __attribute__((noinline)) plus asm volatile("") to prevent > > + * optimizations that override noinline. This is fragile and ultimately > > needs > > + * to be solved by a mechanism that is guaranteed to work by the compiler > > (e.g. > > + * stackless coroutines), but for now we use this approach to prevent > > issues. > > + */ > > I thought we'd determined previously that noinline + asm-volatile wasn't > sufficient? > > https://lore.kernel.org/qemu-devel/YbdUDkTkt5srNdW+@stefanha-x1.localdomain/ > > This version of the patchset does seem to include the asm input operand > you describe there (in one of the three wrappers, anyway), but if that's > necessary then we should document it in the comment here.
Sorry, the message/comments are outdated. I'll change them to reflect the current approach. Stefan
signature.asc
Description: PGP signature