Re: [PATCH RESEND v4 1/4] kernfs: make ->attr.open RCU protected.

From: Imran Khan
Date: Sun Jun 12 2022 - 22:55:36 EST


Hello Tejun,

On 13/6/22 12:46 pm, Tejun Heo wrote:
> Hello,
>
> On Mon, Jun 13, 2022 at 12:36:12PM +1000, Imran Khan wrote:
>>>> +static struct kernfs_open_node *
>>>> +kernfs_check_open_node_protected(struct kernfs_node *kn)
>>>> +{
>>>> + return rcu_dereference_check(kn->attr.open,
>>>> + lockdep_is_held(&kernfs_open_file_mutex));
>>>> +}
>>>
>>> I don't understand why the above is necessary. Whether you're a reader or
>>> writer, you can deref the pointer w/ _protected as long as you're holding
>>> the lock, right?
>>
>> As per [1], we should use rcu_dereference_check() for the reader side when we
>> are holding the lock.
>
> Hmm.... can you quote the exact phrase that you took the above from?
>
I took below phrases as reference:

If the access might be within an RCU read-side critical section on the one hand,
or protected by (say) my_lock on the other, use rcu_dereference_check(), for
example:

p1 = rcu_dereference_check(p->rcu_protected_pointer,
lockdep_is_held(&my_lock));


and


If the access might be within an RCU read-side critical section on the one hand,
or protected by either my_lock or your_lock on the other, again use
rcu_dereference_check(), for example:

p1 = rcu_dereference_check(p->rcu_protected_pointer,
lockdep_is_held(&my_lock) ||
lockdep_is_held(&your_lock));


Thanks,
-- Imran