Skip to content

Commit 83e79ae

Browse files
committed
Merge tag 'drm-misc-fixes-2023-01-05' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes
Several fixes to fix the error path of dma_buf_export, add a missing structure declaration resulting in a compiler warning, fix the GEM handle refcounting in panfrost, fix a corrupted image with AFBC on meson, a memleak in virtio, improper plane width for imx, and a lockup in drm_sched_entity_kill() Signed-off-by: Daniel Vetter <[email protected]> From: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20230105074909.qd2h23hpxac4lxi7@houat
2 parents c8de526 + 6955554 commit 83e79ae

File tree

10 files changed

+77
-90
lines changed

10 files changed

+77
-90
lines changed

drivers/dma-buf/dma-buf-sysfs-stats.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,11 @@ void dma_buf_uninit_sysfs_statistics(void)
168168
kset_unregister(dma_buf_stats_kset);
169169
}
170170

171-
int dma_buf_stats_setup(struct dma_buf *dmabuf)
171+
int dma_buf_stats_setup(struct dma_buf *dmabuf, struct file *file)
172172
{
173173
struct dma_buf_sysfs_entry *sysfs_entry;
174174
int ret;
175175

176-
if (!dmabuf || !dmabuf->file)
177-
return -EINVAL;
178-
179176
if (!dmabuf->exp_name) {
180177
pr_err("exporter name must not be empty if stats needed\n");
181178
return -EINVAL;
@@ -192,7 +189,7 @@ int dma_buf_stats_setup(struct dma_buf *dmabuf)
192189

193190
/* create the directory for buffer stats */
194191
ret = kobject_init_and_add(&sysfs_entry->kobj, &dma_buf_ktype, NULL,
195-
"%lu", file_inode(dmabuf->file)->i_ino);
192+
"%lu", file_inode(file)->i_ino);
196193
if (ret)
197194
goto err_sysfs_dmabuf;
198195

drivers/dma-buf/dma-buf-sysfs-stats.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
int dma_buf_init_sysfs_statistics(void);
1414
void dma_buf_uninit_sysfs_statistics(void);
1515

16-
int dma_buf_stats_setup(struct dma_buf *dmabuf);
16+
int dma_buf_stats_setup(struct dma_buf *dmabuf, struct file *file);
1717

1818
void dma_buf_stats_teardown(struct dma_buf *dmabuf);
1919
#else
@@ -25,7 +25,7 @@ static inline int dma_buf_init_sysfs_statistics(void)
2525

2626
static inline void dma_buf_uninit_sysfs_statistics(void) {}
2727

28-
static inline int dma_buf_stats_setup(struct dma_buf *dmabuf)
28+
static inline int dma_buf_stats_setup(struct dma_buf *dmabuf, struct file *file)
2929
{
3030
return 0;
3131
}

drivers/dma-buf/dma-buf.c

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ static int dma_buf_file_release(struct inode *inode, struct file *file)
9595
return -EINVAL;
9696

9797
dmabuf = file->private_data;
98-
99-
mutex_lock(&db_list.lock);
100-
list_del(&dmabuf->list_node);
101-
mutex_unlock(&db_list.lock);
98+
if (dmabuf) {
99+
mutex_lock(&db_list.lock);
100+
list_del(&dmabuf->list_node);
101+
mutex_unlock(&db_list.lock);
102+
}
102103

103104
return 0;
104105
}
@@ -528,17 +529,17 @@ static inline int is_dma_buf_file(struct file *file)
528529
return file->f_op == &dma_buf_fops;
529530
}
530531

531-
static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags)
532+
static struct file *dma_buf_getfile(size_t size, int flags)
532533
{
533534
static atomic64_t dmabuf_inode = ATOMIC64_INIT(0);
534-
struct file *file;
535535
struct inode *inode = alloc_anon_inode(dma_buf_mnt->mnt_sb);
536+
struct file *file;
536537

537538
if (IS_ERR(inode))
538539
return ERR_CAST(inode);
539540

540-
inode->i_size = dmabuf->size;
541-
inode_set_bytes(inode, dmabuf->size);
541+
inode->i_size = size;
542+
inode_set_bytes(inode, size);
542543

543544
/*
544545
* The ->i_ino acquired from get_next_ino() is not unique thus
@@ -552,8 +553,6 @@ static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags)
552553
flags, &dma_buf_fops);
553554
if (IS_ERR(file))
554555
goto err_alloc_file;
555-
file->private_data = dmabuf;
556-
file->f_path.dentry->d_fsdata = dmabuf;
557556

558557
return file;
559558

@@ -619,19 +618,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
619618
size_t alloc_size = sizeof(struct dma_buf);
620619
int ret;
621620

622-
if (!exp_info->resv)
623-
alloc_size += sizeof(struct dma_resv);
624-
else
625-
/* prevent &dma_buf[1] == dma_buf->resv */
626-
alloc_size += 1;
627-
628-
if (WARN_ON(!exp_info->priv
629-
|| !exp_info->ops
630-
|| !exp_info->ops->map_dma_buf
631-
|| !exp_info->ops->unmap_dma_buf
632-
|| !exp_info->ops->release)) {
621+
if (WARN_ON(!exp_info->priv || !exp_info->ops
622+
|| !exp_info->ops->map_dma_buf
623+
|| !exp_info->ops->unmap_dma_buf
624+
|| !exp_info->ops->release))
633625
return ERR_PTR(-EINVAL);
634-
}
635626

636627
if (WARN_ON(exp_info->ops->cache_sgt_mapping &&
637628
(exp_info->ops->pin || exp_info->ops->unpin)))
@@ -643,10 +634,21 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
643634
if (!try_module_get(exp_info->owner))
644635
return ERR_PTR(-ENOENT);
645636

637+
file = dma_buf_getfile(exp_info->size, exp_info->flags);
638+
if (IS_ERR(file)) {
639+
ret = PTR_ERR(file);
640+
goto err_module;
641+
}
642+
643+
if (!exp_info->resv)
644+
alloc_size += sizeof(struct dma_resv);
645+
else
646+
/* prevent &dma_buf[1] == dma_buf->resv */
647+
alloc_size += 1;
646648
dmabuf = kzalloc(alloc_size, GFP_KERNEL);
647649
if (!dmabuf) {
648650
ret = -ENOMEM;
649-
goto err_module;
651+
goto err_file;
650652
}
651653

652654
dmabuf->priv = exp_info->priv;
@@ -658,43 +660,35 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
658660
init_waitqueue_head(&dmabuf->poll);
659661
dmabuf->cb_in.poll = dmabuf->cb_out.poll = &dmabuf->poll;
660662
dmabuf->cb_in.active = dmabuf->cb_out.active = 0;
663+
INIT_LIST_HEAD(&dmabuf->attachments);
661664

662665
if (!resv) {
663-
resv = (struct dma_resv *)&dmabuf[1];
664-
dma_resv_init(resv);
666+
dmabuf->resv = (struct dma_resv *)&dmabuf[1];
667+
dma_resv_init(dmabuf->resv);
668+
} else {
669+
dmabuf->resv = resv;
665670
}
666-
dmabuf->resv = resv;
667671

668-
file = dma_buf_getfile(dmabuf, exp_info->flags);
669-
if (IS_ERR(file)) {
670-
ret = PTR_ERR(file);
672+
ret = dma_buf_stats_setup(dmabuf, file);
673+
if (ret)
671674
goto err_dmabuf;
672-
}
673675

676+
file->private_data = dmabuf;
677+
file->f_path.dentry->d_fsdata = dmabuf;
674678
dmabuf->file = file;
675679

676-
INIT_LIST_HEAD(&dmabuf->attachments);
677-
678680
mutex_lock(&db_list.lock);
679681
list_add(&dmabuf->list_node, &db_list.head);
680682
mutex_unlock(&db_list.lock);
681683

682-
ret = dma_buf_stats_setup(dmabuf);
683-
if (ret)
684-
goto err_sysfs;
685-
686684
return dmabuf;
687685

688-
err_sysfs:
689-
/*
690-
* Set file->f_path.dentry->d_fsdata to NULL so that when
691-
* dma_buf_release() gets invoked by dentry_ops, it exits
692-
* early before calling the release() dma_buf op.
693-
*/
694-
file->f_path.dentry->d_fsdata = NULL;
695-
fput(file);
696686
err_dmabuf:
687+
if (!resv)
688+
dma_resv_fini(dmabuf->resv);
697689
kfree(dmabuf);
690+
err_file:
691+
fput(file);
698692
err_module:
699693
module_put(exp_info->owner);
700694
return ERR_PTR(ret);

drivers/gpu/drm/imx/ipuv3-plane.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
614614
break;
615615
}
616616

