[PATCH 0/3] TSA: make sure QEMU compiles when using clang TSA

Emanuele Giuseppe Esposito posted 3 patches 1 year, 3 months ago
Failed in applying to current master (apply log)
configure                |  1 +
bsd-user/qemu.h          |  5 +++--
include/exec/exec-all.h  |  5 +++--
include/qemu/thread.h    | 14 +++++++++-----
util/qemu-thread-posix.c |  2 +-
5 files changed, 17 insertions(+), 10 deletions(-)
[PATCH 0/3] TSA: make sure QEMU compiles when using clang TSA
Posted by Emanuele Giuseppe Esposito 1 year, 3 months ago
This serie aims to enable clang Thread Safety Analysis (TSA) in QEMU.
The goal is to use it for our multiqueue project aiming to replace the
block layer AioContext lock with a rwlock and make sure the lock is taken
correctly everywhere [1].

By default, TSA covers pthread mutexes, therefore when added in QEMU it
immediately detects some wrappers using pthread_mutex_lock/unlock without
using the proper TSA macros. Since adding such macro requires scanning all
possible callers of the affected wrapper, simply use TSA_NO_TSA to suppress
the warnings.

[1] = https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg00903.html

Emanuele Giuseppe Esposito (2):
  util/qemu-thread-posix: use TSA_NO_TSA to suppress clang TSA warnings
  bsd-user/mmap: use TSA_NO_TSA to suppress clang TSA warnings

Kevin Wolf (1):
  configure: Enable -Wthread-safety if present

 configure                |  1 +
 bsd-user/qemu.h          |  5 +++--
 include/exec/exec-all.h  |  5 +++--
 include/qemu/thread.h    | 14 +++++++++-----
 util/qemu-thread-posix.c |  2 +-
 5 files changed, 17 insertions(+), 10 deletions(-)

-- 
2.39.0
Re: [PATCH 0/3] TSA: make sure QEMU compiles when using clang TSA
Posted by Kevin Wolf 1 year, 2 months ago
Am 17.01.2023 um 14:52 hat Emanuele Giuseppe Esposito geschrieben:
> This serie aims to enable clang Thread Safety Analysis (TSA) in QEMU.
> The goal is to use it for our multiqueue project aiming to replace the
> block layer AioContext lock with a rwlock and make sure the lock is taken
> correctly everywhere [1].
> 
> By default, TSA covers pthread mutexes, therefore when added in QEMU it
> immediately detects some wrappers using pthread_mutex_lock/unlock without
> using the proper TSA macros. Since adding such macro requires scanning all
> possible callers of the affected wrapper, simply use TSA_NO_TSA to suppress
> the warnings.
> 
> [1] = https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg00903.html

Thanks, changed the commit messages as discussed and applied to my block
branch.

Kevin
Re: [PATCH 0/3] TSA: make sure QEMU compiles when using clang TSA
Posted by Stefan Hajnoczi 1 year, 3 months ago
On Tue, Jan 17, 2023 at 08:52:00AM -0500, Emanuele Giuseppe Esposito wrote:
> This serie aims to enable clang Thread Safety Analysis (TSA) in QEMU.

It's worth covering what TSA is and why it's useful:

Thread Safety Analysis "warns about potential race conditions in code.
The analysis is completely static (i.e. compile-time); there is no
run-time overhead"

"Thread safety analysis works very much like a type system for
multi-threaded programs. In addition to declaring the type of data (e.g.
int, float, etc.), the programmer can (optionally) declare how access to
that data is controlled in a multi-threaded environment. For example, if
foo is guarded by the mutex mu, then the analysis will issue a warning
whenever a piece of code reads or writes to foo without first locking
mu."

https://clang.llvm.org/docs/ThreadSafetyAnalysis.html