Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dma-buf/selftests: test RCU ops and inline lock v2

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>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://lore.kernel.org/r/20260219160822.1529-6-christian.koenig@amd.com

+10 -34
+10 -34
drivers/dma-buf/st-dma-fence.c
··· 14 14 15 15 #include "selftest.h" 16 16 17 - static struct kmem_cache *slab_fences; 18 - 19 - static struct mock_fence { 20 - struct dma_fence base; 21 - struct spinlock lock; 22 - } *to_mock_fence(struct dma_fence *f) { 23 - return container_of(f, struct mock_fence, base); 24 - } 25 - 26 17 static const char *mock_name(struct dma_fence *f) 27 18 { 28 19 return "mock"; 29 20 } 30 21 31 - static void mock_fence_release(struct dma_fence *f) 32 - { 33 - kmem_cache_free(slab_fences, to_mock_fence(f)); 34 - } 35 - 36 22 static const struct dma_fence_ops mock_ops = { 37 23 .get_driver_name = mock_name, 38 24 .get_timeline_name = mock_name, 39 - .release = mock_fence_release, 40 25 }; 41 26 42 27 static struct dma_fence *mock_fence(void) 43 28 { 44 - struct mock_fence *f; 29 + struct dma_fence *f; 45 30 46 - f = kmem_cache_alloc(slab_fences, GFP_KERNEL); 31 + f = kmalloc(sizeof(*f), GFP_KERNEL); 47 32 if (!f) 48 33 return NULL; 49 34 50 - spin_lock_init(&f->lock); 51 - dma_fence_init(&f->base, &mock_ops, &f->lock, 0, 0); 52 - 53 - return &f->base; 35 + dma_fence_init(f, &mock_ops, NULL, 0, 0); 36 + return f; 54 37 } 55 38 56 39 static int sanitycheck(void *arg) ··· 80 97 81 98 if (!dma_fence_test_signaled_flag(f)) { 82 99 pr_err("Fence reported not being already signaled\n"); 100 + goto err_free; 101 + } 102 + 103 + if (rcu_dereference_protected(f->ops, true)) { 104 + pr_err("Fence ops not cleared on signal\n"); 83 105 goto err_free; 84 106 } 85 107 ··· 528 540 SUBTEST(test_stub), 529 541 SUBTEST(race_signal_callback), 530 542 }; 531 - int ret; 532 543 533 544 pr_info("sizeof(dma_fence)=%zu\n", sizeof(struct dma_fence)); 534 - 535 - slab_fences = KMEM_CACHE(mock_fence, 536 - SLAB_TYPESAFE_BY_RCU | 537 - SLAB_HWCACHE_ALIGN); 538 - if (!slab_fences) 539 - return -ENOMEM; 540 - 541 - ret = subtests(tests, NULL); 542 - 543 - kmem_cache_destroy(slab_fences); 544 - 545 - return ret; 545 + return subtests(tests, NULL); 546 546 }