Re: [PATCH v6 07/11] KVM: arm64: CCA: Restrict Realm memslots to the lower IPA half

From: Kohei Enju

Date: Fri Dec 04 2026 - 10:48:36 EST


On 12/04 11:57, Steven Price wrote:
> From: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
>
> The upper half of a Realm's IPA space aliases its lower, protected
> half. Restrict memslots to the lower half so a memslot cannot be
> created in the shared alias.
>
> Keep the existing post-creation move/delete restriction scoped to
> pKVM. Protected VMs, including Realms, continue to reject dirty
> logging and read-only memslots.
>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
> Signed-off-by: Steven Price <steven.price@xxxxxxx>
> Reviewed-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
>
> ---
> Changes since v4:
> - Remove the Realm guest_memfd memslot change restriction; private
> Realm faults now validate guest_memfd backing and attributes.
> - Split out private-memory support and drop the unused early
> memslot validation hook.
>
> Changes since v3:
> - Explain the arm64-wide in-place conversion effect and keep the
> general IPA limit comment.
>
> Changes since v1:
> - Preserve private mappings if KVM invalidates a Realm guest_memfd
> slot before the prepare hook rejects its deletion.
> ---
> arch/arm64/kvm/mmu.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 37adc20f0042..ce7cea447f58 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -2860,11 +2860,13 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
> enum kvm_mr_change change)
> {
> hva_t hva, reg_end;
> + gfn_t ipa_limit;
> int ret = 0;
>
> if (kvm_vm_is_protected(kvm)) {
> /* Cannot modify memslots once a pVM has run. */
> - if (pkvm_hyp_vm_is_created(kvm) &&
> + if (kvm->arch.vm_flavor == VM_PROTECTED_PKVM &&
> + pkvm_hyp_vm_is_created(kvm) &&
> (change == KVM_MR_DELETE || change == KVM_MR_MOVE)) {
> return -EPERM;
> }
> @@ -2881,9 +2883,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
>
> /*
> * Prevent userspace from creating a memory region outside of the IPA
> - * space addressable by the KVM guest IPA space.
> + * space addressable by the KVM guest IPA space. Realm shared IPAs alias
> + * the corresponding private IPAs, so Realm memslots must reside entirely
> + * in the lower half of that space.
> */
> - if ((new->base_gfn + new->npages) > (kvm_phys_size(&kvm->arch.mmu) >> PAGE_SHIFT))
> + ipa_limit = kvm_phys_size(&kvm->arch.mmu) >> PAGE_SHIFT;

Not a big deal, but if you resend this series, how about renaming
ipa_limit to gfn_limit? The current name is a bit confusing to me
because the value is GFNs rather than bytes.

Thanks,
Kohei

> + if (kvm_vm_is_realm(kvm))
> + ipa_limit >>= 1;
> + if (new->base_gfn + new->npages > ipa_limit)
> return -EFAULT;
>
> /*
> --
> 2.43.0
>