From d862816a51ab6fec2321f0410e8aea2d05507542 Mon Sep 17 00:00:00 2001 From: Shell Date: Wed, 16 Aug 2023 15:38:59 +0800 Subject: [components/mm] add unmap page API (#7834) Signed-off-by: Shell --- libcpu/aarch64/common/mmu.c | 3 ++- libcpu/aarch64/common/trap.c | 8 ++++++-- libcpu/arm/cortex-a/trap.c | 4 +++- libcpu/risc-v/t-head/c906/trap.c | 4 +++- libcpu/risc-v/virt64/trap.c | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-) (limited to 'libcpu') diff --git a/libcpu/aarch64/common/mmu.c b/libcpu/aarch64/common/mmu.c index cd38d74ef3..e8a0bfeefb 100644 --- a/libcpu/aarch64/common/mmu.c +++ b/libcpu/aarch64/common/mmu.c @@ -327,7 +327,8 @@ void rt_hw_mmu_unmap(rt_aspace_t aspace, void *v_addr, size_t size) while (npages--) { MM_PGTBL_LOCK(aspace); - _kenrel_unmap_4K(aspace->page_table, v_addr); + if (rt_hw_mmu_v2p(aspace, v_addr) != ARCH_MAP_FAILED) + _kenrel_unmap_4K(aspace->page_table, v_addr); MM_PGTBL_UNLOCK(aspace); v_addr = (char *)v_addr + ARCH_PAGE_SIZE; } diff --git a/libcpu/aarch64/common/trap.c b/libcpu/aarch64/common/trap.c index 8e97a8b0aa..6faa740531 100644 --- a/libcpu/aarch64/common/trap.c +++ b/libcpu/aarch64/common/trap.c @@ -14,7 +14,7 @@ #include #include "interrupt.h" -#include "mm_fault.h" +#include "mm_aspace.h" #include @@ -82,6 +82,8 @@ int check_user_stack(unsigned long esr, struct rt_hw_exp_stack *regs) ec = (unsigned char)((esr >> 26) & 0x3fU); enum rt_mm_fault_op fault_op; enum rt_mm_fault_type fault_type; + struct rt_lwp *lwp; + switch (ec) { case 0x20: @@ -107,7 +109,9 @@ int check_user_stack(unsigned long esr, struct rt_hw_exp_stack *regs) .fault_type = fault_type, .fault_vaddr = dfar, }; - if (rt_aspace_fault_try_fix(&msg)) + lwp = lwp_self(); + RT_ASSERT(lwp); + if (rt_aspace_fault_try_fix(lwp->aspace, &msg)) { ret = 1; } diff --git a/libcpu/arm/cortex-a/trap.c b/libcpu/arm/cortex-a/trap.c index 0aafa55968..02a6e5c316 100644 --- a/libcpu/arm/cortex-a/trap.c +++ b/libcpu/arm/cortex-a/trap.c @@ -46,6 +46,7 @@ void check_user_fault(struct rt_hw_exp_stack *regs, uint32_t pc_adj, char *info) int check_user_stack(struct rt_hw_exp_stack *regs) { void *dfar = RT_NULL; + struct rt_lwp *lwp; asm volatile("MRC p15, 0, %0, c6, c0, 0" : "=r"(dfar)); if ((dfar >= (void *)USER_STACK_VSTART) && (dfar < (void *)USER_STACK_VEND)) @@ -55,7 +56,8 @@ int check_user_stack(struct rt_hw_exp_stack *regs) .fault_type = MM_FAULT_TYPE_PAGE_FAULT, .fault_vaddr = dfar, }; - if (rt_aspace_fault_try_fix(&msg)) + lwp = lwp_self(); + if (lwp && rt_aspace_fault_try_fix(lwp->aspace, &msg)) { regs->pc -= 8; return 1; diff --git a/libcpu/risc-v/t-head/c906/trap.c b/libcpu/risc-v/t-head/c906/trap.c index 184765507b..35d8255a97 100644 --- a/libcpu/risc-v/t-head/c906/trap.c +++ b/libcpu/risc-v/t-head/c906/trap.c @@ -155,6 +155,7 @@ static const char *get_exception_msg(int id) void handle_user(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw_stack_frame *sp) { rt_size_t id = __MASKVALUE(scause, __MASK(63UL)); + struct rt_lwp *lwp; /* user page fault */ enum rt_mm_fault_op fault_op; @@ -203,13 +204,14 @@ void handle_user(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw if (fault_op) { + lwp = lwp_self(); struct rt_aspace_fault_msg msg = { .fault_op = fault_op, .fault_type = fault_type, .fault_vaddr = (void *)stval, }; - if (rt_aspace_fault_try_fix(&msg)) + if (lwp && rt_aspace_fault_try_fix(lwp->aspace, &msg)) { return; } diff --git a/libcpu/risc-v/virt64/trap.c b/libcpu/risc-v/virt64/trap.c index f8413c9d78..3839c03110 100644 --- a/libcpu/risc-v/virt64/trap.c +++ b/libcpu/risc-v/virt64/trap.c @@ -152,6 +152,7 @@ static const char *get_exception_msg(int id) void handle_user(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw_stack_frame *sp) { rt_size_t id = __MASKVALUE(scause, __MASK(63UL)); + struct rt_lwp *lwp; /* user page fault */ enum rt_mm_fault_op fault_op; @@ -200,13 +201,14 @@ void handle_user(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw if (fault_op) { + lwp = lwp_self(); struct rt_aspace_fault_msg msg = { .fault_op = fault_op, .fault_type = fault_type, .fault_vaddr = (void *)stval, }; - if (rt_aspace_fault_try_fix(&msg)) + if (lwp && rt_aspace_fault_try_fix(lwp->aspace, &msg)) { return; } -- cgit v1.3.1