Re: [PATCH v3 08/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation
From: Steven Price
Date: Wed Nov 18 2026 - 11:49:32 EST
On 17/11/2026 14:42, Fuad Tabba wrote:
> On Mon, 16 Nov 2026 16:43:54 +0000, Steven Price <steven.price@xxxxxxx> wrote:
> [...]
>> Define kvm_arch_has_private_mem() so generic KVM recognizes Realm VMs
>> as supporting private memory.
> [...]
>> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> [...]
>> @@ -1611,6 +1611,8 @@ struct kvm *kvm_arch_alloc_vm(void);
>>
>> #define kvm_vm_hyp_is_distrusting(kvm) ((kvm)->arch.vm_flavor >= __VM_DISTRUSTING_HYP)
>>
>> +#define kvm_arch_has_private_mem(kvm) kvm_vm_is_realm(kvm)
>
> Could the message say that defining the macro makes
> gmem_in_place_conversion true for every arm64 VM? One visible change
> is that KVM_SET_MEMORY_ATTRIBUTES2 on a non-Realm VM's guest_memfd
> returns -EINVAL instead of -ENOTTY.
True - I'll explicitly mention that the commit message just in case
anyone bisects that in the future.
> [...]
>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> [...]
>> @@ -2887,10 +2903,13 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
>> return 0;
>>
>> /*
>> - * Prevent userspace from creating a memory region outside of the IPA
>> - * space addressable by the KVM guest IPA space.
>> + * Realm shared IPAs alias the corresponding private IPAs, so memslots
>> + * must reside entirely in the canonical lower half of the IPA 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;
>> + if (kvm_vm_is_realm(kvm))
>> + ipa_limit >>= 1;
>> + if (new->base_gfn + new->npages > ipa_limit)
>> return -EFAULT;
>
> This check still applies to every VM, so I'd keep the old comment and
> add the Realm sentence to it.
Ack.
Thanks,
Steve