From c4901d6f4b7a2faa03a9a22ec3559a2cc249e5bd Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Wed, 5 Oct 2022 07:16:01 +0900 Subject: [PATCH] arch: risc-v: Introduce g_percpu_spin in riscv_percpu.c Summary: - This commit introduces g_percpu_spin to avoid deadlock in riscv_percpu.c instead of using the global spinlock. Impact: - None Testing: - Tested with rv-virt:knsh64 and rv-virt:ksmp64 (will be added later) Signed-off-by: Masayuki Ishikawa --- arch/risc-v/src/common/riscv_percpu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/risc-v/src/common/riscv_percpu.c b/arch/risc-v/src/common/riscv_percpu.c index 6b55e54c764..d80c3d8efa0 100644 --- a/arch/risc-v/src/common/riscv_percpu.c +++ b/arch/risc-v/src/common/riscv_percpu.c @@ -55,6 +55,7 @@ static_assert(RISCV_PERCPU_IRQSTACK == offsetof(riscv_percpu_t, irq_stack), static riscv_percpu_t g_percpu[HART_CNT]; static sq_queue_t g_freelist; static uintptr_t g_initialized; +static spinlock_t g_percpu_spin; /**************************************************************************** * Private Functions @@ -76,7 +77,7 @@ static void riscv_percpu_init(void) /* Need to lock access during configuration */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_percpu_spin); /* Initialize if not done so already */ @@ -102,7 +103,7 @@ static void riscv_percpu_init(void) } out_with_lock: - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_percpu_spin, flags); } /**************************************************************************** @@ -131,9 +132,9 @@ void riscv_percpu_add_hart(uintptr_t hartid) /* Get free entry for this hart, this must not fail */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_percpu_spin); percpu = (riscv_percpu_t *)sq_remfirst(&g_freelist); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_percpu_spin, flags); DEBUGASSERT(percpu); /* Assign hartid, stack has already been assigned */