617+
if (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_BG)
618+
width = ipu_src_rect_width(new_state);
619+
else
620+
width = drm_rect_width(&new_state->src) >> 16;
621+
617622
eba = drm_plane_state_to_eba(new_state, 0);
618623

619624
/*
@@ -622,8 +627,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
622627
*/
623628
if (ipu_state->use_pre) {
624629
axi_id = ipu_chan_assign_axi_id(ipu_plane->dma);
625-
ipu_prg_channel_configure(ipu_plane->ipu_ch, axi_id,
626-
ipu_src_rect_width(new_state),
630+
ipu_prg_channel_configure(ipu_plane->ipu_ch, axi_id, width,
627631
drm_rect_height(&new_state->src) >> 16,
628632
fb->pitches[0], fb->format->format,
629633
fb->modifier, &eba);
@@ -678,9 +682,8 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
678682
break;
679683
}
680684

681-
ipu_dmfc_config_wait4eot(ipu_plane->dmfc, ALIGN(drm_rect_width(dst), 8));
685+
ipu_dmfc_config_wait4eot(ipu_plane->dmfc, width);
682686

683-
width = ipu_src_rect_width(new_state);
684687
height = drm_rect_height(&new_state->src) >> 16;
685688
info = drm_format_info(fb->format->format);
686689
ipu_calculate_bursts(width, info->cpp[0], fb->pitches[0],
@@ -744,8 +747,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
744747
ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, 16);
745748

746749
ipu_cpmem_zero(ipu_plane->alpha_ch);
747-
ipu_cpmem_set_resolution(ipu_plane->alpha_ch,
748-
ipu_src_rect_width(new_state),
750+
ipu_cpmem_set_resolution(ipu_plane->alpha_ch, width,
749751
drm_rect_height(&new_state->src) >> 16);
750752
ipu_cpmem_set_format_passthrough(ipu_plane->alpha_ch, 8);
751753
ipu_cpmem_set_high_priority(ipu_plane->alpha_ch);

drivers/gpu/drm/meson/meson_viu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,14 @@ void meson_viu_init(struct meson_drm *priv)
436436

437437
/* Initialize OSD1 fifo control register */
438438
reg = VIU_OSD_DDR_PRIORITY_URGENT |
439-
VIU_OSD_HOLD_FIFO_LINES(31) |
440439
VIU_OSD_FIFO_DEPTH_VAL(32) | /* fifo_depth_val: 32*8=256 */
441440
VIU_OSD_WORDS_PER_BURST(4) | /* 4 words in 1 burst */
442441
VIU_OSD_FIFO_LIMITS(2); /* fifo_lim: 2*16=32 */
443442

444443
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
445-
reg |= VIU_OSD_BURST_LENGTH_32;
444+
reg |= (VIU_OSD_BURST_LENGTH_32 | VIU_OSD_HOLD_FIFO_LINES(31));
446445
else
447-
reg |= VIU_OSD_BURST_LENGTH_64;
446+
reg |= (VIU_OSD_BURST_LENGTH_64 | VIU_OSD_HOLD_FIFO_LINES(4));
448447

449448
writel_relaxed(reg, priv->io_base + _REG(VIU_OSD1_FIFO_CTRL_STAT));
450449
writel_relaxed(reg, priv->io_base + _REG(VIU_OSD2_FIFO_CTRL_STAT));

drivers/gpu/drm/panfrost/panfrost_drv.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data,
8282
struct panfrost_gem_object *bo;
8383
struct drm_panfrost_create_bo *args = data;
8484
struct panfrost_gem_mapping *mapping;
85+
int ret;
8586

8687
if (!args->size || args->pad ||
8788
(args->flags & ~(PANFROST_BO_NOEXEC | PANFROST_BO_HEAP)))
@@ -92,21 +93,29 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data,
9293
!(args->flags & PANFROST_BO_NOEXEC))
9394
return -EINVAL;
9495

95-
bo = panfrost_gem_create_with_handle(file, dev, args->size, args->flags,
96-
&args->handle);
96+
bo = panfrost_gem_create(dev, args->size, args->flags);
9797
if (IS_ERR(bo))
9898
return PTR_ERR(bo);
9999

100+
ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
101+
if (ret)
102+
goto out;
103+
100104
mapping = panfrost_gem_mapping_get(bo, priv);
101-
if (!mapping) {
102-
drm_gem_object_put(&bo->base.base);
103-
return -EINVAL;
105+
if (mapping) {
106+
args->offset = mapping->mmnode.start << PAGE_SHIFT;
107+
panfrost_gem_mapping_put(mapping);
108+
} else {
109+
/* This can only happen if the handle from
110+
* drm_gem_handle_create() has already been guessed and freed
111+
* by user space
112+
*/
113+
ret = -EINVAL;
104114
}
105115

106-
args->offset = mapping->mmnode.start << PAGE_SHIFT;
107-
panfrost_gem_mapping_put(mapping);
108-
109-
return 0;
116+
out:
117+
drm_gem_object_put(&bo->base.base);
118+
return ret;
110119
}
111120

112121
/**

drivers/gpu/drm/panfrost/panfrost_gem.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,8 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t
235235
}
236236

237237
struct panfrost_gem_object *
238-
panfrost_gem_create_with_handle(struct drm_file *file_priv,
239-
struct drm_device *dev, size_t size,
240-
u32 flags,
241-
uint32_t *handle)
238+
panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags)
242239
{
243-
int ret;
244240
struct drm_gem_shmem_object *shmem;
245241
struct panfrost_gem_object *bo;
246242

@@ -256,16 +252,6 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv,
256252
bo->noexec = !!(flags & PANFROST_BO_NOEXEC);
257253
bo->is_heap = !!(flags & PANFROST_BO_HEAP);
258254

259-
/*
260-
* Allocate an id of idr table where the obj is registered
261-
* and handle has the id what user can see.
262-
*/
263-
ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
264-
/* drop reference from allocate - handle holds it now. */
265-
drm_gem_object_put(&shmem->base);
266-
if (ret)
267-
return ERR_PTR(ret);
268-
269255
return bo;
270256
}
271257

