From 620965dc2c42e3e80b693afa09e916b00d1bc1f4 Mon Sep 17 00:00:00 2001 From: TXuian <1163589503@qq.com> Date: Tue, 19 Mar 2024 10:22:02 +0800 Subject: [PATCH] Fix one dabort and iabort lock bug. --- .../intr/arm/armv7-a/cortex-a9/error_debug.c | 4 ++-- .../intr/arm/armv7-a/cortex-a9/spinlock.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c index dc1ca496f..318307211 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c @@ -95,7 +95,7 @@ void handle_undefined_instruction(struct trapframe* tf) extern void context_switch(struct context**, struct context*); void dabort_handler(struct trapframe* r) { - if (!is_spinlock_locked(&whole_kernel_lock)) { + if (!is_spinlock_locked(&whole_kernel_lock) || whole_kernel_lock.owner_cpu != cur_cpuid()) { spinlock_lock(&whole_kernel_lock); } uint32_t dfs, dfa; @@ -122,7 +122,7 @@ void dabort_handler(struct trapframe* r) void iabort_handler(struct trapframe* r) { - if (!is_spinlock_locked(&whole_kernel_lock)) { + if (!is_spinlock_locked(&whole_kernel_lock) || whole_kernel_lock.owner_cpu != cur_cpuid()) { spinlock_lock(&whole_kernel_lock); } uint32_t ifs, ifa; diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/spinlock.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/spinlock.c index de844c1b1..05098c6d1 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/spinlock.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/spinlock.c @@ -68,22 +68,22 @@ void spinlock_lock(struct spinlock* lock) ERROR("spinlock %s lock double locked by core %d\n", lock->name, lock->owner_cpu); panic(""); } - // _spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER); - // doubleListAddOnBack(&core_lock_request[cur_cpuid()].node, &lock_request_guard); - // _spinlock_unlock(&request_lock); + _spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER); + doubleListAddOnBack(&core_lock_request[cur_cpuid()].node, &lock_request_guard); + _spinlock_unlock(&request_lock); - // while (lock_request_guard.next != &core_lock_request[cur_cpuid()].node) - // ; + while (lock_request_guard.next != &core_lock_request[cur_cpuid()].node) + ; _spinlock_lock(lock, SPINLOCK_LOCK_WAITFOREVER); } void spinlock_unlock(struct spinlock* lock) { - // assert(lock_request_guard.next == &core_lock_request[cur_cpuid()].node); - // _spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER); - // _double_list_del(core_lock_request[cur_cpuid()].node.prev, core_lock_request[cur_cpuid()].node.next); - // _spinlock_unlock(&request_lock); + assert(lock_request_guard.next == &core_lock_request[cur_cpuid()].node); + _spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER); + _double_list_del(core_lock_request[cur_cpuid()].node.prev, core_lock_request[cur_cpuid()].node.next); + _spinlock_unlock(&request_lock); _spinlock_unlock(lock); }