Skip to content

Commit 29e74f3

Browse files
aeglKAGA-KOKO
authored andcommitted
x86/intel_rdt: Add diagnostics when writing the tasks file
About the only tricky case is trying to move a task into a monitor group that is a subdirectory of a different control group. But cover the simple cases too. Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Vikas Shivappa <[email protected]> Cc: Boris Petkov <[email protected]> Cc: Reinette Chatre <[email protected]> Link: https://lkml.kernel.org/r/f1841cce6a242aed37cb926dee8942727331bf78.1506382469.git.tony.luck@intel.com
1 parent c377dcf commit 29e74f3

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
232232
int closid, ret = 0;
233233

234234
/* Valid input requires a trailing newline */
235-
if (nbytes == 0 || buf[nbytes - 1] != '\n') {
236-
seq_buf_puts(&last_cmd_status, "no trailing newline\n");
235+
if (nbytes == 0 || buf[nbytes - 1] != '\n')
237236
return -EINVAL;
238-
}
239237
buf[nbytes - 1] = '\0';
240238

241239
rdtgrp = rdtgroup_kn_lock_live(of->kn);

arch/x86/kernel/cpu/intel_rdt_rdtgroup.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
478478
*/
479479
atomic_dec(&rdtgrp->waitcount);
480480
kfree(callback);
481+
rdt_last_cmd_puts("task exited\n");
481482
} else {
482483
/*
483484
* For ctrl_mon groups move both closid and rmid.
@@ -488,10 +489,12 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
488489
tsk->closid = rdtgrp->closid;
489490
tsk->rmid = rdtgrp->mon.rmid;
490491
} else if (rdtgrp->type == RDTMON_GROUP) {
491-
if (rdtgrp->mon.parent->closid == tsk->closid)
492+
if (rdtgrp->mon.parent->closid == tsk->closid) {
492493
tsk->rmid = rdtgrp->mon.rmid;
493-
else
494+
} else {
495+
rdt_last_cmd_puts("Can't move task to different control group\n");
494496
ret = -EINVAL;
497+
}
495498
}
496499
}
497500
return ret;
@@ -510,8 +513,10 @@ static int rdtgroup_task_write_permission(struct task_struct *task,
510513
*/
511514
if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
512515
!uid_eq(cred->euid, tcred->uid) &&
513-
!uid_eq(cred->euid, tcred->suid))
516+
!uid_eq(cred->euid, tcred->suid)) {
517+
rdt_last_cmd_printf("No permission to move task %d\n", task->pid);
514518
ret = -EPERM;
519+
}
515520

516521
put_cred(tcred);
517522
return ret;
@@ -528,6 +533,7 @@ static int rdtgroup_move_task(pid_t pid, struct rdtgroup *rdtgrp,
528533
tsk = find_task_by_vpid(pid);
529534
if (!tsk) {
530535
rcu_read_unlock();
536+
rdt_last_cmd_printf("No task %d\n", pid);
531537
return -ESRCH;
532538
}
533539
} else {
@@ -555,6 +561,7 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
555561
if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0)
556562
return -EINVAL;
557563
rdtgrp = rdtgroup_kn_lock_live(of->kn);
564+
rdt_last_cmd_clear();
558565

559566
if (rdtgrp)
560567
ret = rdtgroup_move_task(pid, rdtgrp, of);

0 commit comments

Comments
 (0)