From d6d7f43c9edec1c5c93d14f571d9fabdb3f0bd34 Mon Sep 17 00:00:00 2001 From: wdah Date: Fri, 1 Mar 2024 21:45:52 +0800 Subject: [PATCH 1/4] oee zvm hvc --- arch/arm64/core/virtualization/trap_handler.c | 67 +++++++++++++++++++ subsys/virtualization/vm_cpu.c | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/arch/arm64/core/virtualization/trap_handler.c b/arch/arm64/core/virtualization/trap_handler.c index 6f3ca2014..b33661563 100644 --- a/arch/arm64/core/virtualization/trap_handler.c +++ b/arch/arm64/core/virtualization/trap_handler.c @@ -175,13 +175,80 @@ static int cpu_il_exe_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) return 0; } +/* get the hvc 24-0 */ +#define ZVM_OEE_CREATE_RUN 1 +#define ZVM_OEE_PAUSE 2 +#define ZVM_OEE_STOP 3 +#define ZVM_OEE_DELETE 4 +#define ZVM_OEE_TEST 0x4a48 +int new_num=1; +#define BIT_MASK0(last, first) \ + ((0xffffffffffffffffULL >> (64 - ((last) + 1 - (first)))) << (first)) + +#define GET_FIELD(value, last, first) \ + (((value) & BIT_MASK0((last), (first))) >> (first)) + +#define ESR_ISS(esr) GET_FIELD((esr), 24, 0) + +static struct k_spinlock shell_vmops_lock_hvc; + static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) { + k_spinlock_key_t key; + key = k_spin_lock(&shell_vmops_lock_hvc); + int ret = 0; + ARG_UNUSED(arch_ctxt); ARG_UNUSED(esr_elx); + + unsigned long esr_el_2= ESR_ISS(esr_elx); + unsigned long code = GET_FIELD((esr_elx),15,0); + + ZVM_LOG_WARN("TEST \n "); + char *args0[] = {"new", "-t", "zephyr"}; + char *args1[] = {"run", "-n", "0"}; + char *args2[] = {"pause", "-n", "0"}; + char *args3[] = {"delete", "-n", "0"}; + char *args4[] = {"info"}; + + switch (code) + { + case ZVM_OEE_CREATE_RUN: + /* create a zephyr vm */ + if(new_num){ + ret = zvm_new_guest(3, args0); + ret = zvm_info_guest(3, args4); + new_num--; + } + /* run the zephyr vm*/ + ret = zvm_run_guest(3, args1); + break; + case ZVM_OEE_PAUSE: + /* pause the created zephyr vm */ + //ret = zvm_run_guest(3, args1); + ret = zvm_pause_guest(3, args2); + break; + case ZVM_OEE_STOP: + /* stop the zephyr */ + ret = zvm_pause_guest(3, args2); + break; + case ZVM_OEE_DELETE: + /* delete the zephyr */ + ret = zvm_delete_guest(3, args3); + break; + default: + ZVM_LOG_WARN("This is a TEST \n "); + break; + } + k_spin_unlock(&shell_vmops_lock_hvc, key); #ifdef CONFIG_ZVM_TIME_MEASURE vm_irq_timing_print(); #endif + /*The hvc instruction defaults to adding +0x4 to the PC value, + but zvm has already performed +0x4 during processing, causing + a skip of the next assembly instruction. Here, -0x4 is used to + fix this bug.*/ + arch_ctxt->pc -= 0x4; return 0; } diff --git a/subsys/virtualization/vm_cpu.c b/subsys/virtualization/vm_cpu.c index 35ce98b73..0e3713cb0 100644 --- a/subsys/virtualization/vm_cpu.c +++ b/subsys/virtualization/vm_cpu.c @@ -99,7 +99,7 @@ static void vcpu_context_switch(struct k_thread *new_thread, break; } } - ZVM_LOG_INFO("** load_vcpu_context, thread: %p, new vcpu thread? : %d \n ", new_thread, VCPU_THREAD(new_thread)); + //ZVM_LOG_INFO("** load_vcpu_context, thread: %p, new vcpu thread? : %d \n ", new_thread, VCPU_THREAD(new_thread)); if (VCPU_THREAD(new_thread)) { struct vcpu *new_vcpu = new_thread->vcpu_struct; -- Gitee From 56d67af8c17834ac110a9895463aa5c297cc4ed1 Mon Sep 17 00:00:00 2001 From: wdah Date: Mon, 25 Mar 2024 22:39:23 +0800 Subject: [PATCH 2/4] zvm_oee --- arch/arm64/core/virtualization/trap_handler.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/arch/arm64/core/virtualization/trap_handler.c b/arch/arm64/core/virtualization/trap_handler.c index b33661563..6f4c411d3 100644 --- a/arch/arm64/core/virtualization/trap_handler.c +++ b/arch/arm64/core/virtualization/trap_handler.c @@ -176,11 +176,6 @@ static int cpu_il_exe_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) } /* get the hvc 24-0 */ -#define ZVM_OEE_CREATE_RUN 1 -#define ZVM_OEE_PAUSE 2 -#define ZVM_OEE_STOP 3 -#define ZVM_OEE_DELETE 4 -#define ZVM_OEE_TEST 0x4a48 int new_num=1; #define BIT_MASK0(last, first) \ ((0xffffffffffffffffULL >> (64 - ((last) + 1 - (first)))) << (first)) @@ -204,7 +199,6 @@ static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) unsigned long esr_el_2= ESR_ISS(esr_elx); unsigned long code = GET_FIELD((esr_elx),15,0); - ZVM_LOG_WARN("TEST \n "); char *args0[] = {"new", "-t", "zephyr"}; char *args1[] = {"run", "-n", "0"}; char *args2[] = {"pause", "-n", "0"}; @@ -213,7 +207,7 @@ static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) switch (code) { - case ZVM_OEE_CREATE_RUN: + case 1: /* create a zephyr vm */ if(new_num){ ret = zvm_new_guest(3, args0); @@ -223,19 +217,15 @@ static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) /* run the zephyr vm*/ ret = zvm_run_guest(3, args1); break; - case ZVM_OEE_PAUSE: + case 2: /* pause the created zephyr vm */ //ret = zvm_run_guest(3, args1); ret = zvm_pause_guest(3, args2); break; - case ZVM_OEE_STOP: + case 3: /* stop the zephyr */ ret = zvm_pause_guest(3, args2); break; - case ZVM_OEE_DELETE: - /* delete the zephyr */ - ret = zvm_delete_guest(3, args3); - break; default: ZVM_LOG_WARN("This is a TEST \n "); break; -- Gitee From 370d72927d113fa8b7b744131bb11278ca3f7c6b Mon Sep 17 00:00:00 2001 From: wdah Date: Mon, 25 Mar 2024 22:59:29 +0800 Subject: [PATCH 3/4] oee control zephyr in zvm --- arch/arm64/core/virtualization/trap_handler.c | 12 ++++++------ subsys/virtualization/vm_cpu.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm64/core/virtualization/trap_handler.c b/arch/arm64/core/virtualization/trap_handler.c index 6f4c411d3..95ff227f3 100644 --- a/arch/arm64/core/virtualization/trap_handler.c +++ b/arch/arm64/core/virtualization/trap_handler.c @@ -219,12 +219,11 @@ static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) break; case 2: /* pause the created zephyr vm */ - //ret = zvm_run_guest(3, args1); ret = zvm_pause_guest(3, args2); break; case 3: /* stop the zephyr */ - ret = zvm_pause_guest(3, args2); + ret = zvm_delete_guest(3, args3); break; default: ZVM_LOG_WARN("This is a TEST \n "); @@ -234,10 +233,11 @@ static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) #ifdef CONFIG_ZVM_TIME_MEASURE vm_irq_timing_print(); #endif - /*The hvc instruction defaults to adding +0x4 to the PC value, - but zvm has already performed +0x4 during processing, causing - a skip of the next assembly instruction. Here, -0x4 is used to - fix this bug.*/ + /**The hvc instruction defaults to adding +0x4 to the PC value, + * but zvm has already performed +0x4 during processing, causing + * a skip of the next assembly instruction. Here, -0x4 is used + * to fix this bug. + */ arch_ctxt->pc -= 0x4; return 0; } diff --git a/subsys/virtualization/vm_cpu.c b/subsys/virtualization/vm_cpu.c index 0e3713cb0..a62dced12 100644 --- a/subsys/virtualization/vm_cpu.c +++ b/subsys/virtualization/vm_cpu.c @@ -99,7 +99,7 @@ static void vcpu_context_switch(struct k_thread *new_thread, break; } } - //ZVM_LOG_INFO("** load_vcpu_context, thread: %p, new vcpu thread? : %d \n ", new_thread, VCPU_THREAD(new_thread)); + if (VCPU_THREAD(new_thread)) { struct vcpu *new_vcpu = new_thread->vcpu_struct; -- Gitee From 359f4a2741ff68a57b9c5936c0b2c25d5aa1613d Mon Sep 17 00:00:00 2001 From: wdah Date: Fri, 29 Mar 2024 20:09:09 +0800 Subject: [PATCH 4/4] modules:add zvm oee hvc Added OEE control ZVM to create, start/run, and stop Zephyr VMs except delete. Signed-off-by: wdah --- arch/arm64/core/virtualization/trap_handler.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/arm64/core/virtualization/trap_handler.c b/arch/arm64/core/virtualization/trap_handler.c index 95ff227f3..b93d78c84 100644 --- a/arch/arm64/core/virtualization/trap_handler.c +++ b/arch/arm64/core/virtualization/trap_handler.c @@ -176,7 +176,6 @@ static int cpu_il_exe_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) } /* get the hvc 24-0 */ -int new_num=1; #define BIT_MASK0(last, first) \ ((0xffffffffffffffffULL >> (64 - ((last) + 1 - (first)))) << (first)) @@ -209,24 +208,24 @@ static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) { case 1: /* create a zephyr vm */ - if(new_num){ - ret = zvm_new_guest(3, args0); - ret = zvm_info_guest(3, args4); - new_num--; - } + ret = zvm_new_guest(3, args0); + /* show zephyr vm information*/ + ret = zvm_info_guest(3, args4); + break; + case 2: /* run the zephyr vm*/ ret = zvm_run_guest(3, args1); break; - case 2: + case 3: /* pause the created zephyr vm */ ret = zvm_pause_guest(3, args2); break; - case 3: + case 4: /* stop the zephyr */ - ret = zvm_delete_guest(3, args3); - break; + ZVM_LOG_WARN("CAN NOT DELETE NOW! \n "); + break; default: - ZVM_LOG_WARN("This is a TEST \n "); + ZVM_LOG_WARN("UNKNOWN CODE\n "); break; } k_spin_unlock(&shell_vmops_lock_hvc, key); -- Gitee