From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796091470; b=ctfJyVR1DVyu+JBPuCHOnvtdesbS4JUXXGYphL46ewgm+Np1uQ4gbB5610StzjCsyly0 uEa91VTSEZFTv5JE2bQLRRKCs8x/PaYv0Y2OJYMnp+ZIQx/xPMRF85HUIJAdBlPebxj4M YrwqgKGYJxw7WpV0gI/sgpBEe0d9z8s29mOfj9r2iN7lHdRVWGjH6fCGLm1kKdrj+vu0I gCbjiQcD5rzgCQ8v9j8YE6s0FT9Qj2xTRfBEJ/pt25lYvI6H39UCbQA5SuPYsA3/ABASE zYcq5vIxMOGvNJJ4ErqNhrPHdXDUstkwwg1v40RSDR2Z5wH9ejzQD29jccKdBfeJ8Wg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796091470; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=b49R8CH7lLBV7R9MMfKnLMsuBHIvD5qMY6JYhHBrQeA=; b=sxsdy9SOALWyjf+Y90Ult8epTwmhiEHifRX8WtHC6MO4AUSTld/rBJm3Rn+wbTiy4lBy 4y7ed6NtK0B+Imp6siBEmE72PObee+B0/aFvUFMDOcP2AXv9vwUQLC8JJkVelqeGl7Axo XetZYgzyVVFhSOXL2jBAzM1sTmXcSlhZSS+btVDI6N25M+IYCuqMpEwTkCmNSXLdMtEkO uPij1ZosV0BJCp0UqE5dmideLghlQ3wWCnYnAahmhoMDF6Stupsi3WsYYbbTf3OrzwYta RhKs/6Q61jN0CcIpWudV4pNs5U3GS92709VPNSAPYh1r3R+naxTC+uT3RONfCo/H7MQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=eJCqnRrZ; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 4B8B8606A31A; Tue, 1 Dec 2026 02:17:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4B8B8606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=eJCqnRrZ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796091461; bh=y1T26ym0V3Mtpr9VqMD5sKjR+c5ZObcZEZxDIDDNMME=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=eJCqnRrZ+RXD7gI8mmMahFQ3/Yb2wrmc8nbP+jzpLOVi5AhuONrJpB30YgTwnQw/h con0iCwOK+Zkcges5+8QjDK8tby5Pzyj96XFwDx/thUjuwWB40ZXkSFjbandVWeasY T7PcWb3i5gsDh5cv+veVkAUZ/OaY5n+7OD/G42TD98xafAZfJOcg/qa5GzUj1YUuI4 seQt3gzf4aXE+UyDnEoJ5KsnhWRBoB728SvJKXzGjl0AcNjJMPF9xtQ6EeMr/z9oHz xV30vNsQ7tiVvFyIXcKE6UclIcqfswQMvXYho4gcoz/LCkrFk/+40ghMh+wUa6GDXZ cqL3gDxAM3lMQ== Received: from [100.64.0.241] (unknown [100.64.0.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id 265DC17E03D4; Tue, 01 Dec 2026 03:17:41 +0100 (CET) Message-ID: <93924e13-117a-4ba9-b243-42ae79e86c1d@collabora.com> Date: Tue, 1 Dec 2026 04:17:40 +0200 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 v7] drm/bridge: dw-hdmi-qp: serialize HDMI audio callbacks with PHY enable/disable To: Frank Zhang , hjc@rock-chips.com, heiko@sntech.de, andyshrk@163.com, andrzej.hajda@intel.com, neil.armstrong@linaro.org, rfoss@kernel.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, luca.ceresoli@bootlin.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, royalnet026@gmail.com, me@timsurber.de Cc: dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261112101155.47777-1-rmxpzlb@gmail.com> Content-Language: en-US From: Cristian Ciocaltea In-Reply-To: <20261112101155.47777-1-rmxpzlb@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Frank, On 11/12/26 12:11 PM, Frank Zhang wrote: > The following panic was observed during system reboot, it can also be > triggered by the following sequences: > > - Disable the HDMI drm display, open and close the HDMI PCM device. > - Enable the HDMI drm display and start audio stream on the HDMI PCM > device, then switch the HDMI drm display to disable, stop and close > audio stream. [...] > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c > @@ -76,6 +76,8 @@ struct dw_hdmi_qp { > struct { > const struct dw_hdmi_qp_phy_ops *ops; > void *data; > + struct mutex lock; > + bool enabled; > } phy; I agree the audio callbacks need to be serialized against the atomic enable/disable paths, but I don't think we need a new mutex, nor a new flag. struct dw_hdmi_qp already provides hdmi->mutex (currently guards curr_conn), and could be extended to also guard tmds_char_rate. The thing is that tmds_char_rate should act as an indicator for the PHY being up in HDMI mode, which is the only case where audio matters (in DVI mode the DRM audio helpers bail out early anyway). Hence, I'd suggest something like this (untested): - in dw_hdmi_qp_bridge_atomic_enable() hdmi->phy.ops->init(hdmi, hdmi->phy.data); [...] drm_connector_get(connector); scoped_guard(mutex, &hdmi->mutex) { hdmi->curr_conn = connector; hdmi->tmds_char_rate = op_mode ? 0 : conn_state->hdmi.tmds_char_rate; } [...] drm_atomic_helper_connector_hdmi_update_infoframes(connector, state); - in dw_hdmi_qp_bridge_atomic_disable() scoped_guard(mutex, &hdmi->mutex) { if (hdmi->curr_conn) { drm_connector_put(hdmi->curr_conn); hdmi->curr_conn = NULL; } hdmi->tmds_char_rate = 0; } [...] hdmi->phy.ops->disable(hdmi, hdmi->phy.data); - in audio/infoframe callbacks simply check tmds_char_rate with hdmi->mutex held around the register accesses. > unsigned long ref_clk_rate; > @@ -262,6 +264,10 @@ static int dw_hdmi_qp_audio_enable(struct drm_bridge *bridge, > { > struct dw_hdmi_qp *hdmi = dw_hdmi_qp_from_bridge(bridge); > > + guard(mutex)(&hdmi->phy.lock); > + if (!hdmi->phy.enabled) > + return -EOPNOTSUPP; This is a functional change, as opening the PCM device now fails while the display is disabled. Commit 247695b19afc ("drm/bridge: dw-hdmi-qp: Return -EOPNOTSUPP in HDMI audio functions") should already handle this, so please rebase. > + > if (hdmi->tmds_char_rate) > dw_hdmi_qp_mod(hdmi, 0, AVP_DATAPATH_PACKET_AUDIO_SWDISABLE, GLOBAL_SWDISABLE); > > @@ -275,13 +281,23 @@ static int dw_hdmi_qp_audio_prepare(struct drm_bridge *bridge, > { > struct dw_hdmi_qp *hdmi = dw_hdmi_qp_from_bridge(bridge); > bool ref2stream = false; > + int ret = 0; > + > + mutex_lock(&hdmi->phy.lock); > + if (!hdmi->phy.enabled) { > + ret = -EOPNOTSUPP; > + goto err_res; > + } > > - if (!hdmi->tmds_char_rate) > - return -ENODEV; > + if (!hdmi->tmds_char_rate) { > + ret = -ENODEV; > + goto err_res; > + } > > if (fmt->bit_clk_provider | fmt->frame_clk_provider) { > dev_err(hdmi->dev, "unsupported clock settings\n"); > - return -EINVAL; > + ret = -EINVAL; > + goto err_res; > } > > if (fmt->bit_fmt == SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE) > @@ -290,9 +306,13 @@ static int dw_hdmi_qp_audio_prepare(struct drm_bridge *bridge, > dw_hdmi_qp_set_audio_interface(hdmi, fmt, hparms); > dw_hdmi_qp_set_sample_rate(hdmi, hdmi->tmds_char_rate, hparms->sample_rate); > dw_hdmi_qp_set_channel_status(hdmi, hparms->iec.status, ref2stream); > - drm_atomic_helper_connector_hdmi_update_audio_infoframe(connector, &hparms->cea); > + mutex_unlock(&hdmi->phy.lock); > > - return 0; > + return drm_atomic_helper_connector_hdmi_update_audio_infoframe(connector, &hparms->cea); > + > +err_res: > + mutex_unlock(&hdmi->phy.lock); > + return ret; > } > > static void dw_hdmi_qp_audio_disable_regs(struct dw_hdmi_qp *hdmi) > @@ -321,6 +341,10 @@ static void dw_hdmi_qp_audio_disable(struct drm_bridge *bridge, > > drm_atomic_helper_connector_hdmi_clear_audio_infoframe(connector); > > + guard(mutex)(&hdmi->phy.lock); > + if (!hdmi->phy.enabled) > + return; > + > if (hdmi->tmds_char_rate) > dw_hdmi_qp_audio_disable_regs(hdmi); > } > @@ -551,6 +575,7 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge, > if (WARN_ON(!conn_state)) > return; > > + mutex_lock(&hdmi->phy.lock); This is not quite right as it keeps the lock held across drm_connector_hdmi_enable_scrambling() - which involves SCDC I2C transfers - and PHY init. Similarly, atomic_disable() holds it across drm_connector_hdmi_disable_scrambling(), which may call cancel_delayed_work_sync(). Only the state update needs to happen under the lock. > if (connector->display_info.is_hdmi) { > op_mode = 0; > hdmi->tmds_char_rate = conn_state->hdmi.tmds_char_rate; > @@ -572,10 +597,25 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge, > scoped_guard(mutex, &hdmi->mutex) > hdmi->curr_conn = connector; > > - hdmi->phy.ops->init(hdmi, hdmi->phy.data); > + ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data); > + if (unlikely(ret)) { This is unrelated to the audio issue, and also incomplete, as scrambling and the SCDC monitoring work are left enabled on the failure path. > + dev_err(hdmi->dev, "failed to initialize PHY: %d\n", ret); > + scoped_guard(mutex, &hdmi->mutex) { > + drm_connector_put(hdmi->curr_conn); > + hdmi->curr_conn = NULL; > + } > + > + hdmi->phy.enabled = false; > + hdmi->tmds_char_rate = 0; > + > + mutex_unlock(&hdmi->phy.lock); > + return; > + } > + hdmi->phy.enabled = true; > > dw_hdmi_qp_mod(hdmi, HDCP2_BYPASS, HDCP2_BYPASS, HDCP2LOGIC_CONFIG0); > dw_hdmi_qp_mod(hdmi, op_mode, OPMODE_DVI, LINK_CONFIG0); > + mutex_unlock(&hdmi->phy.lock); > > drm_atomic_helper_connector_hdmi_update_infoframes(connector, state); > } > @@ -593,12 +633,14 @@ static void dw_hdmi_qp_bridge_atomic_disable(struct drm_bridge *bridge, > } > } > > + guard(mutex)(&hdmi->phy.lock); > hdmi->tmds_char_rate = 0; > > connector = drm_atomic_get_old_connector_for_encoder(state, bridge->encoder); > drm_connector_hdmi_disable_scrambling(connector); > > hdmi->phy.ops->disable(hdmi, hdmi->phy.data); > + hdmi->phy.enabled = false; > } > > static enum drm_connector_status > @@ -689,10 +731,8 @@ static int dw_hdmi_qp_bridge_clear_spd_infoframe(struct drm_bridge *bridge) > return 0; > } > > -static int dw_hdmi_qp_bridge_clear_audio_infoframe(struct drm_bridge *bridge) > +static int dw_hdmi_qp_clear_audio_infoframe_regs(struct dw_hdmi_qp *hdmi) > { > - struct dw_hdmi_qp *hdmi = bridge->driver_private; > - > dw_hdmi_qp_mod(hdmi, 0, > PKTSCHED_ACR_TX_EN | > PKTSCHED_AUDS_TX_EN | > @@ -702,6 +742,17 @@ static int dw_hdmi_qp_bridge_clear_audio_infoframe(struct drm_bridge *bridge) > return 0; > } > > +static int dw_hdmi_qp_bridge_clear_audio_infoframe(struct drm_bridge *bridge) > +{ > + struct dw_hdmi_qp *hdmi = bridge->driver_private; > + > + guard(mutex)(&hdmi->phy.lock); > + if (!hdmi->phy.enabled) > + return 0; > + > + return dw_hdmi_qp_clear_audio_infoframe_regs(hdmi); > +} > + > static void dw_hdmi_qp_write_pkt(struct dw_hdmi_qp *hdmi, const u8 *buffer, > size_t start, size_t len, unsigned int reg) > { > @@ -796,7 +847,11 @@ static int dw_hdmi_qp_bridge_write_audio_infoframe(struct drm_bridge *bridge, > { > struct dw_hdmi_qp *hdmi = bridge->driver_private; > > - dw_hdmi_qp_bridge_clear_audio_infoframe(bridge); > + guard(mutex)(&hdmi->phy.lock); > + if (!hdmi->phy.enabled) > + return -EOPNOTSUPP; > + > + dw_hdmi_qp_clear_audio_infoframe_regs(hdmi); > > /* > * AUDI_CONTENTS0: { RSV, HB2, HB1, RSV } > @@ -1129,6 +1184,8 @@ struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev, > > hdmi->phy.ops = plat_data->phy_ops; > hdmi->phy.data = plat_data->phy_data; > + hdmi->phy.enabled = false; The explicit false assignment is redundant, as the struct is zero-allocated. > + mutex_init(&hdmi->phy.lock); Please use devm_mutex_init() and check its return value, if we really need a new mutex here. Cristian