Skip to content

Commit 6e9f798

Browse files
danvetairlied
authored andcommitted
drm: Split connection_mutex out of mode_config.mutex (v3)
After the split-out of crtc locks from the big mode_config.mutex there's still two major areas it protects: - Various connector probe states, like connector->status, EDID properties, probed mode lists and similar information. - The links from connector->encoder and encoder->crtc and other modeset-relevant connector state (e.g. properties which control the panel fitter). The later is used by modeset operations. But they don't really care about the former since it's allowed to e.g. enable a disconnected VGA output or with a mode not in the probed list. Thus far this hasn't been a problem, but for the atomic modeset conversion Rob Clark needs to convert all modeset relevant locks into w/w locks. This is required because the order of acquisition is determined by how userspace supplies the atomic modeset data. This has run into troubles in the detect path since the i915 load detect code needs _both_ protections offered by the mode_config.mutex: It updates probe state and it needs to change the modeset configuration to enable the temporary load detect pipe. The big deal here is that for the probe/detect users of this lock a plain mutex fits best, but for atomic modesets we really want a w/w mutex. To fix this lets split out a new connection_mutex lock for the modeset relevant parts. For simplicity I've decided to only add one additional lock for all connector/encoder links and modeset configuration states. We have piles of different modeset objects in addition to those (like bridges or panels), so adding per-object locks would be much more effort. Also, we're guaranteed (at least for now) to do a full modeset if we need to acquire this lock. Which means that fine-grained locking is fairly irrelevant compared to the amount of time the full modeset will take. I've done a full audit, and there's just a few things that justify special focus: - Locking in drm_sysfs.c is almost completely absent. We should sprinkle mode_config.connection_mutex over this file a bit, but since it already lacks mode_config.mutex this patch wont make the situation any worse. This is material for a follow-up patch. - omap has a omap_framebuffer_flush function which walks the connector->encoder->crtc links and is called from many contexts. Some look like they don't acquire mode_config.mutex, so this is already racy. Again fixing this is material for a separate patch. - The radeon hot_plug function to retrain DP links looks at connector->dpms. Currently this happens without any locking, so is already racy. I think radeon_hotplug_work_func should gain mutex_lock/unlock calls for the mode_config.connection_mutex. - Same applies to i915's intel_dp_hot_plug. But again, this is already racy. - i915 load_detect code needs to acquire this lock. Which means the w/w dance due to Rob's work will be nicely contained to _just_ this function. I've added fixme comments everywhere where it looks suspicious but in the sysfs code. After a quick irc discussion with Dave Airlie it sounds like the lack of locking in there is due to sysfs cleanup fun at module unload. v1: original (only compile tested) v2: missing mutex_init(), etc (from Rob Clark) v3: i915 needs more care in the conversion: - Protect the edp pp logic with the connection_mutex. - Use connection_mutex in the backlight code due to get_pipe_from_connector. - Use drm_modeset_lock_all in suspend/resume paths. - Update lock checks in the overlay code. Cc: Alex Deucher <alexdeucher@gmail.com> Cc: Rob Clark <robdclark@gmail.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Rob Clark <robdclark@gmail.com>
1 parent 8291272 commit 6e9f798

14 files changed

Lines changed: 54 additions & 25 deletions

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void drm_modeset_lock_all(struct drm_device *dev)
5454

5555
mutex_lock(&dev->mode_config.mutex);
5656

57+
mutex_lock(&dev->mode_config.connection_mutex);
58+
5759
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
5860
mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex);
5961
}
@@ -72,6 +74,8 @@ void drm_modeset_unlock_all(struct drm_device *dev)
7274
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
7375
mutex_unlock(&crtc->mutex);
7476

77+
mutex_unlock(&dev->mode_config.connection_mutex);
78+
7579
mutex_unlock(&dev->mode_config.mutex);
7680
}
7781
EXPORT_SYMBOL(drm_modeset_unlock_all);
@@ -93,6 +97,7 @@ void drm_warn_on_modeset_not_all_locked(struct drm_device *dev)
9397
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
9498
WARN_ON(!mutex_is_locked(&crtc->mutex));
9599

100+
WARN_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
96101
WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
97102
}
98103
EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked);
@@ -1793,6 +1798,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
17931798
DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
17941799

17951800
mutex_lock(&dev->mode_config.mutex);
1801+
mutex_lock(&dev->mode_config.connection_mutex);
17961802

