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: 10090395 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 AF56760329 for ; Mon, 4 Dec 2017 14:08:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 995F12858B for ; Mon, 4 Dec 2017 14:08:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D99A28812; Mon, 4 Dec 2017 14:08:10 +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=-2.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, URIBL_DBL_ABUSE_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 133DE2858B for ; Mon, 4 Dec 2017 14:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=joif9IPnD9/I8jDUXbHKkzx9k44fdtL1FpY0e5McxnE=; b=HoHnlIp+pdB1qb J9+fbmBdHfVn3XPA3ssZEAFprP4AeTapjvoBsXtPcI14/C9KBv09EAtMyVUOyXDfv9E0IBXdBieLm T4+8vrFDP0cZsTGZoU+hexyjwpGeG5qJ9kmnFM6U9hUBfPS0fVZRrTZ5Z5ItQ7mrRIMPuTPyuprlt 0PBBujkwChNO+8MHFn/KmwdyO3uqvRjpc0c05C+dBPfmyxfD15c9LWGF75uGeL6pS0ys6l6X/VA2Q jCN4oaEBG63HfEBIcVnTpcQ9FDNs6v5zLB9VI6lK6k81r43kaic7zxFrYILG9Nov54MXuLMfYuMDR 0J1h8cvvaK8VL58Mnfqg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLrPl-0007Pf-72; Mon, 04 Dec 2017 14:08:09 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLrM6-0002O6-LK for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 14:04:34 +0000 Received: by mail-wr0-x244.google.com with SMTP id o2so17413205wro.5 for ; Mon, 04 Dec 2017 06:04:02 -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=UhWrCMzy7B2r2xNBjTn+NthKVE/cN3x0qH4y3MZTG4/kVj9boW3Gz4rC/dizx3XxZx xBgD2syymsz2YS8XKgg5goet/9I5G2IrZ+Ocnc24DePw5HkipOwEwjR0Ojj2vOmA10n6 zOXonAu2unGNWZq6rS4ZFYS6850KH21gq8B1FCzP27sffZsu6TpKISQB8wmAotU4PcOS JUHkuhUZvxwH3tJ3RdtIhL9/4HWJ4Fc2CFk9LU92lbv7JywVlok7qr+NCIzWFuMBP2Ah t1Xc2lJiSep84FC/gpdkkzP9Xzqu5oQQH7DDPXpDan5baWF8CqCAYwl38tnnbs2eY8JP VYHA== X-Gm-Message-State: AJaThX4NG8sY9sxbX1ANV21l5bZ0FXcqnltIYrmGYe/JiIjtwverci0f XZv0a8QsYoG0lLE6F12vSivIpg== 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?= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_060423_636776_DFFE9456 X-CRM114-Status: GOOD ( 12.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Christoffer Dall , =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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; +}