From 9beb1b92b5a35d880b017225eb21745a93beda84 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Tue, 26 Jun 2018 16:37:46 +0800 Subject: [PATCH] HV: add MTRR capability check when CPU boot - to avoid reading operations on MTRR registers if no MTRR feature support on current platform in "init_mtrr()". Signed-off-by: Yonghua Huang --- hypervisor/arch/x86/cpu.c | 5 +++++ hypervisor/arch/x86/mtrr.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 31ab5d1ef..8cb8c1312 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -219,6 +219,11 @@ static int hardware_detect_support(void) return -ENODEV; } + if (!cpu_has_cap(X86_FEATURE_MTRR)) { + pr_fatal("%s, MTRR not supported\n", __func__); + return -ENODEV; + } + if (!cpu_has_cap(X86_FEATURE_VMX)) { pr_fatal("%s, vmx not supported\n", __func__); return -ENODEV; diff --git a/hypervisor/arch/x86/mtrr.c b/hypervisor/arch/x86/mtrr.c index 1981a4488..5fbd32031 100755 --- a/hypervisor/arch/x86/mtrr.c +++ b/hypervisor/arch/x86/mtrr.c @@ -103,9 +103,8 @@ void init_mtrr(struct vcpu *vcpu) vcpu->mtrr.def_type.bits.fixed_enable = 1; vcpu->mtrr.def_type.bits.type = MTRR_MEM_TYPE_UC; - if (is_vm0(vcpu->vm) && cpu_has_cap(X86_FEATURE_MTRR)) { + if (is_vm0(vcpu->vm)) cap.value = msr_read(MSR_IA32_MTRR_CAP); - } for (i = 0; i < FIXED_RANGE_MTRR_NUM; i++) { if (cap.bits.fix) {