From 4594e94cacad644a4c1d00872fd5e897e8f7de07 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 19 Jul 2017 12:19:36 +0200 Subject: [PATCH] 4.4-stable patches added patches: kvm-x86-disable-mpx-if-host-did-not-enable-mpx-xsave-features.patch --- ...ost-to-access-guest-msr_ia32_bndcfgs.patch | 12 +- ...-check-value-written-to-ia32_bndcfgs.patch | 4 +- ...o-not-disable-intercepts-for-bndcfgs.patch | 2 +- ...st-did-not-enable-mpx-xsave-features.patch | 157 ++++++++++++++++++ ...t-bndcfgs-requires-guest-mpx-support.patch | 14 +- queue-4.4/series | 1 + 6 files changed, 174 insertions(+), 16 deletions(-) create mode 100644 queue-4.4/kvm-x86-disable-mpx-if-host-did-not-enable-mpx-xsave-features.patch diff --git a/queue-4.4/kvm-vmx-allow-host-to-access-guest-msr_ia32_bndcfgs.patch b/queue-4.4/kvm-vmx-allow-host-to-access-guest-msr_ia32_bndcfgs.patch index c040c1ddcf0..d800677b4d9 100644 --- a/queue-4.4/kvm-vmx-allow-host-to-access-guest-msr_ia32_bndcfgs.patch +++ b/queue-4.4/kvm-vmx-allow-host-to-access-guest-msr_ia32_bndcfgs.patch @@ -21,22 +21,22 @@ Signed-off-by: Greg Kroah-Hartman --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c -@@ -2813,7 +2813,8 @@ static int vmx_get_msr(struct kvm_vcpu * +@@ -2812,7 +2812,8 @@ static int vmx_get_msr(struct kvm_vcpu * msr_info->data = vmcs_readl(GUEST_SYSENTER_ESP); break; case MSR_IA32_BNDCFGS: -- if (!vmx_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) -+ if (!vmx_mpx_supported() || +- if (!kvm_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) ++ if (!kvm_mpx_supported() || + (!msr_info->host_initiated && !guest_cpuid_has_mpx(vcpu))) return 1; msr_info->data = vmcs_read64(GUEST_BNDCFGS); break; -@@ -2890,7 +2891,8 @@ static int vmx_set_msr(struct kvm_vcpu * +@@ -2889,7 +2890,8 @@ static int vmx_set_msr(struct kvm_vcpu * vmcs_writel(GUEST_SYSENTER_ESP, data); break; case MSR_IA32_BNDCFGS: -- if (!vmx_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) -+ if (!vmx_mpx_supported() || +- if (!kvm_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) ++ if (!kvm_mpx_supported() || + (!msr_info->host_initiated && !guest_cpuid_has_mpx(vcpu))) return 1; if (is_noncanonical_address(data & PAGE_MASK) || diff --git a/queue-4.4/kvm-vmx-check-value-written-to-ia32_bndcfgs.patch b/queue-4.4/kvm-vmx-check-value-written-to-ia32_bndcfgs.patch index ab0fc394b97..5486c59ab68 100644 --- a/queue-4.4/kvm-vmx-check-value-written-to-ia32_bndcfgs.patch +++ b/queue-4.4/kvm-vmx-check-value-written-to-ia32_bndcfgs.patch @@ -36,9 +36,9 @@ Signed-off-by: Greg Kroah-Hartman #define FEATURE_CONTROL_LOCKED (1<<0) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c -@@ -2892,6 +2892,9 @@ static int vmx_set_msr(struct kvm_vcpu * +@@ -2891,6 +2891,9 @@ static int vmx_set_msr(struct kvm_vcpu * case MSR_IA32_BNDCFGS: - if (!vmx_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) + if (!kvm_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) return 1; + if (is_noncanonical_address(data & PAGE_MASK) || + (data & MSR_IA32_BNDCFGS_RSVD)) diff --git a/queue-4.4/kvm-vmx-do-not-disable-intercepts-for-bndcfgs.patch b/queue-4.4/kvm-vmx-do-not-disable-intercepts-for-bndcfgs.patch index a5c80a5dae4..1d69fe872da 100644 --- a/queue-4.4/kvm-vmx-do-not-disable-intercepts-for-bndcfgs.patch +++ b/queue-4.4/kvm-vmx-do-not-disable-intercepts-for-bndcfgs.patch @@ -30,7 +30,7 @@ Signed-off-by: Greg Kroah-Hartman --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c -@@ -6253,7 +6253,6 @@ static __init int hardware_setup(void) +@@ -6252,7 +6252,6 @@ static __init int hardware_setup(void) vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_CS, false); vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_ESP, false); vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_EIP, false); diff --git a/queue-4.4/kvm-x86-disable-mpx-if-host-did-not-enable-mpx-xsave-features.patch b/queue-4.4/kvm-x86-disable-mpx-if-host-did-not-enable-mpx-xsave-features.patch new file mode 100644 index 00000000000..a5acd75a387 --- /dev/null +++ b/queue-4.4/kvm-x86-disable-mpx-if-host-did-not-enable-mpx-xsave-features.patch @@ -0,0 +1,157 @@ +From a87036add09283e6c4f4103a15c596c67b86ab86 Mon Sep 17 00:00:00 2001 +From: Paolo Bonzini +Date: Tue, 8 Mar 2016 09:52:13 +0100 +Subject: KVM: x86: disable MPX if host did not enable MPX XSAVE features + +From: Paolo Bonzini + +commit a87036add09283e6c4f4103a15c596c67b86ab86 upstream. + +When eager FPU is disabled, KVM will still see the MPX bit in CPUID and +presumably the MPX vmentry and vmexit controls. However, it will not +be able to expose the MPX XSAVE features to the guest, because the guest's +accessible XSAVE features are always a subset of host_xcr0. + +In this case, we should disable the MPX CPUID bit, the BNDCFGS MSR, +and the MPX vmentry and vmexit controls for nested virtualization. +It is then unnecessary to enable guest eager FPU if the guest has the +MPX CPUID bit set. + +Signed-off-by: Paolo Bonzini +Signed-off-by: Greg Kroah-Hartman + +--- + arch/x86/kvm/cpuid.c | 13 ++++++++++--- + arch/x86/kvm/cpuid.h | 9 +-------- + arch/x86/kvm/vmx.c | 13 ++++++------- + 3 files changed, 17 insertions(+), 18 deletions(-) + +--- a/arch/x86/kvm/cpuid.c ++++ b/arch/x86/kvm/cpuid.c +@@ -46,11 +46,18 @@ static u32 xstate_required_size(u64 xsta + return ret; + } + ++bool kvm_mpx_supported(void) ++{ ++ return ((host_xcr0 & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)) ++ && kvm_x86_ops->mpx_supported()); ++} ++EXPORT_SYMBOL_GPL(kvm_mpx_supported); ++ + u64 kvm_supported_xcr0(void) + { + u64 xcr0 = KVM_SUPPORTED_XCR0 & host_xcr0; + +- if (!kvm_x86_ops->mpx_supported()) ++ if (!kvm_mpx_supported()) + xcr0 &= ~(XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR); + + return xcr0; +@@ -97,7 +104,7 @@ int kvm_update_cpuid(struct kvm_vcpu *vc + if (best && (best->eax & (F(XSAVES) | F(XSAVEC)))) + best->ebx = xstate_required_size(vcpu->arch.xcr0, true); + +- vcpu->arch.eager_fpu = use_eager_fpu() || guest_cpuid_has_mpx(vcpu); ++ vcpu->arch.eager_fpu = use_eager_fpu(); + if (vcpu->arch.eager_fpu) + kvm_x86_ops->fpu_activate(vcpu); + +@@ -295,7 +302,7 @@ static inline int __do_cpuid_ent(struct + #endif + unsigned f_rdtscp = kvm_x86_ops->rdtscp_supported() ? F(RDTSCP) : 0; + unsigned f_invpcid = kvm_x86_ops->invpcid_supported() ? F(INVPCID) : 0; +- unsigned f_mpx = kvm_x86_ops->mpx_supported() ? F(MPX) : 0; ++ unsigned f_mpx = kvm_mpx_supported() ? F(MPX) : 0; + unsigned f_xsaves = kvm_x86_ops->xsaves_supported() ? F(XSAVES) : 0; + + /* cpuid 1.edx */ +--- a/arch/x86/kvm/cpuid.h ++++ b/arch/x86/kvm/cpuid.h +@@ -4,6 +4,7 @@ + #include "x86.h" + + int kvm_update_cpuid(struct kvm_vcpu *vcpu); ++bool kvm_mpx_supported(void); + struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, + u32 function, u32 index); + int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, +@@ -134,14 +135,6 @@ static inline bool guest_cpuid_has_rtm(s + return best && (best->ebx & bit(X86_FEATURE_RTM)); + } + +-static inline bool guest_cpuid_has_mpx(struct kvm_vcpu *vcpu) +-{ +- struct kvm_cpuid_entry2 *best; +- +- best = kvm_find_cpuid_entry(vcpu, 7, 0); +- return best && (best->ebx & bit(X86_FEATURE_MPX)); +-} +- + static inline bool guest_cpuid_has_pcommit(struct kvm_vcpu *vcpu) + { + struct kvm_cpuid_entry2 *best; +--- a/arch/x86/kvm/vmx.c ++++ b/arch/x86/kvm/vmx.c +@@ -863,7 +863,6 @@ static unsigned long nested_ept_get_cr3( + static u64 construct_eptp(unsigned long root_hpa); + static void kvm_cpu_vmxon(u64 addr); + static void kvm_cpu_vmxoff(void); +-static bool vmx_mpx_supported(void); + static bool vmx_xsaves_supported(void); + static int vmx_cpu_uses_apicv(struct kvm_vcpu *vcpu); + static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr); +@@ -2541,7 +2540,7 @@ static void nested_vmx_setup_ctls_msrs(s + VM_EXIT_LOAD_IA32_EFER | VM_EXIT_SAVE_IA32_EFER | + VM_EXIT_SAVE_VMX_PREEMPTION_TIMER | VM_EXIT_ACK_INTR_ON_EXIT; + +- if (vmx_mpx_supported()) ++ if (kvm_mpx_supported()) + vmx->nested.nested_vmx_exit_ctls_high |= VM_EXIT_CLEAR_BNDCFGS; + + /* We support free control of debug control saving. */ +@@ -2562,7 +2561,7 @@ static void nested_vmx_setup_ctls_msrs(s + VM_ENTRY_LOAD_IA32_PAT; + vmx->nested.nested_vmx_entry_ctls_high |= + (VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR | VM_ENTRY_LOAD_IA32_EFER); +- if (vmx_mpx_supported()) ++ if (kvm_mpx_supported()) + vmx->nested.nested_vmx_entry_ctls_high |= VM_ENTRY_LOAD_BNDCFGS; + + /* We support free control of debug control loading. */ +@@ -2813,7 +2812,7 @@ static int vmx_get_msr(struct kvm_vcpu * + msr_info->data = vmcs_readl(GUEST_SYSENTER_ESP); + break; + case MSR_IA32_BNDCFGS: +- if (!vmx_mpx_supported()) ++ if (!kvm_mpx_supported()) + return 1; + msr_info->data = vmcs_read64(GUEST_BNDCFGS); + break; +@@ -2890,7 +2889,7 @@ static int vmx_set_msr(struct kvm_vcpu * + vmcs_writel(GUEST_SYSENTER_ESP, data); + break; + case MSR_IA32_BNDCFGS: +- if (!vmx_mpx_supported()) ++ if (!kvm_mpx_supported()) + return 1; + vmcs_write64(GUEST_BNDCFGS, data); + break; +@@ -3363,7 +3362,7 @@ static void init_vmcs_shadow_fields(void + for (i = j = 0; i < max_shadow_read_write_fields; i++) { + switch (shadow_read_write_fields[i]) { + case GUEST_BNDCFGS: +- if (!vmx_mpx_supported()) ++ if (!kvm_mpx_supported()) + continue; + break; + default: +@@ -10265,7 +10264,7 @@ static void prepare_vmcs12(struct kvm_vc + vmcs12->guest_sysenter_cs = vmcs_read32(GUEST_SYSENTER_CS); + vmcs12->guest_sysenter_esp = vmcs_readl(GUEST_SYSENTER_ESP); + vmcs12->guest_sysenter_eip = vmcs_readl(GUEST_SYSENTER_EIP); +- if (vmx_mpx_supported()) ++ if (kvm_mpx_supported()) + vmcs12->guest_bndcfgs = vmcs_read64(GUEST_BNDCFGS); + if (nested_cpu_has_xsaves(vmcs12)) + vmcs12->xss_exit_bitmap = vmcs_read64(XSS_EXIT_BITMAP); diff --git a/queue-4.4/kvm-x86-guest-bndcfgs-requires-guest-mpx-support.patch b/queue-4.4/kvm-x86-guest-bndcfgs-requires-guest-mpx-support.patch index 872bbd13121..2dc7123f488 100644 --- a/queue-4.4/kvm-x86-guest-bndcfgs-requires-guest-mpx-support.patch +++ b/queue-4.4/kvm-x86-guest-bndcfgs-requires-guest-mpx-support.patch @@ -26,7 +26,7 @@ Signed-off-by: Greg Kroah-Hartman --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h -@@ -150,6 +150,14 @@ static inline bool guest_cpuid_has_pcomm +@@ -143,6 +143,14 @@ static inline bool guest_cpuid_has_pcomm return best && (best->ebx & bit(X86_FEATURE_PCOMMIT)); } @@ -43,21 +43,21 @@ Signed-off-by: Greg Kroah-Hartman struct kvm_cpuid_entry2 *best; --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c -@@ -2813,7 +2813,7 @@ static int vmx_get_msr(struct kvm_vcpu * +@@ -2812,7 +2812,7 @@ static int vmx_get_msr(struct kvm_vcpu * msr_info->data = vmcs_readl(GUEST_SYSENTER_ESP); break; case MSR_IA32_BNDCFGS: -- if (!vmx_mpx_supported()) -+ if (!vmx_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) +- if (!kvm_mpx_supported()) ++ if (!kvm_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) return 1; msr_info->data = vmcs_read64(GUEST_BNDCFGS); break; -@@ -2890,7 +2890,7 @@ static int vmx_set_msr(struct kvm_vcpu * +@@ -2889,7 +2889,7 @@ static int vmx_set_msr(struct kvm_vcpu * vmcs_writel(GUEST_SYSENTER_ESP, data); break; case MSR_IA32_BNDCFGS: -- if (!vmx_mpx_supported()) -+ if (!vmx_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) +- if (!kvm_mpx_supported()) ++ if (!kvm_mpx_supported() || !guest_cpuid_has_mpx(vcpu)) return 1; vmcs_write64(GUEST_BNDCFGS, data); break; diff --git a/queue-4.4/series b/queue-4.4/series index 412487ed1d9..b89009415ac 100644 --- a/queue-4.4/series +++ b/queue-4.4/series @@ -50,6 +50,7 @@ sched-topology-optimize-build_group_mask.patch pm-wakeirq-convert-to-srcu.patch pm-qos-return-einval-for-bogus-strings.patch tracing-use-softirq_offset-for-softirq-dectection-for-more-accurate-results.patch +kvm-x86-disable-mpx-if-host-did-not-enable-mpx-xsave-features.patch kvm-vmx-do-not-disable-intercepts-for-bndcfgs.patch kvm-x86-guest-bndcfgs-requires-guest-mpx-support.patch kvm-vmx-check-value-written-to-ia32_bndcfgs.patch -- 2.47.3