[PATCH v3] KVM: arm64: Reject guest_memfd memslots when the VM has MTE
Fuad Tabba
fuad.tabba at linux.dev
Tue Jul 21 03:51:46 PDT 2026
Hi Alex,
...
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index a5f9ee92f43e..53547fac5e37 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -8414,6 +8414,11 @@ When this capability is enabled all memory in memslots must be mapped as
> attempts to create a memslot with an invalid mmap will result in an
> -EINVAL return.
>
> +``guest_memfd``, even though is an anonymous file, is incompatible with MTE.
> +Attempting to create a memslot backed by ``guest_memfd`` when the MTE capability
> +is enabled, or attempting to enable the MTE capability after ``guest_memfd``
> +backed memslots have been created, will result in an error.
A few couple of smaller things first: "even though _it_ is an
anonymous file". "guest_memfd backed memslots" could be hyphenated,
and "will result in an error" could be "will result in an -EINVAL
return" to match the paragraph above it.
On the wording itself, I would lean towards "not supported" rather
than "incompatible". The gmem fault path currently doesn't handle MTE
tags, but I don't think there's a fundamental reason this can't be
changed in the future.
With these fixed:
Reviewed-by: Fuad Tabba <fuad.tabba at linux.dev>
Cheers,
/fuad
> When enabled the VMM may make use of the ``KVM_ARM_MTE_COPY_TAGS`` ioctl to
> perform a bulk copy of tags to/from the guest.
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 50adfff75be8..9a6c72a18672 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -149,14 +149,27 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> set_bit(KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER,
> &kvm->arch.flags);
> break;
> - case KVM_CAP_ARM_MTE:
> - mutex_lock(&kvm->lock);
> - if (system_supports_mte() && !kvm->created_vcpus) {
> - r = 0;
> - set_bit(KVM_ARCH_FLAG_MTE_ENABLED, &kvm->arch.flags);
> + case KVM_CAP_ARM_MTE: {
> + struct kvm_memory_slot *memslot;
> + int bkt;
> +
> + guard(mutex)(&kvm->lock);
> + if (!system_supports_mte() || kvm->created_vcpus)
> + break;
> +
> + r = 0;
> + guard(mutex)(&kvm->slots_lock);
> + kvm_for_each_memslot(memslot, bkt, kvm_memslots(kvm)) {
> + if (kvm_slot_has_gmem(memslot)) {
> + r = -EINVAL;
> + break;
> + }
> }
> - mutex_unlock(&kvm->lock);
> + if (r == 0)
> + set_bit(KVM_ARCH_FLAG_MTE_ENABLED, &kvm->arch.flags);
> break;
> +
> + }
> case KVM_CAP_ARM_SYSTEM_SUSPEND:
> r = 0;
> set_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags);
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 6c941aaa10c6..2d95203386ba 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -2652,6 +2652,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
> if (kvm_slot_has_gmem(new) && !kvm_memslot_is_gmem_only(new))
> return -EINVAL;
>
> + /* guest_memfd is incompatible with MTE. */
> + if (kvm_slot_has_gmem(new) && kvm_has_mte(kvm))
> + return -EINVAL;
> +
> hva = new->userspace_addr;
> reg_end = hva + (new->npages << PAGE_SHIFT);
>
>
> base-commit: 1590cf0329716306e948a8fc29f1d3ee87d3989f
> --
> 2.55.0
>
More information about the linux-arm-kernel
mailing list