From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Marc Zyngier <maz@kernel.org>,
linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org,
kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org
Cc: Sean Christopherson <seanjc@google.com>,
Matthew Wilcox <willy@infradead.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Will Deacon <will@kernel.org>,
Quentin Perret <qperret@google.com>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
kernel-team@android.com
Subject: Re: [PATCH v2 1/6] KVM: arm64: Introduce helper to retrieve a PTE and its level
Date: Tue, 27 Jul 2021 16:25:34 +0100 [thread overview]
Message-ID: <11d5e176-ac47-e215-b82a-b8f074220bd6@arm.com> (raw)
In-Reply-To: <20210726153552.1535838-2-maz@kernel.org>
Hi Marc,
On 7/26/21 4:35 PM, Marc Zyngier wrote:
> It is becoming a common need to fetch the PTE for a given address
> together with its level. Add such a helper.
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
> arch/arm64/include/asm/kvm_pgtable.h | 19 ++++++++++++++
> arch/arm64/kvm/hyp/pgtable.c | 39 ++++++++++++++++++++++++++++
> 2 files changed, 58 insertions(+)
>
> diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h
> index f004c0115d89..082b9d65f40b 100644
> --- a/arch/arm64/include/asm/kvm_pgtable.h
> +++ b/arch/arm64/include/asm/kvm_pgtable.h
> @@ -432,6 +432,25 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size);
> int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size,
> struct kvm_pgtable_walker *walker);
>
> +/**
> + * kvm_pgtable_get_leaf() - Walk a page-table and retrieve the leaf entry
> + * with its level.
> + * @pgt: Page-table structure initialised by kvm_pgtable_*_init().
Yet in the next patch you use a struct kvm_pgtable_pgt not initialized by any of
the kvm_pgtable_*_init() functions. It doesn't hurt correctness, but it might
confuse potential users of this function.
> + * @addr: Input address for the start of the walk.
> + * @ptep: Pointer to storage for the retrieved PTE.
> + * @level: Pointer to storage for the level of the retrieved PTE.
> + *
> + * The offset of @addr within a page is ignored.
> + *
> + * The walker will walk the page-table entries corresponding to the input
> + * address specified, retrieving the leaf corresponding to this address.
> + * Invalid entries are treated as leaf entries.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr,
> + kvm_pte_t *ptep, u32 *level);
> +
> /**
> * kvm_pgtable_stage2_find_range() - Find a range of Intermediate Physical
> * Addresses with compatible permission
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index 05321f4165e3..78f36bd5df6c 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -326,6 +326,45 @@ int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size,
> return _kvm_pgtable_walk(&walk_data);
> }
>
> +struct leaf_walk_data {
> + kvm_pte_t pte;
> + u32 level;
> +};
> +
> +static int leaf_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
> + enum kvm_pgtable_walk_flags flag, void * const arg)
> +{
> + struct leaf_walk_data *data = arg;
> +
> + data->pte = *ptep;
> + data->level = level;
> +
> + return 0;
> +}
> +
> +int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr,
> + kvm_pte_t *ptep, u32 *level)
> +{
> + struct leaf_walk_data data;
> + struct kvm_pgtable_walker walker = {
> + .cb = leaf_walker,
> + .flags = KVM_PGTABLE_WALK_LEAF,
> + .arg = &data,
> + };
> + int ret;
> +
> + ret = kvm_pgtable_walk(pgt, ALIGN_DOWN(addr, PAGE_SIZE),
> + PAGE_SIZE, &walker);
kvm_pgtable_walk() already aligns addr down to PAGE_SIZE, I don't think that's
needed here. But not harmful either.
Otherwise, the patch looks good to me:
Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
Thanks,
Alex
> + if (!ret) {
> + if (ptep)
> + *ptep = data.pte;
> + if (level)
> + *level = data.level;
> + }
> +
> + return ret;
> +}
> +
> struct hyp_map_data {
> u64 phys;
> kvm_pte_t attr;
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-07-27 15:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-26 15:35 [PATCH v2 0/6] KVM: Remove kvm_is_transparent_hugepage() and friends Marc Zyngier
2021-07-26 15:35 ` [PATCH v2 1/6] KVM: arm64: Introduce helper to retrieve a PTE and its level Marc Zyngier
2021-07-27 10:29 ` Quentin Perret
2021-07-27 15:25 ` Alexandru Elisei [this message]
2021-07-28 12:17 ` Marc Zyngier
2021-07-26 15:35 ` [PATCH v2 2/6] KVM: arm64: Walk userspace page tables to compute the THP mapping size Marc Zyngier
2021-07-27 15:55 ` Alexandru Elisei
2021-07-26 15:35 ` [PATCH v2 3/6] KVM: arm64: Avoid mapping size adjustment on permission fault Marc Zyngier
2021-07-27 16:00 ` Alexandru Elisei
2021-07-26 15:35 ` [PATCH v2 4/6] KVM: Remove kvm_is_transparent_hugepage() and PageTransCompoundMap() Marc Zyngier
2021-07-26 15:35 ` [PATCH v2 5/6] KVM: arm64: Use get_page() instead of kvm_get_pfn() Marc Zyngier
2021-07-27 17:46 ` Alexandru Elisei
2021-07-26 15:35 ` [PATCH v2 6/6] KVM: Get rid " Marc Zyngier
2021-08-02 13:39 ` [PATCH v2 0/6] KVM: Remove kvm_is_transparent_hugepage() and friends Marc Zyngier
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=11d5e176-ac47-e215-b82a-b8f074220bd6@arm.com \
--to=alexandru.elisei@arm.com \
--cc=james.morse@arm.com \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=qperret@google.com \
--cc=seanjc@google.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).