From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30228606A338 for ; Fri, 4 Dec 2026 09:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B54qmV6D Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC08B10E6CD; Fri, 4 Dec 2026 09:52:22 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5BEE4112E07; Fri, 4 Dec 2026 09:52:16 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 14F56432C1; Fri, 4 Dec 2026 09:52:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5B281F000C2; Fri, 4 Dec 2026 09:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796377936; bh=J8CiacOTCa5bxYB37QgSUDsb4I3TdXyU0zrL4c7Gho8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=B54qmV6DQ9bK46VhxZf9/Y3gcoCesaj6uI0JsW9rO8jvg3vGRHbfO6/ujD58R/TWc VlSpnLARwQfiEJHfOn0XhTmoK8EUAGZJptjD5ZanwILvoD4CroOdAfNBS/MvbGP/IU M9I4yGwkfpGWdDnhpAV2BvZSdsBJLfkC1ngOXWwBLq2pqorHGBjGX8bDnpTbmmG0EX WXTZvJvd+7c7kQup6+t/hsaFBdMQixt0FRvWZi0YF2Y5WAwinzD5y4Og8fw/W57eAv 7Ta2d6QZ48CqG1/DeiblEvtAg60zCESzJDXFtoimkkvoy4L9iOtAi1j4FYXp4foeVh PFjwRM77Xz9vQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 11/15] drm/i915/dp: Retrain the PCON FRL link from the link check work To: "Ankit Nautiyal" , intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261204085746.391918-12-ankit.k.nautiyal@intel.com> References: <20261204085746.391918-1-ankit.k.nautiyal@intel.com> <20261204085746.391918-12-ankit.k.nautiyal@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:52:15 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] drm/i915/dp: TOCTOU race before hw_done in intel_dp_pcon_frl_recover() - [Medium] drm/i915/dp: missing connected check and lock in intel_dp_pcon_frl_recover() - [Medium] drm/i915/dp: intel_dp_pcon_frl_recover() accesses AUX on suspended display - [Medium] drm/i915/dp: race between intel_dp_pcon_frl_recover() and HPD pulse work - [Low] drm/i915/dp: redundant -EALREADY check in intel_dp_pcon_frl_recover() - [Low] drm/i915/dp: missing Fixes trailer for commit 9488a030ac91 -- commit 1499fb0865199b2ac41ce39175d24f1ae4317106 Author: Ankit Nautiyal > drm/i915/dp: Retrain the PCON FRL link from the link check work > > When the HDMI link of a PCON goes down while the stream is active, the > HDMI link status change handler restarts the FRL training, or falls back > to TMDS mode, directly from the short pulse handling. That runs without > any modeset lock, so it can race with a modeset that trains the link as > well, and it has no access to the state of the active stream. > > Queue the link check work instead, as it is done for the DP link > retraining, and restart the FRL training there, with the modeset locks > held and only if a stream is active. The work restarts the training only > if the FRL link is not trained and the HDMI link is not active, so it > does nothing after a fallback to TMDS mode. > > This allows to use the state of the active stream for the training in > the following changes. > > Signed-off-by: Ankit Nautiyal [Severity: Low] This fixes a concurrency bug in intel_dp_handle_hdmi_link_status_change(). Should this include: Fixes: 9488a030ac91 ("drm/i915: Add support for enabling link status and = recovery") > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i9= 15/display/intel_dp.c > index 272837cc6efa4..2e92e4898ee6b 100644 > --- a/drivers/gpu/drm/i915/display/intel_dp.c > +++ b/drivers/gpu/drm/i915/display/intel_dp.c > @@ -4637,6 +4637,42 @@ void intel_dp_check_frl_training(struct intel_dp *= intel_dp) > } > } > =20 > +/* > + * Restart FRL training after the HDMI link went down while the stream is > + * active, or fall back to TMDS mode. > + */ > +int intel_dp_pcon_frl_recover(struct intel_encoder *encoder, > + struct drm_modeset_acquire_ctx *ctx) > +{ > + struct intel_display *display =3D to_intel_display(encoder); > + struct intel_dp *intel_dp =3D enc_to_intel_dp(encoder); > + u8 pipe_mask; > + int ret; > + > + if (!(intel_dp->downstream_ports[2] & DP_PCON_SOURCE_CTL_MODE) || > + !intel_dp_is_hdmi_2_1_sink(intel_dp) || > + intel_dp->frl.is_trained || > + drm_dp_pcon_hdmi_link_active(&intel_dp->aux)) > + return 0; [Severity: Medium] Can intel_dp_pcon_frl_recover() race with intel_dp_detect() and attempt FRL recovery on a disconnected port? When the connector is disconnected, intel_dp_retrain_link() returns 0 early without taking mode_config.connection_mutex, so intel_dp_link_check() still calls intel_dp_pcon_frl_recover(). This early check then reads downstream_ports, dpcd, and connector->base.display_info without holding connection_mutex, racing with intel_dp_detect(). On disconnect while the CRTC is still active, a long HPD clears frl.is_trained while intel_dp_unset_edid() leaves downstream_ports, dpcd, and display_info populated. A pending link_check_work then passes the early check, takes connection_mutex and crtc->base.mutex, and either writes TMDS fallback DPCD registers to the disconnected port or polls in intel_dp_pcon_start_frl_training() for up to 1.5 seconds while holding those locks. Checking intel_dp_is_connected() and locking connection_mutex before reading the DPCD state would avoid this. [Severity: Medium] Can drm_dp_pcon_hdmi_link_active() issue DP AUX transfers against suspended display hardware on non-TypeC DDI ports? intel_ddi_init() only sets encoder->suspend_complete (which calls intel_encoder_link_check_flush_work()) for TypeC encoders, and __intel_display_driver_pm_suspend() does not flush display->wq.unordered. Moving FRL recovery from dig_port_work onto encoder->link_check_work allows a pending work item to run after display access, IRQs, and power domains are suspended. Because drm_dp_pcon_hdmi_link_active() runs before acquiring connection_mutex and checking pipe_mask =3D=3D 0, it performs AUX MMIO and runtime PM calls against suspended hardware whenever frl.is_trained is false. Flushing link_check_work for all DDI encoders on suspend and moving the AUX read after the active-pipe check would prevent this. > + > + /* The connection mutex may be held already by the link retraining */ > + ret =3D drm_modeset_lock(&display->drm->mode_config.connection_mutex, c= tx); > + if (ret && ret !=3D -EALREADY) > + return ret; [Severity: Low] Is the ret !=3D -EALREADY check needed here? With a non-NULL ctx, drm_modeset_lock() already converts -EALREADY to 0 internally in modeset_lock(), so this branch is dead code and "if (ret) return ret;" matches intel_dp_retrain_link() and intel_dp_get_active_pipes(). > + > + ret =3D intel_dp_get_active_pipes(intel_dp, ctx, &pipe_mask); > + if (ret) > + return ret; > + > + /* Without an active stream the next enable trains the link */ > + if (pipe_mask =3D=3D 0) > + return 0; > + > + intel_dp_check_frl_training(intel_dp); [Severity: Medium] Can intel_dp_pcon_frl_recover() tear down a working TMDS fallback link because drm_dp_pcon_hdmi_link_active() is checked before wait_for_connector_hw_done()? A non-blocking atomic modeset drops the modeset locks and runs intel_atomic_commit_tail() on display->wq.modeset. If link_check_work runs concurrently, intel_dp_pcon_frl_recover() reads frl.is_trained and DP_PCON_HDMI_TX_LINK_STATUS before intel_dp_get_active_pipes() waits on hw_done, and never re-checks them afterward (unlike intel_dp_retrain_link(), which re-checks intel_dp_needs_link_retrain()): CPU0 (wq.modeset) CPU1 (wq.unordered) intel_atomic_commit_tail() intel_dp_pcon_frl_recover() frl.is_trained =3D=3D false drm_dp_pcon_hdmi_link_active() -> false intel_dp_check_frl_training() intel_dp_pcon_set_tmds_mode() signal hw_done intel_dp_get_active_pipes() wait_for_connector_hw_done() intel_dp_check_frl_training() drm_dp_pcon_frl_prepare() <-- tears down active TMDS link When the modeset falls back to TMDS mode, frl.is_trained remains false while the HDMI link is active in TMDS mode. intel_dp_check_frl_training() then sees !frl.is_trained and calls drm_dp_pcon_frl_prepare(), disrupting the active display and repeating up to 1.5 seconds of FRL polling under connection_mutex and crtc->base.mutex; the pre-wait AUX read can also race with the in-flight modeset's training. Re-checking frl.is_trained and drm_dp_pcon_hdmi_link_active() after intel_dp_get_active_pipes() would close this window. [Severity: Medium] Can intel_dp_pcon_frl_recover() race with HPD pulse handling on frl.is_trained and DP_PCON_HDMI_LINK_CONFIG_1? Previously, FRL recovery ran in dig_port_work, which serialized it against intel_dp_hpd_pulse() and intel_dp_handle_hdmi_link_status_change(). In encoder->link_check_work, intel_dp_pcon_frl_recover() runs on display->wq.unordered without calling intel_hpd_block(encoder) or sharing a lock with dig_port_work: CPU0 (wq.unordered) CPU1 (hotplug.dp_wq) intel_dp_pcon_frl_recover() ... intel_dp_pcon_start_frl_training() intel_dp_pcon_is_frl_trained() -> true intel_dp_hpd_pulse() (long HPD) frl.is_trained =3D false frl.is_trained =3D true <-- overwrites long-HPD reset Losing the long-HPD reset leaves frl.is_trained set, so the next enable skips FRL training even though the HDMI link is down. A concurrent short HPD in intel_dp_handle_hdmi_link_status_change() can also read is_active as false before training finishes, then see frl.is_trained =3D=3D true and cle= ar DP_PCON_ENABLE_HDMI_LINK via an unlocked read-modify-write, tearing down the freshly trained link. Blocking HPD with intel_hpd_block(encoder) around FRL recovery would serialize it with dig_port_work. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204085746.3919= 18-1-ankit.k.nautiyal@intel.com?part=3D11