Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google.com>
To: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org
Cc: joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com,
	yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org,
	kernel-team@android.com, fuad.tabba@linux.dev,
	qperret@google.com
Subject: Re: [PATCH v5 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator
Date: Wed, 30 Sep 2026 15:50:29 +0100	[thread overview]
Message-ID: <ar0htZydVZdB9zVk@google.com> (raw)
In-Reply-To: <20260901080941.997769-1-vdonnefort@google.com>

Gentle ping for this series, 

It's been fully reviewed by Fuad and is already based on 7.3-rc1.

-- 
Vincent

On Tue, Sep 01, 2026 at 09:09:23AM +0100, Vincent Donnefort wrote:
> pKVM historically lacked a dynamic memory allocator: all hypervisor-side
> VM and VCPU structures had to be sized on the host, allocated as
> contiguous pages and donated to the hypervisor.
> 
> This design tightly coupled the hypervisor's memory footprint to
> host-side constraints, complicated memory reclaim, and severely
> restricted VM scalability.
> 
> This patch series introduces a dynamically-mapped custom heap allocator
> (hyp_allocator) to the pKVM hypervisor. The initial users are the
> pkvm_hyp_vm and pkvm_hyp_vcpu structs, and the hypervisor tracing
> metadata.
> 
> In the near future, this heap allocator is expected to be leveraged to
> support SVE in protected VMs and in the distant future, it will also
> support dynamic device assignment.
> 
> By moving to a hypervisor-managed dynamic allocator, we also allow
> deduplicating the donation/reclaim path of EL2-private structures.
> 
> The main building blocks for this series are:
> 
> 1. pkvm_hyp_req:
> ----------------
> When the hypervisor heap allocator goes out of memory (-ENOMEM), it
> suspends the hypercall, embeds a PKVM_HYP_REQ_HYP_ALLOC top-up request
> into the SMCCC HVC return registers, and exits back to the host.
> 
> This building block will also be useful for the future huge-mapping
> support in protected guests, allowing EL2 to raise requests such as
> block splitting back to the host.
> 
> 2. hyp_allocator:
> ----------------
> This heap allocator manages a reserved VA space range, dynamically
> mapping and unmapping physical pages on-demand to minimise the pKVM
> hypervisor footprint. As memory is reclaimed and relinquished to the
> host, unmapped holes are introduced within the VA space. To prevent
> orphan mapped regions, neighboring unused chunks cannot be merged if
> they are separated by an unmapped region.
> 
> The allocator chunk metadata is stored directly into the VA space range.
> To minimize metadata overhead, chunks only link to each other via a
> relative 32-bit offset.
> 
> A simple hardening of the metadata is added via a simple 32-bit hash.
> 
> 3. shrinker:
> ------------
> As the heap allocator isn't reclaimed actively on VM or tracing
> teardown, a shrinker is added to allow the host to reclaim unused memory
> from the hypervisor when the host is under heavy memory pressure.
> 
> Changelog
> ---------
> 
> v5:
> 
>   - Remove unreachable !prev checks in hyp_allocator_destroy_chunk() (Fuad)
>   - Add kerneldoc to pkvm_call_hyp_req() (Fuad)
>   - Avoid duplicate handle___pkvm_hyp_alloc_selftest() definitions when !CONFIG_NVHE_EL2_DEBUG
>   - Chunk pkvm_hyp_reclaim() with cond_resched() to avoid blocking in EL2
>   - Allow shrinker to scan across all runtime topup IDs
>   - Reclaim chunks before draining allocator->mc in hyp_allocator_reclaim() (Fuad)
>   - Make is_ttbr1_addr() check in __kern_hyp_va() conditional to pKVM (Fuad)
>   - Rename pkvm_memcache to stage2_mc
>   - Rebased on 7.3-rc1
> 
> v4: https://lore.kernel.org/all/20260731143541.956291-1-vdonnefort@google.com/
> 
>   - Add kerneldoc to pkvm_remove_mappings
>   - Allow pkvm_private_va_range_pa() to work with block-level mappings (Sashiko)
>   - Add rollback and harden pkvm_map_private_va_range input (Sashiko)
>   - Add missing mc count into reclaimable memory
>   - Differentiate -ENOMEM from hyp_alloc in errno_to_smccc() (Sashiko)
>   - Collect Fuad's Tested-by
> 
> v3: https://lore.kernel.org/all/20260720171513.1415357-1-vdonnefort@google.com/
> 
>   - Remove unsafe WARN_ON(hyp_spin_is_locked(&pkvm_pgd_lock)) check in hyp_allocator_alloc() (Sashiko)
>   - Modify MIN_ALLOC_SIZE to 16-bytes to comply with FPSIMD alignment requirements (Sashiko)
>   - Allow hyp topup/reclaim HVCs pre-deprivilege
>   - Add enum symbols to pkvm_hyp_req_handle event (Fuad)
>   - Various clarification in commit descriptions (Fuad)
>   - Restore unmap_donated_memory() for PGD on error path (Fuad)
>   - Renamed __hyp_allocator_map -> pkvm_map_private_va_range (Fuad)
>   - Collected Fuad's Reviewed-by tags
>   - Rebased on 7.2-rc4
> 
> v2: https://lore.kernel.org/all/20260706175415.2604046-1-vdonnefort@google.com/
> 
>   - Rebased series on 7.2-rc2.
>   - Use scope-based hyp_spinlock.
>   - Fix best_missing/best_data_size priority in hyp_allocator_find_efficient_chunk() (Sashiko)
>   - Fix missing free_hyp_memcache() in pkvm_hyp_topup() (Sashiko)
>   - Fix unused selftest_init() warning when !CONFIG_NVHE_EL2_DEBUG (Sashiko)
>   - Fix missing shrinker_free() in teardown_hyp_mode() (Sashiko)
> 
> v1: https://lore.kernel.org/r/20260520152650.4107895-1-vdonnefort@google.com
> 
> Vincent Donnefort (18):
>   KVM: arm64: Add pkvm_private_va_range_pa
>   KVM: arm64: Add pkvm_remove_mappings
>   KVM: arm64: Add pkvm_map_private_va_range
>   KVM: arm64: Add a heap allocator for the pKVM hyp
>   KVM: arm64: Allow kvm_hyp_memcache usage outside of stage-2
>   KVM: arm64: Add pkvm_hyp_req infrastructure
>   KVM: arm64: Add PKVM_HYP_REQ_HYP_ALLOC request
>   KVM: arm64: Add reclaim interface for the pKVM heap alloc
>   KVM: arm64: Add selftests for the pKVM heap allocator
>   KVM: arm64: Add a shrinker for pKVM
>   KVM: arm64: Filter out non-kernel addresses in kern_hyp_va
>   KVM: arm64: Move hyp_vm refcount into the structure
>   KVM: arm64: Alloc pkvm_hyp_vm using pKVM heap allocator
>   KVM: arm64: Alloc pkvm_hyp_vcpu using pKVM heap allocator
>   KVM: arm64: Rename vCPU pkvm_memcache to stage2_mc
>   KVM: arm64: Reject hyp trace descriptors with fewer CPUs than
>     hyp_nr_cpus
>   KVM: arm64: Reject hyp trace descriptors with fewer than 3 pages
>   KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator
> 
>  arch/arm64/include/asm/kvm_asm.h           |    4 +
>  arch/arm64/include/asm/kvm_host.h          |   16 +-
>  arch/arm64/include/asm/kvm_mmu.h           |    3 +
>  arch/arm64/include/asm/kvm_pkvm.h          |  117 ++
>  arch/arm64/kvm/arm.c                       |    4 +-
>  arch/arm64/kvm/hyp/hyp-constants.c         |    2 -
>  arch/arm64/kvm/hyp/include/nvhe/alloc.h    |   28 +
>  arch/arm64/kvm/hyp/include/nvhe/mm.h       |    3 +
>  arch/arm64/kvm/hyp/include/nvhe/pkvm.h     |   19 +-
>  arch/arm64/kvm/hyp/include/nvhe/spinlock.h |    4 +
>  arch/arm64/kvm/hyp/nvhe/Makefile           |    2 +-
>  arch/arm64/kvm/hyp/nvhe/alloc.c            | 1211 ++++++++++++++++++++
>  arch/arm64/kvm/hyp/nvhe/hyp-main.c         |  125 +-
>  arch/arm64/kvm/hyp/nvhe/mem_protect.c      |   10 +-
>  arch/arm64/kvm/hyp/nvhe/mm.c               |   79 ++
>  arch/arm64/kvm/hyp/nvhe/pkvm.c             |  104 +-
>  arch/arm64/kvm/hyp/nvhe/setup.c            |    6 +
>  arch/arm64/kvm/hyp/nvhe/trace.c            |   70 +-
>  arch/arm64/kvm/hyp_trace.c                 |   15 +-
>  arch/arm64/kvm/mmu.c                       |    6 +-
>  arch/arm64/kvm/pkvm.c                      |  200 +++-
>  arch/arm64/kvm/trace_pkvm.h                |   45 +
>  22 files changed, 1915 insertions(+), 158 deletions(-)
>  create mode 100644 arch/arm64/kvm/hyp/include/nvhe/alloc.h
>  create mode 100644 arch/arm64/kvm/hyp/nvhe/alloc.c
>  create mode 100644 arch/arm64/kvm/trace_pkvm.h
> 
> 
> base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
> -- 
> 2.55.0.897.gb25b4bd76c-goog
> 


  parent reply	other threads:[~2026-09-30 14:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  8:09 [PATCH v5 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 01/18] KVM: arm64: Add pkvm_private_va_range_pa Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 02/18] KVM: arm64: Add pkvm_remove_mappings Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 03/18] KVM: arm64: Add pkvm_map_private_va_range Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 04/18] KVM: arm64: Add a heap allocator for the pKVM hyp Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 05/18] KVM: arm64: Allow kvm_hyp_memcache usage outside of stage-2 Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 06/18] KVM: arm64: Add pkvm_hyp_req infrastructure Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 07/18] KVM: arm64: Add PKVM_HYP_REQ_HYP_ALLOC request Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 08/18] KVM: arm64: Add reclaim interface for the pKVM heap alloc Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 09/18] KVM: arm64: Add selftests for the pKVM heap allocator Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 10/18] KVM: arm64: Add a shrinker for pKVM Vincent Donnefort
2026-09-01 17:30   ` Fuad Tabba
2026-09-01  8:09 ` [PATCH v5 11/18] KVM: arm64: Filter out non-kernel addresses in kern_hyp_va Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 12/18] KVM: arm64: Move hyp_vm refcount into the structure Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 13/18] KVM: arm64: Alloc pkvm_hyp_vm using pKVM heap allocator Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 14/18] KVM: arm64: Alloc pkvm_hyp_vcpu " Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 15/18] KVM: arm64: Rename vCPU pkvm_memcache to stage2_mc Vincent Donnefort
2026-09-01 17:59   ` Fuad Tabba
2026-09-01  8:09 ` [PATCH v5 16/18] KVM: arm64: Reject hyp trace descriptors with fewer CPUs than hyp_nr_cpus Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 17/18] KVM: arm64: Reject hyp trace descriptors with fewer than 3 pages Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 18/18] KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator Vincent Donnefort
2026-09-30 14:50 ` Vincent Donnefort [this message]
2026-10-01  9:22   ` [PATCH v5 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator Marc Zyngier
2026-10-01  9:54     ` Marc Zyngier

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=ar0htZydVZdB9zVk@google.com \
    --to=vdonnefort@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=qperret@google.com \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox