v2 of the patch, addressing the AI review of v1.

The review raised three points:

1. The preferred mode was promoted before validation, so a mode that is
   later rejected by ->mode_valid() could carry DRM_MODE_TYPE_PREFERRED.

   v2 no longer promotes blindly: a candidate is selected first and the old
   PREFERRED bit is cleared only after a different candidate has been
   confirmed. When the highest refresh mode is already the preferred one
   the mode list is left untouched. The remaining window, where the
   candidate itself is pruned later by ->mode_valid(), is inherent to
   running before drm_mode_prune_invalid() and can only be closed by a
   driver side fallback, which is outside the scope of this patch.

2. Modes that are not parsed from detailed timings could be promoted.

   Fixed: only modes carrying DRM_MODE_TYPE_DRIVER are considered, both
   when selecting the candidate and when clearing the flag. Inferred, CVT,
   standard timing and DisplayID modes are skipped.

3. A mode list without any PREFERRED bit, or with several of them, was
   mishandled.

   Fixed: the function returns early when no mode is preferred instead of
   forcing PREFERRED onto the first mode, and the whole list is scanned
   instead of breaking out on the first PREFERRED hit.

Validation: on eDP panels that report a 60Hz timing as preferred while
also supporting 120Hz at the native resolution, and on panels that already
report 120Hz as preferred, userspace now selects the 120Hz mode as
preferred in both cases.

On Wed, Dec 2, 2026 at 8:18 PM <[email protected]> wrote:

> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
>   unvalidated mode
> - [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() promotes
>   non-detailed modes
> - [Medium] drm/edid: edid_fixup_preferred_max_vrefresh() mishandles
>   multiple preferred
> --
>
> commit e313f14ca873716202a489a3beac07169e41bd70
> Author: Jianeng Ceng <[email protected]>
>
> drm/edid: prefer highest refresh mode within native resolution on eDP
>
> This commit adds edid_fixup_preferred_max_vrefresh() to move
> DRM_MODE_TYPE_PREFERRED to the highest refresh rate mode sharing the
> preferred mode's resolution on eDP connectors.
>
> > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > index b8f882a17c8f1..e8a6bdc00e326 100644
> > --- a/drivers/gpu/drm/drm_edid.c
> > +++ b/drivers/gpu/drm/drm_edid.c
> > @@ -3076,6 +3076,53 @@ static void edid_fixup_preferred(struct
> drm_connector *connector)
> >       preferred_mode->type |= 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 modes that
> share the
> > + * resolution of the current preferred mode.
> > + */
> > +static void edid_fixup_preferred_max_vrefresh(struct drm_connector
> *connector)
> > +{
> > +     struct drm_display_mode *cur_mode, *preferred_mode;
> > +     int hdisplay, vdisplay;
> > +
> > +     if (list_empty(&connector->probed_modes))
> > +             return;
> > +
> > +     preferred_mode = list_first_entry(&connector->probed_modes,
> > +                                       struct drm_display_mode, head);
> > +     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]
> Does breaking on the first DRM_MODE_TYPE_PREFERRED mode miss preferred
> modes at a higher resolution from DisplayID extension blocks?
>
> drm_mode_displayid_detailed() adds modes with DRM_MODE_TYPE_PREFERRED
> after add_detailed_modes().  If the base EDID block has a fallback
> preferred mode and a DisplayID block has a higher-resolution preferred
> mode, this loop stops at the base EDID mode and only updates modes at
> that lower resolution.  Also, if no mode in connector->probed_modes has
> DRM_MODE_TYPE_PREFERRED set, preferred_mode falls back to
> list_first_entry() and receives DRM_MODE_TYPE_PREFERRED unconditionally
> at the end of the function.
>
> > +
> > +     hdisplay = preferred_mode->hdisplay;
> > +     vdisplay = preferred_mode->vdisplay;
> > +
> > +     list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> > +             if (cur_mode->hdisplay != hdisplay || cur_mode->vdisplay
> != vdisplay)
> > +                     continue;
> > +
> > +             cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
> > +     }
> > +
> > +     list_for_each_entry(cur_mode, &connector->probed_modes, head) {
> > +             if (cur_mode->hdisplay != hdisplay || cur_mode->vdisplay
> != vdisplay)
> > +                     continue;
> > +
> > +             if (drm_mode_vrefresh(cur_mode) >
> drm_mode_vrefresh(preferred_mode))
> > +                     preferred_mode = cur_mode;
> > +     }
> > +
> > +     preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
>
> [Severity: High]
> Can moving DRM_MODE_TYPE_PREFERRED to the highest refresh rate mode
> before mode validation leave connector->modes with no preferred mode or
> break drivers that latch 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().  If the
> highest-refresh mode exceeds the GPU dotclock, VBT limit, or available
> eDP link bandwidth, drm_mode_prune_invalid() removes it after
> DRM_MODE_TYPE_PREFERRED has already been cleared from the 60Hz mode.
>
> In addition, drivers such as i915 and amdgpu snapshot the preferred mode
> from connector->probed_modes right after drm_edid_connector_add_modes()
> before mode_valid() runs.  In i915, intel_edp_init_connector() ->
> intel_panel_add_edid_fixed_modes() stores that mode as the primary
> fixed_mode, and intel_dp_can_link_train_fallback_for_edp() rejects any
> link training fallback rate or lane count that cannot sustain
> fixed_mode->clock.
>
> > +
> > +     drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] preferred mode: "
> > +                 DRM_MODE_FMT "\n", connector->base.id,
> connector->name,
> > +                 DRM_MODE_ARG(preferred_mode));
> > +}
> > +
> >  static bool
> >  mode_is_rb(const struct drm_display_mode *mode)
> >  {
> > @@ -7242,6 +7289,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: Medium]
> Can calling edid_fixup_preferred_max_vrefresh() here promote an inferred
> VESA DMT mode over the panel's native detailed timing?
>
> At this point in _drm_edid_connector_add_modes(), add_cvt_modes(),
> add_standard_modes(), add_established_modes(), and add_inferred_modes()
> have already appended non-detailed modes to connector->probed_modes.  On
> a VRR eDP panel with DRM_EDID_FEATURE_CONTINUOUS_FREQ and a range
> descriptor extending above the DTD refresh rate (at a DMT resolution
> such as 1920x1200 or 2560x1600), drm_dmt_modes_for_range() adds higher
> refresh DMT timings that do not match the panel's blanking or sync flags,
> which then replace the panel's DTD as DRM_MODE_TYPE_PREFERRED and break
> exact timing checks such as i915's is_alt_drrs_mode().  Running this
> unconditionally after edid_fixup_preferred() also overrides
> EDID_QUIRK_PREFER_LARGE_60 and EDID_QUIRK_PREFER_LARGE_75 on eDP
> connectors.
>
> --
> Sashiko AI review ·
> https://sashiko.dev/#/patchset/20261202120153.1051508-1-cengjian...@huaqin.corp-partner.google.com?part=1
>

Reply via email to