qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] tls: add macros for coroutine-safe TLS variables
@ 2022-02-21 14:29 Stefan Hajnoczi
  2022-02-21 14:29 ` [PATCH v4 1/4] " Stefan Hajnoczi
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Stefan Hajnoczi @ 2022-02-21 14:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Florian Weimer, Kevin Wolf, qemu-block, Peter Maydell,
	Richard Henderson, Stefan Hajnoczi, Paolo Bonzini, Fam Zheng,
	Serge Guelton

v4:
- Dropped '[RFC]'.
- Dropped inline asm for now. -fPIC versions of the code are missing and I
  hit several issues including a clang LTO bug where thread local variables are
  incorrectly discarded because inline asm is not analyzed to find symbol
  dependencies (Serge Guelton is aware).
- Fixed CI failures.
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, 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.

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

-- 
2.34.1




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

end of thread, other threads:[~2022-02-23 10:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-21 14:29 [PATCH v4 0/4] tls: add macros for coroutine-safe TLS variables Stefan Hajnoczi
2022-02-21 14:29 ` [PATCH v4 1/4] " Stefan Hajnoczi
2022-02-21 15:16   ` Peter Maydell
2022-02-22 13:44     ` Stefan Hajnoczi
2022-02-23  9:47   ` Paolo Bonzini
2022-02-21 14:29 ` [PATCH v4 2/4] util/async: replace __thread with QEMU TLS macros Stefan Hajnoczi
2022-02-21 15:09   ` Philippe Mathieu-Daudé
2022-02-21 14:29 ` [PATCH v4 3/4] rcu: use coroutine " Stefan Hajnoczi
2022-02-21 14:29 ` [PATCH v4 4/4] cpus: use coroutine TLS macros for iothread_locked Stefan Hajnoczi
2022-02-21 15:07   ` Philippe Mathieu-Daudé
2022-02-21 15:09   ` Philippe Mathieu-Daudé
2022-02-22 13:25     ` Stefan Hajnoczi
2022-02-23  9:45   ` Paolo Bonzini
2022-02-23  9:48     ` Peter Maydell

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).