From patchwork Thu Nov 16 15:39: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: 119053 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5734438qgn; Thu, 16 Nov 2017 07:39:35 -0800 (PST) X-Google-Smtp-Source: AGs4zMZdeVrney6ZwhjZsuLfnVF/LjydYPDyIIlpHA/+PYZ0kL37LGWMY9cYJXEYc7Fj+lDIkzIk X-Received: by 10.98.186.13 with SMTP id k13mr2267467pff.166.1510846775705; Thu, 16 Nov 2017 07:39:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510846775; cv=none; d=google.com; s=arc-20160816; b=dVBysjVMhjzYqUuUudmhJK2U8OHdysYCZZc5CtbSOZYdanpXPW12D7GbWl++A4uv0C Y3rdmDtaK22cPkbP3apGeP3vsOj9t5k2KTCDMTxntjg8AAncNmRKpPbDFF8BmlEwsN3B ZiiRspWYlw8lVCO9MhXi2KTv2jRxTtWyd2mqCwuuBq9pOAvYUmPeyvs49pVZSzqLbyXc mAhszZct15xOB2utcqqJmH5RLhxECwAr6IzS+gAsy34yGym2jIizRwPcDVHReVJjUpe6 V3AaaalYUZl3iuJnHCQnnBfgD5s6mMOo/RIXv2kTcRTV4lifVetXCM7hZE4lEFNMmmFq ay0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=5fi3uEl+4MxzbaZ2+bcLcHw5MtrOENCEb4BKCKASycs=; b=WKlk10C8epcuBv8ZqW+XiPTvBvEkicl70Eg2WnMgcjOBqEb9Sz3G/vE8iN/E5ffRgR PM3PmgRuNv+tqwV8MypYQ0PSmsFUnIu/PqOT0QnbYyye0u2Sdm2SeCyV1LdiHTjZKyFF 5wPLirhDgImBSUdvSGeLzbn2Z1ScrJexGi6dydz8U4DUeIrxiGeOpfGZOQwGEiNZFLlm mj8qf2q2YWQHfMxKwpb6a0Lo5CObG2fooH16aQdKrnrvn+9e3thxMg29YEAeaSR7S1VO I2HbPdUDhbo13M4a6fx1A0fPyX4t0e6BsTLUJq+BKzKeZ5uqnr4BzPjatDDAFIDadSjH 1BVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S5y/KGhw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si1156918pfx.313.2017.11.16.07.39.35; Thu, 16 Nov 2017 07:39:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S5y/KGhw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965229AbdKPPjc (ORCPT + 28 others); Thu, 16 Nov 2017 10:39:32 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:39202 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935613AbdKPPjZ (ORCPT ); Thu, 16 Nov 2017 10:39:25 -0500 Received: by mail-wm0-f65.google.com with SMTP id l8so1038885wmg.4 for ; Thu, 16 Nov 2017 07:39: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=5fi3uEl+4MxzbaZ2+bcLcHw5MtrOENCEb4BKCKASycs=; b=S5y/KGhwsn5kK6KOLeGGZaBRfOas4zfGst1G9ploRJA49OSjwRMiO4LObiVNJYHcxC 667CmW840UyWArvA2+adMUELNh+f1gOHhcplGH7pJ9NoFulrl6jCUBFEt/RAu4Ea3XWH 87sRJAEDYbIjF7CPtoH2Bni+YS4ZZj0oPi+FQ= 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=5fi3uEl+4MxzbaZ2+bcLcHw5MtrOENCEb4BKCKASycs=; b=L1m5824KukIV7vqdfsUypxyRvV3tIi6mhTObcDVYa7z6e8EJh6XrYq5h78+WbRbNrP Y/vlaT3ADsBDG0AKOnmNFgcCTty5oKCpVfxm2HiXT5mN34qGieP9VpthYD8oYP4eWM0Q 20itXvN0re9MW8O5hQ4oHurpqgu4oAlLdZRmH+HuixFlHPGswYFD0Wv0AVVmoak46O60 RWW0MUjmVKfonqgAMn2WmvEIzBQ1GZIYrJM0mJ4nzybjTBJIQITbVHKiVpeD4fwKZKR5 uh+nSYvIyIhY1wjI+DTzmdEY0T7t+keRDoVD4WFAM/UVtOo6uDF72oejQgE/C7iuElW0 /quQ== X-Gm-Message-State: AJaThX4hGlRFe5ZMAUicqNxCa3hVVBek9vkokgYvjPHbIPheBC9wZYJE jp0AFVBSaSCbQsb14NIxMpH+8w== X-Received: by 10.28.225.87 with SMTP id y84mr1943247wmg.68.1510846764358; Thu, 16 Nov 2017 07:39:24 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p28sm3677373wmf.2.2017.11.16.07.39.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Nov 2017 07:39:23 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0B5C63E03EC; Thu, 16 Nov 2017 15:39:22 +0000 (GMT) From: =?utf-8?q?Alex_Benn=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 Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Russell King , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 1/3] kvm: arm debug: introduce helper for single-step Date: Thu, 16 Nov 2017 15:39:19 +0000 Message-Id: <20171116153921.21991-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171116153921.21991-1-alex.bennee@linaro.org> References: <20171116153921.21991-1-alex.bennee@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 5 +++++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/debug.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) -- 2.15.0 diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 4a879f6ff13b..26a1ea6c6542 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 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; +}