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)