17971803
connector = drm_connector_find(dev, out_resp->connector_id);
17981804
if (!connector) {
@@ -1891,6 +1897,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
18911897
out_resp->count_encoders = encoders_count;
18921898

18931899
out:
1900+
mutex_unlock(&dev->mode_config.connection_mutex);
18941901
mutex_unlock(&dev->mode_config.mutex);
18951902

18961903
return ret;
@@ -4640,6 +4647,7 @@ EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
46404647
void drm_mode_config_init(struct drm_device *dev)
46414648
{
46424649
mutex_init(&dev->mode_config.mutex);
4650+
mutex_init(&dev->mode_config.connection_mutex);
46434651
mutex_init(&dev->mode_config.idr_mutex);
46444652
mutex_init(&dev->mode_config.fb_lock);
46454653
INIT_LIST_HEAD(&dev->mode_config.fb_list);

‎drivers/gpu/drm/drm_crtc_helper.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ bool drm_helper_encoder_in_use(struct drm_encoder *encoder)
8989
struct drm_device *dev = encoder->dev;
9090

9191
WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
92+
WARN_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
93+
9294
list_for_each_entry(connector, &dev->mode_config.connector_list, head)
9395
if (connector->encoder == encoder)
9496
return true;

‎drivers/gpu/drm/drm_edid.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,6 +3304,8 @@ struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
33043304
struct drm_connector *connector;
33053305
struct drm_device *dev = encoder->dev;
33063306

3307+
WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
3308+
33073309
list_for_each_entry(connector, &dev->mode_config.connector_list, head)
33083310
if (connector->encoder == encoder && connector->eld[0])
33093311
return connector;

‎drivers/gpu/drm/drm_plane_helper.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc,
5454
struct drm_connector *connector;
5555
int count = 0;
5656

57+
/*
58+
* Note: Once we change the plane hooks to more fine-grained locking we
59+
* need to grab the connection_mutex here to be able to make these
60+
* checks.
61+
*/
62+
WARN_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
63+
5764
list_for_each_entry(connector, &dev->mode_config.connector_list, head)
5865
if (connector->encoder && connector->encoder->crtc == crtc) {
5966
if (connector_list != NULL && count < num_connectors)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
26092609

26102610
*source = INTEL_PIPE_CRC_SOURCE_PIPE;
26112611

2612-
mutex_lock(&dev->mode_config.mutex);
2612+
drm_modeset_lock_all(dev);
26132613
list_for_each_entry(encoder, &dev->mode_config.encoder_list,
26142614
base.head) {
26152615
if (!encoder->base.crtc)
@@ -2645,7 +2645,7 @@ static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
26452645
break;
26462646
}
26472647
}
2648-
mutex_unlock(&dev->mode_config.mutex);
2648+
drm_modeset_unlock_all(dev);
26492649

26502650
return ret;
26512651
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,11 @@ static int i915_drm_freeze(struct drm_device *dev)
533533
* Disable CRTCs directly since we want to preserve sw state
534534
* for _thaw.
535535
*/
536-
mutex_lock(&dev->mode_config.mutex);
536+
drm_modeset_lock_all(dev);
537537
for_each_crtc(dev, crtc) {
538-
mutex_lock(&crtc->mutex);
539538
dev_priv->display.crtc_disable(crtc);
540-
mutex_unlock(&crtc->mutex);
541539
}
542-
mutex_unlock(&dev->mode_config.mutex);
540+
drm_modeset_unlock_all(dev);
543541

544542
intel_modeset_suspend_hw(dev);
545543
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8323,6 +8323,8 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
83238323
connector->base.id, connector->name,
83248324
encoder->base.id, encoder->name);
83258325

8326+
mutex_lock(&dev->mode_config.connection_mutex);
8327+
83268328
/*
83278329
* Algorithm gets a little messy:
83288330
*
@@ -8365,7 +8367,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
83658367
*/
83668368
if (!crtc) {
83678369
DRM_DEBUG_KMS("no pipe available for load-detect\n");
8368-
return false;
8370+
goto fail_unlock_connector;
83698371
}
83708372

83718373
mutex_lock(&crtc->mutex);
@@ -8419,6 +8421,9 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
84198421
else
84208422
intel_crtc->new_config = NULL;
84218423
mutex_unlock(&crtc->mutex);
8424+
fail_unlock_connector:
8425+
mutex_unlock(&dev->mode_config.connection_mutex);
8426+
84228427
return false;
84238428
}
84248429

@@ -8448,6 +8453,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,
84488453
}
84498454

84508455
mutex_unlock(&crtc->mutex);
8456+
mutex_unlock(&connector->dev->mode_config.connection_mutex);
84518457
return;
84528458
}
84538459

@@ -8456,6 +8462,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,
84568462
connector->funcs->dpms(connector, old->dpms_mode);
84578463

84588464
mutex_unlock(&crtc->mutex);
8465+
mutex_unlock(&connector->dev->mode_config.connection_mutex);
84598466
}
84608467

