From patchwork Tue Dec 6 13:59:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13065847 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 D132EC352A1 for ; Tue, 6 Dec 2022 14:02:43 +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:References:In-Reply-To: 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: List-Owner; bh=EAB4VNxqjoOAVIzvXsaroinpRJw8JNYJSgmPtJmB/fg=; b=FbO75nMS9S2dDr QBUZkVwcEAR7kO0YIRMr3MpB5ZKC3tWSHKFRyHeAbJO21iDek5PYv+rdl3Ax9sww28sKHgLKixFbt 1oapMBGP2xRamMVf6PS6wf5buxj3IB1xEGLm3kkOZRdpXrVyUSfBSmb4UeNWv+nLQWPk9rhjw4dO6 1BhNYrD+bsz7ymD8XMzeIz7bf/4dZHiUHrHn1OFWqCYtmAVqv8p+VI6VHeryY5/IvxiyGxhS8SqFQ L7PdwPuKjGVWo6kXOWEt6Au6I6VhQ6ZvBBq2LEF1Woq6tLmEvOSk3xIQ2VqKxXt2cS6ooZhwtagSL K+XwM8ZRpvZDj4KETmHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2YVW-00AAC2-M5; Tue, 06 Dec 2022 14:01:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2YUa-00A9CD-Ux for linux-arm-kernel@lists.infradead.org; Tue, 06 Dec 2022 14:00:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC13E1424; Tue, 6 Dec 2022 06:00:18 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.159]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 637E93F73D; Tue, 6 Dec 2022 06:00:10 -0800 (PST) From: Ryan Roberts To: Marc Zyngier , Catalin Marinas , Will Deacon , Ard Biesheuvel , Suzuki K Poulose , Anshuman Khandual Cc: Ryan Roberts , James Morse , Alexandru Elisei , Oliver Upton , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 05/12] KVM: arm64: Maintain page-table format info in struct kvm_pgtable Date: Tue, 6 Dec 2022 13:59:23 +0000 Message-Id: <20221206135930.3277585-6-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221206135930.3277585-1-ryan.roberts@arm.com> References: <20221206135930.3277585-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221206_060017_106338_A955CC8F X-CRM114-Status: GOOD ( 11.15 ) 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 As the next step on the journey to supporting FEAT_LPA2 in KVM, add a flag to struct kvm_pgtable, which functions can then use to select the approprate behavior for either the `classic` or `lpa2` page-table formats. For now, all page-tables remain in the `classic` format. No functional changes are intended. Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/kvm_pgtable.h | 2 ++ arch/arm64/kvm/hyp/pgtable.c | 2 ++ arch/arm64/kvm/mmu.c | 1 + 3 files changed, 5 insertions(+) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 2247ed74871a..744e224d964b 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -157,6 +157,7 @@ typedef bool (*kvm_pgtable_force_pte_cb_t)(u64 addr, u64 end, * @start_level: Level at which the page-table walk starts. * @pgd: Pointer to the first top-level entry of the page-table. * @mm_ops: Memory management callbacks. + * @lpa2_ena: Format used for page-table; false->classic, true->lpa2. * @mmu: Stage-2 KVM MMU struct. Unused for stage-1 page-tables. * @flags: Stage-2 page-table flags. * @force_pte_cb: Function that returns true if page level mappings must @@ -167,6 +168,7 @@ struct kvm_pgtable { u32 start_level; kvm_pte_t *pgd; struct kvm_pgtable_mm_ops *mm_ops; + bool lpa2_ena; /* Stage-2 only */ struct kvm_s2_mmu *mmu; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 221e0dafb149..c7799cd50af8 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -530,6 +530,7 @@ int kvm_pgtable_hyp_init(struct kvm_pgtable *pgt, u32 va_bits, pgt->ia_bits = va_bits; pgt->start_level = KVM_PGTABLE_MAX_LEVELS - levels; pgt->mm_ops = mm_ops; + pgt->lpa2_ena = false; pgt->mmu = NULL; pgt->force_pte_cb = NULL; @@ -1190,6 +1191,7 @@ int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu, pgt->ia_bits = ia_bits; pgt->start_level = start_level; pgt->mm_ops = mm_ops; + pgt->lpa2_ena = false; pgt->mmu = mmu; pgt->flags = flags; pgt->force_pte_cb = force_pte_cb; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1ef0704420d9..e3fe3e194fd1 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -645,6 +645,7 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) .start_level = (KVM_PGTABLE_MAX_LEVELS - CONFIG_PGTABLE_LEVELS), .mm_ops = &kvm_user_mm_ops, + .lpa2_ena = lpa2_is_enabled(), }; kvm_pte_t pte = 0; /* Keep GCC quiet... */ u32 level = ~0;