From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: thomas.hellstrom@linux.intel.com, dakr@kernel.org,
ecourtney@nvidia.com, simona@ffwll.ch, matthew.brost@intel.com,
nat@pixelcluster.dev, airlied@gmail.com,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org
Subject: [PATCH 02/12] dma-buf/tests: Convert st-dma-resv tests to use dma_resv_alloc
Date: Fri, 10 Jul 2026 20:52:42 +0200 [thread overview]
Message-ID: <20260710190752.2355-3-christian.koenig@amd.com> (raw)
In-Reply-To: <20260710190752.2355-1-christian.koenig@amd.com>
Update all test cases in st-dma-resv.c to use the new dma_resv_alloc()
API instead of stack-allocating dma_resv objects. This demonstrates the
proper usage of the new allocation and reference counting interface.
All five test functions now:
- Use dma_resv_alloc() to allocate objects
- Check for allocation failure with KUNIT_ASSERT_NOT_NULL
- Clean up with dma_resv_put() which handles freeing
This change also provides better test coverage for the reference
counting implementation.
Signed-off-by: Christian König <christian.koenig@amd.com>
Assisted-by: Claude:Sonnet 4
---
drivers/dma-buf/st-dma-resv.c | 90 +++++++++++++++++++----------------
1 file changed, 50 insertions(+), 40 deletions(-)
diff --git a/drivers/dma-buf/st-dma-resv.c b/drivers/dma-buf/st-dma-resv.c
index 2c43d2d2b0169..b843d90417822 100644
--- a/drivers/dma-buf/st-dma-resv.c
+++ b/drivers/dma-buf/st-dma-resv.c
@@ -41,7 +41,7 @@ static struct dma_fence *alloc_fence(void)
static void test_sanitycheck(struct kunit *test)
{
- struct dma_resv resv;
+ struct dma_resv *resv;
struct dma_fence *f;
int r;
@@ -53,20 +53,22 @@ static void test_sanitycheck(struct kunit *test)
dma_fence_signal(f);
dma_fence_put(f);
- dma_resv_init(&resv);
- r = dma_resv_lock(&resv, NULL);
+ resv = dma_resv_alloc();
+ KUNIT_ASSERT_NOT_NULL(test, resv);
+
+ r = dma_resv_lock(resv, NULL);
if (r)
KUNIT_FAIL(test, "Resv locking failed\n");
else
- dma_resv_unlock(&resv);
- dma_resv_put(&resv);
+ dma_resv_unlock(resv);
+ dma_resv_put(resv);
}
static void test_signaling(struct kunit *test)
{
const struct dma_resv_usage_param *param = test->param_value;
enum dma_resv_usage usage = param->usage;
- struct dma_resv resv;
+ struct dma_resv *resv;
struct dma_fence *f;
int r;
@@ -75,33 +77,35 @@ static void test_signaling(struct kunit *test)
dma_fence_enable_signaling(f);
- dma_resv_init(&resv);
- r = dma_resv_lock(&resv, NULL);
+ resv = dma_resv_alloc();
+ KUNIT_ASSERT_NOT_NULL(test, resv);
+
+ r = dma_resv_lock(resv, NULL);
if (r) {
KUNIT_FAIL(test, "Resv locking failed");
goto err_free;
}
- r = dma_resv_reserve_fences(&resv, 1);
+ r = dma_resv_reserve_fences(resv, 1);
if (r) {
KUNIT_FAIL(test, "Resv shared slot allocation failed");
goto err_unlock;
}
- dma_resv_add_fence(&resv, f, usage);
- if (dma_resv_test_signaled(&resv, usage)) {
+ dma_resv_add_fence(resv, f, usage);
+ if (dma_resv_test_signaled(resv, usage)) {
KUNIT_FAIL(test, "Resv unexpectedly signaled");
goto err_unlock;
}
dma_fence_signal(f);
- if (!dma_resv_test_signaled(&resv, usage)) {
+ if (!dma_resv_test_signaled(resv, usage)) {
KUNIT_FAIL(test, "Resv not reporting signaled");
goto err_unlock;
}
err_unlock:
- dma_resv_unlock(&resv);
+ dma_resv_unlock(resv);
err_free:
- dma_resv_put(&resv);
+ dma_resv_put(resv);
dma_fence_put(f);
}
@@ -111,7 +115,7 @@ static void test_for_each(struct kunit *test)
enum dma_resv_usage usage = param->usage;
struct dma_resv_iter cursor;
struct dma_fence *f, *fence;
- struct dma_resv resv;
+ struct dma_resv *resv;
int r;
f = alloc_fence();
@@ -119,23 +123,25 @@ static void test_for_each(struct kunit *test)
dma_fence_enable_signaling(f);
- dma_resv_init(&resv);
- r = dma_resv_lock(&resv, NULL);
+ resv = dma_resv_alloc();
+ KUNIT_ASSERT_NOT_NULL(test, resv);
+
+ r = dma_resv_lock(resv, NULL);
if (r) {
KUNIT_FAIL(test, "Resv locking failed");
goto err_free;
}
- r = dma_resv_reserve_fences(&resv, 1);
+ r = dma_resv_reserve_fences(resv, 1);
if (r) {
KUNIT_FAIL(test, "Resv shared slot allocation failed");
goto err_unlock;
}
- dma_resv_add_fence(&resv, f, usage);
+ dma_resv_add_fence(resv, f, usage);
r = -ENOENT;
- dma_resv_for_each_fence(&cursor, &resv, usage, fence) {
+ dma_resv_for_each_fence(&cursor, resv, usage, fence) {
if (!r) {
KUNIT_FAIL(test, "More than one fence found");
goto err_unlock;
@@ -158,9 +164,9 @@ static void test_for_each(struct kunit *test)
}
dma_fence_signal(f);
err_unlock:
- dma_resv_unlock(&resv);
+ dma_resv_unlock(resv);
err_free:
- dma_resv_put(&resv);
+ dma_resv_put(resv);
dma_fence_put(f);
}
@@ -170,7 +176,7 @@ static void test_for_each_unlocked(struct kunit *test)
enum dma_resv_usage usage = param->usage;
struct dma_resv_iter cursor;
struct dma_fence *f, *fence;
- struct dma_resv resv;
+ struct dma_resv *resv;
int r;
f = alloc_fence();
@@ -178,25 +184,27 @@ static void test_for_each_unlocked(struct kunit *test)
dma_fence_enable_signaling(f);
- dma_resv_init(&resv);
- r = dma_resv_lock(&resv, NULL);
+ resv = dma_resv_alloc();
+ KUNIT_ASSERT_NOT_NULL(test, resv);
+
+ r = dma_resv_lock(resv, NULL);
if (r) {
KUNIT_FAIL(test, "Resv locking failed");
goto err_free;
}
- r = dma_resv_reserve_fences(&resv, 1);
+ r = dma_resv_reserve_fences(resv, 1);
if (r) {
KUNIT_FAIL(test, "Resv shared slot allocation failed");
- dma_resv_unlock(&resv);
+ dma_resv_unlock(resv);
goto err_free;
}
- dma_resv_add_fence(&resv, f, usage);
- dma_resv_unlock(&resv);
+ dma_resv_add_fence(resv, f, usage);
+ dma_resv_unlock(resv);
r = -ENOENT;
- dma_resv_iter_begin(&cursor, &resv, usage);
+ dma_resv_iter_begin(&cursor, resv, usage);
dma_resv_for_each_fence_unlocked(&cursor, fence) {
if (!r) {
KUNIT_FAIL(test, "More than one fence found");
@@ -231,7 +239,7 @@ static void test_for_each_unlocked(struct kunit *test)
dma_resv_iter_end(&cursor);
dma_fence_signal(f);
err_free:
- dma_resv_put(&resv);
+ dma_resv_put(resv);
dma_fence_put(f);
}
@@ -240,7 +248,7 @@ static void test_get_fences(struct kunit *test)
const struct dma_resv_usage_param *param = test->param_value;
enum dma_resv_usage usage = param->usage;
struct dma_fence *f, **fences = NULL;
- struct dma_resv resv;
+ struct dma_resv *resv;
int r, i;
f = alloc_fence();
@@ -248,24 +256,26 @@ static void test_get_fences(struct kunit *test)
dma_fence_enable_signaling(f);
- dma_resv_init(&resv);
- r = dma_resv_lock(&resv, NULL);
+ resv = dma_resv_alloc();
+ KUNIT_ASSERT_NOT_NULL(test, resv);
+
+ r = dma_resv_lock(resv, NULL);
if (r) {
KUNIT_FAIL(test, "Resv locking failed");
goto err_resv;
}
- r = dma_resv_reserve_fences(&resv, 1);
+ r = dma_resv_reserve_fences(resv, 1);
if (r) {
KUNIT_FAIL(test, "Resv shared slot allocation failed");
- dma_resv_unlock(&resv);
+ dma_resv_unlock(resv);
goto err_resv;
}
- dma_resv_add_fence(&resv, f, usage);
- dma_resv_unlock(&resv);
+ dma_resv_add_fence(resv, f, usage);
+ dma_resv_unlock(resv);
- r = dma_resv_get_fences(&resv, usage, &i, &fences);
+ r = dma_resv_get_fences(resv, usage, &i, &fences);
if (r) {
KUNIT_FAIL(test, "get_fences failed");
goto err_free;
@@ -282,7 +292,7 @@ static void test_get_fences(struct kunit *test)
dma_fence_put(fences[i]);
kfree(fences);
err_resv:
- dma_resv_put(&resv);
+ dma_resv_put(resv);
dma_fence_put(f);
}
--
2.43.0
next prev parent reply other threads:[~2026-07-10 19:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 18:52 Refcounting dma_resv and using that for drm_exec support in TTM Christian König
2026-07-10 18:52 ` [PATCH 01/12] dma-buf: Add reference counting to dma_resv Christian König
2026-07-11 1:27 ` Matthew Brost
2026-07-11 13:10 ` Danilo Krummrich
2026-07-12 19:51 ` Matthew Brost
2026-07-13 9:25 ` Christian König
2026-07-13 14:57 ` Matthew Brost
2026-07-10 18:52 ` Christian König [this message]
2026-07-10 18:52 ` [PATCH 03/12] drm/gem: Add helper for drm_gem_object resv assignment Christian König
2026-07-10 18:52 ` [PATCH 04/12] drm/ttm: Switch LRU cursor to track dma_resv instead of buffer objects Christian König
2026-07-13 13:40 ` Thomas Hellström
2026-07-13 15:15 ` Matthew Brost
2026-07-10 18:52 ` [PATCH 05/12] drm/ttm: switch to ttm_bo_lru_for_each_reserved_guarded for swapout Christian König
2026-07-10 18:52 ` [PATCH 06/12] drm/ttm: move delete handling into ttm_bo_evict Christian König
2026-07-10 18:52 ` [PATCH 07/12] drm/ttm: use ttm_bo_lru_for_each_reserved_guarded in evict_all Christian König
2026-07-10 18:52 ` [PATCH 08/12] drm/ttm: use dma_resv reference in ttm_device_clear_lru_dma_mappings Christian König
2026-07-10 18:52 ` [PATCH 09/12] drm/ttm: nuke buffer refcounting Christian König
2026-07-11 13:26 ` Danilo Krummrich
2026-07-13 15:06 ` Matthew Brost
2026-07-10 18:52 ` [PATCH 10/12] drm/exec: add drm_exec_lock_resv function Christian König
2026-07-13 11:57 ` Thomas Hellström
2026-07-13 12:07 ` Christian König
2026-07-13 12:19 ` Thomas Hellström
2026-07-13 13:14 ` Christian König
2026-07-13 13:37 ` Thomas Hellström
2026-07-10 18:52 ` [PATCH 11/12] drm/ttm: support using drm_exec during eviction v4 Christian König
2026-07-13 11:59 ` Thomas Hellström
2026-07-10 18:52 ` [PATCH 12/12] drm/amdgpu: use drm_exec during BO validation Christian König
2026-07-13 11:32 ` Refcounting dma_resv and using that for drm_exec support in TTM Thomas Hellström
2026-07-13 15:03 ` Matthew Brost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260710190752.2355-3-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=airlied@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.brost@intel.com \
--cc=nat@pixelcluster.dev \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®