From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933215AbbDJNKJ (ORCPT ); Fri, 10 Apr 2015 09:10:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49522 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755628AbbDJNKE (ORCPT ); Fri, 10 Apr 2015 09:10:04 -0400 Date: Fri, 10 Apr 2015 15:09:05 +0200 From: Andrew Jones To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: 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, pbonzini@redhat.com, zhichao.huang@linaro.org, jan.kiszka@siemens.com, dahi@linux.vnet.ibm.com, r65777@freescale.com, bp@suse.de, Gleb Natapov , Jonathan Corbet , Russell King , Catalin Marinas , Will Deacon , "open list:DOCUMENTATION" , open list Subject: Re: [PATCH v2 06/10] KVM: arm64: guest debug, add SW break point support Message-ID: <20150410130904.GG3227@hawk.usersys.redhat.com> References: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 31, 2015 at 04:08:04PM +0100, Alex Bennée wrote: > This adds support for SW breakpoints inserted by userspace. > > We do this by trapping all BKPT exceptions in the > hypervisor (MDCR_EL2_TDE). The kvm_debug_exit_arch carries the address > of the exception. If user-space doesn't know of the 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 > > --- > v2 > - update to use new exit struct > - tweak for C setup > - do our setup in debug_setup/clear code > - fixed up comments > > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > index 06c5064..17d4f9c 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -2626,7 +2626,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 7ea8b0e..d3bc8dc 100644 > --- a/arch/arm/kvm/arm.c > +++ b/arch/arm/kvm/arm.c > @@ -304,7 +304,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) > kvm_arm_set_running_vcpu(NULL); > } > > -#define KVM_GUESTDBG_VALID (KVM_GUESTDBG_ENABLE) > +#define KVM_GUESTDBG_VALID (KVM_GUESTDBG_ENABLE|KVM_GUESTDBG_USE_SW_BP) > > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg) > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > index 8a29d0b..cff0475 100644 > --- a/arch/arm64/kvm/debug.c > +++ b/arch/arm64/kvm/debug.c > @@ -45,11 +45,18 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) > vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | MDCR_EL2_TPMCR); > vcpu->arch.mdcr_el2 |= (MDCR_EL2_TDRA | MDCR_EL2_TDOSA); > > + /* Trap debug register access? */ > if (!vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) > vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA; > else > vcpu->arch.mdcr_el2 &= ~MDCR_EL2_TDA; > > + /* Trap breakpoints? */ > + if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) > + vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE; > + else > + vcpu->arch.mdcr_el2 &= ~MDCR_EL2_TDE; > + > } > > void kvm_arch_clear_debug(struct kvm_vcpu *vcpu) > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > index 524fa25..ed1bbb4 100644 > --- a/arch/arm64/kvm/handle_exit.c > +++ b/arch/arm64/kvm/handle_exit.c > @@ -82,6 +82,37 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) > return 1; > } > > +/** > + * kvm_handle_debug_exception - handle a debug exception instruction > + * > + * @vcpu: the vcpu pointer > + * @run: access to the kvm_run structure for results > + * > + * We route all debug exceptions through the same handler as we > + * just need to report the PC and the HSR values to userspace. > + * Userspace may decide to re-inject the exception and deliver it to > + * the guest if it wasn't for the host to deal with. > + */ > +static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) > +{ > + u32 hsr = kvm_vcpu_get_hsr(vcpu); > + > + run->exit_reason = KVM_EXIT_DEBUG; > + run->debug.arch.hsr = hsr; > + > + switch (hsr >> ESR_ELx_EC_SHIFT) { > + case ESR_ELx_EC_BKPT32: > + case ESR_ELx_EC_BRK64: > + run->debug.arch.pc = *vcpu_pc(vcpu); > + break; > + default: > + kvm_err("%s: un-handled case hsr: %#08x\n", > + __func__, (unsigned int) hsr); > + break; > + } > + return 0; > +} > + > static exit_handle_fn arm_exit_handlers[] = { > [ESR_ELx_EC_WFx] = kvm_handle_wfx, > [ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32, > @@ -96,6 +127,8 @@ static exit_handle_fn arm_exit_handlers[] = { > [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg, > [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort, > [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort, > + [ESR_ELx_EC_BKPT32] = kvm_handle_guest_debug, > + [ESR_ELx_EC_BRK64] = kvm_handle_guest_debug, > }; > > static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) > -- > 2.3.4 > I agree with David's name change suggestion, "kvm_handle_guest_debug", otherwise Reviewed-by: Andrew Jones From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: Re: [PATCH v2 06/10] KVM: arm64: guest debug, add SW break point support Date: Fri, 10 Apr 2015 15:09:05 +0200 Message-ID: <20150410130904.GG3227@hawk.usersys.redhat.com> References: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: Russell King , kvm@vger.kernel.org, Jonathan Corbet , marc.zyngier@arm.com, jan.kiszka@siemens.com, "open list:DOCUMENTATION" , Will Deacon , open list , Catalin Marinas , dahi@linux.vnet.ibm.com, linux-arm-kernel@lists.infradead.org, zhichao.huang@linaro.org, r65777@freescale.com, pbonzini@redhat.com, bp@suse.de, Gleb Natapov , kvmarm@lists.cs.columbia.edu To: Alex =?iso-8859-1?Q?Benn=E9e?= Return-path: Content-Disposition: inline In-Reply-To: <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu List-Id: kvm.vger.kernel.org On Tue, Mar 31, 2015 at 04:08:04PM +0100, Alex Benn=E9e wrote: > This adds support for SW breakpoints inserted by userspace. > = > We do this by trapping all BKPT exceptions in the > hypervisor (MDCR_EL2_TDE). The kvm_debug_exit_arch carries the address > of the exception. If user-space doesn't know of the 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=E9e > = > --- > v2 > - update to use new exit struct > - tweak for C setup > - do our setup in debug_setup/clear code > - fixed up comments > = > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kv= m/api.txt > index 06c5064..17d4f9c 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -2626,7 +2626,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 7ea8b0e..d3bc8dc 100644 > --- a/arch/arm/kvm/arm.c > +++ b/arch/arm/kvm/arm.c > @@ -304,7 +304,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) > kvm_arm_set_running_vcpu(NULL); > } > = > -#define KVM_GUESTDBG_VALID (KVM_GUESTDBG_ENABLE) > +#define KVM_GUESTDBG_VALID (KVM_GUESTDBG_ENABLE|KVM_GUESTDBG_USE_SW_BP) > = > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg) > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > index 8a29d0b..cff0475 100644 > --- a/arch/arm64/kvm/debug.c > +++ b/arch/arm64/kvm/debug.c > @@ -45,11 +45,18 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) > vcpu->arch.mdcr_el2 |=3D (MDCR_EL2_TPM | MDCR_EL2_TPMCR); > vcpu->arch.mdcr_el2 |=3D (MDCR_EL2_TDRA | MDCR_EL2_TDOSA); > = > + /* Trap debug register access? */ > if (!vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) > vcpu->arch.mdcr_el2 |=3D MDCR_EL2_TDA; > else > vcpu->arch.mdcr_el2 &=3D ~MDCR_EL2_TDA; > = > + /* Trap breakpoints? */ > + if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) > + vcpu->arch.mdcr_el2 |=3D MDCR_EL2_TDE; > + else > + vcpu->arch.mdcr_el2 &=3D ~MDCR_EL2_TDE; > + > } > = > void kvm_arch_clear_debug(struct kvm_vcpu *vcpu) > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > index 524fa25..ed1bbb4 100644 > --- a/arch/arm64/kvm/handle_exit.c > +++ b/arch/arm64/kvm/handle_exit.c > @@ -82,6 +82,37 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struc= t kvm_run *run) > return 1; > } > = > +/** > + * kvm_handle_debug_exception - handle a debug exception instruction > + * > + * @vcpu: the vcpu pointer > + * @run: access to the kvm_run structure for results > + * > + * We route all debug exceptions through the same handler as we > + * just need to report the PC and the HSR values to userspace. > + * Userspace may decide to re-inject the exception and deliver it to > + * the guest if it wasn't for the host to deal with. > + */ > +static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run = *run) > +{ > + u32 hsr =3D kvm_vcpu_get_hsr(vcpu); > + > + run->exit_reason =3D KVM_EXIT_DEBUG; > + run->debug.arch.hsr =3D hsr; > + > + switch (hsr >> ESR_ELx_EC_SHIFT) { > + case ESR_ELx_EC_BKPT32: > + case ESR_ELx_EC_BRK64: > + run->debug.arch.pc =3D *vcpu_pc(vcpu); > + break; > + default: > + kvm_err("%s: un-handled case hsr: %#08x\n", > + __func__, (unsigned int) hsr); > + break; > + } > + return 0; > +} > + > static exit_handle_fn arm_exit_handlers[] =3D { > [ESR_ELx_EC_WFx] =3D kvm_handle_wfx, > [ESR_ELx_EC_CP15_32] =3D kvm_handle_cp15_32, > @@ -96,6 +127,8 @@ static exit_handle_fn arm_exit_handlers[] =3D { > [ESR_ELx_EC_SYS64] =3D kvm_handle_sys_reg, > [ESR_ELx_EC_IABT_LOW] =3D kvm_handle_guest_abort, > [ESR_ELx_EC_DABT_LOW] =3D kvm_handle_guest_abort, > + [ESR_ELx_EC_BKPT32] =3D kvm_handle_guest_debug, > + [ESR_ELx_EC_BRK64] =3D kvm_handle_guest_debug, > }; > = > static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) > -- = > 2.3.4 > I agree with David's name change suggestion, "kvm_handle_guest_debug", otherwise Reviewed-by: Andrew Jones From mboxrd@z Thu Jan 1 00:00:00 1970 From: drjones@redhat.com (Andrew Jones) Date: Fri, 10 Apr 2015 15:09:05 +0200 Subject: [PATCH v2 06/10] KVM: arm64: guest debug, add SW break point support In-Reply-To: <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> References: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> Message-ID: <20150410130904.GG3227@hawk.usersys.redhat.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Tue, Mar 31, 2015 at 04:08:04PM +0100, Alex Benn?e wrote: > This adds support for SW breakpoints inserted by userspace. > > We do this by trapping all BKPT exceptions in the > hypervisor (MDCR_EL2_TDE). The kvm_debug_exit_arch carries the address > of the exception. If user-space doesn't know of the 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 > > --- > v2 > - update to use new exit struct > - tweak for C setup > - do our setup in debug_setup/clear code > - fixed up comments > > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > index 06c5064..17d4f9c 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -2626,7 +2626,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 7ea8b0e..d3bc8dc 100644 > --- a/arch/arm/kvm/arm.c > +++ b/arch/arm/kvm/arm.c > @@ -304,7 +304,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) > kvm_arm_set_running_vcpu(NULL); > } > > -#define KVM_GUESTDBG_VALID (KVM_GUESTDBG_ENABLE) > +#define KVM_GUESTDBG_VALID (KVM_GUESTDBG_ENABLE|KVM_GUESTDBG_USE_SW_BP) > > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg) > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > index 8a29d0b..cff0475 100644 > --- a/arch/arm64/kvm/debug.c > +++ b/arch/arm64/kvm/debug.c > @@ -45,11 +45,18 @@ void kvm_arch_setup_debug(struct kvm_vcpu *vcpu) > vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | MDCR_EL2_TPMCR); > vcpu->arch.mdcr_el2 |= (MDCR_EL2_TDRA | MDCR_EL2_TDOSA); > > + /* Trap debug register access? */ > if (!vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) > vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA; > else > vcpu->arch.mdcr_el2 &= ~MDCR_EL2_TDA; > > + /* Trap breakpoints? */ > + if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) > + vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE; > + else > + vcpu->arch.mdcr_el2 &= ~MDCR_EL2_TDE; > + > } > > void kvm_arch_clear_debug(struct kvm_vcpu *vcpu) > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > index 524fa25..ed1bbb4 100644 > --- a/arch/arm64/kvm/handle_exit.c > +++ b/arch/arm64/kvm/handle_exit.c > @@ -82,6 +82,37 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) > return 1; > } > > +/** > + * kvm_handle_debug_exception - handle a debug exception instruction > + * > + * @vcpu: the vcpu pointer > + * @run: access to the kvm_run structure for results > + * > + * We route all debug exceptions through the same handler as we > + * just need to report the PC and the HSR values to userspace. > + * Userspace may decide to re-inject the exception and deliver it to > + * the guest if it wasn't for the host to deal with. > + */ > +static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) > +{ > + u32 hsr = kvm_vcpu_get_hsr(vcpu); > + > + run->exit_reason = KVM_EXIT_DEBUG; > + run->debug.arch.hsr = hsr; > + > + switch (hsr >> ESR_ELx_EC_SHIFT) { > + case ESR_ELx_EC_BKPT32: > + case ESR_ELx_EC_BRK64: > + run->debug.arch.pc = *vcpu_pc(vcpu); > + break; > + default: > + kvm_err("%s: un-handled case hsr: %#08x\n", > + __func__, (unsigned int) hsr); > + break; > + } > + return 0; > +} > + > static exit_handle_fn arm_exit_handlers[] = { > [ESR_ELx_EC_WFx] = kvm_handle_wfx, > [ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32, > @@ -96,6 +127,8 @@ static exit_handle_fn arm_exit_handlers[] = { > [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg, > [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort, > [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort, > + [ESR_ELx_EC_BKPT32] = kvm_handle_guest_debug, > + [ESR_ELx_EC_BRK64] = kvm_handle_guest_debug, > }; > > static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) > -- > 2.3.4 > I agree with David's name change suggestion, "kvm_handle_guest_debug", otherwise Reviewed-by: Andrew Jones