From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=213.97.179.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796152313; b=ojoS7czpRYPIjqz4hUEPTjHSNYrbG9l0iiQ/1a4RsG0iwnRzKXONPVqcyWZufc0PHfo3 IewIciA8OgzQ4NyFy+CfqbtgsYECeeOhCb1ngIWvW7DbQRk60rOLlJn8EUArskK6psxV7 I3pdZl1CQjuHpIyED1ZtyQ2fNW6ccNfcLZiY2uo3qvPgp2+qpCxE8HGM7Ubx0TUTWHMTY FWVeHsOJp3AX/9DPlD5+9jWWVaxDi/Trdgm9EeSBB9+J0icHwjWnQugcssfskavBV7vFg NNiquIGiDnBEpN4i/zZFBKMIhckmD6QUdKk/KfVp+CKGo4kygiDkOD0uqrS8xF/dJLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796152313; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:From:Content-Language:Autocrypt: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=qv6L5ov/6h5BRqq6Laps3ITc/INiowwP1md3alQCY9g=; b=gwlGU31RCRbv1Ppj12bsMDHeIJnpBZW2bTUdAXs/BPumxnKVODpJbi2RvLqSHxcCZlrz FQRwLHJ7oClSSISADFW1rMahz9JEvOAbgnv394w4xqiYgJA/Z+b1af49veCuJq7lkqESu eOb9pld6mi2gjI7LvMed9ueYAFoT1500/2QE4mDkgJETupNJw9olJMa8RRMBr5KAcCzUg RUh4NLdPlomtWI87Tl42RvVVra0jiJQlDL1sSw45kqPhrqDhAWwj6ysUf8lg1UYvIH6Ty YGmVE/PEBQoexdFSjwOhOlqnqrfOa3JXklBNUJEbkVNpoTSe4wcB90I5Kqd0BaPdAAQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=dJQmDmn2; arc=none smtp.remote-ip=213.97.179.56 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18D7E606A31A for ; Tue, 1 Dec 2026 19:11:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 18D7E606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=dJQmDmn2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:From:Cc:To:Subject: MIME-Version:Date:Message-ID:From:Reply-To; bh=qv6L5ov/6h5BRqq6Laps3ITc/INiowwP1md3alQCY9g=; t=1796152311; x=2111512311; b=dJQmDmn2Y+llnQVz6pkHx8z8p7S7FxW3n4NiZWS/vb7Nd2d9/Pg7S+dcywDGIQM1UIvIlALyChp 0W8vnohxpZP0EK0JFhdZ9MUl/Fu0yIu4MEPq8v2TFDOtUiW/+r9yX7nILpA09bloowjilQNTb/y1p +/1Pvh4EOg2u7ygPCnKDLXV+OyTJyyc9g630hqpD5vUynEDVJyCJ2EvsaLXTNN+/jkrvlmNwEfD2V 3rX/cTYEQtmVOthDmI8xmfNDKSziOgb5cZf40aluLnqKMmXT9xdvHcnqc1DMyqkkF4t5UrQuE8Xed yZEwisn0KGWZcWXRdMJpQY7Syw6w5PaDFrSg==; Received: from [179.105.94.163] (helo=[192.168.0.6]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) (envelope-from ) id 1xYTGT-00000000o53-1pPn; Tue, 01 Dec 2026 20:11:45 +0100 Message-ID: <7c3bfac8-2ebd-4189-a44b-2c092d870a03@igalia.com> Date: Tue, 1 Dec 2026 16:11:40 -0300 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] drm/vc4: hdmi: Reject modes that don't fit the BCM2711 timing registers To: Lin Tzu Yang , Maxime Ripard , Dave Stevenson Cc: Raspberry Pi Kernel Maintenance , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20261130061704.830142-1-rongh7426@gmail.com> From: =?UTF-8?Q?Ma=C3=ADra_Canal?= Content-Language: en-US Autocrypt: addr=mcanal@igalia.com; keydata= xsBNBGcCwywBCADgTji02Sv9zjHo26LXKdCaumcSWglfnJ93rwOCNkHfPIBll85LL9G0J7H8 /PmEL9y0LPo9/B3fhIpbD8VhSy9Sqz8qVl1oeqSe/rh3M+GceZbFUPpMSk5pNY9wr5raZ63d gJc1cs8XBhuj1EzeE8qbP6JAmsL+NMEmtkkNPfjhX14yqzHDVSqmAFEsh4Vmw6oaTMXvwQ40 SkFjtl3sr20y07cJMDe++tFet2fsfKqQNxwiGBZJsjEMO2T+mW7DuV2pKHr9aifWjABY5EPw G7qbrh+hXgfT+njAVg5+BcLz7w9Ju/7iwDMiIY1hx64Ogrpwykj9bXav35GKobicCAwHABEB AAHNIE1hw61yYSBDYW5hbCA8bWNhbmFsQGlnYWxpYS5jb20+wsCRBBMBCAA7FiEE+ORdfQEW dwcppnfRP/MOinaI+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jWghEjC+Jh9xUvJco2tUTepw4OwuPxOvtuPTUa1kgixYyG1Jck/67reJzMigeuYFt raV3P8t/6cmtawVjurhnCDuURyhUrjpRhgFp+lW8OGr6pepHol/WFIOQEg== In-Reply-To: <20261130061704.830142-1-rongh7426@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, On 30/11/26 03:17, Lin Tzu Yang wrote: > vc5_hdmi_set_timings() packs the mode timings into register fields that > are much narrower than the values a mode can carry (for example 11 bits > for the horizontal back porch and 9 bits for the vertical back porch), > but nothing checks that a mode fits before it gets there. Such a mode > passes the atomic check, VC4_SET_FIELD() warns once for every field > that overflows, and the truncated timings are written to the hardware. > > The igt test kms_invalid_mode, subtest overflow-vrefresh, hits this on a > Raspberry Pi 5: it sets a mode with htotal = vtotal = 32768, the commit > succeeds and four warnings are printed: > > WARNING: CPU: 0 PID: 64500 at vc4_hdmi.c:1282 vc5_hdmi_set_timings+0x970/0xed8 [vc4] > WARNING: CPU: 0 PID: 64500 at vc4_hdmi.c:1284 vc5_hdmi_set_timings+0x980/0xed8 [vc4] > WARNING: CPU: 0 PID: 64500 at vc4_hdmi.c:1288 vc5_hdmi_set_timings+0x994/0xed8 [vc4] > WARNING: CPU: 0 PID: 64500 at vc4_hdmi.c:1311 vc5_hdmi_set_timings+0xbb4/0xed8 [vc4] > > Add a timings_valid() variant hook, implemented for the BCM2711 and > BCM2712 controllers, that computes the same values as > vc5_hdmi_set_timings() and checks each one against its field, and call > it from the encoder's mode_valid(). Modes that don't fit are now > rejected at atomic check time, and dropped from the probed mode list. > The atomic check calls it again after its DBLCLK fixup, since that can > lengthen the horizontal back porch. > > The check compares against FIELD_MAX() rather than using FIELD_FIT(): > VC4_MASK() makes the masks u32, and FIELD_FIT() then shifts the value > as a u32 and drops its upper bits, so for example a 256-line vertical > sync would pass for the 5-bit VSP field. These are implementation details that don't belong to a commit message. > > The BCM2835 controller (vc4_hdmi_set_timings()) has the same kind of > narrow fields but is left alone here, as I have no hardware to test it. Same. Please, as a general note, make your commit messages more human- readable. > > Tested on a Raspberry Pi 5 (Raspberry Pi OS kernel 6.18.39, with this > change applied to its vc4 driver): > - kms_invalid_mode: 12 pass / 1 fail, 4 warnings -> 13 pass / 0 fail, > no warnings > - all 12 modes from the monitor's EDID (including 1920x1080i and > 720x480) are still listed, and none is reported as rejected > > The failure was found with igt-gpu-tools. The fix and this changelog > were written with the help of an AI coding assistant (Claude); the > testing above was done on real hardware. > > Fixes: 8323989140f3 ("drm/vc4: hdmi: Support the BCM2711 HDMI controllers") > Signed-off-by: Lin Tzu Yang > --- > Changes in v2: > - Compare against FIELD_MAX() instead of FIELD_FIT(), which misses > overflows with the u32 VC4_MASK() masks. > - Also check the even field's vertical back porch. > - Check the adjusted mode again in atomic_check() after the DBLCLK > fixup. > - Use my full name. > All three were pointed out by the Sashiko review bot. v2 is build > tested (W=1). I checked the new logic against v1 in a userspace copy > of the function: the same 8 common modes (1080p/i, 480i/576i DBLCLK, > 720p, 4K30, ...) are accepted, and the three cases Sashiko described > are now rejected. The hardware test above was done on v1. > > v1: https://lore.kernel.org/all/20261126025311.640543-1-rongh7426@gmail.com/ > > drivers/gpu/drm/vc4/vc4_hdmi.c | 76 ++++++++++++++++++++++++++++++++++ > drivers/gpu/drm/vc4/vc4_hdmi.h | 6 +++ > 2 files changed, 82 insertions(+) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index f3ec65d..9e4d6c5 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -1254,6 +1254,61 @@ static void vc5_hdmi_set_timings(struct vc4_hdmi *vc4_hdmi, > drm_dev_exit(idx); > } > > +/* > + * FIELD_FIT() can't be used here: VC4_MASK() makes the masks u32, so > + * FIELD_FIT() shifts the value as a u32 and loses its upper bits (a > + * vertical sync of 256 lines would pass for the 5-bit VSP field). > + * Compare against the field's maximum instead. Taking the value as s64 > + * also rejects differences that went negative. > + */ Please, delete this comment. > +static bool vc5_hdmi_fits(u32 max, s64 val) > +{ > + return val >= 0 && val <= max; > +} > + > +#define VC5_HDMI_FITS(field, val) vc5_hdmi_fits(FIELD_MAX(field##_MASK), val) Maybe just implement the function vc5_hdmi_fits() in the macro itself. > + > +/* > + * 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. > + */ The comment in struct vc4_hdmi_variant already explains the reasoning behind this function. No need for an extra comment. > +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 (!VC5_HDMI_FITS(VC5_HDMI_HORZA_HAP, m.hdisplay * pixel_rep) || > + !VC5_HDMI_FITS(VC5_HDMI_HORZA_HFP, > + (m.hsync_start - m.hdisplay) * pixel_rep) || > + !VC5_HDMI_FITS(VC5_HDMI_HORZB_HBP, > + (m.htotal - m.hsync_end) * pixel_rep) || > + !VC5_HDMI_FITS(VC5_HDMI_HORZB_HSP, > + (m.hsync_end - m.hsync_start) * pixel_rep) || > + !VC5_HDMI_FITS(VC5_HDMI_VERTB_VSPO, m.htotal >> (2 - pixel_rep))) > + return MODE_H_ILLEGAL; > + > + /* The even field's back porch is one line shorter than the odd one's. */ > + if (!VC5_HDMI_FITS(VC5_HDMI_VERTA_VSP, > + m.crtc_vsync_end - m.crtc_vsync_start) || > + !VC5_HDMI_FITS(VC5_HDMI_VERTA_VFP, > + m.crtc_vsync_start - m.crtc_vdisplay) || > + !VC5_HDMI_FITS(VC5_HDMI_VERTA_VAL, m.crtc_vdisplay) || > + !VC5_HDMI_FITS(VC4_HDMI_VERTB_VBP, > + m.crtc_vtotal - m.crtc_vsync_end) || > + !VC5_HDMI_FITS(VC4_HDMI_VERTB_VBP, > + m.crtc_vtotal - m.crtc_vsync_end + interlaced)) > + return MODE_V_ILLEGAL; > + > + return MODE_OK; > +} > + > static void vc4_hdmi_recenter_fifo(struct vc4_hdmi *vc4_hdmi) > { > struct drm_device *drm = vc4_hdmi->connector.dev; > @@ -1633,6 +1688,15 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder, > return -EINVAL; > } > > + /* > + * mode_valid() checked the mode before the fixup above, which can > + * lengthen the horizontal back porch, so check what will actually > + * be programmed. > + */ > + if (vc4_hdmi->variant->timings_valid && > + vc4_hdmi->variant->timings_valid(mode) != MODE_OK) > + return -EINVAL; > + I believe this really doesn't fit here, as the validation should happen in mode_valid. Considering that the DBLCLK fixup depends only on the mode, mode_valid() can apply it too. You could move the fixup into a helper. Then, in mode_valid(), when unsupported_odd_h_timings is set, apply it to a copy of the mode, then run the odd-timing check and timings_valid() on the copy, DBLCLK modes included. In atomic_check(), apply the helper to adjusted_mode and drop both checks. This would leave all validation in mode_valid(). Best regards, - MaĆ­ra