All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>,
	"Wincy Van" <fanwenyi0529@gmail.com>,
	kvm@vger.kernel.org
Cc: Jim Mattson <jmattson@google.com>
Subject: [PATCH v2] KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls
Date: Mon, 19 Jun 2017 15:23:42 -0700	[thread overview]
Message-ID: <20170619222342.123646-1-jmattson@google.com> (raw)
In-Reply-To: <20170607142154.GA28750@potion>

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")
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 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 60fa010d3fa1..8b403682dcdf 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -4624,6 +4624,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;
@@ -9559,20 +9564,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.1.518.g3df882009-goog

  reply	other threads:[~2017-06-19 22:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-25 18:01 [PATCH 1/2] KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls Jim Mattson
2017-05-25 18:01 ` [PATCH 2/2] KVM: nVMX: Check host support for MSR bitmaps Jim Mattson
2017-05-26  0:04   ` [PATCH v2 " Jim Mattson
2017-06-07 14:21     ` Radim Krčmář
2017-06-19 22:23       ` Jim Mattson [this message]
2017-05-25 20:41 ` [PATCH 1/2] KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls kbuild test robot
2017-05-26  0:02 ` [PATCH v2 " Jim Mattson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170619222342.123646-1-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=fanwenyi0529@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.