From: Tejun Heo <tj@kernel.org>
To: Imran Khan <imran.f.khan@oracle.com>
Cc: viro@zeniv.linux.org.uk, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] kernfs: make ->attr.open RCU protected.
Date: Mon, 16 May 2022 18:21:09 -1000 [thread overview]
Message-ID: <YoMitbmf5hIm7QRh@slm.duckdns.org> (raw)
In-Reply-To: <4532123f-4c03-0303-1480-a51faabca806@oracle.com>
On Tue, May 17, 2022 at 12:30:26PM +1000, Imran Khan wrote:
> +/**
> + * kernfs_deref_open_node - Get kernfs_open_node corresponding to @kn.
> + *
> + * @kn: target kernfs_node.
> + * @val: RCU dereference will take place only if val is true.
> + *
> + * Fetch and return ->attr.open of @kn when current updater of ->attr.open
> + * ensures that as long as @val is true, other updater(s) of ->attr.open
> + * can not change it. The caller needs to pass value of the condition
> + * (@val) that prevents value of ->attr.open from changing.
> + *
> + * This should ONLY be used by updaters of ->attr.open.
> + */
> +static struct kernfs_open_node *
> +kernfs_deref_open_node(struct kernfs_node *kn, bool val)
> +{
> + return rcu_dereference_protected(kn->attr.open, val);
> +}
> +
> +/**
> + * kernfs_check_open_node - Get kernfs_open_node corresponding to @kn.
> + *
> + * @kn: target kernfs_node.
> + * @val: RCU dereference will take place only if val is true.
> + *
> + * rcu_dereference and return ->attr.open of @kn. This is used in cases
> + * where we can access ->attr.open outside RCU read-side critical section
> + * as long as specified conditions are correct i.e @val is true.
> + *
> + * This should ONLY be used by readers of ->attr.open.
> + */
> +static struct kernfs_open_node *
> +kernfs_check_open_node(struct kernfs_node *kn, bool val)
> +{
> + return rcu_dereference_check(kn->attr.open, val);
> +}
You gotta put the conditions inside these wrappers. These wrappers are
supposed to describe as strict as reasonably possible so that the checks can
catch people making mistakes. It doesn't make much sense to defer the
condition to the callers. Just describe what the expected conditions are in
the wrappers as best as you reasonably can.
Thanks.
--
tejun
next prev parent reply other threads:[~2022-05-17 4:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 5:54 [PATCH 0/5] kernfs: Remove reference counting for kernfs_open_node Imran Khan
2022-04-28 5:54 ` [PATCH 1/5] " Imran Khan
2022-05-05 19:46 ` Tejun Heo
2022-04-28 5:54 ` [PATCH 2/5] kernfs: make ->attr.open RCU protected Imran Khan
2022-05-05 20:01 ` Tejun Heo
2022-05-05 23:12 ` Imran Khan
2022-05-12 17:09 ` Tejun Heo
2022-05-15 16:00 ` Imran Khan
2022-05-16 19:35 ` Tejun Heo
2022-05-17 2:30 ` Imran Khan
2022-05-17 4:21 ` Tejun Heo [this message]
2022-04-28 5:54 ` [PATCH 3/5] kernfs: Change kernfs_notify_list to llist Imran Khan
2022-05-05 20:03 ` Tejun Heo
2022-04-28 5:54 ` [PATCH 4/5] kernfs: Introduce interface to access global kernfs_open_file_mutex Imran Khan
2022-05-05 20:04 ` Tejun Heo
2022-04-28 5:54 ` [PATCH 5/5] kernfs: Replace global kernfs_open_file_mutex with hashed mutexes Imran Khan
2022-05-05 20:05 ` Tejun Heo
2022-05-11 9:58 ` 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=YoMitbmf5hIm7QRh@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