From patchwork Tue Mar 31 15:08:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 6131331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CE6B89F2EC for ; Tue, 31 Mar 2015 15:46:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2669C2017D for ; Tue, 31 Mar 2015 15:46:09 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 04F0A20149 for ; Tue, 31 Mar 2015 15:46:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YcyI2-0005aI-DT; Tue, 31 Mar 2015 15:41:18 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YcyAd-00077m-SO for linux-arm-kernel@bombadil.infradead.org; Tue, 31 Mar 2015 15:33:39 +0000 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155] helo=socrates.bennee.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YcyAZ-0000QB-PN for linux-arm-kernel@lists.infradead.org; Tue, 31 Mar 2015 15:33:36 +0000 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1Ycysb-0005gI-LV; Tue, 31 Mar 2015 18:19:05 +0200 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, peter.maydell@linaro.org, agraf@suse.de, drjones@redhat.com, pbonzini@redhat.com, zhichao.huang@linaro.org Subject: [PATCH v2 10/10] KVM: arm64: add trace points for guest_debug debug Date: Tue, 31 Mar 2015 16:08:08 +0100 Message-Id: <1427814488-28467-11-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.3.4 In-Reply-To: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> References: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150331_113335_948776_6B328C19 X-CRM114-Status: GOOD ( 14.81 ) X-Spam-Score: -1.2 (-) Cc: Catalin Marinas , Gleb Natapov , jan.kiszka@siemens.com, Will Deacon , open list , dahi@linux.vnet.ibm.com, r65777@freescale.com, bp@suse.de, =?UTF-8?q?Alex=20Benn=C3=A9e?= X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This includes trace points for: kvm_arch_setup_guest_debug kvm_arch_clear_guest_debug kvm_handle_guest_debug I've also added some generic register setting trace events so I can watch the register values being built up over time. The local dump_dbg_regs() function dumps all the HW BKPT and WPT registers. I've also added a #define trace_dreg to shorten some lines. Signed-off-by: Alex BennĂ©e diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c index 638c111..7c96288 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -25,12 +25,37 @@ #include #include +#include "trace.h" + +#define trace_dreg(name, value) trace_kvm_arch_setup_debug_reg32(name, value) + /* These are the bits of MDSCR_EL1 we may mess with */ #define MDSCR_EL1_DEBUG_BITS (DBG_MDSCR_SS | \ DBG_MDSCR_KDE | \ DBG_MDSCR_MDE) /** + * dump_dbg_regs - simple debug helper + * + * This provides a simple helper to dump the HW debug registers + */ +static void dump_dbg_regs(struct kvm_vcpu *vcpu, int nb, int nw) +{ + int i; + + for (i = 0; i < nb; i++) { + trace_printk("bkpt%d: 0x%08x:0x%llx\n", i, + (u32) vcpu_sys_reg(vcpu, DBGBCR0_EL1 + i), + vcpu_sys_reg(vcpu, DBGBVR0_EL1 + i)); + } + for (i = 0; i < nb; i++) { + trace_printk("wtpt%d: 0x%08x:0x%llx\n", i, + (u32) vcpu_sys_reg(vcpu, DBGWCR0_EL1 + i), + vcpu_sys_reg(vcpu, DBGWVR0_EL1 + i)); + } +} + +/** * kvm_arch_setup_debug - set-up debug related stuff * * @vcpu: the vcpu pointer @@ -52,9 +77,13 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) { bool trap_debug = false; + trace_kvm_arch_setup_debug(vcpu->guest_debug); + vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | MDCR_EL2_TPMCR); vcpu->arch.mdcr_el2 |= (MDCR_EL2_TDRA | MDCR_EL2_TDOSA); + trace_kvm_arch_setup_debug_reg32("MDCR_EL2", vcpu->arch.mdcr_el2); + /* * If we are not treating debug registers are dirty we need * to trap if the guest starts accessing them. @@ -66,6 +95,8 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) if (vcpu->guest_debug) { vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE; + trace_dreg("MDCR_EL2", vcpu->arch.mdcr_el2); + /* Save pstate/mdscr */ vcpu_debug_saved_reg(vcpu, pstate_ss_bit) = *vcpu_cpsr(vcpu) & DBG_SPSR_SS; @@ -73,6 +104,11 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) vcpu_debug_saved_reg(vcpu, mdscr_el1) = vcpu_sys_reg(vcpu, MDSCR_EL1); + trace_dreg("Save: PSTATE.SS", + vcpu_debug_saved_reg(vcpu, pstate_ss_bit)); + trace_dreg("Save: MDSCR", + vcpu_debug_saved_reg(vcpu, mdscr_el1)); + /* * Single Step (ARM ARM D2.12.3 The software step state * machine) @@ -88,6 +124,8 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; vcpu_sys_reg(vcpu, MDSCR_EL1) &= ~DBG_MDSCR_SS; } + trace_dreg("SPSR_EL2", *vcpu_cpsr(vcpu)); + trace_dreg("MDSCR_EL1", vcpu_sys_reg(vcpu, MDSCR_EL1)); /* * HW Break/Watch points @@ -136,6 +174,9 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) &host->dbg_wvr, sizeof(__u64)*nw); + if (trace_kvm_arch_setup_debug_reg32_enabled()) + dump_dbg_regs(vcpu, nb, nw); + /* Make sure hyp.S copies them in/out */ vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY; /* Also track guest changes */ @@ -147,15 +188,24 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) vcpu->arch.mdcr_el2 &= ~MDCR_EL2_TDE; } + trace_kvm_arch_setup_debug_reg32("MDCR_EL2", vcpu->arch.mdcr_el2); + trace_kvm_arch_setup_debug_reg32("MDSCR_EL1", + vcpu_sys_reg(vcpu, MDSCR_EL1)); + + /* Trap debug register access? */ if (trap_debug) vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA; else vcpu->arch.mdcr_el2 &= ~MDCR_EL2_TDA; + + trace_kvm_arch_setup_debug_reg32("MDCR_EL2", vcpu->arch.mdcr_el2); } void kvm_arch_clear_debug(struct kvm_vcpu *vcpu) { + trace_kvm_arch_clear_debug(vcpu->guest_debug); + if (vcpu->guest_debug) { /* Restore pstate/mdscr bits we may have messed with */ *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; @@ -164,6 +214,8 @@ void kvm_arch_clear_debug(struct kvm_vcpu *vcpu) vcpu_sys_reg(vcpu, MDSCR_EL1) = vcpu_debug_saved_reg(vcpu, mdscr_el1); + trace_dreg("SPSR_EL2", *vcpu_cpsr(vcpu)); + trace_dreg("MDSCR_EL1", vcpu_sys_reg(vcpu, MDSCR_EL1)); /* * If we were using HW debug we need to restore the * values the guest had set them up with @@ -188,6 +240,10 @@ void kvm_arch_clear_debug(struct kvm_vcpu *vcpu) memcpy(&vcpu_sys_reg(vcpu, DBGWVR0_EL1), ®s->dbg_wvr, sizeof(__u64)*nw); + + if (trace_kvm_arch_setup_debug_reg32_enabled()) + dump_dbg_regs(vcpu, nb, nw); + } } } diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 460a1aa..c6cc69a 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -97,6 +97,8 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) { u32 hsr = kvm_vcpu_get_hsr(vcpu); + trace_kvm_handle_guest_debug(*vcpu_pc(vcpu), hsr); + run->exit_reason = KVM_EXIT_DEBUG; run->debug.arch.hsr = hsr; diff --git a/arch/arm64/kvm/trace.h b/arch/arm64/kvm/trace.h index 157416e9..dffdb49 100644 --- a/arch/arm64/kvm/trace.h +++ b/arch/arm64/kvm/trace.h @@ -44,6 +44,72 @@ TRACE_EVENT(kvm_hvc_arm64, __entry->vcpu_pc, __entry->r0, __entry->imm) ); +TRACE_EVENT(kvm_handle_guest_debug, + TP_PROTO(unsigned long vcpu_pc, u32 hsr), + TP_ARGS(vcpu_pc, hsr), + + TP_STRUCT__entry( + __field(unsigned long, vcpu_pc) + __field(u32, hsr) + ), + + TP_fast_assign( + __entry->vcpu_pc = vcpu_pc; + __entry->hsr = hsr; + ), + + TP_printk("debug exception at 0x%08lx (HSR: 0x%08x)", + __entry->vcpu_pc, __entry->hsr) +); + + +TRACE_EVENT(kvm_arch_setup_debug, + TP_PROTO(__u32 guest_debug), + TP_ARGS(guest_debug), + + TP_STRUCT__entry( + __field(__u32, guest_debug) + ), + + TP_fast_assign( + __entry->guest_debug = guest_debug; + ), + + TP_printk("flags: 0x%08x", __entry->guest_debug) +); + +TRACE_EVENT(kvm_arch_clear_debug, + TP_PROTO(__u32 guest_debug), + TP_ARGS(guest_debug), + + TP_STRUCT__entry( + __field(__u32, guest_debug) + ), + + TP_fast_assign( + __entry->guest_debug = guest_debug; + ), + + TP_printk("flags: 0x%08x", __entry->guest_debug) +); + +TRACE_EVENT(kvm_arch_setup_debug_reg32, + TP_PROTO(const char *name, __u32 value), + TP_ARGS(name, value), + + TP_STRUCT__entry( + __field(const char *, name) + __field(__u32, value) + ), + + TP_fast_assign( + __entry->name = name; + __entry->value = value; + ), + + TP_printk("%s now 0x%08x", __entry->name, __entry->value) +); + #endif /* _TRACE_ARM64_KVM_H */ #undef TRACE_INCLUDE_PATH