Skip to contentSkip to conversation

kcmp: Comment get_file_raw_ptr() RCU usage

PATCH In review Jason Andryuk 2 participants 2 messages Feb 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kcmp: Comment get_file_raw_ptr() RCU usage

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.

---
v2:
Rephrase comment and tweak commit message. (Cyrill)

 kernel/kcmp.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/kcmp.c +5 -0
index 5353edfad8e1..04874c7ac0ab 100644
@@ -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();
Signature · 1 line
2.34.1
Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · 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.

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