Skip to contentSkip to conversation

kvm-unit-test: x86: Add RDPRU test

PATCH Applied Jim Mattson 4 participants 10 messages Sep 19, 2019 – Sep 25, 2019 KVM

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm-unit-test: x86: Add RDPRU test

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

---
 lib/x86/processor.h |  1 +
 x86/Makefile.x86_64 |  1 +
 x86/rdpru.c         | 23 +++++++++++++++++++++++
 x86/unittests.cfg   |  5 +++++
 4 files changed, 30 insertions(+)
 create mode 100644 x86/rdpru.c
lib/x86/processor.h +1 -0
index b1c579b..121f19c 100644
@@ -150,6 +150,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
x86/Makefile.x86_64 +1 -0
index 51f9b80..010102b 100644
@@ -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
 
x86/rdpru.c new file +23 -0
new file mode 100644
index 0000000..a298960
@@ -0,0 +1,23 @@
+/* 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();
+
+	report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
+	report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
+
+	return report_summary();
+}
x86/unittests.cfg +5 -0
index 694ee3d..9764e18 100644
@@ -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
Signature · 1 line
2.23.0.351.gc4317032e6-goog
#1 lore raw
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

The AMD spec says,

        "When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will generate a #UD fault."

So we don't need to check the CR4.TSD value here ?

Quoted 80 lines
---
  lib/x86/processor.h |  1 +
  x86/Makefile.x86_64 |  1 +
  x86/rdpru.c         | 23 +++++++++++++++++++++++
  x86/unittests.cfg   |  5 +++++
  4 files changed, 30 insertions(+)

create mode 100644 x86/rdpru.c

lib/x86/processor.h +1 -0
index b1c579b..121f19c 100644
@@ -150,6 +150,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
x86/Makefile.x86_64 +1 -0
index 51f9b80..010102b 100644
@@ -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
 
x86/rdpru.c new file +23 -0
new file mode 100644
index 0000000..a298960
@@ -0,0 +1,23 @@
+/* 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();
+
+	report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
+	report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
+
+	return report_summary();
+}
x86/unittests.cfg +5 -0
index 694ee3d..9764e18 100644
@@ -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 lore raw
Quoted 7 lines · Krish Sadhukhan
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

Quoted 6 lines

The AMD spec says,

"When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will
generate a #UD fault."

So we don't need to check the CR4.TSD value here ?

KVM should set CPUID Fn8000_0008_EBX[RDPRU] to 0.

However, I should modify the test so it passes (or skips) on hardware. :-)

Quoted 81 lines
Quoted 81 lines
---
  lib/x86/processor.h |  1 +
  x86/Makefile.x86_64 |  1 +
  x86/rdpru.c         | 23 +++++++++++++++++++++++
  x86/unittests.cfg   |  5 +++++
  4 files changed, 30 insertions(+)

create mode 100644 x86/rdpru.c

lib/x86/processor.h +1 -0
index b1c579b..121f19c 100644
@@ -150,6 +150,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
x86/Makefile.x86_64 +1 -0
index 51f9b80..010102b 100644
@@ -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
 
x86/rdpru.c new file +23 -0
new file mode 100644
index 0000000..a298960
@@ -0,0 +1,23 @@
+/* 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();
+
+     report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
+     report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
+
+     return report_summary();
+}
x86/unittests.cfg +5 -0
index 694ee3d..9764e18 100644
@@ -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
#3 lore raw
Quoted 11 lines · Jim Mattson
Quoted 7 lines · Krish Sadhukhan
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

The AMD spec says,

Quoted 8 lines
Quoted 4 lines

"When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will
generate a #UD fault."

So we don't need to check the CR4.TSD value here ?

KVM should set CPUID Fn8000_0008_EBX[RDPRU] to 0.

However, I should modify the test so it passes (or skips) on hardware. :-)

Thanks for making this exception. Just wondering: have you or anyone else used this functionality - of running tests on bare-metal?

I ask because it would also save me the trouble of checking (occasionally) that nothing broke.

#4 lore raw
Quoted 15 lines · Nadav Amit
Quoted 15 lines · Jim Mattson
Quoted 10 lines · Krish Sadhukhan
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

The AMD spec says,

"When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will
generate a #UD fault."

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

So we don't need to check the CR4.TSD value here ?

KVM should set CPUID Fn8000_0008_EBX[RDPRU] to 0.

However, I should modify the test so it passes (or skips) on hardware. :-)

Thanks for making this exception. Just wondering: have you or anyone else used this functionality - of running tests on bare-metal?

I have not. However, if there is a simple way to add this testing to our workflow, I would be happy to ask the team to do so before sending submissions upstream.

Quoted 3 lines

I ask because it would also save me the trouble of checking (occasionally) that nothing broke.

#5 lore raw
Quoted 21 lines · Jim Mattson
Quoted 18 lines · Nadav Amit
Quoted 18 lines · Jim Mattson
Quoted 11 lines · Krish Sadhukhan
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

The AMD spec says,

"When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will
generate a #UD fault."

So we don't need to check the CR4.TSD value here ?

KVM should set CPUID Fn8000_0008_EBX[RDPRU] to 0.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

However, I should modify the test so it passes (or skips) on hardware. :-)

Thanks for making this exception. Just wondering: have you or anyone else used this functionality - of running tests on bare-metal?

I have not. However, if there is a simple way to add this testing to our workflow, I would be happy to ask the team to do so before sending submissions upstream.

I guess I should build some script that uses idrac to automate this process.

#6 lore raw
Quoted 24 lines · Nadav Amit
Quoted 24 lines · Jim Mattson
Quoted 20 lines · Nadav Amit
Quoted 19 lines · Jim Mattson
Quoted 11 lines · Krish Sadhukhan
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

The AMD spec says,

"When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will
generate a #UD fault."

So we don't need to check the CR4.TSD value here ?

KVM should set CPUID Fn8000_0008_EBX[RDPRU] to 0.

However, I should modify the test so it passes (or skips) on hardware. :-)

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Thanks for making this exception. Just wondering: have you or anyone else used this functionality - of running tests on bare-metal?

I have not. However, if there is a simple way to add this testing to our workflow, I would be happy to ask the team to do so before sending submissions upstream.

I guess I should build some script that uses idrac to automate this process.

I'm not familiar with idrac. What sort of functionality do you need from the test infrastructure to automate this process?

#7 lore raw
Quoted 29 lines · Jim Mattson
Quoted 26 lines · Nadav Amit
Quoted 26 lines · Jim Mattson
Quoted 22 lines · Nadav Amit
Quoted 11 lines · Jim Mattson
Quoted 7 lines · Krish Sadhukhan
Quoted 2 lines · Jim Mattson

Ensure that support for RDPRU is not enumerated in the guest's CPUID and that the RDPRU instruction raises #UD.

The AMD spec says,

Quoted 8 lines
Quoted 4 lines

"When the CPL>0 with CR4.TSD=1, the RDPRUinstruction will
generate a #UD fault."

So we don't need to check the CR4.TSD value here ?

KVM should set CPUID Fn8000_0008_EBX[RDPRU] to 0.

However, I should modify the test so it passes (or skips) on hardware. :-)

Thanks for making this exception. Just wondering: have you or anyone else used this functionality - of running tests on bare-metal?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I have not. However, if there is a simple way to add this testing to our workflow, I would be happy to ask the team to do so before sending submissions upstream.

I guess I should build some script that uses idrac to automate this process.

I'm not familiar with idrac. What sort of functionality do you need from the test infrastructure to automate this process?

Redirecting the serial port to the console and rebooting the machine remotely.

maintainer
#8 lore raw
In reply to Jim Mattson
Quoted 1 line · Jim Mattson

However, I should modify the test so it passes (or skips) on hardware. :-)

This should do.

x86/rdpru.c +4 -2
index a298960..3cdb2d6 100644
@@ -16,8 +16,10 @@ int main(int ac, char **av)
 {
 	setup_idt();
 
-	report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
-	report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
+	if (this_cpu_has(X86_FEATURE_RDPRU))
+		report_skip("RDPRU raises #UD");
+	else
+		report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
 
 	return report_summary();
 }

Paolo

maintainer Applied
#9 lore raw
In reply to Jim Mattson
Quoted 16 lines · Jim Mattson
x86/rdpru.c new file +9 -0
+int main(int ac, char **av)
+{
+	setup_idt();
+
+	report("RDPRU not supported", !this_cpu_has(X86_FEATURE_RDPRU));
+	report("RDPRU raises #UD", rdpru_checking() == UD_VECTOR);
+
+	return report_summary();
+}
x86/unittests.cfg +0 -0
index 694ee3d..9764e18 100644
@@ -221,6 +221,11 @@ file = pcid.flat
 extra_params = -cpu qemu64,+pcid

x86/unittests.cfg file = pcid.flat · line 231

Quoted 10 lines
x86/unittests.cfg +5 -0
 arch = x86_64
 
+[rdpru]
+file = rdpru.flat
+extra_params = -cpu host
+arch = x86_64
+
 [umip]
 file = umip.flat
 extra_params = -cpu qemu64,+umip

Queued, thanks.

Paolo