Skip to content

Commit 1152b16

Browse files
committed
Merge tag 'drm-misc-fixes-2021-12-02' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes
Switch back to drm_poll for virtio, multiple fixes (memory leak, improper error check, some functional fixes too) for vc4, memory leak fix in dma-buf, Signed-off-by: Dave Airlie <[email protected]> From: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20211202084440.u3b7lbeulj7k3ltg@houat
2 parents 52e81b6 + 679d94c commit 1152b16

File tree

6 files changed

+28
-66
lines changed

6 files changed

+28
-66
lines changed

drivers/dma-buf/heaps/system_heap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static void system_heap_dma_buf_release(struct dma_buf *dmabuf)
290290
int i;
291291

292292
table = &buffer->sg_table;
293-
for_each_sg(table->sgl, sg, table->nents, i) {
293+
for_each_sgtable_sg(table, sg, i) {
294294
struct page *page = sg_page(sg);
295295

296296
__free_pages(page, compound_order(page));

drivers/gpu/drm/vc4/vc4_kms.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ static void vc4_atomic_commit_tail(struct drm_atomic_state *state)
337337
struct drm_device *dev = state->dev;
338338
struct vc4_dev *vc4 = to_vc4_dev(dev);
339339
struct vc4_hvs *hvs = vc4->hvs;
340-
struct drm_crtc_state *old_crtc_state;
341340
struct drm_crtc_state *new_crtc_state;
342341
struct drm_crtc *crtc;
343342
struct vc4_hvs_state *old_hvs_state;
343+
unsigned int channel;
344344
int i;
345345

346346
for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
@@ -353,30 +353,32 @@ static void vc4_atomic_commit_tail(struct drm_atomic_state *state)
353353
vc4_hvs_mask_underrun(dev, vc4_crtc_state->assigned_channel);
354354
}
355355

356-
if (vc4->hvs->hvs5)
357-
clk_set_min_rate(hvs->core_clk, 500000000);
358-
359356
old_hvs_state = vc4_hvs_get_old_global_state(state);
360-
if (!old_hvs_state)
357+
if (IS_ERR(old_hvs_state))
361358
return;
362359

363-
for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) {
364-
struct vc4_crtc_state *vc4_crtc_state =
365-
to_vc4_crtc_state(old_crtc_state);
366-
unsigned int channel = vc4_crtc_state->assigned_channel;
360+
for (channel = 0; channel < HVS_NUM_CHANNELS; channel++) {
361+
struct drm_crtc_commit *commit;
367362
int ret;
368363

369-
if (channel == VC4_HVS_CHANNEL_DISABLED)
364+
if (!old_hvs_state->fifo_state[channel].in_use)
370365
continue;
371366

372-
if (!old_hvs_state->fifo_state[channel].in_use)
367+
commit = old_hvs_state->fifo_state[channel].pending_commit;
368+
if (!commit)
373369
continue;
374370

375-
ret = drm_crtc_commit_wait(old_hvs_state->fifo_state[channel].pending_commit);
371+
ret = drm_crtc_commit_wait(commit);
376372
if (ret)
377373
drm_err(dev, "Timed out waiting for commit\n");
374+
375+
drm_crtc_commit_put(commit);
376+
old_hvs_state->fifo_state[channel].pending_commit = NULL;
378377
}
379378

379+
if (vc4->hvs->hvs5)
380+
clk_set_min_rate(hvs->core_clk, 500000000);
381+
380382
drm_atomic_helper_commit_modeset_disables(dev, state);
381383

382384
vc4_ctm_commit(vc4, state);
@@ -410,8 +412,8 @@ static int vc4_atomic_commit_setup(struct drm_atomic_state *state)
410412
unsigned int i;
411413

412414
hvs_state = vc4_hvs_get_new_global_state(state);
413-
if (!hvs_state)
414-
return -EINVAL;
415+
if (WARN_ON(IS_ERR(hvs_state)))
416+
return PTR_ERR(hvs_state);
415417

416418
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
417419
struct vc4_crtc_state *vc4_crtc_state =
@@ -668,12 +670,6 @@ vc4_hvs_channels_duplicate_state(struct drm_private_obj *obj)
668670

669671
for (i = 0; i < HVS_NUM_CHANNELS; i++) {
670672
state->fifo_state[i].in_use = old_state->fifo_state[i].in_use;
671-
672-
if (!old_state->fifo_state[i].pending_commit)
673-
continue;
674-
675-
state->fifo_state[i].pending_commit =
676-
drm_crtc_commit_get(old_state->fifo_state[i].pending_commit);
677673
}
678674

679675
return &state->base;
@@ -762,8 +758,8 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev,
762758
unsigned int i;
763759

764760
hvs_new_state = vc4_hvs_get_global_state(state);
765-
if (!hvs_new_state)
766-
return -EINVAL;
761+
if (IS_ERR(hvs_new_state))
762+
return PTR_ERR(hvs_new_state);
767763

768764
for (i = 0; i < ARRAY_SIZE(hvs_new_state->fifo_state); i++)
769765
if (!hvs_new_state->fifo_state[i].in_use)

drivers/gpu/drm/virtio/virtgpu_drv.c

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -157,36 +157,6 @@ static void virtio_gpu_config_changed(struct virtio_device *vdev)
157157
schedule_work(&vgdev->config_changed_work);
158158
}
159159

