Skip to content

Commit 669c921

Browse files
committed
drm/atomic: Make async plane update checks work as intended, v2.
By always keeping track of the last commit in plane_state, we know whether there is an active update on the plane or not. With that information we can reject the fast update, and force the slowpath to be used as was originally intended. We cannot use plane_state->crtc->state here, because this only mentions the most recent commit for the crtc, but not the planes that were part of it. We specifically care about what the last commit involving this plane is, which can only be tracked with a pointer in the plane state. Changes since v1: - Clean up the whole function here, instead of partially earlier. - Add mention in the commit message why we need commit in plane_state. - Swap plane->state in intel_legacy_cursor_update, instead of reassigning all variables. With this commit We know that the cursor is not part of any active commits so this hack can be removed. Cc: Gustavo Padovan <gustavo.padovan@collabora.com> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> #v1 Link: https://patchwork.freedesktop.org/patch/msgid/20170904104838.23822-7-maarten.lankhorst@linux.intel.com [mlankhorst: Amend commit for merge conflicts with drm-intel]
1 parent 21a01ab commit 669c921

3 files changed

Lines changed: 34 additions & 50 deletions

File tree

‎drivers/gpu/drm/drm_atomic_helper.c‎

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,67 +1388,43 @@ int drm_atomic_helper_async_check(struct drm_device *dev,
13881388
{
13891389
struct drm_crtc *crtc;
13901390
struct drm_crtc_state *crtc_state;
1391-
struct drm_crtc_commit *commit;
1392-
struct drm_plane *__plane, *plane = NULL;
1393-
struct drm_plane_state *__plane_state, *plane_state = NULL;
1391+
struct drm_plane *plane;
1392+
struct drm_plane_state *old_plane_state, *new_plane_state;
13941393
const struct drm_plane_helper_funcs *funcs;
1395-
int i, j, n_planes = 0;
1394+
int i, n_planes = 0;
13961395

13971396
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
13981397
if (drm_atomic_crtc_needs_modeset(crtc_state))
13991398
return -EINVAL;
14001399
}
14011400

1402-
for_each_new_plane_in_state(state, __plane, __plane_state, i) {
1401+
for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
14031402
n_planes++;
1404-
plane = __plane;
1405-
plane_state = __plane_state;
1406-
}
14071403

14081404
/* FIXME: we support only single plane updates for now */
1409-
if (!plane || n_planes != 1)
1405+
if (n_planes != 1)
14101406
return -EINVAL;
14111407

1412-
if (!plane_state->crtc)
1408+
if (!new_plane_state->crtc)
14131409
return -EINVAL;
14141410

14151411
funcs = plane->helper_private;
14161412
if (!funcs->atomic_async_update)
14171413
return -EINVAL;
14181414

1419-
if (plane_state->fence)
1415+
if (new_plane_state->fence)
14201416
return -EINVAL;
14211417

14221418
/*
14231419
* Don't do an async update if there is an outstanding commit modifying
14241420
* the plane. This prevents our async update's changes from getting
14251421
* overridden by a previous synchronous update's state.
14261422
*/
1427-
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
1428-
if (plane->crtc != crtc)
1429-
continue;
1430-
1431-
spin_lock(&crtc->commit_lock);
1432-
commit = list_first_entry_or_null(&crtc->commit_list,
1433-
struct drm_crtc_commit,
1434-
commit_entry);
1435-
if (!commit) {
1436-
spin_unlock(&crtc->commit_lock);
1437-
continue;
1438-
}
1439-
spin_unlock(&crtc->commit_lock);
1440-
1441-
if (!crtc->state->state)
1442-
continue;
1423+
if (old_plane_state->commit &&
1424+
!try_wait_for_completion(&old_plane_state->commit->hw_done))
1425+
return -EBUSY;
14431426

1444-
for_each_plane_in_state(crtc->state->state, __plane,
1445-
__plane_state, j) {
1446-
if (__plane == plane)
1447-
return -EINVAL;
1448-
}
1449-
}
1450-
1451-
return funcs->atomic_async_check(plane, plane_state);
1427+
return funcs->atomic_async_check(plane, new_plane_state);
14521428
}
14531429
EXPORT_SYMBOL(drm_atomic_helper_async_check);
14541430

