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

Stefan Hajnoczi posted 4 patches 2 years, 4 months ago
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20211201170120.286139-1-stefanha@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Richard Henderson <richard.henderson@linaro.org>
There is a newer version of this series
include/qemu/coroutine-tls.h | 202 +++++++++++++++++++++++++++++++++++
include/qemu/rcu.h           |   7 +-
softmmu/cpus.c               |   8 +-
tests/unit/rcutorture.c      |  10 +-
tests/unit/test-rcu-list.c   |   4 +-
util/async.c                 |  12 ++-
util/rcu.c                   |  10 +-
7 files changed, 229 insertions(+), 24 deletions(-)
create mode 100644 include/qemu/coroutine-tls.h
[RFC v2 0/4] tls: add macros for coroutine-safe TLS variables
Posted by Stefan Hajnoczi 2 years, 4 months ago
This patch series solves the coroutines TLS problem. Coroutines re-entered from
another thread sometimes see stale TLS values. This happens because compilers
may cache values across yield points, so a value from the previous thread will
be used when the coroutine is re-entered in another thread.

Serge Guelton developed a portable technique and Richard Henderson developed an
inline-friendly architecture-specific technique, see the first patch for
details.

I have audited all __thread variables in QEMU and converted those that can be
used from coroutines. Most actually look safe to me. This patch does not
include a checkpatch.pl rule that requires coroutine-tls.h usage, but perhaps
we should add one for block/ at least?

Stefan Hajnoczi (4):
  tls: add macros for coroutine-safe TLS variables
  util/async: replace __thread with QEMU TLS macros
  rcu: use coroutine TLS macros
  cpus: use coroutine TLS macros for iothread_locked

 include/qemu/coroutine-tls.h | 202 +++++++++++++++++++++++++++++++++++
 include/qemu/rcu.h           |   7 +-
 softmmu/cpus.c               |   8 +-
 tests/unit/rcutorture.c      |  10 +-
 tests/unit/test-rcu-list.c   |   4 +-
 util/async.c                 |  12 ++-
 util/rcu.c                   |  10 +-
 7 files changed, 229 insertions(+), 24 deletions(-)
 create mode 100644 include/qemu/coroutine-tls.h

-- 
2.33.1