From: Rob Herring <robh@kernel.org>
To: Ryder Wang <rydercoding@hotmail.com>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: Bug: lock problem for the function of_find_node_by_name
Date: Tue, 11 Mar 2025 08:13:48 -0500 [thread overview]
Message-ID: <20250311131348.GA2859052-robh@kernel.org> (raw)
In-Reply-To: <MEYP282MB3164D0271E9BDA49BBB7E7D1BFD42@MEYP282MB3164.AUSP282.PROD.OUTLOOK.COM>
On Sat, Mar 08, 2025 at 10:00:31AM +0000, Ryder Wang wrote:
> It looks there is a potential bug in some device tree function in
> Kernel code (It does not depend on the version of the kernel).
>
> One device tree function of_find_node_by_name() calls
> raw_spin_lock_irqsave() to lock. Then it calls of_node_put(), before
> unlocking (raw_spin_unlock_irqrestore). of_node_put() will call
> kernfs_remove() in some cases. So problem is here: kernfs_remove()
> will always call down_write() which might make the process sleep. As
> we know, sleep is not allowed between lock and unlock of spin lock.
> That's why there is might_sleep checking within down_write(), as
> there may be dead lock risk or disabling interrupt too long.
>
> The actual call trace is like this:
> of_find_node_by_name
> raw_spin_lock_irqsave
> ...
> kernfs_remove
> down_write
> ...
> raw_spin_unlock_irqrestore
The bug here would be the reference count going to 0. Do you have a
case or unittest that can trigger this?
Rob
next prev parent reply other threads:[~2025-03-11 13:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-08 10:00 Bug: lock problem for the function of_find_node_by_name Ryder Wang
2025-03-11 13:13 ` Rob Herring [this message]
2025-03-12 1:41 ` Ryder Wang
2025-03-12 14:19 ` Rob Herring
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=20250311131348.GA2859052-robh@kernel.org \
--to=robh@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=rydercoding@hotmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.