From: Tejun Heo <tj@kernel.org>
To: Imran Khan <imran.f.khan@oracle.com>
Cc: gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 1/4] kernfs: make ->attr.open RCU protected.
Date: Tue, 14 Jun 2022 06:20:21 -1000 [thread overview]
Message-ID: <Yqi1RVRK2XahPWlg@slm.duckdns.org> (raw)
In-Reply-To: <20220614070346.810168-2-imran.f.khan@oracle.com>
On Tue, Jun 14, 2022 at 05:03:43PM +1000, Imran Khan wrote:
> +/**
> + * kernfs_deref_open_node_protected - Get kernfs_open_node corresponding to @kn
> + *
> + * @kn: target kernfs_node.
> + *
> + * Fetch and return ->attr.open of @kn when caller holds the
> + * kernfs_open_file_mutex.
> + *
> + * Update of ->attr.open happens under kernfs_open_file_mutex. So when
> + * the caller guarantees that this mutex is being held, other updaters can't
> + * change ->attr.open and this means that we can safely deref ->attr.open
> + * outside RCU read-side critical section.
> + *
> + * The caller needs to make sure that kernfs_open_file_mutex is held.
> + */
> +static struct kernfs_open_node *
> +kernfs_deref_open_node_protected(struct kernfs_node *kn)
> +{
> + return rcu_dereference_check(kn->attr.open,
> + lockdep_is_held(&kernfs_open_file_mutex));
Hey, so, the difference between rcu_dereference_check() and
rcu_dereference_protected() is that the former can be called either with rcu
read locked or under the extra condition (here, open_file_mutex held) while
the latter can't be used under rcu read lock. The two can generate different
codes too - the former enforces dependency ordering which makes accesses
under rcu read lock safe, while the latter doesn't.
In the above, you're saying that the accessor is only to be used while
holding kernfs_open_file_mutex but then using rcu_dereference_check() which
is odd. There are two ways you can go 1. ensure that the accessor is always
used under the mutex and use rcu_dereference_protected() or 2. if the
function can be used under rcu read lock, rename so that the differentiation
between the two accessors is based on the parameter type, not whether
they're protected or not.
Can you please post the updated patch as a reply to this one? No need to
post the whole thing over and over again.
Thanks.
--
tejun
next prev parent reply other threads:[~2022-06-14 16:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-14 7:03 [PATCH v6 0/4] " Imran Khan
2022-06-14 7:03 ` [PATCH v6 1/4] " Imran Khan
2022-06-14 16:20 ` Tejun Heo [this message]
2022-06-15 2:13 ` Imran Khan
2022-06-15 6:12 ` Tejun Heo
2022-06-14 7:03 ` [PATCH v6 2/4] kernfs: Change kernfs_notify_list to llist Imran Khan
2022-06-14 7:03 ` [PATCH v6 3/4] kernfs: Introduce interface to access global kernfs_open_file_mutex Imran Khan
2022-06-14 7:03 ` [PATCH v6 4/4] kernfs: Replace global kernfs_open_file_mutex with hashed mutexes Imran Khan
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=Yqi1RVRK2XahPWlg@slm.duckdns.org \
--to=tj@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=imran.f.khan@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®