84618468
static int i9xx_pll_refclk(struct drm_device *dev,
@@ -10986,8 +10993,9 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
1098610993
enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
1098710994
{
1098810995
struct drm_encoder *encoder = connector->base.encoder;
10996+
struct drm_device *dev = connector->base.dev;
1098910997

10990-
WARN_ON(!mutex_is_locked(&connector->base.dev->mode_config.mutex));
10998+
WARN_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
1099110999

1099211000
if (!encoder)
1099311001
return INVALID_PIPE;
@@ -11756,9 +11764,9 @@ void intel_modeset_init(struct drm_device *dev)
1175611764
/* Just in case the BIOS is doing something questionable. */
1175711765
intel_disable_fbc(dev);
1175811766

11759-
mutex_lock(&dev->mode_config.mutex);
11767+
drm_modeset_lock_all(dev);
1176011768
intel_modeset_setup_hw_state(dev, false);
11761-
mutex_unlock(&dev->mode_config.mutex);
11769+
drm_modeset_unlock_all(dev);
1176211770

1176311771
for_each_intel_crtc(dev, crtc) {
1176411772
if (!crtc->active)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
11541154
u32 pp;
11551155
u32 pp_stat_reg, pp_ctrl_reg;
11561156

1157-
WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1157+
WARN_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
11581158

11591159
if (!intel_dp->want_panel_vdd && edp_have_panel_vdd(intel_dp)) {
11601160
struct intel_digital_port *intel_dig_port =
@@ -1191,9 +1191,9 @@ static void edp_panel_vdd_work(struct work_struct *__work)
11911191
struct intel_dp, panel_vdd_work);
11921192
struct drm_device *dev = intel_dp_to_dev(intel_dp);
11931193

1194-
mutex_lock(&dev->mode_config.mutex);
1194+
mutex_lock(&dev->mode_config.connection_mutex);
11951195
edp_panel_vdd_off_sync(intel_dp);
1196-
mutex_unlock(&dev->mode_config.mutex);
1196+
mutex_unlock(&dev->mode_config.connection_mutex);
11971197
}
11981198

11991199
static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
@@ -3235,6 +3235,7 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
32353235
u8 sink_irq_vector;
32363236
u8 link_status[DP_LINK_STATUS_SIZE];
32373237

3238+
/* FIXME: This access isn't protected by any locks. */
32383239
if (!intel_encoder->connectors_active)
32393240
return;
32403241

@@ -3665,9 +3666,9 @@ void intel_dp_encoder_destroy(struct drm_encoder *encoder)
36653666
drm_encoder_cleanup(encoder);
36663667
if (is_edp(intel_dp)) {
36673668
cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
3668-
mutex_lock(&dev->mode_config.mutex);
3669+
mutex_lock(&dev->mode_config.connection_mutex);
36693670
edp_panel_vdd_off_sync(intel_dp);
3670-
mutex_unlock(&dev->mode_config.mutex);
3671+
mutex_unlock(&dev->mode_config.connection_mutex);
36713672
}
36723673
kfree(intel_dig_port);
36733674
}
@@ -4246,9 +4247,9 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
42464247
drm_dp_aux_unregister_i2c_bus(&intel_dp->aux);
42474248
if (is_edp(intel_dp)) {
42484249
cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4249-
mutex_lock(&dev->mode_config.mutex);
4250+
mutex_lock(&dev->mode_config.connection_mutex);
42504251
edp_panel_vdd_off_sync(intel_dp);
4251-
mutex_unlock(&dev->mode_config.mutex);
4252+
mutex_unlock(&dev->mode_config.connection_mutex);
42524253
}
42534254
drm_sysfs_connector_remove(connector);
42544255
drm_connector_cleanup(connector);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static u32 asle_set_backlight(struct drm_device *dev, u32 bclp)
410410
if (bclp > 255)
411411
return ASLC_BACKLIGHT_FAILED;
412412

413-
mutex_lock(&dev->mode_config.mutex);
413+
mutex_lock(&dev->mode_config.connection_mutex);
414414

415415
/*
416416
* Update backlight on all connectors that support backlight (usually
@@ -421,7 +421,7 @@ static u32 asle_set_backlight(struct drm_device *dev, u32 bclp)
421421
intel_panel_set_backlight(intel_connector, bclp, 255);
422422
iowrite32(DIV_ROUND_UP(bclp * 100, 255) | ASLE_CBLV_VALID, &asle->cblv);
423423

424-
mutex_unlock(&dev->mode_config.mutex);
424+
mutex_unlock(&dev->mode_config.connection_mutex);
425425

426426

427427
return 0;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,
688688
u32 swidth, swidthsw, sheight, ostride;
689689

690690
BUG_ON(!mutex_is_locked(&dev->struct_mutex));
691-
BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
691+
BUG_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
692692
BUG_ON(!overlay);
693693

694694
ret = intel_overlay_release_old_vid(overlay);
@@ -793,7 +793,7 @@ int intel_overlay_switch_off(struct intel_overlay *overlay)
793793
int ret;
794794

795795
BUG_ON(!mutex_is_locked(&dev->struct_mutex));
796-
BUG_ON(!mutex_is_locked(&dev->mode_config.mutex));
796+
BUG_ON(!mutex_is_locked(&dev->mode_config.connection_mutex));
797797

798798
ret = intel_overlay_recover_from_interrupt(overlay);
799799
if (ret != 0)

0 commit comments

Comments
 (0)