From: "Carlos López" <carlos.lopezr4096@gmail.com>
To: opensbi@lists.infradead.org
Cc: "Carlos López" <carlos.lopezr4096@gmail.com>
Subject: [PATCH v2 01/14] include: sbi: add thread safety analysis macros
Date: Wed, 9 Sep 2026 18:23:10 +0200 [thread overview]
Message-ID: <20260909162322.29778-3-carlos.lopezr4096@gmail.com> (raw)
In-Reply-To: <20260909162322.29778-2-carlos.lopezr4096@gmail.com>
Add macros to properly guard clang's thread safety analysis attributes
keeping compatibility with GCC, on top of making things more readable.
Clang < 19 does not support guarded_by() [0], so do not define the
macros in that case.
[0] https://github.com/llvm/llvm-project/pull/94216
Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
---
include/sbi/sbi_visibility.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/sbi/sbi_visibility.h b/include/sbi/sbi_visibility.h
index f900c44565a4..993561ef5eea 100644
--- a/include/sbi/sbi_visibility.h
+++ b/include/sbi/sbi_visibility.h
@@ -15,4 +15,21 @@
#pragma GCC visibility push(hidden)
#endif
+/* Thread Safety Analysis (TSA) annotations for use with clang -Wthread-safety */
+#if defined(__clang__) && __clang_major__ >= 19
+#define TSA_ATTR(x) __attribute__((x))
+#else
+#define TSA_ATTR(x)
+#endif
+
+#define CAPABILITY(x) TSA_ATTR(capability(x))
+#define GUARDED_BY(x) TSA_ATTR(guarded_by(x))
+#define PT_GUARDED_BY(x) TSA_ATTR(pt_guarded_by(x))
+#define ACQUIRE(...) TSA_ATTR(acquire_capability(__VA_ARGS__))
+#define RELEASE(...) TSA_ATTR(release_capability(__VA_ARGS__))
+#define MUST_HOLD(...) TSA_ATTR(requires_capability(__VA_ARGS__))
+#define MUST_NOT_HOLD(...) TSA_ATTR(locks_excluded(__VA_ARGS__))
+#define TRY_ACQUIRE(b, ...) TSA_ATTR(try_acquire_capability(b, __VA_ARGS__))
+#define NO_THREAD_SAFETY_ANALYSIS TSA_ATTR(no_thread_safety_analysis)
+
#endif
--
2.51.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-09-09 16:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 16:23 [PATCH v2 00/14] Add clang Thread Safety Analysis (TSA) support Carlos López
2026-09-09 16:23 ` Carlos López [this message]
2026-09-09 16:23 ` [PATCH v2 02/14] lib: sbi_locks: annotate spinlock APIs for TSA Carlos López
2026-09-09 16:23 ` [PATCH v2 03/14] lib: sbi_fifo: add TSA annotations Carlos López
2026-09-09 16:23 ` [PATCH v2 04/14] lib: sbi_heap: " Carlos López
2026-09-09 16:23 ` [PATCH v2 05/14] lib: sbi_scratch: " Carlos López
2026-09-09 16:23 ` [PATCH v2 06/14] lib: rpmi: " Carlos López
2026-09-09 16:23 ` [PATCH v2 07/14] lib: sbi_timer: " Carlos López
2026-09-09 16:23 ` [PATCH v2 08/14] lib: htif: " Carlos López
2026-09-09 16:23 ` [PATCH v2 09/14] lib: sbi_domain: " Carlos López
2026-09-09 16:23 ` [PATCH v2 10/14] lib: sbi_sse: inline enable event locking Carlos López
2026-09-09 16:23 ` [PATCH v2 11/14] lib: sbi_sse: pass SSE hart state explicitly Carlos López
2026-09-09 16:23 ` [PATCH v2 12/14] lib: sbi_sse: add TSA annotations Carlos López
2026-09-09 16:23 ` [PATCH v2 13/14] lib: test: disable TSA for spinlock tests Carlos López
2026-09-09 16:23 ` [PATCH v2 14/14] Makefile: enable Thread Safety Analysis Carlos López
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260909162322.29778-3-carlos.lopezr4096@gmail.com \
--to=carlos.lopezr4096@gmail.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox