Re: [PATCH v12 01/10] drm/ttm/tests: Fix a warning in ttm_bo_unreserve_bulk

2024-05-24 Thread Thomas Hellström
On Wed, 2024-05-15 at 13:24 +0200, Karolina Stolarek wrote:
> BOs in a bulk move have to share the same reservation object. That is
> not the case in the ttm_bo_unreserve_bulk subtest. Update
> ttm_bo_kunit_init() helper to accept dma_resv object so we can define
> buffer objects that share the same resv. Update calls to that helper
> accordingly.
> 
> Fixes: 995279d280d1 ("drm/ttm/tests: Add tests for ttm_bo functions")
> Suggested-by: Christian König 
> Signed-off-by: Karolina Stolarek 

Reviewed-by: Thomas Hellström 


> ---
>  drivers/gpu/drm/ttm/tests/ttm_bo_test.c   | 40 +++--
> --
>  drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c |  7 +++-
>  drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h |  3 +-
>  drivers/gpu/drm/ttm/tests/ttm_pool_test.c |  4 +-
>  drivers/gpu/drm/ttm/tests/ttm_resource_test.c |  2 +-
>  drivers/gpu/drm/ttm/tests/ttm_tt_test.c   | 20 +-
>  6 files changed, 45 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
> b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
> index 1f8a4f8adc92..ffcfe5e6709a 100644
> --- a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
> +++ b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
> @@ -56,7 +56,7 @@ static void
> ttm_bo_reserve_optimistic_no_ticket(struct kunit *test)
>   struct ttm_buffer_object *bo;
>   int err;
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>  
>   err = ttm_bo_reserve(bo, params->interruptible, params-
> >no_wait, NULL);
>   KUNIT_ASSERT_EQ(test, err, 0);
> @@ -71,7 +71,7 @@ static void ttm_bo_reserve_locked_no_sleep(struct
> kunit *test)
>   bool no_wait = true;
>   int err;
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>  
>   /* Let's lock it beforehand */
>   dma_resv_lock(bo->base.resv, NULL);
> @@ -92,7 +92,7 @@ static void ttm_bo_reserve_no_wait_ticket(struct
> kunit *test)
>  
>   ww_acquire_init(, _ww_class);
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>  
>   err = ttm_bo_reserve(bo, interruptible, no_wait, );
>   KUNIT_ASSERT_EQ(test, err, -EBUSY);
> @@ -110,7 +110,7 @@ static void ttm_bo_reserve_double_resv(struct
> kunit *test)
>  
>   ww_acquire_init(, _ww_class);
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>  
>   err = ttm_bo_reserve(bo, interruptible, no_wait, );
>   KUNIT_ASSERT_EQ(test, err, 0);
> @@ -138,8 +138,8 @@ static void ttm_bo_reserve_deadlock(struct kunit
> *test)
>   bool no_wait = false;
>   int err;
>  
> - bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> - bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
> + bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>  
>   ww_acquire_init(, _ww_class);
>   mutex_lock(>base.resv->lock.base);
> @@ -208,7 +208,7 @@ static void ttm_bo_reserve_interrupted(struct
> kunit *test)
>   struct task_struct *task;
>   int err;
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>  
>   task = kthread_create(threaded_ttm_bo_reserve, bo, "ttm-bo-
> reserve");
>  
> @@ -249,7 +249,7 @@ static void ttm_bo_unreserve_basic(struct kunit
> *test)
>   KUNIT_ASSERT_EQ(test, err, 0);
>   priv->ttm_dev = ttm_dev;
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>   bo->priority = bo_prio;
>  
>   err = ttm_resource_alloc(bo, place, );
> @@ -288,7 +288,7 @@ static void ttm_bo_unreserve_pinned(struct kunit
> *test)
>   KUNIT_ASSERT_EQ(test, err, 0);
>   priv->ttm_dev = ttm_dev;
>  
> - bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
> + bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
>   place = ttm_place_kunit_init(test, mem_type, 0);
>  
>   dma_resv_lock(bo->base.resv, NULL);
> @@ -321,6 +321,7 @@ static void ttm_bo_unreserve_bulk(struct kunit
> *test)
>   struct ttm_resource *res1, *res2;
>   struct ttm_device *ttm_dev;
>   struct ttm_place *place;
> + struct dma_resv *resv;
>   uint32_t mem_type = TTM_PL_SYSTEM;
>   unsigned int bo_priority = 0;
>   int err;
> @@ -332,12 +333,17 @@ static void ttm_bo_unreserve_bulk(struct kunit
> *test)
>   ttm_dev = kunit_kzalloc(test, sizeof(*ttm_dev), GFP_KERNEL);
>   KUNIT_ASSERT_NOT_NULL(test, ttm_dev);
>  
> + resv = kunit_kzalloc(test, sizeof(*resv), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, ttm_dev);
> +
>   err = ttm_device_kunit_init(priv, ttm_dev, false, false);
>   KUNIT_ASSERT_EQ(test, err, 0);
>   priv->ttm_dev = ttm_dev;
> 

[PATCH v12 01/10] drm/ttm/tests: Fix a warning in ttm_bo_unreserve_bulk

2024-05-15 Thread Karolina Stolarek
BOs in a bulk move have to share the same reservation object. That is
not the case in the ttm_bo_unreserve_bulk subtest. Update
ttm_bo_kunit_init() helper to accept dma_resv object so we can define
buffer objects that share the same resv. Update calls to that helper
accordingly.

Fixes: 995279d280d1 ("drm/ttm/tests: Add tests for ttm_bo functions")
Suggested-by: Christian König 
Signed-off-by: Karolina Stolarek 
---
 drivers/gpu/drm/ttm/tests/ttm_bo_test.c   | 40 +++
 drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.c |  7 +++-
 drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h |  3 +-
 drivers/gpu/drm/ttm/tests/ttm_pool_test.c |  4 +-
 drivers/gpu/drm/ttm/tests/ttm_resource_test.c |  2 +-
 drivers/gpu/drm/ttm/tests/ttm_tt_test.c   | 20 +-
 6 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c 
b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
index 1f8a4f8adc92..ffcfe5e6709a 100644
--- a/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
+++ b/drivers/gpu/drm/ttm/tests/ttm_bo_test.c
@@ -56,7 +56,7 @@ static void ttm_bo_reserve_optimistic_no_ticket(struct kunit 
*test)
struct ttm_buffer_object *bo;
int err;
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
 
err = ttm_bo_reserve(bo, params->interruptible, params->no_wait, NULL);
KUNIT_ASSERT_EQ(test, err, 0);
@@ -71,7 +71,7 @@ static void ttm_bo_reserve_locked_no_sleep(struct kunit *test)
bool no_wait = true;
int err;
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
 
/* Let's lock it beforehand */
dma_resv_lock(bo->base.resv, NULL);
@@ -92,7 +92,7 @@ static void ttm_bo_reserve_no_wait_ticket(struct kunit *test)
 
ww_acquire_init(, _ww_class);
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
 
err = ttm_bo_reserve(bo, interruptible, no_wait, );
KUNIT_ASSERT_EQ(test, err, -EBUSY);
@@ -110,7 +110,7 @@ static void ttm_bo_reserve_double_resv(struct kunit *test)
 
ww_acquire_init(, _ww_class);
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
 
err = ttm_bo_reserve(bo, interruptible, no_wait, );
KUNIT_ASSERT_EQ(test, err, 0);
@@ -138,8 +138,8 @@ static void ttm_bo_reserve_deadlock(struct kunit *test)
bool no_wait = false;
int err;
 
-   bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
-   bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
+   bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
 
ww_acquire_init(, _ww_class);
mutex_lock(>base.resv->lock.base);
@@ -208,7 +208,7 @@ static void ttm_bo_reserve_interrupted(struct kunit *test)
struct task_struct *task;
int err;
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
 
task = kthread_create(threaded_ttm_bo_reserve, bo, "ttm-bo-reserve");
 
@@ -249,7 +249,7 @@ static void ttm_bo_unreserve_basic(struct kunit *test)
KUNIT_ASSERT_EQ(test, err, 0);
priv->ttm_dev = ttm_dev;
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
bo->priority = bo_prio;
 
err = ttm_resource_alloc(bo, place, );
@@ -288,7 +288,7 @@ static void ttm_bo_unreserve_pinned(struct kunit *test)
KUNIT_ASSERT_EQ(test, err, 0);
priv->ttm_dev = ttm_dev;
 
-   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);
place = ttm_place_kunit_init(test, mem_type, 0);
 
dma_resv_lock(bo->base.resv, NULL);
@@ -321,6 +321,7 @@ static void ttm_bo_unreserve_bulk(struct kunit *test)
struct ttm_resource *res1, *res2;
struct ttm_device *ttm_dev;
struct ttm_place *place;
+   struct dma_resv *resv;
uint32_t mem_type = TTM_PL_SYSTEM;
unsigned int bo_priority = 0;
int err;
@@ -332,12 +333,17 @@ static void ttm_bo_unreserve_bulk(struct kunit *test)
ttm_dev = kunit_kzalloc(test, sizeof(*ttm_dev), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, ttm_dev);
 
+   resv = kunit_kzalloc(test, sizeof(*resv), GFP_KERNEL);
+   KUNIT_ASSERT_NOT_NULL(test, ttm_dev);
+
err = ttm_device_kunit_init(priv, ttm_dev, false, false);
KUNIT_ASSERT_EQ(test, err, 0);
priv->ttm_dev = ttm_dev;
 
-   bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
-   bo2 = ttm_bo_kunit_init(test, test->priv, BO_SIZE);
+   dma_resv_init(resv);
+
+   bo1 = ttm_bo_kunit_init(test, test->priv, BO_SIZE, resv);
+   bo2