mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-09-20 15:21:42 +01:00
lib: htif: add TSA annotations
Add Thread Safety Analysis (TSA) annotations for the HTIF driver implementation. This requires annotating the tohost/fromhost and htif_console_buf globals to indicate that they are protected by htif_lock. htif_system_reset() can be excluded since it is only called under special circumstances from sbi_system_reset(), when all other harts have been stopped. 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-10-carlos.lopezr4096@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
+18
-14
@@ -46,22 +46,25 @@
|
||||
|
||||
#define PK_SYS_write 64
|
||||
|
||||
volatile uint64_t tohost __attribute__((section(".htif")));
|
||||
volatile uint64_t fromhost __attribute__((section(".htif")));
|
||||
|
||||
static uint64_t *htif_fromhost = NULL;
|
||||
static uint64_t *htif_tohost = NULL;
|
||||
static bool htif_custom = false;
|
||||
|
||||
static int htif_console_buf;
|
||||
static spinlock_t htif_lock = SPIN_LOCK_INITIALIZER;
|
||||
|
||||
static inline uint64_t __read_tohost(void)
|
||||
volatile uint64_t tohost
|
||||
__attribute__((section(".htif"))) GUARDED_BY(&htif_lock);
|
||||
volatile uint64_t fromhost
|
||||
__attribute__((section(".htif"))) GUARDED_BY(&htif_lock);
|
||||
|
||||
static uint64_t *htif_fromhost PT_GUARDED_BY(&htif_lock) = NULL;
|
||||
static uint64_t *htif_tohost PT_GUARDED_BY(&htif_lock) = NULL;
|
||||
static bool htif_custom = false;
|
||||
|
||||
static int htif_console_buf GUARDED_BY(&htif_lock);
|
||||
|
||||
static inline uint64_t __read_tohost(void) MUST_HOLD(&htif_lock)
|
||||
{
|
||||
return (htif_custom) ? *htif_tohost : tohost;
|
||||
}
|
||||
|
||||
static inline void __write_tohost(uint64_t val)
|
||||
static inline void __write_tohost(uint64_t val) MUST_HOLD(&htif_lock)
|
||||
{
|
||||
if (htif_custom)
|
||||
*htif_tohost = val;
|
||||
@@ -69,12 +72,12 @@ static inline void __write_tohost(uint64_t val)
|
||||
tohost = val;
|
||||
}
|
||||
|
||||
static inline uint64_t __read_fromhost(void)
|
||||
static inline uint64_t __read_fromhost(void) MUST_HOLD(&htif_lock)
|
||||
{
|
||||
return (htif_custom) ? *htif_fromhost : fromhost;
|
||||
}
|
||||
|
||||
static inline void __write_fromhost(uint64_t val)
|
||||
static inline void __write_fromhost(uint64_t val) MUST_HOLD(&htif_lock)
|
||||
{
|
||||
if (htif_custom)
|
||||
*htif_fromhost = val;
|
||||
@@ -82,7 +85,7 @@ static inline void __write_fromhost(uint64_t val)
|
||||
fromhost = val;
|
||||
}
|
||||
|
||||
static void __check_fromhost()
|
||||
static void __check_fromhost() MUST_HOLD(&htif_lock)
|
||||
{
|
||||
uint64_t fh = __read_fromhost();
|
||||
if (!fh)
|
||||
@@ -104,6 +107,7 @@ static void __check_fromhost()
|
||||
}
|
||||
|
||||
static void __set_tohost(uint64_t dev, uint64_t cmd, uint64_t data)
|
||||
MUST_HOLD(&htif_lock)
|
||||
{
|
||||
while (__read_tohost())
|
||||
__check_fromhost();
|
||||
@@ -217,7 +221,7 @@ static int htif_system_reset_check(u32 type, u32 reason)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void htif_system_reset(u32 type, u32 reason)
|
||||
static void htif_system_reset(u32 type, u32 reason) NO_THREAD_SAFETY_ANALYSIS
|
||||
{
|
||||
while (1) {
|
||||
__write_fromhost(0);
|
||||
|
||||
Reference in New Issue
Block a user