drm/atomic_helper: Stop modesets on unregistered connectors harder
Subsystems (4)
PATCH 1/1 drm/atomic_helper: Stop modesets on unregistered connectors harder
Unfortunately, it appears our fix in:
commit b5d29843d8ef ("drm/atomic_helper: Allow DPMS On<->Off changes for unregistered connectors")
Which attempted to work around the problems introduced by:
commit 4d80273976bf ("drm/atomic_helper: Disallow new modesets on unregistered connectors")
Is still not the right solution, as modesets can still be triggered outside of drm_atomic_set_crtc_for_connector().
So in order to fix this, while still being careful that we don't break modesets that a driver may perform before being registered with userspace, we replace connector->registered with a tristate member, connector->registration_state. This allows us to keep track of whether or not a connector is still initializing and hasn't been exposed to userspace, is currently registered and exposed to userspace, or has been legitimately removed from the system after having once been present.
Using this info, we can prevent userspace from performing new modesets on unregistered connectors while still allowing the driver to perform modesets on unregistered connectors before the driver has finished being registered.
--- drivers/gpu/drm/drm_atomic_helper.c | 60 +++++++++++++++++++++---- drivers/gpu/drm/drm_atomic_uapi.c | 21 --------- drivers/gpu/drm/drm_connector.c | 10 ++--- drivers/gpu/drm/i915/intel_dp_mst.c | 8 ++-- include/drm/drm_connector.h | 68 ++++++++++++++++++++++++++++- 5 files changed, 127 insertions(+), 40 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +52 -8
@@ -529,6 +529,35 @@ mode_valid(struct drm_atomic_state *state)return 0 ; } +static int +unregistered_connector_check (struct drm_atomic_state *state, +struct drm_connector *connector, +struct drm_connector_state *old_conn_state, +struct drm_connector_state *new_conn_state) +{ +struct drm_crtc_state *crtc_state; +struct drm_crtc *crtc; + +if (!drm_connector_unregistered (connector)) +return 0 ; + + crtc = new_conn_state->crtc; +if (!crtc) +return 0 ; + + crtc_state =drm_atomic_get_new_crtc_state (state, crtc); +if (!crtc_state || !drm_atomic_crtc_needs_modeset (crtc_state)) +return 0 ; + +if (crtc_state->mode_changed) { +DRM_DEBUG_ATOMIC ("[CONNECTOR:%d:%s] can't change mode on unregistered connector\n" , + connector->base.id, connector->name); +return -EINVAL ; + } + +return 0 ; +} +/** * drm_atomic_helper_check_modeset - validate state object for modeset changes * @dev: DRM device
@@ -684,18 +713,33 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,return ret; } -/* -* Iterate over all connectors again, to make sure atomic_check() -* has been called on them when a modeset is forced. -*/ for_each_oldnew_connector_in_state (state, connector, old_connector_state, new_connector_state, i) {const struct drm_connector_helper_funcs *funcs = connector->helper_private; -if (connectors_mask &BIT (i)) -continue ; +/* Make sure atomic_check() is called on any unchecked +* connectors when a modeset has been forced +*/ +if (connectors_mask &BIT (i) && funcs->atomic_check) { + ret = funcs->atomic_check (connector, + new_connector_state); +if (ret) +return ret; + } -if (funcs->atomic_check) - ret = funcs->atomic_check (connector, new_connector_state); +/* +* Prevent userspace from turning on new displays or setting +* new modes using connectors which have been removed from +* userspace. This is racy since an unplug could happen at any +* time including after this check, but that's OK: we only +* care about preventing userspace from trying to set invalid +* state using destroyed connectors that it's been notified +* about. No one can save us after the atomic check completes +* but ourselves. +*/ + ret =unregistered_connector_check (state, + connector, + old_connector_state, + new_connector_state);if (ret)return ret; }
drivers/gpu/drm/drm_atomic_uapi.c +0 -21
@@ -299,27 +299,6 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,struct drm_connector *connector = conn_state->connector;struct drm_crtc_state *crtc_state; -/* -* For compatibility with legacy users, we want to make sure that -* we allow DPMS On<->Off modesets on unregistered connectors, since -* legacy modesetting users will not be expecting these to fail. We do -* not however, want to allow legacy users to assign a connector -* that's been unregistered from sysfs to another CRTC, since doing -* this with a now non-existent connector could potentially leave us -* in an invalid state. -* -* Since the connector can be unregistered at any point during an -* atomic check or commit, this is racy. But that's OK: all we care -* about is ensuring that userspace can't use this connector for new -* configurations after it's been notified that the connector is no -* longer present. -*/ -if (!READ_ONCE (connector->registered) && crtc) { -DRM_DEBUG_ATOMIC ("[CONNECTOR:%d:%s] is not registered\n" , - connector->base.id, connector->name); -return -EINVAL ; - } -if (conn_state->crtc == crtc)return 0 ;
drivers/gpu/drm/drm_connector.c +5 -5
@@ -396,7 +396,7 @@ void drm_connector_cleanup(struct drm_connector *connector)/* The connector should have been removed from userspace long before * it is finally destroyed. */ -if (WARN_ON (connector->registered)) +if (WARN_ON (!drm_connector_unregistered (connector)))drm_connector_unregister (connector);if (connector->tile_group) {
@@ -453,7 +453,7 @@ int drm_connector_register(struct drm_connector *connector)return 0 ;mutex_lock (&connector->mutex); -if (connector->registered) +if (connector->registration_state !=DRM_CONNECTOR_INITIALIZING ) goto unlock; ret =drm_sysfs_connector_add (connector);
@@ -473,7 +473,7 @@ int drm_connector_register(struct drm_connector *connector)drm_mode_object_register (connector->dev, &connector->base); - connector->registered = true; + connector->registration_state =DRM_CONNECTOR_REGISTERED ; goto unlock; err_debugfs:
@@ -495,7 +495,7 @@ EXPORT_SYMBOL(drm_connector_register);void drm_connector_unregister (struct drm_connector *connector) {mutex_lock (&connector->mutex); -if (!connector->registered) { +if (connector->registration_state !=DRM_CONNECTOR_REGISTERED ) {mutex_unlock (&connector->mutex);return ; }
@@ -506,7 +506,7 @@ void drm_connector_unregister(struct drm_connector *connector)drm_sysfs_connector_remove (connector);drm_debugfs_connector_remove (connector); - connector->registered = false; + connector->registration_state =DRM_CONNECTOR_UNREGISTERED ;mutex_unlock (&connector->mutex); }EXPORT_SYMBOL (drm_connector_unregister);
drivers/gpu/drm/i915/intel_dp_mst.c +4 -4
@@ -78,7 +78,7 @@ static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, pipe_config->pbn = mst_pbn;/* Zombie connectors can't have VCPI slots */ -if (READ_ONCE (connector->registered)) { +if (!drm_connector_unregistered (connector)) { slots = drm_dp_atomic_find_vcpi_slots(state, &intel_dp->mst_mgr, port,
@@ -314,7 +314,7 @@ static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector)struct edid *edid;int ret; -if (!READ_ONCE (connector->registered)) +if (drm_connector_unregistered (connector))return intel_connector_update_modes (connector,NULL ); edid =drm_dp_mst_get_edid (connector, &intel_dp->mst_mgr, intel_connector->port);
@@ -330,7 +330,7 @@ intel_dp_mst_detect(struct drm_connector *connector, bool force)struct intel_connector *intel_connector =to_intel_connector (connector);struct intel_dp *intel_dp = intel_connector->mst_port; -if (!READ_ONCE (connector->registered)) +if (drm_connector_unregistered (connector))return connector_status_disconnected;return drm_dp_mst_detect_port (connector, &intel_dp->mst_mgr, intel_connector->port);
@@ -361,7 +361,7 @@ intel_dp_mst_mode_valid(struct drm_connector *connector,int bpp =24 ;/* MST uses fixed bpp */ int max_rate, mode_rate, max_lanes, max_link_clock; -if (!READ_ONCE (connector->registered)) +if (drm_connector_unregistered (connector))return MODE_ERROR ;if (mode->flags &DRM_MODE_FLAG_DBLSCAN )
include/drm/drm_connector.h +66 -2
88 lines not on this page · raw message
Signature · 6 lines
2.17.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BAT: failure for drm/atomic_helper: Stop modesets on unregistered connectors harder
== Series Details ==
== Series Details ==
Series: drm/atomic_helper: Stop modesets on unregistered connectors harder
URL : https://patchwork.freedesktop.org/series/51041/
State : failure
== Summary ==
= CI Bug Log - changes from CI_DRM_4984 -> Patchwork_10466 =
== Summary - FAILURE ==
Serious unknown changes coming with Patchwork_10466 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_10466, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://patchwork.freedesktop.org/api/1.0/series/51041/revisions/1/mbox/
== Possible new issues ==
Here are the unknown changes that may have been introduced in Patchwork_10466:
=== IGT changes ===
==== Possible regressions ====
igt@drv_module_reload@basic-reload:
fi-kbl-8809g: PASS -> DMESG-WARN +3
igt@drv_module_reload@basic-reload-inject:
fi-skl-6260u: PASS -> DMESG-WARN
fi-snb-2600: PASS -> DMESG-WARN
fi-kbl-7560u: PASS -> DMESG-WARN
fi-kbl-guc: PASS -> DMESG-WARN
fi-skl-6770hq: PASS -> DMESG-WARN
fi-bwr-2160: PASS -> DMESG-WARN
fi-kbl-r: PASS -> DMESG-WARN
fi-cfl-s3: PASS -> DMESG-WARN
fi-byt-clapper: PASS -> DMESG-WARN
fi-gdg-551: PASS -> DMESG-WARN
fi-icl-u2: PASS -> DMESG-WARN
fi-bsw-kefka: PASS -> DMESG-WARN
fi-bdw-gvtdvm: PASS -> DMESG-WARN
fi-ilk-650: PASS -> DMESG-WARN
fi-bsw-n3050: PASS -> DMESG-WARN
fi-cnl-u: PASS -> DMESG-WARN
fi-kbl-7567u: PASS -> DMESG-WARN +2
fi-glk-j4005: PASS -> DMESG-WARN
fi-skl-iommu: PASS -> DMESG-WARN
fi-ivb-3770: PASS -> DMESG-WARN
fi-skl-gvtdvm: PASS -> DMESG-WARN
fi-whl-u: PASS -> DMESG-WARN
fi-skl-6700hq: PASS -> DMESG-WARN
fi-ivb-3520m: PASS -> DMESG-WARN
fi-glk-dsi: PASS -> DMESG-WARN
fi-bdw-5557u: PASS -> DMESG-WARN
{fi-apl-guc}: PASS -> DMESG-WARN
fi-cfl-8700k: PASS -> DMESG-WARN
fi-icl-u: NOTRUN -> DMESG-WARN
fi-kbl-x1275: PASS -> DMESG-WARN
fi-skl-6600u: PASS -> DMESG-WARN
fi-pnv-d510: PASS -> DMESG-WARN
fi-skl-guc: PASS -> DMESG-WARN
fi-cfl-guc: PASS -> DMESG-WARN
fi-skl-6700k2: PASS -> DMESG-WARN
fi-elk-e7500: PASS -> DMESG-WARN
igt@pm_rpm@module-reload:
fi-cfl-8109u: PASS -> DMESG-WARN +2
fi-kbl-7500u: PASS -> DMESG-WARN +2== Known issues ==
Here are the changes found in Patchwork_10466 that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@drv_getparams_basic@basic-subslice-total:
fi-snb-2520m: PASS -> DMESG-WARN (fdo#103713) +10
igt@drv_module_reload@basic-reload-inject:
fi-bxt-j4205: PASS -> DMESG-WARN (fdo#107821)
fi-bxt-dsi: PASS -> DMESG-WARN (fdo#107821)
fi-hsw-4770: PASS -> DMESG-WARN (fdo#107924)
fi-hsw-peppy: PASS -> DMESG-WARN (fdo#107924)
fi-hsw-4770r: PASS -> DMESG-WARN (fdo#107924)
igt@drv_selftest@live_hangcheck:
fi-icl-u: NOTRUN -> INCOMPLETE (fdo#108315)
igt@kms_flip@basic-flip-vs-modeset:
fi-hsw-4770r: PASS -> DMESG-WARN (fdo#105602) +1
==== Possible fixes ====
igt@kms_frontbuffer_tracking@basic:
fi-byt-clapper: FAIL (fdo#103167) -> PASS {name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
fdo#105602 https://bugs.freedesktop.org/show_bug.cgi?id=105602
fdo#107821 https://bugs.freedesktop.org/show_bug.cgi?id=107821
fdo#107924 https://bugs.freedesktop.org/show_bug.cgi?id=107924
fdo#108315 https://bugs.freedesktop.org/show_bug.cgi?id=108315
== Participating hosts (53 -> 47) ==
Additional (1): fi-icl-u
Missing (7): fi-ilk-m540 fi-hsw-4200u fi-byt-j1900 fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-n2820
== Build changes ==
* Linux: CI_DRM_4984 -> Patchwork_10466
CI_DRM_4984: 90b59df999a13a6405f8d7ece08a69120a9b361a @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4678: 9310a1265ceabeec736bdf0a76e1e0357c76c0b1 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_10466: 26909bc1ea409e674f04fca95b55bed4c69caa9c @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
26909bc1ea40 drm/atomic_helper: Stop modesets on unregistered connectors harder
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_10466/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 108 lines · Lyude Paul
Unfortunately, it appears our fix in:
commitb5d29843d8ef("drm/atomic_helper: Allow DPMS On<->Off changes for unregistered connectors")Which attempted to work around the problems introduced by:
commit4d80273976bf("drm/atomic_helper: Disallow new modesets on unregistered connectors")Is still not the right solution, as modesets can still be triggered outside of
drm_atomic_set_crtc_for_connector().So in order to fix this, while still being careful that we don't break modesets that a driver may perform before being registered with userspace, we replace
connector->registeredwith a tristate member,connector->registration_state. This allows us to keep track of whether or not a connector is still initializing and hasn't been exposed to userspace, is currently registered and exposed to userspace, or has been legitimately removed from the system after having once been present.Using this info, we can prevent userspace from performing new modesets on unregistered connectors while still allowing the driver to perform modesets on unregistered connectors before the driver has finished being registered.
Fixes b5d29843d8ef ("drm/atomic_helper: Allow DPMS On<->Off changes for unregistered connectors")Cc Ville Syrjälä <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc David Airlie <[email protected]>Signed-off-by Lyude Paul <[email protected]>--- drivers/gpu/drm/drm_atomic_helper.c | 60 +++++++++++++++++++++---- drivers/gpu/drm/drm_atomic_uapi.c | 21 --------- drivers/gpu/drm/drm_connector.c | 10 ++--- drivers/gpu/drm/i915/intel_dp_mst.c | 8 ++-- include/drm/drm_connector.h | 68 ++++++++++++++++++++++++++++- 5 files changed, 127 insertions(+), 40 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +42
-8@@ -529,6 +529,35 @@ mode_valid(struct drm_atomic_state *state)return 0 ; } +static int +unregistered_connector_check (struct drm_atomic_state *state, +struct drm_connector *connector, +struct drm_connector_state *old_conn_state, +struct drm_connector_state *new_conn_state) +{ +struct drm_crtc_state *crtc_state; +struct drm_crtc *crtc; + +if (!drm_connector_unregistered (connector)) +return 0 ; + + crtc = new_conn_state->crtc; +if (!crtc) +return 0 ; + + crtc_state =drm_atomic_get_new_crtc_state (state, crtc); +if (!crtc_state || !drm_atomic_crtc_needs_modeset (crtc_state)) +return 0 ; + +if (crtc_state->mode_changed) { +DRM_DEBUG_ATOMIC ("[CONNECTOR:%d:%s] can't change mode on unregistered connector\n" , + connector->base.id, connector->name); +return -EINVAL ; + } + +return 0 ; +} +/** * drm_atomic_helper_check_modeset - validate state object for modeset changes * @dev: DRM device @@ -684,18 +713,33 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,return ret; } -/* -* Iterate over all connectors again, to make sure atomic_check() -* has been called on them when a modeset is forced. -*/ for_each_oldnew_connector_in_state (state, connector, old_connector_state, new_connector_state, i) {const struct drm_connector_helper_funcs *funcs = connector->helper_private; -if (connectors_mask &BIT (i)) -continue ; +/* Make sure atomic_check() is called on any unchecked +* connectors when a modeset has been forced +*/ +if (connectors_mask &BIT (i) && funcs->atomic_check) { + ret = funcs->atomic_check (connector, + new_connector_state); +if (ret) +return ret; + } -if (funcs->atomic_check) - ret = funcs->atomic_check (connector, new_connector_state); +/* +* Prevent userspace from turning on new displays or setting +* new modes using connectors which have been removed from +* userspace. This is racy since an unplug could happen at any
drivers/gpu/drm/drm_atomic_helper.c drm_atomic_helper_check_modeset(struct drm_device *dev, · line 742
Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +10
-0+* time including after this check, but that's OK: we only +* care about preventing userspace from trying to set invalid +* state using destroyed connectors that it's been notified +* about. No one can save us after the atomic check completes +* but ourselves. +*/ + ret =unregistered_connector_check (state, + connector, + old_connector_state, + new_connector_state);
I expect a functional revert of b5d29843d8ef ("drm/atomic_helper: Allow DPMS On<->Off changes for unregistered connectors"), but with drm_connector_unregistered() instead of the READ_ONCE. This here is entirely different, and I'm not clear on why.
Aside from this looks good to me.
[snip]
drivers/gpu/drm/drm_atomic_helper.c drm_atomic_helper_check_modeset(struct drm_device *dev,
Quoted 12 lines
drivers/gpu/drm/drm_atomic_helper.c +12
-0+/** +* drm_connector_unregistered - has the connector been unregistered from +* userspace? +* @connector: DRM connector +* +* Checks whether or not @connector has been unregistered from userspace. +* +* Returns: +* True if the connector was unregistered, false if the connector is +* registered or has not yet been registered with userspace. +*/ +static inline bool drm_connector_unregistered (struct drm_connector *connector)
Bikeshed: I'd call this drm_connector_is_unregistered(). C is imperative, functions without verbs always look a bit funny to me :-)
Feel free to ignore the bikeshed.
Cheers, Daniel
Quoted 11 lines
drivers/gpu/drm/drm_atomic_helper.c +5
-0+{ +return READ_ONCE (connector->registration_state) == +DRM_CONNECTOR_UNREGISTERED ; +} +const char *drm_get_connector_status_name (enum drm_connector_status status);const char *drm_get_subpixel_order_name (enum subpixel_order order);const char *drm_get_dpms_name (int val);Signature · 1 line
2.17.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx