access: use write_cr4_checking to verify support for SMEP or PKE
Paolo Bonzini
maintainerPATCH 1/1 access: use write_cr4_checking to verify support for SMEP or PKE
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 <[email protected]>
--- x86/access.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
x86/access.c +8 -11
@@ -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); } }
Signature · 1 line
2.30.1