Skip to content

Commit e00fb85

Browse files
committed
drm: Stop updating plane->crtc/fb/old_fb on atomic drivers
Stop playing around with plane->crtc/fb/old_fb with atomic drivers. Make life a lot simpler when we don't have to do the magic old_fb vs. fb dance around plane updates. That way we can't risk plane->fb getting out of sync with plane->state->fb and we're less likely to leak any refcounts as well. Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Acked-by: Harry Wentland <harry.wentland@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20180525185045.29689-14-ville.syrjala@linux.intel.com Reviewed-by: Sinclair Yeh <syeh@vmware.com>
1 parent 2f958af commit e00fb85

8 files changed

Lines changed: 24 additions & 87 deletions

File tree

‎drivers/gpu/drm/drm_atomic.c‎

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ drm_atomic_get_plane_state(struct drm_atomic_state *state,
692692

693693
WARN_ON(!state->acquire_ctx);
694694

695+
/* the legacy pointers should never be set */
696+
WARN_ON(plane->fb);
697+
WARN_ON(plane->old_fb);
698+
WARN_ON(plane->crtc);
699+
695700
plane_state = drm_atomic_get_existing_plane_state(state, plane);
696701
if (plane_state)
697702
return plane_state;
@@ -2039,45 +2044,6 @@ int drm_atomic_set_property(struct drm_atomic_state *state,
20392044
return ret;
20402045
}
20412046

2042-
/**
2043-
* drm_atomic_clean_old_fb -- Unset old_fb pointers and set plane->fb pointers.
2044-
*
2045-
* @dev: drm device to check.
2046-
* @plane_mask: plane mask for planes that were updated.
2047-
* @ret: return value, can be -EDEADLK for a retry.
2048-
*
2049-
* Before doing an update &drm_plane.old_fb is set to &drm_plane.fb, but before
2050-
* dropping the locks old_fb needs to be set to NULL and plane->fb updated. This
2051-
* is a common operation for each atomic update, so this call is split off as a
2052-
* helper.
2053-
*/
2054-
void drm_atomic_clean_old_fb(struct drm_device *dev,
2055-
unsigned plane_mask,
2056-
int ret)
2057-
{
2058-
struct drm_plane *plane;
2059-
2060-
/* if succeeded, fixup legacy plane crtc/fb ptrs before dropping
2061-
* locks (ie. while it is still safe to deref plane->state). We
2062-
* need to do this here because the driver entry points cannot
2063-
* distinguish between legacy and atomic ioctls.
2064-
*/
2065-
drm_for_each_plane_mask(plane, dev, plane_mask) {
2066-
if (ret == 0) {
2067-
struct drm_framebuffer *new_fb = plane->state->fb;
2068-
if (new_fb)
2069-
drm_framebuffer_get(new_fb);
2070-
plane->fb = new_fb;
2071-
plane->crtc = plane->state->crtc;
2072-
2073-
if (plane->old_fb)
2074-
drm_framebuffer_put(plane->old_fb);
2075-
}
2076-
plane->old_fb = NULL;
2077-
}
2078-
}
2079-
EXPORT_SYMBOL(drm_atomic_clean_old_fb);
2080-
20812047
/**
20822048
* DOC: explicit fencing properties
20832049
*
@@ -2298,9 +2264,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
22982264
unsigned int copied_objs, copied_props;
22992265
struct drm_atomic_state *state;
23002266
struct drm_modeset_acquire_ctx ctx;
2301-
struct drm_plane *plane;
23022267
struct drm_out_fence_state *fence_state;
2303-
unsigned plane_mask;
23042268
int ret = 0;
23052269
unsigned int i, j, num_fences;
23062270

@@ -2340,7 +2304,6 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
23402304
state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
23412305

23422306
retry:
2343-
plane_mask = 0;
23442307
copied_objs = 0;
23452308
copied_props = 0;
23462309
fence_state = NULL;
@@ -2411,12 +2374,6 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
24112374
copied_props++;
24122375
}
24132376

2414-
if (obj->type == DRM_MODE_OBJECT_PLANE && count_props &&
2415-
!(arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
2416-
plane = obj_to_plane(obj);
2417-
plane_mask |= (1 << drm_plane_index(plane));
2418-
plane->old_fb = plane->fb;
2419-
}
24202377
drm_mode_object_put(obj);
24212378
}
24222379

@@ -2437,8 +2394,6 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
24372394
}
24382395

24392396
out:
2440-
drm_atomic_clean_old_fb(dev, plane_mask, ret);
2441-
24422397
complete_crtc_signaling(dev, state, fence_state, num_fences, !ret);
24432398

24442399
if (ret == -EDEADLK) {

‎drivers/gpu/drm/drm_atomic_helper.c‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,6 @@ static int __drm_atomic_helper_disable_all(struct drm_device *dev,
29142914
struct drm_plane *plane;
29152915
struct drm_crtc_state *crtc_state;
29162916
struct drm_crtc *crtc;
2917-
unsigned plane_mask = 0;
29182917
int ret, i;
29192918

29202919
state = drm_atomic_state_alloc(dev);
@@ -2957,17 +2956,10 @@ static int __drm_atomic_helper_disable_all(struct drm_device *dev,
29572956
goto free;
29582957

29592958
drm_atomic_set_fb_for_plane(plane_state, NULL);
2960-
2961-
if (clean_old_fbs) {
2962-
plane->old_fb = plane->fb;
2963-
plane_mask |= BIT(drm_plane_index(plane));
2964-
}
29652959
}
29662960

29672961
ret = drm_atomic_commit(state);
29682962
free:
2969-
if (plane_mask)
2970-
drm_atomic_clean_old_fb(dev, plane_mask, ret);
29712963
drm_atomic_state_put(state);
29722964
return ret;
29732965
}
@@ -3129,13 +3121,8 @@ int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
31293121

31303122
state->acquire_ctx = ctx;
31313123

3132-
for_each_new_plane_in_state(state, plane, new_plane_state, i) {
3133-
WARN_ON(plane->crtc != new_plane_state->crtc);
3134-
WARN_ON(plane->fb != new_plane_state->fb);
3135-
WARN_ON(plane->old_fb);
3136-
3124+
for_each_new_plane_in_state(state, plane, new_plane_state, i)
31373125
state->planes[i].old_state = plane->state;
3138-
}
31393126

31403127
for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
31413128
state->crtcs[i].old_state = crtc->state;

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,12 @@ static int __drm_mode_set_config_internal(struct drm_mode_set *set,
479479

480480
ret = crtc->funcs->set_config(set, ctx);
481481
if (ret == 0) {
482-
crtc->primary->crtc = fb ? crtc : NULL;
483-
crtc->primary->fb = fb;
482+
struct drm_plane *plane = crtc->primary;
483+
484+
if (!plane->state) {
485+
plane->crtc = fb ? crtc : NULL;
486+
plane->fb = fb;
487+
}
484488
}
485489

486490
drm_for_each_crtc(tmp, crtc->dev) {

‎drivers/gpu/drm/drm_fb_helper.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ
368368
struct drm_plane *plane;
369369
struct drm_atomic_state *state;
370370
int i, ret;
371-
unsigned int plane_mask;
372371
struct drm_modeset_acquire_ctx ctx;
373372

374373
drm_modeset_acquire_init(&ctx, 0);
@@ -381,7 +380,6 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ
381380

382381
state->acquire_ctx = &ctx;
383382
retry:
384-
plane_mask = 0;
385383
drm_for_each_plane(plane, dev) {
386384
plane_state = drm_atomic_get_plane_state(state, plane);
387385
if (IS_ERR(plane_state)) {
@@ -391,9 +389,6 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ
391389

392390
plane_state->rotation = DRM_MODE_ROTATE_0;
393391

394-
plane->old_fb = plane->fb;
395-
plane_mask |= 1 << drm_plane_index(plane);
396-
397392
/* disable non-primary: */
398393
if (plane->type == DRM_PLANE_TYPE_PRIMARY)
399394
continue;
@@ -430,8 +425,6 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ
430425
ret = drm_atomic_commit(state);
431426

432427
out_state:
433-
drm_atomic_clean_old_fb(dev, plane_mask, ret);
434-
435428
if (ret == -EDEADLK)
436429
goto backoff;
437430

‎drivers/gpu/drm/drm_framebuffer.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,6 @@ static int atomic_remove_fb(struct drm_framebuffer *fb)
836836
goto unlock;
837837

838838
plane_mask |= BIT(drm_plane_index(plane));
839-
840-
plane->old_fb = plane->fb;
841839
}
842840

