[PATCH] x86: Test debug exceptions with disabled fast-string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



x86 allows to enable "fast strings", sacrificing the precision of debug
watchpoints.  Previously, KVM did not reflect the guest "fast strings" settings
in the actual MSR, resulting always in imprecise exception.

This test checks whether disabled "fast strings" causes the debug trap on
rep-string to occur on the precise iteration. A debug watchpoint which is not
cache-line aligned is set, and 128 bytes are set using rep-string operation.
The iteration in which the debug exception occurred is then checked.

Signed-off-by: Nadav Amit <namit@xxxxxxxxxxxxxxxxx>
---
 x86/debug.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/x86/debug.c b/x86/debug.c
index 34e56fb..eb96dbe 100644
--- a/x86/debug.c
+++ b/x86/debug.c
@@ -11,10 +11,13 @@
 
 #include "libcflat.h"
 #include "desc.h"
+#include "msr.h"
+#include "processor.h"
 
-static volatile unsigned long bp_addr[10], dr6[10];
+static volatile unsigned long bp_addr[10], dr6[10], rcx[10];
 static volatile unsigned int n;
 static volatile unsigned long value;
+static unsigned char dst[128] __attribute__ ((aligned(64)));
 
 static unsigned long get_dr6(void)
 {
@@ -43,6 +46,7 @@ static void handle_db(struct ex_regs *regs)
 {
 	bp_addr[n] = regs->rip;
 	dr6[n] = get_dr6();
+	rcx[n] = regs->rcx;
 
 	if (dr6[n] & 0x1)
 		regs->rflags |= (1 << 16);
@@ -60,7 +64,7 @@ static void handle_bp(struct ex_regs *regs)
 
 int main(int ac, char **av)
 {
-	unsigned long start;
+	unsigned long start, misc_enable;
 
 	setup_idt();
 	handle_exception(DB_VECTOR, handle_db);
@@ -109,5 +113,18 @@ hw_wp:
 	       n == 1 &&
 	       bp_addr[0] == ((unsigned long)&&hw_wp) && dr6[0] == 0xffff4ff2);
 
+	misc_enable = rdmsr(MSR_IA32_MISC_ENABLE);
+	wrmsr(MSR_IA32_MISC_ENABLE,
+	      misc_enable & ~MSR_IA32_MISC_ENABLE_FAST_STRING);
+
+	n = 0;
+	set_dr1((void *)&dst[59]);
+	set_dr7(0x0010040a);
+
+	asm volatile("rep stosb\n\t" : : "D"(dst), "c"(128) : "cc", "memory");
+
+	report("hw watchpoint with disabled fast-string", rcx[0] == 128-1-59);
+	wrmsr(MSR_IA32_MISC_ENABLE, misc_enable);
+
 	return report_summary();
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux