From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796205392; b=jJRah3Gf+vSwCUQ6uqcZZcvUBbuS3UhAjVSBZwEcmVawJf2lG05bFW9m57UruRjyoULP I6omgtSOI4EmN5JAnwhNVf2oSBMPST/nxutszPT76kDIYKpogvKVpq88aniuNLTVMLa2K vbbctwjsKyreGQZ7BMBp+cdM2rgKdZ2GbXJnpLrcavIfOKJwn1ZK12VQHgjphCubEi+IE lxIntzrIJGbb4S6BOJbqcTcHB8XaeIPbV3K/+JayhCSV5IDdY5LNr2RdETdrJLnQLbwU+ /Z/TS2bDQyb8TMksEvBda4EIHToM+oAzmdBVo65NzIxZLoHydoRjvQFbk/XaEgh2DEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796205392; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:From:Subject:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=94HNsxao765YlKxdyt+hwTtQtJFuEIKsZjyFKzyqEqs=; b=fmY4NSl5a2IDSRSW9aeB6lX/R3UB43R+vyReLPCTTwmtFYgfoduQZU7v19Iui9ljtA9c XiKT/EjSMSQEutrHgqekPAzV/+e8mriGLvmGN3tZTM8xziO4osx/M+FtBOHgoRGwF/8Um DzePV5uxTUyPW9Lv9t93EDLW52pa+l2kxGwqUKEWMkj4+7CYACiMt9uElm3bnV5PLaaCG Do/PplEDJih1xAvhcYKwo+Q/WbwOdALBbE7rne/QHBK/gLnHC30v6Cujo5ySZbtFyVt+D ipOw7mSN6ZPRfT9QtKIuYncSvwPnTIK0j9gtuL2RCz8+W9TxOSE6FGSzTML0WlUvMLg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kX9AcTa+; arc=none smtp.remote-ip=74.125.82.181 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 869F0606A32F for ; Wed, 2 Dec 2026 09:56:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 869F0606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kX9AcTa+ Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-33bb5afa736so1612045eec.1 for ; Wed, 02 Dec 2026 01:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796205391; x=1796810191; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=94HNsxao765YlKxdyt+hwTtQtJFuEIKsZjyFKzyqEqs=; b=kX9AcTa+qrLuXZ5mKa94KCyq9GsStkQSjl1PJ8A4WCu3a+K6BUVTdmTY0D2CXO0EDK KDuteKfm06dR5ii7q4EsDXsXUWOXmxSDDe61ZZzDrdgdAeXO5q46Cptrw4zYV+XtYRjJ eDeAmw/cB/o607weHjghsF6eC7FCPN0uG9yiD0N4GTzarXUISUPgbz5zcX6BjOcfeZfV fmy0tMZztSE0l0O6jJwzERLXvZVlO/NMXs+28rEYOmQWvF22S5ylQfJFQuIVwwIJTFjJ 2shzb5o6l+QOFQLRifDT+e7xH1AwDp7rxkz6mAKC2XZkmfMZWP/vyY1JyS0Jmo+vAGR+ UE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796205391; x=1796810191; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=94HNsxao765YlKxdyt+hwTtQtJFuEIKsZjyFKzyqEqs=; b=K5oOSreisb+sivc0hjD3oNcAVgVI4lGurqIA2Po3syfhXMdnD7ii8hOnmimjF/Mzt6 2aohmkFGsbv7paNJGT5985IAsbKZMsW3DKHaBnk/Fp+JWS5jGYf6NFPhbL1okm2XkJYQ Ijr9MfCkh54zUrLFU+xgmdhK21AOYcWLjd+6ZI63CEVFOjpMo33Lz0cb25YEAyOaionW b90uSq1a9UzDFx96BRbovQ+LfSBWH5W+u5R5yhIvPd4k1hv6++OGaIh62D3TKhlK9NI8 kDtuYAQw8GoUoBx901MUgZ12/bdFHrVOwAF3nul6RCBRuJ/z7NmjE0L6FjQMwWWfEzta JWfA== X-Forwarded-Encrypted: i=1; AL+hErG2ejnTD/fZ70NDpaUOfvvkQlsrX/NFB7lutrKSOxzVt9blNikjqDJ4W1B3AUE1SzGQQU9dAHoEaGOrqNA=@vger.kernel.org X-Gm-Message-State: APuU4Z+LaEkOaUVAr0o1I30eHguaWKxHySUSdOuvGW05nSKVcBXvDRnj D7S7YqdKAR8ayCtaEF8/gZ2s04yZv12w6W6RyfzcO/QQvmU+LpWEpjL2 X-Gm-Gg: AZFdTZejjOdya+2svFZR4hql8s9FqBOK3FCIxiMAmxtnOHpiVUzLin0VRnoDAFAkNSv 9E4nFAeSw4NHf8cSNl4ZvWaqr23khQPIzowjOEusdIphXupU2ZsUc1gT2227hIthOIBXsKxK58h wuxVAH4GwE4wvHxz400Q27zFAXFhPNFyeicmGH5X7qCJaJLcJL8sXvb8GANMPnnUR1Mn5R1Qe7Y IBI2SuJX1aRI9IJ4O6h4FRLu69MszF3dexsLkHzVq2Zo0mqLD2oz1HCQoWyGn6VA4Bnp36l4vgz u22ryuKmGidvJhvL7XIj5nhWQxL5SReyl+2zQSmIk2WIu6ZDQXw6iXul1NtB5qYDdEBX3i/zEW5 434PArkmpPnA7nE0+IjP71SLfjubcnmirHxhCfJHueRC8misCJ2tp8R9EzrctfQSGCxJWit2tqf jVT1Q0t+31lwijrDNkbnAV9sdJR7UOlqxoJ/iZPfmOIPbcP0/EYkeY6NAR9wcW1mBVYMLdbytvX W9gHx02GmDWOowIWrkHdmPO+qChI/y5ZCGM1f8CP1WIzxbEINEi9m427q7ZncS2feXcqSl2khnH K22rNptJicYPBraTqGwZatR82tCUtynYJv/wE3OBhfeJDc5Jw0pCwdHmCIBE2rRVXSvyaA== X-Received: by 2002:a05:693c:26cb:b0:381:6297:8f99 with SMTP id 5a478bee46e88-3856e748babmr59947242eec.2.1796205391416; Wed, 02 Dec 2026 01:56:31 -0800 (PST) Received: from [192.168.1.206] (2607-8700-5500-a805-0000-0000-0000-0002.16clouds.com. [2607:8700:5500:a805::2]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385677c0c1dsm130803813eec.21.2026.12.02.01.56.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 01:56:30 -0800 (PST) Message-ID: Date: Wed, 2 Dec 2026 17:56:14 +0800 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 From: Frank Zhang Subject: Re: [PATCH v7] drm/bridge: dw-hdmi-qp: serialize HDMI audio callbacks with PHY enable/disable To: Cristian Ciocaltea , 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> <93924e13-117a-4ba9-b243-42ae79e86c1d@collabora.com> Content-Language: en-US In-Reply-To: <93924e13-117a-4ba9-b243-42ae79e86c1d@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Cristian, Thanks for your comments. On 12/1/26 10:17, Cristian Ciocaltea wrote: > 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. > Reusing `tmds_char_rate` as phy indicator is reasonable, I will remove `phy.enabled` in the next version. Regarding `hdmi->mutex`, this mutex is not only used in atomic enable/disable, but also used in dw_hdmi_qp_hpd_notify(). Although the lock scope is very small, it still introduces lock condition for audio callbacks, or am I missing something? To keep the lock scope cleaner, we can use a dedicated mutex (e.g., `hdmi->audio_mutex`) for tmds_char_rate. Does this sound reasonable to you? >> 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. > This commit(247695b19afc) is on branch: drm-misc-next, right? I will rebase onto this branch in the next version. >> + >> 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. > Thanks for the suggestion, I will reduce lock scope in the next version. >> 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. > Indeed this unlikely failure isn't critical, we can remove the change until the PHY driver actually has failures to handle. >> + 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 Thanks for the suggestion, I will modify it if the decision is adding a new mutex in the next version. Best regards, Frank Zhang