From: sashiko-bot@kernel.org
To: "Steven Price" <steven.price@arm.com>,
kvm@vger.kernel.org, kvmarm@lists.linux.dev
Cc: "Oliver Upton" <oupton@kernel.org>, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v3 09/11] KVM: arm64: CCA: Support runtime faulting of memory
Date: Mon, 16 Nov 2026 17:31:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-217436@kernel.org> (raw)
In-Reply-To: <20261116164358.142785-10-steven.price@arm.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] KVM: arm64: KVM_CAP_PRE_FAULT_MEMORY advertised for Realm VMs
- [Medium] KVM: arm64: missing unmap on partial failure in
realm_map_unprotected()
- [Low] KVM: arm64: unhandled exec fault on shared Realm IPA in
gmem_abort() and user_mem_abort()
--
commit 5a0919ef6adc946a1afb4f6ad7cf84e5573597f3
Author: Steven Price <steven.price@arm.com>
KVM: arm64: CCA: Support runtime faulting of memory
This commit adds runtime stage-2 fault handling for Realm VMs, delegating
and mapping private guest_memfd pages in the protected IPA region and
mapping shared pages in the unprotected IPA region via the RMM.
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 0db3c293fdd52..9b371159be92c 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
[ ... ]
> @@ -1846,6 +1882,16 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd,
> goto out_unlock;
> }
>
> + switch (kvm->arch.vm_flavor) {
> + case VM_REALM:
> + prot &= ~KVM_PGTABLE_PROT_X;
> + ret = realm_map_ipa(kvm, s2fd->fault_ipa, s2vi.pfn,
> + PAGE_SIZE, prot, memcache);
> + goto out_unlock;
> + default:
> + break;
> + }
> +
[ ... ]
> @@ -2242,12 +2289,15 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,
> if (!perm_fault_granule && !s2vi->map_non_cacheable && kvm_has_mte(kvm))
> sanitise_mte_tags(kvm, pfn, mapping_size);
>
> - /*
> - * Under the premise of getting a FSC_PERM fault, we just need to relax
> - * permissions only if mapping_size equals perm_fault_granule. Otherwise,
> - * kvm_pgtable_stage2_map() should be called to change block size.
> - */
> - if (mapping_size == perm_fault_granule) {
> + if (kvm_vm_is_realm(kvm)) {
> + ret = realm_map_ipa(kvm, s2fd->fault_ipa, pfn, mapping_size,
> + prot, memcache);
[Severity: Low]
This question rests on an architecture detail that could not be confirmed
from the kernel source: can a Realm guest instruction fetch from an
unprotected (shared) IPA exit to the host as a stage-2 instruction abort
that reaches kvm_handle_guest_abort()?
If so, unprotected RTT mappings only encode RMI_S2AP_DIRECT_READ and
RMI_S2AP_DIRECT_WRITE and cannot grant execute permission, but neither
gmem_abort() nor user_mem_abort() rejects kvm_s2_fault_is_exec(s2fd) with
-ENOEXEC to inject an instruction abort. Instead, realm_map_unprotected()
installs a non-executable mapping, and on subsequent instruction permission
faults at the same IPA where level >= req_level, unmaps and remaps the page
with the same non-executable permissions and returns 0 in an endless fault
loop.
[ ... ]
> @@ -3155,7 +3217,7 @@ pre_fault_bytes_consumed(gpa_t gpa, unsigned long granule_size,
>
> int kvm_arch_pre_fault_allowed(struct kvm_vcpu *vcpu)
> {
> - if (is_protected_kvm_enabled())
> + if (is_protected_kvm_enabled() || kvm_vm_is_realm(vcpu->kvm))
> return -EOPNOTSUPP;
> if (!kvm_vcpu_initialized(vcpu))
> return -ENOEXEC;
[Severity: Medium]
Should kvm_vm_ioctl_check_extension() also report 0 for
KVM_CAP_PRE_FAULT_MEMORY when kvm && kvm_vm_is_realm(kvm)?
Currently kvm_vm_ioctl_check_extension() only gates capabilities on
is_protected_kvm_enabled() and otherwise unconditionally sets r = 1 for
KVM_CAP_PRE_FAULT_MEMORY, advertising the capability on a Realm VM file
descriptor even though KVM_PRE_FAULT_MEMORY always fails here with
-EOPNOTSUPP.
> diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
> index 838f95c201ada..4cacb9fe000f4 100644
> --- a/arch/arm64/kvm/rmi.c
> +++ b/arch/arm64/kvm/rmi.c
[ ... ]
> +static int realm_map_unprotected(struct kvm *kvm,
> + unsigned long ipa,
> + kvm_pfn_t pfn,
> + unsigned long size,
> + enum kvm_pgtable_prot prot,
> + struct kvm_mmu_memory_cache *memcache)
> +{
[ ... ]
> + while (ipa < ipa_top) {
> + unsigned long range_desc = addr_range_desc(realm, ipa, phys,
> + ipa_top - ipa,
> + RMI_OP_MEM_UNDELEGATED);
> + unsigned long call_top = ipa + RMI_ADDR_RANGE_COUNT(range_desc) *
> + rmi_addr_block_size_to_bytes(RMI_ADDR_RANGE_BLOCK_SIZE(range_desc));
> + unsigned long out_top;
> +
> + ret = rmi_rtt_unprot_map(rd, ipa, call_top, flags, range_desc,
> + &out_top);
> + if (ret < 0)
> + return ret;
> +
> + if (ret) {
> + /* Create missing RTTs and retry */
> + int level = RMI_RESULT_DATA_LEVEL(ret);
> + int req_level = KVM_PGTABLE_LAST_LEVEL -
> + RMI_ADDR_RANGE_BLOCK_SIZE(range_desc);
> +
> + if (RMI_RESULT_STATUS(ret) != RMI_ERROR_RTT ||
> + ++retries > KVM_PGTABLE_LAST_LEVEL + 2)
> + return -ENXIO;
> +
> + /* Replace an existing mapping to update its permissions. */
> + if (level >= req_level) {
> + realm_unmap_shared_range(kvm, ipa, ipa_top, false,
> + memcache);
> + continue;
> + }
> +
> + ret = realm_create_rtt_levels(realm, ipa, level,
> + req_level,
> + memcache);
> + if (ret)
> + return ret;
> +
> + continue;
> + }
> +
> + /* Retry the fault after releasing mmu_lock to service the IRQ. */
> + if (out_top == ipa)
> + return -EAGAIN;
> + if (WARN_ON_ONCE(out_top < ipa || out_top > call_top))
> + return -ENXIO;
> +
> + phys += out_top - ipa;
> + ipa = out_top;
> + retries = 0;
> + }
[Severity: Medium]
Can a multi-iteration call to realm_map_unprotected() leave a writable
prefix mapped when a later iteration fails or returns -EAGAIN?
For a Realm with a 32- to 34-bit IPA space on 4KB pages, get_start_level()
is 2, so addr_range_desc() caps rmi_size at 1 (PMD_SIZE). When a shared
memslot is backed by a 1GB hugetlbfs VMA, kvm_s2_fault_map() passes
mapping_size = PUD_SIZE and this loop runs across multiple 2MB iterations.
If an iteration after the first is interrupted (out_top == ipa) or hits an
error, realm_map_unprotected() returns non-zero without unmapping the
already-installed prefix (unlike realm_map_protected()). kvm_s2_fault_map()
then passes !!ret (unused = true) to kvm_release_faultin_page() and skips
mark_page_dirty_in_slot(), so if the faulting IPA lies in the mapped prefix,
the guest can write to the page without marking the host folio dirty.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116164358.142785-1-steven.price@arm.com?part=9
next prev parent reply other threads:[~2026-11-16 17:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 16:43 [PATCH v3 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-11-16 16:43 ` [PATCH v3 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot Steven Price
2026-11-16 16:43 ` [PATCH v3 02/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-11-16 16:43 ` [PATCH v3 03/11] KVM: arm64: Handle attributes in stage2_unmap_range Steven Price
2026-11-16 16:43 ` [PATCH v3 04/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-11-16 16:43 ` [PATCH v3 05/11] KVM: arm64: CCA: Tear down RTTs Steven Price
2026-11-16 17:08 ` sashiko-bot
2026-11-16 16:43 ` [PATCH v3 06/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-11-16 17:21 ` sashiko-bot
2026-11-16 16:43 ` [PATCH v3 07/11] KVM: Allow architectures to reject memslot changes before invalidation Steven Price
2026-11-16 16:43 ` [PATCH v3 08/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation Steven Price
2026-11-16 16:43 ` [PATCH v3 09/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-11-16 17:31 ` sashiko-bot [this message]
2026-11-16 16:43 ` [PATCH v3 10/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-11-16 16:43 ` [PATCH v3 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price
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-217436@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=steven.price@arm.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