Skip to content

Commit d89585f

Browse files
pccMarc Zyngier
authored andcommitted
KVM: arm64: unify the tests for VMAs in memslots when MTE is enabled
Previously we allowed creating a memslot containing a private mapping that was not VM_MTE_ALLOWED, but would later reject KVM_RUN with -EFAULT. Now we reject the memory region at memslot creation time. Since this is a minor tweak to the ABI (a VMM that created one of these memslots would fail later anyway), no VMM to my knowledge has MTE support yet, and the hardware with the necessary features is not generally available, we can probably make this ABI change at this point. Signed-off-by: Peter Collingbourne <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Steven Price <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d77e59a commit d89585f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

arch/arm64/kvm/mmu.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,19 @@ static void sanitise_mte_tags(struct kvm *kvm, kvm_pfn_t pfn,
11081108
}
11091109
}
11101110

1111+
static bool kvm_vma_mte_allowed(struct vm_area_struct *vma)
1112+
{
1113+
/*
1114+
* VM_SHARED mappings are not allowed with MTE to avoid races
1115+
* when updating the PG_mte_tagged page flag, see
1116+
* sanitise_mte_tags for more details.
1117+
*/
1118+
if (vma->vm_flags & VM_SHARED)
1119+
return false;
1120+
1121+
return vma->vm_flags & VM_MTE_ALLOWED;
1122+
}
1123+
11111124
static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
11121125
struct kvm_memory_slot *memslot, unsigned long hva,
11131126
unsigned long fault_status)
@@ -1284,9 +1297,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
12841297
}
12851298

12861299
if (fault_status != FSC_PERM && !device && kvm_has_mte(kvm)) {
1287-
/* Check the VMM hasn't introduced a new VM_SHARED VMA */
1288-
if ((vma->vm_flags & VM_MTE_ALLOWED) &&
1289-
!(vma->vm_flags & VM_SHARED)) {
1300+
/* Check the VMM hasn't introduced a new disallowed VMA */
1301+
if (kvm_vma_mte_allowed(vma)) {
12901302
sanitise_mte_tags(kvm, pfn, vma_pagesize);
12911303
} else {
12921304
ret = -EFAULT;
@@ -1730,12 +1742,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
17301742
if (!vma)
17311743
break;
17321744

1733-
/*
1734-
* VM_SHARED mappings are not allowed with MTE to avoid races
1735-
* when updating the PG_mte_tagged page flag, see
1736-
* sanitise_mte_tags for more details.
1737-
*/
1738-
if (kvm_has_mte(kvm) && vma->vm_flags & VM_SHARED) {
1745+
if (kvm_has_mte(kvm) && !kvm_vma_mte_allowed(vma)) {
17391746
ret = -EINVAL;
17401747
break;
17411748
}

0 commit comments

Comments
 (0)