From 200424e59d0b4b5618a5d4b3af3f3674c6088d3d Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Sat, 13 Apr 2024 08:09:10 +0800 Subject: [PATCH] arch/risc-v: fix RV32 up_addrenv_destroy This patch fixes the issue/12122 for RV32, where the scanning should be limited to user space only. Signed-off-by: Yanfeng Liu --- arch/risc-v/src/common/riscv_addrenv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/src/common/riscv_addrenv.c b/arch/risc-v/src/common/riscv_addrenv.c index a6524abe47..20695ed1e6 100644 --- a/arch/risc-v/src/common/riscv_addrenv.c +++ b/arch/risc-v/src/common/riscv_addrenv.c @@ -539,7 +539,10 @@ int up_addrenv_destroy(arch_addrenv_t *addrenv) ptprev = (uintptr_t *)riscv_pgvaddr(addrenv->spgtables[ARCH_SPGTS - 1]); if (ptprev) { - for (i = 0; i < ENTRIES_PER_PGT; i++, vaddr += pgsize) + /* walk user space only */ + + i = (ARCH_SPGTS < 2) ? vaddr / pgsize : 0; + for (; i < ENTRIES_PER_PGT; i++, vaddr += pgsize) { ptlast = (uintptr_t *)riscv_pgvaddr(mmu_pte_to_paddr(ptprev[i])); if (ptlast)