Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/prime: reject DMA-BUF attach when get_sg_table is missing

drm_gem_map_dma_buf() requires drm_gem_object_funcs.get_sg_table
to be implemented, or else WARNs.

Allow drivers to leave this hook unimplemented to implement purely
local DMA-BUFs (ie, DMA-BUFs which cannot be imported anywhere
else but the device which allocated them). In that case, reject
imports to other devices in drm_gem_map_attach().

v2: new patch

v3: use ENOSYS

Signed-off-by: Simon Ser <contact@emersion.fr>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Tian Tao <tiantao6@hisilicon.com>
Cc: Maxime Ripard <maxime@cerno.tech>
Cc: Hans de Goede <hdegoede@redhat.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230302143502.500661-1-contact@emersion.fr

+5 -1
+5 -1
drivers/gpu/drm/drm_prime.c
··· 544 544 * Optional pinning of buffers is handled at dma-buf attach and detach time in 545 545 * drm_gem_map_attach() and drm_gem_map_detach(). Backing storage itself is 546 546 * handled by drm_gem_map_dma_buf() and drm_gem_unmap_dma_buf(), which relies on 547 - * &drm_gem_object_funcs.get_sg_table. 547 + * &drm_gem_object_funcs.get_sg_table. If &drm_gem_object_funcs.get_sg_table is 548 + * unimplemented, exports into another device are rejected. 548 549 * 549 550 * For kernel-internal access there's drm_gem_dmabuf_vmap() and 550 551 * drm_gem_dmabuf_vunmap(). Userspace mmap support is provided by ··· 583 582 struct dma_buf_attachment *attach) 584 583 { 585 584 struct drm_gem_object *obj = dma_buf->priv; 585 + 586 + if (!obj->funcs->get_sg_table) 587 + return -ENOSYS; 586 588 587 589 return drm_gem_pin(obj); 588 590 }