Skip to contentSkip to conversation

add vmexit tests for IBRS and IBPB

PATCH Liran Alon 2 participants 2 messages Jan 9, 2018 KVM

lore
Share & tools
lore

Liran Alon

author
#0 lore raw
Quoted 56 lines · ----- [email protected] wrote:
Quoted 6 lines · Liran Alon
Quoted 3 lines · ----- [email protected] wrote:

Results on Haswell:

wr_ibrs_msr 506 (actually ~250, because the test writes

twice)

Quoted 32 lines
Quoted 32 lines
   wr_ibpb_msr 4212

Yuck.

---
 lib/x86/msr.h |  3 +++
 x86/vmexit.c  | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+)
lib/x86/msr.h +3 -0
index 2c0598c..3eff710 100644
@@ -32,6 +32,9 @@
 #define EFER_FFXSR		(1<<_EFER_FFXSR)
 
 /* Intel MSRs. Some also available on other CPUs */
+#define MSR_IA32_SPEC_CTRL              0x00000048
+#define MSR_IA32_PRED_CMD               0x00000049
+
 #define MSR_IA32_PERFCTR0		0x000000c1
 #define MSR_IA32_PERFCTR1		0x000000c2
 #define MSR_FSB_FREQ			0x000000cd
x86/vmexit.c +0 -0
index 65111ae..a04e971 100644
@@ -413,6 +413,27 @@ static void tscdeadline(void)
 	while (x == 0) barrier();
 }
 
Quoted 14 lines
Quoted 4 lines
x86/vmexit.c +4 -0
+static int has_spec_ctrl(void)
+{
+    return !!(cpuid_indexed(7,0).d & (1 << 26));
+}

x86/vmexit.c static void tscdeadline(void) · line 429

Quoted 10 lines
x86/vmexit.c +10 -0
+
+static void wr_ibrs_msr(void)
+{
+	wrmsr(MSR_IA32_SPEC_CTRL, 1);
+	wrmsr(MSR_IA32_SPEC_CTRL, 0);
+}
+
+static int has_ibpb(void)
+{
+    return has_spec_ctrl() || !!(cpuid(0x80000008).b & (1 <<

12));

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Why are you doing here "has_spec_ctrl() ||" and not just checking

"cpuid(0x80000008).b & (1 << 12)"?

Because Intel's recent microcode updates do not expose CPUID[EAX=0x80000008].EBX[12], but they do add PRED_CMD MSR.

Paolo

OK that's weird... :)
So doesn't it make sense to also have same logic in cpu_has_ibpb_support() in KVM?

Also, I would add an appropriate comment above those lines as this is not trivial.

-Liran

Quoted 25 lines
Quoted 25 lines

-Liran

Quoted 21 lines
x86/vmexit.c +9 -0
+}
+
+static void wr_ibpb_msr(void)
+{
+	wrmsr(MSR_IA32_PRED_CMD, 1);
+}
+
 static struct test tests[] = {
 	{ cpuid_test, "cpuid", .parallel = 1,  },
 	{ vmcall, "vmcall", .parallel = 1, },
@@ -440,6 +461,8 @@ static struct test tests[] = {
 	{ ipi, "ipi", is_smp, .parallel = 0, },
 	{ ipi_halt, "ipi_halt", is_smp, .parallel = 0, },
 	{ ple_round_robin, "ple_round_robin", .parallel = 1 },
+	{ wr_ibrs_msr, "wr_ibrs_msr", has_spec_ctrl, .parallel = 1 },
+	{ wr_ibpb_msr, "wr_ibpb_msr", has_ibpb, .parallel = 1 },
 	{ wr_tsc_adjust_msr, "wr_tsc_adjust_msr", .parallel = 1 },
 	{ rd_tsc_adjust_msr, "rd_tsc_adjust_msr", .parallel = 1 },
 	{ NULL, "pci-mem", .parallel = 0, .next = pci_mem_next },
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 8 lines · Liran Alon
Quoted 5 lines
Quoted 1 line

Why are you doing here "has_spec_ctrl() ||" and not just checking

"cpuid(0x80000008).b & (1 << 12)"?

Because Intel's recent microcode updates do not expose CPUID[EAX=0x80000008].EBX[12], but they do add PRED_CMD MSR.

OK that's weird... :)
So doesn't it make sense to also have same logic in cpu_has_ibpb_support() in KVM?

Note that cpu_has_ibpb_support() is not going to exist in the final committed version of the series. It's just a hack for testing before the bare metal IBRS/IBPB patches are in.

Quoted 1 line

Also, I would add an appropriate comment above those lines as this is not trivial.

Ok, will do.

Paolo