From patchwork Tue Jun 25 13:34:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13711168 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 A7D9DC2BBCA for ; Tue, 25 Jun 2024 13:37:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=28yg/DxOLzF7IRc2gGF/EnJuW5ADb/kwstOjHPUm5TQ=; b=Q5JlPH4erxbZ+m3j0NR9eYntwA 5GTxM6bG8MTQIBJZoXVZD/ckQ2W51WrhVOY9UfSiiR2xFdbl9T6OKdf1O6/1XGKs2cz3UKCAAqkge 1Li0kabOyGPboGGMpz+y3m8Rg9ClRSef/BVTs5M1xzaydFab+wKsMG3tORfHTntMVdhg6rxgYZFwM s6lIlYAIdgKDXQZcPoSYv8U6/L2AfhMihTFB/dJO6yDvr2tnPNmNJR/1BMsi4P/4mIFqUDlexeVet 6PVXkGnVkFRGIhKI5FiYaj6GxP1rLx2/XT7oVzO14PKUCXyj+SNipMZWLVuRbFjLDH7v8DWyxPvsd Cvn8rIVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM6ME-000000030io-0C2s; Tue, 25 Jun 2024 13:37:14 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM6KT-00000002zwh-1Ixu for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 13:35:27 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0A2F36146E; Tue, 25 Jun 2024 13:35:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2F74C32781; Tue, 25 Jun 2024 13:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719322523; bh=rIwXw3VVf63R+nYIyJ7imfCtCbeyIyaFBa507dbV90A=; h=From:To:Cc:Subject:Date:From; b=SYoQxZlb7i768hcHyWDjEAOGslll5Hzqq9r8jmfnCeLFcLMAfQdJ1063kb0amcZut qOPIl/8aT2/2sQpTouTqPCXrqSeVrriJA6DUEH90IR3qL8UQJKwSNNPgwLyA9oYfQ1 9QAe2Namfq5+e8k1Au1pp6QQKLiN/vGp9bMY7B0mq0GSxue+/VW3hXdayH86nq0X9D phISVgYI/zaIQTgsOABOOAxZB9PC5rT7QBhkzStV4m4vbIEphm+famj++ZEEUQe0Y/ kOVdxZy9/tY5FWdonMDrMsc9uriFjVzCPxHJ5CPoCrbZvo41Zng+0KreOhvVJoccXY DABlJjP7WfbVg== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sM6KP-007A6l-Pf; Tue, 25 Jun 2024 14:35:21 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: [PATCH 00/12] KVM: arm64: nv: Add support for address translation instructions Date: Tue, 25 Jun 2024 14:34:59 +0100 Message-Id: <20240625133508.259829-1-maz@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_063525_782851_E60CA27F X-CRM114-Status: GOOD ( 14.98 ) 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 Another task that a hypervisor supporting NV on arm64 has to deal with is to emulate the AT instruction, because we multiplex all the S1 translations on a single set of registers, and the guest S2 is never truly resident on the CPU. So given that we lie about page tables, we also have to lie about translation instructions, hence the emulation. Things are made complicated by the fact that guest S1 page tables can be swapped out, and that our shadow S2 is likely to be incomplete. So while using AT to emulate AT is tempting (and useful), it is not going to always work, and we thus need a fallback in the shape of a SW S1 walker. This series is built in 4 basic blocks: - Add missing definition and basic reworking - Dumb emulation of all relevant AT instructions using AT instructions - Add a SW S1 walker that is using our S2 walker - Add FEAT_ATS1A support, which is almost trivial This has been tested by comparing the output of a HW walker with the output of the SW one. Obviously, this isn't bullet proof, and I'm pretty sure there are some nasties in there. In a departure from my usual habit, this series is on top of kvmarm/next, as it depends on the NV S2 shadow code. Joey Gouly (1): KVM: arm64: make kvm_at() take an OP_AT_* Marc Zyngier (11): arm64: Add missing APTable and TCR_ELx.HPD masks arm64: Add PAR_EL1 field description KVM: arm64: nv: Turn upper_attr for S2 walk into the full descriptor KVM: arm64: nv: Honor absence of FEAT_PAN2 KVM: arm64: nv: Add basic emulation of AT S1E{0,1}{R,W}[P] KVM: arm64: nv: Add basic emulation of AT S1E2{R,W} KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W} KVM: arm64: nv: Make ps_to_output_size() generally available KVM: arm64: nv: Add SW walker for AT S1 emulation KVM: arm64: nv: Plumb handling of AT S1* traps from EL2 KVM: arm64: nv: Add support for FEAT_ATS1A arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_asm.h | 6 +- arch/arm64/include/asm/kvm_nested.h | 18 +- arch/arm64/include/asm/pgtable-hwdef.h | 7 + arch/arm64/include/asm/sysreg.h | 19 + arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/at.c | 1007 ++++++++++++++++++++++++ arch/arm64/kvm/emulate-nested.c | 2 + arch/arm64/kvm/hyp/include/hyp/fault.h | 2 +- arch/arm64/kvm/nested.c | 26 +- arch/arm64/kvm/sys_regs.c | 60 ++ 11 files changed, 1125 insertions(+), 25 deletions(-) create mode 100644 arch/arm64/kvm/at.c