Skip to contentSkip to conversation

drm/ttm/tests: Let ttm_bo_test consider different ww_mutex implementation.

PATCH In review Sebastian Andrzej Siewior 2 participants 3 messages Jun 13, 2024

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

PATCH 1/1 drm/ttm/tests: Let ttm_bo_test consider different ww_mutex implementation.

PREEMPT_RT has a different locking implementation for ww_mutex. The base mutex of struct ww_mutex is declared as struct WW_MUTEX_BASE. The latter is defined as mutex' for non-PREEMPT_RT builds and rt_mutex' for PREEMPT_RT builds.

Using mutex_lock() directly on the base mutex in ttm_bo_reserve_deadlock() leads to compile error on PREEMPT_RT.

The locking-selftest has its own defines to deal with this and it is probably best to defines the needed one within the test program since their usefulness is limited outside of well known selftests.

Provide ww_mutex_base_lock() which points to the correct function for PREEMPT_RT and non-PREEMPT_RT builds.

Fixes 995279d280d1e ("drm/ttm/tests: Add tests for ttm_bo functions")

---
Repost of https://lore.kernel.org/r/[email protected]

 drivers/gpu/drm/ttm/tests/ttm_bo_test.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/tests/ttm_bo_test.c +7 -1
@@ -18,6 +18,12 @@
 
 #define BO_SIZE		SZ_8K
 
+#ifdef CONFIG_PREEMPT_RT
+#define ww_mutex_base_lock(b)			rt_mutex_lock(b)
+#else
+#define ww_mutex_base_lock(b)			mutex_lock(b)
+#endif
+
 struct ttm_bo_test_case {
 	const char *description;
 	bool interruptible;
@@ -142,7 +148,7 @@ static void ttm_bo_reserve_deadlock(stru
 	bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
 
 	ww_acquire_init(&ctx1, &reservation_ww_class);
-	mutex_lock(&bo2->base.resv->lock.base);
+	ww_mutex_base_lock(&bo2->base.resv->lock.base);
 
 	/* The deadlock will be caught by WW mutex, don't warn about it */
 	lock_release(&bo2->base.resv->lock.base.dep_map, 1);
#1 lore raw

Am 13.06.24 um 08:47 schrieb Sebastian Andrzej Siewior:

Quoted 8 lines

PREEMPT_RT has a different locking implementation for ww_mutex. The base mutex of struct ww_mutex is declared as struct WW_MUTEX_BASE. The latter is defined as mutex' for non-PREEMPT_RT builds and rt_mutex' for PREEMPT_RT builds.

Using mutex_lock() directly on the base mutex in ttm_bo_reserve_deadlock() leads to compile error on PREEMPT_RT.

Quoted 6 lines

The locking-selftest has its own defines to deal with this and it is probably best to defines the needed one within the test program since their usefulness is limited outside of well known selftests.

Provide ww_mutex_base_lock() which points to the correct function for PREEMPT_RT and non-PREEMPT_RT builds.

In general good that somebody is looking into this, but I can't even judge why ww_mutex would use rt_mutex in the first place.

So I don't feel well reviewing this.

Regards,
Christian.

Quoted 33 lines
Fixes 995279d280d1e ("drm/ttm/tests: Add tests for ttm_bo functions")

---
Repost of https://lore.kernel.org/r/[email protected]

  drivers/gpu/drm/ttm/tests/ttm_bo_test.c |    8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/tests/ttm_bo_test.c +7 -1
@@ -18,6 +18,12 @@
 
  #define BO_SIZE		SZ_8K
 
+#ifdef CONFIG_PREEMPT_RT
+#define ww_mutex_base_lock(b)			rt_mutex_lock(b)
+#else
+#define ww_mutex_base_lock(b)			mutex_lock(b)
+#endif
+
  struct ttm_bo_test_case {
  	const char *description;
  	bool interruptible;
@@ -142,7 +148,7 @@ static void ttm_bo_reserve_deadlock(stru
  	bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
 
  	ww_acquire_init(&ctx1, &reservation_ww_class);
-	mutex_lock(&bo2->base.resv->lock.base);
+	ww_mutex_base_lock(&bo2->base.resv->lock.base);
 
  	/* The deadlock will be caught by WW mutex, don't warn about it */
  	lock_release(&bo2->base.resv->lock.base.dep_map, 1);
#2 lore raw
Quoted 5 lines · Christian König
Quoted 2 lines

Provide ww_mutex_base_lock() which points to the correct function for PREEMPT_RT and non-PREEMPT_RT builds.

In general good that somebody is looking into this, but I can't even judge why ww_mutex would use rt_mutex in the first place.

as noted in commit message, this is already done in lib/locking-selftest.c
The base mutex of struct ww_mutex is WW_MUTEX_BASE which is defined as

| #ifndef CONFIG_PREEMPT_RT
| #define WW_MUTEX_BASE mutex
…
| #else
| #define WW_MUTEX_BASE rt_mutex
…
| #endif

this is all in-tree.

Quoted 4 lines

So I don't feel well reviewing this.

Regards,
Christian.

Sebastian