From 0ed8adfe3ae59672e284331d40ef3b9e0bc8e094 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Sun, 25 Apr 2021 20:16:51 +0800 Subject: [PATCH 1/3] fix: no exception information output, when the system is abnormal after holding the scheduling lock in SMP. Change-Id: Idb793a5446126e638af52ff78b43bb7f8271317c --- arch/arm/arm/include/los_hw_cpu.h | 18 +++++++++++++++ arch/arm/arm/src/los_exc.c | 38 +++++++++++++++++++++++++------ arch/arm/arm/src/los_hw_exc.S | 2 -- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/arch/arm/arm/include/los_hw_cpu.h b/arch/arm/arm/include/los_hw_cpu.h index 02c7ea4d..f6fc4460 100644 --- a/arch/arm/arm/include/los_hw_cpu.h +++ b/arch/arm/arm/include/los_hw_cpu.h @@ -189,6 +189,24 @@ STATIC INLINE UINT32 ArchIntUnlock(VOID) return intSave; } +STATIC INLINE VOID ArchIrqDisable(VOID) +{ + __asm__ __volatile__( + "cpsid i " + : + : + : "memory", "cc"); +} + +STATIC INLINE VOID ArchIrqEnable(VOID) +{ + __asm__ __volatile__( + "cpsie i " + : + : + : "memory", "cc"); +} + #else STATIC INLINE UINT32 ArchIntLock(VOID) diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c index 3197c397..8a085942 100644 --- a/arch/arm/arm/src/los_exc.c +++ b/arch/arm/arm/src/los_exc.c @@ -185,18 +185,32 @@ STATIC INT32 OsDecodeDataFSR(UINT32 regDFSR) #ifdef LOSCFG_KERNEL_VM UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT32 fsr) { - PRINT_INFO("page fault entry!!!\n"); - BOOL instruction_fault = FALSE; + BOOL instructionFault = FALSE; UINT32 pfFlags = 0; UINT32 fsrFlag; BOOL write = FALSE; + UINT32 ret; +#ifdef LOSCFG_KERNEL_SMP + BOOL irqEnable = TRUE; +#endif + PRINT_INFO("page fault entry!!!\n"); if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) { return LOS_ERRNO_VM_NOT_FOUND; } - +#ifdef LOSCFG_KERNEL_SMP + irqEnable = !(LOS_SpinHeld(&g_taskSpin) && (OsPercpuGet()->taskLockCnt != 0)); + if (irqEnable) { + ArchIrqEnable(); + } else { + PrintExcInfo("[ERR][%s] may be held scheduler lock when entering [%s]\n", + OsCurrTaskGet()->taskName, __FUNCTION__); + } +#else + ArchIrqEnable(); +#endif if (excType == OS_EXCEPT_PREFETCH_ABORT) { - instruction_fault = TRUE; + instructionFault = TRUE; } else { write = !!BIT_GET(fsr, WNR_BIT); } @@ -214,13 +228,23 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3 BOOL user = (frame->regCPSR & CPSR_MODE_MASK) == CPSR_MODE_USR; pfFlags |= write ? VM_MAP_PF_FLAG_WRITE : 0; pfFlags |= user ? VM_MAP_PF_FLAG_USER : 0; - pfFlags |= instruction_fault ? VM_MAP_PF_FLAG_INSTRUCTION : 0; + pfFlags |= instructionFault ? VM_MAP_PF_FLAG_INSTRUCTION : 0; pfFlags |= VM_MAP_PF_FLAG_NOT_PRESENT; - return OsVmPageFaultHandler(far, pfFlags, frame); + ret = OsVmPageFaultHandler(far, pfFlags, frame); + break; } default: - return LOS_ERRNO_VM_NOT_FOUND; + ret = LOS_ERRNO_VM_NOT_FOUND; + break; } +#ifdef LOSCFG_KERNEL_SMP + if (irqEnable) { + ArchIrqDisable(); + } +#else + ArchIrqDisable(); +#endif + return ret; } #endif diff --git a/arch/arm/arm/src/los_hw_exc.S b/arch/arm/arm/src/los_hw_exc.S index 007537d1..6a02fb89 100644 --- a/arch/arm/arm/src/los_hw_exc.S +++ b/arch/arm/arm/src/los_hw_exc.S @@ -205,9 +205,7 @@ _osExceptSwiHdl: PUSH_FPU_REGS R1 MOV FP, #0 @ Init frame pointer - CPSIE I BLX OsArmA32SyscallHandle - CPSID I POP_FPU_REGS R1 ADD SP, SP,#4 From 28aa777191e7b41e4f1f346ab79f8688edc59c6d Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Sun, 25 Apr 2021 20:53:33 +0800 Subject: [PATCH 2/3] fix: no exception information output, when the system is abnormal after holding the scheduling lock in SMP. Change-Id: Ib10128fede9aa3e00269f1265089a917ffd96d88 --- arch/arm/arm/src/los_hw_exc.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/arm/src/los_hw_exc.S b/arch/arm/arm/src/los_hw_exc.S index 6a02fb89..a1d7d2e9 100644 --- a/arch/arm/arm/src/los_hw_exc.S +++ b/arch/arm/arm/src/los_hw_exc.S @@ -205,7 +205,9 @@ _osExceptSwiHdl: PUSH_FPU_REGS R1 MOV FP, #0 @ Init frame pointer + CPSIE I BLX OsArmA32SyscallHandle + CPSID I POP_FPU_REGS R1 ADD SP, SP,#4 @@ -329,9 +331,7 @@ _osExcPageFault: MOV R5, R0 MOV R8, R2 MOV R9, R3 - CPSIE I BLX OsArmSharedPageFault - CPSID I POP_FPU_REGS R1 MOV SP, R4 From 5bf4d1c7128e6718611bbec23cb4373bcb3bfe55 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Mon, 26 Apr 2021 20:13:13 +0800 Subject: [PATCH 3/3] fix: no exception information output, when the system is abnormal after holding the scheduling lock in SMP. Change-Id: I6f148d7b36d7aa6d0df09300949f53ea3c3d63b7 --- arch/arm/arm/src/los_exc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c index 8a085942..dd94396d 100644 --- a/arch/arm/arm/src/los_exc.c +++ b/arch/arm/arm/src/los_exc.c @@ -190,16 +190,13 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3 UINT32 fsrFlag; BOOL write = FALSE; UINT32 ret; -#ifdef LOSCFG_KERNEL_SMP - BOOL irqEnable = TRUE; -#endif PRINT_INFO("page fault entry!!!\n"); if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) { return LOS_ERRNO_VM_NOT_FOUND; } -#ifdef LOSCFG_KERNEL_SMP - irqEnable = !(LOS_SpinHeld(&g_taskSpin) && (OsPercpuGet()->taskLockCnt != 0)); +#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION) + BOOL irqEnable = !(LOS_SpinHeld(&g_taskSpin) && (OsPercpuGet()->taskLockCnt != 0)); if (irqEnable) { ArchIrqEnable(); } else { @@ -237,7 +234,7 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3 ret = LOS_ERRNO_VM_NOT_FOUND; break; } -#ifdef LOSCFG_KERNEL_SMP +#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION) if (irqEnable) { ArchIrqDisable(); }