Skip to content

Commit ce22e89

Browse files
committed
Merge tag 'drm-misc-fixes-2023-08-24' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes
A samsung-dsim initialization fix, a devfreq fix for panfrost, a DP DSC define fix, a recursive lock fix for dma-buf, a shader validation fix and a reference counting fix for vmwgfx Signed-off-by: Dave Airlie <airlied@redhat.com> From: Maxime Ripard <mripard@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/amy26vu5xbeeikswpx7nt6rddwfocdidshrtt2qovipihx5poj@y45p3dtzrloc
2 parents 706a741 + f9e96bf commit ce22e89

File tree

11 files changed

+67
-55
lines changed

11 files changed

+67
-55
lines changed

drivers/dma-buf/sw_sync.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ static const struct dma_fence_ops timeline_fence_ops = {
191191
*/
192192
static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
193193
{
194+
LIST_HEAD(signalled);
194195
struct sync_pt *pt, *next;
195196

196197
trace_sync_timeline(obj);
@@ -203,21 +204,20 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
203204
if (!timeline_fence_signaled(&pt->base))
204205
break;
205206

206-
list_del_init(&pt->link);
207+
dma_fence_get(&pt->base);
208+
209+
list_move_tail(&pt->link, &signalled);
207210
rb_erase(&pt->node, &obj->pt_tree);
208211

209-
/*
210-
* A signal callback may release the last reference to this
211-
* fence, causing it to be freed. That operation has to be
212-
* last to avoid a use after free inside this loop, and must
213-
* be after we remove the fence from the timeline in order to
214-
* prevent deadlocking on timeline->lock inside
215-
* timeline_fence_release().
216-
*/
217212
dma_fence_signal_locked(&pt->base);
218213
}
219214

220215
spin_unlock_irq(&obj->lock);
216+
217+
list_for_each_entry_safe(pt, next, &signalled, link) {
218+
list_del_init(&pt->link);
219+
dma_fence_put(&pt->base);
220+
}
221221
}
222222

223223
/**

drivers/gpu/drm/bridge/samsung-dsim.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,18 @@ static void samsung_dsim_disable_irq(struct samsung_dsim *dsi)
13861386
disable_irq(dsi->irq);
13871387
}
13881388

1389+
static void samsung_dsim_set_stop_state(struct samsung_dsim *dsi, bool enable)
1390+
{
1391+
u32 reg = samsung_dsim_read(dsi, DSIM_ESCMODE_REG);
1392+
1393+
if (enable)
1394+
reg |= DSIM_FORCE_STOP_STATE;
1395+
else
1396+
reg &= ~DSIM_FORCE_STOP_STATE;
1397+
1398+
samsung_dsim_write(dsi, DSIM_ESCMODE_REG, reg);
1399+
}
1400+
13891401
static int samsung_dsim_init(struct samsung_dsim *dsi)
13901402
{
13911403
const struct samsung_dsim_driver_data *driver_data = dsi->driver_data;
@@ -1445,15 +1457,12 @@ static void samsung_dsim_atomic_enable(struct drm_bridge *bridge,
14451457
struct drm_bridge_state *old_bridge_state)
14461458
{
14471459
struct samsung_dsim *dsi = bridge_to_dsi(bridge);
1448-
u32 reg;
14491460

14501461
if (samsung_dsim_hw_is_exynos(dsi->plat_data->hw_type)) {
14511462
samsung_dsim_set_display_mode(dsi);
14521463
samsung_dsim_set_display_enable(dsi, true);
14531464
} else {
1454-
reg = samsung_dsim_read(dsi, DSIM_ESCMODE_REG);
1455-
reg &= ~DSIM_FORCE_STOP_STATE;
1456-
samsung_dsim_write(dsi, DSIM_ESCMODE_REG, reg);
1465+
samsung_dsim_set_stop_state(dsi, false);
14571466
}
14581467

14591468
dsi->state |= DSIM_STATE_VIDOUT_AVAILABLE;
@@ -1463,16 +1472,12 @@ static void samsung_dsim_atomic_disable(struct drm_bridge *bridge,
14631472
struct drm_bridge_state *old_bridge_state)
14641473
{
14651474
struct samsung_dsim *dsi = bridge_to_dsi(bridge);
1466-
u32 reg;
14671475

14681476
if (!(dsi->state & DSIM_STATE_ENABLED))
14691477
return;
14701478

1471-
if (!samsung_dsim_hw_is_exynos(dsi->plat_data->hw_type)) {
1472-
reg = samsung_dsim_read(dsi, DSIM_ESCMODE_REG);
1473-
reg |= DSIM_FORCE_STOP_STATE;
1474-
samsung_dsim_write(dsi, DSIM_ESCMODE_REG, reg);
1475-
}
1479+
if (!samsung_dsim_hw_is_exynos(dsi->plat_data->hw_type))
1480+
samsung_dsim_set_stop_state(dsi, true);
14761481

14771482
dsi->state &= ~DSIM_STATE_VIDOUT_AVAILABLE;
14781483
}
@@ -1775,6 +1780,8 @@ static ssize_t samsung_dsim_host_transfer(struct mipi_dsi_host *host,
17751780
if (ret)
17761781
return ret;
17771782

1783+
samsung_dsim_set_stop_state(dsi, false);
1784+
17781785
ret = mipi_dsi_create_packet(&xfer.packet, msg);
17791786
if (ret < 0)
17801787
return ret;

drivers/gpu/drm/panfrost/panfrost_devfreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int panfrost_read_speedbin(struct device *dev)
9696
* keep going without it; any other error means that we are
9797
* supposed to read the bin value, but we failed doing so.
9898
*/
99-
if (ret != -ENOENT) {
99+
if (ret != -ENOENT && ret != -EOPNOTSUPP) {
100100
DRM_DEV_ERROR(dev, "Cannot read speed-bin (%d).", ret);
101101
return ret;
102102
}

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,9 @@ static int vmw_user_bo_synccpu_release(struct drm_file *filp,
497497
if (!(flags & drm_vmw_synccpu_allow_cs)) {
498498
atomic_dec(&vmw_bo->cpu_writers);
499499
}
500-
ttm_bo_put(&vmw_bo->tbo);
500+
vmw_user_bo_unref(vmw_bo);
501501
}
502502

503-
drm_gem_object_put(&vmw_bo->tbo.base);
504503
return ret;
505504
}
506505

@@ -540,8 +539,7 @@ int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
540539
return ret;
541540

542541
ret = vmw_user_bo_synccpu_grab(vbo, arg->flags);
543-
vmw_bo_unreference(&vbo);
544-
drm_gem_object_put(&vbo->tbo.base);
542+
vmw_user_bo_unref(vbo);
545543
if (unlikely(ret != 0)) {
546544
if (ret == -ERESTARTSYS || ret == -EBUSY)
547545
return -EBUSY;

drivers/gpu/drm/vmwgfx/vmwgfx_bo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ static inline struct vmw_bo *vmw_bo_reference(struct vmw_bo *buf)
195195
return buf;
196196
}
197197

198+
static inline void vmw_user_bo_unref(struct vmw_bo *vbo)
199+
{
200+
if (vbo) {
201+
ttm_bo_put(&vbo->tbo);
202+
drm_gem_object_put(&vbo->tbo.base);
203+
}
204+
}
205+
198206
static inline struct vmw_bo *to_vmw_bo(struct drm_gem_object *gobj)
199207
{
200208
return container_of((gobj), struct vmw_bo, tbo.base);

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,4 +1513,16 @@ static inline bool vmw_has_fences(struct vmw_private *vmw)
15131513
return (vmw_fifo_caps(vmw) & SVGA_FIFO_CAP_FENCE) != 0;
15141514
}
15151515

1516+
static inline bool vmw_shadertype_is_valid(enum vmw_sm_type shader_model,
1517+
u32 shader_type)
1518+
{
1519+
SVGA3dShaderType max_allowed = SVGA3D_SHADERTYPE_PREDX_MAX;
1520+
1521+
if (shader_model >= VMW_SM_5)
1522+
max_allowed = SVGA3D_SHADERTYPE_MAX;
1523+
else if (shader_model >= VMW_SM_4)
1524+
max_allowed = SVGA3D_SHADERTYPE_DX10_MAX;
1525+
return shader_type >= SVGA3D_SHADERTYPE_MIN && shader_type < max_allowed;
1526+
}
1527+
15161528
#endif

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,7 @@ static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,
11641164
}
11651165
vmw_bo_placement_set(vmw_bo, VMW_BO_DOMAIN_MOB, VMW_BO_DOMAIN_MOB);
11661166
ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo);
1167-
ttm_bo_put(&vmw_bo->tbo);
1168-
drm_gem_object_put(&vmw_bo->tbo.base);
1167+
vmw_user_bo_unref(vmw_bo);
11691168
if (unlikely(ret != 0))
11701169
return ret;
11711170

@@ -1221,8 +1220,7 @@ static int vmw_translate_guest_ptr(struct vmw_private *dev_priv,
12211220
vmw_bo_placement_set(vmw_bo, VMW_BO_DOMAIN_GMR | VMW_BO_DOMAIN_VRAM,
12221221
VMW_BO_DOMAIN_GMR | VMW_BO_DOMAIN_VRAM);
12231222
ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo);
1224-
ttm_bo_put(&vmw_bo->tbo);
1225-
drm_gem_object_put(&vmw_bo->tbo.base);
1223+
vmw_user_bo_unref(vmw_bo);
12261224
if (unlikely(ret != 0))
12271225
return ret;
12281226

@@ -1992,7 +1990,7 @@ static int vmw_cmd_set_shader(struct vmw_private *dev_priv,
19921990

19931991
cmd = container_of(header, typeof(*cmd), header);
19941992

1995-
if (cmd->body.type >= SVGA3D_SHADERTYPE_PREDX_MAX) {
1993+
if (!vmw_shadertype_is_valid(VMW_SM_LEGACY, cmd->body.type)) {
19961994
VMW_DEBUG_USER("Illegal shader type %u.\n",
19971995
(unsigned int) cmd->body.type);
19981996
return -EINVAL;
@@ -2115,8 +2113,6 @@ vmw_cmd_dx_set_single_constant_buffer(struct vmw_private *dev_priv,
21152113
SVGA3dCmdHeader *header)
21162114
{
21172115
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetSingleConstantBuffer);
2118-
SVGA3dShaderType max_shader_num = has_sm5_context(dev_priv) ?
2119-
SVGA3D_NUM_SHADERTYPE : SVGA3D_NUM_SHADERTYPE_DX10;
21202116

21212117
struct vmw_resource *res = NULL;
21222118
struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
@@ -2133,6 +2129,14 @@ vmw_cmd_dx_set_single_constant_buffer(struct vmw_private *dev_priv,
21332129
if (unlikely(ret != 0))
21342130
return ret;
21352131

2132+
if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type) ||
2133+
cmd->body.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
2134+
VMW_DEBUG_USER("Illegal const buffer shader %u slot %u.\n",
2135+
(unsigned int) cmd->body.type,
2136+
(unsigned int) cmd->body.slot);
2137+
return -EINVAL;
2138+
}
2139+
21362140
binding.bi.ctx = ctx_node->ctx;
21372141
binding.bi.res = res;
21382142
binding.bi.bt = vmw_ctx_binding_cb;
@@ -2141,14 +2145,6 @@ vmw_cmd_dx_set_single_constant_buffer(struct vmw_private *dev_priv,
21412145
binding.size = cmd->body.sizeInBytes;
21422146
binding.slot = cmd->body.slot;
21432147

2144-
if (binding.shader_slot >= max_shader_num ||
2145-
binding.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
2146-
VMW_DEBUG_USER("Illegal const buffer shader %u slot %u.\n",
2147-
(unsigned int) cmd->body.type,
2148-
(unsigned int) binding.slot);
2149-
return -EINVAL;
2150-
}
2151-
21522148
vmw_binding_add(ctx_node->staged, &binding.bi, binding.shader_slot,
21532149
binding.slot);
21542150

@@ -2207,15 +2203,13 @@ static int vmw_cmd_dx_set_shader_res(struct vmw_private *dev_priv,
22072203
{
22082204
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShaderResources) =
22092205
container_of(header, typeof(*cmd), header);
2210-
SVGA3dShaderType max_allowed = has_sm5_context(dev_priv) ?
2211-
SVGA3D_SHADERTYPE_MAX : SVGA3D_SHADERTYPE_DX10_MAX;
22122206

22132207
u32 num_sr_view = (cmd->header.size - sizeof(cmd->body)) /
22142208
sizeof(SVGA3dShaderResourceViewId);
22152209

22162210
if ((u64) cmd->body.startView + (u64) num_sr_view >
22172211
(u64) SVGA3D_DX_MAX_SRVIEWS ||
2218-
cmd->body.type >= max_allowed) {
2212+
!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
22192213
VMW_DEBUG_USER("Invalid shader binding.\n");
22202214
return -EINVAL;
22212215
}
@@ -2239,8 +2233,6 @@ static int vmw_cmd_dx_set_shader(struct vmw_private *dev_priv,
22392233
SVGA3dCmdHeader *header)
22402234
{
22412235
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShader);
2242-
SVGA3dShaderType max_allowed = has_sm5_context(dev_priv) ?
2243-
SVGA3D_SHADERTYPE_MAX : SVGA3D_SHADERTYPE_DX10_MAX;
22442236
struct vmw_resource *res = NULL;
22452237
struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
22462238
struct vmw_ctx_bindinfo_shader binding;
@@ -2251,8 +2243,7 @@ static int vmw_cmd_dx_set_shader(struct vmw_private *dev_priv,
22512243

22522244
cmd = container_of(header, typeof(*cmd), header);
22532245

2254-
if (cmd->body.type >= max_allowed ||
2255-
cmd->body.type < SVGA3D_SHADERTYPE_MIN) {
2246+
if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
22562247
VMW_DEBUG_USER("Illegal shader type %u.\n",
22572248
(unsigned int) cmd->body.type);
22582249
return -EINVAL;

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,10 +1665,8 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
16651665

16661666
err_out:
16671667
/* vmw_user_lookup_handle takes one ref so does new_fb */
1668-
if (bo) {
1669-
vmw_bo_unreference(&bo);
1670-
drm_gem_object_put(&bo->tbo.base);
1671-
}
1668+
if (bo)
1669+
vmw_user_bo_unref(bo);
16721670
if (surface)
16731671
vmw_surface_unreference(&surface);
16741672

drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ int vmw_overlay_ioctl(struct drm_device *dev, void *data,
451451

452452
ret = vmw_overlay_update_stream(dev_priv, buf, arg, true);
453453

454-
vmw_bo_unreference(&buf);
455-
drm_gem_object_put(&buf->tbo.base);
454+
vmw_user_bo_unref(buf);
456455

457456
out_unlock:
458457
mutex_unlock(&overlay->mutex);

drivers/gpu/drm/vmwgfx/vmwgfx_shader.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,7 @@ static int vmw_shader_define(struct drm_device *dev, struct drm_file *file_priv,
809809
shader_type, num_input_sig,
810810
num_output_sig, tfile, shader_handle);
811811
out_bad_arg:
812-
vmw_bo_unreference(&buffer);
813-
drm_gem_object_put(&buffer->tbo.base);
812+
vmw_user_bo_unref(buffer);
814813
return ret;
815814
}
816815

0 commit comments

Comments
 (0)