[PATCH v2 2/3] sched/debug: Mark a truncated group path at the start
From: Chris Down
Date: Sun Nov 29 2026 - 00:38:41 EST
When another reader holds sched_debug_lock,
SEQ_printf_task_group_path() builds the group path in a 128 byte buffer
on the stack, and writes "..." over the end of it in case the path
filled it. Since the previous commit, cgroup_path() keeps the end of a
path, so a long path now prints as its last 124 bytes followed by "...",
which suggests the end was cut off when it was the start.
Let's have task_group_path() put the "..." at the start when
cgroup_path() returns -E2BIG, and drop the suffix.
Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx>
---
kernel/sched/debug.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index e6a3b516c703..b5ed9eeecd49 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -935,15 +935,15 @@ static void task_group_path(struct task_group *tg, char *path, int plen)
if (autogroup_path(tg, path, plen))
return;
- cgroup_path(tg->css.cgroup, path, plen);
+ /* An overlong path keeps its end, so mark the start as cut off. */
+ if (cgroup_path(tg->css.cgroup, path, plen) == -E2BIG)
+ memcpy(path, "...", 3);
}
/*
* Only 1 SEQ_printf_task_group_path() caller can use the full length
* group_path[] for cgroup path. Other simultaneous callers will have
- * to use a shorter stack buffer. A "..." suffix is appended at the end
- * of the stack buffer so that it will show up in case the output length
- * matches the given buffer size to indicate possible path name truncation.
+ * to use a shorter stack buffer.
*/
#define SEQ_printf_task_group_path(m, tg, fmt...) \
{ \
@@ -953,9 +953,7 @@ static void task_group_path(struct task_group *tg, char *path, int plen)
spin_unlock(&sched_debug_lock); \
} else { \
char buf[128]; \
- char *bufend = buf + sizeof(buf) - 3; \
- task_group_path(tg, buf, bufend - buf); \
- strcpy(bufend - 1, "..."); \
+ task_group_path(tg, buf, sizeof(buf)); \
SEQ_printf(m, fmt, buf); \
} \
}
--
2.56.1