Skip to contentSkip to conversation

x86/resctrl: Only show tasks' pid in current pid namespace

PATCH In review Shawn Wang 2 participants 2 messages May 15, 2023 – May 16, 2023

Subsystems (2)
lore
Share & tools
lore

Shawn Wang

author
#0 lore raw

PATCH v2 1/1 x86/resctrl: Only show tasks' pid in current pid namespace

When writing a task id to the "tasks" file in an rdtgroup, rdtgroup_tasks_write() treats the pid as a number in the current pid namespace. But when reading the "tasks" file, rdtgroup_tasks_show() shows the list of global pids from the init namespace, which is confusing and incorrect.

To be more robust, let the "tasks" file only show pids in the current pid namespace.

---
Changes since v1:
- Update commit message and commit tags.

 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -2
index 6ad33f355861..61cdd9b1bb6d 100644
@@ -726,11 +726,15 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
 static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
 {
 	struct task_struct *p, *t;
+	pid_t pid;
 
 	rcu_read_lock();
 	for_each_process_thread(p, t) {
-		if (is_closid_match(t, r) || is_rmid_match(t, r))
-			seq_printf(s, "%d\n", t->pid);
+		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
+			pid = task_pid_vnr(t);
+			if (pid)
+				seq_printf(s, "%d\n", pid);
+		}
 	}
 	rcu_read_unlock();
 }
Signature · 1 line
2.31.1
Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · Shawn Wang

When writing a task id to the "tasks" file in an rdtgroup, rdtgroup_tasks_write() treats the pid as a number in the current pid namespace. But when reading the "tasks" file, rdtgroup_tasks_show() shows the list of global pids from the init namespace, which is confusing and incorrect.

Quoted 8 lines

To be more robust, let the "tasks" file only show pids in the current pid namespace.

Thanks.

-Fenghua