Skip to contentSkip to conversation

sched: clarify ptrace's effect on task_struct->parent

PATCH Superseded Ziran Zhang 2 participants 8 messages Sep 10 – Nov 24 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: clarify ptrace's effect on task_struct->parent

The current comment for the parent field does not explain that it can be temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this important behavior.

No functional change.

---
 include/linux/sched.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/sched.h +5 -1
index 705970d07..977859a63 100644
@@ -1093,7 +1093,11 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/*
+	 * Recipient of SIGCHLD, wait4() reports. Normally the same as
+	 * real_parent, but temporarily replaced by the tracer while the
+	 * task is ptraced.
+	 */
 	struct task_struct __rcu	*parent;
 
 	/*
Signature · 1 line
2.51.0
#1 lore raw
Quoted 18 lines · Ziran Zhang

The current comment for the parent field does not explain that it can be temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this important behavior.

No functional change.

---
 include/linux/sched.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/sched.h +0 -0
index 705970d07..977859a63 100644

include/linux/sched.h struct task_struct { · line 1101

Quoted 10 lines
include/linux/sched.h +5 -1
@@ -1093,7 +1093,11 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/*
+	 * Recipient of SIGCHLD, wait4() reports. Normally the same as
+	 * real_parent, but temporarily replaced by the tracer while the
+	 * task is ptraced.
+	 */
 	struct task_struct __rcu	*parent;

Well. Not sure this comment needs to be updated...

Anyway, this looks like overdocumentation to me. Perhaps just

	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */

?

Oleg.

#2 lore raw
Quoted 9 lines · Oleg Nesterov

Well. Not sure this comment needs to be updated...

Anyway, this looks like overdocumentation to me. Perhaps just

	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */

?

Oleg.

Agreed, the long form is overdocumenting it. I'll send a v2 patch with your suggestion.

Best,
Ziran Zhang

#3 lore raw

PATCH v2 1/1 sched: clarify ptrace's effect on task_struct->parent

In reply to Ziran Zhang

The current comment for the parent field does not explain that it can be temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this important behavior.

No functional change.

---
Changes in v2:
- Use Oleg's minimal wording suggestion to adjust comment.

 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sched.h +1 -1
index 705970d07..8aad8a8ef 100644
@@ -1093,7 +1093,7 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */
 	struct task_struct __rcu	*parent;
 
 	/*
Signature · 1 line
2.51.0
#4 lore raw
Quoted 32 lines

The current comment for the parent field does not explain that it can be temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this important behavior.

No functional change.

---
Changes in v2:
- Use Oleg's minimal wording suggestion to adjust comment.

 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sched.h +1 -1
index 705970d07..8aad8a8ef 100644
@@ -1093,7 +1093,7 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */
 	struct task_struct __rcu	*parent;
 
 	/*
Signature · 1 line
2.51.0

Ping on this v2 patch. Suggested-by ptrace maintainer since September.

Sorry for the noise.

Thanks,
Ziran Zhang

Acked-by
#5 lore raw
Quoted 30 lines · Ziran Zhang
Quoted 30 lines

The current comment for the parent field does not explain that it can be temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this important behavior.

No functional change.

---
Changes in v2:
- Use Oleg's minimal wording suggestion to adjust comment.

 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sched.h +1 -1
index 705970d07..8aad8a8ef 100644
@@ -1093,7 +1093,7 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */
 	struct task_struct __rcu	*parent;
 
Quoted 5 lines
Quoted 3 lines
include/linux/sched.h +0 -1
 	/*
--

2.51.0

Ping on this v2 patch. Suggested-by ptrace maintainer since September.

Well, I only suggested to simplify the comment you proposed in V1 ;) So please remove the Suggested-by tag, feel free to add

#6 lore raw
Quoted 4 lines

Well, I only suggested to simplify the comment you proposed in V1 ;) So please remove the Suggested-by tag, feel free to add

Hi Oleg,

Thanks for the clarification. I'll drop the Suggested-by tag and add your Acked-by in v3.

Regards,
Ziran Zhang

#7 lore raw

PATCH v3 1/1 sched: clarify ptrace's effect on task_struct->parent

In reply to Ziran Zhang

The current comment for the parent field does not explain that it can be temporarily replaced by the tracer when the task is being ptraced.

This can lead to confusion, so clarify the comment to document this important behavior.

No functional change.

---
Changes in v3:
- Remove Suggested-by tag as requested by Oleg and add his Acked-by.

 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sched.h +1 -1
index 705970d07..8aad8a8ef 100644
@@ -1093,7 +1093,7 @@ struct task_struct {
 	/* Real parent process: */
 	struct task_struct __rcu	*real_parent;
 
-	/* Recipient of SIGCHLD, wait4() reports: */
+	/* Recipient of SIGCHLD, wait4() reports: ->real_parent or ptracer */
 	struct task_struct __rcu	*parent;
 
 	/*
Signature · 1 line
2.51.0