From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796306867; b=HvdabwE93eqAONGBkM84FVglRUhof72DNvp0K+cbC/EM+RPJFewZwwl6mmXc14U4E6wv z87l9VI2HYmCZbbfn+Ia/GhjZP7lkXzrcp1qKm3fayXev3aJziL9BaY1XxwtIOKPmbo16 ThEEVDmCO5Xohg52l2htK+CQktZn6GaZnXpxgfLVkWhbPI/MGrjDLtN2JOzV/VzZhRj5y h+jao86RaWBwKToQH3zz2KiwyTxj7m0SZBydVpPPYx6T5Ee/K69ZlRMkGVbWYRzZi53AN mAdgLnhc8rz9IofkdPbCXkxWFV3kJpEtKE8BI/U6XhsXTEy4U2/JrPPAB57bIL8UwNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796306867; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=388ztI594AS+nKGPU4H0M5a2RIBgnI1LfiHUyoQUutQ=; b=oaEeHOGyzSGUT1N8j5ya/DEgeNpRpTFy9haVpUvWOeNexXvAzpfvzkDooel+9rQ/NxQn GUrDeXnNpJti63RuG7Sul4emlKlRlEHP8payrfkCK4ZhI2PHk47z0xN+9/U1tLisk2jOe J1T9Ytl7OUZtudWGDd4JjVvDSH9k9yMl9jhP6EPDnnenN9Yf7fcAabdz528UwUbFCZUuK 3F0aCGMYFRm/B6YBToukXI8PlKaCn7Zvf7wtHsAegvfmkZuv16e0kXXc/i2kh4i8vfFvU YeQcsfCHfym5bxPanBwpO9UnY3Z98K4cCv9xx4aCvw+AmFILMUTDKm6lggQfhE3SwpA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cA7ceCTo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBE2F606A33A for ; Thu, 3 Dec 2026 14:07:47 +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=cA7ceCTo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 167B91F00899; Thu, 3 Dec 2026 14:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796306867; bh=388ztI594AS+nKGPU4H0M5a2RIBgnI1LfiHUyoQUutQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=cA7ceCToJPezlHf+JleQZuxI8qciO8ycMTomKRD1xcKsD043bxGV2EYDmay/s/Iyn gyrbe3BWH8Zd+ZQekuesnFhLGScFqeOfNsoeGKlD0c5tO2Xgqn/6gWsH3e0ESO4cKF 7ZnBN0qCwjdiF6g7+C3GOrEN6A4f/gPOZjnJrRFfWfxFbhcbSYIdGhGQyZ+pwVf6i2 jN6JV9sAuITvo/YTcHoEGV8CvsJmO+i02DYD9JoMXa0LvkiVrEAwxTFHHWaVrBY+aa caaXEN60phCvOPMQbZo/v7xnSmjzuQjRVMx+Ctgh69ksyMMA5nopmpD1AaP+0nXbV5 BxJKCXcpIcQYQ== From: Maxime Ripard Date: Thu, 03 Dec 2026 15:07:24 +0100 Subject: [PATCH v13 6/9] drm/vc4: Carry the HVS channel over to created CRTC states 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20261203-drm-reset-state-flag-v13-6-b09f19f64e64@kernel.org> References: <20261203-drm-reset-state-flag-v13-0-b09f19f64e64@kernel.org> In-Reply-To: <20261203-drm-reset-state-flag-v13-0-b09f19f64e64@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Louis Chauvet , Haneen Mohammed , Melissa Wen Cc: Daniel Stone , Harry Wentland , Jocelyn Falempe , =?utf-8?q?Jonas_=C3=85dahl?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Pekka Paalanen , Sebastian Wick , Simon Ser , Victoria Brekenfeld , Xaver Hugl , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Maxime Ripard , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Canal?= , Raspberry Pi Kernel Maintenance X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6843; i=mripard@kernel.org; h=from:subject:message-id; bh=Aen0UsFhzRDDkrCC3Fuk/+qjL8RrEjAcNfYIsatGIkI=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDNmC5bN5K6d+cGg/t9NZ+9PN20Whc2Jcn1Z0TCmYyf27R OzA/Rl7O6ayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEfjxgrFO5v5s1ukQqbor7 go/b/SLjr+xvvJWQURxibGPkVZ15SsdyknZ/clHAuurVgQYH+RJlGBvudBmes5ofV1vat972aXm HP28alzzHtyWnTnxk5eQvXueQKFsaufHhgx3RccFWTi0JfwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D drm_atomic_commit_fill_with_defaults() builds its commits out of states created through atomic_create_state() instead of duplicating the current state. A created CRTC state comes with its assigned_channel left to VC4_HVS_CHANNEL_DISABLED, while a duplicated state carries the channel currently in use. vc4_pv_muxing_atomic_check() skips the CRTCs whose enablement doesn't change, so a CRTC that stays enabled with a created state keeps its channel unset, and vc4_core_clock_atomic_check() then indexes hvs_new_state->fifo_state[] with VC4_HVS_CHANNEL_DISABLED (-1U), far outside of the array. Copy the channel of the current state over in the skip branch, like a duplicated state would have carried it. This is a no-op for duplicated states, which already have the channel set. Add a KUnit test that enables an output, fills a state with defaults and re-applies the same configuration, and checks that the CRTC kept its channel. Acked-by: Dave Stevenson Signed-off-by: Maxime Ripard --- To: Dave Stevenson To: MaĆ­ra Canal Cc: Raspberry Pi Kernel Maintenance --- drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c | 105 +++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_kms.c | 16 +++- 2 files changed, 119 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c index 7a54f46acff9..c868d2cd1b3d 100644 --- a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c +++ b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c @@ -1119,14 +1119,119 @@ drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state(struct ku drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); } +/* + * Test that a CRTC that stays enabled with a state created through + * atomic_create_state(), like the ones drm_atomic_commit_fill_with_defaults() + * builds for a reset, keeps the HVS channel it was assigned: + * vc4_pv_muxing_atomic_check() skips the CRTCs whose enablement doesn't + * change, so their new state has to carry the channel over from the + * current state, the way a duplicated state would, for + * vc4_core_clock_atomic_check() to see a valid channel. + */ +static void +drm_test_vc5_pv_muxing_bugs_created_state_keeps_channel(struct kunit *test) +{ + struct drm_modeset_acquire_ctx ctx; + struct drm_atomic_commit *state; + struct vc4_crtc_state *new_vc4_crtc_state; + struct drm_device *drm; + struct vc4_dev *vc4; + unsigned int old_channel; + int ret; + + vc4 = vc5_mock_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vc4); + + drm_modeset_acquire_init(&ctx, 0); + + drm = &vc4->base; +retry_first: + state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state); + + ret = vc4_mock_atomic_add_output(test, state, VC4_ENCODER_TYPE_HDMI0); + if (ret == -EDEADLK) { + drm_atomic_commit_clear(state); + ret = drm_modeset_backoff(&ctx); + if (!ret) + goto retry_first; + } + KUNIT_ASSERT_EQ(test, ret, 0); + + ret = drm_atomic_check_only(state); + if (ret == -EDEADLK) { + drm_atomic_commit_clear(state); + ret = drm_modeset_backoff(&ctx); + if (!ret) + goto retry_first; + } + KUNIT_ASSERT_EQ(test, ret, 0); + + new_vc4_crtc_state = get_vc4_crtc_state_for_encoder(test, state, + VC4_ENCODER_TYPE_HDMI0); + KUNIT_ASSERT_NOT_NULL(test, new_vc4_crtc_state); + + old_channel = new_vc4_crtc_state->assigned_channel; + KUNIT_ASSERT_NE(test, old_channel, VC4_HVS_CHANNEL_DISABLED); + + /* Make the enabled state the current one */ + ret = drm_atomic_helper_swap_state(state, false); + KUNIT_ASSERT_EQ(test, ret, 0); + +retry_second: + state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state); + + /* + * Fill the state with defaults, like a DRM_MODE_ATOMIC_RESET + * commit would, then re-apply the exact same configuration. + */ + ret = drm_atomic_commit_fill_with_defaults(NULL, state); + if (ret == -EDEADLK) { + drm_atomic_commit_clear(state); + ret = drm_modeset_backoff(&ctx); + if (!ret) + goto retry_second; + } + KUNIT_ASSERT_EQ(test, ret, 0); + + ret = vc4_mock_atomic_add_output(test, state, VC4_ENCODER_TYPE_HDMI0); + if (ret == -EDEADLK) { + drm_atomic_commit_clear(state); + ret = drm_modeset_backoff(&ctx); + if (!ret) + goto retry_second; + } + KUNIT_ASSERT_EQ(test, ret, 0); + + ret = drm_atomic_check_only(state); + if (ret == -EDEADLK) { + drm_atomic_commit_clear(state); + ret = drm_modeset_backoff(&ctx); + if (!ret) + goto retry_second; + } + KUNIT_ASSERT_EQ(test, ret, 0); + + new_vc4_crtc_state = get_vc4_crtc_state_for_encoder(test, state, + VC4_ENCODER_TYPE_HDMI0); + KUNIT_ASSERT_NOT_NULL(test, new_vc4_crtc_state); + + KUNIT_EXPECT_EQ(test, new_vc4_crtc_state->assigned_channel, old_channel); + + drm_modeset_drop_locks(&ctx); + drm_modeset_acquire_fini(&ctx); +} + static struct kunit_case vc5_pv_muxing_bugs_tests[] = { KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable), KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_subsequent_crtc_enable_too_many_crtc_state), KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_stable_fifo), + KUNIT_CASE(drm_test_vc5_pv_muxing_bugs_created_state_keeps_channel), {} }; static struct kunit_suite vc5_pv_muxing_bugs_test_suite = { .name = "vc5-pv-muxing-bugs", diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c index ab551eb2da50..562f2d1f45a4 100644 --- a/drivers/gpu/drm/vc4/vc4_kms.c +++ b/drivers/gpu/drm/vc4/vc4_kms.c @@ -970,15 +970,27 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev, drm_dbg(dev, "%s: Trying to find a channel.\n", crtc->name); /* Nothing to do here, let's skip it */ if (old_crtc_state->enable == new_crtc_state->enable) { - if (new_crtc_state->enable) + /* + * A CRTC that stays enabled keeps its channel. A + * duplicated state carries it over, but a state + * created through atomic_create_state() comes with + * the channel unset, so copy it from the current + * state to make sure the core clock check and the + * commit see the channel in use. + */ + if (new_crtc_state->enable) { + new_vc4_crtc_state->assigned_channel = + old_vc4_crtc_state->assigned_channel; + drm_dbg(dev, "%s: Already enabled, reusing channel %d.\n", crtc->name, new_vc4_crtc_state->assigned_channel); - else + } else { drm_dbg(dev, "%s: Disabled, ignoring.\n", crtc->name); + } continue; } /* Muxing will need to be modified, mark it as such */ -- 2.56.1