160-
static __poll_t virtio_gpu_poll(struct file *filp,
161-
struct poll_table_struct *wait)
162-
{
163-
struct drm_file *drm_file = filp->private_data;
164-
struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv;
165-
struct drm_device *dev = drm_file->minor->dev;
166-
struct virtio_gpu_device *vgdev = dev->dev_private;
167-
struct drm_pending_event *e = NULL;
168-
__poll_t mask = 0;
169-
170-
if (!vgdev->has_virgl_3d || !vfpriv || !vfpriv->ring_idx_mask)
171-
return drm_poll(filp, wait);
172-
173-
poll_wait(filp, &drm_file->event_wait, wait);
174-
175-
if (!list_empty(&drm_file->event_list)) {
176-
spin_lock_irq(&dev->event_lock);
177-
e = list_first_entry(&drm_file->event_list,
178-
struct drm_pending_event, link);
179-
drm_file->event_space += e->event->length;
180-
list_del(&e->link);
181-
spin_unlock_irq(&dev->event_lock);
182-
183-
kfree(e);
184-
mask |= EPOLLIN | EPOLLRDNORM;
185-
}
186-
187-
return mask;
188-
}
189-
190160
static struct virtio_device_id id_table[] = {
191161
{ VIRTIO_ID_GPU, VIRTIO_DEV_ANY_ID },
192162
{ 0 },
@@ -226,17 +196,7 @@ MODULE_AUTHOR("Dave Airlie <[email protected]>");
226196
MODULE_AUTHOR("Gerd Hoffmann <[email protected]>");
227197
MODULE_AUTHOR("Alon Levy");
228198

229-
static const struct file_operations virtio_gpu_driver_fops = {
230-
.owner = THIS_MODULE,
231-
.open = drm_open,
232-
.release = drm_release,
233-
.unlocked_ioctl = drm_ioctl,
234-
.compat_ioctl = drm_compat_ioctl,
235-
.poll = virtio_gpu_poll,
236-
.read = drm_read,
237-
.llseek = noop_llseek,
238-
.mmap = drm_gem_mmap
239-
};
199+
DEFINE_DRM_GEM_FOPS(virtio_gpu_driver_fops);
240200

241201
static const struct drm_driver driver = {
242202
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_RENDER | DRIVER_ATOMIC,

drivers/gpu/drm/virtio/virtgpu_drv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ struct virtio_gpu_fence_driver {
138138
spinlock_t lock;
139139
};
140140

141-
#define VIRTGPU_EVENT_FENCE_SIGNALED_INTERNAL 0x10000000
142141
struct virtio_gpu_fence_event {
143142
struct drm_pending_event base;
144143
struct drm_event event;

drivers/gpu/drm/virtio/virtgpu_ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int virtio_gpu_fence_event_create(struct drm_device *dev,
5454
if (!e)
5555
return -ENOMEM;
5656

57-
e->event.type = VIRTGPU_EVENT_FENCE_SIGNALED_INTERNAL;
57+
e->event.type = VIRTGPU_EVENT_FENCE_SIGNALED;
5858
e->event.length = sizeof(e->event);
5959

6060
ret = drm_event_reserve_init(dev, file, &e->base, &e->event);

include/uapi/drm/virtgpu_drm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ struct drm_virtgpu_context_init {
196196
__u64 ctx_set_params;
197197
};
198198

199+
/*
200+
* Event code that's given when VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK is in
201+
* effect. The event size is sizeof(drm_event), since there is no additional
202+
* payload.
203+
*/
204+
#define VIRTGPU_EVENT_FENCE_SIGNALED 0x90000000
205+
199206
#define DRM_IOCTL_VIRTGPU_MAP \
200207
DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_MAP, struct drm_virtgpu_map)
201208

0 commit comments

Comments
 (0)