From e4b15845776b9c082bc314210f555830846e3ad6 Mon Sep 17 00:00:00 2001 From: YuanXin-Intel Date: Tue, 11 Jun 2024 18:06:54 -0400 Subject: [PATCH] Change Service VM to supervisor role 1. Enable Service VM to power off or restart the whole platform even when RTVM is running. 2. Allow Service VM stop the RTVM using acrnctl tool with option "stop -f". 3. Add 'Service VM supervisor role enabled' option in ACRN configurator Tracked-On: #8618 Signed-off-by: YuanXin-Intel Reviewed-by: Junjie Mao Reviewed-by: Jian Jun Chen --- devicemodel/core/main.c | 3 +-- devicemodel/core/monitor.c | 2 +- devicemodel/hw/pci/passthrough.c | 11 ++++------- hypervisor/arch/x86/guest/vm.c | 5 ++--- hypervisor/common/hypercall.c | 6 +----- hypervisor/include/arch/x86/asm/guest/vm.h | 5 +++++ hypervisor/include/arch/x86/asm/vm_config.h | 2 +- misc/config_tools/schema/config.xsd | 5 +++++ misc/config_tools/xforms/config_common.xsl | 4 ++++ misc/config_tools/xforms/misc_cfg.h.xsl | 12 ++++++++++++ 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index e2d2905243..fa68c6d7e5 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -830,8 +830,7 @@ vm_loop(struct vmctx *ctx) break; } - /* RTVM can't be reset */ - if ((VM_SUSPEND_SYSTEM_RESET == vm_get_suspend_mode()) && (!is_rtvm)) { + if (VM_SUSPEND_SYSTEM_RESET == vm_get_suspend_mode()) { vm_system_reset(ctx); } diff --git a/devicemodel/core/monitor.c b/devicemodel/core/monitor.c index fe34047299..9ecdc0c6fa 100644 --- a/devicemodel/core/monitor.c +++ b/devicemodel/core/monitor.c @@ -350,7 +350,7 @@ static void handle_stop(struct mngr_msg *msg, int client_fd, void *param) ack.msgid = msg->msgid; ack.timestamp = msg->timestamp; - if (msg->data.acrnd_stop.force && !is_rtvm) { + if (msg->data.acrnd_stop.force) { pr_info("%s: setting VM state to %s\n", __func__, vm_state_to_str(VM_SUSPEND_POWEROFF)); vm_set_suspend_mode(VM_SUSPEND_POWEROFF); ack.data.err = 0; diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index 5ac6cbc99f..e87e261b87 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -1012,13 +1012,10 @@ passthru_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts) pciaccess_cleanup(); free(ptdev); - if (!is_rtvm) { - /* Let the HV to deassign the pt device for RTVM, In this case, the RTVM - * could still be alive if DM died. - */ - vm_deassign_pcidev(ctx, &pcidev); - } - if (!is_rtvm && phys_bdf) { + /*Let device model to deassign pt device for all VMs, including RTVM if the Service VM plays + *supervisor role.*/ + vm_deassign_pcidev(ctx, &pcidev); + if (phys_bdf) { memset(reset_path, 0, sizeof(reset_path)); snprintf(reset_path, 40, "/sys/bus/pci/devices/0000:%02x:%02x.%x/reset", diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index f4a247be89..f3a21b0d96 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -1048,9 +1048,8 @@ void pause_vm(struct acrn_vm *vm) uint16_t i; struct acrn_vcpu *vcpu = NULL; - /* For RTVM, we can only pause its vCPUs when it is powering off by itself */ - if (((!is_rt_vm(vm)) && (vm->state == VM_RUNNING)) || - ((is_rt_vm(vm)) && (vm->state == VM_READY_TO_POWEROFF)) || + if (((is_severity_pass(vm->vm_id)) && (vm->state == VM_RUNNING)) || + (vm->state == VM_READY_TO_POWEROFF) || (vm->state == VM_CREATED)) { foreach_vcpu(i, vm, vcpu) { zombie_vcpu(vcpu, VCPU_ZOMBIE); diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index bf4d74d5c6..5d60cc5cfb 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -69,11 +70,6 @@ bool is_hypercall_from_ring0(void) return ret; } -inline static bool is_severity_pass(uint16_t target_vmid) -{ - return SEVERITY_SERVICE_VM >= get_vm_severity(target_vmid); -} - /** * @brief offline vcpu from Service VM * diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index 71b0329f40..7d2f16dad2 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -233,6 +233,11 @@ static inline uint16_t vmid_2_rel_vmid(uint16_t service_vmid, uint16_t vmid) { return (vmid - service_vmid); } +static inline bool is_severity_pass(uint16_t target_vmid) +{ + return SEVERITY_SERVICE_VM >= get_vm_severity(target_vmid); +} + void make_shutdown_vm_request(uint16_t pcpu_id); bool need_shutdown_vm(uint16_t pcpu_id); int32_t shutdown_vm(struct acrn_vm *vm); diff --git a/hypervisor/include/arch/x86/asm/vm_config.h b/hypervisor/include/arch/x86/asm/vm_config.h index 14311652b9..476e5cbd19 100644 --- a/hypervisor/include/arch/x86/asm/vm_config.h +++ b/hypervisor/include/arch/x86/asm/vm_config.h @@ -70,7 +70,7 @@ /* ACRN guest severity */ enum acrn_vm_severity { SEVERITY_SAFETY_VM = 0x40U, - SEVERITY_RTVM = 0x30U, + SEVERITY_RTVM = RTVM_SEVERITY_LEVEL, SEVERITY_SERVICE_VM = 0x20U, SEVERITY_STANDARD_VM = 0x10U, }; diff --git a/misc/config_tools/schema/config.xsd b/misc/config_tools/schema/config.xsd index b75b91f021..2569c93e4e 100644 --- a/misc/config_tools/schema/config.xsd +++ b/misc/config_tools/schema/config.xsd @@ -63,6 +63,11 @@ Enable multiboot2 protocol support (with multiboot1 downward compatibility). If multiboot1 meets your requirements, disable this feature to reduce hypervisor code size. + + + Enable Service VM to play the supervisor role. If Enabled, the severity level of Service VM is higher than RTVM. + + Enable detection of split locks. A split lock can negatively affect an application's real-time performance. If a lock is detected, an alignment check exception #AC occurs. diff --git a/misc/config_tools/xforms/config_common.xsl b/misc/config_tools/xforms/config_common.xsl index 1d8e0a5ced..d486e1dd61 100644 --- a/misc/config_tools/xforms/config_common.xsl +++ b/misc/config_tools/xforms/config_common.xsl @@ -79,6 +79,10 @@ + + + + diff --git a/misc/config_tools/xforms/misc_cfg.h.xsl b/misc/config_tools/xforms/misc_cfg.h.xsl index d4df118ebd..5c35a121b4 100644 --- a/misc/config_tools/xforms/misc_cfg.h.xsl +++ b/misc/config_tools/xforms/misc_cfg.h.xsl @@ -40,6 +40,7 @@ + @@ -172,6 +173,17 @@ + + + + + + + + + + +