Skip to contentSkip to conversation

drm/tests: Drop drm_kunit_helper_acquire_ctx_alloc()

PATCH Superseded Maxime Ripard 2 participants 2 messages Feb 6, 2025 – Feb 7, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Maxime Ripard

author maintainer
#0 lore raw

PATCH 1/1 drm/tests: Drop drm_kunit_helper_acquire_ctx_alloc()

lockdep complains when a lock is released in a separate function the lock is taken in, and it's even worse in the kunit case since the kunit actions run in a separate thread.

This means that drm_kunit_helper_acquire_ctx_alloc() just cannot work as it's supposed to, so let's just get rid of it.

---
 drivers/gpu/drm/tests/drm_atomic_state_test.c |  24 +-
 .../drm/tests/drm_hdmi_state_helper_test.c    | 242 +++++++++++-------
 drivers/gpu/drm/tests/drm_kunit_helpers.c     |  41 ---
 .../gpu/drm/vc4/tests/vc4_test_pv_muxing.c    |  46 ++--
 include/drm/drm_kunit_helpers.h               |   2 -
 5 files changed, 184 insertions(+), 171 deletions(-)
drivers/gpu/drm/tests/drm_atomic_state_test.c +14 -10
index 0ab5d9ec4a75..0add74417110 100644
@@ -187,11 +187,11 @@ static int set_up_atomic_state(struct kunit *test,
  * connectors are changed but the CRTC mode is not.
  */
 static void drm_test_check_connector_changed_modeset(struct kunit *test)
 {
 	struct drm_atomic_test_priv *priv;
-	struct drm_modeset_acquire_ctx *ctx;
+	struct drm_modeset_acquire_ctx ctx;
 	struct drm_connector *old_conn, *new_conn;
 	struct drm_atomic_state *state;
 	struct drm_device *drm;
 	struct drm_connector_state *new_conn_state, *old_conn_state;
 	int ret, initial_modeset_count;
@@ -201,18 +201,17 @@ static void drm_test_check_connector_changed_modeset(struct kunit *test)
 
 	drm = &priv->drm;
 	old_conn = &priv->connectors[0];
 	new_conn = &priv->connectors[1];
 
-	ctx = drm_kunit_helper_acquire_ctx_alloc(test);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
+	drm_modeset_acquire_init(&ctx, 0);
 
 	// first modeset to enable
-	ret = set_up_atomic_state(test, priv, old_conn, ctx);
+	ret = set_up_atomic_state(test, priv, old_conn, &ctx);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
-	state = drm_kunit_helper_atomic_state_alloc(test, drm, ctx);
+	state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
 
 	new_conn_state = drm_atomic_get_connector_state(state, new_conn);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_conn_state);
 
@@ -229,10 +228,13 @@ static void drm_test_check_connector_changed_modeset(struct kunit *test)
 
 	// modeset_disables is called as part of the atomic commit tail
 	ret = drm_atomic_commit(state);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 	KUNIT_ASSERT_EQ(test, modeset_counter, initial_modeset_count + 1);
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
 }
 
 /*
  * Test that the drm_crtc_in_clone_mode() helper can detect if a given CRTC
  * state is in clone mode
@@ -261,27 +263,26 @@ static void drm_test_check_in_clone_mode(struct kunit *test)
 static void drm_test_check_valid_clones(struct kunit *test)
 {
 	int ret;
 	const struct drm_clone_mode_test *param = test->param_value;
 	struct drm_atomic_test_priv *priv;
-	struct drm_modeset_acquire_ctx *ctx;
+	struct drm_modeset_acquire_ctx ctx;
 	struct drm_device *drm;
 	struct drm_atomic_state *state;
 	struct drm_crtc_state *crtc_state;
 
 	priv = drm_atomic_test_init_drm_components(test, false);
 	KUNIT_ASSERT_NOT_NULL(test, priv);
 
 	drm = &priv->drm;
 
-	ctx = drm_kunit_helper_acquire_ctx_alloc(test);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
+	drm_modeset_acquire_init(&ctx, 0);
 
-	ret = set_up_atomic_state(test, priv, NULL, ctx);
+	ret = set_up_atomic_state(test, priv, NULL, &ctx);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
-	state = drm_kunit_helper_atomic_state_alloc(test, drm, ctx);
+	state = drm_kunit_helper_atomic_state_alloc(test, drm, &ctx);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
 
 	crtc_state = drm_atomic_get_crtc_state(state, priv->crtc);
 	KUNIT_ASSERT_NOT_NULL(test, crtc_state);
 
@@ -290,10 +291,13 @@ static void drm_test_check_valid_clones(struct kunit *test)
 	// force modeset
 	crtc_state->mode_changed = true;
 
 	ret = drm_atomic_helper_check_modeset(drm, state);
 	KUNIT_ASSERT_EQ(test, ret, param->expected_result);
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
 }
 
 static void drm_check_in_clone_mode_desc(const struct drm_clone_mode_test *t,
 				      char *desc)
 {
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +143 -99

928 lines not on this page · raw message

drivers/gpu/drm/tests/drm_kunit_helpers.c +0 -41

51 lines not on this page · raw message

drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c +27 -19

195 lines not on this page · raw message

include/drm/drm_kunit_helpers.h +0 -2
index afdd46ef04f7..11d59ce0bac0 100644
@@ -93,12 +93,10 @@ __drm_kunit_helper_alloc_drm_device(struct kunit *test,
 #define drm_kunit_helper_alloc_drm_device(_test, _dev, _type, _member, _feat)	\
 	((_type *)__drm_kunit_helper_alloc_drm_device(_test, _dev,		\
 						      sizeof(_type),		\
 						      offsetof(_type, _member),	\
 						      _feat))
-struct drm_modeset_acquire_ctx *
-drm_kunit_helper_acquire_ctx_alloc(struct kunit *test);
 
 struct drm_atomic_state *
 drm_kunit_helper_atomic_state_alloc(struct kunit *test,
 				    struct drm_device *drm,
 				    struct drm_modeset_acquire_ctx *ctx);
Signature · 1 line
2.48.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Maxime Ripard

lockdep complains when a lock is released in a separate function the lock is taken in, and it's even worse in the kunit case since the kunit actions run in a separate thread.

This means that drm_kunit_helper_acquire_ctx_alloc() just cannot work as it's supposed to, so let's just get rid of it.

Quoted 8 lines
---
 drivers/gpu/drm/tests/drm_atomic_state_test.c |  24 +-
 .../drm/tests/drm_hdmi_state_helper_test.c    | 242 +++++++++++-------
 drivers/gpu/drm/tests/drm_kunit_helpers.c     |  41 ---
 .../gpu/drm/vc4/tests/vc4_test_pv_muxing.c    |  46 ++--
 include/drm/drm_kunit_helpers.h               |   2 -
 5 files changed, 184 insertions(+), 171 deletions(-)
Signature · 2 lines
With best wishes
Dmitry