@@ -1814,9 +1790,10 @@ int drm_atomic_helper_setup_commit(struct drm_atomic_state *state,
18141790
}
18151791

18161792
for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
1817-
/* commit tracked through new_crtc_state->commit, no need to do it explicitly */
1818-
if (new_plane_state->crtc)
1819-
continue;
1793+
/*
1794+
* Unlike connectors, always track planes explicitly for
1795+
* async pageflip support.
1796+
*/
18201797

18211798
/* Userspace is not allowed to get ahead of the previous
18221799
* commit with nonblocking ones. */

‎drivers/gpu/drm/i915/intel_display.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13548,6 +13548,14 @@ intel_legacy_cursor_update(struct drm_plane *plane,
1354813548
goto slow;
1354913549

1355013550
old_plane_state = plane->state;
13551+
/*
13552+
* Don't do an async update if there is an outstanding commit modifying
13553+
* the plane. This prevents our async update's changes from getting
13554+
* overridden by a previous synchronous update's state.
13555+
*/
13556+
if (old_plane_state->commit &&
13557+
!try_wait_for_completion(&old_plane_state->commit->hw_done))
13558+
goto slow;
1355113559

1355213560
/*
1355313561
* If any parameters change that may affect watermarks,
@@ -13609,19 +13617,12 @@ intel_legacy_cursor_update(struct drm_plane *plane,
1360913617
}
1361013618

1361113619
old_fb = old_plane_state->fb;
13612-
old_vma = to_intel_plane_state(old_plane_state)->vma;
1361313620

1361413621
i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
1361513622
intel_plane->frontbuffer_bit);
1361613623

1361713624
/* Swap plane state */
13618-
new_plane_state->fence = old_plane_state->fence;
13619-
new_plane_state->commit = old_plane_state->commit;
13620-
*to_intel_plane_state(old_plane_state) = *to_intel_plane_state(new_plane_state);
13621-
new_plane_state->fence = NULL;
13622-
new_plane_state->commit = NULL;
13623-
new_plane_state->fb = old_fb;
13624-
to_intel_plane_state(new_plane_state)->vma = old_vma;
13625+
plane->state = new_plane_state;
1362513626

1362613627
if (plane->state->visible) {
1362713628
trace_intel_update_plane(plane, to_intel_crtc(crtc));
@@ -13633,12 +13634,17 @@ intel_legacy_cursor_update(struct drm_plane *plane,
1363313634
intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
1363413635
}
1363513636

13636-
intel_cleanup_plane_fb(plane, new_plane_state);
13637+
old_vma = fetch_and_zero(&to_intel_plane_state(old_plane_state)->vma);
13638+
if (old_vma)
13639+
intel_unpin_fb_vma(old_vma);
1363713640

1363813641
out_unlock:
1363913642
mutex_unlock(&dev_priv->drm.struct_mutex);
1364013643
out_free:
13641-
intel_plane_destroy_state(plane, new_plane_state);
13644+
if (ret)
13645+
intel_plane_destroy_state(plane, new_plane_state);
13646+
else
13647+
intel_plane_destroy_state(plane, old_plane_state);
1364213648
return ret;
1364313649

1364413650
slow:

‎include/drm/drm_plane.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ struct drm_plane_state {
124124
bool visible;
125125

126126
/**
127-
* @commit: Tracks the pending commit to prevent use-after-free conditions.
127+
* @commit: Tracks the pending commit to prevent use-after-free conditions,
128+
* and for async plane updates.
128129
*
129-
* Is only set when @crtc is NULL.
130+
* May be NULL.
130131
*/
131132
struct drm_crtc_commit *commit;
132133

0 commit comments

Comments
 (0)