From patchwork Tue Nov 25 16:10:02 2014 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: 41481 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5C69025E18 for ; Tue, 25 Nov 2014 16:14:03 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf639197lbj.3 for ; Tue, 25 Nov 2014 08:14:02 -0800 (PST) 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:subject:date:message-id :in-reply-to:references:mime-version:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=EolznyP2AtPmKsyovb/dbOkZtXoS9ZOT6vfgeLTdfoo=; b=JjfJzYEUwPtB8DXPyP5hi74Lg7PlFnZZKk5mno3h32Nd9ULuIuWam5vkFfBIVmG8XD 9MjFDisKS+3H2csXPE1o9cdsPuRQ975n8LxseoqrtoAo4owJEHt5SVZ5pOsyvWALENvc AYZq4Hwk6+xwsAj7shvChOKsOFzepNVsnOFqYwk8KpQfVigFydXtbm7qdbCGNv+jQcu/ 8sIO/36jlcokNgJsF+emnAN1MstYtpmyxQUGAA7CObmSrgX5uXzG4i4Z4bdmkdZEaZ48 kSPzxDK0tgn2fN1wjRPNsO8wrx8rn/ererPGT0CKpdUs8jS+e1g6KWcb79XL9D+klVRy hGag== X-Gm-Message-State: ALoCoQk/aGrI5ledXY7dUW0lAr1CJAn7iUx1xaJlQGeU4to8jI8mtMqVDSW0DX5oW9q8SiDc8JaD X-Received: by 10.112.55.10 with SMTP id n10mr711103lbp.14.1416932042322; Tue, 25 Nov 2014 08:14:02 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.12 with SMTP id cq12ls603032lad.42.gmail; Tue, 25 Nov 2014 08:14:02 -0800 (PST) X-Received: by 10.112.135.229 with SMTP id pv5mr28160625lbb.52.1416932042176; Tue, 25 Nov 2014 08:14:02 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id n4si1849614lan.14.2014.11.25.08.14.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Nov 2014 08:14:02 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so830785lab.6 for ; Tue, 25 Nov 2014 08:14:02 -0800 (PST) X-Received: by 10.152.8.170 with SMTP id s10mr28214815laa.56.1416932042004; Tue, 25 Nov 2014 08:14:02 -0800 (PST) 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.184.201 with SMTP id ew9csp462796lbc; Tue, 25 Nov 2014 08:13:59 -0800 (PST) X-Received: by 10.70.138.14 with SMTP id qm14mr13712161pdb.98.1416932038314; Tue, 25 Nov 2014 08:13:58 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id lg2si2623682pab.114.2014.11.25.08.13.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Nov 2014 08:13:58 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1XtIjD-0003md-9B; Tue, 25 Nov 2014 16:12:35 +0000 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155] helo=socrates.bennee.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtIho-0003I4-OC for linux-arm-kernel@lists.infradead.org; Tue, 25 Nov 2014 16:11:21 +0000 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1XtJJT-0005HW-L8; Tue, 25 Nov 2014 17:50:03 +0100 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 Subject: [PATCH 4/7] KVM: arm64: guest debug, add SW break point support Date: Tue, 25 Nov 2014 16:10:02 +0000 Message-Id: <1416931805-23223-5-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1416931805-23223-1-git-send-email-alex.bennee@linaro.org> References: <1416931805-23223-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-20141125_081108_957354_08814090 X-CRM114-Status: GOOD ( 18.10 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- Cc: Lorenzo Pieralisi , Russell King , Jonathan Corbet , Gleb Natapov , jan.kiszka@siemens.com, "open list:DOCUMENTATION" , Will Deacon , open list , dahi@linux.vnet.ibm.com, Catalin Marinas , r65777@freescale.com, pbonzini@redhat.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+patch=linaro.org@lists.infradead.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.47 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 This adds support for SW breakpoints inserted by userspace. First we need to trap all BKPT exceptions in the hypervisor (ELS). This in controlled through the MDCR_EL2 register. I've added a new field to the vcpu structure to hold this value. There should be scope to rationlise this with the VCPU_DEBUG_FLAGS/KVM_ARM64_DEBUG_DIRTY_SHIFT manipulation in later patches. Once the exception arrives we triggers an exit from the main hypervisor loop to the hypervisor controller. The kvm_debug_exit_arch carries the address of the exception. If the controller doesn't know of breakpoint then we have a guest inserted breakpoint and the hypervisor needs to start again and deliver the exception to guest. Signed-off-by: Alex Bennée diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 2c6386e..9383359 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -2592,7 +2592,7 @@ when running. Common control bits are: The top 16 bits of the control field are architecture specific control flags which can include the following: - - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86] + - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64] - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390] - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86] - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86] diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index a0ff410..48d26bb 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -303,6 +303,9 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg) { + /* Route debug traps to el2? */ + bool route_el2 = false; + /* If it's not enabled clear all flags */ if (!(dbg->control & KVM_GUESTDBG_ENABLE)) { vcpu->guest_debug = 0; @@ -320,8 +323,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, /* Software Break Points */ if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) { - kvm_info("SW BP support requested, not yet implemented\n"); - return -EINVAL; + kvm_info("SW BP support requested\n"); + route_el2 = true; } /* Hardware assisted Break and Watch points */ @@ -330,6 +333,20 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, return -EINVAL; } + /* If we are going to handle any debug exceptions we need to + * set MDCE_EL2.TDE to ensure they are routed to the + * hypervisor. If userspace determines the exception was + * actually internal to the guest it needs to handle + * re-injecting the exception. + */ + if (route_el2) { + kvm_info("routing debug exceptions"); + vcpu->arch.mdcr_el2 = MDCR_EL2_TDE; + } else { + kvm_info("not routing debug exceptions"); + vcpu->arch.mdcr_el2 = 0; + } + return 0; } diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 2012c4b..38b0f07 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -98,6 +98,7 @@ struct kvm_vcpu_arch { /* HYP configuration */ u64 hcr_el2; + u32 mdcr_el2; /* Exception Information */ struct kvm_vcpu_fault_info fault; diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 9a9fce0..8da1043 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -122,6 +122,7 @@ int main(void) DEFINE(VCPU_HPFAR_EL2, offsetof(struct kvm_vcpu, arch.fault.hpfar_el2)); DEFINE(VCPU_DEBUG_FLAGS, offsetof(struct kvm_vcpu, arch.debug_flags)); DEFINE(VCPU_HCR_EL2, offsetof(struct kvm_vcpu, arch.hcr_el2)); + DEFINE(VCPU_MDCR_EL2, offsetof(struct kvm_vcpu, arch.mdcr_el2)); DEFINE(VCPU_IRQ_LINES, offsetof(struct kvm_vcpu, arch.irq_lines)); DEFINE(VCPU_HOST_CONTEXT, offsetof(struct kvm_vcpu, arch.host_cpu_context)); DEFINE(VCPU_TIMER_CNTV_CTL, offsetof(struct kvm_vcpu, arch.timer_cpu.cntv_ctl)); diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 34b8bd0..28dc92b 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -71,6 +71,26 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) return 1; } +/** + * kvm_handle_bkpt - handle a break-point instruction + * + * @vcpu: the vcpu pointer + * + * By definition if we arrive here it's because we are routing + * all SW breakpoints to the hyper-visor as some may be a result of + * guest debugging. If user-space decides this particular break-point + * isn't for the host to handle it can re-feed the exception to the + * guest. + */ +static int kvm_handle_bkpt(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + run->exit_reason = KVM_EXIT_DEBUG; + run->debug.arch.exit_type = KVM_DEBUG_EXIT_SW_BKPT; + run->debug.arch.address = *vcpu_pc(vcpu); + kvm_info("exiting from %llx\n", run->debug.arch.address); + return 0; +} + static exit_handle_fn arm_exit_handlers[] = { [ESR_EL2_EC_WFI] = kvm_handle_wfx, [ESR_EL2_EC_CP15_32] = kvm_handle_cp15_32, @@ -85,6 +105,8 @@ static exit_handle_fn arm_exit_handlers[] = { [ESR_EL2_EC_SYS64] = kvm_handle_sys_reg, [ESR_EL2_EC_IABT] = kvm_handle_guest_abort, [ESR_EL2_EC_DABT] = kvm_handle_guest_abort, + [ESR_EL2_EC_BKPT32] = kvm_handle_bkpt, + [ESR_EL2_EC_BRK64] = kvm_handle_bkpt, }; static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index b72aa9f..3c733ea 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S @@ -772,6 +772,10 @@ orr x2, x2, #(MDCR_EL2_TPM | MDCR_EL2_TPMCR) orr x2, x2, #(MDCR_EL2_TDRA | MDCR_EL2_TDOSA) + // Any other bits (currently TDE) + ldr x3, [x0, #VCPU_MDCR_EL2] + orr x2, x2, x3 + // Check for KVM_ARM64_DEBUG_DIRTY, and set debug to trap // if not dirty. ldr x3, [x0, #VCPU_DEBUG_FLAGS]