drivers/gpu/drm/panfrost/panfrost_gem.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev,
6969
struct sg_table *sgt);
7070

7171
struct panfrost_gem_object *
72-
panfrost_gem_create_with_handle(struct drm_file *file_priv,
73-
struct drm_device *dev, size_t size,
74-
u32 flags,
75-
uint32_t *handle);
72+
panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags);
7673

7774
int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv);
7875
void panfrost_gem_close(struct drm_gem_object *obj,

drivers/gpu/drm/virtio/virtgpu_object.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
184184
struct virtio_gpu_object_array *objs = NULL;
185185
struct drm_gem_shmem_object *shmem_obj;
186186
struct virtio_gpu_object *bo;
187-
struct virtio_gpu_mem_entry *ents;
187+
struct virtio_gpu_mem_entry *ents = NULL;
188188
unsigned int nents;
189189
int ret;
190190

@@ -210,7 +210,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
210210
ret = -ENOMEM;
211211
objs = virtio_gpu_array_alloc(1);
212212
if (!objs)
213-
goto err_put_id;
213+
goto err_free_entry;
214214
virtio_gpu_array_add_obj(objs, &bo->base.base);
215215

216216
ret = virtio_gpu_array_lock_resv(objs);
@@ -239,6 +239,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
239239

240240
err_put_objs:
241241
virtio_gpu_array_put_free(objs);
242+
err_free_entry:
243+
kvfree(ents);
242244
err_put_id:
243245
virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle);
244246
err_free_gem:

include/drm/drm_plane_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <linux/types.h>
2828

29+
struct drm_atomic_state;
2930
struct drm_crtc;
3031
struct drm_framebuffer;
3132
struct drm_modeset_acquire_ctx;

0 commit comments

Comments
 (0)