[PATCH kvm-unit-tests v2] x86: Test illegal movbe

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

 



Previously KVM ignored the mod field of MOVBE instruction, so MOVBE from
register to register succeeds, although it should fail (cause a #UD exception).
This test check that a #UD is indeed delivered upon such MOVBE.

The test would not work if MOVBE is unsupported.

Signed-off-by: Nadav Amit <namit@xxxxxxxxxxxxxxxxx>
---
v1->v2: Add missing return upon no support for MOVBE
---
 x86/emulator.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/x86/emulator.c b/x86/emulator.c
index 5aa4dbf..567e421 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -1051,6 +1051,29 @@ static void test_simplealu(u32 *mem)
     report("test", *mem == 0x8400);
 }
 
+static void illegal_movbe_handler(struct ex_regs *regs)
+{
+	extern char bad_movbe_cont;
+
+	++exceptions;
+	regs->rip = (ulong)&bad_movbe_cont;
+}
+
+static void test_illegal_movbe(void)
+{
+	if (!(cpuid(1).c & (1 << 22))) {
+		printf("SKIP: illegal movbe\n");
+		return;
+	}
+
+	exceptions = 0;
+	handle_exception(UD_VECTOR, illegal_movbe_handler);
+	asm volatile(".byte 0x0f; .byte 0x38; .byte 0xf0; .byte 0xc0;\n\t"
+		     " bad_movbe_cont:" : : : "rax");
+	report("illegal movbe", exceptions == 1);
+	handle_exception(UD_VECTOR, 0);
+}
+
 int main()
 {
 	void *mem;
@@ -1119,6 +1142,7 @@ int main()
 	test_string_io_mmio(mem);
 
 	test_jmp_noncanonical(mem);
+	test_illegal_movbe();
 
 	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