* [PATCH v2] timekeeping: Always initialize use_nsecs when querying time from phc drivers
@ 2025-07-20 13:54 Markus Blöchl
2025-07-22 0:33 ` John Stultz
2025-07-22 12:37 ` [tip: timers/urgent] timekeeping: Zero initialize system_counterval " tip-bot2 for Markus Blöchl
0 siblings, 2 replies; 3+ messages in thread
From: Markus Blöchl @ 2025-07-20 13:54 UTC (permalink / raw)
To: Thomas Gleixner, John Stultz
Cc: Stephen Boyd, Lakshmi Sowjanya D, Christopher S. Hall, netdev,
linux-kernel, markus.bloechl, Markus Blöchl
Most drivers only populate the fields cycles and cs_id in their
get_time_fn() callback for get_device_system_crosststamp() unless
they explicitly provide nanosecond values.
When this new use_nsecs field was added and used most drivers did not
care.
Clock sources other than CSID_GENERIC could then get converted in
convert_base_to_cs() based on an uninitialized use_nsecs which usually
results in -EINVAL during the following range check.
Pass in a fully initialized system_counterval_t.
Fixes: 6b2e29977518 ("timekeeping: Provide infrastructure for converting to/from a base clock")
Cc: stable@vger.kernel.org
Signed-off-by: Markus Blöchl <markus@blochl.de>
---
Changes in v2:
- Initialize entire system_counterval_t, not just use_nsecs
- Only initialize system_counterval_t once during instantiation instead
of every iteration.
- Link to v1: https://lore.kernel.org/lkml/txyrr26hxe3xpq3ebqb5ewkgvhvp7xalotaouwludjtjifnah2@7tmgczln4aoo/
---
kernel/time/timekeeping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index a009c91f7b05fcb433073862a1b1a3de0345bffe..83c65f3afccaacff7a2e53e62f32657c201fbc8c 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1256,7 +1256,7 @@ int get_device_system_crosststamp(int (*get_time_fn)
struct system_time_snapshot *history_begin,
struct system_device_crosststamp *xtstamp)
{
- struct system_counterval_t system_counterval;
+ struct system_counterval_t system_counterval = {};
struct timekeeper *tk = &tk_core.timekeeper;
u64 cycles, now, interval_start;
unsigned int clock_was_set_seq = 0;
---
base-commit: f4a40a4282f467ec99745c6ba62cb84346e42139
change-id: 20250720-timekeeping_uninit_crossts-c130ee69fb1e
Best regards,
--
Markus Blöchl <markus@blochl.de>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] timekeeping: Always initialize use_nsecs when querying time from phc drivers
2025-07-20 13:54 [PATCH v2] timekeeping: Always initialize use_nsecs when querying time from phc drivers Markus Blöchl
@ 2025-07-22 0:33 ` John Stultz
2025-07-22 12:37 ` [tip: timers/urgent] timekeeping: Zero initialize system_counterval " tip-bot2 for Markus Blöchl
1 sibling, 0 replies; 3+ messages in thread
From: John Stultz @ 2025-07-22 0:33 UTC (permalink / raw)
To: Markus Blöchl
Cc: Thomas Gleixner, Stephen Boyd, Lakshmi Sowjanya D,
Christopher S. Hall, netdev, linux-kernel, markus.bloechl
On Sun, Jul 20, 2025 at 6:56 AM Markus Blöchl <markus@blochl.de> wrote:
>
> Most drivers only populate the fields cycles and cs_id in their
> get_time_fn() callback for get_device_system_crosststamp() unless
> they explicitly provide nanosecond values.
> When this new use_nsecs field was added and used most drivers did not
> care.
> Clock sources other than CSID_GENERIC could then get converted in
> convert_base_to_cs() based on an uninitialized use_nsecs which usually
> results in -EINVAL during the following range check.
>
> Pass in a fully initialized system_counterval_t.
>
> Fixes: 6b2e29977518 ("timekeeping: Provide infrastructure for converting to/from a base clock")
> Cc: stable@vger.kernel.org
> Signed-off-by: Markus Blöchl <markus@blochl.de>
Sounds good. Sorry for sending you down the wrong path, and thanks to
tglx for lighting the way. :)
Acked-by: John Stultz <jstultz@google.com>
thanks
-john
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: timers/urgent] timekeeping: Zero initialize system_counterval when querying time from phc drivers
2025-07-20 13:54 [PATCH v2] timekeeping: Always initialize use_nsecs when querying time from phc drivers Markus Blöchl
2025-07-22 0:33 ` John Stultz
@ 2025-07-22 12:37 ` tip-bot2 for Markus Blöchl
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Markus Blöchl @ 2025-07-22 12:37 UTC (permalink / raw)
To: linux-tip-commits
Cc: markus, Thomas Gleixner, John Stultz, stable, x86, linux-kernel
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 67c632b4a7fbd6b76a08b86f4950f0f84de93439
Gitweb: https://git.kernel.org/tip/67c632b4a7fbd6b76a08b86f4950f0f84de93439
Author: Markus Blöchl <markus@blochl.de>
AuthorDate: Sun, 20 Jul 2025 15:54:51 +02:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Tue, 22 Jul 2025 14:25:21 +02:00
timekeeping: Zero initialize system_counterval when querying time from phc drivers
Most drivers only populate the fields cycles and cs_id of system_counterval
in their get_time_fn() callback for get_device_system_crosststamp(), unless
they explicitly provide nanosecond values.
When the use_nsecs field was added to struct system_counterval, most
drivers did not care. Clock sources other than CSID_GENERIC could then get
converted in convert_base_to_cs() based on an uninitialized use_nsecs field,
which usually results in -EINVAL during the following range check.
Pass in a fully zero initialized system_counterval_t to cure that.
Fixes: 6b2e29977518 ("timekeeping: Provide infrastructure for converting to/from a base clock")
Signed-off-by: Markus Blöchl <markus@blochl.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20250720-timekeeping_uninit_crossts-v2-1-f513c885b7c2@blochl.de
---
kernel/time/timekeeping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index a009c91..83c65f3 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1256,7 +1256,7 @@ int get_device_system_crosststamp(int (*get_time_fn)
struct system_time_snapshot *history_begin,
struct system_device_crosststamp *xtstamp)
{
- struct system_counterval_t system_counterval;
+ struct system_counterval_t system_counterval = {};
struct timekeeper *tk = &tk_core.timekeeper;
u64 cycles, now, interval_start;
unsigned int clock_was_set_seq = 0;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-22 12:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20 13:54 [PATCH v2] timekeeping: Always initialize use_nsecs when querying time from phc drivers Markus Blöchl
2025-07-22 0:33 ` John Stultz
2025-07-22 12:37 ` [tip: timers/urgent] timekeeping: Zero initialize system_counterval " tip-bot2 for Markus Blöchl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).