[PATCH 09/14] lib: sbi_domain: add TSA annotations
Carlos López
carlos.lopezr4096 at gmail.com
Wed Jul 29 09:35:36 PDT 2026
Add Thread Safety Analysis (TSA) annotations for the domain handling
code. This includes indicating which fields are protected by a spinlock,
and annotating which functions acquire a spinlock, in order to prevent
nesting. Exclude sbi_domain_register() from analysis, as it initializes
a domain's spinlock.
Signed-off-by: Carlos López <carlos.lopezr4096 at gmail.com>
---
include/sbi/sbi_domain.h | 10 ++++++----
lib/sbi/sbi_domain.c | 3 +++
lib/sbi/sbi_domain_context.c | 2 ++
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
index 16edd4ce4493..d4ad2297284e 100644
--- a/include/sbi/sbi_domain.h
+++ b/include/sbi/sbi_domain.h
@@ -193,10 +193,10 @@ struct sbi_domain {
struct sbi_domain_data_priv data_priv;
/** Logical index of this domain */
u32 index;
- /** HARTs assigned to this domain */
- struct sbi_hartmask assigned_harts;
/** Spinlock for accessing assigned_harts */
spinlock_t assigned_harts_lock;
+ /** HARTs assigned to this domain */
+ struct sbi_hartmask assigned_harts GUARDED_BY(&assigned_harts_lock);
/** Name of this domain */
char name[64];
/** Possible HARTs in this domain */
@@ -252,7 +252,8 @@ extern struct sbi_dlist domain_list;
* @param hartindex the HART index
* @return true if HART is assigned to domain otherwise false
*/
-bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex);
+bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex)
+ MUST_NOT_HOLD(&dom->assigned_harts_lock);
/**
* Get the assigned HART mask for given domain
@@ -261,7 +262,8 @@ bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex);
* @return 0 on success and SBI_Exxx (< 0) on failure
*/
int sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom,
- struct sbi_hartmask *mask);
+ struct sbi_hartmask *mask)
+ MUST_NOT_HOLD(&dom->assigned_harts_lock);
/**
* Initialize a domain memory region based on it's physical
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index fa69170bdc92..7bdb912acf25 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -60,6 +60,7 @@ void sbi_update_hartindex_to_domain(u32 hartindex, struct sbi_domain *dom)
}
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex)
+ MUST_NOT_HOLD(&dom->assigned_harts_lock)
{
bool ret;
struct sbi_domain *tdom = (struct sbi_domain *)dom;
@@ -76,6 +77,7 @@ bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartindex)
int sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom,
struct sbi_hartmask *mask)
+ MUST_NOT_HOLD(&dom->assigned_harts_lock)
{
ulong ret = 0;
struct sbi_domain *tdom = (struct sbi_domain *)dom;
@@ -627,6 +629,7 @@ void sbi_domain_dump_all(const char *suffix)
int sbi_domain_register(struct sbi_domain *dom,
const struct sbi_hartmask *assign_mask)
+ NO_THREAD_SAFETY_ANALYSIS
{
u32 i;
int rc;
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index cc4cc04ddb46..31f00e5b0f56 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -107,6 +107,8 @@ static void hart_context_set(struct sbi_domain *dom, u32 hartindex,
*/
static int switch_to_next_domain_context(struct hart_context *ctx,
struct hart_context *dom_ctx)
+ MUST_NOT_HOLD(&ctx->dom->assigned_harts_lock)
+ MUST_NOT_HOLD(&dom_ctx->dom->assigned_harts_lock)
{
u32 hartindex = current_hartindex();
struct sbi_trap_context *trap_ctx;
--
2.51.0
More information about the opensbi
mailing list