Skip to contentSkip to conversation

delayacct: fix uapi timespec64 definition

PATCH Applied Arnd Bergmann 5 participants 5 messages Feb 2 – Feb 13 Per-task delay accounting

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 delayacct: fix uapi timespec64 definition

From: Arnd Bergmann <[email protected]>

The custom definition of 'struct timespec64' is incompatible with both the kernel's internal definition and the glibc type, at least on big-endian targets that have the tv_nsec field in a different place, and the definition clashes with any userspace that also defines a timespec64 structure.

Running the header check with -Wpadding enabled produces this output that warns about the incorrect padding:

usr/include/linux/taskstats.h:25:1: error: padding struct size to alignment boundary with 4 bytes [-Werror=padded]

Remove the hack and instead use the regular __kernel_timespec type that is meant to be used in uapi definitions.

Fixes 29b63f6eff0e ("delayacct: add timestamp of delay max")
---
 include/uapi/linux/taskstats.h | 27 +++++++++------------------
 kernel/delayacct.c             |  6 ++++--
 2 files changed, 13 insertions(+), 20 deletions(-)
include/uapi/linux/taskstats.h +9 -18
index a66b2d84a310..cc7fccd57979 100644
@@ -18,16 +18,7 @@
 #define _LINUX_TASKSTATS_H
 
 #include <linux/types.h>
-#ifdef __KERNEL__
-#include <linux/time64.h>
-#else
-#ifndef _LINUX_TIME64_H
-struct timespec64 {
-	__s64   tv_sec;         /* seconds */
-	long    tv_nsec;        /* nanoseconds */
-};
-#endif
-#endif
+#include <linux/time_types.h>
 
 /* Format for per-task data returned to userland when
  *	- a task exits
@@ -251,14 +242,14 @@ struct taskstats {
 	__u64	irq_delay_min;
 
 	/*v17: delay max timestamp record*/
-	struct timespec64 cpu_delay_max_ts;
-	struct timespec64 blkio_delay_max_ts;
-	struct timespec64 swapin_delay_max_ts;
-	struct timespec64 freepages_delay_max_ts;
-	struct timespec64 thrashing_delay_max_ts;
-	struct timespec64 compact_delay_max_ts;
-	struct timespec64 wpcopy_delay_max_ts;
-	struct timespec64 irq_delay_max_ts;
+	struct __kernel_timespec cpu_delay_max_ts;
+	struct __kernel_timespec blkio_delay_max_ts;
+	struct __kernel_timespec swapin_delay_max_ts;
+	struct __kernel_timespec freepages_delay_max_ts;
+	struct __kernel_timespec thrashing_delay_max_ts;
+	struct __kernel_timespec compact_delay_max_ts;
+	struct __kernel_timespec wpcopy_delay_max_ts;
+	struct __kernel_timespec irq_delay_max_ts;
 } __uapi_arch_align;
 
 
