[PATCH v2 4/9] lib/utils: Make fdt_parse_isa_extensions reentrant
Xiang W
wxjstz at 126.com
Fri Jun 20 21:22:52 PDT 2025
The fdt_parse_isa_extensions function accesses a static variable,
fdt_isa_bitmap_offset, which has reentry issues when concurrent on
multiple cores. This patch fixes this issue.
Signed-off-by: Xiang W <wxjstz at 126.com>
---
lib/utils/fdt/fdt_helper.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
index 0f4859c1..f80928b0 100644
--- a/lib/utils/fdt/fdt_helper.c
+++ b/lib/utils/fdt/fdt_helper.c
@@ -325,6 +325,8 @@ int fdt_parse_timebase_frequency(const void *fdt, unsigned long *freq)
#define RISCV_ISA_EXT_NAME_LEN_MAX 32
static unsigned long fdt_isa_bitmap_offset;
+static spinlock_t fdt_isa_bitmap_offset_lock = SPIN_LOCK_INITIALIZER;
+
static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
{
@@ -461,6 +463,7 @@ int fdt_parse_isa_extensions(const void *fdt, unsigned int hartid,
unsigned long *hart_exts;
struct sbi_scratch *scratch;
+ spin_lock(&fdt_isa_bitmap_offset_lock);
if (!fdt_isa_bitmap_offset) {
fdt_isa_bitmap_offset = sbi_scratch_alloc_offset(
sizeof(*hart_exts) *
@@ -472,6 +475,7 @@ int fdt_parse_isa_extensions(const void *fdt, unsigned int hartid,
if (rc)
return rc;
}
+ spin_unlock(&fdt_isa_bitmap_offset_lock);
scratch = sbi_hartid_to_scratch(hartid);
if (!scratch)
--
2.47.2
More information about the opensbi
mailing list