843841
/* This list is only filled when disable_crtcs is set. */
@@ -852,9 +850,6 @@ static int atomic_remove_fb(struct drm_framebuffer *fb)
852850
ret = drm_atomic_commit(state);
853851

854852
unlock:
855-
if (plane_mask)
856-
drm_atomic_clean_old_fb(dev, plane_mask, ret);
857-
858853
if (ret == -EDEADLK) {
859854
drm_atomic_state_clear(state);
860855
drm_modeset_backoff(&ctx);

‎drivers/gpu/drm/drm_plane.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,11 @@ static int __setplane_internal(struct drm_plane *plane,
651651
crtc_x, crtc_y, crtc_w, crtc_h,
652652
src_x, src_y, src_w, src_h, ctx);
653653
if (!ret) {
654-
plane->crtc = crtc;
655-
plane->fb = fb;
656-
drm_framebuffer_get(plane->fb);
654+
if (!plane->state) {
655+
plane->crtc = crtc;
656+
plane->fb = fb;
657+
drm_framebuffer_get(plane->fb);
658+
}
657659
} else {
658660
plane->old_fb = NULL;
659661
}
@@ -1093,8 +1095,10 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
10931095
/* Keep the old fb, don't unref it. */
10941096
plane->old_fb = NULL;
10951097
} else {
1096-
plane->fb = fb;
1097-
drm_framebuffer_get(fb);
1098+
if (!plane->state) {
1099+
plane->fb = fb;
1100+
drm_framebuffer_get(fb);
1101+
}
10981102
}
10991103

11001104
out:

‎drivers/gpu/drm/drm_plane_helper.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ EXPORT_SYMBOL(drm_plane_helper_update);
502502
int drm_plane_helper_disable(struct drm_plane *plane)
503503
{
504504
struct drm_plane_state *plane_state;
505+
struct drm_framebuffer *old_fb;
505506

506507
/* crtc helpers love to call disable functions for already disabled hw
507508
* functions. So cope with that. */
@@ -521,8 +522,9 @@ int drm_plane_helper_disable(struct drm_plane *plane)
521522
plane_state->plane = plane;
522523

523524
plane_state->crtc = NULL;
525+
old_fb = plane_state->fb;
524526
drm_atomic_set_fb_for_plane(plane_state, NULL);
525527

526-
return drm_plane_helper_commit(plane, plane_state, plane->fb);
528+
return drm_plane_helper_commit(plane, plane_state, old_fb);
527529
}
528530
EXPORT_SYMBOL(drm_plane_helper_disable);

‎include/drm/drm_atomic.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,6 @@ int __must_check
601601
drm_atomic_add_affected_planes(struct drm_atomic_state *state,
602602
struct drm_crtc *crtc);
603603

604-
void
605-
drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret);
606-
607604
int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
608605
int __must_check drm_atomic_commit(struct drm_atomic_state *state);
609606
int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);

0 commit comments

Comments
 (0)