From patchwork Mon Dec 4 14:03:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10090339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6FD9B60329 for ; Mon, 4 Dec 2017 14:04:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57B1C2899A for ; Mon, 4 Dec 2017 14:04:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CB2F28D48; Mon, 4 Dec 2017 14:04:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,URIBL_DBL_ABUSE_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B709B2899A for ; Mon, 4 Dec 2017 14:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754486AbdLDOEM (ORCPT ); Mon, 4 Dec 2017 09:04:12 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:41144 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754459AbdLDOEC (ORCPT ); Mon, 4 Dec 2017 09:04:02 -0500 Received: by mail-wr0-f194.google.com with SMTP id z18so17450593wrb.8 for ; Mon, 04 Dec 2017 06:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ein/Nby7sgDLTA7uxbc+atuaNBKVCQldTuDobTGDHS8=; b=cgsusLZkx3silE9HgtJlC7ZttflgKQjOmDTpffyzTxhWxnLqjG053NireJNIJh37Jg mVQ+H7407kIdqGuQg5O3axAmMwIplOeL2ycBsLWPBCM+TujE4CIzwnypwqb76NwTcI+J p8PZ6uvDdB1ltSM25MLTqcjRRlAza7/06bkQt0AD2+mHcEgdzt2+BrjdHGx7TO4Lukuv 4X2e3sQjWUn0D3g+IYLevSlIVIwk5MnlAFhhKPPw4bl9YN6BxT0Q1hWLb/ZANuH85Hoo +It6DoT2oQAkxU7n5Q87Gpgl9cp7h47yaBTesFo0nuwM/47pCqvB7AKJTM+nesVlwePM /akw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ein/Nby7sgDLTA7uxbc+atuaNBKVCQldTuDobTGDHS8=; b=TPEff/oTeC/gN40nHa/2MA5MbL4PUdT86x7nLsFBYA4vAao0kKWuSi1TZg6fnbivA1 lDGMjPaqZFIdhdzZoRC92TxUu5LL39GGOp2/dyIC0vhq6bNxHSSifhQ0uVznWtwxV1hC 39UrfOyGYV2Ph7pcJ30+JXQXtLpvtoFXtG2cEf3T1qPOFOmY8xLjzT5oOxUcYf/JxSjX BpT5vV/o/pnKWaB1iF3FJliVwb7FXcIc83GxRzKnumJ0UBFUZC6byH1S3yI5AfQkVw/X 02zI7tqcLVho7TmN/DWv/HYD0tsMtsMqaa47eqTD/0WLBPpU6TQsERCF+GKWtuWR9uj0 HU1g== X-Gm-Message-State: AJaThX6Gi7KH0/8F/7YZmd6SrsuO9jQ9Z7gefTkupenxfPz4dicEKuUi 54KgQpe5XMm97Vjpbluv+Zlv5Q== X-Google-Smtp-Source: AGs4zMaQ+gYDUsiQsvgdMeOIEt3IYg7zqJ6oBTM875c+hIUy8fWwNKcE4Og9HBVolgEI2BuGVlicSA== X-Received: by 10.223.164.22 with SMTP id d22mr14432415wra.232.1512396241167; Mon, 04 Dec 2017 06:04:01 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id g7sm22794279wra.38.2017.12.04.06.03.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 06:04:00 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall Subject: [PULL 10/19] KVM: arm/arm64: debug: Introduce helper for single-step Date: Mon, 4 Dec 2017 15:03:39 +0100 Message-Id: <20171204140348.21965-8-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204135637.21620-1-cdall@kernel.org> References: <20171204135637.21620-1-cdall@kernel.org> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alex Bennée After emulating instructions we may want return to user-space to handle single-step debugging. Introduce a helper function, which, if single-step is enabled, sets the run structure for return and returns true. Signed-off-by: Alex Bennée Reviewed-by: Julien Thierry Signed-off-by: Christoffer Dall --- arch/arm/include/asm/kvm_host.h | 5 +++++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/debug.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 242151ea6908..a9f7d3f47134 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -285,6 +285,11 @@ static inline void kvm_arm_init_debug(void) {} static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {} static inline void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) {} static inline void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu) {} +static inline bool kvm_arm_handle_step_debug(struct kvm_vcpu *vcpu, + struct kvm_run *run) +{ + return false; +} int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 674912d7a571..ea6cb5b24258 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -370,6 +370,7 @@ void kvm_arm_init_debug(void); void kvm_arm_setup_debug(struct kvm_vcpu *vcpu); void kvm_arm_clear_debug(struct kvm_vcpu *vcpu); void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu); +bool kvm_arm_handle_step_debug(struct kvm_vcpu *vcpu, struct kvm_run *run); int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu, diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c index dbadfaf850a7..fa63b28c65e0 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -221,3 +221,24 @@ void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) } } } + + +/* + * After successfully emulating an instruction, we might want to + * return to user space with a KVM_EXIT_DEBUG. We can only do this + * once the emulation is complete, though, so for userspace emulations + * we have to wait until we have re-entered KVM before calling this + * helper. + * + * Return true (and set exit_reason) to return to userspace or false + * if no further action is required. + */ +bool kvm_arm_handle_step_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { + run->exit_reason = KVM_EXIT_DEBUG; + run->debug.arch.hsr = ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT; + return true; + } + return false; +}