diff --git a/hypervisor/arch/x86/Kconfig b/hypervisor/arch/x86/Kconfig index f2742a51f..8a04ea1c2 100644 --- a/hypervisor/arch/x86/Kconfig +++ b/hypervisor/arch/x86/Kconfig @@ -274,10 +274,6 @@ config GPU_SBDF 00:02.0 in DRHD segment 0, this SBDF would be (0 << 16) | (0 << 8) | (2 << 3) | (0 << 0), i.e. 0x00000010. -config MTRR_ENABLED - bool "Memory Type Range Registers (MTRR) enabled" - default y - config RELOC bool "Enable hypervisor relocation" default y diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 580d1dec7..53fcdb1ee 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -391,9 +391,9 @@ int32_t create_vcpu(uint16_t pcpu_id, struct acrn_vm *vm, struct acrn_vcpu **rtn /* Create per vcpu vlapic */ vlapic_create(vcpu); -#ifdef CONFIG_MTRR_ENABLED - init_vmtrr(vcpu); -#endif + if (!vm_hide_mtrr(vm)) { + init_vmtrr(vcpu); + } spinlock_init(&(vcpu->arch.lock)); diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index 03488fe36..5a68f35fb 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -322,10 +322,10 @@ void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ebx &= ~APIC_ID_MASK; *ebx |= (apicid << APIC_ID_SHIFT); -#ifndef CONFIG_MTRR_ENABLED - /* mask mtrr */ - *edx &= ~CPUID_EDX_MTRR; -#endif + if (vm_hide_mtrr(vcpu->vm)) { + /* mask mtrr */ + *edx &= ~CPUID_EDX_MTRR; + } /* mask Debug Store feature */ *ecx &= ~(CPUID_ECX_DTES64 | CPUID_ECX_DS_CPL); diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 9d30dceb6..d0a5ee28b 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -71,6 +71,16 @@ bool is_lapic_pt(const struct acrn_vm *vm) return ((vm_config->guest_flags & LAPIC_PASSTHROUGH) != 0U); } +/** + * @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM + */ +bool vm_hide_mtrr(const struct acrn_vm *vm) +{ + struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); + + return ((vm_config->guest_flags & HIDE_MTRR) != 0U); +} + /** * @brief Initialize the I/O bitmap for \p vm * diff --git a/hypervisor/arch/x86/guest/vmsr.c b/hypervisor/arch/x86/guest/vmsr.c index 3b97bf3ca..7cc6861bf 100644 --- a/hypervisor/arch/x86/guest/vmsr.c +++ b/hypervisor/arch/x86/guest/vmsr.c @@ -407,11 +407,11 @@ int32_t rdmsr_vmexit_handler(struct acrn_vcpu *vcpu) case MSR_IA32_MTRR_FIX4K_F0000: case MSR_IA32_MTRR_FIX4K_F8000: { -#ifdef CONFIG_MTRR_ENABLED - v = read_vmtrr(vcpu, msr); -#else - err = -EACCES; -#endif + if (!vm_hide_mtrr(vcpu->vm)) { + v = read_vmtrr(vcpu, msr); + } else { + err = -EACCES; + } break; } case MSR_IA32_BIOS_SIGN_ID: @@ -549,11 +549,11 @@ int32_t wrmsr_vmexit_handler(struct acrn_vcpu *vcpu) case MSR_IA32_MTRR_FIX4K_F0000: case MSR_IA32_MTRR_FIX4K_F8000: { -#ifdef CONFIG_MTRR_ENABLED - write_vmtrr(vcpu, msr, v); -#else - err = -EACCES; -#endif + if (!vm_hide_mtrr(vcpu->vm)) { + write_vmtrr(vcpu, msr, v); + } else { + err = -EACCES; + } break; } case MSR_IA32_BIOS_SIGN_ID: diff --git a/hypervisor/arch/x86/guest/vmtrr.c b/hypervisor/arch/x86/guest/vmtrr.c index f879d0df1..21764a77d 100644 --- a/hypervisor/arch/x86/guest/vmtrr.c +++ b/hypervisor/arch/x86/guest/vmtrr.c @@ -12,8 +12,6 @@ #include #include -#ifdef CONFIG_MTRR_ENABLED - #define MTRR_FIXED_RANGE_ALL_WB (MTRR_MEM_TYPE_WB \ | (MTRR_MEM_TYPE_WB << 8U) \ | (MTRR_MEM_TYPE_WB << 16U) \ @@ -266,5 +264,3 @@ uint64_t read_vmtrr(const struct acrn_vcpu *vcpu, uint32_t msr) return ret; } - -#endif /* CONFIG_MTRR_ENABLED */ diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index 2a44c74c9..0abec4766 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -256,9 +256,7 @@ struct acrn_vcpu_arch { /* per vcpu lapic */ struct acrn_vlapic vlapic; -#ifdef CONFIG_MTRR_ENABLED struct acrn_vmtrr vmtrr; -#endif int32_t cur_context; struct cpu_context contexts[NR_WORLD]; diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index bddc2a48a..55f662b7f 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -221,6 +221,7 @@ void vrtc_init(struct acrn_vm *vm); #endif bool is_lapic_pt(const struct acrn_vm *vm); +bool vm_hide_mtrr(const struct acrn_vm *vm); #endif /* !ASSEMBLER */ diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index 89d2bbb03..d88a8a03f 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -50,7 +50,8 @@ #define SECURE_WORLD_ENABLED (1UL << 0U) /* Whether secure world is enabled */ #define LAPIC_PASSTHROUGH (1UL << 1U) /* Whether LAPIC is passed through */ #define IO_COMPLETION_POLLING (1UL << 2U) /* Whether need hypervisor poll IO completion */ -#define CLOS_REQUIRED (1UL << 3U) /* Whether CLOS is required */ +#define CLOS_REQUIRED (1UL << 3U) /* Whether CLOS is required */ +#define HIDE_MTRR (1UL << 4U) /* Whether hide MTRR from VM */ /** * @brief Hypercall