From nobody Wed Sep 30 17:08:57 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E794F417D99 for ; Sat, 8 Aug 2026 13:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786194165; cv=none; b=nSKzFgla1hH5gBkGILXFsis2/a99hQ3HC6/nn2dEUXj+By071F7GxdibPyjf8FdALW51B00oslT2X6Jet5uIBwSEkdEVywRL0uQ42zDMAunQMUyn1AHN5oXHDcJ71PKAlfFKCKPCf465xwVmaPWPRI5PneFcJUVVBljEvs1Fwyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786194165; c=relaxed/simple; bh=Fz8uUuJuZicLOuefarTv8QYWKTzU19sc/T7t7JLcAKk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h6XZIK0IBJZgHunoGknyp5QcNGmlTYSswe+PTFRPMXEeUBHjvkH2K+JQsHXOodgs1h4F7X2tTQ/0CWlLJHDbKMq21bf98TgxNfDsuGthA4K80gG1iWPaqndcVTQN5WdE6uzeGtZ70Wzo+gTyrqDAOdLTf96Ec+uRIVmzIdvhTds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RQtpOGVl; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RQtpOGVl" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2cca0c5799eso4281325ad.0 for ; Sat, 08 Aug 2026 06:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786194160; x=1786798960; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DcsQzzuEG+9D2g/tQc/6AnTj5eKcDL5LL0P3pegqw9k=; b=RQtpOGVldfkKO3DRzx36FTKKajNjnouAEVvk9HtGSFvQlWBRRWl47xy/NuYjM2npis hEHnfYF+Qp02vc2btYr/Qoos2hEr0ba57OVNUhMx1h3Vq+KfhWtnfwFvd+SR11dDimGe M7g3/6J6HxXnFt43Zzj4/qKEnc3ycpqR225FTZE/Lsu+illCxD9Uj+YwFRvsci2y3nlo P4Br6iGP9tSHDNEwwSleqcLOwjhqK2jjd5+qRq9Q+U0gXBQNDZplEe76LEbArQL4aUVm +0dw2v+Tc69sRB6Gw3qvyIxJe6vFDDZwNjpDduqnRYF822JnEkDVlmnMF9jkbJLo6R5F KWcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786194160; x=1786798960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=DcsQzzuEG+9D2g/tQc/6AnTj5eKcDL5LL0P3pegqw9k=; b=ls5AFIMz2Ueq3xhPMRoO3XIpPiIlHzvXYFQ0yGtpa+stig7gNcqB42Xw4I6eIU3WMs Am0SmpWdBB54MsNMVVXaQpK2rpw97ZJ8lzYdLNi8HKzXpy/b0OwADCk3AQR/m5xXwJi2 NNJgGWqZuAjbZi2LuFNE7KJHg7/ity/cYRu07y32qQXsC3IFp9FYcB4ZrvILtYzEaSFY 4bMkySJWBla8UWpzJ25w76nLIltBjFG08o/OS/Ybp/K2f+RGnJdqE9n8IocoSTzdk0s1 jRndrqOr/YrZZ8CaK6Xao3JXoDy/tpX1Y9qFWpb4L2I81o06yCDmYwDPVF65kDdFXlWq ckWQ== X-Forwarded-Encrypted: i=1; AHgh+Rru9o/ojzDQVTf4BPZJkFE2ptOoABwWQTBe71lcRN1pRkRFaTg2jir4516dW9eoW4U1n315Sa383AGxz94=@vger.kernel.org X-Gm-Message-State: AOJu0YwbD5nhlfWJeVTqrMRY/QPs339qGzSS1sbB2qn7gpFoJk2OhmLW CO9EAE7SsVxODl+uRZ2sXxlbOdmXDuWmZB4y5VWFvUtahummpB+eHya4 X-Gm-Gg: AR+sD12hq0ilzRlZdJmG6qlS/ycsijC8tzvuTZXQB2jQPQztUJlQNurQfKAPlQASUlO 1yoVIXxZS6oGSO8kSRZ3gOiwGy/sB2nYaAcWU7pg7igXrIBeTpXDho2QI0ARn34qsbVh43a2Ke3 vBU+u9BTl+KeZgNOHFTrh01EzH+bVRMTaiWZ5/0NNlUECP32UaPxAop9tLytsvFQ7IBvQcT6An9 +yTYCmodMkbsgzc23AcHRgchsCLYydPjPwXf2DazT0xrp1piRAnqu/drAdPZK7U5+cOaNfMTQ1W tOTAo0UrjS4DEKO2GxZMrPH4kCD034BTHbhlyYYLCsGE3PxE66H1qI/VZghBxVh6qgXHCUs6GeJ MEFpzm+bAwvD0za/iRStMfpRhwgJO+6vhihHRZcEDBMJLenttzfxl+EVTDsJsm6b7J55v+Ls3F7 V6bqJ5vHha9bCd7QtBpJCGP7/3zw9UCV5O1BBffYOMfy6T5dGy+YSQUb7+mGFPmYJmPmvLTqxDc bmmdCGcuBFehPHPz4nz6Y7QJs+cRXsX X-Received: by 2002:a17:902:ebc2:b0:2cc:d69a:354a with SMTP id d9443c01a7336-2d2a8eb76e2mr101854685ad.22.1786194159557; Sat, 08 Aug 2026 06:02:39 -0700 (PDT) Received: from lixiang-ThinkCentre-M755e-N000.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d14ccae6f8sm18584645ad.1.2026.08.08.06.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 06:02:37 -0700 (PDT) From: ruipengqi To: akpm@linux-foundation.org, peterz@infradead.org, bigeasy@linutronix.de Cc: lance.yang@linux.dev, mhiramat@kernel.org, pmladek@suse.com, mingo@redhat.com, will@kernel.org, boqun@kernel.org, longman@redhat.com, clrkwllms@kernel.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, ruipengqi3@gmail.com, Zhan Xusheng Subject: [PATCH v2 1/2] hung_task: show the blocker task if the task is hung on rtmutex Date: Sat, 8 Aug 2026 21:02:17 +0800 Message-Id: <51d7411207693824ee515b62a31c2a3d76fdf0d4.1786193045.git.ruipengqi3@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ruipeng Qi Currently, debug_show_blocker() only tracks mutex, semaphore and rwsem lock types. Extend it to also cover rtmutex or rt_mutex-based lock implementations on PREEMPT_RT, so that when a task is hung on an rtmutex, the hung task detector can identify and report which task holds the lock. Add rt_mutex_task_owner() to get the task's lock owner when a task is blocked by an rtmutex-based lock implementation. Since the LSBs of task->blocker pointer are already fully utilized and leave no room for new blocker types, this version avoids adding a new blocker type by directly leveraging rt_mutex_task_owner() to retrieve the lock owner information. With this change, the hung task detector can now show blocker task's info like below: [ 3000.899985] INFO: task cat:195 blocked for more than 120 seconds. [ 3000.900561] Not tainted 7.2.0-rc4-00366-gf339a6eb59f3-dirty #22 [ 3000.900930] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables = this message. [ 3000.901376] task:cat state:D stack:13784 pid:195 tgid:195 = ppid:1 task_flags:0x400000 flags:0x00080000 [ 3000.902081] Call Trace: [ 3000.902233] [ 3000.902383] __schedule+0x514/0xf50 [ 3000.902677] rt_mutex_schedule+0x1b/0x30 [ 3000.902916] rt_mutex_slowlock_block.constprop.0+0x3b/0x1c0 [ 3000.903242] __rt_mutex_slowlock_locked.constprop.0+0xa8/0x200 [ 3000.903716] rt_mutex_slowlock.constprop.0+0x48/0xb0 [ 3000.904023] rt_mutex_lock+0x32/0x40 [ 3000.904249] read_dummy_rtmutex+0x2a/0x60 [hung_task_tests] [ 3000.904647] full_proxy_read+0x5b/0x90 [ 3000.904843] vfs_read+0xb0/0x370 [ 3000.905051] ? vm_mmap_pgoff+0xf1/0x1b0 [ 3000.905293] ? vm_mmap_pgoff+0x122/0x1b0 [ 3000.905684] ksys_read+0x68/0xe0 [ 3000.905980] do_syscall_64+0xf9/0x540 [ 3000.906213] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 3000.906643] RIP: 0033:0x49a182 [ 3000.906844] RSP: 002b:00007ffc431f6528 EFLAGS: 00000246 ORIG_RAX: 000000= 0000000000 [ 3000.907251] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00000000004= 9a182 [ 3000.907673] RDX: 0000000000010000 RSI: 00007f69b2166000 RDI: 00000000000= 00003 [ 3000.908044] RBP: 00007f69b2166000 R08: 00000000ffffffff R09: 00000000000= 00000 [ 3000.908485] R10: 0000000000000022 R11: 0000000000000246 R12: 00000000000= 10000 [ 3000.908816] R13: 0000000000000003 R14: 0000000000000001 R15: 00000000010= 00000 [ 3000.909206] [ 3000.909351] INFO: task cat:195 is blocked on a rtmutex likely owned by t= ask cat:194. [ 3000.909832] task:cat state:S stack:13784 pid:194 tgid:194 = ppid:1 task_flags:0x400000 flags:0x00080000 [ 3000.910426] Call Trace: [ 3000.910618] [ 3000.910727] __schedule+0x514/0xf50 [ 3000.910912] schedule+0x22/0xa0 [ 3000.911064] schedule_timeout+0x81/0x100 [ 3000.911254] ? __pfx_process_timeout+0x10/0x10 [ 3000.911522] msleep_interruptible+0x28/0x50 [ 3000.911754] read_dummy_rtmutex+0x34/0x60 [hung_task_tests] [ 3000.912019] full_proxy_read+0x5b/0x90 [ 3000.912212] vfs_read+0xb0/0x370 [ 3000.912378] ? vm_mmap_pgoff+0xf1/0x1b0 [ 3000.912630] ? vm_mmap_pgoff+0x122/0x1b0 [ 3000.912839] ksys_read+0x68/0xe0 [ 3000.913007] do_syscall_64+0xf9/0x540 [ 3000.913187] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 3000.913461] RIP: 0033:0x49a182 [ 3000.913618] RSP: 002b:00007ffd0b4cf048 EFLAGS: 00000246 ORIG_RAX: 000000= 0000000000 [ 3000.913972] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00000000004= 9a182 [ 3000.914294] RDX: 0000000000010000 RSI: 00007fbf49a0d000 RDI: 00000000000= 00003 [ 3000.914648] RBP: 00007fbf49a0d000 R08: 00000000ffffffff R09: 00000000000= 00000 [ 3000.914955] R10: 0000000000000022 R11: 0000000000000246 R12: 00000000000= 10000 [ 3000.915208] R13: 0000000000000003 R14: 0000000000000001 R15: 00000000010= 00000 [ 3000.915439] Suggested-by: Petr Mladek Suggested-by: Zhan Xusheng Signed-off-by: Ruipeng Qi --- v2 changes: - Reduce #ifdef-ery by using rt_mutex_task_owner() instead of adding a new= blocker type. - Remove the unused function debug_trace_blocker(). - Clean up and update relevant comments. --- include/linux/rtmutex.h | 2 ++ kernel/hung_task.c | 26 +++++++++++++++++++++++--- kernel/locking/rtmutex_api.c | 29 +++++++++++++++++++++++++++++ lib/Kconfig.debug | 1 - 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 9e1f012f89db89..c179f946d2d040 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -53,6 +53,8 @@ static inline struct task_struct *rt_mutex_owner(struct r= t_mutex_base *lock) =20 return (struct task_struct *) (owner & ~RT_MUTEX_HAS_WAITERS); } + +extern struct task_struct *rt_mutex_task_owner(struct task_struct *task); #endif extern void rt_mutex_base_init(struct rt_mutex_base *rtb); =20 diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 6fcc94ce4ca9d2..9467011f878c95 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -27,6 +27,7 @@ #include =20 #include +#include =20 /* * The number of tasks checked: @@ -139,9 +140,19 @@ static void debug_show_blocker(struct task_struct *tas= k, unsigned long timeout) struct task_struct *g, *t; unsigned long owner, blocker, blocker_type; const char *rwsem_blocked_by, *rwsem_blocked_as; + bool is_rtmutex =3D false; =20 RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "No rcu lock held"); =20 +#if defined(CONFIG_RT_MUTEXES) + owner =3D (unsigned long)rt_mutex_task_owner(task); + if (owner) { + is_rtmutex =3D true; + blocker_type =3D -1; + goto found; + } +#endif + blocker =3D READ_ONCE(task->blocker); if (!blocker) return; @@ -149,12 +160,13 @@ static void debug_show_blocker(struct task_struct *ta= sk, unsigned long timeout) blocker_type =3D hung_task_get_blocker_type(blocker); =20 switch (blocker_type) { - case BLOCKER_TYPE_MUTEX: - owner =3D mutex_get_owner(hung_task_blocker_to_lock(blocker)); - break; case BLOCKER_TYPE_SEM: owner =3D sem_last_holder(hung_task_blocker_to_lock(blocker)); break; +#ifndef CONFIG_PREEMPT_RT + case BLOCKER_TYPE_MUTEX: + owner =3D mutex_get_owner(hung_task_blocker_to_lock(blocker)); + break; case BLOCKER_TYPE_RWSEM_READER: case BLOCKER_TYPE_RWSEM_WRITER: owner =3D (unsigned long)rwsem_owner( @@ -165,6 +177,7 @@ static void debug_show_blocker(struct task_struct *task= , unsigned long timeout) hung_task_blocker_to_lock(blocker)) ? "reader" : "writer"; break; +#endif default: WARN_ON_ONCE(1); return; @@ -190,6 +203,7 @@ static void debug_show_blocker(struct task_struct *task= , unsigned long timeout) return; } =20 +found: /* Ensure the owner information is correct. */ for_each_process_thread(g, t) { if ((unsigned long)t !=3D owner) @@ -210,6 +224,12 @@ static void debug_show_blocker(struct task_struct *tas= k, unsigned long timeout) task->comm, task->pid, rwsem_blocked_as, t->comm, t->pid, rwsem_blocked_by); break; + default: + if (is_rtmutex) { + pr_err("INFO: task %s:%d is blocked on a rtmutex likely owned by task = %s:%d.\n", + task->comm, task->pid, t->comm, t->pid); + } + break; } /* Avoid duplicated task dump, skip if the task is also hung. */ if (!task_is_hung(t, timeout)) diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c index 5d48d64725b125..d0826b31a148c0 100644 --- a/kernel/locking/rtmutex_api.c +++ b/kernel/locking/rtmutex_api.c @@ -530,6 +530,35 @@ void __sched rt_mutex_postunlock(struct rt_wake_q_head= *wqh) rt_mutex_wake_up_q(wqh); } =20 +/** + * rt_mutex_task_owner - Get the lock owner a task is blocked on + * @task: Task to inspect. + * + * Caller must hold an RCU read lock. The owner value is a snapshot read + * without exclusion, so it may become stale immediately. Use only for + * best-effort diagnostics (e.g., hung task detection). + * + * Return: The task_struct owning the lock, or NULL if not blocked. + */ +struct task_struct *rt_mutex_task_owner(struct task_struct *task) +{ + struct task_struct *owner =3D NULL; + struct rt_mutex_base *lock; + unsigned long flags; + + lockdep_assert(rcu_read_lock_held()); + + raw_spin_lock_irqsave(&task->pi_lock, flags); + lock =3D task_blocked_on_lock(task); + + if (lock) + owner =3D rt_mutex_owner(lock); + raw_spin_unlock_irqrestore(&task->pi_lock, flags); + + return owner; +} +EXPORT_SYMBOL(rt_mutex_task_owner); + #ifdef CONFIG_DEBUG_RT_MUTEXES void rt_mutex_debug_task_free(struct task_struct *task) { diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 1244dcac2294ad..92dff380027e78 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1317,7 +1317,6 @@ config BOOTPARAM_HUNG_TASK_PANIC config DETECT_HUNG_TASK_BLOCKER bool "Dump Hung Tasks Blocker" depends on DETECT_HUNG_TASK - depends on !PREEMPT_RT default y help Say Y here to show the blocker task's stacktrace who acquires --=20 2.25.1 From nobody Wed Sep 30 17:08:57 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AD83368D73 for ; Sat, 8 Aug 2026 13:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786194170; cv=none; b=Tr7OSy1EuvgaU1muDM0r8NU+0HhycHv4t66zNaM6zpjII7N+xVEG4f9BsQhqAhoClyDYTI3XeRWTbzbbPcxakatGciUaExiHd1+VE9vm2uKTYG9z0oRjx2gATiRshIyh/ZA+6kKtf3l5+xJ9XJ98jBon9Q3WZvusJrxBjetgFOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786194170; c=relaxed/simple; bh=tZdQfkIbTLMmQhIIpHLZqNvhV3UwMghKr9YQEd8kgnU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SU9t68WtJgW3URX1XR+a7XcRzEthQZtweFB12RqR2GOCBSplGk8qFKEHn+R5wIcX2rpPlyR2rJGMr2msCBrF1I8sBtGg4ZP0hetRSrdKhaxeW/wREANQoYOuJNqAMuaU3ZeeJ0LBRBwpb6GxDhK/DVgc6CIthb/p021vS866d3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CKTmsJzD; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CKTmsJzD" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2d032846c95so5882775ad.1 for ; Sat, 08 Aug 2026 06:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786194165; x=1786798965; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Kp2VJTNh84D6ZjQn57/lnKrcvYZ5tmwmH9yfxoK/7b0=; b=CKTmsJzDO+FHKRN1BPu8ScO+rvlFccaimF0Xd+KLP1namdoq9rxj35M1WQrQKMUayo Og1G5EkO03VcpwrCVAnPv65dxA+QYRJrRiTgZ7RBSOpoLooGKKjlsFuQmUv9h2gqUdws IhakC43F+0PuFfCJieyi+o4vrm1872Aem+Tp5wLpOIM/7JdLvoHb6ILsSzRXgeLDZc9W WsyzJZ8po583PlpeGM+XSRN7sycKXbaT/7VqlYjZQpyrl+m76zzFZLEk6t7a/XzSK+Am z6j4PYzzMhblHo84ukU9QinLClnRi9E6cWPwoioCgUvlAXHnM96RfTwr2lh5lUxEehC2 tdBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786194165; x=1786798965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Kp2VJTNh84D6ZjQn57/lnKrcvYZ5tmwmH9yfxoK/7b0=; b=X9MhI3QdkrgFMBWlikeR3ajcv8/rbHjR/ar8otHxN8k49mPsVfL+OQqnMmCOPblrC4 fV9zzcRdl7lvZV3bm9z18zSPh4KXDz7IwzQMil15wROQF0f5QpGz4Lw5srOVPb2iUl5v COOPZy9YDqFWFem8FktyqS9pDS1gIFH84HXWLXTAm+3Lkf3b3JQpO1FYbENcJesC/ml1 gqEkKbGZl06ICKz6uH8d+ZRMe715IQdp0XpD/jLh+URFYKxegb/a4bv9IXeBTjugrzEG Esr9es2aM6sQ0Kgc0zPlpDdSK2SHGzStHug+vsuAZX2atEtV4q6ymeSentXtEr1vMgLQ RlRw== X-Forwarded-Encrypted: i=1; AHgh+RqS7wRhvSb7lmnoKhpL3q76B9M1sHuPpjhV2LZ/aMaTSRw3hydjdStf+Yf7Hi5auYGTFqzROG6hl5d7rd0=@vger.kernel.org X-Gm-Message-State: AOJu0YxJZebPEeJfAzeu9Dg9xJ06oUV1X1E9eoAcOoWxDsUg2RrKRm0k xr8RbKeiUVNOKMFex+vNFGkZZO7nzoJ88tZ/XdzW13icOo/MeCP7ouR+ X-Gm-Gg: AR+sD10FnNpRTIH/LimWMkViuo1GHXqd0pLj9Bjvol9tTWgCQGGxmtmksQES+8NLsVS V5b1ZvjYFfvYfw5opM1W9lOO1x4EoGr+zBzSjdR5L3cKZPz9D1ZhnBsm5JQrYUyS3bl5LpXQ+ax YC2gCmv5jsu+coi0C8Gnx9e9r3laKi/3IiCkHTM9Qj1mnQgDPeupEJyUeZym8xyNYb+h9th+NmD AybALpBjjEFuMrw1SW9deL5eAGJaIMQ0ljBmgoJVZFM3sU3trNdXO2xKWGAGw2SRvaKIZWVacdz M2jQ5TnipZj/cWZhQPaYrlUfth6+h+6PdEb25Ulgo1H0TFtuiw8l55QRE2M5nS0mnCi8U02UAVe hyLUoQ8SSqd399Gj+v6TiWrwQ8O8WpmjC6rG+MBk+FnVrp8se8wK7D1qLf8r7Dd6y4k3A404FhM /czs7vNHyD7MfT4O/vQO62NeMVVot4H5HSDucV7cxTTKdPrrm2Qc5FIJt5Ddz7A8TU9EDyrB8o/ el46ohtDKiOdUOBjlplpgEbMCCpSw2/ X-Received: by 2002:a17:902:f605:b0:2c6:9f66:d573 with SMTP id d9443c01a7336-2d0ca71b3f0mr392851375ad.2.1786194164766; Sat, 08 Aug 2026 06:02:44 -0700 (PDT) Received: from lixiang-ThinkCentre-M755e-N000.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d14ccae6f8sm18584645ad.1.2026.08.08.06.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 06:02:44 -0700 (PDT) From: ruipengqi To: akpm@linux-foundation.org, peterz@infradead.org, bigeasy@linutronix.de Cc: lance.yang@linux.dev, mhiramat@kernel.org, pmladek@suse.com, mingo@redhat.com, will@kernel.org, boqun@kernel.org, longman@redhat.com, clrkwllms@kernel.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, ruipengqi3@gmail.com Subject: [PATCH v2 2/2] samples: enhance hung_task detector test with rtmutex support Date: Sat, 8 Aug 2026 21:02:18 +0800 Message-Id: <4991cd8e1bbddb42a1fe31dde38f85d74ff1c4cc.1786193045.git.ruipengqi3@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ruipeng Qi Extend the hung_task detector test module with an rtmutex test. When CONFIG_RT_MUTEXES is enabled, the module creates an additional "rtmutex" debugfs file under /hung_task. Concurrent reads hold and contend on an rtmutex for 256 seconds, allowing hung-task and blocker reporting to be tested for rtmutex waits. Usage is: > cd /sys/kernel/debug/hung_task > cat rtmutex & cat rtmutex Update the module usage comments and Kconfig description to document the rtmutex debugfs file. Signed-off-by: Ruipeng Qi --- samples/Kconfig | 2 +- samples/hung_task/hung_task_tests.c | 50 ++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/samples/Kconfig b/samples/Kconfig index a75e8e78330da5..11096dbc43413f 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -318,7 +318,7 @@ config SAMPLE_HUNG_TASK depends on DETECT_HUNG_TASK && DEBUG_FS help Build a module that provides debugfs files (e.g., mutex, semaphore, - rw_semaphore_read, rw_semaphore_write) under /hung_task. + rw_semaphore_read, rw_semaphore_write, rtmutex) under /hung_ta= sk. Reading these files with multiple processes triggers hung task detection by holding locks for a long time (256 seconds). =20 diff --git a/samples/hung_task/hung_task_tests.c b/samples/hung_task/hung_t= ask_tests.c index 0360ec916890b3..87346d65f860a5 100644 --- a/samples/hung_task/hung_task_tests.c +++ b/samples/hung_task/hung_task_tests.c @@ -1,14 +1,16 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * hung_task_tests.c - Sample code for testing hung tasks with mutex, - * semaphore, etc. + * semaphore, rwsem, and rtmutex. * * Usage: Load this module and read `/hung_task/mutex`, * `/hung_task/semaphore`, `/hung_task/rw_semapho= re_read`, - * `/hung_task/rw_semaphore_write`, etc., with 2 or more p= rocesses. + * `/hung_task/rw_semaphore_write`, and `/hung_ta= sk/rtmutex`, + * with 2 or more processes. * * This is for testing kernel hung_task error messages with various locking - * mechanisms (e.g., mutex, semaphore, rw_semaphore_read, rw_semaphore_wri= te, etc.). + * mechanisms (e.g., mutex, semaphore, rw_semaphore_read, rw_semaphore_wri= te, + * and rtmutex). * Note that this may freeze your system or cause a panic. Use only for te= sting purposes. */ =20 @@ -17,6 +19,7 @@ #include #include #include +#include #include #include =20 @@ -25,10 +28,16 @@ #define HUNG_TASK_SEM_FILE "semaphore" #define HUNG_TASK_RWSEM_READ_FILE "rw_semaphore_read" #define HUNG_TASK_RWSEM_WRITE_FILE "rw_semaphore_write" +#ifdef CONFIG_RT_MUTEXES +#define HUNG_TASK_RTMUTEX_FILE "rtmutex" +#endif #define SLEEP_SECOND 256 =20 static const char dummy_string[] =3D "This is a dummy string."; static DEFINE_MUTEX(dummy_mutex); +#ifdef CONFIG_RT_MUTEXES +static DEFINE_RT_MUTEX(dummy_rtmutex); +#endif static DEFINE_SEMAPHORE(dummy_sem, 1); static DECLARE_RWSEM(dummy_rwsem); static struct dentry *hung_task_dir; @@ -51,6 +60,28 @@ static ssize_t read_dummy_mutex(struct file *file, char = __user *user_buf, sizeof(dummy_string)); } =20 +#ifdef CONFIG_RT_MUTEXES +/* RT mutex-based read function */ +static ssize_t read_dummy_rtmutex(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + /* Check if data is already read */ + if (*ppos >=3D sizeof(dummy_string)) + return 0; + + /* Second task waits on rtmutex, entering uninterruptible sleep */ + rt_mutex_lock(&dummy_rtmutex); + + /* First task sleeps here, interruptible */ + msleep_interruptible(SLEEP_SECOND * 1000); + + rt_mutex_unlock(&dummy_rtmutex); + + return simple_read_from_buffer(user_buf, count, ppos, dummy_string, + sizeof(dummy_string)); +} +#endif + /* Semaphore-based read function */ static ssize_t read_dummy_semaphore(struct file *file, char __user *user_b= uf, size_t count, loff_t *ppos) @@ -116,6 +147,13 @@ static const struct file_operations hung_task_mutex_fo= ps =3D { .read =3D read_dummy_mutex, }; =20 +#ifdef CONFIG_RT_MUTEXES +/* File operations for rtmutex */ +static const struct file_operations hung_task_rtmutex_fops =3D { + .read =3D read_dummy_rtmutex, +}; +#endif + /* File operations for semaphore */ static const struct file_operations hung_task_sem_fops =3D { .read =3D read_dummy_semaphore, @@ -137,9 +175,13 @@ static int __init hung_task_tests_init(void) if (IS_ERR(hung_task_dir)) return PTR_ERR(hung_task_dir); =20 - /* Create debugfs files for mutex and semaphore tests */ + /* Create debugfs files for lock tests */ debugfs_create_file(HUNG_TASK_MUTEX_FILE, 0400, hung_task_dir, NULL, &hung_task_mutex_fops); +#ifdef CONFIG_RT_MUTEXES + debugfs_create_file(HUNG_TASK_RTMUTEX_FILE, 0400, hung_task_dir, NULL, + &hung_task_rtmutex_fops); +#endif debugfs_create_file(HUNG_TASK_SEM_FILE, 0400, hung_task_dir, NULL, &hung_task_sem_fops); debugfs_create_file(HUNG_TASK_RWSEM_READ_FILE, 0400, hung_task_dir, NULL, --=20 2.25.1