]> git.dujemihanovic.xyz Git - linux.git/commit
drm: new helper: drm_gem_prime_handle_to_dmabuf()
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 2 Aug 2024 13:56:28 +0000 (09:56 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 10 Sep 2024 17:44:30 +0000 (13:44 -0400)
commitb2d4da31a1f40b05a61076efd4c79b88439003b7
tree37a37520741de98d766a78d626625cae997e1be7
parent81f7804ba84ee617ed594de934ed87bcc4f83531
drm: new helper: drm_gem_prime_handle_to_dmabuf()

Once something had been put into descriptor table, the only thing you
can do with it is returning descriptor to userland - you can't withdraw
it on subsequent failure exit, etc.  You certainly can't count upon
it staying in the same slot of descriptor table - another thread
could've played with close(2)/dup2(2)/whatnot.

drm_gem_prime_handle_to_fd() creates a dmabuf, allocates a descriptor
and attaches dmabuf's file to it (the last two steps are done
in dma_buf_fd()).  That's nice when all you are going to do is
passing a descriptor to userland.  If you just need to work with the
resulting object or have something else to be done that might fail,
drm_gem_prime_handle_to_fd() is racy.

The problem is analogous to one with anon_inode_getfd(), and solution
is similar to what anon_inode_getfile() provides.

Add drm_gem_prime_handle_to_dmabuf() - the "set dmabuf up" parts of
drm_gem_prime_handle_to_fd() without the descriptor-related ones.
Instead of inserting into descriptor table and returning the file
descriptor it just returns the struct file.

drm_gem_prime_handle_to_fd() becomes a wrapper for it.  Other users
will be introduced in the next commit.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/drm_prime.c
include/drm/drm_prime.h