kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86: Add one-off test to verify setting LA57 fails when it's unsupported
@ 2020-09-30  4:34 Sean Christopherson
  2020-10-01 17:12 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2020-09-30  4:34 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Sean Christopherson

Add an i386-only test to check that setting CR4.LA57 fails when 5-level
paging is not exposed to the guest.  Old versions of KVM don't intercept
LA57 by default on VMX, which means a clever guest could set LA57
without it being detected by KVM.

This test is i386-only because toggling CR4.LA57 in long mode is
illegal, i.e. won't verify the desired KVM behavior.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 x86/Makefile.i386 |  2 +-
 x86/la57.c        | 13 +++++++++++++
 x86/unittests.cfg |  4 ++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 x86/la57.c

diff --git a/x86/Makefile.i386 b/x86/Makefile.i386
index be9d6bc..c04e5aa 100644
--- a/x86/Makefile.i386
+++ b/x86/Makefile.i386
@@ -6,6 +6,6 @@ COMMON_CFLAGS += -mno-sse -mno-sse2
 cflatobjs += lib/x86/setjmp32.o
 
 tests = $(TEST_DIR)/taskswitch.flat $(TEST_DIR)/taskswitch2.flat \
-	$(TEST_DIR)/cmpxchg8b.flat
+	$(TEST_DIR)/cmpxchg8b.flat $(TEST_DIR)/la57.flat
 
 include $(SRCDIR)/$(TEST_DIR)/Makefile.common
diff --git a/x86/la57.c b/x86/la57.c
new file mode 100644
index 0000000..b537bb2
--- /dev/null
+++ b/x86/la57.c
@@ -0,0 +1,13 @@
+#include "libcflat.h"
+#include "processor.h"
+#include "desc.h"
+
+int main(int ac, char **av)
+{
+	int vector = write_cr4_checking(read_cr4() | X86_CR4_LA57);
+	int expected = this_cpu_has(X86_FEATURE_LA57) ? 0 : 13;
+
+	report(vector == expected, "%s when CR4.LA57 %ssupported",
+	       expected ? "#GP" : "No fault", expected ? "un" : "");
+	return report_summary();
+}
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 3a79151..6eb8e19 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -245,6 +245,10 @@ arch = x86_64
 file = umip.flat
 extra_params = -cpu qemu64,+umip
 
+[la57]
+file = la57.flat
+arch = i386
+
 [vmx]
 file = vmx.flat
 extra_params = -cpu host,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test"
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [kvm-unit-tests PATCH] x86: Add one-off test to verify setting LA57 fails when it's unsupported
  2020-09-30  4:34 [kvm-unit-tests PATCH] x86: Add one-off test to verify setting LA57 fails when it's unsupported Sean Christopherson
@ 2020-10-01 17:12 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-10-01 17:12 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm

On 30/09/20 06:34, Sean Christopherson wrote:
> Add an i386-only test to check that setting CR4.LA57 fails when 5-level
> paging is not exposed to the guest.  Old versions of KVM don't intercept
> LA57 by default on VMX, which means a clever guest could set LA57
> without it being detected by KVM.
> 
> This test is i386-only because toggling CR4.LA57 in long mode is
> illegal, i.e. won't verify the desired KVM behavior.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  x86/Makefile.i386 |  2 +-
>  x86/la57.c        | 13 +++++++++++++
>  x86/unittests.cfg |  4 ++++
>  3 files changed, 18 insertions(+), 1 deletion(-)
>  create mode 100644 x86/la57.c
> 
> diff --git a/x86/Makefile.i386 b/x86/Makefile.i386
> index be9d6bc..c04e5aa 100644
> --- a/x86/Makefile.i386
> +++ b/x86/Makefile.i386
> @@ -6,6 +6,6 @@ COMMON_CFLAGS += -mno-sse -mno-sse2
>  cflatobjs += lib/x86/setjmp32.o
>  
>  tests = $(TEST_DIR)/taskswitch.flat $(TEST_DIR)/taskswitch2.flat \
> -	$(TEST_DIR)/cmpxchg8b.flat
> +	$(TEST_DIR)/cmpxchg8b.flat $(TEST_DIR)/la57.flat
>  
>  include $(SRCDIR)/$(TEST_DIR)/Makefile.common
> diff --git a/x86/la57.c b/x86/la57.c
> new file mode 100644
> index 0000000..b537bb2
> --- /dev/null
> +++ b/x86/la57.c
> @@ -0,0 +1,13 @@
> +#include "libcflat.h"
> +#include "processor.h"
> +#include "desc.h"
> +
> +int main(int ac, char **av)
> +{
> +	int vector = write_cr4_checking(read_cr4() | X86_CR4_LA57);
> +	int expected = this_cpu_has(X86_FEATURE_LA57) ? 0 : 13;
> +
> +	report(vector == expected, "%s when CR4.LA57 %ssupported",
> +	       expected ? "#GP" : "No fault", expected ? "un" : "");
> +	return report_summary();
> +}
> diff --git a/x86/unittests.cfg b/x86/unittests.cfg
> index 3a79151..6eb8e19 100644
> --- a/x86/unittests.cfg
> +++ b/x86/unittests.cfg
> @@ -245,6 +245,10 @@ arch = x86_64
>  file = umip.flat
>  extra_params = -cpu qemu64,+umip
>  
> +[la57]
> +file = la57.flat
> +arch = i386
> +
>  [vmx]
>  file = vmx.flat
>  extra_params = -cpu host,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test"
> 

Applied, thanks.

Paolo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-01 17:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30  4:34 [kvm-unit-tests PATCH] x86: Add one-off test to verify setting LA57 fails when it's unsupported Sean Christopherson
2020-10-01 17:12 ` 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).