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: 46598 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 552462159A for ; Tue, 31 Mar 2015 15:33:22 +0000 (UTC) Received: by wgfb3 with SMTP id b3sf4521617wgf.3 for ; Tue, 31 Mar 2015 08:33:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3Rvt66wkFxPoiucfk1jT3CFFg3oU9XbWKOqDkYjKkQ0=; b=bZweBxp15uhDI052RPcFFMj5s3JrxwijsX5KOu9whN/PmRTr56QDMOvubotr8eNewB QotXNdAeKwvYeZ7xSV5M/YXjV7y2A49NH/661G9wgAhLNWcPE/Yind/s9k+t5FDZay/M 0BzwabPr2RdqS4q0RjA+gOKe4p1JidlrFy0IaDufg6ystbqowme6ebbMji9nKxO+w7Gt g/P9Ol9Wx/4zoM4DxnGUjWjdYPu5trB5TGW6qgH65KVfHBRPbdSoy8G+1tmsnhIKFDYL kjDorzCg+p+QOoWMqqMNlqXabe/9W+GuEFg9evZI9jFlKW4o2NH7vWFkFImFzDEg4Lop 9E7g== X-Gm-Message-State: ALoCoQkblbhrBQsQlkAm+znXp8bO5Lm/Bh7fAByt56AgizqNVSzktfI3cWdObbXGBWN3v2f68j0K X-Received: by 10.180.90.175 with SMTP id bx15mr825406wib.3.1427816001574; Tue, 31 Mar 2015 08:33:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.82 with SMTP id u18ls782098lal.79.gmail; Tue, 31 Mar 2015 08:33:21 -0700 (PDT) X-Received: by 10.152.171.5 with SMTP id aq5mr8595953lac.91.1427816001299; Tue, 31 Mar 2015 08:33:21 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id df12si1670086lac.57.2015.03.31.08.33.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Mar 2015 08:33:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lajy8 with SMTP id y8so15650522laj.0 for ; Tue, 31 Mar 2015 08:33:21 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr31578380lba.19.1427816001147; Tue, 31 Mar 2015 08:33:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp60220lbq; Tue, 31 Mar 2015 08:33:20 -0700 (PDT) X-Received: by 10.68.136.133 with SMTP id qa5mr489145pbb.105.1427815999224; Tue, 31 Mar 2015 08:33:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bx3si19895483pab.125.2015.03.31.08.33.17; Tue, 31 Mar 2015 08:33:19 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755217AbbCaPdN (ORCPT + 27 others); Tue, 31 Mar 2015 11:33:13 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:48273 "EHLO socrates.bennee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754231AbbCaPdK (ORCPT ); Tue, 31 Mar 2015 11:33:10 -0400 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 Cc: jan.kiszka@siemens.com, dahi@linux.vnet.ibm.com, r65777@freescale.com, bp@suse.de, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gleb Natapov , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org (open list) 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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