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: 115055 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp1262986edb; Fri, 6 Oct 2017 04:39:31 -0700 (PDT) X-Received: by 10.98.214.17 with SMTP id r17mr2001556pfg.246.1507289970892; Fri, 06 Oct 2017 04:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507289970; cv=none; d=google.com; s=arc-20160816; b=HySkLV4t+/U7foAuwXlC7o326asB03mVaXkeK1c7nzDdQ9BroQKVJnl8nQwOpzN9O6 1a5u+s+HDGva4E1mHKr5UBrCd3TMj7Sc+6Rjupg2O/8srd3oC5wQbyHXfi9hJshbr9fa 79Ho3vAwMSpA6y91ykZV33Bn8Ao5vt5lritzwfBP71TJu+6ESMFRihq8vsUVyN6fTX7z 8h0w+D8IwbSO2YnoHuSn2GR/26HYw6XQZgrjCBcjZkgyIU3B1FDNXpEzjOX+RMIuvcNV 5rqqEmnJj5Qg4zVU3YK/dMaoRSni3PE91MvSJ4B/u3MCqvdSP0aTb/p7TJSZN80wCnKu x9gA== 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=UwKuQC/yk7g/K15Qz0LbymMDwJ+ks4gf80Kx2AJkLyY=; b=LeyE3Sh+IF6rAqIzqP8no7uvGFag3AEajNaEfZPH3d4a7eYYq9SQngFKCI1fQImMnL CmBkdRnjP+zCTCFQKkbpd5K62NYqWys44zJodxk9WH4Vi6jle53dX4cfQdztFeyB3EXy qSrCpLm9GQUwjGaGL0Qgb0T9fTWtUXoPyxvDos558LPpGx3LMWgQRgAjZWRiuoJeP8sF xbRT1sctyG6a0fCi4PIrYJf2iUziKVx+JYN95cCyx2mqQ34Ih70pUg+R/L+tbCmiLKSi KYHSL1vlP6NTQG7fCtdGR7JQE8ZljhtAmK9cajKlRg9/Wl2fokfT7s6H5m86SHhuMPZQ qv3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hWX6ybeA; 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 b1si1050591pld.697.2017.10.06.04.39.30; Fri, 06 Oct 2017 04:39:30 -0700 (PDT) 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=hWX6ybeA; 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 S1752083AbdJFLj2 (ORCPT + 26 others); Fri, 6 Oct 2017 07:39:28 -0400 Received: from mail-wr0-f182.google.com ([209.85.128.182]:55627 "EHLO mail-wr0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751774AbdJFLjZ (ORCPT ); Fri, 6 Oct 2017 07:39:25 -0400 Received: by mail-wr0-f182.google.com with SMTP id 22so1659962wrb.12 for ; Fri, 06 Oct 2017 04:39:24 -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=sPsDo5Oz/ujbAjeiR6ZPsR75Oj71ltP4YPXPC6JrIpqodllKS3msIj+er9gETbJ30p 9FvC2p9aGxiLidfN0JcMNsr4PrpC2pziP2Fp1VQ5k9ZevpiJw9OZyEJ41cu4sI28AnDX 7SfY2QFou4Lg2ofiJviAFviACrWaIr6F2m7TgGbp/JI98GKxNUvYIo2CiCvX6wtG7+K4 nAljJYfeqx4JaJ2Kda0PQcAwhAPlHTWtng8lRXMdM+YaV8Xi9KDUmEVrbPvnE9KPrVYC 4U11+R3fIHYBpT2Pq+xOV+FBqFoIYBN9kQmkH1Bh/FKxmLfveeXdFqwFIMZHr7DXcL7P SMAA== X-Gm-Message-State: AMCzsaVRVqPTXSn7rW0851P3eMlR60nG4PqBxIAcPnShl6q08SmXbrTf rw+qvwnqTuK3giGLUCu+myYJ6w== 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 Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org (open list) 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- arch/arm64/kvm/handle_exit.c | 48 +++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) -- 2.14.1 Reviewed-by: Julien Thierry 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: 115056 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp1263013edb; Fri, 6 Oct 2017 04:39:33 -0700 (PDT) X-Received: by 10.84.217.13 with SMTP id o13mr1743321pli.280.1507289973030; Fri, 06 Oct 2017 04:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507289973; cv=none; d=google.com; s=arc-20160816; b=IoKPy7288pnynMPfC1I6fZZQgMXz/Y5S++PJyPkxZPgDBPGhL15gkGuKb4PtHJgJZU 7XBtLSHdgCOWCmmwl0XH4C5qMf+ZcpmN0981lImgkYv0uiMzi5OdNOVMbupdDRgXBQdI fJOdqfZSx7Swumcfz9y0yji02zcfKNGHvE9zxlidyMXwaYB+RiGCkNgv78t0eT/MPGyn kyX512IMbdO/5DsM25PpJN5sodw6jVock7IPkoko1E5+n4mYMAKsSsJqAEFl93oNuXqC dAVy2Pp52jwL1bf1y1lGZHR+nYf149Bw3NcltwMnxga6oyHOx+JDI1hwuFZnrHvQ692F gjwg== 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=HYF7hHobPSSuQ8IJMTfxPpGY1uEg67AuQE03qJbobuE=; b=B2tSNZIBs1aOWznO8ZbXC3v4FU/oShWqwtunCmyMh0xYTjcheHrpofq6T7s9j3QMAp qOKN9hwJSIZXoF5PJkAVWIACiwyxoikE2hTViDlcdlv6b9tjVDk9bRkY+EDAbFNdeSGV Hg4MAnUuFp9wgBwu++HKnca/msScRxQrs/1wp6y8nLsTJJLC/wNkPX9/8NkJIVkvxyJC gBJJzQ4mRcQuKbdN9irKT3Z/Gr83DJa9PqiurrvHKG6G0rlGCy0NQYSC79wOmQCgKGoY Uw6iB0Ch9KckXkeRcblOM0TvUbJi0KuEAtoPNanTAB2FHXvbqpbYNDBe9PH6V5mG0SKp RNxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kSijtQCR; 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 b1si1050591pld.697.2017.10.06.04.39.32; Fri, 06 Oct 2017 04:39:33 -0700 (PDT) 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=kSijtQCR; 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 S1752122AbdJFLjb (ORCPT + 26 others); Fri, 6 Oct 2017 07:39:31 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:51516 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751557AbdJFLj0 (ORCPT ); Fri, 6 Oct 2017 07:39:26 -0400 Received: by mail-wr0-f181.google.com with SMTP id j14so12907853wre.8 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=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=rzFfd6yNum91shjEpoN0Qe1OCcOyQ0SSUqi22WKi0rLSEEFqizD/MhC/O6OukX6f7W rq2fA9OorzAfFNa3V/ehwZaNToef1ns/wbcgXx3Dv4XgmSeO66PUH2fbUU1W9os1JDtL MJCYjBgmzRrYaQCTXVv2278kkJJNhGTulTMEgG/GT6wjAfFW5iyDwMeSsLtGT71G8p5Q HhkIDNyQ3Vy4rcqljpQekTHnyXN41mUQEggRd7n9RMBbh6aB5tfAtlhjXBUjcGf9S0Ac PPFiBaCgfFNlOkwx1uFVlS59IbTkp2PE2mqeXjqstZFevmeM5WFpFa4B5JTsX2DoMDPy eqFg== X-Gm-Message-State: AMCzsaUmfT6TvOp2C1B8a7zw09U6wjcvnC07lu0R9hIw4sO7lYZKgsUH vCLFkZtSWiB2qnyAP9Lz5RD1zw== 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 Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Russell King , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org (open list) 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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(-) -- 2.14.1 Reviewed-by: Julien Thierry 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)