From patchwork Wed Nov 22 17:07:46 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: 10070663 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 809CF6038F for ; Wed, 22 Nov 2017 17:08:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69D9329DEF for ; Wed, 22 Nov 2017 17:08:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E8FE29E0E; Wed, 22 Nov 2017 17:08:36 +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 D4B5C29DEF for ; Wed, 22 Nov 2017 17:08:35 +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:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=tiWh1zIDJ8bogU74IiCOWPTpavfu2p7qEgH/Ws4DZ30=; b=lNIiNIngpNuv5Z g1FgrXHBFkYdDlz0ofqa9c8O6i3zWj7ML2f5HY1pHDi5lPrwroW+CRYajCFlzBFas4r7D4g4cPUw9 sWF0m9iVgOC3/g0HJntEdam06emVxuIeRAUv2nYI9sdSRpo+eV2rpX8TtBVgBG6fDEMm6BiXmQoM1 Bdy7klfxSSe2pZFW8FHnAP2t3o1VmbHm9li9BfkQXzJVeynU1dwb4gMK5DS5W1d63GpWOzvbqwh9G NTPlmWoQqXGCg8Agg82yoFUBqSVnsHSWdI4rbqnmPPSnaZboWelrhogpNcphymKZTai9Brvqh2t+M 5WlsW32F9mH+WK4yy9eA==; 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 1eHYVg-0003CH-05; Wed, 22 Nov 2017 17:08:28 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eHYVT-0002zo-5Z for linux-arm-kernel@lists.infradead.org; Wed, 22 Nov 2017 17:08:17 +0000 Received: by mail-wr0-x243.google.com with SMTP id a63so15155614wrc.12 for ; Wed, 22 Nov 2017 09:07:53 -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:mime-version :content-transfer-encoding; bh=Qp54BFdBCzBZ7SGgJL60HNSwUjNz9s60Ymc1KvsGmbE=; b=VEhSI0BJAXO/dqnBVafGlptQ1L7Ot8q5C/Yq8pGam65TpS66QoKlW7qboJWSYQ0WWS YzbrF/xIfodpmcHlRmWfReh6e/HJPlCgOvEpEDnvL09ScTScS93cnmWIK8vSV2dwfcsP 3+hoLoFSbuKwwfIrW1xKXdTEYC/O61kLbl7zg= 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:mime-version :content-transfer-encoding; bh=Qp54BFdBCzBZ7SGgJL60HNSwUjNz9s60Ymc1KvsGmbE=; b=FB6JCHThajJM5R/kbE5IYF5VLkWAvSqBsVuGk5+sFz4VmgjfjO186Z2wiDNbWVL1PO 2g0MCwLL74orl5OicgmJegIFWaPn5QDB/bTqL40QbJme9Fozs0i+uTjye3Nl4+xkeGxk e49B/X1IOEi4a0KwS5Zo9g17yD7wmKwLxFvWhd/2NWjGLEihgUuyfTU4C8bPZXsD4cxo ShxKEGhZuXSCN3zhyTFJSP0zwhotE22TY2pS1sQxUNZWmFYfdwGNL1suI34ajZS1WSx1 xn6Y7ESOA7lj5ZJ37w0OVMmHrhGR0c/rz5S1Q5pzAeDQ4H4PR6kA2qRaaJz0y+9qr60p mQxw== X-Gm-Message-State: AJaThX4uzWd8TE4EZAlUuWuNrptPWkKX243QiFaFLd0Ymik81xklrae+ RmPbZ/AB620epWBT4Tj+9Bkvnw== X-Google-Smtp-Source: AGs4zMaozOF0B4JYd176cPje4ia773qHasrQiG02lVBzUOPbOXjTe0FKouopJ246PzsZyI+F38Jrwg== X-Received: by 10.223.145.35 with SMTP id j32mr18154324wrj.176.1511370472479; Wed, 22 Nov 2017 09:07:52 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id r14sm7069458wra.71.2017.11.22.09.07.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 09:07:51 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 250EA3E025C; Wed, 22 Nov 2017 17:07:51 +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: [RFC PATCH] kvm: arm64: handle single-step of hyp emulated mmio instructions Date: Wed, 22 Nov 2017 17:07:46 +0000 Message-Id: <20171122170747.12192-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171122_090815_395585_FE3D1FED X-CRM114-Status: GOOD ( 17.17 ) 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: David Daney , Catalin Marinas , Will Deacon , open list , Eric Auger , James Morse , =?UTF-8?q?Alex=20Benn=C3=A9e?= 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 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. For the case of an emulated illegal access causing an SError we signal to handle_exit() by clearing the DBG_SPSR_SS bit as would have actually happened had the hardware really single-stepped the instruction. [AJB: currently compile tested only] Signed-off-by: Alex Bennée --- arch/arm64/kvm/handle_exit.c | 8 +++++++- arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index af1c804742f6..128120f04e0e 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -28,6 +28,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include "trace.h" @@ -242,7 +243,12 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, return 1; case ARM_EXCEPTION_EL1_SERROR: kvm_inject_vabt(vcpu); - return 1; + /* We may still need to return for single-step */ + if (!(*vcpu_cpsr(vcpu) & DBG_SPSR_SS) + && kvm_arm_handle_step_debug(vcpu, run)) + return 0; + else + return 1; case ARM_EXCEPTION_TRAP: return handle_trap_exceptions(vcpu, run); case ARM_EXCEPTION_HYP_GONE: diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 945e79c641c4..a6712f179b52 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -22,6 +22,7 @@ #include #include #include +#include static bool __hyp_text __fpsimd_enabled_nvhe(void) { @@ -263,7 +264,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 +281,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,13 +349,21 @@ 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) { - /* Promote an illegal access to an SError */ - __skip_instr(vcpu); + /* Promote an illegal access to an + * SError. If we would be returning + * due to single-step clear the SS + * bit so handle_exit knows what to + * do after dealing with the error. + */ + if (!__skip_instr(vcpu)) + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; exit_code = ARM_EXCEPTION_EL1_SERROR; } @@ -357,8 +378,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 */