Skip to contentSkip to conversation

drm/amd/display: fix GPU hang on SST<->MST switch of the same sink

PATCH New Bart Verwilst 1 participant 3 messages Nov 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover drm/amd/display: fix GPU hang on SST<->MST switch of the same sink

Toggling Picture-by-Picture on a Samsung Odyssey Neo G9 57" switches the sink between SST (PbP) and MST (fullscreen) on the same UHBR link. On an RX 9070 XT (DCN 4.0.1) it hard-locked the machine every time: the stale stream of the previous mode is torn down after the new mode's stream is lit, and that teardown powers the sink down and turns the PHY off under the new stream. Analysis and logs are in
https://gitlab.freedesktop.org/drm/amd/-/work_items/5671

Patch 2 fixes the teardown. Patch 1 makes the MST payload release in amdgpu_dm safe against releasing a payload twice or one that was never added. The tested sequences hit both, and without patch 1 payload_count underflows.

Tested on 7.3.5 with the equivalent code in link_dpms.c, with DP AUX debug logging: PbP off and on, and DPMS sleep/wake in both modes, including a wake where the first UHBR13.5 training fails with channel EQ timeouts and the link recovers after re-detection. No hangs, the payloads always start at slot 0, and the "kept up" path only triggers when the other mode's stream is enabled.

Changes in v3:
- 1/2: when there are no time slots to release, still drop the port malloc reference of a deleted payload and mark it unallocated, as drm_dp_remove_payload_part2() does. drm_dp_mst_destroy_state() skips deleted payloads, so skipping part2 entirely leaked the reference. The two teardowns this guards against run on different MST state copies, so each copy still drops its own reference exactly once.
- 1/2: add Fixes: tag.
- 2/2: unchanged.

Changes in v2 (thanks to the Sashiko review of v1):
- Detect a stale stream by checking the current state for an enabled stream of the other mode on the same link, instead of comparing the signal with link->type. link->type is temporarily SST during detection, so v1 also skipped the teardown during destructive link verification on an MST link and released the payload twice.
- Use link_set_dsc_on_stream() for the stale stream so the sink's DP_DSC_ENABLE is left alone.
- Skip deallocate_usb4_bandwidth() for the stale stream.
- Clear the stale stream encoder's VC rate and hblank settings when the link runs 128b/132b.
- New patch 1/2.

v2: https://lore.kernel.org/amd-gfx/[email protected]/
v1: https://lore.kernel.org/amd-gfx/[email protected]/

Bart Verwilst (2):
drm/amd/display: don't release an MST payload that holds no time slots drm/amd/display: don't tear down a shared link for a stale SST/MST
stream

 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 31 +++++-
 .../drm/amd/display/dc/link/link_dpms_v1.c    | 96 +++++++++++++++++--
 2 files changed, 118 insertions(+), 9 deletions(-)
Signature · 1 line
2.56.1
#1 lore raw

PATCH v3 1/2 drm/amd/display: don't release an MST payload that holds no time slots

dm_helpers_dp_mst_update_mst_mgr_for_deallocation() calls drm_dp_remove_payload_part2() unconditionally. That function decrements payload_count and moves next_start_slot back by the payload's time slots. If the payload was never added with drm_dp_add_payload_part1(), or was already released, both counters underflow. Every payload allocated afterwards then starts at a bogus slot and ACT never completes.

This can happen when the same stream is disabled twice, e.g. first by link_set_all_streams_dpms_off_for_link() during a destructive link verification and then again when userspace disables its CRTC, or when the stream enable was aborted before its payload was allocated.

drm_dp_add_payload_part1() sets vc_start_slot and drm_dp_remove_payload_part2() resets it to -1, so a negative vc_start_slot means there is nothing to release. Skip the time slot accounting in that case, but still drop the port reference of a deleted payload and mark it unallocated, as drm_dp_remove_payload_part2() would.

Fixes 83a79dd6f4fb ("drm/amd/display: adjust flow for deallocation mst payload")
---
 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 31 +++++++++++++++++--
 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +28 -3
index 6192c0f..b25d707 100644
@@ -524,10 +524,35 @@ void dm_helpers_dp_mst_update_mst_mgr_for_deallocation(
 	mst_mgr = &aconnector->mst_root->mst_mgr;
 	mst_state = to_drm_dp_mst_topology_state(mst_mgr->base.state);
 	new_payload = drm_atomic_get_mst_payload_state(mst_state, aconnector->mst_output_port);
-	dm_helpers_construct_old_payload(mst_mgr, mst_state,
-					 new_payload, &old_payload);
+	if (!new_payload)
+		return;
 
-	drm_dp_remove_payload_part2(mst_mgr, mst_state, &old_payload, new_payload);
+	/*
+	 * Only a payload that went through drm_dp_add_payload_part1() holds
+	 * time slots in the manager (vc_start_slot >= 0). Releasing a payload
+	 * that was never added, or releasing one twice, would underflow
+	 * payload_count and next_start_slot.
+	 */
+	if (new_payload->vc_start_slot >= 0) {
+		dm_helpers_construct_old_payload(mst_mgr, mst_state,
+						 new_payload, &old_payload);
+		drm_dp_remove_payload_part2(mst_mgr, mst_state, &old_payload,
+					    new_payload);
+	} else {
+		drm_dbg_kms(mst_mgr->dev,
+			    "MST payload for VCPI %d holds no time slots, nothing to release\n",
+			    new_payload->vcpi);
+		/*
+		 * Still do what drm_dp_remove_payload_part2() does apart from
+		 * the time slot accounting: drop the port reference of a
+		 * deleted payload, which drm_dp_mst_destroy_state() skips, and
+		 * mark the payload as unallocated.
+		 */
+		if (new_payload->delete)
+			drm_dp_mst_put_port_malloc(new_payload->port);
+		new_payload->payload_allocation_status =
+			DRM_DP_MST_PAYLOAD_ALLOCATION_NONE;
+	}
 
 	amdgpu_dm_set_mst_status(&aconnector->mst_status, set_flag, true);
 	amdgpu_dm_set_mst_status(&aconnector->mst_status, clr_flag, false);
Signature · 1 line
2.56.1
#2 lore raw

PATCH v3 2/2 drm/amd/display: don't tear down a shared link for a stale SST/MST stream

In reply to Bart Verwilst

A sink can switch between SST and MST on the same link. The Samsung Odyssey Neo G9 57" does that when Picture-by-Picture is toggled in its
OSD: PbP is a 3840x2160 SST stream, fullscreen is a 7680x2160 MST stream with DSC, both over UHBR.

The stream of the previous mode stays in the dc state until userspace disables its CRTC. On PbP off, the MST stream is already up (UHBR13.5 trained, payload allocated, ACT done) when the compositor disables the old SST CRTC on the same link. link_set_dpms_off_v1() treats that as a regular SST teardown:

link_set_dpms_off ... signal=20 link=2 sink_count=1
DPCD 0x00600 AUX <- 02 (sink to D3)

update_sst_payload(false) rewrites the payload allocation of the shared 128b/132b link encoder, and disable_link() powers the sink down and turns the PHY off while the MST stream is still running on it. disable_link_dp() only protects a link with active MST payloads when the stream being disabled is itself an MST stream. On Navi 48 (DCN 4.0.1) the GPU locks up about 2.5 s later and needs a hard reset. The mirrored case, a stale MST stream disabled on a link that is now SST, does the same through deallocate_mst_payload() and disable_link().

When another enabled stream of the other mode (SST vs. MST) is present on the same link in the current state, only release the disabled stream's own
resources: blank it, clear its own VC rate and hblank settings while the link runs 128b/132b, disable the stream and its DSC, and do the MST bookkeeping in software. Leave the sink power and DSC enable, the PHY, USB4 bandwidth and the link encoder's payload table to the stream of the new mode. Without such a stream, e.g. during link verification on detection, the teardown is unchanged.

---
 .../drm/amd/display/dc/link/link_dpms_v1.c    | 96 +++++++++++++++++--
 1 file changed, 90 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/link/link_dpms_v1.c +90 -6
index 1a6fe2e..c229366 100644
@@ -2403,6 +2403,42 @@ static struct vpg *get_vpg(struct pipe_ctx *pipe_ctx)
 		return pipe_ctx->stream_res.stream_enc->vpg;
 }
 
+/*
+ * A sink can switch between SST and MST on the same link, e.g. a monitor
+ * toggling Picture-by-Picture. The stream of the previous mode stays in the
+ * state until userspace disables its CRTC, which can happen after a stream of
+ * the new mode is already lit on this link. Returns true if such a stream of
+ * the other mode is enabled on the link, i.e. the link must stay up.
+ */
+static bool link_in_use_by_other_mode(const struct dc_link *link,
+				      const struct dc_stream_state *stream)
+{
+	const struct dc *dc = link->dc;
+	bool is_mst = stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST;
+	int i;
+
+	if (!dc_is_dp_signal(stream->signal) || !dc->current_state)
+		return false;
+
+	for (i = 0; i < dc->res_pool->pipe_count; i++) {
+		const struct pipe_ctx *pipe =
+				&dc->current_state->res_ctx.pipe_ctx[i];
+		bool other_is_mst;
+
+		if (!pipe->stream || pipe->stream == stream ||
+		    !is_master_pipe_for_link(link, pipe) ||
+		    pipe->stream->dpms_off ||
+		    !dc_is_dp_signal(pipe->stream->signal))
+			continue;
+
+		other_is_mst = pipe->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST;
+		if (other_is_mst != is_mst)
+			return true;
+	}
+
+	return false;
+}
+
 enum dc_status link_set_dpms_off_v1(struct pipe_ctx *pipe_ctx)
 {
 	DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
@@ -2411,6 +2447,7 @@ enum dc_status link_set_dpms_off_v1(struct pipe_ctx *pipe_ctx)
 	struct dc_link *link = stream->link;
 	struct vpg *vpg = get_vpg(pipe_ctx);
 	enum dp_panel_mode panel_mode_dp = dp_get_panel_mode(link);
+	bool stale_on_link;
 
 	ASSERT(is_master_pipe_for_link(link, pipe_ctx));
 
@@ -2418,6 +2455,17 @@ enum dc_status link_set_dpms_off_v1(struct pipe_ctx *pipe_ctx)
 		/* No real hardware to program for virtual signals. */
 		return DC_DPMS_SKIPPED_HANDSHAKE;
 
+	/*
+	 * Tearing down the stale stream of a previous SST/MST mode must not
+	 * touch what the new mode's stream shares with it: sink power
+	 * (DP_SET_POWER), sink DSC, the PHY, USB4 bandwidth, or the link
+	 * encoder's payload allocation. Only release the stream's own resources.
+	 */
+	stale_on_link = link_in_use_by_other_mode(link, stream);
+	if (stale_on_link)
+		DC_LOG_WARNING("%s: stale signal %x on link %u, link in use, kept up\n",
+			       __func__, stream->signal, link->link_index);
+
 	if (stream->sink) {
 		if (stream->sink->sink_signal != SIGNAL_TYPE_VIRTUAL &&
 			stream->sink->sink_signal != SIGNAL_TYPE_NONE) {
@@ -2440,14 +2488,45 @@ enum dc_status link_set_dpms_off_v1(struct pipe_ctx *pipe_ctx)
 	dc->hwss.blank_stream(pipe_ctx);
 
 	if (pipe_ctx->link_config.dp_tunnel_settings.should_use_dp_bw_allocation &&
-	    stream->sink)
+	    stream->sink && !stale_on_link)
 		deallocate_usb4_bandwidth(stream);
 
-	if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
+	if (stale_on_link) {
+		const struct link_hwss *link_hwss =
+				get_link_hwss(link, &pipe_ctx->link_res);
+		const struct dc_link_settings empty_link_settings = {0};
+
+		/*
+		 * Clear this stream encoder's own VC rate and hblank settings.
+		 * Those registers are only clocked while the link runs
+		 * 128b/132b.
+		 */
+		if (link_dp_get_encoding_format(&link->cur_link_settings) ==
+				DP_128b_132b_ENCODING &&
+		    dp_is_128b_132b_signal(pipe_ctx)) {
+			if (link_hwss->ext.set_throttled_vcp_size)
+				link_hwss->ext.set_throttled_vcp_size(pipe_ctx,
+						dc_fixpt_from_int(0));
+			if (link_hwss->ext.set_hblank_min_symbol_width)
+				link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
+						&empty_link_settings,
+						dc_fixpt_from_int(0));
+		}
+
+		/* bookkeeping only, the link belongs to the new mode now */
+		if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
+			remove_stream_from_alloc_table(link,
+						       pipe_ctx->stream_res.stream_enc,
+						       pipe_ctx->stream_res.hpo_dp_stream_enc);
+			dm_helpers_dp_mst_update_mst_mgr_for_deallocation(stream->ctx,
+									  stream);
+		}
+	} else if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
 		deallocate_mst_payload(pipe_ctx);
-	else if (dc_is_dp_sst_signal(stream->signal) &&
-			dp_is_128b_132b_signal(pipe_ctx))
+	} else if (dc_is_dp_sst_signal(stream->signal) &&
+			dp_is_128b_132b_signal(pipe_ctx)) {
 		update_sst_payload(pipe_ctx, false);
+	}
 
 	if (dc_is_hdmi_signal(stream->signal)) {
 		struct ext_hdmi_settings settings = {0};
@@ -2472,7 +2551,9 @@ enum dc_status link_set_dpms_off_v1(struct pipe_ctx *pipe_ctx)
 		}
 	}
 
-	if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+	if (stale_on_link) {
+		dc->hwss.disable_stream(pipe_ctx);
+	} else if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
 			!dp_is_128b_132b_signal(pipe_ctx)) {
 
 		/* In DP1.x SST mode, our encoder will go to TPS1
@@ -2491,7 +2572,10 @@ enum dc_status link_set_dpms_off_v1(struct pipe_ctx *pipe_ctx)
 	edp_set_panel_assr(link, pipe_ctx, &panel_mode_dp, false);
 
 	if (stream->timing.flags.DSC) {
-		if (dc_is_dp_signal(stream->signal))
+		if (stale_on_link)
+			/* release our DSC, leave the sink's DSC_ENABLE alone */
+			link_set_dsc_on_stream(pipe_ctx, false);
+		else if (dc_is_dp_signal(stream->signal))
 			link_set_dsc_enable(pipe_ctx, false);
 		else if (dc_is_hdmi_frl_signal(stream->signal))
 			link_set_dsc_on_stream(pipe_ctx, false);
Signature · 1 line
2.56.1