From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex =?utf-8?Q?Benn=C3=A9e?= Subject: Re: [PATCH v2 06/10] KVM: arm64: guest debug, add SW break point support Date: Wed, 22 Apr 2015 10:46:47 +0100 Message-ID: <87383s7awo.fsf@linaro.org> 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="utf-8" Content-Transfer-Encoding: base64 Return-path: Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 61FF04E2D5 for ; Wed, 22 Apr 2015 05:38:28 -0400 (EDT) Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xUVjwXkbMjCh for ; Wed, 22 Apr 2015 05:38:27 -0400 (EDT) Received: from socrates.bennee.com (static.88-198-71-155.clients.your-server.de [88.198.71.155]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 342854E2CB for ; Wed, 22 Apr 2015 05:38:26 -0400 (EDT) In-reply-to: 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 To: Zhichao Huang 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, r65777@freescale.com, pbonzini@redhat.com, bp@suse.de, Gleb Natapov , kvmarm@lists.cs.columbia.edu List-Id: kvmarm@lists.cs.columbia.edu ClpoaWNoYW8gSHVhbmcgPHpoaWNoYW8uaHVhbmdAbGluYXJvLm9yZz4gd3JpdGVzOgoKPiBPbiBU dWUsIE1hciAzMSwgMjAxNSBhdCAwNDowODowNFBNICswMTAwLCBBbGV4IEJlbm7D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G9pbnQgd2FzIG9uZSBvZiB0aGUgb25l cyB3ZQppbnNlcnRlZCBhdCB3aGljaCBwb2ludCBjb250cm9sIGlzIHBhc3NlZCBiYWNrIHRvIHRo ZSBob3N0IEdEQiAoYXR0YWNoZWQKdmlhIHRoZSBHREIgc3R1YiBpbiBRRU1VKS4gSWYgaXQgaXMg bm90IGEgYnJlYWtwb2ludCB3aGljaCB3YXMgc2V0LXVwIGJ5CnRoZSBob3N0IHRoZW4gaXQgbXVz dCBiZSBvbmUgZm9yIHRoZSBndWVzdCBhdCB3aGljaCBwb2ludCB3ZSBuZWVkIHRvCmVuc3VyZSB0 aGUgZXhjZXB0aW9uIGlzIGRlbGl2ZXJlZCB0byB0aGUgZ3Vlc3QgZm9yIGl0IHRvIHByb2Nlc3Mu CgotLSAKQWxleCBCZW5uw6llCl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fCmt2bWFybSBtYWlsaW5nIGxpc3QKa3ZtYXJtQGxpc3RzLmNzLmNvbHVtYmlhLmVk dQpodHRwczovL2xpc3RzLmNzLmNvbHVtYmlhLmVkdS9tYWlsbWFuL2xpc3RpbmZvL2t2bWFybQo= From mboxrd@z Thu Jan 1 00:00:00 1970 From: alex.bennee@linaro.org (Alex =?utf-8?Q?Benn=C3=A9e?=) Date: Wed, 22 Apr 2015 10:46:47 +0100 Subject: [PATCH v2 06/10] KVM: arm64: guest debug, add SW break point support In-Reply-To: References: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> Message-ID: <87383s7awo.fsf@linaro.org> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Zhichao Huang writes: > 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). > > why should we trap all debug exceptions? > > The trap for cp14 register r/w seems enough to record relevant > informations to context switch the dbg register while neccessary. Lets think about this case when the SW breakpoint exception occurs: If KVM doesn't trap it and pass it back to userspace to handle it would have to deliver it to the guest. The guest not having inserted the breakpoint in the first place would get very confused. So what we actually do is re-route the exception to the hypervisor and stop the VM and return to userspace with the debug information. Once in QEMU we check to see if the SW breakpoint was one of the ones we inserted at which point control is passed back to the host GDB (attached via the GDB stub in QEMU). If it is not a breakpoint which was set-up by the host then it must be one for the guest at which point we need to ensure the exception is delivered to the guest for it to process. -- Alex Benn?e From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965943AbbDVJqo (ORCPT ); Wed, 22 Apr 2015 05:46:44 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:49462 "EHLO socrates.bennee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965926AbbDVJqk (ORCPT ); Wed, 22 Apr 2015 05:46:40 -0400 References: <1427814488-28467-1-git-send-email-alex.bennee@linaro.org> <1427814488-28467-7-git-send-email-alex.bennee@linaro.org> From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Zhichao Huang 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, drjones@redhat.com, pbonzini@redhat.com, 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 In-reply-to: Date: Wed, 22 Apr 2015 10:46:47 +0100 Message-ID: <87383s7awo.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Zhichao Huang writes: > 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). > > why should we trap all debug exceptions? > > The trap for cp14 register r/w seems enough to record relevant > informations to context switch the dbg register while neccessary. Lets think about this case when the SW breakpoint exception occurs: If KVM doesn't trap it and pass it back to userspace to handle it would have to deliver it to the guest. The guest not having inserted the breakpoint in the first place would get very confused. So what we actually do is re-route the exception to the hypervisor and stop the VM and return to userspace with the debug information. Once in QEMU we check to see if the SW breakpoint was one of the ones we inserted at which point control is passed back to the host GDB (attached via the GDB stub in QEMU). If it is not a breakpoint which was set-up by the host then it must be one for the guest at which point we need to ensure the exception is delivered to the guest for it to process. -- Alex Bennée