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 v6 20/24] KVM: arm64: Add __pkvm_host_split_guest HVC
Date: Thu, 03 Dec 2026 17:49:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-248304@kernel.org> (raw)
In-Reply-To: <20261203115209.1690207-21-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] KVM: arm64: __pkvm_host_split_guest() skips guest page state
check
- [Low] KVM: arm64: left-shift overflow on inputs in
__pkvm_host_split_guest()
- [Low] KVM: arm64: premature mc->nr_pages check in
__pkvm_host_split_guest()
--
commit c0a936c062694cf8e366e1ea2cfe5c0af145f622
Author: Vincent Donnefort <vdonnefort@google.com>
KVM: arm64: Add __pkvm_host_split_guest HVC
This commit adds the __pkvm_host_split_guest host hypercall and its EL2
implementation to split a PMD block mapping in a protected VM's stage-2
page table along with the corresponding host stage-2 GFN metadata.
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index d94e1d94d9953..118f92472299d 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
[ ... ]
> @@ -1783,6 +1831,55 @@ int __pkvm_host_mkyoung_guest(u64 gfn, struct pkvm_hyp_vcpu *vcpu)
> return 0;
> }
>
> +int __pkvm_host_split_guest(u64 gfn, u64 nr_pages, struct pkvm_hyp_vcpu *vcpu)
> +{
> + struct kvm_hyp_memcache *mc = &vcpu->vcpu.arch.stage2_mc;
> + struct pkvm_hyp_vm *vm = pkvm_hyp_vcpu_to_hyp_vm(vcpu);
> + u64 size = nr_pages << PAGE_SHIFT;
> + u64 ipa = hyp_pfn_to_phys(gfn);
> + kvm_pte_t pte, *table;
> + phys_addr_t phys;
> + s8 level;
> + int ret;
> +
> + if (!mc->nr_pages)
> + return -ENOMEM;
[Severity: Low]
Is this upfront mc->nr_pages check needed here? Checking it before
validating the arguments and guest PTE returns -ENOMEM instead of
-EINVAL, -ENOENT, or -E2BIG when stage2_mc is empty, and also rejects
the split even when vm->pool already has free pages.
Since kvm_pgtable_stage2_create_unlinked() allocates before either page
table is modified, and guest_s2_zalloc_page() tries vm->pool before
falling back to stage2_mc, dropping this check would preserve error
precedence and allow reusing pooled pages.
> +
> + if (size != PMD_SIZE || !IS_ALIGNED(ipa, PMD_SIZE))
> + return -EINVAL;
[Severity: Low]
Can the left shifts on nr_pages and gfn silently truncate out-of-range
host HVC inputs? Non-zero bits in the upper PAGE_SHIFT bits wrap
modulo 2^64, allowing invalid arguments to pass these checks and split
an aliased PMD block instead of returning -EINVAL.
Comparing nr_pages directly against PMD_SIZE >> PAGE_SHIFT (as in
__guest_check_transition_size()) and checking hyp_phys_to_pfn(ipa) == gfn
would avoid the truncation.
> +
> + level = KVM_PGTABLE_LAST_LEVEL - 1;
> +
> + host_lock_component();
> + guest_lock_component(vm);
> +
> + ret = get_valid_guest_pte(vm, ipa, size, &pte, &phys);
> + if (ret)
> + goto unlock;
> +
> + table = kvm_pgtable_stage2_create_unlinked(&vm->pgt, kvm_pte_to_phys(pte), level,
> + kvm_pgtable_stage2_pte_prot(pte),
> + mc, true);
> + if (IS_ERR(table)) {
> + ret = PTR_ERR(table);
> + goto unlock;
> + }
> +
> + ret = host_stage2_try(host_stage2_split_gfn_meta, phys, ipa, size, vm);
[Severity: Low]
Should __pkvm_host_split_guest() verify that guest_get_page_state(pte, ipa)
is PKVM_PAGE_OWNED before allocating the unlinked table and calling
host_stage2_split_gfn_meta()?
For a PMD block in PKVM_PAGE_SHARED_OWNED state, __pkvm_guest_share_host()
leaves a valid PMD in both vm->pgt and host_mmu.pgt. Passing that valid
host PTE from host_stage2_split_gfn_meta() to host_stage2_decode_gfn_meta()
hits WARN_ON(kvm_pte_valid(pte)) and panics EL2.
Today only __pkvm_ownership_selftest() shares a PMD_SIZE block from a
protected VM, so this is host-kernel-only for now, but checking the guest
page state first avoids the EL2 panic and prevents it from becoming
guest-triggerable once huge-page guest memshare is enabled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203115209.1690207-1-vdonnefort@google.com?part=20
next prev parent reply other threads:[~2026-12-03 17:49 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:51 [PATCH v6 00/24] Huge mapping support for protected VMs Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 01/24] KVM: arm64: Introduce kvm_pgtable_stage2_table_install() Vincent Donnefort
2026-12-03 12:07 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 02/24] KVM: arm64: Preserve idmap stage-2 entries on block split Vincent Donnefort
2026-12-03 12:30 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 03/24] KVM: arm64: Allow block-level stage-2 annotation Vincent Donnefort
2026-12-03 12:52 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 04/24] KVM: arm64: Use block-level annotations when setting up the host stage-2 Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 05/24] KVM: arm64: Make pKVM ownership selftest an HVC Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 06/24] KVM: arm64: Reject zero-sized ranges in pfn_range_is_valid() Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 07/24] KVM: arm64: Add a range to __pkvm_host_share/unshare_hyp() Vincent Donnefort
2026-12-03 13:46 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 08/24] KVM: arm64: Add a range to __pkvm_host_donate_guest() Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 09/24] KVM: arm64: Add a range to hyp_poison_page() Vincent Donnefort
2026-12-03 14:26 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 10/24] KVM: arm64: Add a range to __pkvm_host_reclaim_guest() Vincent Donnefort
2026-12-03 14:47 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 11/24] KVM: arm64: Add a range to __pkvm_guest_share_host() Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 12/24] KVM: arm64: Add a range to __pkvm_guest_unshare_host() Vincent Donnefort
2026-12-03 11:51 ` [PATCH v6 13/24] KVM: arm64: Handle huge mappings in __pkvm_host_force_reclaim_page_guest() Vincent Donnefort
2026-12-03 15:37 ` sashiko-bot
2026-12-03 11:51 ` [PATCH v6 14/24] KVM: arm64: Handle huge mappings in __pkvm_vcpu_in_poison_fault() Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 15/24] KVM: arm64: Add a range to pKVM ownership selftest Vincent Donnefort
2026-12-03 16:17 ` sashiko-bot
2026-12-03 11:52 ` [PATCH v6 16/24] KVM: arm64: Warn on pKVM guest stage-2 block collapse Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 17/24] KVM: arm64: Add vcpu conduit for pkvm_hyp_req Vincent Donnefort
2026-12-03 17:07 ` sashiko-bot
2026-12-03 11:52 ` [PATCH v6 18/24] KVM: arm64: Factor out host_stage2_encode_annotation() Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 19/24] KVM: arm64: Return VM handle from host_stage2_decode_gfn_meta() Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 20/24] KVM: arm64: Add __pkvm_host_split_guest HVC Vincent Donnefort
2026-12-03 17:49 ` sashiko-bot [this message]
2026-12-03 11:52 ` [PATCH v6 21/24] KVM: arm64: Extend pKVM page ownership selftests to cover guest block split Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 22/24] KVM: arm64: Add PKVM_HYP_REQ_SPLIT Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 23/24] KVM: arm64: Raise PKVM_HYP_REQ_SPLIT on guest to host sharing Vincent Donnefort
2026-12-03 11:52 ` [PATCH v6 24/24] KVM: arm64: Stage-2 huge mappings for protected VMs Vincent Donnefort
2026-12-03 19:28 ` sashiko-bot
2026-12-04 14:50 ` Vincent Donnefort
2026-12-03 19:27 ` [PATCH v6 00/24] Huge mapping support " Fuad Tabba
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-248304@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.