Skip to contentSkip to conversation

cgroup: Properly init nr_tasks in cgroup_taskset

PATCH In review Waiman Long 2 participants 3 messages Sep 14, 2017 – Sep 15, 2017 cgroup

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup: Properly init nr_tasks in cgroup_taskset

Commit 610467270fb3 ("cgroup: don't call migration methods if there are no tasks to migrate") introduces a new field nr_tasks to the cgroup_taskset structure for keeping track of the number of tasks contained in the structure. The initial value of this field, however, is not guaranteed to be 0 as all the cgroup_taskset structures are allocated from stack. Therefore, we need to explicitly initilized it in the CGROUP_TASKSET_INIT() macro for the new code to behave correctly.

---
 kernel/cgroup/cgroup-internal.h | 1 +
 1 file changed, 1 insertion(+)
kernel/cgroup/cgroup-internal.h +1 -0
index 5151ff2..6b4c04e 100644
@@ -76,6 +76,7 @@ struct cgroup_mgctx {
 	.src_csets		= LIST_HEAD_INIT(tset.src_csets),		\
 	.dst_csets		= LIST_HEAD_INIT(tset.dst_csets),		\
 	.csets			= &tset.src_csets,				\
+	.nr_tasks		= 0,						\
 }
 
 #define CGROUP_MGCTX_INIT(name)							\
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw

Hello, Waiman.

Quoted 19 lines · Waiman Long

Commit 610467270fb3 ("cgroup: don't call migration methods if there are no tasks to migrate") introduces a new field nr_tasks to the cgroup_taskset structure for keeping track of the number of tasks contained in the structure. The initial value of this field, however, is not guaranteed to be 0 as all the cgroup_taskset structures are allocated from stack. Therefore, we need to explicitly initilized it in the CGROUP_TASKSET_INIT() macro for the new code to behave correctly.

---
 kernel/cgroup/cgroup-internal.h | 1 +
 1 file changed, 1 insertion(+)
kernel/cgroup/cgroup-internal.h +0 -0
index 5151ff2..6b4c04e 100644

kernel/cgroup/cgroup-internal.h struct cgroup_mgctx { · line 79

Quoted 4 lines
kernel/cgroup/cgroup-internal.h +1 -0
@@ -76,6 +76,7 @@ struct cgroup_mgctx {
 	.src_csets		= LIST_HEAD_INIT(tset.src_csets),		\
 	.dst_csets		= LIST_HEAD_INIT(tset.dst_csets),		\
 	.csets			= &tset.src_csets,				\
+	.nr_tasks		= 0,						\

But it's an initialization macro, which means that the only way these are used is as a part of whole struct initialization and the compiler would always set the unspecified fields to zero.

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 30 lines · Tejun Heo

Hello, Waiman.

Quoted 19 lines · Waiman Long

Commit 610467270fb3 ("cgroup: don't call migration methods if there are no tasks to migrate") introduces a new field nr_tasks to the cgroup_taskset structure for keeping track of the number of tasks contained in the structure. The initial value of this field, however, is not guaranteed to be 0 as all the cgroup_taskset structures are allocated from stack. Therefore, we need to explicitly initilized it in the CGROUP_TASKSET_INIT() macro for the new code to behave correctly.

---
 kernel/cgroup/cgroup-internal.h | 1 +
 1 file changed, 1 insertion(+)
kernel/cgroup/cgroup-internal.h +0 -0
index 5151ff2..6b4c04e 100644

kernel/cgroup/cgroup-internal.h struct cgroup_mgctx { · line 79

Quoted 4 lines
kernel/cgroup/cgroup-internal.h +1 -0
@@ -76,6 +76,7 @@ struct cgroup_mgctx {
 	.src_csets		= LIST_HEAD_INIT(tset.src_csets),		\
 	.dst_csets		= LIST_HEAD_INIT(tset.dst_csets),		\
 	.csets			= &tset.src_csets,	Y			\
+	.nr_tasks		= 0,						\

But it's an initialization macro, which means that the only way thhese are used is as a part of whole struct initialization and the compiler would always set the unspecified fields to zero.

Quoted 2 lines

Thanks.

You are right. I checked the assembly code and it did initialize the other fields of the structure to 0. So my fix is bogus.

I sent this patch out because our QE people were still seeing the same panic in PPC machines even with your patch applied. So I mistakenly thought maybe the structure initialization wasn't complete. I will have to further into why this was still happening.

Sorry for bothering you.

Cheers,
Longman