All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	David Matlack <dmatlack@google.com>,
	Peter Feiner <pfeiner@google.com>
Subject: [kvm-unit-tests PATCH 3/3] x86/vmx: get EPT at the last level
Date: Thu, 29 Jun 2017 19:26:47 +0200	[thread overview]
Message-ID: <20170629172647.22188-4-rkrcmar@redhat.com> (raw)
In-Reply-To: <20170629172647.22188-1-rkrcmar@redhat.com>

vmx_EPT_AD_* tests mark the last level as non-present, but that doesn't
mean we cannot look at A/D bits of that last level.
This fixes "EPT - guest physical address is not mapped" in case 3.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 x86/vmx.c       | 4 ++--
 x86/vmx_tests.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/x86/vmx.c b/x86/vmx.c
index 5e3832727f05..56c2c079ebc5 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -821,12 +821,12 @@ bool get_ept_pte(unsigned long *pml4, unsigned long guest_addr, int level,
 	for (l = EPT_PAGE_LEVEL; ; --l) {
 		offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK;
 		iter_pte = pt[offset];
-		if (!(iter_pte & (EPT_PRESENT)))
-			return false;
 		if (l == level)
 			break;
 		if (l < 4 && (iter_pte & EPT_LARGE_PAGE))
 			return false;
+		if (!(iter_pte & (EPT_PRESENT)))
+			return false;
 		pt = (unsigned long *)(iter_pte & EPT_ADDR_MASK);
 	}
 	offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK;
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 181c3c73cb60..567f7143b427 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -2582,6 +2582,7 @@ static void ept_access_test_setup(void)
 	unsigned long npages = 1ul << PAGE_1G_ORDER;
 	unsigned long size = npages * PAGE_SIZE;
 	unsigned long *page_table = current_page_table();
+	unsigned long pte;
 
 	if (setup_ept(false))
 		test_skip("EPT not supported");
@@ -2603,8 +2604,8 @@ static void ept_access_test_setup(void)
 	 * Make sure nothing's mapped here so the tests that screw with the
 	 * pml4 entry don't inadvertently break something.
 	 */
-	TEST_ASSERT(!get_ept_pte(pml4, data->gpa, 4, NULL));
-	TEST_ASSERT(!get_ept_pte(pml4, data->gpa + size - 1, 4, NULL));
+	TEST_ASSERT(get_ept_pte(pml4, data->gpa, 4, &pte) && pte == 0);
+	TEST_ASSERT(get_ept_pte(pml4, data->gpa + size - 1, 4, &pte) && pte == 0);
 	install_ept(pml4, data->hpa, data->gpa, EPT_PRESENT);
 
 	data->hva[0] = MAGIC_VAL_1;
-- 
2.13.2

  parent reply	other threads:[~2017-06-29 17:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 17:26 [kvm-unit-tests PATCH 0/3] x86/vmx: fix vmx_EPT_AD_* tests Radim Krčmář
2017-06-29 17:26 ` [kvm-unit-tests PATCH 1/3] x86/vmx: fix EPT - MMIO access Radim Krčmář
2017-06-29 17:34   ` Peter Feiner
2017-06-30 10:22     ` Paolo Bonzini
2017-07-03 17:13       ` Radim Krčmář
2017-07-03 17:28         ` Paolo Bonzini
2017-06-29 17:26 ` [kvm-unit-tests PATCH 2/3] x86/vmx: fix detection of unmapped PTE Radim Krčmář
2017-06-29 17:38   ` Peter Feiner
2017-06-30 10:33   ` Paolo Bonzini
2017-07-03 10:34     ` Paolo Bonzini
2017-07-03 16:42       ` Radim Krčmář
2017-06-29 17:26 ` Radim Krčmář [this message]
2017-06-29 17:51   ` [kvm-unit-tests PATCH 3/3] x86/vmx: get EPT at the last level Peter Feiner
2017-06-29 18:08     ` Radim Krčmář
2017-06-29 18:17       ` Peter Feiner

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=20170629172647.22188-4-rkrcmar@redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pfeiner@google.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.