Commit 8b93d1d7 authored by Daniel Vetter's avatar Daniel Vetter

drm/shmem-helper: Switch to vmf_insert_pfn

We want to stop gup, which isn't the case if we use vmf_insert_page
and VM_MIXEDMAP, because that does not set pte_special.

The motivation here is to stop get_user_pages from working on buffer
object mmaps in general. Quoting some discussion with Thomas:

On Thu, Jul 22, 2021 at 08:22:43PM +0200, Thomas Zimmermann wrote:
> Am 13.07.21 um 22:51 schrieb Daniel Vetter:
> > We want to stop gup, which isn't the case if we use vmf_insert_page
>
> What is gup?

get_user_pages. It pins memory wherever it is, which badly wreaks at least
ttm and could also cause trouble with cma allocations. In both cases
becaue we can't move/reuse these pages anymore.

Now get_user_pages fails when the memory isn't considered "normal", like
with VM_PFNMAP and using vm_insert_pfn. For consistency across all dma-buf
I'm trying (together with Christian König) to roll this out everywhere,
for fewer surprises.

E.g. for 5.14 iirc we merged a patch to do the same for ttm, where it
closes an actual bug (ttm gets really badly confused when there's suddenly
pinned pages where it thought it can move them).

cma allcoations already use VM_PFNMAP (because that's what dma_mmap is
using underneath), as is anything that's using remap_pfn_range. Worst case
we have to revert this patch for shmem helpers if it breaks something, but
I hope that's not the case. On the ttm side we've also had some fallout
that we needed to paper over with clever tricks.
v2: With this shmem gem helpers now definitely need CONFIG_MMU (0day)

v3: add more depends on MMU. For usb drivers this is a bit awkward,
but really it's correct: To be able to provide a contig mapping of
buffers to userspace on !MMU platforms we'd need to use the cma
helpers for these drivers on those platforms. As-is this wont work.

Also not exactly sure why vm_insert_page doesn't go boom, because that
definitely wont fly in practice since the pages are non-contig to
begin with.

v4: Explain the entire motivation a lot more (Thomas)
Acked-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210812131412.2487363-2-daniel.vetter@ffwll.ch
parent c7782443
...@@ -211,7 +211,7 @@ config DRM_KMS_CMA_HELPER ...@@ -211,7 +211,7 @@ config DRM_KMS_CMA_HELPER
config DRM_GEM_SHMEM_HELPER config DRM_GEM_SHMEM_HELPER
bool bool
depends on DRM depends on DRM && MMU
help help
Choose this if you need the GEM shmem helper functions Choose this if you need the GEM shmem helper functions
......
...@@ -542,7 +542,7 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf) ...@@ -542,7 +542,7 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf)
} else { } else {
page = shmem->pages[page_offset]; page = shmem->pages[page_offset];
ret = vmf_insert_page(vma, vmf->address, page); ret = vmf_insert_pfn(vma, vmf->address, page_to_pfn(page));
} }
mutex_unlock(&shmem->pages_lock); mutex_unlock(&shmem->pages_lock);
...@@ -612,7 +612,7 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) ...@@ -612,7 +612,7 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
return ret; return ret;
} }
vma->vm_flags |= VM_MIXEDMAP | VM_DONTEXPAND; vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND;
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
if (shmem->map_wc) if (shmem->map_wc)
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
config DRM_GUD config DRM_GUD
tristate "GUD USB Display" tristate "GUD USB Display"
depends on DRM && USB depends on DRM && USB && MMU
select LZ4_COMPRESS select LZ4_COMPRESS
select DRM_KMS_HELPER select DRM_KMS_HELPER
select DRM_GEM_SHMEM_HELPER select DRM_GEM_SHMEM_HELPER
......
...@@ -44,7 +44,7 @@ config DRM_CIRRUS_QEMU ...@@ -44,7 +44,7 @@ config DRM_CIRRUS_QEMU
config DRM_GM12U320 config DRM_GM12U320
tristate "GM12U320 driver for USB projectors" tristate "GM12U320 driver for USB projectors"
depends on DRM && USB depends on DRM && USB && MMU
select DRM_KMS_HELPER select DRM_KMS_HELPER
select DRM_GEM_SHMEM_HELPER select DRM_GEM_SHMEM_HELPER
help help
...@@ -53,7 +53,7 @@ config DRM_GM12U320 ...@@ -53,7 +53,7 @@ config DRM_GM12U320
config DRM_SIMPLEDRM config DRM_SIMPLEDRM
tristate "Simple framebuffer driver" tristate "Simple framebuffer driver"
depends on DRM depends on DRM && MMU
select DRM_GEM_SHMEM_HELPER select DRM_GEM_SHMEM_HELPER
select DRM_KMS_HELPER select DRM_KMS_HELPER
help help
......
...@@ -4,6 +4,7 @@ config DRM_UDL ...@@ -4,6 +4,7 @@ config DRM_UDL
depends on DRM depends on DRM
depends on USB depends on USB
depends on USB_ARCH_HAS_HCD depends on USB_ARCH_HAS_HCD
depends on MMU
select DRM_GEM_SHMEM_HELPER select DRM_GEM_SHMEM_HELPER
select DRM_KMS_HELPER select DRM_KMS_HELPER
help help
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment