Skip to contentSkip to conversation

drm/virtio: exbuf->fence_fd unmodified on interrupted wait

PATCH Applied Ryan Neph 2 participants 2 messages Feb 3, 2023 – Feb 6, 2023

Subsystems (3)
lore
Share & tools
lore

Ryan Neph

author
#0 lore raw

PATCH v2 1/1 drm/virtio: exbuf->fence_fd unmodified on interrupted wait

An interrupted dma_fence_wait() becomes an -ERESTARTSYS returned to userspace ioctl(DRM_IOCTL_VIRTGPU_EXECBUFFER) calls, prompting to retry the ioctl(), but the passed exbuf->fence_fd has been reset to -1, making the retry attempt fail at sync_file_get_fence().

The uapi for DRM_IOCTL_VIRTGPU_EXECBUFFER is changed to retain the passed value for exbuf->fence_fd when returning anything besides a successful result from the ioctl.

Fixes 2cd7b6f08bc4 ("drm/virtio: add in/out fence support for explicit synchronization")

---

Changes in v2:
- No longer modifies exbuf->fence_fd unless DRM_IOCTL_VIRTGPU_EXECBUFFER succeeds.
- Added r-b tags (Rob/Dmitry) from v1.

 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +----
 include/uapi/drm/virtgpu_drm.h         | 1 +
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1 -4
index 9f4a90493aea..da45215a933d 100644
@@ -126,7 +126,6 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	void __user *user_bo_handles = NULL;
 	struct virtio_gpu_object_array *buflist = NULL;
 	struct sync_file *sync_file;
-	int in_fence_fd = exbuf->fence_fd;
 	int out_fence_fd = -1;
 	void *buf;
 	uint64_t fence_ctx;
@@ -152,13 +151,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 		ring_idx = exbuf->ring_idx;
 	}
 
-	exbuf->fence_fd = -1;
-
 	virtio_gpu_create_context(dev, file);
 	if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
 		struct dma_fence *in_fence;
 
-		in_fence = sync_file_get_fence(in_fence_fd);
+		in_fence = sync_file_get_fence(exbuf->fence_fd);
 
 		if (!in_fence)
 			return -EINVAL;
include/uapi/drm/virtgpu_drm.h +1 -0
index 0512fde5e697..7b158fcb02b4 100644
@@ -64,6 +64,7 @@ struct drm_virtgpu_map {
 	__u32 pad;
 };
 
+/* fence_fd is modified on success if VIRTGPU_EXECBUF_FENCE_FD_OUT flag is set. */
 struct drm_virtgpu_execbuffer {
 	__u32 flags;
 	__u32 size;
Signature · 1 line
2.39.1.519.gcb327c4b5f-goog
maintainer Applied
#1 lore raw
Quoted 14 lines · Ryan Neph

An interrupted dma_fence_wait() becomes an -ERESTARTSYS returned to userspace ioctl(DRM_IOCTL_VIRTGPU_EXECBUFFER) calls, prompting to retry the ioctl(), but the passed exbuf->fence_fd has been reset to -1, making the retry attempt fail at sync_file_get_fence().

The uapi for DRM_IOCTL_VIRTGPU_EXECBUFFER is changed to retain the passed value for exbuf->fence_fd when returning anything besides a successful result from the ioctl.

Fixes 2cd7b6f08bc4 ("drm/virtio: add in/out fence support for explicit synchronization")
Quoted 6 lines

---

Changes in v2:
- No longer modifies exbuf->fence_fd unless DRM_IOCTL_VIRTGPU_EXECBUFFER succeeds.
- Added r-b tags (Rob/Dmitry) from v1.

Thanks! Applied to misc-fixes

Signature · 2 lines
Best regards,
Dmitry