From: Jim Mattson Subject: [PATCH v2 2/3] kvm: nVMX: Fix nested_vmx_check_msr_bitmap_controls Date: Mon, 10 Jul 2017 12:29:03 -0700 Message-ID: <20170710192904.102893-2-jmattson@google.com> References: <201707081510.ZhaGqybS%fengguang.wu@intel.com> <20170710192904.102893-1-jmattson@google.com> Cc: Jim Mattson To: kvm@vger.kernel.org Return-path: Received: from mail-pf0-f170.google.com ([209.85.192.170]:34975 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754265AbdGJT3z (ORCPT ); Mon, 10 Jul 2017 15:29:55 -0400 Received: by mail-pf0-f170.google.com with SMTP id c73so54727072pfk.2 for ; Mon, 10 Jul 2017 12:29:55 -0700 (PDT) In-Reply-To: <20170710192904.102893-1-jmattson@google.com> Sender: kvm-owner@vger.kernel.org List-ID: Allow the L1 guest to specify the last page of addressable guest physical memory for an L2 MSR permission bitmap. Also remove the vmcs12_read_any() check that should never fail. Fixes: 3af18d9c5fe95 ("KVM: nVMX: Prepare for using hardware MSR bitmap") Change-Id: I37f0482f32c4e77e403f6726e63bbe99880a185b --- arch/x86/kvm/vmx.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 7ffe1c8438c2..eec9e0191311 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -4634,6 +4634,11 @@ static bool guest_state_valid(struct kvm_vcpu *vcpu) return true; } +static bool page_address_valid(struct kvm_vcpu *vcpu, gpa_t gpa) +{ + return PAGE_ALIGNED(gpa) && !(gpa >> cpuid_maxphyaddr(vcpu)); +} + static int init_rmode_tss(struct kvm *kvm) { gfn_t fn; @@ -9592,20 +9597,10 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu) static int nested_vmx_check_msr_bitmap_controls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { - int maxphyaddr; - u64 addr; - if (!nested_cpu_has(vmcs12, CPU_BASED_USE_MSR_BITMAPS)) return 0; - if (vmcs12_read_any(vcpu, MSR_BITMAP, &addr)) { - WARN_ON(1); - return -EINVAL; - } - maxphyaddr = cpuid_maxphyaddr(vcpu); - - if (!PAGE_ALIGNED(vmcs12->msr_bitmap) || - ((addr + PAGE_SIZE) >> maxphyaddr)) + if (!page_address_valid(vcpu, vmcs12->msr_bitmap)) return -EINVAL; return 0; -- 2.13.2.725.g09c95d1e9-goog