From patchwork Fri Apr 5 13:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13619056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20C2ACD11C2 for ; Fri, 5 Apr 2024 13:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date: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=tw5pZ0CQtWm1dONZFz8C6uHPEQJzZjhM0++rDObExFI=; b=1Yu/fPaYrPJpJO p/qo5zbZ0VrZRKT59B7owuPccNBV2l8PUfwZxMcVLgzO0K3sBVy6bsIcenHm5cO5ZNQIgo6yTMV7S Oj8K8Ayg25uxMGwtY5WUsi2TIGlvehgVxtBUWCCW3NffwCACoZX0GmG0Z16vwRKXrHvBvrMVrsxxp wn8KdHz1U4UNMwv3GE7a+mOErTrBP5xeqyejfg9qr9ui6ZDICmg5Q9mnSYm9035ppvdBGALeB+lc3 1aZWeAZUcmrVtk88YnHX6J8jb5G1vngDoi85cDYNrAdKomh+jkfhipnet9qZE0dffV2wl+7Ggp+Nz tY7gxqWqNbrjt8r2isgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsjHv-000000078aK-2gzD; Fri, 05 Apr 2024 13:07:23 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsjHs-000000078YP-3ROP for linux-arm-kernel@lists.infradead.org; Fri, 05 Apr 2024 13:07:22 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 872B7618F6; Fri, 5 Apr 2024 13:07:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13B55C4166D; Fri, 5 Apr 2024 13:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712322439; bh=EYf9aJVWWapg+rOs2VOwVmeQbQXK+25yKMQolondcvo=; h=From:Date:Subject:To:Cc:From; b=T4FcA2sEJ3X0TSwn3M1+mGADP1xvuwfDrCrlzpdPmRMmsg2rEtGvEwkw/aLJc2c+u rtt/qI5ICDYPuMgzdfHiR6YCrviNrOysvPjscn8S5m850ZESQjP7UkS4HefrJFghoL IYXnvZwUdIHbokNse/RnpXFQ6RdjJ4nO9gZn4eW2Q5Y4nrVRENVWt3d5uzAEF+kdLu PeqXTVuPqX195bxg4cvPArbSrRKmO231FMIngqYCNjX2CrAFsXJBOi/DEo6HdmH+8W jSXSAFBTBe2P2YQyTElYfwliC3azFn0+1sX+gZjcC3oacRPnq8i5iMqj2iVBOHIJ6v sqk9sv1km+jhg== From: Mark Brown Date: Fri, 05 Apr 2024 14:07:14 +0100 Subject: [PATCH v2] KVM: arm64: Document why we trap SVE access from the host in nVHE MIME-Version: 1.0 Message-Id: <20240405-kvm-arm64-nvhe-sve-trap-v2-1-a179da25ee34@kernel.org> X-B4-Tracking: v=1; b=H4sIAIH3D2YC/3WNyw6CMBBFf4XM2jH2QaOu+A/DoikDbZBCpqTRE P7dSty6PCe5526QiAMluFcbMOWQwhwLyFMFzts4EIauMMiLVEKKK455QsuT0RizJ0yZcGW7YG9 qq7pOG2sslPXC1IfXUX60hX1I68zv4yiLr/01pfjbzAIFKiXJudr05qabkTjS8zzzAO2+7x/vu q2QvwAAAA== To: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Cc: Dave Martin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2265; i=broonie@kernel.org; h=from:subject:message-id; bh=EYf9aJVWWapg+rOs2VOwVmeQbQXK+25yKMQolondcvo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmD/eD0zTvKa3D86qnQSr+XkOhX1FPfd2oKxzOugwx ZkeA2JGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZg/3gwAKCRAk1otyXVSH0AmvB/ 9B5FqSRCIYIwoRkZL7zuAdbWUckXWCiiQjiVU2NUg+Jpbj+OjnL1J4iVD8DTREsLl9WKen1ofSsz7P x64X2WUI/lhQTO5TBdAJ80dBeXXo9gSP+4As+ljSJXwKzcf977CHw0MhMmqQg+ibIv+yxM8IIFCjZI af6WEPkj2+1/NLo0Vh7f9jd+W8GKOLzfuWEZptDURS0zCQms6ldUBPLKfGr+kmZRb+FL9CLpz+yLxM nMKDx4vBTZQX1CA7p7cWPyH1RZp6xoTJWQWD+7PwL1LsYz14A9gA+bih+tvpZFItTBJdmv86NQBppy HB6TN/F27mgA+VmbqKtA6UIVK3t3Vg X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240405_060721_073948_99F9F313 X-CRM114-Status: GOOD ( 11.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When we exit from a SVE guest we leave the SVE configuration in EL2 as it was for the guest, only switching back to the host configuration on next use by the host. This is perhaps a little surprising when encountered in the code by itself, add comments explaining what is going on both in the trap handler and when we configure the traps. Signed-off-by: Mark Brown --- Changes in v2: - Rebase onto v6.9-rc1. - Link to v1: https://lore.kernel.org/r/20231221-kvm-arm64-nvhe-sve-trap-v1-1-332ecc56f694@kernel.org --- arch/arm64/include/asm/kvm_emulate.h | 2 ++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 1 + 2 files changed, 3 insertions(+) --- base-commit: 4cece764965020c22cff7665b18a012006359095 change-id: 20231218-kvm-arm64-nvhe-sve-trap-f65a3dd46a6a Best regards, diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 975af30af31f..68a5c7b380a0 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -587,6 +587,7 @@ static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu) } else if (has_hvhe()) { val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN); + /* Leave traps enabled, we will restore EL2 lazily */ if (!vcpu_has_sve(vcpu) || (vcpu->arch.fp_state != FP_STATE_GUEST_OWNED)) val |= CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN; @@ -595,6 +596,7 @@ static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu) } else { val = CPTR_NVHE_EL2_RES1; + /* Leave traps enabled, we will restore EL2 lazily */ if (vcpu_has_sve(vcpu) && (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED)) val |= CPTR_EL2_TZ; diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 2385fd03ed87..84deed83e580 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -420,6 +420,7 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) handle_host_smc(host_ctxt); break; case ESR_ELx_EC_SVE: + /* Handle lazy restore of the host VL */ if (has_hvhe()) sysreg_clear_set(cpacr_el1, 0, (CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN));