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.

locking/lockdep: Add a test for lockdep_set_subclass()

Add a test case to ensure that no new name string literal will be
created in lockdep_set_subclass(), otherwise a warning will be triggered
in look_up_lock_class(). Add this to catch the problem in the future.

[boqun: Reword the title, replace #if with #ifdef and rename functions
and variables]

Signed-off-by: Ahmed Ehab <bottaawesome633@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/lkml/20240905011220.356973-1-bottaawesome633@gmail.com/

authored by

Ahmed Ehab and committed by
Boqun Feng
5eadeb7b d7fe143c

+39
+39
lib/locking-selftest.c
··· 2710 2710 2711 2711 } 2712 2712 2713 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 2714 + static inline const char *rw_semaphore_lockdep_name(struct rw_semaphore *rwsem) 2715 + { 2716 + return rwsem->dep_map.name; 2717 + } 2718 + #else 2719 + static inline const char *rw_semaphore_lockdep_name(struct rw_semaphore *rwsem) 2720 + { 2721 + return NULL; 2722 + } 2723 + #endif 2724 + 2725 + static void test_lockdep_set_subclass_name(void) 2726 + { 2727 + const char *name_before = rw_semaphore_lockdep_name(&rwsem_X1); 2728 + const char *name_after; 2729 + 2730 + lockdep_set_subclass(&rwsem_X1, 1); 2731 + name_after = rw_semaphore_lockdep_name(&rwsem_X1); 2732 + DEBUG_LOCKS_WARN_ON(name_before != name_after); 2733 + } 2734 + 2735 + /* 2736 + * lockdep_set_subclass() should reuse the existing lock class name instead 2737 + * of creating a new one. 2738 + */ 2739 + static void lockdep_set_subclass_name_test(void) 2740 + { 2741 + printk(" --------------------------------------------------------------------------\n"); 2742 + printk(" | lockdep_set_subclass() name test|\n"); 2743 + printk(" -----------------------------------\n"); 2744 + 2745 + print_testname("compare name before and after"); 2746 + dotest(test_lockdep_set_subclass_name, SUCCESS, LOCKTYPE_RWSEM); 2747 + pr_cont("\n"); 2748 + } 2749 + 2713 2750 static void local_lock_tests(void) 2714 2751 { 2715 2752 printk(" --------------------------------------------------------------------------\n"); ··· 2956 2919 print_testname("hardirq_unsafe_softirq_safe"); 2957 2920 dotest(hardirq_deadlock_softirq_not_deadlock, FAILURE, LOCKTYPE_SPECIAL); 2958 2921 pr_cont("\n"); 2922 + 2923 + lockdep_set_subclass_name_test(); 2959 2924 2960 2925 if (unexpected_testcase_failures) { 2961 2926 printk("-----------------------------------------------------------------\n");