From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>, kvmarm@lists.linux.dev
Cc: "Oliver Upton" <oupton@kernel.org>, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v3 18/23] KVM: arm64: Introduce kvm_pgtable_stage2_table_install()
Date: Mon, 02 Nov 2026 21:02:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-194174@kernel.org> (raw)
In-Reply-To: <20261102204628.401871-19-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] KVM: arm64: missing block alignment check in stage2_table_install_walker()
- [Low] KVM: arm64: kernel-doc mismatch for kvm_pgtable_stage2_table_install()
--
commit 2ec53eff489eca020eb2705b64a21720b1def67f
Author: Vincent Donnefort <vdonnefort@google.com>
KVM: arm64: Introduce kvm_pgtable_stage2_table_install()
This commit introduces kvm_pgtable_stage2_table_install() to replace a
stage-2 leaf entry with a pre-allocated table, enabling pKVM to handle block
splitting in mem_protect.c without relying on kvm_mmu_memory_cache.
> diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h
> index 1c9c57cd6ae40..587874c3a5259 100644
> --- a/arch/arm64/include/asm/kvm_pgtable.h
> +++ b/arch/arm64/include/asm/kvm_pgtable.h
> @@ -835,6 +835,18 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size);
> int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size,
> struct kvm_mmu_memory_cache *mc);
>
> +/**
> + * kvm_pgtable_stage2_table_install() - Replace a stage-2 leaf entry with a table.
> + * @pgt: Page-table structure initialised by kvm_pgtable_stage2_create_unlinked().
> + * @addr: Address identifying the leaf entry to replace.
> + * @size: Size of the block to replace.
> + * @tab: Pointer to the pre-allocated table to install.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int kvm_pgtable_stage2_table_install(struct kvm_pgtable *pgt, u64 addr, u64 size,
> + kvm_pte_t *table);
[Severity: Low]
In the kernel-doc comment for kvm_pgtable_stage2_table_install(), @tab does
not match the parameter name table in the prototype (and definition in
arch/arm64/kvm/hyp/pgtable.c), which triggers a scripts/kernel-doc warning.
Also, @pgt is described as initialised by
kvm_pgtable_stage2_create_unlinked(). Should @pgt be documented as
initialised by kvm_pgtable_stage2_init*(), with @table being the table that
may be created by kvm_pgtable_stage2_create_unlinked()?
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index abd32e94f6ff0..19634e5ec5557 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
[ ... ]
> @@ -1620,6 +1634,55 @@ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size,
> return ret;
> }
>
> +struct stage2_table_install_data {
> + struct kvm_s2_mmu *mmu;
> + kvm_pte_t *table;
> +};
> +
> +static int stage2_table_install_walker(const struct kvm_pgtable_visit_ctx *ctx,
> + enum kvm_pgtable_walk_flags visit)
> +{
> + struct stage2_table_install_data *data = ctx->arg;
> + struct kvm_s2_mmu *mmu = data->mmu;
> + kvm_pte_t *childp = data->table;
> +
> + if (ctx->level == KVM_PGTABLE_LAST_LEVEL)
> + return -EINVAL;
> +
> + if (ctx->addr != ctx->start ||
> + ctx->end != ctx->addr + kvm_granule_size(ctx->level))
> + return -EINVAL;
[Severity: Medium]
Does this check verify that ctx->addr is aligned to the block granule size
kvm_granule_size(ctx->level)?
In kvm_pgtable_walk(), both walk_data.start and walk_data.addr are
initialised to ALIGN_DOWN(addr, PAGE_SIZE):
struct kvm_pgtable_walk_data walk_data = {
.start = ALIGN_DOWN(addr, PAGE_SIZE),
.addr = ALIGN_DOWN(addr, PAGE_SIZE),
.end = PAGE_ALIGN(walk_data.addr + size),
.walker = walker,
};
In __kvm_pgtable_visit(), data->addr is only aligned down to
kvm_granule_size(level) and advanced after the leaf callback returns 0:
if (!table) {
data->addr = ALIGN_DOWN(data->addr, kvm_granule_size(level));
data->addr += kvm_granule_size(level);
goto out;
}
Because stage2_table_install_walker() is only invoked for
KVM_PGTABLE_WALK_LEAF and always returns a non-zero value, ctx->addr is
always equal to ctx->start on the first visited leaf entry, making
ctx->addr != ctx->start always false.
If kvm_pgtable_stage2_table_install() is called with an addr that is
page-aligned but not aligned to kvm_granule_size(ctx->level) and with size
equal to kvm_granule_size(ctx->level), this check will pass, replacing the
enclosing block PTE and passing an unaligned IPA to stage2_try_break_pte().
Although the callers added later in the series (__pkvm_host_split_guest()
and host_stage2_split_gfn_meta()) check PMD_SIZE alignment beforehand,
should stage2_table_install_walker() check
!IS_ALIGNED(ctx->addr, kvm_granule_size(ctx->level))?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102204628.401871-1-vdonnefort@google.com?part=18
next prev parent reply other threads:[~2026-11-02 21:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 20:46 [PATCH v3 00/23] Huge mapping support for protected VMs Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 01/23] KVM: arm64: Prefault host stage-2 entries on block split Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 02/23] KVM: arm64: Propagate host stage-2 annotated " Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 03/23] KVM: arm64: Allow block-level stage-2 annotation Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 04/23] KVM: arm64: Use block-level annotations when setting up the host stage-2 Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 05/23] KVM: arm64: Make pKVM ownership selftest an HVC Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 06/23] KVM: arm64: Reject zero-sized ranges in pfn_range_is_valid() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 07/23] KVM: arm64: Add a range to __pkvm_host_share/unshare_hyp() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 08/23] KVM: arm64: Add a range to __pkvm_host_donate_guest() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 09/23] KVM: arm64: Add a range to hyp_poison_page() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 10/23] KVM: arm64: Add a range to __pkvm_host_reclaim_guest() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 11/23] KVM: arm64: Add a range to __pkvm_guest_share_host() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 12/23] KVM: arm64: Add a range to __pkvm_guest_unshare_host() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 13/23] KVM: arm64: Handle huge mappings in __pkvm_host_force_reclaim_page_guest() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 14/23] KVM: arm64: Handle huge mappings in __pkvm_vcpu_in_poison_fault() Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 15/23] KVM: arm64: Add a range to pKVM ownership selftest Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 16/23] KVM: arm64: Warn on pKVM guest stage-2 block collapse Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 17/23] KVM: arm64: Add vcpu conduit for pkvm_hyp_req Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 18/23] KVM: arm64: Introduce kvm_pgtable_stage2_table_install() Vincent Donnefort
2026-11-02 21:02 ` sashiko-bot [this message]
2026-11-02 20:46 ` [PATCH v3 19/23] KVM: arm64: Add __pkvm_host_split_guest HVC Vincent Donnefort
2026-11-02 21:13 ` sashiko-bot
2026-11-02 20:46 ` [PATCH v3 20/23] KVM: arm64: Extend pKVM page ownership selftests to cover guest block split Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 21/23] KVM: arm64: Add PKVM_HYP_REQ_SPLIT Vincent Donnefort
2026-11-02 20:46 ` [PATCH v3 22/23] KVM: arm64: Raise PKVM_HYP_REQ_SPLIT on guest to host sharing Vincent Donnefort
2026-11-02 21:10 ` sashiko-bot
2026-11-02 20:46 ` [PATCH v3 23/23] KVM: arm64: Stage-2 huge mappings for protected VMs Vincent Donnefort
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=sashiko-outbox-194174@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vdonnefort@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.