From patchwork Tue Nov 21 12:43:12 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: 10068027 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 7654D602B7 for ; Tue, 21 Nov 2017 12:43:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 692E829516 for ; Tue, 21 Nov 2017 12:43:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DE922951B; Tue, 21 Nov 2017 12:43:42 +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 C8F9829519 for ; Tue, 21 Nov 2017 12:43:41 +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:Message-ID:Date: In-reply-to:Subject:To:From:References:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UqYZSvi3hFFuLlVGAz9JDZHiHxHEv8eXZn6FxHlzRB0=; b=utMCJx6g6nd3eoFkJ+YG3MeOBg uCzFoc07MgyuAuaYYDf5MgeRqPvC2OF8ggfBEjdvjxZV4XBueBY1xMb7KPf58dMnqAHk8KCmPKLQe v1O5iR3P9yzS6GOh6uHDgj4plqgf1hXc8CjfJgIth0oIpf/xPtGB4seKA1M5TZ3jDkmm4tQShbKqj 2QY6NB/l7p6hoCKw/ffEJzt+53Y0Zb+qttIYwGPvzYnMkBBUVA+EIbvb0c4JgXmHLz8Ok1qMnjPqe q0ELfaXk4WQYlT9TxQ8hy3p9JQertYUCUeS/Z+XEAjf+xsSgCvUiNXHFshsIWsFAyj5q7P+ACrm9C Rayb9Q+g==; 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 1eH7ts-0005oa-IW; Tue, 21 Nov 2017 12:43:40 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eH7to-0005mq-Di for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2017 12:43:38 +0000 Received: by mail-wm0-x241.google.com with SMTP id l188so1298673wma.1 for ; Tue, 21 Nov 2017 04:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=E75ajD7Zjhx/WX2mUj/OmStKqGVQXbOD3m3qivw+0XQ=; b=gOnbX4Vtd9M5ytkoyZRmOKhZu/KFuQZtkhI7LmHxqOmI1LjsT0eC7UI1wDEGKpUcN3 YaNucjt/xntl0j0YPgdgtXRP1bQkKI7ColgGzfVHRsuim1NQQVcWHwLbsrNBpyR9C4VM kFUjZc+eQ5U0UmhP35T7azZAPE80O2/bZU5IY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-transfer-encoding; bh=E75ajD7Zjhx/WX2mUj/OmStKqGVQXbOD3m3qivw+0XQ=; b=gTr7NhLd2bTrUeBWLSTnC+bXOlyedURU6p2T4SodGexl+6dUjNIkPjWghfJJy2RrTo QqTs/bgqjceH29BiRKDH5wmXUsUMV52Ravm2RDI1MbcvB9SmDQuMSER74/azYl1bUIMY NQJ2wRKWatPGksFcNpcNTb0VUrpgS7139yoGMfOqWNMlESUPSr3IjLoZRpnr8AD7Zsva Lag5oxLuetGlgmCzq5G6EgKfoNfYKZZ2tpKdl383D+5EwY9nttfx9golWtSsFn97o18+ 3ej/qAAyKHyStsZq+Dmj1wPAFST3hOoFdpWPScfZpe+nooe/zcL90/roUgR20Rw4rg8u A4TQ== X-Gm-Message-State: AJaThX5bps/Z6Q3xR8bWyf42udQcdoAIaJPq2xdekymoYaPqzcqOshON IOpimZwCGqmiV7uVAyT0JzR31A== X-Google-Smtp-Source: AGs4zMYMMHyiJ1EurYiyr9m7wwQiqJBgPEjWkarjbH61EGIJa30zSxmeAb3CY4i12ZzW6bZu5NyEHA== X-Received: by 10.28.62.67 with SMTP id l64mr1167605wma.6.1511268193536; Tue, 21 Nov 2017 04:43:13 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o22sm30184838wrb.40.2017.11.21.04.43.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Nov 2017 04:43:12 -0800 (PST) Received: from zen (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTPS id 42A053E00A0; Tue, 21 Nov 2017 12:43:12 +0000 (GMT) References: <20171116153921.21991-1-alex.bennee@linaro.org> <20171120154131.GO28855@cbox> User-agent: mu4e 1.0-alpha2; emacs 26.0.90 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Christoffer Dall Subject: Re: [PATCH v3 0/3] KVM: arm64: single step emulation instructions In-reply-to: <20171120154131.GO28855@cbox> Date: Tue, 21 Nov 2017 12:43:12 +0000 Message-ID: <873757yf8f.fsf@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171121_044336_650228_ABBD742C X-CRM114-Status: GOOD ( 17.58 ) 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: kvm@vger.kernel.org, julien.thierry@arm.com, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org 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 Christoffer Dall writes: > Hi Alex, > > On Thu, Nov 16, 2017 at 03:39:18PM +0000, Alex Bennée wrote: >> Hi, >> >> This is rev 3 of the series, practically the same than rev 2 but fixed >> a return 1->0 in the kvm_run loop that Julien caught. I've added his >> r-b tags to the other patches. >> >> As usual revision details bellow the --- in each patch. > > Thanks for taking care of this. > > I have applied the series and slightly tweaked the commit messages and > commentary. > > Did we simply decide to not worry about exiting to userspace if we do > fast-path emulation, such as for the errata workaround and GIC > mashaling in switch.c ? Compile tested only: --8<---------------cut here---------------start------------->8--- kvm: arm64: handle single-step of hyp emulated mmio There is a fast-path of MMIO emulation inside hyp mode. The handling of single-step is broadly the same as kvm_arm_handle_step_debug() except we just setup ESR/HSR so handle_exit() does the correct thing as we exit. Signed-off-by: Alex Bennée --- arch/arm64/kvm/hyp/switch.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) --8<---------------cut here---------------end--------------->8--- diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 945e79c641c4..841dc79d11fd 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -263,7 +263,11 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) return true; } -static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu) +/* Skip an instruction which has been emulated. Returns true if + * execution can continue or false if we need to exit hyp mode because + * single-step was in effect. + */ +static bool __hyp_text __skip_instr(struct kvm_vcpu *vcpu) { *vcpu_pc(vcpu) = read_sysreg_el2(elr); @@ -276,6 +280,14 @@ static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu) } write_sysreg_el2(*vcpu_pc(vcpu), elr); + + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { + vcpu->arch.fault.esr_el2 = + (ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT) | 0x22; + return false; + } else { + return true; + } } int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) @@ -336,8 +348,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) int ret = __vgic_v2_perform_cpuif_access(vcpu); if (ret == 1) { - __skip_instr(vcpu); - goto again; + if (__skip_instr(vcpu)) + goto again; + else + exit_code = ARM_EXCEPTION_TRAP; } if (ret == -1) { @@ -357,8 +371,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) int ret = __vgic_v3_perform_cpuif_access(vcpu); if (ret == 1) { - __skip_instr(vcpu); - goto again; + if (__skip_instr(vcpu)) + goto again; + else + exit_code = ARM_EXCEPTION_TRAP; } /* 0 falls through to be handled out of EL2 */