winsys/amdgpu: fix FD mismatch

The original fd was only used like this. Importing the ioctl wrappers
started using it for calling ioctls, which was incorrect.

Fixes: 049641ca54 - amd: import libdrm_amdgpu ioctl wrappers
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12208

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32356>
This commit is contained in:
Marek Olšák 2024-11-26 13:10:07 -05:00 committed by Marge Bot
parent 733e0ebf19
commit 9223528059
3 changed files with 10 additions and 7 deletions

View file

@ -1652,7 +1652,7 @@ static bool amdgpu_bo_get_handle(struct radeon_winsys *rws,
type = amdgpu_bo_handle_type_gem_flink_name;
break;
case WINSYS_HANDLE_TYPE_KMS:
if (sws->fd == aws->fd) {
if (sws->fd == aws->input_fd) {
whandle->handle = bo->kms_handle;
if (bo->is_shared)

View file

@ -427,13 +427,14 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
goto fail;
aws->dev = dev;
aws->fd = amdgpu_device_get_fd(dev);
/* The device fd might be different from the one we passed because of
* libdrm_amdgpu device dedup logic. This can happen if radv is initialized
* first.
* Get the correct fd or the buffer sharing will not work (see #3424).
*/
int device_fd = amdgpu_device_get_fd(dev);
if (!are_file_descriptions_equal(device_fd, fd)) {
if (!are_file_descriptions_equal(aws->fd, fd)) {
sws->kms_handles = _mesa_hash_table_create(NULL, kms_handle_hash,
kms_handle_equals);
if (!sws->kms_handles)
@ -442,9 +443,9 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
* we need it but we'd have to use os_same_file_description() to
* compare the fds.
*/
aws->fd = device_fd;
aws->input_fd = aws->fd;
} else {
aws->fd = sws->fd;
aws->input_fd = sws->fd;
}
aws->info.drm_major = drm_major;
aws->info.drm_minor = drm_minor;

View file

@ -50,7 +50,7 @@ struct amdgpu_cs;
*
* This fd tracking is useful for buffer sharing. As an example, if an app
* wants to use drmModeAddFB it'll need a KMS handle valid for its
* fd (== amdgpu_screen_winsys::fd). If both fds are identical, there's
* fd (== amdgpu_screen_winsys::input_fd). If both fds are identical, there's
* nothing to do: bo->u.real.kms_handle can be used directly
* (see amdgpu_bo_get_handle). If they're different, the BO has to be exported
* from the device fd as a dma-buf, then imported to the app fd to get the
@ -188,8 +188,10 @@ static_assert(sizeof(((struct amdgpu_seq_no_fences*)NULL)->valid_fence_mask) * 8
/* One struct amdgpu_winsys is created for one gpu in amdgpu_winsys_create(). */
struct amdgpu_winsys {
struct pipe_reference reference;
/* See comment above */
/* Returned by amdgpu_device_get_fd. */
int fd;
/* See comment above */
int input_fd;
/* Protected by bo_fence_lock. */
struct amdgpu_queue queues[AMDGPU_MAX_QUEUES];