dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/ttm: fix locking in test ttm_bo_validate_no_placement_signaled
@ 2025-07-10 14:41 Christian König
  2025-07-10 14:41 ` [PATCH 2/2] drm/ttm: remove ttm_bo_validate_swapout test Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2025-07-10 14:41 UTC (permalink / raw)
  To: matthew.brost, thomas.hellstrom, dri-devel, intel-xe

The test works even without it, but lockdep starts screaming when it is
activated.

Trivially fix it by acquiring the lock before we try to allocate
something.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
index 3148f5d3dbd6..38f476787302 100644
--- a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
+++ b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
@@ -542,14 +542,15 @@ static void ttm_bo_validate_no_placement_signaled(struct kunit *test)
 		bo->ttm = old_tt;
 	}
 
-	err = ttm_resource_alloc(bo, place, &bo->resource, NULL);
-	KUNIT_EXPECT_EQ(test, err, 0);
-	KUNIT_ASSERT_EQ(test, man->usage, size);
-
 	placement = kunit_kzalloc(test, sizeof(*placement), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, placement);
 
 	ttm_bo_reserve(bo, false, false, NULL);
+
+	err = ttm_resource_alloc(bo, place, &bo->resource, NULL);
+	KUNIT_EXPECT_EQ(test, err, 0);
+	KUNIT_ASSERT_EQ(test, man->usage, size);
+
 	err = ttm_bo_validate(bo, placement, &ctx);
 	ttm_bo_unreserve(bo);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm/ttm: remove ttm_bo_validate_swapout test
  2025-07-10 14:41 [PATCH 1/2] drm/ttm: fix locking in test ttm_bo_validate_no_placement_signaled Christian König
@ 2025-07-10 14:41 ` Christian König
  2025-07-10 18:13   ` Matthew Brost
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2025-07-10 14:41 UTC (permalink / raw)
  To: matthew.brost, thomas.hellstrom, dri-devel, intel-xe

The test is quite fragile since it tries to allocate halve available system
memory + 1 page.

If the system has either not enough memory to make the allocation work
with other things running in parallel or to much memory so the allocation
fails as to large/invalid the test won't fail.

Completely remove the test. We already validate swapout on the device
level and that test seems to be stable.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 .../gpu/drm/ttm/tests/ttm_bo_validate_test.c  | 51 -------------------
 1 file changed, 51 deletions(-)

diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
index 38f476787302..1bcc67977f48 100644
--- a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
+++ b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
@@ -758,56 +758,6 @@ static void ttm_bo_validate_move_fence_not_signaled(struct kunit *test)
 	ttm_mock_manager_fini(priv->ttm_dev, snd_mem);
 }
 
-static void ttm_bo_validate_swapout(struct kunit *test)
-{
-	unsigned long size_big, size = ALIGN(BO_SIZE, PAGE_SIZE);
-	enum ttm_bo_type bo_type = ttm_bo_type_device;
-	struct ttm_buffer_object *bo_small, *bo_big;
-	struct ttm_test_devices *priv = test->priv;
-	struct ttm_operation_ctx ctx = { };
-	struct ttm_placement *placement;
-	u32 mem_type = TTM_PL_TT;
-	struct ttm_place *place;
-	struct sysinfo si;
-	int err;
-
-	si_meminfo(&si);
-	size_big = ALIGN(((u64)si.totalram * si.mem_unit / 2), PAGE_SIZE);
-
-	ttm_mock_manager_init(priv->ttm_dev, mem_type, size_big + size);
-
-	place = ttm_place_kunit_init(test, mem_type, 0);
-	placement = ttm_placement_kunit_init(test, place, 1);
-
-	bo_small = kunit_kzalloc(test, sizeof(*bo_small), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, bo_small);
-
-	drm_gem_private_object_init(priv->drm, &bo_small->base, size);
-
-	err = ttm_bo_init_reserved(priv->ttm_dev, bo_small, bo_type, placement,
-				   PAGE_SIZE, &ctx, NULL, NULL,
-				   &dummy_ttm_bo_destroy);
-	KUNIT_EXPECT_EQ(test, err, 0);
-	dma_resv_unlock(bo_small->base.resv);
-
-	bo_big = ttm_bo_kunit_init(test, priv, size_big, NULL);
-
-	dma_resv_lock(bo_big->base.resv, NULL);
-	err = ttm_bo_validate(bo_big, placement, &ctx);
-	dma_resv_unlock(bo_big->base.resv);
-
-	KUNIT_EXPECT_EQ(test, err, 0);
-	KUNIT_EXPECT_NOT_NULL(test, bo_big->resource);
-	KUNIT_EXPECT_EQ(test, bo_big->resource->mem_type, mem_type);
-	KUNIT_EXPECT_EQ(test, bo_small->resource->mem_type, TTM_PL_SYSTEM);
-	KUNIT_EXPECT_TRUE(test, bo_small->ttm->page_flags & TTM_TT_FLAG_SWAPPED);
-
-	ttm_bo_put(bo_big);
-	ttm_bo_put(bo_small);
-
-	ttm_mock_manager_fini(priv->ttm_dev, mem_type);
-}
-
 static void ttm_bo_validate_happy_evict(struct kunit *test)
 {
 	u32 mem_type = TTM_PL_VRAM, mem_multihop = TTM_PL_TT,
@@ -1202,7 +1152,6 @@ static struct kunit_case ttm_bo_validate_test_cases[] = {
 	KUNIT_CASE(ttm_bo_validate_move_fence_signaled),
 	KUNIT_CASE_PARAM(ttm_bo_validate_move_fence_not_signaled,
 			 ttm_bo_validate_wait_gen_params),
-	KUNIT_CASE(ttm_bo_validate_swapout),
 	KUNIT_CASE(ttm_bo_validate_happy_evict),
 	KUNIT_CASE(ttm_bo_validate_all_pinned_evict),
 	KUNIT_CASE(ttm_bo_validate_allowed_only_evict),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] drm/ttm: remove ttm_bo_validate_swapout test
  2025-07-10 14:41 ` [PATCH 2/2] drm/ttm: remove ttm_bo_validate_swapout test Christian König
