Thank you for your contribution! Sashiko AI review found 2 potential issue(s) 
to consider:
- [High] drm/connector: hdmi: missing sink QMS capability check in VTEM 
generation
- [High] drm/connector: hdmi: vfront read from unpopulated adjusted_mode in VTEM
--

commit cd1865130cc65c0f62c6e87bad2b21911a9e7073
Author: Nicolas Frattaroli <[email protected]>

drm/connector: hdmi: Add QMS to VTEM EMP generation

This commit updates hdmi_generate_emp_infoframe_vtem() to populate QMS VTEM
Extended Metadata Packet fields when conn_state->vrr_display_mode is set to
VRR_DISPLAY_MODE_MEDIA and the connector supports QMS.

> diff --git a/drivers/gpu/drm/display/drm_hdmi_state_helper.c 
> b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> index 1e576dfbd856d..892079e41a0fb 100644
> --- a/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> +++ b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> @@ -890,11 +890,18 @@ static int hdmi_generate_emp_infoframe_vtem(const 
> struct drm_connector *connecto
>               break;
>       case VRR_DISPLAY_MODE_OFF:
>               break;
> +     case VRR_DISPLAY_MODE_MEDIA:
> +             if (!connector->hdmi.qms_supported)
> +                     return -EOPNOTSUPP;
> +             vtem->qms_en = true;
> +             vtem->next_tfr = conn_state->hdmi.qms_tfr_byte;
> +             vtem->m_const = !vrr->dynamic;
> +             break;

[Severity: High]
Does hdmi_generate_emp_infoframe_vtem() in
drivers/gpu/drm/display/drm_hdmi_state_helper.c also need to check the sink's
QMS capability in info->hdmi.vrr_cap.qms_capable?

In drivers/gpu/drm/drm_edid.c:drm_parse_hdmi_gaming_info(), sink QMS support
and Gaming-VRR support are tracked as independent flags:

        vrr->qms_capable = db[8] & DRM_EDID_QMS;

        if (cea_db_payload_len(db) < 9)
                return;

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

Earlier in hdmi_generate_emp_infoframe_vtem(), VTEM generation returns early
when Gaming-VRR is not supported by the sink:

        if (!info->hdmi.vrr_cap.supported)
                return 0;

When drm_atomic_helper_connector_hdmi_check() -> hdmi_generate_infoframes() ->
hdmi_generate_emp_infoframe_vtem() runs with conn_state->vrr_display_mode set
to VRR_DISPLAY_MODE_MEDIA, this leads to two issues:

1. On a sink that supports QMS (info->hdmi.vrr_cap.qms_capable is true) but
not Gaming-VRR (info->hdmi.vrr_cap.supported is false),
hdmi_generate_emp_infoframe_vtem() returns 0 early with infoframe->set = false
and never generates the QMS VTEM packet.

2. On a sink that supports Gaming-VRR (info->hdmi.vrr_cap.supported is true)
but not QMS (info->hdmi.vrr_cap.qms_capable is false), the
VRR_DISPLAY_MODE_MEDIA case only checks source-side
connector->hdmi.qms_supported. Because vrr_display_mode can be set when
crtc_state->vrr_enabled is false (where hdmi_validate_vrr() returns 0 early),
selecting VRR_DISPLAY_MODE_MEDIA sets vtem->qms_en = true and transmits QMS
VTEM packets to a sink that does not support QMS.

Should the early check allow either info->hdmi.vrr_cap.supported or
info->hdmi.vrr_cap.qms_capable, and the VRR_DISPLAY_MODE_GAME and
VRR_DISPLAY_MODE_MEDIA cases verify their respective sink capability flags?

>       default:
>               return -EINVAL;
>       }
>  
> -     if (vtem->game_vrr_en && !avi_vic) {
> +     if ((vtem->game_vrr_en || vtem->qms_en) && !avi_vic) {
>               vtem->base_refresh_rate = drm_mode_vrefresh(&crtc_state->mode);
>               vfront = crtc_state->adjusted_mode.crtc_vsync_start -
>                        crtc_state->adjusted_mode.crtc_vdisplay;

[Severity: High]
When (vtem->game_vrr_en || vtem->qms_en) && !avi_vic is true in
drivers/gpu/drm/display/drm_hdmi_state_helper.c:hdmi_generate_emp_infoframe_vtem(),
is crtc_state->adjusted_mode guaranteed to be populated yet?

In drivers/gpu/drm/drm_atomic_helper.c:drm_atomic_helper_check_modeset(), the
connector atomic_check callback
(drm_atomic_helper_connector_hdmi_check() -> hdmi_generate_infoframes() ->
hdmi_generate_emp_infoframe_vtem()) runs before mode_fixup() copies
new_crtc_state->mode into new_crtc_state->adjusted_mode:

        for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
                if (!new_crtc_state->mode_changed &&
                    !new_crtc_state->connectors_changed)
                        continue;

                drm_mode_copy(&new_crtc_state->adjusted_mode, 
&new_crtc_state->mode);
        }

As a result, during an initial modeset on a non-CEA mode (!avi_vic),
crtc_state->adjusted_mode is still zeroed and vfront evaluates to 0, while on
a mode change crtc_state->adjusted_mode still contains the previous mode's
timings.

Note that hdmi_validate_vrr() in the same file computes vfront from
crtc_state->mode:

        vfront = mode->crtc_vsync_start - mode->crtc_vdisplay;
        if (vfront < 0 || vfront > U8_MAX) {
                drm_dbg_kms(dev, "Vfront of %d would not fit in VTEM packet\n", 
vfront);
                return -EINVAL;
        }

Should hdmi_generate_emp_infoframe_vtem() also read crtc_vsync_start and
crtc_vdisplay from crtc_state->mode (matching base_refresh_rate just above
it and hdmi_validate_vrr())?

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

Reply via email to