* [PATCH kvm-unit-tests] access: use write_cr4_checking to verify support for SMEP or PKE
@ 2021-04-10 14:42 Paolo Bonzini
0 siblings, 0 replies; only message in thread
From: Paolo Bonzini @ 2021-04-10 14:42 UTC (permalink / raw)
To: kvm; +Cc: seanjc
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-10 14:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-10 14:42 [PATCH kvm-unit-tests] access: use write_cr4_checking to verify support for SMEP or PKE Paolo Bonzini
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).