Skip to content

Commit 337d5b5

Browse files
committed
Merge tag 'drm-misc-fixes-2023-02-09' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes
A fix for a circular refcounting in drm/client, one for a memory leak in amdgpu and a virtio fence fix when interrupted Signed-off-by: Dave Airlie <[email protected]> From: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20230209083600.7hi6roht6xxgldgz@houat
2 parents 4684f5c + 85e26dd commit 337d5b5

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,10 +1220,13 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
12201220
* next job actually sees the results from the previous one
12211221
* before we start executing on the same scheduler ring.
12221222
*/
1223-
if (!s_fence || s_fence->sched != sched)
1223+
if (!s_fence || s_fence->sched != sched) {
1224+
dma_fence_put(fence);
12241225
continue;
1226+
}
12251227

12261228
r = amdgpu_sync_fence(&p->gang_leader->explicit_sync, fence);
1229+
dma_fence_put(fence);
12271230
if (r)
12281231
return r;
12291232
}

drivers/gpu/drm/drm_client.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,17 @@ void drm_client_dev_restore(struct drm_device *dev)
233233

234234
static void drm_client_buffer_delete(struct drm_client_buffer *buffer)
235235
{
236-
struct drm_device *dev = buffer->client->dev;
237-
238236
if (buffer->gem) {
239237
drm_gem_vunmap_unlocked(buffer->gem, &buffer->map);
240238
drm_gem_object_put(buffer->gem);
241239
}
242240

243-
if (buffer->handle)
244-
drm_mode_destroy_dumb(dev, buffer->handle, buffer->client->file);
245-
246241
kfree(buffer);
247242
}
248243

249244
static struct drm_client_buffer *
250-
drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format)
245+
drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height,
246+
u32 format, u32 *handle)
251247
{
252248
const struct drm_format_info *info = drm_format_info(format);
253249
struct drm_mode_create_dumb dumb_args = { };
@@ -269,16 +265,15 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u
269265
if (ret)
270266
goto err_delete;
271267

272-
buffer->handle = dumb_args.handle;
273-
buffer->pitch = dumb_args.pitch;
274-
275268
obj = drm_gem_object_lookup(client->file, dumb_args.handle);
276269
if (!obj) {
277270
ret = -ENOENT;
278271
goto err_delete;
279272
}
280273

274+
buffer->pitch = dumb_args.pitch;
281275
buffer->gem = obj;
276+
*handle = dumb_args.handle;
282277

283278
return buffer;
284279

@@ -365,7 +360,8 @@ static void drm_client_buffer_rmfb(struct drm_client_buffer *buffer)
365360
}
366361

367362
static int drm_client_buffer_addfb(struct drm_client_buffer *buffer,
368-
u32 width, u32 height, u32 format)
363+
u32 width, u32 height, u32 format,
364+
u32 handle)
369365
{
370366
struct drm_client_dev *client = buffer->client;
371367
struct drm_mode_fb_cmd fb_req = { };
@@ -377,7 +373,7 @@ static int drm_client_buffer_addfb(struct drm_client_buffer *buffer,
377373
fb_req.depth = info->depth;
378374
fb_req.width = width;
379375
fb_req.height = height;
380-
fb_req.handle = buffer->handle;
376+
fb_req.handle = handle;
381377
fb_req.pitch = buffer->pitch;
382378

383379
ret = drm_mode_addfb(client->dev, &fb_req, client->file);
@@ -414,13 +410,24 @@ struct drm_client_buffer *
414410
drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format)
415411
{
416412
struct drm_client_buffer *buffer;
413+
u32 handle;
417414
int ret;
418415

419-
buffer = drm_client_buffer_create(client, width, height, format);
416+
buffer = drm_client_buffer_create(client, width, height, format,
417+
&handle);
420418
if (IS_ERR(buffer))
421419
return buffer;
422420

423-
ret = drm_client_buffer_addfb(buffer, width, height, format);
421+
ret = drm_client_buffer_addfb(buffer, width, height, format, handle);
422+
423+
/*
424+
* The handle is only needed for creating the framebuffer, destroy it
425+
* again to solve a circular dependency should anybody export the GEM
426+
* object as DMA-buf. The framebuffer and our buffer structure are still
427+
* holding references to the GEM object to prevent its destruction.
428+
*/
429+
drm_mode_destroy_dumb(client->dev, handle, client->file);
430+
424431
if (ret) {
425432
drm_client_buffer_delete(buffer);
426433
return ERR_PTR(ret);

drivers/gpu/drm/virtio/virtgpu_ioctl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
126126
void __user *user_bo_handles = NULL;
127127
struct virtio_gpu_object_array *buflist = NULL;
128128
struct sync_file *sync_file;
129-
int in_fence_fd = exbuf->fence_fd;
130129
int out_fence_fd = -1;
131130
void *buf;
132131
uint64_t fence_ctx;
@@ -152,13 +151,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
152151
ring_idx = exbuf->ring_idx;
153152
}
154153

155-
exbuf->fence_fd = -1;
156-
157154
virtio_gpu_create_context(dev, file);
158155
if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
159156
struct dma_fence *in_fence;
160157

161-
in_fence = sync_file_get_fence(in_fence_fd);
158+
in_fence = sync_file_get_fence(exbuf->fence_fd);
162159

163160
if (!in_fence)
164161
return -EINVAL;

include/drm/drm_client.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ struct drm_client_buffer {
126126
*/
127127
struct drm_client_dev *client;
128128

129-
/**
130-
* @handle: Buffer handle
131-
*/
132-
u32 handle;
133-
134129
/**
135130
* @pitch: Buffer pitch
136131
*/

include/uapi/drm/virtgpu_drm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct drm_virtgpu_map {
6464
__u32 pad;
6565
};
6666

67+
/* fence_fd is modified on success if VIRTGPU_EXECBUF_FENCE_FD_OUT flag is set. */
6768
struct drm_virtgpu_execbuffer {
6869
__u32 flags;
6970
__u32 size;

0 commit comments

Comments
 (0)