From patchwork Thu Nov 9 17:00:19 2017 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: 10051319 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 9BA5A603FA for ; Thu, 9 Nov 2017 17:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B3B22AFD9 for ; Thu, 9 Nov 2017 17:01:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FEE82AFF3; Thu, 9 Nov 2017 17:01:37 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 0161C2AFE2 for ; Thu, 9 Nov 2017 17:01:37 +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=VVwl3IvBttwzszjb+IDQvn9niTM2f7UPijE1DDx+4lY=; b=ZJRMkOn1Vdfh84 D0yZ8TI+8RKOO2cy7JY+Wof0JgWRN8WeRbKUlzeRB/lZlTGjPV5SXUBvEj33mwk9PBV/PLb1MzEDK 4mgr+6mWidYIMEBc+0Y3xOWOjf6u0MhhjZ2pj0+6mlKD/qErmefh67Biv4TuXP+zqnz1xa7Dd57kY EZ1tm5w2lMK75aWr99Bvw5Jz5aTl01dPyT5pfvtpDVTlyQX3FbcT/c5sacm+kZZRpzFd33V1JyquB mMsM7v4mKdwAp8GcHpEnZnx9zSynzugVvezzNgUCVR939BuR3DYWHmzrPUVA5f4ZFazKXDf0EgKHe 8iaXwbgZxxiGVSMeIbBw==; 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 1eCqCm-0002ch-Ib; Thu, 09 Nov 2017 17:01:28 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eCqC6-0001me-6i for linux-arm-kernel@lists.infradead.org; Thu, 09 Nov 2017 17:00:49 +0000 Received: by mail-wm0-x241.google.com with SMTP id b14so3314789wme.2 for ; Thu, 09 Nov 2017 09:00:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XIx5BIGLo7HnFAZHupTGZAVVsZz1nNYmnmudk/N+eFA=; b=dA4VEx/Ig/1mcZXysTAE0mMDeVcDb8B4x3uwlRTu1gJx8pyZHkidpNzJo6jEj/6Q1F 0eH9mD2Qdn+A3Y5HCNHJKkwIa4vYa2ODTcaZtvTrgX3/YgW+B/fLUzi5ptQgZkHYtIDP lcSPVyajiqlG+qM6TyKzF25xIWf0h9bmKvMwI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XIx5BIGLo7HnFAZHupTGZAVVsZz1nNYmnmudk/N+eFA=; b=rTCpvU0D2cU4LpQSLLmke6b3Jdx3qqKRcjGFsPHzFfs2beyF0EW5A9kNrWz8YK0M4y XiVpMPq+5vmwqL2eJjEWy8oIzPTygQ6FMMxhhvL112kMGUDCt6q1CS/iWMD53Oso1JO+ C9Bguuk9xBaxF9p6JPFU2TTFkcCLiOzBdrWRGHwIS23ASM0La8Kc3+8GzuICMJbPiwhh NzqHCLvmvXz6P2nUD/Tc8OU/oo41TwfQa3UopG/0QOtrkyv4LWZ2swZ6gfpr0YwDDI9o N/nUpgCipSuL6I+GUtQdPCJyIxt2XbUKcv0MulmIhqbOGjOEWfBhRXOLWOv9XFDnHLpJ 1whA== X-Gm-Message-State: AJaThX7FzyrZuEsQJRG/mIgWXt5a+Ots2iS+Bs18Fn6yZxMYzCE2XXrr 9kw4YS+TJ0iLO05+ScIBtLONLA== X-Google-Smtp-Source: AGs4zMb4ey3x9GITrDdpM63Zd7rXq5gAWUd5Mso1rQkA8PoSy1snvJPWxA3nD2kZAz1HH8GZ1KB/VQ== X-Received: by 10.28.90.85 with SMTP id o82mr380057wmb.69.1510246824318; Thu, 09 Nov 2017 09:00:24 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 128sm8964755wmi.28.2017.11.09.09.00.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 09:00:22 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 35A053E01F7; Thu, 9 Nov 2017 17:00:22 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: julien.thierry@arm.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Subject: [PATCH v2 1/3] kvm: arm debug: introduce helper for single-step Date: Thu, 9 Nov 2017 17:00:19 +0000 Message-Id: <20171109170021.2984-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171109170021.2984-1-alex.bennee@linaro.org> References: <20171109170021.2984-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171109_090046_395922_E07F16E9 X-CRM114-Status: GOOD ( 15.31 ) 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: Catalin Marinas , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Russell King , Will Deacon , open list 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 After emulating instructions we may want return to user-space to handle a single-step. If single-step is enabled the helper set the run structure for return and returns true. Signed-off-by: Alex Bennée Reviewed-by: Julien Thierry --- v2 - kvm_arm_maybe_return_debug -> kvm_arm_handle_step_debug - return bool, true if return to userspace is required --- arch/arm/include/asm/kvm_host.h | 2 ++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/debug.c | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 4a879f6ff13b..a2e881d6108e 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -285,6 +285,8 @@ 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) {} 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 e923b58606e2..bbfd6a2adb2b 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -369,6 +369,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..95afd22a4634 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -221,3 +221,25 @@ void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) } } } + + +/* + * When KVM has successfully emulated the 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 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; +}