On 13/01/2026 15:16, Christian König wrote:
Drop the mock_fence and the kmem_cache, instead use the inline lock and test if the ops are properly dropped after signaling.
v2: move the RCU check to the end of the test
Signed-off-by: Christian König christian.koenig@amd.com
drivers/dma-buf/st-dma-fence.c | 44 ++++++++-------------------------- 1 file changed, 10 insertions(+), 34 deletions(-)
diff --git a/drivers/dma-buf/st-dma-fence.c b/drivers/dma-buf/st-dma-fence.c index 5d0d9abc6e21..0d9d524d79b6 100644 --- a/drivers/dma-buf/st-dma-fence.c +++ b/drivers/dma-buf/st-dma-fence.c @@ -14,43 +14,26 @@ #include "selftest.h" -static struct kmem_cache *slab_fences;
-static struct mock_fence {
- struct dma_fence base;
- struct spinlock lock;
-} *to_mock_fence(struct dma_fence *f) {
- return container_of(f, struct mock_fence, base);
-}
- static const char *mock_name(struct dma_fence *f) { return "mock"; }
-static void mock_fence_release(struct dma_fence *f) -{
- kmem_cache_free(slab_fences, to_mock_fence(f));
-}
- static const struct dma_fence_ops mock_ops = { .get_driver_name = mock_name, .get_timeline_name = mock_name,
- .release = mock_fence_release, };
static struct dma_fence *mock_fence(void) {
- struct mock_fence *f;
- struct dma_fence *f;
- f = kmem_cache_alloc(slab_fences, GFP_KERNEL);
- f = kmalloc(sizeof(*f), GFP_KERNEL); if (!f) return NULL;
- spin_lock_init(&f->lock);
- dma_fence_init(&f->base, &mock_ops, &f->lock, 0, 0);
- return &f->base;
- dma_fence_init(f, &mock_ops, NULL, 0, 0);
- return f; }
static int sanitycheck(void *arg) @@ -100,6 +83,11 @@ static int test_signaling(void *arg) goto err_free; }
- if (rcu_dereference_protected(f->ops, true)) {
pr_err("Fence ops not cleared on signal\n");goto err_free;- }
- err = 0; err_free: dma_fence_put(f);
@@ -540,19 +528,7 @@ int dma_fence(void) SUBTEST(test_stub), SUBTEST(race_signal_callback), };
- int ret;
pr_info("sizeof(dma_fence)=%zu\n", sizeof(struct dma_fence));
- slab_fences = KMEM_CACHE(mock_fence,
SLAB_TYPESAFE_BY_RCU |SLAB_HWCACHE_ALIGN);- if (!slab_fences)
return -ENOMEM;- ret = subtests(tests, NULL);
- kmem_cache_destroy(slab_fences);
- return ret;
- return subtests(tests, NULL); }
Reviewed-by: Tvrtko Ursulin tvrtko.ursulin@igalia.com
Regards,
Tvrtko