All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage
@ 2022-02-03 13:31 Jason Andryuk
  2022-02-03 13:58 ` Cyrill Gorcunov
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Andryuk @ 2022-02-03 13:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Eric W . Biederman, Cyrill Gorcunov, Jason Andryuk

This usage of RCU appears wrong since the pointer is passed outside the
RCU region.  However, it is only used as a number and 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>
---
v2:
Rephrase comment and tweak commit message.  (Cyrill)

 kernel/kcmp.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/kcmp.c b/kernel/kcmp.c
index 5353edfad8e1..04874c7ac0ab 100644
--- a/kernel/kcmp.c
+++ b/kernel/kcmp.c
@@ -63,6 +63,11 @@ get_file_raw_ptr(struct task_struct *task, unsigned int idx)
 {
 	struct file *file;
 
+	/*
+	 * Fetch file pointers inside RCU read-lock section, but
+	 * skip additional locking for speed.  The pointer values
+	 * will be used as integers and must not be dereferenced.
+	 */
 	rcu_read_lock();
 	file = task_lookup_fd_rcu(task, idx);
 	rcu_read_unlock();
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage
  2022-02-03 13:31 [PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage Jason Andryuk
@ 2022-02-03 13:58 ` Cyrill Gorcunov
  0 siblings, 0 replies; 2+ messages in thread
From: Cyrill Gorcunov @ 2022-02-03 13:58 UTC (permalink / raw)
  To: Jason Andryuk; +Cc: linux-kernel, Eric W . Biederman

On Thu, Feb 03, 2022 at 08:31:34AM -0500, Jason Andryuk wrote:
> This usage of RCU appears wrong since the pointer is passed outside the
> RCU region.  However, it is only used as a number and 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>

Looks ok to me, thanks a lot! I should put somthing similar a way
earlier when this code been developed. I must confess I'm not a big
fan of merging comments-only commits (since they affect git history),
but since it brings more understanding into what the code is doing

Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-03 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 13:31 [PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage Jason Andryuk
2022-02-03 13:58 ` Cyrill Gorcunov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.