mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Håkon Bugge" <haakon.bugge@oracle.com>
To: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	John Stultz <jstultz@google.com>
Cc: "Håkon Bugge" <haakon.bugge@oracle.com>,
	"Ingo Molnar" <mingo@kernel.org>
Subject: [PATCH 1/4] test-ww_mutex: Fix module cleanup
Date: Wed, 17 Jun 2026 14:13:30 +0200	[thread overview]
Message-ID: <20260617121335.2036954-2-haakon.bugge@oracle.com> (raw)
In-Reply-To: <20260617121335.2036954-1-haakon.bugge@oracle.com>

When test-ww_mutex is compiled as a module, there are two bugs. One is
related to the case where the module fails to load. In that case, some
or all of the allocated objects are not released. Also, if loaded OK
and thereafter unloaded, the sysfs file is not removed.

The latter bug gives the following splat (trimmed for better brevity):

sysfs: cannot create duplicate filename '/kernel/test_ww_mutex'
 dump_stack_lvl+0x5d/0x90
 sysfs_warn_dup.cold+0x17/0x23
 sysfs_create_dir_ns+0xe2/0x100
 kobject_add_internal+0xba/0x270
 kobject_add+0x95/0xd0
 kobject_create_and_add+0xa3/0xd0
 test_ww_mutex_init+0x90/0xff0 [test_ww_mutex]
 do_one_initcall+0x5c/0x330
 do_init_module+0x90/0x290
 __do_sys_init_module+0x195/0x1d0
 do_syscall_64+0xe8/0x550
 entry_SYSCALL_64_after_hwframe+0x76/0x7e

Fixes: 2a0c11282881 ("locking/ww_mutex: Add kselftests for ww_mutex stress")
Fixes: de2c5a1523fd ("test-ww_mutex: Allow test to be run (and re-run) from userland")
Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com>
---
 kernel/locking/test-ww_mutex.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index 838d631544ed2..6f56a29ed6d77 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -734,7 +734,7 @@ static struct kobject *test_ww_mutex_kobj;
 
 static int __init test_ww_mutex_init(void)
 {
-	int ret;
+	int ret = -ENOMEM;
 
 	prandom_seed_state(&rng, get_random_u64());
 
@@ -743,28 +743,35 @@ static int __init test_ww_mutex_init(void)
 		return -ENOMEM;
 
 	test_ww_mutex_kobj = kobject_create_and_add("test_ww_mutex", kernel_kobj);
-	if (!test_ww_mutex_kobj) {
-		destroy_workqueue(wq);
-		return -ENOMEM;
-	}
+	if (!test_ww_mutex_kobj)
+		goto kobj_err;
 
 	/* Create the files associated with this kobject */
 	ret = sysfs_create_group(test_ww_mutex_kobj, &attr_group);
-	if (ret) {
-		kobject_put(test_ww_mutex_kobj);
-		destroy_workqueue(wq);
-		return ret;
-	}
+	if (ret)
+		goto sysfs_err;
 
 	mutex_lock(&run_lock);
 	ret = run_test_classes();
 	mutex_unlock(&run_lock);
 
+	if (!ret)
+		return 0;
+
+	sysfs_remove_group(test_ww_mutex_kobj, &attr_group);
+
+sysfs_err:
+	kobject_put(test_ww_mutex_kobj);
+
+kobj_err:
+	destroy_workqueue(wq);
+
 	return ret;
 }
 
 static void __exit test_ww_mutex_exit(void)
 {
+	sysfs_remove_group(test_ww_mutex_kobj, &attr_group);
 	kobject_put(test_ww_mutex_kobj);
 	destroy_workqueue(wq);
 }
-- 
2.43.5


  reply	other threads:[~2026-06-17 12:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 12:13 [PATCH 0/4] test-ww_mutex: Miscellaneous fixes Håkon Bugge
2026-06-17 12:13 ` Håkon Bugge [this message]
2026-06-18 17:49   ` [PATCH 1/4] test-ww_mutex: Fix module cleanup John Stultz
2026-06-17 12:13 ` [PATCH 2/4] test-ww_mutex: Report errors from stress workers Håkon Bugge
2026-06-18 17:52   ` John Stultz
2026-07-09  0:03     ` John Stultz
2026-07-09 16:51       ` Haakon Bugge
2026-06-17 12:13 ` [PATCH 3/4] test-ww_mutex: Handle transient -EDEADLK in test_cycle_work Håkon Bugge
2026-06-18 19:04   ` John Stultz
2026-06-22 13:21     ` Haakon Bugge
2026-07-08 19:55       ` John Stultz
2026-07-09 17:05         ` Haakon Bugge
2026-06-17 12:13 ` [PATCH 4/4] test-ww_mutex: Retry lock acquisition after timeout if deadlocked Håkon Bugge
2026-06-18 18:55   ` John Stultz
2026-06-22 13:47     ` Haakon Bugge
2026-07-06  9:01       ` Haakon Bugge
2026-07-06  9:02         ` Haakon Bugge
2026-07-08 20:01       ` John Stultz
2026-07-09 16:56         ` Haakon Bugge

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=20260617121335.2036954-2-haakon.bugge@oracle.com \
    --to=haakon.bugge@oracle.com \
    --cc=boqun@kernel.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /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®