* [kvm-unit-tests PATCH v2] kvm-unit-test: x86: Add RDPRU test
@ 2019-09-20 23:08 Jim Mattson
2019-09-24 5:55 ` Krish Sadhukhan
0 siblings, 1 reply; 2+ messages in thread
From: Jim Mattson @ 2019-09-20 23:08 UTC (permalink / raw)
To: kvm, Krish Sadhukhan; +Cc: Jim Mattson, Peter Shier
When running in a VM, ensure that support for RDPRU is not enumerated
in the guest's CPUID and that the RDPRU instruction raises #UD.
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
---
lib/x86/processor.h | 2 ++
x86/Makefile.x86_64 | 1 +
x86/rdpru.c | 27 +++++++++++++++++++++++++++
x86/unittests.cfg | 5 +++++
4 files changed, 35 insertions(+)
create mode 100644 x86/rdpru.c
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index b1c579b..fe72c13 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -131,6 +131,7 @@ static inline u8 cpuid_maxphyaddr(void)
#define X86_FEATURE_XSAVE (CPUID(0x1, 0, ECX, 26))
#define X86_FEATURE_OSXSAVE (CPUID(0x1, 0, ECX, 27))
#define X86_FEATURE_RDRAND (CPUID(0x1, 0, ECX, 30))
+#define X86_FEATURE_HYPERVISOR (CPUID(0x1, 0, ECX, 31))
#define X86_FEATURE_MCE (CPUID(0x1, 0, EDX, 7))
#define X86_FEATURE_APIC (CPUID(0x1, 0, EDX, 9))
#define X86_FEATURE_CLFLUSH (CPUID(0x1, 0, EDX, 19))
@@ -150,6 +151,7 @@ static inline u8 cpuid_maxphyaddr(void)
#define X86_FEATURE_RDPID (CPUID(0x7, 0, ECX, 22))
#define X86_FEATURE_SPEC_CTRL (CPUID(0x7, 0, EDX, 26))
#define X86_FEATURE_NX (CPUID(0x80000001, 0, EDX, 20))
+#define X86_FEATURE_RDPRU (CPUID(0x80000008, 0, EBX, 4))
/*
* AMD CPUID features
diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64
index 51f9b80..010102b 100644
--- a/x86/Makefile.x86_64
+++ b/x86/Makefile.x86_64
@@ -19,6 +19,7 @@ tests += $(TEST_DIR)/vmx.flat
tests += $(TEST_DIR)/tscdeadline_latency.flat
tests += $(TEST_DIR)/intel-iommu.flat
tests += $(TEST_DIR)/vmware_backdoors.flat
+tests += $(TEST_DIR)/rdpru.flat
include $(SRCDIR)/$(TEST_DIR)/Makefile.common
diff --git a/x86/rdpru.c b/x86/rdpru.c
new file mode 100644
index 0000000..87a517e
--- /dev/null
+++ b/x86/rdpru.c
@@ -0,0 +1,27 @@
+/* RDPRU test */
+
+#include "libcflat.h"
+#include "processor.h"
+#include "desc.h"
+
+static int rdpru_checking(void)
+{
+ asm volatile (ASM_TRY("1f")
+ ".byte 0x0f,0x01,0xfd \n\t" /* rdpru */
+ "1:" : : "c" (0) : "eax", "edx");
+ return exception_vector();
+}
+
+int main(int ac, char **av)
+{
+ setup_idt();
+
+ if (this_cpu_has(X86_FEATURE_HYPERVISOR)) {
+ report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
+ report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
+ } else {
+ report_skip("Not in a VM");
+ }
+
+ return report_summary();
+}
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 694ee3d..9764e18 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -221,6 +221,11 @@ file = pcid.flat
extra_params = -cpu qemu64,+pcid
arch = x86_64
+[rdpru]
+file = rdpru.flat
+extra_params = -cpu host
+arch = x86_64
+
[umip]
file = umip.flat
extra_params = -cpu qemu64,+umip
--
2.23.0.351.gc4317032e6-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [kvm-unit-tests PATCH v2] kvm-unit-test: x86: Add RDPRU test
2019-09-20 23:08 [kvm-unit-tests PATCH v2] kvm-unit-test: x86: Add RDPRU test Jim Mattson
@ 2019-09-24 5:55 ` Krish Sadhukhan
0 siblings, 0 replies; 2+ messages in thread
From: Krish Sadhukhan @ 2019-09-24 5:55 UTC (permalink / raw)
To: Jim Mattson, kvm; +Cc: Peter Shier
On 9/20/19 4:08 PM, Jim Mattson wrote:
> When running in a VM, ensure that support for RDPRU is not enumerated
> in the guest's CPUID and that the RDPRU instruction raises #UD.
>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> ---
> lib/x86/processor.h | 2 ++
> x86/Makefile.x86_64 | 1 +
> x86/rdpru.c | 27 +++++++++++++++++++++++++++
> x86/unittests.cfg | 5 +++++
> 4 files changed, 35 insertions(+)
> create mode 100644 x86/rdpru.c
>
> diff --git a/lib/x86/processor.h b/lib/x86/processor.h
> index b1c579b..fe72c13 100644
> --- a/lib/x86/processor.h
> +++ b/lib/x86/processor.h
> @@ -131,6 +131,7 @@ static inline u8 cpuid_maxphyaddr(void)
> #define X86_FEATURE_XSAVE (CPUID(0x1, 0, ECX, 26))
> #define X86_FEATURE_OSXSAVE (CPUID(0x1, 0, ECX, 27))
> #define X86_FEATURE_RDRAND (CPUID(0x1, 0, ECX, 30))
> +#define X86_FEATURE_HYPERVISOR (CPUID(0x1, 0, ECX, 31))
> #define X86_FEATURE_MCE (CPUID(0x1, 0, EDX, 7))
> #define X86_FEATURE_APIC (CPUID(0x1, 0, EDX, 9))
> #define X86_FEATURE_CLFLUSH (CPUID(0x1, 0, EDX, 19))
> @@ -150,6 +151,7 @@ static inline u8 cpuid_maxphyaddr(void)
> #define X86_FEATURE_RDPID (CPUID(0x7, 0, ECX, 22))
> #define X86_FEATURE_SPEC_CTRL (CPUID(0x7, 0, EDX, 26))
> #define X86_FEATURE_NX (CPUID(0x80000001, 0, EDX, 20))
> +#define X86_FEATURE_RDPRU (CPUID(0x80000008, 0, EBX, 4))
>
> /*
> * AMD CPUID features
> diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64
> index 51f9b80..010102b 100644
> --- a/x86/Makefile.x86_64
> +++ b/x86/Makefile.x86_64
> @@ -19,6 +19,7 @@ tests += $(TEST_DIR)/vmx.flat
> tests += $(TEST_DIR)/tscdeadline_latency.flat
> tests += $(TEST_DIR)/intel-iommu.flat
> tests += $(TEST_DIR)/vmware_backdoors.flat
> +tests += $(TEST_DIR)/rdpru.flat
>
> include $(SRCDIR)/$(TEST_DIR)/Makefile.common
>
> diff --git a/x86/rdpru.c b/x86/rdpru.c
> new file mode 100644
> index 0000000..87a517e
> --- /dev/null
> +++ b/x86/rdpru.c
> @@ -0,0 +1,27 @@
> +/* RDPRU test */
> +
> +#include "libcflat.h"
> +#include "processor.h"
> +#include "desc.h"
> +
> +static int rdpru_checking(void)
> +{
> + asm volatile (ASM_TRY("1f")
> + ".byte 0x0f,0x01,0xfd \n\t" /* rdpru */
> + "1:" : : "c" (0) : "eax", "edx");
> + return exception_vector();
> +}
> +
> +int main(int ac, char **av)
> +{
> + setup_idt();
> +
> + if (this_cpu_has(X86_FEATURE_HYPERVISOR)) {
> + report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
> + report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
> + } else {
> + report_skip("Not in a VM");
> + }
> +
> + return report_summary();
> +}
> diff --git a/x86/unittests.cfg b/x86/unittests.cfg
> index 694ee3d..9764e18 100644
> --- a/x86/unittests.cfg
> +++ b/x86/unittests.cfg
> @@ -221,6 +221,11 @@ file = pcid.flat
> extra_params = -cpu qemu64,+pcid
> arch = x86_64
>
> +[rdpru]
> +file = rdpru.flat
> +extra_params = -cpu host
> +arch = x86_64
> +
> [umip]
> file = umip.flat
> extra_params = -cpu qemu64,+umip
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-09-24 5:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-20 23:08 [kvm-unit-tests PATCH v2] kvm-unit-test: x86: Add RDPRU test Jim Mattson
2019-09-24 5:55 ` Krish Sadhukhan
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).