[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CA+_y_2EsStP+zNOfykjrmJBx6a1pxaewC2X9TnXnj3kNpixsWg@mail.gmail.com>
Date: Tue, 17 Aug 2021 14:53:11 +0100
From: Andrew Walbran <qwandor@...gle.com>
To: Quentin Perret <qperret@...gle.com>
Cc: Marc Zyngier <maz@...nel.org>, James Morse <james.morse@....com>,
alexandru.elisei@....com,
Suzuki K Poulose <suzuki.poulose@....com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.cs.columbia.edu,
linux-kernel@...r.kernel.org, ardb@...nel.org,
Fuad Tabba <tabba@...gle.com>,
David Brazdil <dbrazdil@...gle.com>,
Android Kernel Team <kernel-team@...roid.com>
Subject: Re: [PATCH v4 04/21] KVM: arm64: Introduce helper to retrieve a PTE
and its level
On Mon, 9 Aug 2021 at 16:25, Quentin Perret <qperret@...gle.com> wrote:
>
> From: Marc Zyngier <maz@...nel.org>
>
> 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@...nel.org>
> Signed-off-by: Quentin Perret <qperret@...gle.com>
> ---
> 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().
> + * @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);
> + if (!ret) {
> + if (ptep)
> + *ptep = data.pte;
> + if (level)
> + *level = data.level;
> + }
> +
> + return ret;
> +}
> +
> struct hyp_map_data {
> u64 phys;
> kvm_pte_t attr;
> --
> 2.32.0.605.g8dce9f2422-goog
>
Reviewed-by: Andrew Walbran <qwandor@...gle.com>
Download attachment "smime.p7s" of type "application/pkcs7-signature" (3998 bytes)
Powered by blists - more mailing lists