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 22/23] KVM: arm64: Raise PKVM_HYP_REQ_SPLIT on guest to host sharing
Date: Mon, 02 Nov 2026 21:10:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-194183@kernel.org> (raw)
In-Reply-To: <20261102204628.401871-23-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] KVM: arm64: unwanted block split and latent panic in pkvm_memunshare_call()
--
commit 8b44fbe0de868cf9681f0eef63a65d11368c1c9d
Author: Vincent Donnefort <vdonnefort@google.com>
KVM: arm64: Raise PKVM_HYP_REQ_SPLIT on guest to host sharing
This commit raises a PKVM_HYP_REQ_SPLIT hypervisor request and rewinds
ELR_EL2 when a guest MEM_SHARE or MEM_UNSHARE hypercall encounters a huge
stage-2 block mapping (-E2BIG) so that the host can split the block and
replay the hypercall.
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index d92f4da1c1807..6c126fcc3831b 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
[ ... ]
> @@ -1197,17 +1218,29 @@ static bool pkvm_memshare_call(u64 *ret, struct kvm_vcpu *vcpu, u64 *exit_code)
> return false;
> }
>
> -static void pkvm_memunshare_call(u64 *ret, struct kvm_vcpu *vcpu)
> +static bool pkvm_memunshare_call(u64 *ret, struct kvm_vcpu *vcpu, u64 *exit_code)
> {
> struct pkvm_hyp_vcpu *hyp_vcpu;
> u64 ipa = smccc_get_arg1(vcpu);
> + u64 gfn = hyp_phys_to_pfn(ipa);
>
> if (!PAGE_ALIGNED(ipa))
> - return;
> + goto out_guest;
>
> hyp_vcpu = container_of(vcpu, struct pkvm_hyp_vcpu, vcpu);
> - if (!__pkvm_guest_unshare_host(hyp_vcpu, hyp_phys_to_pfn(ipa), 1))
> + switch (__pkvm_guest_unshare_host(hyp_vcpu, gfn, 1)) {
> + case 0:
> ret[0] = SMCCC_RET_SUCCESS;
> + goto out_guest;
> + case -E2BIG:
> + *exit_code = pkvm_request_split(hyp_vcpu, gfn, 1);
> + goto out_host;
> + }
[Severity: Medium]
Should pkvm_memunshare_call() request a block split when
__pkvm_guest_unshare_host() returns -E2BIG?
In arch/arm64/kvm/hyp/nvhe/mem_protect.c, __pkvm_guest_unshare_host() calls
get_valid_guest_pte() before checking whether the page state is
PKVM_PAGE_SHARED_OWNED:
arch/arm64/kvm/hyp/nvhe/mem_protect.c:__pkvm_guest_unshare_host() {
...
ret = get_valid_guest_pte(vm, ipa, size, &pte, &phys);
if (ret)
goto unlock;
ret = -EPERM;
if (pkvm_getstate(kvm_pgtable_stage2_pte_prot(pte)) != PKVM_PAGE_SHARED_OWNED)
goto unlock;
...
}
If a protected guest issues ARM_SMCCC_VENDOR_HYP_KVM_MEM_UNSHARE_FUNC_ID on
an IPA backed by an unshared (PKVM_PAGE_OWNED) PMD block mapping,
get_valid_guest_pte() sees size == PAGE_SIZE against the level-2 block leaf
and immediately returns -E2BIG.
With this change, pkvm_memunshare_call() catches -E2BIG and exits to the
host via pkvm_request_split() to shatter the unshared 2MB block in both
guest and host stage-2 page tables (and split its pkvm_mapping into 512
entries), only for the replayed MEM_UNSHARE hypercall to fail the
PKVM_PAGE_SHARED_OWNED check with -EPERM.
Furthermore, if a PMD block were ever shared with the host in the future as
mentioned in the commit message, __pkvm_guest_share_host() ->
__host_set_page_state_range() installs a valid PKVM_HOST_MEM_PROT entry in
host_mmu.pgt (replacing the invalid donation metadata PTE). If
pkvm_memunshare_call() then triggers PKVM_HYP_REQ_SPLIT on that shared
block, the host split path calls:
__pkvm_host_split_guest()
-> host_stage2_split_gfn_meta()
-> host_stage2_decode_gfn_meta()
which hits WARN_ON(kvm_pte_valid(pte)) and panics EL2:
arch/arm64/kvm/hyp/nvhe/mem_protect.c:host_stage2_decode_gfn_meta() {
...
if (WARN_ON(kvm_pte_valid(pte)))
return -EINVAL;
...
}
Would it be better not to request PKVM_HYP_REQ_SPLIT in
pkvm_memunshare_call() while MEM_SHARE is single-page only (or check the
guest PTE state before returning -E2BIG)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102204628.401871-1-vdonnefort@google.com?part=22
next prev parent reply other threads:[~2026-11-02 21:10 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
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 [this message]
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-194183@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.