summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-11-15 09:09:04 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2026-11-15 09:09:04 -0800
commit0feaf5349e0a0521de3406343df32954801784d9 (patch)
treef292e3d410f8abeaac28a12d8d19ad5c2e6272a5
parentfc28723faec6c5eda0263b46e23dd89d5c29f464 (diff)
parentc1b96ba87e3caaa701d6dba254e58db7cc3c99be (diff)
Merge tag 'timers-urgent-2026-11-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer fixes from Ingo Molnar:: - Add VDSO_UNALIGNED_PACKED config option for targets without efficient unaligned memory accesses (such as ARMv5), and turn it on for !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS platforms. Propagate these changes into tooling headers as well (Ian Rogers) - Read getboottime64() offsets under the tk_core.seq sequence counter (Hungyu Lin) - Keep tsacct task begin times stable across suspend (Hungyu Lin) - Reject cross timestamps for invalid AUX clocks (Avi Weiss) - Refresh auxiliary timekeeper base before offset validation (Avi Weiss) * tag 'timers-urgent-2026-11-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: timekeeping: Refresh auxiliary base before offset validation timekeeping: Reject cross timestamps for invalid AUX clocks tsacct: Keep task begin times stable across suspend timekeeping: Read getboottime64() offsets under the sequence counter tools headers: Update the vdso/unaligned.h copy with the kernel sources vdso: Add VDSO_UNALIGNED_PACKED config option
-rw-r--r--include/vdso/unaligned.h16
-rw-r--r--kernel/time/timekeeping.c12
-rw-r--r--kernel/tsacct.c10
-rw-r--r--lib/vdso/Kconfig10
-rw-r--r--tools/include/vdso/unaligned.h16
5 files changed, 59 insertions, 5 deletions
diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
index 9076483c9fbb..726fd15efc82 100644
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -4,6 +4,20 @@
#include <linux/compiler_types.h>
+#ifdef CONFIG_VDSO_UNALIGNED_PACKED
+
+#define __get_unaligned_t(type, ptr) ({ \
+ const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
+ __get_pptr->x; \
+})
+
+#define __put_unaligned_t(type, val, ptr) do { \
+ struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \
+ __put_pptr->x = (val); \
+} while (0)
+
+#else /* !CONFIG_VDSO_UNALIGNED_PACKED */
+
/**
* __get_unaligned_t - read an unaligned value from memory.
* @type: the type to load from the pointer.
@@ -41,4 +55,6 @@
sizeof(__put_unaligned_val)); \
} while (0)
+#endif /* CONFIG_VDSO_UNALIGNED_PACKED */
+
#endif /* __VDSO_UNALIGNED_H */
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index dcf47f1ffdcf..be72cfd2b1ca 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1600,6 +1600,9 @@ int get_device_system_crosststamp(int (*get_time_fn)
do {
seq = read_seqcount_begin(&tkd->seq);
+ if (!tk->clock_valid)
+ return -ENODEV;
+
/*
* Try to synchronously capture device time and a system
* counter value calling back into the device driver
@@ -1775,6 +1778,7 @@ static int __timekeeping_inject_offset(struct tk_data *tkd, const struct timespe
struct tk_read_base *tkr_mono = &tks->tkr_mono;
ktime_t now, offs;
+ tk_update_ktime_data(tks);
/* Get the current time */
now = ktime_add_ns(tkr_mono->base, timekeeping_get_ns(tkr_mono));
/* Add the relative offset change */
@@ -2700,7 +2704,13 @@ void update_wall_time(void)
void getboottime64(struct timespec64 *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
- ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot);
+ unsigned int seq;
+ ktime_t t;
+
+ do {
+ seq = read_seqcount_begin(&tk_core.seq);
+ t = ktime_sub(tk->offs_real, tk->offs_boot);
+ } while (read_seqcount_retry(&tk_core.seq, seq));
*ts = ktime_to_timespec64(t);
}
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 5c153106e642..48320684c7c0 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -24,7 +24,7 @@ void bacct_add_tsk(struct user_namespace *user_ns,
const struct cred *tcred;
u64 utime, stime, utimescaled, stimescaled;
u64 now_ns, delta;
- time64_t btime;
+ struct timespec64 btime;
BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);
@@ -39,9 +39,11 @@ void bacct_add_tsk(struct user_namespace *user_ns,
do_div(delta, NSEC_PER_USEC);
stats->ac_etime = delta;
/* Convert to seconds for btime (note y2106 limit) */
- btime = ktime_get_real_seconds() - div_u64(delta, USEC_PER_SEC);
- stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX);
- stats->ac_btime64 = btime;
+ getboottime64(&btime);
+ btime = timespec64_add(btime, ns_to_timespec64(tsk->start_boottime));
+ stats->ac_btime = clamp_t(time64_t, btime.tv_sec, 0, U32_MAX);
+ /* Setting the clock back after suspend can make btime negative. */
+ stats->ac_btime64 = max_t(time64_t, btime.tv_sec, 0);
if (tsk->flags & PF_EXITING)
stats->ac_exitcode = tsk->exit_code;
diff --git a/lib/vdso/Kconfig b/lib/vdso/Kconfig
index 597f5f0f9681..2436c20ee0ef 100644
--- a/lib/vdso/Kconfig
+++ b/lib/vdso/Kconfig
@@ -23,3 +23,13 @@ config VDSO_GETRANDOM
select VDSO_DATASTORE
help
Selected by architectures that support vDSO getrandom().
+
+config VDSO_UNALIGNED_PACKED
+ bool
+ default !HAVE_EFFICIENT_UNALIGNED_ACCESS
+ help
+ Use packed structs rather than memcpy() in include/vdso/unaligned.h
+ for unaligned memory accesses. Enabled by default when the
+ architecture does not have efficient unaligned accesses, as GCC may
+ emit stack spills or out-of-line memcpy() calls instead of inlining
+ byte shifts.
diff --git a/tools/include/vdso/unaligned.h b/tools/include/vdso/unaligned.h
index 9076483c9fbb..726fd15efc82 100644
--- a/tools/include/vdso/unaligned.h
+++ b/tools/include/vdso/unaligned.h
@@ -4,6 +4,20 @@
#include <linux/compiler_types.h>
+#ifdef CONFIG_VDSO_UNALIGNED_PACKED
+
+#define __get_unaligned_t(type, ptr) ({ \
+ const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
+ __get_pptr->x; \
+})
+
+#define __put_unaligned_t(type, val, ptr) do { \
+ struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \
+ __put_pptr->x = (val); \
+} while (0)
+
+#else /* !CONFIG_VDSO_UNALIGNED_PACKED */
+
/**
* __get_unaligned_t - read an unaligned value from memory.
* @type: the type to load from the pointer.
@@ -41,4 +55,6 @@
sizeof(__put_unaligned_val)); \
} while (0)
+#endif /* CONFIG_VDSO_UNALIGNED_PACKED */
+
#endif /* __VDSO_UNALIGNED_H */