The Linux Kernel Mailing List
 help / color / mirror / Atom feed
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 RESEND v4 1/4] kernfs: make ->attr.open RCU protected.
Date: Sun, 12 Jun 2022 17:09:33 -1000	[thread overview]
Message-ID: <Yqaqbas1JaWz25jB@slm.duckdns.org> (raw)
In-Reply-To: <c8a8a616-da4c-f2ce-0bb2-e0cba69db24d@oracle.com>

On Mon, Jun 13, 2022 at 12:55:14PM +1000, Imran Khan wrote:
> 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));

So, both are saying that if a given reference can be under both read
critical section or a lock which blocks updates, you can use deref_check to
cover both cases - we're just using the stronger form of derefing even
though that's not necessary while update side is locked out, which is fine.

The protected one is different in that it doesn't enforce the load ordering
which is required for accesses with only RCU read lock. Given that all
that's required is dependency ordering, I doubt it makes any actual
difference and it likely is more useful in marking a specific dereference as
always being with the update side locked.

tl;dr is that you're way over-thinking the rcu deref code. Just make one
deref accessor which encompasses all three use cases.

Thanks.

-- 
tejun

  reply	other threads:[~2022-06-13  3:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02  6:39 [PATCH RESEND v4 0/4] kernfs: make ->attr.open RCU protected Imran Khan
2022-06-02  6:39 ` [PATCH RESEND v4 1/4] " Imran Khan
2022-06-12 17:58   ` Tejun Heo
2022-06-13  2:36     ` Imran Khan
2022-06-13  2:46       ` Tejun Heo
2022-06-13  2:55         ` Imran Khan
2022-06-13  3:09           ` Tejun Heo [this message]
2022-06-13  3:56             ` Imran Khan
2022-06-13 17:30               ` Tejun Heo
2022-06-14  2:31                 ` Imran Khan
2022-06-02  6:39 ` [PATCH RESEND v4 2/4] kernfs: Change kernfs_notify_list to llist Imran Khan
2022-06-02  6:39 ` [PATCH RESEND v4 3/4] kernfs: Introduce interface to access global kernfs_open_file_mutex Imran Khan
2022-06-02  6:39 ` [PATCH RESEND v4 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=Yqaqbas1JaWz25jB@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