Re: [PATCH v6 10/11] KVM: arm64: CCA: Support runtime faulting of memory
From: Steven Price
Date: Fri Dec 04 2026 - 11:27:17 EST
On 04/12/2026 15:32, Kohei Enju wrote:
> On 12/04 11:57, Steven Price wrote:
>> At runtime, if the realm guest accesses an IPA without a stage-2
>> mapping, then KVM fixes up the stage-2 mapping for the backing memory.
>>
>> For memory in the lower (protected) region of IPA, verify that the
>> corresponding guest_memfd page is private before delegating to the RMM.
>> The RMM then maps the delegated page into the Realm.
>>
>> For memory in the upper (shared) IPA region, map the backing page as
>> non-secure memory. Check that a guest_memfd page is shared when the
>> fault uses guest_memfd; ordinary userspace-backed memslots can only be
>> mapped at unprotected IPAs and follow the normal user memory fault path.
>>
>> If the fault IPA and guest_memfd attributes disagree then exit to
>> userspace with KVM_EXIT_MEMORY_FAULT so the VMM can perform the required
>> conversion. If a shared IPA has no memslot, KVM follows the existing
>> MMIO or abort-injection path. The latter can result in injecting a SEA
>> to the guest.
>>
>> Realm faults may need to create RTTs, including when updating a
>> mapping after a permission fault. Take the write side of mmu_lock
>> and top up the MMU cache for these faults. Do not pre-fault Realm
>> memory.
>
> Hello Steve,
>
> Not a review comment, but just a question for clarification.
>
> My understanding is that this series and the following ones aim to
> provide basic CCA/KVM functionality, leaving out optional features for
> the initial upstream support.
>
> I've been looking into supporting pre-faulting for CCA/KVM in the
> future, and I'm not aware of any architectural blockers.
>
> Are you aware of any potential blockers or limitations that might
> prevent us from supporting pre-faulting in the future, or is it simply
> being left out for now as an *optional* feature, as I assume?
(I assume you mean stage-2 pre-faulting - i.e. populating the guest's
IPA-to-PA translations with KVM_PRE_FAULT_MEMORY, pre-faulting the
guest_memfd itself isn't specific to CCA.)
There's nothing architectural preventing pre-faulting. The host is free
to proactively map the protected memory into the guest before the first
fault.
My reasons for leaving it out now are:
* It's obviously an "optional" feature - and I'm trying to focus on
getting enough support to boot a guest before looking at more features.
* As a feature it could hide bugs - faulting is the more complex path,
so I've wanted to focus testing on that path rather than the pre-fault
path which is naturally less racy.
* It's a performance feature and I'm currently doing most of my testing
on a model. So I've no way of meaningfully telling whether it's actually
useful in reality. Although my suspicion is that it could turn out to be
important.
Note that KVM_PRE_FAULT_MEMORY is a VCPU ioctl, but the RMI API executes
it on the realm descriptor - so I'm not sure how much benefit there
would be to running multiple in parallel.
My assumption is that KVM_PRE_FAULT_MEMORY would be treated as a "first
VCPU run" and would trigger the realm setup (kvm_activate_realm()), but
that's certainly an area of uAPI that needs nailing down.
Let me know if you do come up with an implementation - hopefully it
won't be too long before we move on past the basic functionality.
Thanks,
Steve