From: Ricardo Koller <ricarkol@google.com>
To: pbonzini@redhat.com, maz@kernel.org, oupton@google.com,
yuzenghui@huawei.com, dmatlack@google.com
Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, qperret@google.com,
catalin.marinas@arm.com, andrew.jones@linux.dev,
seanjc@google.com, alexandru.elisei@arm.com,
suzuki.poulose@arm.com, eric.auger@redhat.com, gshan@redhat.com,
reijiw@google.com, rananta@google.com, bgardon@google.com,
ricarkol@gmail.com, Ricardo Koller <ricarkol@google.com>,
Shaoqin Huang <shahuang@redhat.com>
Subject: [PATCH v7 03/12] KVM: arm64: Add helper for creating unlinked stage2 subtrees
Date: Sun, 9 Apr 2023 06:29:51 +0000 [thread overview]
Message-ID: <20230409063000.3559991-5-ricarkol@google.com> (raw)
In-Reply-To: <20230409063000.3559991-1-ricarkol@google.com>
Add a stage2 helper, kvm_pgtable_stage2_create_unlinked(), for
creating unlinked tables (which is the opposite of
kvm_pgtable_stage2_free_unlinked()). Creating an unlinked table is
useful for splitting level 1 and 2 entries into subtrees of PAGE_SIZE
PTEs. For example, a level 1 entry can be split into PAGE_SIZE PTEs
by first creating a fully populated tree, and then use it to replace
the level 1 entry in a single step. This will be used in a subsequent
commit for eager huge-page splitting (a dirty-logging optimization).
Signed-off-by: Ricardo Koller <ricarkol@google.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
---
arch/arm64/include/asm/kvm_pgtable.h | 26 +++++++++++++++
arch/arm64/kvm/hyp/pgtable.c | 49 ++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h
index 3f2d43ba2b628..c8e0e7d9303b2 100644
--- a/arch/arm64/include/asm/kvm_pgtable.h
+++ b/arch/arm64/include/asm/kvm_pgtable.h
@@ -458,6 +458,32 @@ void kvm_pgtable_stage2_destroy(struct kvm_pgtable *pgt);
*/
void kvm_pgtable_stage2_free_unlinked(struct kvm_pgtable_mm_ops *mm_ops, void *pgtable, u32 level);
+/**
+ * kvm_pgtable_stage2_create_unlinked() - Create an unlinked stage-2 paging structure.
+ * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*().
+ * @phys: Physical address of the memory to map.
+ * @level: Starting level of the stage-2 paging structure to be created.
+ * @prot: Permissions and attributes for the mapping.
+ * @mc: Cache of pre-allocated and zeroed memory from which to allocate
+ * page-table pages.
+ * @force_pte: Force mappings to PAGE_SIZE granularity.
+ *
+ * Returns an unlinked page-table tree. This new page-table tree is
+ * not reachable (i.e., it is unlinked) from the root pgd and it's
+ * therefore unreachableby the hardware page-table walker. No TLB
+ * invalidation or CMOs are performed.
+ *
+ * If device attributes are not explicitly requested in @prot, then the
+ * mapping will be normal, cacheable.
+ *
+ * Return: The fully populated (unlinked) stage-2 paging structure, or
+ * an ERR_PTR(error) on failure.
+ */
+kvm_pte_t *kvm_pgtable_stage2_create_unlinked(struct kvm_pgtable *pgt,
+ u64 phys, u32 level,
+ enum kvm_pgtable_prot prot,
+ void *mc, bool force_pte);
+
/**
* kvm_pgtable_stage2_map() - Install a mapping in a guest stage-2 page-table.
* @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*().
diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index 633679ee3c49a..477d2be67d401 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -1222,6 +1222,55 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size)
return kvm_pgtable_walk(pgt, addr, size, &walker);
}
+kvm_pte_t *kvm_pgtable_stage2_create_unlinked(struct kvm_pgtable *pgt,
+ u64 phys, u32 level,
+ enum kvm_pgtable_prot prot,
+ void *mc, bool force_pte)
+{
+ struct stage2_map_data map_data = {
+ .phys = phys,
+ .mmu = pgt->mmu,
+ .memcache = mc,
+ .force_pte = force_pte,
+ };
+ struct kvm_pgtable_walker walker = {
+ .cb = stage2_map_walker,
+ .flags = KVM_PGTABLE_WALK_LEAF |
+ KVM_PGTABLE_WALK_SKIP_BBM_TLBI |
+ KVM_PGTABLE_WALK_SKIP_CMO,
+ .arg = &map_data,
+ };
+ /* .addr (the IPA) is irrelevant for an unlinked table */
+ struct kvm_pgtable_walk_data data = {
+ .walker = &walker,
+ .addr = 0,
+ .end = kvm_granule_size(level),
+ };
+ struct kvm_pgtable_mm_ops *mm_ops = pgt->mm_ops;
+ kvm_pte_t *pgtable;
+ int ret;
+
+ if (!IS_ALIGNED(phys, kvm_granule_size(level)))
+ return ERR_PTR(-EINVAL);
+
+ ret = stage2_set_prot_attr(pgt, prot, &map_data.attr);
+ if (ret)
+ return ERR_PTR(ret);
+
+ pgtable = mm_ops->zalloc_page(mc);
+ if (!pgtable)
+ return ERR_PTR(-ENOMEM);
+
+ ret = __kvm_pgtable_walk(&data, mm_ops, (kvm_pteref_t)pgtable,
+ level + 1);
+ if (ret) {
+ kvm_pgtable_stage2_free_unlinked(mm_ops, pgtable, level);
+ mm_ops->put_page(pgtable);
+ return ERR_PTR(ret);
+ }
+
+ return pgtable;
+}
int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu,
struct kvm_pgtable_mm_ops *mm_ops,
--
2.40.0.577.gac1e443424-goog
next prev parent reply other threads:[~2023-04-09 6:30 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-09 6:29 [PATCH v7 00/12] Implement Eager Page Splitting for ARM Ricardo Koller
2023-04-09 6:29 ` [PATCH v7 01/12] KVM: arm64: Rename free_removed to free_unlinked Ricardo Koller
2023-04-17 6:08 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 02/12] KVM: arm64: Add KVM_PGTABLE_WALK ctx->flags for skipping BBM and CMO Ricardo Koller
2023-04-17 6:10 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 02/12] KVM: arm64: Add KVM_PGTABLE_WALK flags for skipping CMOs and BBM TLBIs Ricardo Koller
2023-04-17 6:13 ` Gavin Shan
2023-04-09 6:29 ` Ricardo Koller [this message]
2023-04-17 6:18 ` [PATCH v7 03/12] KVM: arm64: Add helper for creating unlinked stage2 subtrees Gavin Shan
2023-04-22 20:09 ` Ricardo Koller
2023-04-22 20:32 ` Oliver Upton
2023-04-22 20:37 ` Ricardo Koller
2023-04-23 6:55 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 04/12] KVM: arm64: Add kvm_pgtable_stage2_split() Ricardo Koller
2023-04-09 9:36 ` kernel test robot
2023-04-10 17:40 ` Ricardo Koller
2023-04-17 6:38 ` Gavin Shan
2023-04-22 20:32 ` Ricardo Koller
2023-04-23 6:58 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 05/12] KVM: arm64: Refactor kvm_arch_commit_memory_region() Ricardo Koller
2023-04-17 6:41 ` Gavin Shan
2023-04-23 19:47 ` Ricardo Koller
2023-04-17 6:42 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 06/12] KVM: arm64: Add kvm_uninit_stage2_mmu() Ricardo Koller
2023-04-17 6:44 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 07/12] KVM: arm64: Export kvm_are_all_memslots_empty() Ricardo Koller
2023-04-17 6:47 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 08/12] KVM: arm64: Add KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE Ricardo Koller
2023-04-17 7:04 ` Gavin Shan
2023-04-23 20:27 ` Ricardo Koller
2023-04-24 11:14 ` Gavin Shan
2023-04-24 18:48 ` Ricardo Koller
2023-04-09 6:29 ` [PATCH v7 09/12] KVM: arm64: Split huge pages when dirty logging is enabled Ricardo Koller
2023-04-17 7:11 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 10/12] KVM: arm64: Open-code kvm_mmu_write_protect_pt_masked() Ricardo Koller
2023-04-17 7:14 ` Gavin Shan
2023-04-09 6:29 ` [PATCH v7 11/12] KVM: arm64: Split huge pages during KVM_CLEAR_DIRTY_LOG Ricardo Koller
2023-04-17 7:18 ` Gavin Shan
2023-04-09 6:30 ` [PATCH v7 12/12] KVM: arm64: Use local TLBI on permission relaxation Ricardo Koller
2023-04-17 7:20 ` Gavin Shan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230409063000.3559991-5-ricarkol@google.com \
--to=ricarkol@google.com \
--cc=alexandru.elisei@arm.com \
--cc=andrew.jones@linux.dev \
--cc=bgardon@google.com \
--cc=catalin.marinas@arm.com \
--cc=dmatlack@google.com \
--cc=eric.auger@redhat.com \
--cc=gshan@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=qperret@google.com \
--cc=rananta@google.com \
--cc=reijiw@google.com \
--cc=ricarkol@gmail.com \
--cc=seanjc@google.com \
--cc=shahuang@redhat.com \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox