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.

test-ww_mutex: Allow test to be run (and re-run) from userland

In cases where the ww_mutex test was occasionally tripping on
hard to find issues, leaving qemu in a reboot loop was my best
way to reproduce problems. These reboots however wasted time
when I just wanted to run the test-ww_mutex logic.

So tweak the test-ww_mutex test so that it can be re-triggered
via a sysfs file, so the test can be run repeatedly without
doing module loads or restarting.

This has been particularly valuable to stressing and finding
issues with the proxy-exec series.

To use, run as root:
echo 1 > /sys/kernel/test_ww_mutex/run_tests

Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251205013515.759030-4-jstultz@google.com

authored by

John Stultz and committed by
Peter Zijlstra
de2c5a15 d327e716

+49 -2
+49 -2
kernel/locking/test-ww_mutex.c
··· 642 642 return 0; 643 643 } 644 644 645 - static int __init run_tests(struct ww_class *class) 645 + static int run_tests(struct ww_class *class) 646 646 { 647 647 int ncpus = num_online_cpus(); 648 648 int ret, i; ··· 684 684 return 0; 685 685 } 686 686 687 - static int __init run_test_classes(void) 687 + static int run_test_classes(void) 688 688 { 689 689 int ret; 690 690 ··· 703 703 return 0; 704 704 } 705 705 706 + static DEFINE_MUTEX(run_lock); 707 + 708 + static ssize_t run_tests_store(struct kobject *kobj, struct kobj_attribute *attr, 709 + const char *buf, size_t count) 710 + { 711 + if (!mutex_trylock(&run_lock)) { 712 + pr_err("Test already running\n"); 713 + return count; 714 + } 715 + 716 + run_test_classes(); 717 + mutex_unlock(&run_lock); 718 + 719 + return count; 720 + } 721 + 722 + static struct kobj_attribute run_tests_attribute = 723 + __ATTR(run_tests, 0664, NULL, run_tests_store); 724 + 725 + static struct attribute *attrs[] = { 726 + &run_tests_attribute.attr, 727 + NULL, /* need to NULL terminate the list of attributes */ 728 + }; 729 + 730 + static struct attribute_group attr_group = { 731 + .attrs = attrs, 732 + }; 733 + 734 + static struct kobject *test_ww_mutex_kobj; 735 + 706 736 static int __init test_ww_mutex_init(void) 707 737 { 708 738 int ret; ··· 743 713 if (!wq) 744 714 return -ENOMEM; 745 715 716 + test_ww_mutex_kobj = kobject_create_and_add("test_ww_mutex", kernel_kobj); 717 + if (!test_ww_mutex_kobj) { 718 + destroy_workqueue(wq); 719 + return -ENOMEM; 720 + } 721 + 722 + /* Create the files associated with this kobject */ 723 + ret = sysfs_create_group(test_ww_mutex_kobj, &attr_group); 724 + if (ret) { 725 + kobject_put(test_ww_mutex_kobj); 726 + destroy_workqueue(wq); 727 + return ret; 728 + } 729 + 730 + mutex_lock(&run_lock); 746 731 ret = run_test_classes(); 732 + mutex_unlock(&run_lock); 747 733 748 734 return ret; 749 735 } 750 736 751 737 static void __exit test_ww_mutex_exit(void) 752 738 { 739 + kobject_put(test_ww_mutex_kobj); 753 740 destroy_workqueue(wq); 754 741 } 755 742