Skip to content

Commit f91142c

Browse files
drm/ttm: nuke VM_MIXEDMAP on BO mappings v3
We discussed if that is really the right approach for quite a while now, but digging deeper into a bug report on arm turned out that this is actually horrible broken right now. The reason for this is that vmf_insert_mixed_prot() always tries to grab a reference to the underlaying page on architectures without ARCH_HAS_PTE_SPECIAL and as far as I can see also enabled GUP. So nuke using VM_MIXEDMAP here and use VM_PFNMAP instead. Also make sure to reject mappings without VM_SHARED. v2: reject COW mappings, merge function with only caller v3: adjust comment as suggested by Thomas Signed-off-by: Christian König <[email protected]> Bugs: https://gitlab.freedesktop.org/drm/amd/-/issues/1606#note_936174 Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Thomas Hellström <[email protected]>
1 parent ceb515b commit f91142c

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

drivers/gpu/drm/ttm/ttm_bo_vm.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
359359
* at arbitrary times while the data is mmap'ed.
360360
* See vmf_insert_mixed_prot() for a discussion.
361361
*/
362-
if (vma->vm_flags & VM_MIXEDMAP)
363-
ret = vmf_insert_mixed_prot(vma, address,
364-
__pfn_to_pfn_t(pfn, PFN_DEV),
365-
prot);
366-
else
367-
ret = vmf_insert_pfn_prot(vma, address, pfn, prot);
362+
ret = vmf_insert_pfn_prot(vma, address, pfn, prot);
368363

369364
/* Never error on prefaulted PTEs */
370365
if (unlikely((ret & VM_FAULT_ERROR))) {
@@ -411,15 +406,9 @@ vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot)
411406
pfn = page_to_pfn(page);
412407

413408
/* Prefault the entire VMA range right away to avoid further faults */
414-
for (address = vma->vm_start; address < vma->vm_end; address += PAGE_SIZE) {
415-
416-
if (vma->vm_flags & VM_MIXEDMAP)
417-
ret = vmf_insert_mixed_prot(vma, address,
418-
__pfn_to_pfn_t(pfn, PFN_DEV),
419-
prot);
420-
else
421-
ret = vmf_insert_pfn_prot(vma, address, pfn, prot);
422-
}
409+
for (address = vma->vm_start; address < vma->vm_end;
410+
address += PAGE_SIZE)
411+
ret = vmf_insert_pfn_prot(vma, address, pfn, prot);
423412

424413
return ret;
425414
}
@@ -560,8 +549,14 @@ static const struct vm_operations_struct ttm_bo_vm_ops = {
560549
.access = ttm_bo_vm_access,
561550
};
562551

563-
static void ttm_bo_mmap_vma_setup(struct ttm_buffer_object *bo, struct vm_area_struct *vma)
552+
int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
564553
{
554+
/* Enforce no COW since would have really strange behavior with it. */
555+
if (is_cow_mapping(vma->vm_flags))
556+
return -EINVAL;
557+
558+
ttm_bo_get(bo);
559+
565560
/*
566561
* Drivers may want to override the vm_ops field. Otherwise we
567562
* use TTM's default callbacks.
@@ -576,21 +571,8 @@ static void ttm_bo_mmap_vma_setup(struct ttm_buffer_object *bo, struct vm_area_s
576571

577572
vma->vm_private_data = bo;
578573

579-
/*
580-
* We'd like to use VM_PFNMAP on shared mappings, where
581-
* (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
582-
* but for some reason VM_PFNMAP + x86 PAT + write-combine is very
583-
* bad for performance. Until that has been sorted out, use
584-
* VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
585-
*/
586-
vma->vm_flags |= VM_MIXEDMAP;
574+
vma->vm_flags |= VM_PFNMAP;
587575
vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
588-
}
589-
590-
int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
591-
{
592-
ttm_bo_get(bo);
593-
ttm_bo_mmap_vma_setup(bo, vma);
594576
return 0;
595577
}
596578
EXPORT_SYMBOL(ttm_bo_mmap_obj);

0 commit comments

Comments
 (0)