Thank you for your contribution! Sashiko AI review found 3 potential issue(s) 
to consider:
- [Medium] drm/hdmi: handle vrr_max == 0 in 
drm_connector_hdmi_update_vrr_limits()
- [Medium] drm/hdmi: stale VRR limits on unplug in 
drm_connector_hdmi_update_vrr_limits()
- [Medium] drm/hdmi: unclamped cnmvrr max_hz in 
drm_connector_hdmi_update_vrr_limits()
--

commit 8141ba1132150753b66c1d4aef2157bc2d78d4cb
Author: Nicolas Frattaroli <[email protected]>

drm/connector: Add vrr_display_{min,max} connector properties

This commit adds the immutable vrr_display_min and vrr_display_max connector
properties to expose the minimum and maximum integer refresh rates supported
with VRR in the current mode. It also introduces helpers to attach these
properties and update their values for HDMI connectors.

> diff --git a/drivers/gpu/drm/display/drm_hdmi_helper.c 
> b/drivers/gpu/drm/display/drm_hdmi_helper.c
> index f85cce3d62547..8f325d5e496d1 100644
> --- a/drivers/gpu/drm/display/drm_hdmi_helper.c
> +++ b/drivers/gpu/drm/display/drm_hdmi_helper.c
> @@ -730,3 +730,58 @@ int drm_connector_hdmi_sync_scdc(struct drm_connector 
> *connector, bool plugged,
>       return ret;
>  }
>  EXPORT_SYMBOL(drm_connector_hdmi_sync_scdc);
> +
> +/**
> + * drm_connector_hdmi_update_vrr_limits - update VRR display limit properties
> + * @conn: pointer to the &struct drm_connector to set the properties on
> + * @mode: pointer to the &struct drm_display_mode to consider while updating
> + *
> + * Update the "vrr_display_min" and "vrr_display_max" properties on @conn 
> based
> + * on its HDMI sink info and the current mode. Does not consider any display
> + * protocol other than HDMI.
> + *
> + * Will set both min and max to 0 if max happens to end up below min, which 
> can
> + * happen with CNMVRR==0 and a lower refresh rate @mode.
> + *
> + * Return: %0 on success, negative errno otherwise
> + */
> +int drm_connector_hdmi_update_vrr_limits(struct drm_connector *conn,
> +                                      const struct drm_display_mode *mode)
> +{
> +     struct drm_mode_object *obj = &conn->base;
> +     const struct drm_display_info *info;
> +     u16 min_hz, max_hz;
> +
> +     if (!conn->vrr_display_min_property || !conn->vrr_display_max_property)
> +             return -ENOENT;
> +
> +     info = &conn->display_info;
> +
> +     if (!info->is_hdmi)
> +             return -EINVAL;
> +
> +     if (conn->status != connector_status_connected ||
> +         !info->hdmi.vrr_cap.supported) {
> +             drm_object_property_set_value(obj, 
> conn->vrr_display_min_property, 0);
> +             drm_object_property_set_value(obj, 
> conn->vrr_display_max_property, 0);
> +
> +             return 0;
> +     }

[Severity: Medium]
When an HDMI VRR display is unplugged or replaced with a non-HDMI sink (such
as DVI), drm_edid_connector_update() calls drm_reset_display_info():

drivers/gpu/drm/drm_edid.c:drm_reset_display_info() {
        ...
        info->is_hdmi = false;
        info->has_audio = false;
        info->has_hdmi_infoframe = false;
        info->rgb_quant_range_selectable = false;
        memset(&info->hdmi, 0, sizeof(info->hdmi));
        ...
}

Because drm_connector_hdmi_update_vrr_limits() checks !info->is_hdmi and
returns -EINVAL before checking conn->status != connector_status_connected,
won't calling this helper after an unplug or sink swap fail to reset
vrr_display_min_property and vrr_display_max_property to 0, leaving stale
non-zero limits exposed to userspace?

> +
> +     min_hz = info->hdmi.vrr_cap.vrr_min;
> +
> +     if (info->hdmi.vrr_cap.cnmvrr)
> +             max_hz = info->hdmi.vrr_cap.vrr_max;

[Severity: Medium]
Should max_hz still be clamped to drm_mode_vrefresh(mode) when
info->hdmi.vrr_cap.cnmvrr is set?

In HDMI 2.1, negative M_VRR (cnmvrr) only allows shortening Vfront by at most
ceil(Vfront_base / 4) lines in constant-rate CinemaVRR mode for fractional
pull-up (such as 59.94 Hz to 60 Hz), and cannot increase a lower-rate mode
(such as 60 Hz or 24 Hz) up to vrr_max (such as 120 Hz) at that mode's pixel
clock.

In addition, hdmi_validate_vrr() in
drivers/gpu/drm/display/drm_hdmi_state_helper.c unconditionally caps the
maximum refresh rate to mode_refresh regardless of cnmvrr:

        if (!max_vfreq_n || max_vfreq_n > mode_refresh)
                max_vfreq_n = mode_refresh;
        ...
        vrr_state->base_vtotal = max(vrr_state->base_vtotal, mode->crtc_vtotal);

Leaving max_hz unclamped when cnmvrr is true advertises a vrr_display_max
above mode_refresh that hdmi_validate_vrr() will reject, and also causes
modes with drm_mode_vrefresh(mode) <= min_hz (for example, a 24 Hz mode on a
48-120 Hz display) to bypass the max_hz <= min_hz check below instead of
reporting 0.

> +     else
> +             max_hz = min(drm_mode_vrefresh(mode), 
> info->hdmi.vrr_cap.vrr_max);
> +
> +     /* VRR is impossible in the current mode */
> +     if (max_hz <= min_hz)
> +             min_hz = max_hz = 0;

[Severity: Medium]
What happens here when a VRR-capable HDMI 2.1 sink leaves vrr_max as 0 in its
EDID HF-VSDB to indicate that the upper VRR bound is the video mode's base
refresh rate?

In drivers/gpu/drm/drm_edid.c, drm_parse_hdmi_gaming_info() treats
vrr_max == 0 as valid when VRR is supported:

        vrr->vrr_min = db[9] & DRM_EDID_VRR_MIN_MASK;
        vrr->supported = (vrr->vrr_min > 0 && vrr->vrr_min <= 48);

        if (cea_db_payload_len(db) < 10)
                return;

        vrr->vrr_max = (db[9] & DRM_EDID_VRR_MAX_UPPER_MASK) << 2 | db[10];
        vrr->supported &= (vrr->vrr_max == 0 || vrr->vrr_max >= 100);

And hdmi_validate_vrr() in drivers/gpu/drm/display/drm_hdmi_state_helper.c
handles a 0 maximum by falling back to mode_refresh:

        if (!max_vfreq_n || max_vfreq_n > mode_refresh)
                max_vfreq_n = mode_refresh;

In drm_connector_hdmi_update_vrr_limits(), however, if
info->hdmi.vrr_cap.vrr_max is 0, both branches of the if/else evaluate
max_hz to 0, which then triggers max_hz <= min_hz and sets both
vrr_display_min_property and vrr_display_max_property to 0. Should a vrr_max
of 0 fall back to drm_mode_vrefresh(mode) instead?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=10

Reply via email to