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: Peter Maydell
Subject: Re: [PATCH v4 1/4] tls: add macros for coroutine-safe TLS variables
Date: Mon, 21 Feb 2022 15:16:22 +0000

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.

thanks
-- PMM



reply via email to

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