aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel/vmem.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-30 02:18:12 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-30 02:18:12 +0200
commite7b5881903ad81efee63966e7d2c42524d465dfc (patch)
tree86753586a7be933685c313c172545bdaf9086dd1 /arch/riscv64/kernel/vmem.c
parent44a73ecab6e91519627786a5101cd4f1a2f2b0d7 (diff)
downloadkmi-e7b5881903ad81efee63966e7d2c42524d465dfc.tar.gz
kmi-e7b5881903ad81efee63966e7d2c42524d465dfc.zip
tests pass
Diffstat (limited to 'arch/riscv64/kernel/vmem.c')
-rw-r--r--arch/riscv64/kernel/vmem.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 5a44f53..1648706 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -309,9 +309,7 @@ stat_t map_vpage(struct vmem *branch, pm_t paddr, vm_t vaddr, vmflags_t flags,
}
size_t idx = vm_to_index(vaddr, top);
- if (is_branch(branch->leaf[idx]))
- /* something has gone terribly wrong? */
- __destroy_branch(branch->leaf[idx]);
+ assert(!is_branch(branch->leaf[idx]));
branch->leaf[idx] =
(struct vmem *)to_pte((pm_t)__pa(paddr), vp_flags(flags));
@@ -482,6 +480,20 @@ void destroy_vmem(struct vmem *b)
free_page(MM_KPAGE, (pm_t)b);
}
+void destroy_rpcmem(struct vmem *b)
+{
+ if (!b)
+ return;
+
+ /* only destroy branches that the rpc vmem is sure to own */
+ for (size_t i = CSTACK_PAGE; i < KERNEL_PAGE; ++i) {
+ if (is_branch(b->leaf[i]))
+ __destroy_branch((struct vmem *)pte_addr(b->leaf[i]));
+ }
+
+ free_page(MM_KPAGE, (pm_t)b);
+}
+
/**
* Helper for mapping in the kernel virtual page.
* Remember that the kernel lives on its own in a 2MiB (riscv64) region at