[PATCH kvm-unit-tests] x86: debug: test debug extensions

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

 



Not committing this yet since KVM does not support I/O breakpoints, but posting
it because it is useful for TCG too.

TCG fails the tests because it doesn't preserve DRn_FIXED_1 on mov to dr6 and
dr7, and also because it lacks support for ICEBP, but it is easy to fix the
former and disable the ICEBP test.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
 x86/debug.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/x86/debug.c b/x86/debug.c
index d04de23..a71a8ae 100644
--- a/x86/debug.c
+++ b/x86/debug.c
@@ -11,6 +11,7 @@
 
 #include "libcflat.h"
 #include "desc.h"
+#include "processor.h"
 
 static volatile unsigned long bp_addr[10], dr6[10];
 static volatile unsigned int n;
@@ -71,6 +72,8 @@ int main(int ac, char **av)
 	handle_exception(DB_VECTOR, handle_db);
 	handle_exception(BP_VECTOR, handle_bp);
 
+	write_cr4(read_cr4() | X86_CR4_DE);
+
 sw_bp:
 	asm volatile("int3");
 	report("#BP", bp_addr[0] == (unsigned long)&&sw_bp + 1);
@@ -146,5 +149,51 @@ sw_icebp:
 	       bp_addr[0] == (unsigned long)&&sw_icebp + 1 &&
 	       dr6[0] == 0xffff0ff0);
 
+	n = 0;
+	set_dr1((void *)0xe1ul);
+	set_dr7(0x0020400a);
+	set_dr6(0);
+
+	asm volatile(
+		"out %ax,$0xe0\n\t"
+		"out %al,$0xe1\n\t");
+hw_wp_out1:
+
+	set_dr1((void *)0xe0ul);
+	set_dr7(0x00e0400a);
+	asm volatile(
+		"out %al,$0xe0\n\t");
+hw_wp_out2:
+
+	report("hw I/O port watchpoint (out)",
+	       n == 3 &&
+	       bp_addr[0] == ((unsigned long)&&hw_wp_out1 - 2) &&
+	       bp_addr[1] == ((unsigned long)&&hw_wp_out1) &&
+	       bp_addr[2] == ((unsigned long)&&hw_wp_out2) &&
+	       dr6[0] == 0xffff0ff2);
+
+	n = 0;
+	set_dr1((void *)0xe1ul);
+	set_dr7(0x0020400a);
+	set_dr6(0);
+
+	asm volatile(
+		"in $0xe0,%%ax\n\t"
+		"in $0xe1,%%al\n\t" : : : "rax");
+hw_wp_in1:
+
+	set_dr1((void *)0xe0ul);
+	set_dr7(0x00e0400a);
+
+	asm volatile(
+		"in $0xe0,%%al\n\t" : : : "rax");
+hw_wp_in2:
+	report("hw I/O port watchpoint (in)",
+	       n == 3 &&
+	       bp_addr[0] == ((unsigned long)&&hw_wp_in1 - 2) &&
+	       bp_addr[1] == ((unsigned long)&&hw_wp_in1) &&
+	       bp_addr[2] == ((unsigned long)&&hw_wp_in2) &&
+	       dr6[0] == 0xffff0ff2);
+
 	return report_summary();
 }
-- 
2.5.0

--
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