Skip to contentSkip to conversation

sched/core: add rcu_read_lock/unlock() protection

PATCH In review [email protected] 2 participants 3 messages Jan 26, 2021 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: add rcu_read_lock/unlock() protection

From: Zqiang <[email protected]>

Due to for_each_process_thread belongs to RCU read operation, need to add rcu_read_lock/unlock() protection.

---
 kernel/sched/core.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/core.c +2 -0
index 8c5481077c9c..c3f0103fdf53 100644
@@ -7738,6 +7738,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 	lockdep_assert_held(&rq->lock);
 
 	printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
+	rcu_read_lock();
 	for_each_process_thread(g, p) {
 		if (task_cpu(p) != cpu)
 			continue;
@@ -7747,6 +7748,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 
 		printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
 	}
+	rcu_read_unlock();
 }
 
 int sched_cpu_dying(unsigned int cpu)
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 23 lines · On Tue, Jan 26, 2021 at 04:46:51PM +0800, [email protected] wrote:

From: Zqiang <[email protected]>

Due to for_each_process_thread belongs to RCU read operation, need to add rcu_read_lock/unlock() protection.

---
 kernel/sched/core.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/core.c +1 -0
index 8c5481077c9c..c3f0103fdf53 100644
@@ -7738,6 +7738,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 	lockdep_assert_held(&rq->lock);
 
 	printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
+	rcu_read_lock();
 	for_each_process_thread(g, p) {
 		if (task_cpu(p) != cpu)
 			continue;

kernel/sched/core.c static void dump_rq_tasks(struct rq *rq, const char *loglvl) · line 7751

Quoted 4 lines
kernel/sched/core.c +1 -0
@@ -7747,6 +7748,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 
 		printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
 	}
+	rcu_read_unlock();

We're in stop machine, with IRQs disabled, please explain how this can make any difference?

#2 lore raw
In reply to [email protected]

________________________________________
发件人: Zhang, Qiang <[email protected]>
发送时间: 2021年1月26日 16:29
收件人: [email protected]
抄送: [email protected]; [email protected] 主题: [PATCH] sched/core: add rcu_read_lock/unlock() protection

Quoted 4 lines

From: Zqiang <[email protected]>

Due to for_each_process_thread belongs to RCU read operation, need to add rcu_read_lock/unlock() protection.

Sorry to disturb you
I find it's already in the RCU critical zone
Please ignore this change

Quoted 18 lines

---
kernel/sched/core.c | 2 ++

1 file changed, 2 insertions(+)
kernel/sched/core.c +1 -0
index 8c5481077c9c..c3f0103fdf53 100644
@@ -7738,6 +7738,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
       lockdep_assert_held(&rq->lock);
 
       printk("%sCPU%d enqueued tasks (%u total):\n", loglvl, cpu, rq->nr_running);
+       rcu_read_lock();
       for_each_process_thread(g, p) {
               if (task_cpu(p) != cpu)
                       continue;

kernel/sched/core.c static void dump_rq_tasks(struct rq *rq, const char *loglvl) · line 7754

Quoted 7 lines
kernel/sched/core.c +1 -0
@@ -7747,6 +7748,7 @@ static void dump_rq_tasks(struct rq *rq, const char *loglvl)
 
               printk("%s\tpid: %d, name: %s\n", loglvl, p->pid, p->comm);
       }
+       rcu_read_unlock();
 }
 
 int sched_cpu_dying(unsigned int cpu)

--
2.17.1