Skip to content

Commit f66cb86

Browse files
committed
nvidia-drm: handle -EDEADLK in nv_drm_reset_input_colorspace
drm_atomic_get_plane_state() and drm_atomic_commit() can return -EDEADLK when ww-mutex deadlock avoidance triggers. The current nv_drm_reset_input_colorspace() path drops locks and returns without running the required modeset backoff/retry flow. Rework the function to retry the atomic sequence with drm_modeset_backoff(&ctx), rebuilding atomic state on each retry, and only finish once the sequence succeeds or another error is returned. Signed-off-by: Paul Moses <p@1g4.org>
1 parent 2ccbad2 commit f66cb86

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

kernel-open/nvidia-drm/nvidia-drm-drv.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -937,21 +937,25 @@ int nv_drm_reset_input_colorspace(struct drm_device *dev)
937937
bool do_reset = false;
938938
NvU32 flags = 0;
939939

940-
state = drm_atomic_state_alloc(dev);
941-
if (!state)
942-
return -ENOMEM;
943-
944940
#if defined(DRM_MODESET_ACQUIRE_INTERRUPTIBLE)
945941
flags |= DRM_MODESET_ACQUIRE_INTERRUPTIBLE;
946942
#endif
947943
drm_modeset_acquire_init(&ctx, flags);
944+
945+
retry:
946+
do_reset = false;
947+
state = drm_atomic_state_alloc(dev);
948+
if (!state) {
949+
ret = -ENOMEM;
950+
goto out;
951+
}
948952
state->acquire_ctx = &ctx;
949953

950954
nv_drm_for_each_plane(plane, dev) {
951955
plane_state = drm_atomic_get_plane_state(state, plane);
952956
if (IS_ERR(plane_state)) {
953957
ret = PTR_ERR(plane_state);
954-
goto out;
958+
goto put_state;
955959
}
956960

957961
nv_drm_plane_state = to_nv_drm_plane_state(plane_state);
@@ -967,8 +971,17 @@ int nv_drm_reset_input_colorspace(struct drm_device *dev)
967971
ret = drm_atomic_commit(state);
968972
}
969973

970-
out:
974+
put_state:
971975
drm_atomic_state_put(state);
976+
977+
if (ret == -EDEADLK) {
978+
ret = drm_modeset_backoff(&ctx);
979+
if (!ret) {
980+
goto retry;
981+
}
982+
}
983+
984+
out:
972985
drm_modeset_drop_locks(&ctx);
973986
drm_modeset_acquire_fini(&ctx);
974987

@@ -1386,8 +1399,8 @@ nv_drm_atomic_disable_connector(struct drm_atomic_state *state,
13861399
if (nv_connector->modeset_permission_crtc) {
13871400
crtc_state = drm_atomic_get_crtc_state(
13881401
state, &nv_connector->modeset_permission_crtc->base);
1389-
if (!crtc_state) {
1390-
return -EINVAL;
1402+
if (IS_ERR(crtc_state)) {
1403+
return PTR_ERR(crtc_state);
13911404
}
13921405

13931406
crtc_state->active = false;
@@ -1398,8 +1411,8 @@ nv_drm_atomic_disable_connector(struct drm_atomic_state *state,
13981411
}
13991412

14001413
connector_state = drm_atomic_get_connector_state(state, &nv_connector->base);
1401-
if (!connector_state) {
1402-
return -EINVAL;
1414+
if (IS_ERR(connector_state)) {
1415+
return PTR_ERR(connector_state);
14031416
}
14041417

14051418
return drm_atomic_set_crtc_for_connector(connector_state, NULL);
@@ -1442,6 +1455,7 @@ static int nv_drm_revoke_modeset_permission(struct drm_device *dev,
14421455
(!dpyId || nv_drm_connector_is_dpy_id(connector, dpyId))) {
14431456
ret = nv_drm_atomic_disable_connector(state, nv_connector);
14441457
if (ret < 0) {
1458+
drm_connector_list_iter_end(&conn_iter);
14451459
goto done;
14461460
}
14471461

kernel-open/nvidia-drm/nvidia-drm-helper.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ int nv_drm_atomic_helper_disable_all(struct drm_device *dev,
9898
struct drm_plane *plane;
9999
struct drm_crtc_state *crtc_state;
100100
struct drm_crtc *crtc;
101-
unsigned plane_mask = 0;
101+
unsigned plane_mask;
102102
int ret, i;
103103

104+
retry:
105+
plane_mask = 0;
104106
state = drm_atomic_state_alloc(dev);
105107
if (!state)
106108
return -ENOMEM;
@@ -175,6 +177,12 @@ int nv_drm_atomic_helper_disable_all(struct drm_device *dev,
175177

176178
drm_atomic_state_put(state);
177179

180+
if (ret == -EDEADLK) {
181+
ret = drm_modeset_backoff(ctx);
182+
if (!ret)
183+
goto retry;
184+
}
185+
178186
return ret;
179187
}
180188

0 commit comments

Comments
 (0)