lkml.org 
[lkml]   [2022]   [May]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/5] kernfs: make ->attr.open RCU protected.
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

\
 
 \ /
  Last update: 2022-05-17 06:22    [W:0.149 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site