From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Jason Andryuk <jandryuk@gmail.com>
Cc: linux-kernel@vger.kernel.org,
"Eric W . Biederman" <ebiederm@xmission.com>
Subject: Re: [PATCH] kcmp: Comment get_file_raw_ptr() RCU usage
Date: Wed, 2 Feb 2022 20:44:29 +0300 [thread overview]
Message-ID: <YfrC/fQvQ1nkIJNJ@grain> (raw)
In-Reply-To: <20220202151734.10418-1-jandryuk@gmail.com>
On Wed, Feb 02, 2022 at 10:17:34AM -0500, Jason Andryuk wrote:
> This usage of RCU appears wrong since the pointer is passed outside the
> RCU region. However, it is not dereferenced, so it is "okay". Leave a
> comment for the next reader.
>
> Without a reference, these comparisons are racy, but even with their use
> inside an RCU region, the result could go stale.
>
> Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
> ---
> I was looking for examples of task_lookup_fd_rcu()/files_lookup_fd_rcu()
> and found this. It differed from the example given in
> Documentation/filesystems/files.rst, so I was initially confused. A
> comment seemed appropriate to avoid confusion.
>
> kernel/kcmp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/kcmp.c b/kernel/kcmp.c
> index 5353edfad8e1..4fb23f242e0f 100644
> --- a/kernel/kcmp.c
> +++ b/kernel/kcmp.c
> @@ -63,6 +63,9 @@ get_file_raw_ptr(struct task_struct *task, unsigned int idx)
> {
> struct file *file;
>
> + /* This RCU locking is only present to silence warnings. The pointer
> + * value is only used for comparison and not dereferenced, so it is
> + * acceptable. */
> rcu_read_lock();
> file = task_lookup_fd_rcu(task, idx);
> rcu_read_unlock();
They are not wrong, this is just such a bit weird semantics where
we fetch the pointers and strictly speaking map them into numbers
set to compare. But I agree that such tricks might confuse. How about
/*
* Fetching file pointers inside RCU read-lock section
* and reuse them as plain numbers is done in a sake
* of speed. But make sure never dereference them after.
*/
?
next prev parent reply other threads:[~2022-02-02 17:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 15:17 [PATCH] kcmp: Comment get_file_raw_ptr() RCU usage Jason Andryuk
2022-02-02 17:44 ` Cyrill Gorcunov [this message]
2022-02-02 19:48 ` Jason Andryuk
2022-02-02 19:57 ` Cyrill Gorcunov
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=YfrC/fQvQ1nkIJNJ@grain \
--to=gorcunov@gmail.com \
--cc=ebiederm@xmission.com \
--cc=jandryuk@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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