qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Stefan Hajnoczi
Subject: Re: [PATCH v4 1/4] tls: add macros for coroutine-safe TLS variables
Date: Tue, 22 Feb 2022 13:44:09 +0000

On Mon, Feb 21, 2022 at 03:16:22PM +0000, Peter Maydell wrote:
> On Mon, 21 Feb 2022 at 14:29, Stefan Hajnoczi <stefanha@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

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]