From: sashiko-bot@kernel.org
To: Roy <rongh7426@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/vc4: hdmi: Reject modes that don't fit the BCM2711 timing registers
Date: Thu, 26 Nov 2026 03:14:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-234681@kernel.org> (raw)
In-Reply-To: <20261126025311.640543-1-rongh7426@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/vc4: hdmi: unvalidated DBLCLK fixup in
vc4_hdmi_encoder_atomic_check()
- [Medium] drm/vc4: hdmi: u32 FIELD_FIT() truncation in
vc5_hdmi_timings_valid()
- [Medium] drm/vc4: hdmi: unchecked even-field VBP in
vc5_hdmi_timings_valid()
--
commit cdf386363de742cee9aaccb1142e521a753912f5
Author: Roy <rongh7426@gmail.com>
drm/vc4: hdmi: Reject modes that don't fit the BCM2711 timing registers
This commit adds a timings_valid() variant hook for the BCM2711 and
BCM2712 HDMI controllers to check that mode timings fit in the hardware
timing register fields before modeset.
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> index f3ec65d86078f..4e10cdedb8a8f 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> @@ -1254,6 +1254,44 @@ static void vc5_hdmi_set_timings(struct vc4_hdmi *vc4_hdmi,
> drm_dev_exit(idx);
> }
>
> +/*
> + * Check that every value vc5_hdmi_set_timings() writes fits in its
> + * register field. Such a mode would otherwise be programmed with
> + * truncated timings, and VC4_SET_FIELD() would warn about it on every
> + * modeset.
> + */
> +static enum drm_mode_status
> +vc5_hdmi_timings_valid(const struct drm_display_mode *mode)
> +{
> + bool interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
> + u32 pixel_rep = (mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1;
> + struct drm_display_mode m;
> +
> + drm_mode_init(&m, mode);
> + drm_mode_set_crtcinfo(&m, CRTC_INTERLACE_HALVE_V);
> +
> + if (!FIELD_FIT(VC5_HDMI_HORZA_HAP_MASK, m.hdisplay * pixel_rep) ||
> + !FIELD_FIT(VC5_HDMI_HORZA_HFP_MASK,
> + (m.hsync_start - m.hdisplay) * pixel_rep) ||
> + !FIELD_FIT(VC5_HDMI_HORZB_HBP_MASK,
> + (m.htotal - m.hsync_end) * pixel_rep) ||
> + !FIELD_FIT(VC5_HDMI_HORZB_HSP_MASK,
> + (m.hsync_end - m.hsync_start) * pixel_rep) ||
> + !FIELD_FIT(VC5_HDMI_VERTB_VSPO_MASK, m.htotal >> (2 - pixel_rep)))
> + return MODE_H_ILLEGAL;
> +
> + if (!FIELD_FIT(VC5_HDMI_VERTA_VSP_MASK,
> + m.crtc_vsync_end - m.crtc_vsync_start) ||
> + !FIELD_FIT(VC5_HDMI_VERTA_VFP_MASK,
> + m.crtc_vsync_start - m.crtc_vdisplay) ||
[Severity: Medium]
Can FIELD_FIT() miss overflowing values on these shifted masks because
VC4_MASK() casts GENMASK() to u32?
include/linux/bitfield.h:FIELD_FIT() shifts ((typeof(_mask))_val) left by
__bf_shf(_mask) before testing against ~(_mask). With a 32-bit mask,
that shift discards the upper __bf_shf(_mask) bits of _val. For
VC5_HDMI_VERTA_VSP_MASK (VC4_MASK(28, 24)), shifting left by 24 drops
bits 8..15, so a mode with m.crtc_vsync_end - m.crtc_vsync_start == 256
passes FIELD_FIT() and programs a truncated 0 VSP into HDMI_VERTA0/1.
The masks at shift 16 (VC5_HDMI_HORZA_HFP_MASK, VC5_HDMI_HORZB_HBP_MASK
and VC5_HDMI_VERTA_VFP_MASK) similarly drop bits 16..31.
> + !FIELD_FIT(VC5_HDMI_VERTA_VAL_MASK, m.crtc_vdisplay) ||
> + !FIELD_FIT(VC4_HDMI_VERTB_VBP_MASK,
> + m.crtc_vtotal - m.crtc_vsync_end + interlaced))
> + return MODE_V_ILLEGAL;
[Severity: Medium]
Should this also check m.crtc_vtotal - m.crtc_vsync_end without
+ interlaced for vertb_even?
vc5_hdmi_set_timings() packs mode->crtc_vtotal - mode->crtc_vsync_end
into VC4_HDMI_VERTB_VBP for vertb_even (HDMI_VERTB0). When an interlaced
mode has vscan > 1 (e.g. vdisplay = vsync_start = vsync_end = 512,
vtotal = 1022, vscan = 257), the u16 multiplication in
drm_mode_set_crtcinfo() wraps crtc_vtotal to 255 and crtc_vsync_end to
256. m.crtc_vtotal - m.crtc_vsync_end + interlaced is 0 and passes this
check, after which vc5_hdmi_set_timings() passes -1 to VC4_SET_FIELD()
for vertb_even and triggers a WARN_ON().
> +
> + return MODE_OK;
> +}
> +
> static void vc4_hdmi_recenter_fifo(struct vc4_hdmi *vc4_hdmi)
> {
> struct drm_device *drm = vc4_hdmi->connector.dev;
> @@ -1656,6 +1694,14 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
> {
> struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
>
> + if (vc4_hdmi->variant->timings_valid) {
> + enum drm_mode_status status;
> +
> + status = vc4_hdmi->variant->timings_valid(mode);
> + if (status != MODE_OK)
> + return status;
> + }
> +
[Severity: Medium]
Can the DBLCLK odd-timing fixup in vc4_hdmi_encoder_atomic_check() push
adjusted_mode past the 11-bit VC5_HDMI_HORZB_HBP or VC5_HDMI_HORZB_HSP
limit after vc4_hdmi_encoder_mode_valid() has already approved the mode?
drivers/gpu/drm/vc4/vc4_hdmi.c:vc4_hdmi_encoder_atomic_check() {
...
if (mode->flags & DRM_MODE_FLAG_DBLCLK) {
if ((mode->hsync_start - mode->hdisplay) & 1)
mode->hsync_start--;
if ((mode->hsync_end - mode->hsync_start) & 1)
mode->hsync_end--;
}
...
}
On BCM2711, a DRM_MODE_FLAG_DBLCLK mode with even hdisplay, even
hsync_start, odd hsync_end and htotal - hsync_end == 1023 passes
vc5_hdmi_timings_valid() with (htotal - hsync_end) * 2 == 2046 <= 2047.
vc4_hdmi_encoder_atomic_check() then decrements adjusted_mode.hsync_end
without re-running timings_valid(), so vc5_hdmi_set_timings() sees
(htotal - hsync_end) * 2 == 2048, triggers WARN_ON() in VC4_SET_FIELD(),
and writes a truncated 0 HBP to HDMI_HORZB.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126025311.640543-1-rongh7426@gmail.com?part=1
prev parent reply other threads:[~2026-11-26 3:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 2:53 [PATCH] drm/vc4: hdmi: Reject modes that don't fit the BCM2711 timing registers Roy
2026-11-26 3:14 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-234681@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=rongh7426@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.