From patchwork Fri Oct 6 11:39:20 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: 822365 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lzVtMTci"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="hWX6ybeA"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7nk42xfTz9t41 for ; Fri, 6 Oct 2017 22:39:56 +1100 (AEDT) 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=0GLFbWztITL4qtBjJJfc3GeX/H8GxLTObw0SdqXhqLI=; b=lzVtMTciaNVO7Q QidN2r0dDCazKrbH819xLlOS29hcyBqlBlO02nnIct3LTzBeJFBVSafHWXvBGfoAY+pt0IKWuuMLg t1ejR2GLhkAoMuxHJjcO4Y6t+6r+TqTqdFXJ+qbnzeJ53sNHmqjsFe50I1aIlM2Capn4/XuNYiw7T jxO+qI51CPP6lU4YGi9Xg6RKgs+VFvI4SNQOBv3bQJbe3IgU2566LHAsjE8MdPEun3aoqT9tKHWkK nIVshvj6yFnARnrUxgxNalN6Ep2lMhoNYlihtCko/g+3Q4pJgTzVBhCgAgb0mf/j0vdO0jhz0So6K 9uzFS3RuQxmKMdAQuARQ==; 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 1e0Qyt-0002WI-3x; Fri, 06 Oct 2017 11:39:51 +0000 Received: from mail-wr0-x229.google.com ([2a00:1450:400c:c0c::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e0Qyo-0002Sc-Gk for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2017 11:39:48 +0000 Received: by mail-wr0-x229.google.com with SMTP id z1so4040987wre.3 for ; Fri, 06 Oct 2017 04:39:25 -0700 (PDT) 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=UwKuQC/yk7g/K15Qz0LbymMDwJ+ks4gf80Kx2AJkLyY=; b=hWX6ybeAx+1+lTdHpEDsW9uC4IF4YdzA7Ek45g4r+kJqJwgpc5FELEf2AHMN4bnzY/ IBOegnAwojwP9UDP/jV+2M00w5ow1IIqtmuKRorFDTp9QkFIUl2pV3PvZ8wOrnGNybfn /Psv3iebyz18sX5SXSyYjRbcjEX3aGXM5kE4s= 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=UwKuQC/yk7g/K15Qz0LbymMDwJ+ks4gf80Kx2AJkLyY=; b=fDPtUqmb7e2/hAJ+gJXl6K5Pa5aNg05/m8WBE5ztPdxqPDZQ1jCJ4iuPUV1OzFQYzm T7k5ouMKkvviWs1l32gbhBnCWTswxDgnWpubGm4WzAj//IuLDnyaL55o1ZvR9QldQ5BD OHskfmVeEyIdmdd+eCLfWaitR5qb2EVNy8qBebMRhPgX5d5t5Fx+UgY/ykJv1Z4USxLx SvOAGEiD0cGd3YgRupu1ZAA+Ta3ondP1idck2DddG/5GdlyuJCoqLp0OYOb4PPa8qfir e92GFUevODafmegeaxAcTGzjCToCY37OfM2pkYkD8SlcIZcIMDBIPsZwyfoHmhOvkpX7 Tvjg== X-Gm-Message-State: AMCzsaVEJvjA0bWvGKSSHMdrJT8sO1C5BUxToc7bYRFw8auRaur3rZlo EYcgrT4EZm5r5F9sxH4ydtbg/Q== X-Google-Smtp-Source: AOwi7QBMKIAxc7e36w2r7R+yvbPS9T4ZY8zvC7yOeiJsK6JER/ZnFNd9zdqXkfNB9/ZW2oHxhkoDjw== X-Received: by 10.223.131.4 with SMTP id 4mr1898341wrd.106.1507289963681; Fri, 06 Oct 2017 04:39:23 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k141sm1503463wmg.15.2017.10.06.04.39.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Oct 2017 04:39:21 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 86E8B3E04DE; Fri, 6 Oct 2017 12:39:21 +0100 (BST) 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 Subject: [PATCH v1 1/2] KVM: arm64: handle single-stepping trapped instructions Date: Fri, 6 Oct 2017 12:39:20 +0100 Message-Id: <20171006113921.24880-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171006113921.24880-1-alex.bennee@linaro.org> References: <20171006113921.24880-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-20171006_043946_723708_9FF0F3AD X-CRM114-Status: GOOD ( 16.49 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:229 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , =?utf-8?q?Alex_Benn=C3=A9e?= , open list , Will Deacon Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org If we are using guest debug to single-step the guest we need to ensure we exit after emulating the instruction. This only affects instructions completely emulated by the kernel. For userspace emulated instructions we need to exit and return to complete the emulation. We fake debug.arch.hsr to contain ESR_ELx_EC_SOFTSTP_LOW so QEMU knows it was a single-step event (and without altering the userspace ABI). Signed-off-by: Alex Bennée Reviewed-by: Julien Thierry --- arch/arm64/kvm/handle_exit.c | 48 +++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 7debb74843a0..c918d291cb58 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -178,6 +178,39 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) return arm_exit_handlers[hsr_ec]; } +/* + * When handling traps we need to ensure exit the guest if we + * completely emulated the instruction while single-stepping. Stuff to + * be emulated in userspace needs to complete that first. + */ + +static int handle_trap_exceptions(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + int handled; + + /* + * See ARM ARM B1.14.1: "Hyp traps on instructions + * that fail their condition code check" + */ + if (!kvm_condition_valid(vcpu)) { + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); + handled = 1; + } else { + exit_handle_fn exit_handler; + + exit_handler = kvm_get_exit_handler(vcpu); + handled = exit_handler(vcpu, run); + } + + if (handled && (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)) { + handled = 0; + run->exit_reason = KVM_EXIT_DEBUG; + run->debug.arch.hsr = ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT; + } + + return handled; +} + /* * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on * proper exit to userspace. @@ -185,8 +218,6 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, int exception_index) { - exit_handle_fn exit_handler; - if (ARM_SERROR_PENDING(exception_index)) { u8 hsr_ec = ESR_ELx_EC(kvm_vcpu_get_hsr(vcpu)); @@ -214,18 +245,7 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, kvm_inject_vabt(vcpu); return 1; case ARM_EXCEPTION_TRAP: - /* - * See ARM ARM B1.14.1: "Hyp traps on instructions - * that fail their condition code check" - */ - if (!kvm_condition_valid(vcpu)) { - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - return 1; - } - - exit_handler = kvm_get_exit_handler(vcpu); - - return exit_handler(vcpu, run); + return handle_trap_exceptions(vcpu, run); case ARM_EXCEPTION_HYP_GONE: /* * EL2 has been reset to the hyp-stub. This happens when a guest From patchwork Fri Oct 6 11:39:21 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: 822368 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NSyY3tvk"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kSijtQCR"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7nsm1kTgz9t41 for ; Fri, 6 Oct 2017 22:46:36 +1100 (AEDT) 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=GvNBsPpz3UXLPgsC9NPVA7SslUyZ2yYxec8ezJxeFiE=; b=NSyY3tvkXulhHz hMigrAs5eLcNbiFwIYwbbDVNhwuiRa9hLpK82Co3y5tF/05vmC+AiLXiG69rVu0PS4mIlGnaQ8ks+ ELHuemrgOnqYRwwEoo/72ExHJ+0XwWdwUQIeVydraM8mQ/J/XEdjzcMVWWGVXT59cvyIVmC6U7tQE o5g+Aw15MyTUo+TLvzKSktblHL4u8ct9ZCg8CZoOCDXiowx/rKnG+bIKpgh1NVAfQ4GAJCC6ex7F5 D8wyRKwrJPYLjJu3YVlg196YHTx47Jl2YY+YGC+LWVBKKs6ja7Ey4OfOzXzcyqDraBBrAcRJ3l+/1 l8aV91BtpNB6/uuVNDcg==; 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 1e0R5J-0006GE-EO; Fri, 06 Oct 2017 11:46:29 +0000 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e0Qyo-0002So-R8 for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2017 11:39:50 +0000 Received: by mail-wr0-x234.google.com with SMTP id u5so12678639wrc.5 for ; Fri, 06 Oct 2017 04:39:26 -0700 (PDT) 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=HYF7hHobPSSuQ8IJMTfxPpGY1uEg67AuQE03qJbobuE=; b=kSijtQCRzN2WAcXmBVwdlIHUgR563lok3GQqScibHfByxEBI4q89gVDreIyx35XV6E oRLesUjpCnM6Dk+VAo9C7auA/q4kac0eKXX/54puZsmB1HPyACo2Jk45CUKp10uFz1/Z maaf+UV0YfpDUn8DjIdOP/LOASQ+BldzLlb8E= 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=HYF7hHobPSSuQ8IJMTfxPpGY1uEg67AuQE03qJbobuE=; b=TcAJTQE1QfbXz5qnILe8pXpkVuOiyIfEklLtkbj6NNKshXn9EmLAlzGDYFSN8JLn4u KXPktCe4zM+RRRpXWc9/OgDBvT10KGWz0D1nYeGxn1aQnZ58yasTwOgL3gDv3T+FmxQs qskrZ11baFJxY6vV6l0f/DR2/wuLe7P3URNmsblraCOno7Sea6xCjv2qUP+PamPBIFWd WR5jd1ZhoAKRSSoKYzZpou4BLvHTX2OVTX+hBGkI0MdJ4BzTFFdb9GqV7/f5hCV4NZMX 7pRmnak290WfTvpmNwDh+oGVX0fTEywV/VbcqzguRwyFY5Dq09bBRjnabsX85gaqvPxG D2aQ== X-Gm-Message-State: AMCzsaWkNB/CBoFrNHBuAj6d16z9B8WM0YrqmApI0ZM6r8BRd2TU8Ssk p+EU2efWL1wFUV8jBJWd5Z7Pww== X-Google-Smtp-Source: AOwi7QCqWCPXmcMu+Yd0GjXFiU++3I8aEz/V2sRHKYDQc8Py7hxeWXG9oKeGT6V8qbcQS28AdsKRvg== X-Received: by 10.223.142.45 with SMTP id n42mr1656732wrb.278.1507289964704; Fri, 06 Oct 2017 04:39:24 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w62sm1119448wmb.32.2017.10.06.04.39.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Oct 2017 04:39:23 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id CBDA53E07E1; Fri, 6 Oct 2017 12:39:21 +0100 (BST) 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 Subject: [PATCH v1 2/2] kvm: arm64: handle single-step of userspace mmio instructions Date: Fri, 6 Oct 2017 12:39:21 +0100 Message-Id: <20171006113921.24880-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171006113921.24880-1-alex.bennee@linaro.org> References: <20171006113921.24880-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-20171006_043947_029059_48C75307 X-CRM114-Status: GOOD ( 18.82 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:234 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , =?utf-8?q?Alex_Benn=C3=A9e?= , Russell King , Will Deacon , open list Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org The system state of KVM when using userspace emulation is not complete until we return into KVM_RUN. To handle mmio related updates we wait until they have been committed and then schedule our KVM_EXIT_DEBUG. I've introduced a new function kvm_arm_maybe_return_debug() to wrap up the differences between arm/arm64 which is currently null for arm. Signed-off-by: Alex Bennée Reviewed-by: Julien Thierry --- arch/arm/include/asm/kvm_host.h | 2 ++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/debug.c | 21 +++++++++++++++++++++ arch/arm64/kvm/handle_exit.c | 9 +++------ virt/kvm/arm/arm.c | 2 +- virt/kvm/arm/mmio.c | 3 ++- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 4a879f6ff13b..aec943f6d123 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 int kvm_arm_maybe_return_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..fa67d21662f6 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); +int kvm_arm_maybe_return_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..a10a18c55c87 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) } } } + + +/* + * When KVM has successfully emulated the instruction we might want to + * return we 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. + * + * Return > 0 to return to guest, 0 (and set exit_reason) on proper + * exit to userspace. + */ + +int kvm_arm_maybe_return_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 0; + } + return 1; +} diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index c918d291cb58..7b04f59217bf 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -202,13 +202,10 @@ static int handle_trap_exceptions(struct kvm_vcpu *vcpu, struct kvm_run *run) handled = exit_handler(vcpu, run); } - if (handled && (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)) { - handled = 0; - run->exit_reason = KVM_EXIT_DEBUG; - run->debug.arch.hsr = ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT; - } + if (handled) + return kvm_arm_maybe_return_debug(vcpu, run); - return handled; + return 0; } /* diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index b9f68e4add71..3d28fe2daa26 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -623,7 +623,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) if (run->exit_reason == KVM_EXIT_MMIO) { ret = kvm_handle_mmio_return(vcpu, vcpu->run); - if (ret) + if (ret < 1) return ret; } diff --git a/virt/kvm/arm/mmio.c b/virt/kvm/arm/mmio.c index b6e715fd3c90..e43e3bd6222f 100644 --- a/virt/kvm/arm/mmio.c +++ b/virt/kvm/arm/mmio.c @@ -117,7 +117,8 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run) vcpu_set_reg(vcpu, vcpu->arch.mmio_decode.rt, data); } - return 0; + /* If debugging in effect we may need to return now */ + return kvm_arm_maybe_return_debug(vcpu, run); } static int decode_hsr(struct kvm_vcpu *vcpu, bool *is_write, int *len)