kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org,
	Sean Christopherson <sean.j.christopherson@intel.com>
Subject: [kvm-unit-tests PATCH] x86: access: Add test for illegal toggling of CR4.LA57 in 64-bit mode
Date: Thu,  2 Jul 2020 19:19:03 -0700	[thread overview]
Message-ID: <20200703021903.5683-1-sean.j.christopherson@intel.com> (raw)

Add a test to verify that KVM correctly injects a #GP if the guest
attempts to toggle CR4.LA57 while 64-bit mode is active.  Use two
versions of the toggling, one to toggle only LA57 and a second to toggle
PSE in addition to LA57.  KVM doesn't intercept LA57, i.e. toggling only
LA57 effectively tests the CPU, not KVM.  Use PSE as the whipping boy as
it will not trigger a #GP on its own, is universally available, is
ignored in 64-bit mode, and most importantly is trapped by KVM.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 lib/x86/processor.h |  1 +
 x86/access.c        | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index 6e0811e..74a2498 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -44,6 +44,7 @@
 #define X86_CR4_PGE    0x00000080
 #define X86_CR4_PCE    0x00000100
 #define X86_CR4_UMIP   0x00000800
+#define X86_CR4_LA57   0x00001000
 #define X86_CR4_VMXE   0x00002000
 #define X86_CR4_PCIDE  0x00020000
 #define X86_CR4_SMEP   0x00100000
diff --git a/x86/access.c b/x86/access.c
index ac879c3..7dc9eb6 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -1004,6 +1004,18 @@ static int ac_test_run(void)
 	}
     }
 
+    /* Toggling LA57 in 64-bit mode (guaranteed for this test) is illegal. */
+    if (this_cpu_has(X86_FEATURE_LA57)) {
+        tests++;
+        if (write_cr4_checking(shadow_cr4 ^ X86_CR4_LA57) == GP_VECTOR)
+            successes++;
+
+        /* Force a VM-Exit on KVM, which doesn't intercept LA57 itself. */
+        tests++;
+        if (write_cr4_checking(shadow_cr4 ^ (X86_CR4_LA57 | X86_CR4_PSE)) == GP_VECTOR)
+            successes++;
+    }
+
     ac_env_int(&pool);
     ac_test_init(&at, (void *)(0x123400000000 + 16 * smp_id()));
     do {
-- 
2.26.0


                 reply	other threads:[~2020-07-03  2:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200703021903.5683-1-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@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 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).