All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: kvm@vger.kernel.org
Cc: seanjc@google.com
Subject: [PATCH kvm-unit-tests] access: use write_cr4_checking to verify support for SMEP or PKE
Date: Sat, 10 Apr 2021 16:42:33 +0200	[thread overview]
Message-ID: <20210410144234.32124-1-pbonzini@redhat.com> (raw)

Free set_cr4_smep from having to report failure to set CR4.SMEP,
so that it can report instead whether CR4 was changed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/access.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/x86/access.c b/x86/access.c
index 7dc9eb6..66bd466 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -192,26 +192,23 @@ static void set_cr0_wp(int wp)
     }
 }
 
-static unsigned set_cr4_smep(int smep)
+static void set_cr4_smep(int smep)
 {
     unsigned long cr4 = shadow_cr4;
     extern u64 ptl2[];
-    unsigned r;
 
     cr4 &= ~CR4_SMEP_MASK;
     if (smep)
 	cr4 |= CR4_SMEP_MASK;
     if (cr4 == shadow_cr4)
-        return 0;
+        return;
 
     if (smep)
         ptl2[2] &= ~PT_USER_MASK;
-    r = write_cr4_checking(cr4);
-    if (r || !smep)
+    write_cr4(cr4);
+    if (!smep)
         ptl2[2] |= PT_USER_MASK;
-    if (!r)
-        shadow_cr4 = cr4;
-    return r;
+    shadow_cr4 = cr4;
 }
 
 static void set_cr4_pke(int pke)
@@ -988,19 +985,19 @@ static int ac_test_run(void)
             printf("CR4.PKE not available, disabling PKE tests\n");
 	} else {
             printf("Set PKE in CR4 - expect #GP: FAIL!\n");
-            set_cr4_pke(0);
+            write_cr4_checking(shadow_cr4);
 	}
     }
 
     if (!this_cpu_has(X86_FEATURE_SMEP)) {
 	tests++;
-	if (set_cr4_smep(1) == GP_VECTOR) {
+	if (write_cr4_checking(shadow_cr4 | X86_CR4_SMEP) == GP_VECTOR) {
             successes++;
             invalid_mask |= AC_CPU_CR4_SMEP_MASK;
             printf("CR4.SMEP not available, disabling SMEP tests\n");
 	} else {
             printf("Set SMEP in CR4 - expect #GP: FAIL!\n");
-            set_cr4_smep(0);
+            write_cr4_checking(shadow_cr4);
 	}
     }
 
-- 
2.30.1



                 reply	other threads:[~2021-04-10 14:42 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=20210410144234.32124-1-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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 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.