From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [kvm-unit-tests PATCH] x86: Test single stepping with emulated instructions Date: Wed, 30 Nov 2016 19:17:35 +0100 Message-ID: <20161130181735.GE1682@potion> References: <20161128041932.11671-1-khuey@kylehuey.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Kyle Huey Return-path: Received: from mx1.redhat.com ([209.132.183.28]:42972 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758058AbcK3SRj (ORCPT ); Wed, 30 Nov 2016 13:17:39 -0500 Content-Disposition: inline In-Reply-To: <20161128041932.11671-1-khuey@kylehuey.com> Sender: kvm-owner@vger.kernel.org List-ID: 2016-11-27 20:19-0800, Kyle Huey: > This test checks that single stepping through CPUID and RDMSR works. > Both instructions trigger VM exits and are emulated by the hypervisor. > > Signed-off-by: Kyle Huey > --- > diff --git a/x86/debug.c b/x86/debug.c > @@ -107,16 +107,47 @@ hw_bp2: > "popf\n\t" > : "=g" (start) : : "rax"); > report("single step", > n == 3 && > bp_addr[0] == start+1+6 && dr6[0] == 0xffff4ff0 && > bp_addr[1] == start+1+6+1 && dr6[1] == 0xffff4ff0 && > bp_addr[2] == start+1+6+1+1 && dr6[2] == 0xffff4ff0); > > + /* > + * cpuid and rdmsr (among others) trigger VM exits and are then > + * emulated. Test that single stepping works on emulated instructions. > + */ > + n = 0; > + set_dr6(0); > + asm volatile( > + "pushf\n\t" > + "pop %%rax\n\t" > + "or $(1<<8),%%rax\n\t" > + "push %%rax\n\t" > + "lea (%%rip),%0\n\t" > + "popf\n\t" > + "and $~(1<<8),%%rax\n\t" > + "push %%rax\n\t" > + "xor %%rax,%%rax\n\t" > + "cpuid\n\t" > + "movl $0x1a0,%%ecx\n\t" > + "rdmsr\n\t" > + "popf\n\t" > + : "=g" (start) : : "rax", "ebx", "ecx", "edx"); > + report("single step emulated instructions", > + n == 7 && > + bp_addr[0] == start+1+6 && dr6[0] == 0xffff4ff0 && > + bp_addr[1] == start+1+6+1 && dr6[1] == 0xffff4ff0 && > + bp_addr[2] == start+1+6+1+3 && dr6[2] == 0xffff4ff0 && > + bp_addr[3] == start+1+6+1+3+2 && dr6[3] == 0xffff4ff0 && > + bp_addr[4] == start+1+6+1+3+2+5 && dr6[4] == 0xffff4ff0 && > + bp_addr[5] == start+1+6+1+3+2+5+2 && dr6[4] == 0xffff4ff0 && > + bp_addr[6] == start+1+6+1+3+2+5+2+1 && dr6[4] == 0xffff4ff0); You probably wanted to check dr6[5] and dr6[6] too, I will fix that while applying. Thanks.