Re: [PATCH v5 1/3] hung_task: replace blocker_mutex with encoded blocker

From: Andrew Morton
Date: Mon Apr 14 2025 - 17:36:45 EST


On Mon, 14 Apr 2025 22:59:43 +0800 Lance Yang <ioworker0@xxxxxxxxx> wrote:

> This patch replaces 'struct mutex *blocker_mutex' with 'unsigned long
> blocker', as only one blocker is active at a time.
>
> The blocker filed can store both the lock addrees and the lock type, with
> LSB used to encode the type as Masami suggested, making it easier to extend
> the feature to cover other types of locks.
>
> Also, once the lock type is determined, we can directly extract the address
> and cast it to a lock pointer ;)
>
> ...
>
> static void debug_show_blocker(struct task_struct *task)
> {
> struct task_struct *g, *t;
> - unsigned long owner;
> - struct mutex *lock;
> + unsigned long owner, blocker;
>
> RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "No rcu lock held");
>
> - lock = READ_ONCE(task->blocker_mutex);
> - if (!lock)
> + blocker = READ_ONCE(task->blocker);
> + if (!blocker ||
> + hung_task_get_blocker_type(blocker) != BLOCKER_TYPE_MUTEX)
> return;
>
> - owner = mutex_get_owner(lock);
> + owner = mutex_get_owner(
> + (struct mutex *)hung_task_blocker_to_lock(blocker));

typecast is unneeded?