qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables
@ 2021-12-06 14:26 Stefan Hajnoczi
  2021-12-06 14:26 ` [RFC v3 1/4] " Stefan Hajnoczi
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Stefan Hajnoczi @ 2021-12-06 14:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, fweimer, thuth, Daniel Berrange, qemu-block,
	Richard Henderson, Stefan Hajnoczi, Paolo Bonzini, Kevin Wolf,
	Warner Losh, sguelton

v3:
- Added __attribute__((weak)) to get_ptr_*() [Florian]
- Replace rdfsbase with mov %%fs:0,%0 [Florian]

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 | 205 +++++++++++++++++++++++++++++++++++
 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, 232 insertions(+), 24 deletions(-)
 create mode 100644 include/qemu/coroutine-tls.h

-- 
2.33.1




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-12-13 14:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-06 14:26 [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 1/4] " Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 2/4] util/async: replace __thread with QEMU TLS macros Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 3/4] rcu: use coroutine " Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 4/4] cpus: use coroutine TLS macros for iothread_locked Stefan Hajnoczi
2021-12-06 14:34 ` [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables Peter Maydell
2021-12-07 13:34   ` Stefan Hajnoczi
2021-12-07 13:53   ` Stefan Hajnoczi
2021-12-07 13:55     ` Peter Maydell
2021-12-07 16:29       ` Stefan Hajnoczi
2021-12-13 14:09       ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).