From 4267c5285a5e4ea46f1f2694c9fbf1fce7958bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E5=8F=AB=E8=BF=99=E4=B8=AA=E5=90=A7?= Date: Tue, 23 May 2023 22:30:31 +0800 Subject: [PATCH 1/4] Memory: Using k_malloc to create a new address for os image signed-off-by: Junfan Song --- subsys/_zvm/vm.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subsys/_zvm/vm.c b/subsys/_zvm/vm.c index 2fcf3a90..a0a1567e 100644 --- a/subsys/_zvm/vm.c +++ b/subsys/_zvm/vm.c @@ -135,11 +135,22 @@ int vm_mem_init(struct vm *vm) { int ret = 0; struct vm_mem_domain *vmem_dm = vm->vmem_domain; + struct vm_mem_partition* vmem_part; + uint64_t phpa_base; + if (vmem_dm->is_init) { ZVM_LOG_WARN("Vm mem has been init before! \n"); return -EMMAO; } + + /* Create a new address space using kmalloc + to store Linux and Zephyr images. */ + vmem_part = vmem_dm->vmem_partition; + phpa_base = (uint64_t) k_malloc(vmem_part->part_hpa_size); + vmem_part->part_hpa_base = phpa_base; + + #ifndef CONFIG_VM_DYNAMIC_MEMORY ret = vm_mem_apart_add(vmem_dm); if (ret) { -- Gitee From c6ae503a3bfec068fe3298cd4d8c20ad41c6e104 Mon Sep 17 00:00:00 2001 From: sjf Date: Wed, 24 May 2023 00:20:48 +0800 Subject: [PATCH 2/4] Memory: Using k_malloc to create a new address for os image signed-off-by: Junfan Song --- subsys/_zvm/vm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/subsys/_zvm/vm.c b/subsys/_zvm/vm.c index a0a1567e..fba8f1b9 100644 --- a/subsys/_zvm/vm.c +++ b/subsys/_zvm/vm.c @@ -135,8 +135,9 @@ int vm_mem_init(struct vm *vm) { int ret = 0; struct vm_mem_domain *vmem_dm = vm->vmem_domain; - struct vm_mem_partition* vmem_part; - uint64_t phpa_base; + struct _dnode *d_node,*ds_node; + struct vm_mem_partition *vpart; + uint64_t hpa_base; if (vmem_dm->is_init) { @@ -146,9 +147,17 @@ int vm_mem_init(struct vm *vm) /* Create a new address space using kmalloc to store Linux and Zephyr images. */ - vmem_part = vmem_dm->vmem_partition; - phpa_base = (uint64_t) k_malloc(vmem_part->part_hpa_size); - vmem_part->part_hpa_base = phpa_base; + + SYS_DLIST_FOR_EACH_NODE_SAFE(&vmem_dm->idle_vpart_list,d_node,ds_node){ + vpart = CONTAINER_OF(d_node,struct vm_mem_patition,vpart_node); + + if(vpart->part_hpa_size != LINUX_VM_MEM_SIZE && vpart->part_hpa_size != ZEPHYR_VM_MEM_SIZE) + continue; + + hpa_base = (uint64_t) k_malloc(vpart->part_hpa_size); + vpart->part_hpa_base = hpa_base; + } + #ifndef CONFIG_VM_DYNAMIC_MEMORY -- Gitee From 7a6a9ccd68fcb6a48530b3b3463c0a417b050c66 Mon Sep 17 00:00:00 2001 From: sjf Date: Wed, 24 May 2023 23:00:00 +0800 Subject: [PATCH 3/4] zvm Memory: Using k_malloc to create a new address for os image signed-off-by: Junfan Song --- include/_zvm/vm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/_zvm/vm.h b/include/_zvm/vm.h index a47dd3d2..290a55f3 100644 --- a/include/_zvm/vm.h +++ b/include/_zvm/vm.h @@ -69,6 +69,8 @@ #define vcpu_need_switch(tid1, tid2) ((VCPU_THREAD(tid1)) || (VCPU_THREAD(tid2))) +#define PAGE_ALIGN(addr) ((addr + CONFIG_MMU_PAGE_SIZE - 1) & ~(CONFIG_MMU_PAGE_SIZE - 1)) + struct vcpu_work; struct z_vm_info; struct os; -- Gitee From 4b0fa69c4fa47a93b77b44af9a89531d5b47abb9 Mon Sep 17 00:00:00 2001 From: sjf Date: Wed, 24 May 2023 23:06:06 +0800 Subject: [PATCH 4/4] zvm Memory: Using k_malloc to create a new address for os image signed-off-by: Junfan Song --- subsys/_zvm/vm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/subsys/_zvm/vm.c b/subsys/_zvm/vm.c index fba8f1b9..1855fecc 100644 --- a/subsys/_zvm/vm.c +++ b/subsys/_zvm/vm.c @@ -149,12 +149,13 @@ int vm_mem_init(struct vm *vm) to store Linux and Zephyr images. */ SYS_DLIST_FOR_EACH_NODE_SAFE(&vmem_dm->idle_vpart_list,d_node,ds_node){ - vpart = CONTAINER_OF(d_node,struct vm_mem_patition,vpart_node); + vpart = CONTAINER_OF(d_node,struct vm_mem_partition,vpart_node); - if(vpart->part_hpa_size != LINUX_VM_MEM_SIZE && vpart->part_hpa_size != ZEPHYR_VM_MEM_SIZE) - continue; + // if(vpart->part_hpa_size != LINUX_VM_MEM_SIZE && vpart->part_hpa_size != ZEPHYR_VM_MEM_SIZE) + // continue; - hpa_base = (uint64_t) k_malloc(vpart->part_hpa_size); + hpa_base = (uint64_t) k_malloc(vpart->part_hpa_size+CONFIG_MMU_PAGE_SIZE-1); + hpa_base = PAGE_ALIGN(hpa_base); vpart->part_hpa_base = hpa_base; } -- Gitee