@ 2025-07-10 18:13   ` Matthew Brost
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Brost @ 2025-07-10 18:13 UTC (permalink / raw)
  To: Christian König; +Cc: thomas.hellstrom, dri-devel, intel-xe

On Thu, Jul 10, 2025 at 04:41:29PM +0200, Christian König wrote:
> The test is quite fragile since it tries to allocate halve available system
> memory + 1 page.
> 
> If the system has either not enough memory to make the allocation work
> with other things running in parallel or to much memory so the allocation
> fails as to large/invalid the test won't fail.
> 
> Completely remove the test. We already validate swapout on the device
> level and that test seems to be stable.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

The first patch in series in nowhere to be found in my inbox, but feel
free to add RB to that patch as well.

Matt 

> ---
>  .../gpu/drm/ttm/tests/ttm_bo_validate_test.c  | 51 -------------------
>  1 file changed, 51 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
> index 38f476787302..1bcc67977f48 100644
> --- a/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
> +++ b/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
> @@ -758,56 +758,6 @@ static void ttm_bo_validate_move_fence_not_signaled(struct kunit *test)
>  	ttm_mock_manager_fini(priv->ttm_dev, snd_mem);
>  }
>  
> -static void ttm_bo_validate_swapout(struct kunit *test)
> -{
> -	unsigned long size_big, size = ALIGN(BO_SIZE, PAGE_SIZE);
> -	enum ttm_bo_type bo_type = ttm_bo_type_device;
> -	struct ttm_buffer_object *bo_small, *bo_big;
> -	struct ttm_test_devices *priv = test->priv;
> -	struct ttm_operation_ctx ctx = { };
> -	struct ttm_placement *placement;
> -	u32 mem_type = TTM_PL_TT;
> -	struct ttm_place *place;
> -	struct sysinfo si;
> -	int err;
> -
> -	si_meminfo(&si);
> -	size_big = ALIGN(((u64)si.totalram * si.mem_unit / 2), PAGE_SIZE);
> -
> -	ttm_mock_manager_init(priv->ttm_dev, mem_type, size_big + size);
> -
> -	place = ttm_place_kunit_init(test, mem_type, 0);
> -	placement = ttm_placement_kunit_init(test, place, 1);
> -
> -	bo_small = kunit_kzalloc(test, sizeof(*bo_small), GFP_KERNEL);
> -	KUNIT_ASSERT_NOT_NULL(test, bo_small);
> -
> -	drm_gem_private_object_init(priv->drm, &bo_small->base, size);
> -
> -	err = ttm_bo_init_reserved(priv->ttm_dev, bo_small, bo_type, placement,
> -				   PAGE_SIZE, &ctx, NULL, NULL,
> -				   &dummy_ttm_bo_destroy);
> -	KUNIT_EXPECT_EQ(test, err, 0);
> -	dma_resv_unlock(bo_small->base.resv);
> -
> -	bo_big = ttm_bo_kunit_init(test, priv, size_big, NULL);
> -
> -	dma_resv_lock(bo_big->base.resv, NULL);
> -	err = ttm_bo_validate(bo_big, placement, &ctx);
> -	dma_resv_unlock(bo_big->base.resv);
> -
> -	KUNIT_EXPECT_EQ(test, err, 0);
> -	KUNIT_EXPECT_NOT_NULL(test, bo_big->resource);
> -	KUNIT_EXPECT_EQ(test, bo_big->resource->mem_type, mem_type);
> -	KUNIT_EXPECT_EQ(test, bo_small->resource->mem_type, TTM_PL_SYSTEM);
> -	KUNIT_EXPECT_TRUE(test, bo_small->ttm->page_flags & TTM_TT_FLAG_SWAPPED);
> -
> -	ttm_bo_put(bo_big);
> -	ttm_bo_put(bo_small);
> -
> -	ttm_mock_manager_fini(priv->ttm_dev, mem_type);
> -}
> -
>  static void ttm_bo_validate_happy_evict(struct kunit *test)
>  {
>  	u32 mem_type = TTM_PL_VRAM, mem_multihop = TTM_PL_TT,
> @@ -1202,7 +1152,6 @@ static struct kunit_case ttm_bo_validate_test_cases[] = {
>  	KUNIT_CASE(ttm_bo_validate_move_fence_signaled),
>  	KUNIT_CASE_PARAM(ttm_bo_validate_move_fence_not_signaled,
>  			 ttm_bo_validate_wait_gen_params),
> -	KUNIT_CASE(ttm_bo_validate_swapout),
>  	KUNIT_CASE(ttm_bo_validate_happy_evict),
>  	KUNIT_CASE(ttm_bo_validate_all_pinned_evict),
>  	KUNIT_CASE(ttm_bo_validate_allowed_only_evict),
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-10 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-10 14:41 [PATCH 1/2] drm/ttm: fix locking in test ttm_bo_validate_no_placement_signaled Christian König
2025-07-10 14:41 ` [PATCH 2/2] drm/ttm: remove ttm_bo_validate_swapout test Christian König
2025-07-10 18:13   ` Matthew Brost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).