mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-09-20 15:21:42 +01:00
lib: sbi_locks: annotate spinlock APIs for TSA
Add Thread Safety Analysis (TSA) annotations for spinlock APIs, allowing
the compiler to reason about lock acquisition and release.
Annotations have a different meaning if used in header declarations vs C
file implementations. In header declarations, they specify the semantics
of the given function, meaning that we must specify that the spinlock
functions acquire and release a lock ("capability" in clang terms).
In function implementations, attributes affect the function body and
callers in the same translation unit; since the spinlock functions
contain inline assembly, they must be excluded from analysis.
Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260909162322.29778-4-carlos.lopezr4096@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -20,7 +20,7 @@ typedef struct {
|
|||||||
u16 owner;
|
u16 owner;
|
||||||
u16 next;
|
u16 next;
|
||||||
#endif
|
#endif
|
||||||
} __aligned(4) spinlock_t;
|
} __aligned(4) CAPABILITY("spinlock") spinlock_t;
|
||||||
|
|
||||||
#define __SPIN_LOCK_UNLOCKED \
|
#define __SPIN_LOCK_UNLOCKED \
|
||||||
(spinlock_t) { 0, 0 }
|
(spinlock_t) { 0, 0 }
|
||||||
@@ -36,10 +36,10 @@ typedef struct {
|
|||||||
|
|
||||||
bool spin_lock_check(spinlock_t *lock);
|
bool spin_lock_check(spinlock_t *lock);
|
||||||
|
|
||||||
bool spin_trylock(spinlock_t *lock);
|
bool spin_trylock(spinlock_t *lock) TRY_ACQUIRE(true, *lock);
|
||||||
|
|
||||||
void spin_lock(spinlock_t *lock);
|
void spin_lock(spinlock_t *lock) ACQUIRE(*lock) MUST_NOT_HOLD(*lock);
|
||||||
|
|
||||||
void spin_unlock(spinlock_t *lock);
|
void spin_unlock(spinlock_t *lock) RELEASE(*lock);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ bool spin_trylock(spinlock_t *lock)
|
|||||||
return l0 == 0;
|
return l0 == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spin_lock(spinlock_t *lock)
|
void spin_lock(spinlock_t *lock) NO_THREAD_SAFETY_ANALYSIS
|
||||||
{
|
{
|
||||||
unsigned long inc = 1u << TICKET_SHIFT;
|
unsigned long inc = 1u << TICKET_SHIFT;
|
||||||
unsigned long mask = 0xffffu;
|
unsigned long mask = 0xffffu;
|
||||||
@@ -84,7 +84,7 @@ void spin_lock(spinlock_t *lock)
|
|||||||
: "memory");
|
: "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
void spin_unlock(spinlock_t *lock)
|
void spin_unlock(spinlock_t *lock) NO_THREAD_SAFETY_ANALYSIS
|
||||||
{
|
{
|
||||||
__smp_store_release(&lock->owner, lock->owner + 1);
|
__smp_store_release(&lock->owner, lock->owner + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user