Skip to contentSkip to conversation

Make HDMI state helpers handle odd max bpc requests

PATCH In review Nicolas Frattaroli 2 participants 4 messages Jun 19 – Jun 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 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 v3:
- Move bpc check before vic check, and show debug message on failure
- Link to v2: https://patch.msgid.link/[email protected]

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    | 13 +++-
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 71 ++++++++++++++++++++++
 2 files changed, 83 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 v3 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 | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +11 -0
index ce17eeefc2da..6d02cf85f7c9 100644
@@ -405,6 +405,17 @@ sink_supports_format_bpc(const struct drm_connector *connector,
 	struct drm_device *dev = connector->dev;
 	u8 vic = drm_match_cea_mode(mode);
 
+	switch (bpc) {
+	case 8:
+	case 10:
+	case 12:
+	case 16:
+		break;
+	default:
+		drm_dbg_kms(dev, "bpc of %u is not supported by standard\n", bpc);
+		return false;
+	}
+
 	/*
 	 * CTA-861-F, section 5.4 - Color Coding & Quantization states
 	 * that the bpc must be 8, 10, 12 or 16 except for the default
Signature · 1 line
2.54.0
maintainer Reviewed-by on v3 1/2
#2 lore raw

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

Quoted 7 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.

[ ... ]

Thanks!
Maxime

#3 lore raw

PATCH v3 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 6d02cf85f7c9..f3824fa2bf29 100644
@@ -650,7 +650,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