Skip to content

Commit ebbcaec

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Fix MTE flag initialization for protected VMs
The function pkvm_init_features_from_host() initializes guest features, propagating them from the host. The logic to propagate KVM_ARCH_FLAG_MTE_ENABLED (Memory Tagging Extension) has a couple of issues. First, the check was in the common path, before the divergence for protected and non-protected VMs. For non-protected VMs, this was unnecessary, as 'kvm->arch.flags' is completely overwritten by host_arch_flags immediately after, which already contains the MTE flag. For protected VMs, this was setting the flag even if the feature is not allowed. Second, the check was reading 'host_kvm->arch.flags' instead of using the local 'host_arch_flags', which is read once from the host flags. Fix these by moving the MTE flag check inside the protected-VM-only path, checking if the feature is allowed, and changing it to use the correct host_arch_flags local variable. This ensures non-protected VMs get the flag via the bulk copy, and protected VMs get it via an explicit check. Fixes: b7f345f ("KVM: arm64: Fix FEAT_MTE in pKVM") Reviewed-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://patch.msgid.link/20251211104710.151771-4-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent e913c7c commit ebbcaec

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc
340340
/* Preserve the vgic model so that GICv3 emulation works */
341341
hyp_vm->kvm.arch.vgic.vgic_model = host_kvm->arch.vgic.vgic_model;
342342

343-
if (test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &host_kvm->arch.flags))
344-
set_bit(KVM_ARCH_FLAG_MTE_ENABLED, &kvm->arch.flags);
345-
346343
/* No restrictions for non-protected VMs. */
347344
if (!kvm_vm_is_protected(kvm)) {
348345
hyp_vm->kvm.arch.flags = host_arch_flags;
@@ -357,6 +354,9 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc
357354
return;
358355
}
359356

357+
if (kvm_pvm_ext_allowed(KVM_CAP_ARM_MTE))
358+
kvm->arch.flags |= host_arch_flags & BIT(KVM_ARCH_FLAG_MTE_ENABLED);
359+
360360
bitmap_zero(allowed_features, KVM_VCPU_MAX_FEATURES);
361361

362362
set_bit(KVM_ARM_VCPU_PSCI_0_2, allowed_features);

0 commit comments

Comments
 (0)