kernel/delayacct.c +4 -2
index d58ffc63bcba..2e55c493c98b 100644
@@ -18,7 +18,8 @@
 do { \
 	d->type##_delay_max = tsk->delays->type##_delay_max; \
 	d->type##_delay_min = tsk->delays->type##_delay_min; \
-	d->type##_delay_max_ts = tsk->delays->type##_delay_max_ts; \
+	d->type##_delay_max_ts.tv_sec = tsk->delays->type##_delay_max_ts.tv_sec; \
+	d->type##_delay_max_ts.tv_nsec = tsk->delays->type##_delay_max_ts.tv_nsec; \
 	tmp = d->type##_delay_total + tsk->delays->type##_delay; \
 	d->type##_delay_total = (tmp < d->type##_delay_total) ? 0 : tmp; \
 	d->type##_count += tsk->delays->type##_count; \
@@ -175,7 +176,8 @@ int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
 
 	d->cpu_delay_max = tsk->sched_info.max_run_delay;
 	d->cpu_delay_min = tsk->sched_info.min_run_delay;
-	d->cpu_delay_max_ts = tsk->sched_info.max_run_delay_ts;
+	d->cpu_delay_max_ts.tv_sec = tsk->sched_info.max_run_delay_ts.tv_sec;
+	d->cpu_delay_max_ts.tv_nsec = tsk->sched_info.max_run_delay_ts.tv_nsec;
 	tmp = (s64)d->cpu_delay_total + t2;
 	d->cpu_delay_total = (tmp < (s64)d->cpu_delay_total) ? 0 : tmp;
 	tmp = (s64)d->cpu_run_virtual_total + t3;
Signature · 1 line
2.39.5
#1 lore raw
Quoted 11 lines

From: Arnd Bergmann <[email protected]>

The custom definition of 'struct timespec64' is incompatible with both the kernel's internal definition and the glibc type, at least on big-endian targets that have the tv_nsec field in a different place, and the definition clashes with any userspace that also defines a timespec64 structure.

Running the header check with -Wpadding enabled produces this output that warns about the incorrect padding:

Quoted 7 lines

usr/include/linux/taskstats.h:25:1: error: padding struct size to alignment boundary with 4 bytes >[-Werror=padded]

Remove the hack and instead use the regular __kernel_timespec type that is meant to be used in uapi definitions.

Fixes 29b63f6eff0e ("delayacct: add timestamp of delay max")

In uapi definition, __kernel_timespec is indeed a better solution compared to timespec64, as the former provides superior binary compatibility, nice job!

Thanks
Yaxin

#2 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · On Mon, 2 Feb 2026 10:59:00 +0100 Arnd Bergmann <[email protected]> wrote:

From: Arnd Bergmann <[email protected]>

The custom definition of 'struct timespec64' is incompatible with both the kernel's internal definition and the glibc type, at least on big-endian targets that have the tv_nsec field in a different place, and the definition clashes with any userspace that also defines a timespec64 structure.

Quoted 8 lines

Running the header check with -Wpadding enabled produces this output that warns about the incorrect padding:

usr/include/linux/taskstats.h:25:1: error: padding struct size to alignment boundary with 4 bytes [-Werror=padded]

Remove the hack and instead use the regular __kernel_timespec type that is meant to be used in uapi definitions.

Thanks.

Quoted 11 lines
include/uapi/linux/taskstats.h +0 -7
@@ -251,14 +242,14 @@ struct taskstats {
 	__u64	irq_delay_min;
 
 	/*v17: delay max timestamp record*/
-	struct timespec64 cpu_delay_max_ts;
-	struct timespec64 blkio_delay_max_ts;
-	struct timespec64 swapin_delay_max_ts;
-	struct timespec64 freepages_delay_max_ts;
-	struct timespec64 thrashing_delay_max_ts;
-	struct timespec64 compact_delay_max_ts;
-	struct timespec64 wpcopy_delay_max_ts;

include/uapi/linux/taskstats.h struct taskstats { · line 253

Quoted 10 lines
include/uapi/linux/taskstats.h +8 -1
-	struct timespec64 irq_delay_max_ts;
+	struct __kernel_timespec cpu_delay_max_ts;
+	struct __kernel_timespec blkio_delay_max_ts;
+	struct __kernel_timespec swapin_delay_max_ts;
+	struct __kernel_timespec freepages_delay_max_ts;
+	struct __kernel_timespec thrashing_delay_max_ts;
+	struct __kernel_timespec compact_delay_max_ts;
+	struct __kernel_timespec wpcopy_delay_max_ts;
+	struct __kernel_timespec irq_delay_max_ts;
 } __uapi_arch_align;

There's no __uapi_arch_align here in any tree I looked at?

#3 lore raw
Quoted 12 lines · Andrew Morton
Quoted 12 lines
include/uapi/linux/taskstats.h +3 -8
 	/*v17: delay max timestamp record*/
-	struct timespec64 cpu_delay_max_ts;
-	struct timespec64 blkio_delay_max_ts;
-	struct timespec64 swapin_delay_max_ts;
-	struct timespec64 freepages_delay_max_ts;
-	struct timespec64 thrashing_delay_max_ts;
-	struct timespec64 compact_delay_max_ts;
-	struct timespec64 wpcopy_delay_max_ts;
-	struct timespec64 irq_delay_max_ts;
+	struct __kernel_timespec cpu_delay_max_ts;
+	struct __kernel_timespec blkio_delay_max_ts;
+	struct __kernel_timespec swapin_delay_max_ts;
Quoted 8 lines

include/uapi/linux/taskstats.h struct taskstats { · line 253

Quoted 6 lines
include/uapi/linux/taskstats.h +5 -0
+	struct __kernel_timespec freepages_delay_max_ts;
+	struct __kernel_timespec thrashing_delay_max_ts;
+	struct __kernel_timespec compact_delay_max_ts;
+	struct __kernel_timespec wpcopy_delay_max_ts;
+	struct __kernel_timespec irq_delay_max_ts;
 } __uapi_arch_align;

There's no __uapi_arch_align here in any tree I looked at?

My mistake, that was a remnant of a work-in-progress series that I used to detect unintended padding in uapi structures.

Thanks for fixing up the patch and applying the correct version.

Arnd

#4 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The custom definition of 'struct timespec64' is incompatible with both the kernel's internal definition and the glibc type, at least on big-endian targets that have the tv_nsec field in a different place, and the definition clashes with any userspace that also defines a timespec64 structure.

Running the header check with -Wpadding enabled produces this output that warns about the incorrect padding:

Quoted 6 lines

usr/include/linux/taskstats.h:25:1: error: padding struct size to alignment boundary with 4 bytes [-Werror=padded]

Remove the hack and instead use the regular __kernel_timespec type that is meant to be used in uapi definitions.

Fixes 29b63f6eff0e ("delayacct: add timestamp of delay max")

JFTR, this commit was rebased, and is now commit 503efe850c7463a1 ("delayacct: add timestamp of delay max") upstream.

Fixes 503efe850c7463a1 ("delayacct: add timestamp of delay max")
Quoted 1 line

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds