kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aaron Lewis <aaronlewis@google.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
	Aaron Lewis <aaronlewis@google.com>
Subject: [kvm-unit-tests PATCH] x86: Look up the PTE rather than assuming it
Date: Fri, 29 Oct 2021 21:48:00 +0000	[thread overview]
Message-ID: <20211029214759.1541992-1-aaronlewis@google.com> (raw)

Rather than assuming which PTE the SMEP test is running on, look it up
to ensure we have the correct entry.  If this test were to run on a
different page table (ie: run in an L2 test) the wrong PTE would be set.
Switch to looking up the PTE to avoid this from happening.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
---
 x86/access.c   | 9 ++++++---
 x86/cstart64.S | 1 -
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/x86/access.c b/x86/access.c
index 4725bbd..a4d72d9 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -204,7 +204,7 @@ static void set_cr0_wp(int wp)
 static unsigned set_cr4_smep(int smep)
 {
     unsigned long cr4 = shadow_cr4;
-    extern u64 ptl2[];
+    pteval_t *pte;
     unsigned r;
 
     cr4 &= ~CR4_SMEP_MASK;
@@ -213,11 +213,14 @@ static unsigned set_cr4_smep(int smep)
     if (cr4 == shadow_cr4)
         return 0;
 
+    pte = get_pte(phys_to_virt(read_cr3()), set_cr4_smep);
+    assert(pte);
+
     if (smep)
-        ptl2[2] &= ~PT_USER_MASK;
+        *pte &= ~PT_USER_MASK;
     r = write_cr4_checking(cr4);
     if (r || !smep) {
-        ptl2[2] |= PT_USER_MASK;
+        *pte |= PT_USER_MASK;
 
 	/* Flush to avoid spurious #PF */
 	invlpg((void *)(2 << 21));
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 5c6ad38..4ba9943 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -26,7 +26,6 @@ ring0stacktop:
 .data
 
 .align 4096
-.globl ptl2
 ptl2:
 i = 0
 	.rept 512 * 4
-- 
2.33.1.1089.g2158813163f-goog


             reply	other threads:[~2021-10-29 21:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 21:48 Aaron Lewis [this message]
2021-10-29 22:48 ` [kvm-unit-tests PATCH] x86: Look up the PTE rather than assuming it Sean Christopherson
2021-10-29 22:59   ` Jim Mattson
2021-11-01 15:00     ` Aaron Lewis
2021-11-01 17:10       ` 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=20211029214759.1541992-1-aaronlewis@google.com \
    --to=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).