tls: add macros for coroutine-safe TLS variables
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 22 Feb 2022 14:01:47 +0000 (14:01 +0000)
committerKevin Wolf <kwolf@redhat.com>
Fri, 4 Mar 2022 17:14:40 +0000 (18:14 +0100)
commit7d29c341c9d402cf0bcb3a3b76fce0c09dd24e94
tree46d04234051c29163330e5bdb6e1015eca3133be
parent11d0c9b37e94959662f6bcd640aa33137e11dcac
tls: add macros for coroutine-safe TLS variables

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 compiler can still optimize based on analyzing noinline code, so an
asm volatile barrier with an output constraint is required to prevent
unwanted optimizations.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1952483
Suggested-by: Serge Guelton <sguelton@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220222140150.27240-2-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
include/qemu/coroutine-tls.h [new file with mode: 0644]