Skip to contentSkip to conversation

Make HDMI state helpers handle odd max bpc requests

PATCH Superseded Nicolas Frattaroli 2 participants 4 messages Jun 18 – Jun 19

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Make HDMI state helpers handle odd max bpc requests

With the "max bpc" KMS connector property, userspace can arbitrarily restrict the upper end of the bits-per-component range. This is fine and good, except the HDMI state helpers never considered that max_bpc could be influenced by a userspace setting, so assumed it'll always be an even value from the HDMI standards.

This, unfortunately, is not the world we live in anymore. Patch 1 corrects sink_supports_format_bpc to return false on BPCs outside of what HDMI allows. Patch 2 then corrects handling of odd-numbered max bpcs by rounding the loop start value down to an even number instead. It also adds a KUnit test to make sure nobody breaks this again in the future.

---
Changes in v2:
- Use rounddown() from linux/math.h instead of the bespoke rounding. No functional changes.
- Note: switch statement in patch 1 kept as-is, as 14bpc is not allowed
by HDMI it seems.
- Link to v1: https://patch.msgid.link/[email protected]

---
Nicolas Frattaroli (2):
drm/display: hdmi: Only allow BPC values of 8, 10, 12 and 16 drm/display: hdmi: Round odd max_bpc down to even numbers

 drivers/gpu/drm/display/drm_hdmi_state_helper.c    | 12 +++-
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 71 ++++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)

---
base-commit: 24209d838338d162bb25aadfd637b11747a357ca
change-id: 20260608-hdmi-max-bpc-fix-703019763834

Best regards,

Signature · 1 line
Nicolas Frattaroli <[email protected]>
#1 lore raw

PATCH v2 1/2 drm/display: hdmi: Only allow BPC values of 8, 10, 12 and 16

As per the comment in sink_supports_format_bpc(), CTA-861-F defines that only bits-per-channel values of 8, 10, 12 and 16 are allowed for HDMI. Allowing more than this has surprising consequences for the atomic check phase. The HDMI state helpers may accidentally conclude that a sink supports 11bpc if a caller asks for it.

Fix this by exiting early if the bpc value doesn't match one of those given in the standard.

Fixes 26ff1c38fc29 ("drm/connector: hdmi: Compute bpc and format automatically")
---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +10 -0
index ce17eeefc2da..0bf6102244f7 100644
@@ -420,6 +420,16 @@ sink_supports_format_bpc(const struct drm_connector *connector,
 		return false;
 	}
 
+	switch (bpc) {
+	case 8:
+	case 10:
+	case 12:
+	case 16:
+		break;
+	default:
+		return false;
+	}
+
 	if (!info->is_hdmi &&
 	    (format != DRM_OUTPUT_COLOR_FORMAT_RGB444 || bpc != 8)) {
 		drm_dbg_kms(dev, "DVI Monitors require an RGB output at 8 bpc\n");
Signature · 1 line
2.54.0
maintainer
#2 lore raw

Re: [PATCH v2 1/2] drm/display: hdmi: Only allow BPC values of 8, 10, 12 and 16

Hi Nicolas,

Quoted 23 lines · Nicolas Frattaroli

As per the comment in sink_supports_format_bpc(), CTA-861-F defines that only bits-per-channel values of 8, 10, 12 and 16 are allowed for HDMI. Allowing more than this has surprising consequences for the atomic check phase. The HDMI state helpers may accidentally conclude that a sink supports 11bpc if a caller asks for it.

Fix this by exiting early if the bpc value doesn't match one of those given in the standard.

Fixes 26ff1c38fc29 ("drm/connector: hdmi: Compute bpc and format automatically")
---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
index ce17eeefc2da..0bf6102244f7 100644
@@ -420,6 +420,16 @@ sink_supports_format_bpc(const struct drm_connector *connector,
 		return false;
 	}
 

drivers/gpu/drm/display/drm_hdmi_state_helper.c sink_supports_format_bpc(const struct drm_connector *connector, · line 432

Quoted 10 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +10 -0
+	switch (bpc) {
+	case 8:
+	case 10:
+	case 12:
+	case 16:
+		break;
+	default:
+		return false;
+	}
+

Sorry for not noticing in your first version, but I'd move this before the VIC 1 check, and would add a comment to refer to the spec (possibly by splitting the comment already there for the VIC 1 check).

We should also log debug message on failure like we do for every other rejection path.

Maxime

#3 lore raw

PATCH v2 2/2 drm/display: hdmi: Round odd max_bpc down to even numbers

In reply to Nicolas Frattaroli

The HDMI state helpers will count down from the max bpc to 8 in steps of 2, trying each value as a possible output bpc. This goes awry if max bpc is restricted by userspace to an odd number with the "max bpc" connector property.

Prevent this, without introducing any additional bpc format trial steps, by simply rounding down to the next multiple of 2 as the starting point for the for loop.

Additionally, add a KUnit test to validate the handling of this.

Fixes 26ff1c38fc29 ("drm/connector: hdmi: Compute bpc and format automatically")
---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c    |  2 +-
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 71 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -1
index 0bf6102244f7..e9553fab99b5 100644
@@ -649,7 +649,7 @@ hdmi_compute_format_bpc(const struct drm_connector *connector,
 	unsigned int bpc;
 	int ret;
 
-	for (bpc = max_bpc; bpc >= 8; bpc -= 2) {
+	for (bpc = rounddown(max_bpc, 2); bpc >= 8; bpc -= 2) {
 		ret = hdmi_try_format_bpc(connector, conn_state, mode, bpc, fmt);
 		if (!ret)
 			continue;
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +71 -0

83 lines not on this page · raw message

Signature · 1 line
2.54.0