Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/edid: edid_fixup_preferred_max_vrefresh() promotes unvalidated mode - [Medium] drm/edid: is_detailed_mode() matches non-detailed DRM_MODE_TYPE_DRIVER modes - [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() mishandles multiple preferred - [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() replaces equal-vrefresh mode --
commit 74767c3cc3c0bdb88a5c146313bff24e0fe4bfc0 Author: Jianeng Ceng <[email protected]> drm/edid: prefer highest refresh mode within native resolution on eDP This commit updates eDP connector mode probing to re-point DRM_MODE_TYPE_PREFERRED to the highest refresh rate detailed mode that shares the resolution of the original preferred mode. > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c > index b8f882a17c8f1..13c5a4d099b01 100644 > --- a/drivers/gpu/drm/drm_edid.c > +++ b/drivers/gpu/drm/drm_edid.c > @@ -3076,6 +3076,79 @@ static void edid_fixup_preferred(struct drm_connector > *connector) > preferred_mode->type |= DRM_MODE_TYPE_PREFERRED; > } > > +/* Only modes parsed from detailed timings describe the panel itself. */ > +static bool is_detailed_mode(const struct drm_display_mode *mode) > +{ > + return mode->type & DRM_MODE_TYPE_DRIVER; > +} [Severity: Medium] Does checking DRM_MODE_TYPE_DRIVER in is_detailed_mode() also match non-detailed modes? edid_fixup_preferred_max_vrefresh() runs at the end of _drm_edid_connector_add_modes() after standard, established, CEA, DisplayID, and inferred modes have been added to connector->probed_modes. Modes in drm_dmt_modes[] (added by add_inferred_modes() -> drm_dmt_modes_for_range() on continuous-frequency panels and by add_standard_modes()), edid_est_modes[], CEA mode tables, and DisplayID modes from drm_mode_displayid_detailed() and drm_mode_displayid_formula() all carry DRM_MODE_TYPE_DRIVER. An inferred DMT or DisplayID formula mode at the native resolution with a higher refresh rate (such as a 75Hz, 85Hz, or 120Hz RB DMT entry) will pass is_detailed_mode() and replace the panel's actual detailed timing as DRM_MODE_TYPE_PREFERRED. > + > +/* > + * Walk the mode list for connector and re-point the preferred status to the > + * mode with the highest vertical refresh rate among the detailed modes that > + * share the resolution of the current preferred mode. > + * > + * Only detailed timings are considered: inferred, CVT and standard timing > + * modes are not derived from the panel's own timing descriptors and must not > + * replace it as preferred. > + */ > +static void edid_fixup_preferred_max_vrefresh(struct drm_connector > *connector) > +{ > + struct drm_display_mode *cur_mode, *preferred_mode = NULL; > + struct drm_display_mode *candidate_mode = NULL; > + int hdisplay, vdisplay; > + > + /* Nothing to do if the EDID does not mark any mode preferred. */ > + list_for_each_entry(cur_mode, &connector->probed_modes, head) { > + if (cur_mode->type & DRM_MODE_TYPE_PREFERRED) { > + preferred_mode = cur_mode; > + break; > + } > + } [Severity: Medium] What happens when connector->probed_modes has more than one mode marked DRM_MODE_TYPE_PREFERRED? Breaking on the first preferred mode ignores any later preferred mode, such as a higher-resolution preferred timing added by add_displayid_detailed_modes(), leaving multiple preferred modes in the list and failing to promote the highest refresh rate at the DisplayID preferred resolution. In addition, if multiple modes at the first preferred mode's resolution have DRM_MODE_TYPE_PREFERRED set and the first one already has the highest refresh rate, the candidate_mode == preferred_mode check below returns early without clearing DRM_MODE_TYPE_PREFERRED from the other modes. > + > + if (!preferred_mode) > + return; > + > + if (!is_detailed_mode(preferred_mode)) > + return; > + > + /* The preferred mode defines the native resolution. */ > + hdisplay = preferred_mode->hdisplay; > + vdisplay = preferred_mode->vdisplay; > + > + list_for_each_entry(cur_mode, &connector->probed_modes, head) { > + if (!is_detailed_mode(cur_mode)) > + continue; > + > + if (cur_mode->hdisplay != hdisplay || > + cur_mode->vdisplay != vdisplay) > + continue; > + > + if (!candidate_mode || > + drm_mode_vrefresh(cur_mode) > > drm_mode_vrefresh(candidate_mode)) > + candidate_mode = cur_mode; > + } > + > + if (!candidate_mode || candidate_mode == preferred_mode) > + return; [Severity: Medium] Can this replace preferred_mode with an earlier mode that has the same integer drm_mode_vrefresh() value? Because candidate_mode starts at NULL instead of preferred_mode, an earlier non-preferred mode at (hdisplay, vdisplay) with the same drm_mode_vrefresh() value is latched on the first matching iteration and is not replaced when the loop reaches preferred_mode. candidate_mode != preferred_mode then causes DRM_MODE_TYPE_PREFERRED to be moved to that earlier mode even though its refresh rate is not higher. Initializing candidate_mode to preferred_mode would ensure it only changes when a mode has a strictly higher vertical refresh rate. > + > + list_for_each_entry(cur_mode, &connector->probed_modes, head) { > + if (!is_detailed_mode(cur_mode)) > + continue; > + > + if (cur_mode->hdisplay != hdisplay || > + cur_mode->vdisplay != vdisplay) > + continue; > + > + cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED; > + } > + > + candidate_mode->type |= DRM_MODE_TYPE_PREFERRED; > + > + drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] preferred mode: " > + DRM_MODE_FMT "\n", connector->base.id, connector->name, > + DRM_MODE_ARG(candidate_mode)); > +} > + > static bool > mode_is_rb(const struct drm_display_mode *mode) > { > @@ -7242,6 +7315,9 @@ static int _drm_edid_connector_add_modes(struct > drm_connector *connector, > drm_edid_has_internal_quirk(connector, EDID_QUIRK_PREFER_LARGE_75)) > edid_fixup_preferred(connector); > > + if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) > + edid_fixup_preferred_max_vrefresh(connector); > + > return num_modes; > } [Severity: High] Can promoting the highest-refresh mode in _drm_edid_connector_add_modes() before mode validation leave the connector without a preferred mode or break drivers that snapshot the preferred mode from probed_modes? _drm_edid_connector_add_modes() runs during .get_modes(), before __drm_helper_update_and_validate() and drm_mode_prune_invalid() in drm_helper_probe_single_connector_modes(). If the promoted highest-refresh mode exceeds source GPU dotclock, bridge, VBT, or eDP link bandwidth limits and is later rejected by mode_valid(), drm_mode_prune_invalid() removes it after DRM_MODE_TYPE_PREFERRED has already been stripped from the original 60Hz preferred mode, leaving connector->modes with no preferred mode. Drivers also consume DRM_MODE_TYPE_PREFERRED directly from connector->probed_modes right after drm_edid_connector_add_modes() and before mode_valid() runs. In i915, intel_edp_init_connector() calls intel_panel_add_edid_fixed_modes() immediately after drm_edid_connector_add_modes(), caching the preferred mode as intel_panel_preferred_fixed_mode(), and intel_dp_can_link_train_fallback_for_edp() rejects any fallback link rate or lane count that cannot sustain fixed_mode->clock. In amdgpu_dm, amdgpu_dm_connector_ddc_get_modes() latches the preferred mode into amdgpu_encoder->native_mode before mode_valid() and uses its pixel clock to synthesize all common scaled modes in amdgpu_dm_create_common_mode(). Also, running edid_fixup_preferred_max_vrefresh() unconditionally after edid_fixup_preferred() overrides the 60Hz or 75Hz target refresh rate selected when EDID_QUIRK_PREFER_LARGE_60 or EDID_QUIRK_PREFER_LARGE_75 is set on an eDP connector. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203034601.675116-1-cengjian...@huaqin.corp-partner.google.com?part=1
