The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Waiman Long <llong@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Joel Granados <joel.granados@kernel.org>,
	Anna Schumaker <anna.schumaker@oracle.com>,
	Lance Yang <ioworker0@gmail.com>,
	Kent Overstreet <kent.overstreet@linux.dev>,
	Yongliang Gao <leonylgao@tencent.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Tomasz Figa <tfiga@chromium.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] hung_task: Show the blocker task if the task is hung on mutex
Date: Fri, 21 Feb 2025 15:29:57 -0500	[thread overview]
Message-ID: <63fc7bff-168e-478b-a3fc-4897f2ee9d69@redhat.com> (raw)
In-Reply-To: <20250221185939.GB7373@noisy.programming.kicks-ass.net>


On 2/21/25 1:59 PM, Peter Zijlstra wrote:
> On Fri, Feb 21, 2025 at 11:30:01PM +0900, Masami Hiramatsu (Google) wrote:
>> +static void debug_show_blocker(struct task_struct *task)
>> +{
>> +	struct task_struct *g, *t;
>> +	unsigned long owner;
>> +	struct mutex *lock;
>> +
>> +	lock = READ_ONCE(task->blocker_mutex);
>> +	if (!lock)
>> +		return;
>> +
>> +	owner = mutex_get_owner(lock);
>> +	if (likely(owner)) {
>> +		/* Ensure the owner information is correct. */
>> +		for_each_process_thread(g, t)
>> +			if ((unsigned long)t == owner) {
>> +				pr_err("INFO: task %s:%d is blocked on a mutex owned by task %s:%d.\n",
>> +					task->comm, task->pid, t->comm, t->pid);
>> +				sched_show_task(t);
>> +				return;
>> +			}
>   - that for_each_process_thread() scope needs { }
>
>   - that for_each_process_thread() loop needs RCU or tasklist_lock

The call chain should be

check_hung_uninterruptible_tasks()
   -> check_hung_task()
     -> debug_show_blocker()

check_hung_uninterruptible_tasks() takes rcu_read_lock() before calling 
check_hung_task(). Perhaps add a statement like

     RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "no rcu lock held");

>
>   - there is no saying that the owner you read with mutex_get_owner() is
>     still the owner by the time you do the compare, there can have been
>     owner changes.

Maybe change "owned by" to "likely owned by" :-)

Cheers,
Longman


  reply	other threads:[~2025-02-21 20:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 14:29 [PATCH v2 0/2] hung_task: Dump the blocking task stacktrace Masami Hiramatsu (Google)
2025-02-21 14:30 ` [PATCH v2 1/2] hung_task: Show the blocker task if the task is hung on mutex Masami Hiramatsu (Google)
2025-02-21 18:59   ` Peter Zijlstra
2025-02-21 20:29     ` Waiman Long [this message]
2025-02-22  1:07       ` Masami Hiramatsu
2025-02-21 14:30 ` [PATCH v2 2/2] samples: Add hung_task detector mutex blocking sample Masami Hiramatsu (Google)

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=63fc7bff-168e-478b-a3fc-4897f2ee9d69@redhat.com \
    --to=llong@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=anna.schumaker@oracle.com \
    --cc=boqun.feng@gmail.com \
    --cc=ioworker0@gmail.com \
    --cc=joel.granados@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=leonylgao@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tfiga@chromium.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