netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [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
  0 siblings, 1 reply; 2+ 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] 2+ 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
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2025-07-22  0:33 UTC | newest]

Thread overview: 2+ 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

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).