All of lore.kernel.org
 help / color / mirror / Atom feed
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 13/24] KVM: arm64: Handle huge mappings in __pkvm_host_force_reclaim_page_guest()
Date: Thu, 03 Dec 2026 15:37:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-248123@kernel.org> (raw)
In-Reply-To: <20261203115209.1690207-14-vdonnefort@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] kvm: __pkvm_host_force_reclaim_page_guest() holds global
  locks over PMD
--

commit e4160fc03dbf17fa5fb410c53a8820d2609da1f1
Author: Vincent Donnefort <vdonnefort@google.com>

KVM: arm64: Handle huge mappings in __pkvm_host_force_reclaim_page_guest()

This commit extends __pkvm_host_force_reclaim_page_guest() to handle PMD_SIZE
mappings by reading the mapping size from the host stage-2 page table and
validating it against the guest stage-2.

> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index d9b67b4ca581f..da5aa3bbca72f 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c

[ ... ]

>  int __pkvm_host_force_reclaim_page_guest(phys_addr_t phys)
>  {
> +	u64 gfn, ipa, pa, size;
>  	struct pkvm_hyp_vm *vm;
> -	u64 gfn, ipa, pa;
>  	kvm_pte_t pte;
>  	int ret;
>  
> -	phys &= PAGE_MASK;
> -
>  	hyp_spin_lock(&vm_table_lock);
>  	host_lock_component();
>  
> -	ret = host_stage2_get_guest_info(phys, &vm, &gfn);
> +	ret = host_stage2_get_guest_info(phys, &size, &vm, &gfn);
>  	if (ret)
>  		goto unlock_host;
>  
>  	ipa = hyp_pfn_to_phys(gfn);
> +
>  	guest_lock_component(vm);
> -	ret = get_valid_guest_pte(vm, ipa, PAGE_SIZE, &pte, &pa);
> +	ret = get_valid_guest_pte(vm, ipa, size, &pte, &pa);
>  	if (ret)
>  		goto unlock_guest;
>  
> +	phys = ALIGN_DOWN(phys, size);
> +	pa = ALIGN_DOWN(pa, size);
> +
>  	WARN_ON(pa != phys);
>  	if (guest_get_page_state(pte, ipa) != PKVM_PAGE_OWNED) {
>  		ret = -EPERM;
> @@ -1403,14 +1412,14 @@ int __pkvm_host_force_reclaim_page_guest(phys_addr_t phys)
>  	}
>  
>  	/* We really shouldn't be allocating, so don't pass a memcache */
> -	ret = kvm_pgtable_stage2_annotate(&vm->pgt, ipa, PAGE_SIZE, NULL,
> +	ret = kvm_pgtable_stage2_annotate(&vm->pgt, ipa, size, NULL,
>  					  KVM_GUEST_INVALID_PTE_TYPE_POISONED,
>  					  0);
>  	if (ret)
>  		goto unlock_guest;
>  
> -	hyp_poison_range(phys, PAGE_SIZE);
> -	WARN_ON(host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HOST));
> +	hyp_poison_range(phys, size);
> +	WARN_ON(host_stage2_set_owner_locked(phys, size, PKVM_ID_HOST));
>  unlock_guest:
>  	guest_unlock_component(vm);
>  unlock_host:

[Severity: Medium]
Can holding vm_table_lock, host_mmu.lock, and vm->lock across
hyp_poison_range() for a PMD_SIZE mapping cause long EL2 stalls across the
host and unrelated VMs?

hyp_poison_range() zeroes up to 2 MiB (4K), 32 MiB (16K), or 512 MiB (64K)
and flushes dcache to PoC with interrupts masked at EL2.  Holding
vm_table_lock blocks pkvm_load_hyp_vcpu() and pkvm_put_hyp_vcpu() across all
VMs, while host_mmu.lock blocks host stage-2 faults across the host.

On 64K kernels, HAS_FIXBLOCK is undefined in arch/arm64/kvm/hyp/nvhe/mm.c,
so hyp_fixblock_map() falls back to PAGE_SIZE.  __apply_guest_page() then
iterates 8192 times per 512 MiB PMD, issuing 8192 broadcast vale2is TLBIs
under these locks.

A VMM running a THP-backed protected VM can reach this path through a GUP
syscall that accesses a donated page via the kernel linear mapping
(is_spurious_el1_translation_fault() -> pkvm_force_reclaim_guest_page()).

Once kvm_pgtable_stage2_annotate() completes, neither vm nor vm_table is
used again, so guest_unlock_component(vm) and hyp_spin_unlock(&vm_table_lock)
could be released before hyp_poison_range(), leaving only host_mmu.lock held
until host_stage2_set_owner_locked() finishes.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203115209.1690207-1-vdonnefort@google.com?part=13

  reply	other threads:[~2026-12-03 15:37 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 [this message]
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
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-248123@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.