From: Jim Mattson <jmattson@google.com>
To: kvm@vger.kernel.org
Cc: Jim Mattson <jmattson@google.com>, Peter Shier <pshier@google.com>
Subject: [kvm-unit-tests PATCH] kvm-unit-test: x86: Add RDPRU test
Date: Thu, 19 Sep 2019 16:02:25 -0700 [thread overview]
Message-ID: <20190919230225.37796-1-jmattson@google.com> (raw)
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 | 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
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index b1c579b..121f19c 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -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
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..a298960
--- /dev/null
+++ b/x86/rdpru.c
@@ -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();
+}
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
next reply other threads:[~2019-09-19 23:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-19 23:02 Jim Mattson [this message]
2019-09-20 19:36 ` [kvm-unit-tests PATCH] kvm-unit-test: x86: Add RDPRU test Krish Sadhukhan
2019-09-20 19:44 ` Jim Mattson
2019-09-24 17:29 ` Nadav Amit
2019-09-24 18:09 ` Jim Mattson
2019-09-24 18:14 ` Nadav Amit
2019-09-24 19:29 ` Jim Mattson
2019-09-24 19:31 ` Nadav Amit
2019-09-25 13:47 ` Paolo Bonzini
2019-09-25 13:43 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190919230225.37796-1-jmattson@google.com \
--to=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pshier@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.