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: 10061425 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 36A4A601AE for ; Thu, 16 Nov 2017 15:40:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 279FE2AA97 for ; Thu, 16 Nov 2017 15:40:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C0F42AA9A; Thu, 16 Nov 2017 15:40:43 +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 8B8502AA97 for ; Thu, 16 Nov 2017 15:40:42 +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=Pjf12K6Z1B2GeSJSd1fqj9nNgZJkfkHJjp+pdOenYfQ=; b=Z9VTKMRtSgz20e gGZRj3SU7mGoKvzsYHGO+8Gxv3C/iruNZfIL0iSYYNiTa91umTr2LVDPlmORtmf0X/aSp2DbHTJ1F meu1LU20OdzrDI9nA2miULth39AyySQvsp9QlJ4Pge4nJlm2tgS7peqGsNE7vyy5C0hvejeZHPb3K yXwmzv4NnyA7+fbOobp4I8gGINxYn66UbkIIyzufFiq5cyqJiQeKcY1YHkZNuqyTh279XqG14jd/4 dao41MB/TMaqusv73dMxkifLUZDLQRdeykKbbe1M/yLP6lVJeDjIOuAXq0DGEldZPsdq+SDYvWTyb yrhBv/7OvA1BWBsucXEg==; 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 1eFMHK-0003E0-BZ; Thu, 16 Nov 2017 15:40:34 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eFMGY-0001Pv-6c for linux-arm-kernel@lists.infradead.org; Thu, 16 Nov 2017 15:39:50 +0000 Received: by mail-wm0-x242.google.com with SMTP id r68so1096245wmr.1 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=PUHKgv5WCj58JoZRDgYj/cOypr7syprH8PLwmoRtzf9+CKoaylj05x4U+58t42kKgD yoGW+/4SlUiVBa7yfQy5c2q4AL3k6swWEXNdeWJRadgPu5HHFMcxJnm+Cp/K/6DUVMp2 KG8eTfMOpSff93UcFtos92l4HloXalsemOArNnkuomuOeGj2+LEvBSEKbiLOrVbHEqNH cxibaCpw0338S2hXETch5/RpJsTIkyY9FdVDm3JPjzN0EQQr0WDac478/9zYOTFekmNJ kWR3Wl8Sva7kJT/hkLclwXLpyVSAHLAhsh08Q7rlb0QF9Dpe10QXVfhQfcLX4Gghl37Z zrTQ== X-Gm-Message-State: AJaThX7KqevnB+edSFx1wW3HsdMA2KMLMiGbCEwbPc+I0Z14MA4z7jHP AJAEKWKF6kmPGXshJ+Jeg2eRWjiji3Y= X-Google-Smtp-Source: AGs4zMbvWL7R+u42puXSWY8J/RksmOMdsZFjnMFtn1YTsSTo7Ra26f2NXRkT2TjCaV4KRjP5mPN7Zw== 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=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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171116_073946_393725_2196C45F X-CRM114-Status: GOOD ( 14.32 ) 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 | 5 +++++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/debug.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) 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; +}