From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1741220995 for ; Fri, 26 May 2023 14:33:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB423C433D2; Fri, 26 May 2023 14:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685111633; bh=SF86W45rNNzwtS2zme2rgxuO0AM+zp3YypnP+jojmxI=; h=From:To:Cc:Subject:Date:From; b=C6df6TtKy9fZj8es0dK0LaNt6oH3kVNdlogV2vdjMxYh1/fgcpBgAXzhsXQBBhXq8 +YqdOG4xrcm8RsVETxr8ePgxN3IdXuvVQFL6Q1zrk/6/5ilqDgs8yGwjsbLk/rTeKS 6NJj/z8k3muJ0NbLtpGe90uDOgEvCqBAbb+LnjDtwvPHmZkjHOt0d/HdTHDHWoDotw rhAqxZ55hk6esfw4b9ZvwDXd8RVd/gL/18DkuHaVHvsNsojmgMsHuYtdQRt0/UxWk7 osTqwNVe9o3sTJbR/6UkyXkQaLcRv32Mh8zSwTlDS2IsDDn585kwWRgXgCHQA1tuPk KSz07o/a37Wkg== 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 1q2YVr-000aHS-Be; Fri, 26 May 2023 15:33:51 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Quentin Perret , Will Deacon , Fuad Tabba Subject: [PATCH v2 00/17] KVM: arm64: Allow using VHE in the nVHE hypervisor Date: Fri, 26 May 2023 15:33:31 +0100 Message-Id: <20230526143348.4072074-1-maz@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, qperret@google.com, will@kernel.org, tabba@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false KVM (on ARMv8.0) and pKVM (on all revisions of the architecture) use the split hypervisor model that makes the EL2 code more or less standalone. In the later case, we totally ignore the VHE mode and stick with the good old v8.0 EL2 setup. This is all good, but means that the EL2 code is limited in what it can do with its own address space. This series proposes to remove this limitation and to allow VHE to be used even with the split hypervisor model. This has some potential isolation benefits[1], and eventually allow systems that do not support HCR_EL2.E2H==0 to eventually run pKVM. We introduce a new "mode" for KVM called hVHE, in reference to the nVHE mode, and indicating that only the hypervisor is using VHE. Note that this is all this series does. No effort is made to improve the VA space management, which will be the subject of another series if this one ever makes it. This has been tested on a M1 box (bare metal) as well as as a nested guest on M2, both with the standard nVHE and protected modes, with no measurable change in performance. Note: the last patch of this series is not a merge candidate. Thanks, M. [1] https://www.youtube.com/watch?v=1F_Mf2j9eIo&list=PLbzoR-pLrL6qWL3v2KOcvwZ54-w0z5uXV&index=11 * From v1: - Fixed CNTHCTL_EL2 setup when switching from E2H=0 to E2H=1 Amusingly, this was found on NV... - Rebased on 6.4-rc2 Marc Zyngier (17): KVM: arm64: Drop is_kernel_in_hyp_mode() from __invalidate_icache_guest_page() arm64: Prevent the use of is_kernel_in_hyp_mode() in hypervisor code arm64: Turn kaslr_feature_override into a generic SW feature override arm64: Add KVM_HVHE capability and has_hvhe() predicate arm64: Don't enable VHE for the kernel if OVERRIDE_HVHE is set arm64: Allow EL1 physical timer access when running VHE arm64: Use CPACR_EL1 format to set CPTR_EL2 when E2H is set KVM: arm64: Remove alternatives from sysreg accessors in VHE hypervisor context KVM: arm64: Key use of VHE instructions in nVHE code off ARM64_KVM_HVHE KVM: arm64: Force HCR_EL2.E2H when ARM64_KVM_HVHE is set KVM: arm64: Disable TTBR1_EL2 when using ARM64_KVM_HVHE KVM: arm64: Adjust EL2 stage-1 leaf AP bits when ARM64_KVM_HVHE is set KVM: arm64: Rework CPTR_EL2 programming for HVHE configuration KVM: arm64: Program the timer traps with VHE layout in hVHE mode KVM: arm64: Force HCR_E2H in guest context when ARM64_KVM_HVHE is set arm64: Allow arm64_sw.hvhe on command line KVM: arm64: Terrible timer hack for M1 with hVHE arch/arm64/include/asm/arch_timer.h | 8 ++++ arch/arm64/include/asm/cpufeature.h | 5 +++ arch/arm64/include/asm/el2_setup.h | 26 ++++++++++++- arch/arm64/include/asm/kvm_arm.h | 4 +- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_emulate.h | 33 +++++++++++++++- arch/arm64/include/asm/kvm_hyp.h | 37 +++++++++++++----- arch/arm64/include/asm/kvm_mmu.h | 3 +- arch/arm64/include/asm/virt.h | 15 +++++++- arch/arm64/kernel/cpufeature.c | 17 +++++++++ arch/arm64/kernel/hyp-stub.S | 10 ++++- arch/arm64/kernel/idreg-override.c | 25 ++++++++----- arch/arm64/kernel/image-vars.h | 3 ++ arch/arm64/kernel/kaslr.c | 6 +-- arch/arm64/kvm/arch_timer.c | 5 +++ arch/arm64/kvm/arm.c | 12 +++++- arch/arm64/kvm/fpsimd.c | 4 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 9 +++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 17 ++++++++- arch/arm64/kvm/hyp/nvhe/pkvm.c | 27 ++++++++++--- arch/arm64/kvm/hyp/nvhe/switch.c | 28 ++++++++------ arch/arm64/kvm/hyp/nvhe/timer-sr.c | 25 +++++++++++-- arch/arm64/kvm/hyp/pgtable.c | 6 ++- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- arch/arm64/kvm/sys_regs.c | 2 +- arch/arm64/tools/cpucaps | 1 + drivers/irqchip/irq-apple-aic.c | 50 ++++++++++++++++++++++++- 28 files changed, 319 insertions(+), 64 deletions(-) -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 71C38C7EE2C for ; Fri, 26 May 2023 14:34:32 +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:MIME-Version:Message-Id:Date:Subject:Cc :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=A1AFyhhZSM6b9FZ+ul7abwkf6dXxFMpbbcoCa9vC/zc=; b=YlEXlJAVeRpV9o Mq8dLOZ9dsC5T+dTuslGkNgwgt6J4LOqwPgDzMbP22SBPJGfsVlA33iEINRMZz9rD9a8XWZlrTnEH cw0ryfTGm8hdqZV/6w7rFZHsYVb0AlTHwlZzeWAOFpscrxIwyKLe2QrKNjleGYZd48VSJtdO3N9lF RVJetYfmXw7RqaVyPk56Qi5avHJdC2WTUqrbwRcEkKG/cBQu0yFMUxawcVuJDrEUGRkBzXSQIDCIl 4z+tBtRAnCEGEuYJ3LRiZuoGS3hti6PrTaffDwLL2RX75PR2CXqfHXVTqC9CL7QoGCUGCKemiI2r0 gMPvpK4OhEEHEzIBz1tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2YW6-002oMo-13; Fri, 26 May 2023 14:34:06 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2YVv-002oGc-0Q for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 14:33:57 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5DC626151E; Fri, 26 May 2023 14:33:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB423C433D2; Fri, 26 May 2023 14:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685111633; bh=SF86W45rNNzwtS2zme2rgxuO0AM+zp3YypnP+jojmxI=; h=From:To:Cc:Subject:Date:From; b=C6df6TtKy9fZj8es0dK0LaNt6oH3kVNdlogV2vdjMxYh1/fgcpBgAXzhsXQBBhXq8 +YqdOG4xrcm8RsVETxr8ePgxN3IdXuvVQFL6Q1zrk/6/5ilqDgs8yGwjsbLk/rTeKS 6NJj/z8k3muJ0NbLtpGe90uDOgEvCqBAbb+LnjDtwvPHmZkjHOt0d/HdTHDHWoDotw rhAqxZ55hk6esfw4b9ZvwDXd8RVd/gL/18DkuHaVHvsNsojmgMsHuYtdQRt0/UxWk7 osTqwNVe9o3sTJbR/6UkyXkQaLcRv32Mh8zSwTlDS2IsDDn585kwWRgXgCHQA1tuPk KSz07o/a37Wkg== 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 1q2YVr-000aHS-Be; Fri, 26 May 2023 15:33:51 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Quentin Perret , Will Deacon , Fuad Tabba Subject: [PATCH v2 00/17] KVM: arm64: Allow using VHE in the nVHE hypervisor Date: Fri, 26 May 2023 15:33:31 +0100 Message-Id: <20230526143348.4072074-1-maz@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, qperret@google.com, will@kernel.org, tabba@google.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-20230526_073355_252288_B5EB5472 X-CRM114-Status: GOOD ( 20.20 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org KVM (on ARMv8.0) and pKVM (on all revisions of the architecture) use the split hypervisor model that makes the EL2 code more or less standalone. In the later case, we totally ignore the VHE mode and stick with the good old v8.0 EL2 setup. This is all good, but means that the EL2 code is limited in what it can do with its own address space. This series proposes to remove this limitation and to allow VHE to be used even with the split hypervisor model. This has some potential isolation benefits[1], and eventually allow systems that do not support HCR_EL2.E2H==0 to eventually run pKVM. We introduce a new "mode" for KVM called hVHE, in reference to the nVHE mode, and indicating that only the hypervisor is using VHE. Note that this is all this series does. No effort is made to improve the VA space management, which will be the subject of another series if this one ever makes it. This has been tested on a M1 box (bare metal) as well as as a nested guest on M2, both with the standard nVHE and protected modes, with no measurable change in performance. Note: the last patch of this series is not a merge candidate. Thanks, M. [1] https://www.youtube.com/watch?v=1F_Mf2j9eIo&list=PLbzoR-pLrL6qWL3v2KOcvwZ54-w0z5uXV&index=11 * From v1: - Fixed CNTHCTL_EL2 setup when switching from E2H=0 to E2H=1 Amusingly, this was found on NV... - Rebased on 6.4-rc2 Marc Zyngier (17): KVM: arm64: Drop is_kernel_in_hyp_mode() from __invalidate_icache_guest_page() arm64: Prevent the use of is_kernel_in_hyp_mode() in hypervisor code arm64: Turn kaslr_feature_override into a generic SW feature override arm64: Add KVM_HVHE capability and has_hvhe() predicate arm64: Don't enable VHE for the kernel if OVERRIDE_HVHE is set arm64: Allow EL1 physical timer access when running VHE arm64: Use CPACR_EL1 format to set CPTR_EL2 when E2H is set KVM: arm64: Remove alternatives from sysreg accessors in VHE hypervisor context KVM: arm64: Key use of VHE instructions in nVHE code off ARM64_KVM_HVHE KVM: arm64: Force HCR_EL2.E2H when ARM64_KVM_HVHE is set KVM: arm64: Disable TTBR1_EL2 when using ARM64_KVM_HVHE KVM: arm64: Adjust EL2 stage-1 leaf AP bits when ARM64_KVM_HVHE is set KVM: arm64: Rework CPTR_EL2 programming for HVHE configuration KVM: arm64: Program the timer traps with VHE layout in hVHE mode KVM: arm64: Force HCR_E2H in guest context when ARM64_KVM_HVHE is set arm64: Allow arm64_sw.hvhe on command line KVM: arm64: Terrible timer hack for M1 with hVHE arch/arm64/include/asm/arch_timer.h | 8 ++++ arch/arm64/include/asm/cpufeature.h | 5 +++ arch/arm64/include/asm/el2_setup.h | 26 ++++++++++++- arch/arm64/include/asm/kvm_arm.h | 4 +- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_emulate.h | 33 +++++++++++++++- arch/arm64/include/asm/kvm_hyp.h | 37 +++++++++++++----- arch/arm64/include/asm/kvm_mmu.h | 3 +- arch/arm64/include/asm/virt.h | 15 +++++++- arch/arm64/kernel/cpufeature.c | 17 +++++++++ arch/arm64/kernel/hyp-stub.S | 10 ++++- arch/arm64/kernel/idreg-override.c | 25 ++++++++----- arch/arm64/kernel/image-vars.h | 3 ++ arch/arm64/kernel/kaslr.c | 6 +-- arch/arm64/kvm/arch_timer.c | 5 +++ arch/arm64/kvm/arm.c | 12 +++++- arch/arm64/kvm/fpsimd.c | 4 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 9 +++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 17 ++++++++- arch/arm64/kvm/hyp/nvhe/pkvm.c | 27 ++++++++++--- arch/arm64/kvm/hyp/nvhe/switch.c | 28 ++++++++------ arch/arm64/kvm/hyp/nvhe/timer-sr.c | 25 +++++++++++-- arch/arm64/kvm/hyp/pgtable.c | 6 ++- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- arch/arm64/kvm/sys_regs.c | 2 +- arch/arm64/tools/cpucaps | 1 + drivers/irqchip/irq-apple-aic.c | 50 ++++++++++++++++++++++++- 28 files changed, 319 insertions(+), 64 deletions(-) -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel