[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zy5EIHUwoXjK1sAJ@slm.duckdns.org>
Date: Fri, 8 Nov 2024 07:02:24 -1000
From: Tejun Heo <tj@...nel.org>
To: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: Boqun Feng <boqun.feng@...il.com>, Hillf Danton <hdanton@...a.com>,
"Paul E. McKenney" <paulmck@...nel.org>,
Marco Elver <elver@...gle.com>, linux-kernel@...r.kernel.org,
gregkh@...uxfoundation.org, tglx@...utronix.de,
syzbot <syzbot+6ea37e2e6ffccf41a7e6@...kaller.appspotmail.com>
Subject: Re: [BUG] -next lockdep invalid wait context
Hello,
On Fri, Nov 08, 2024 at 11:05:03AM +0100, Sebastian Andrzej Siewior wrote:
...
> static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen)
> {
> + struct kernfs_node *kn_parent;
> + const char *kn_name;
> +
> if (!kn)
> return strscpy(buf, "(null)", buflen);
>
> - return strscpy(buf, kn->parent ? kn->name : "/", buflen);
> + kn_parent = rcu_dereference(kn->parent);
kn->parent can never change. This can just be a regular deref.
> + kn_name = rcu_dereference(kn->name);
> + return strscpy(buf, kn_parent ? kn_name : "/", buflen);
> }
>
> /* kernfs_node_depth - compute depth from @from to @to */
> @@ -66,7 +70,7 @@ static size_t kernfs_depth(struct kernfs_node *from, struct kernfs_node *to)
>
> while (to->parent && to != from) {
> depth++;
> - to = to->parent;
> + to = rcu_dereference(to->parent);
Ditto here and other places.
> int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
> {
> - unsigned long flags;
> int ret;
>
> - read_lock_irqsave(&kernfs_rename_lock, flags);
> + rcu_read_lock();
> ret = kernfs_name_locked(kn, buf, buflen);
> - read_unlock_irqrestore(&kernfs_rename_lock, flags);
> + rcu_read_unlock();
> return ret;
> }
>
> @@ -223,12 +226,11 @@ int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
> int kernfs_path_from_node(struct kernfs_node *to, struct kernfs_node *from,
> char *buf, size_t buflen)
> {
> - unsigned long flags;
> int ret;
>
> - read_lock_irqsave(&kernfs_rename_lock, flags);
> + rcu_read_lock();
> ret = kernfs_path_from_node_locked(to, from, buf, buflen);
> - read_unlock_irqrestore(&kernfs_rename_lock, flags);
> + rcu_read_unlock();
> return ret;
> }
The _locked suffix looks awkward afterwards. Given that there's no
restriction on how the function is called anymore, maybe we can just
collapse _locked bodies into the callers?
...
> diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
> index 87c79d076d6d7..733d89de40542 100644
> --- a/include/linux/kernfs.h
> +++ b/include/linux/kernfs.h
> @@ -199,8 +199,8 @@ struct kernfs_node {
> * never moved to a different parent, it is safe to access the
> * parent directly.
> */
> - struct kernfs_node *parent;
> - const char *name;
> + struct kernfs_node __rcu *parent;
> + const char __rcu *name;
->parent doesn't have to be converted to RCU. As long as the node is
accessible, the parent is guaranteed to be pinned and unchanged. We only
need to RCUfy ->name.
Thanks.
--
tejun
Powered by blists - more mailing lists