lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250513145137.740202418@linutronix.de>
Date: Tue, 13 May 2025 17:13:28 +0200 (CEST)
From: Thomas Gleixner <tglx@...utronix.de>
To: LKML <linux-kernel@...r.kernel.org>
Cc: netdev@...r.kernel.org,
 Richard Cochran <richardcochran@...il.com>,
 Christopher Hall <christopher.s.hall@...el.com>,
 David Zage <david.zage@...el.com>,
 John Stultz <jstultz@...gle.com>,
 Frederic Weisbecker <frederic@...nel.org>,
 Anna-Maria Behnsen <anna-maria@...utronix.de>,
 Miroslav Lichvar <mlichvar@...hat.com>,
 Werner Abt <werner.abt@...nberg-usa.com>,
 David Woodhouse <dwmw2@...radead.org>,
 Stephen Boyd <sboyd@...nel.org>,
 Thomas Weißschuh <thomas.weissschuh@...utronix.de>,
 Kurt Kanzenbach <kurt@...utronix.de>,
 Nam Cao <namcao@...utronix.de>,
 Alex Gieringer <gieri@...utronix.de>
Subject: [patch 18/26] timekeeping: Add minimal posix-timers support for PTP
 clocks

Provide clock_getres(2) and clock_gettime(2) for PTP clocks.

Signed-off-by: Thomas Gleixner <tglx@...utronix.de>

---
 kernel/time/posix-timers.c |    3 +++
 kernel/time/posix-timers.h |    1 +
 kernel/time/timekeeping.c  |   21 +++++++++++++++++++++
 3 files changed, 25 insertions(+)
---
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1526,6 +1526,9 @@ static const struct k_clock * const posi
 	[CLOCK_REALTIME_ALARM]		= &alarm_clock,
 	[CLOCK_BOOTTIME_ALARM]		= &alarm_clock,
 	[CLOCK_TAI]			= &clock_tai,
+#ifdef CONFIG_POSIX_PTP_CLOCKS
+	[CLOCK_PTP ... CLOCK_PTP_LAST]	= &clock_ptp,
+#endif
 };
 
 static const struct k_clock *clockid_to_kclock(const clockid_t id)
--- a/kernel/time/posix-timers.h
+++ b/kernel/time/posix-timers.h
@@ -41,6 +41,7 @@ extern const struct k_clock clock_posix_
 extern const struct k_clock clock_process;
 extern const struct k_clock clock_thread;
 extern const struct k_clock alarm_clock;
+extern const struct k_clock clock_ptp;
 
 void posix_timer_queue_signal(struct k_itimer *timr);
 
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -2655,6 +2655,7 @@ EXPORT_SYMBOL(hardpps);
 #endif /* CONFIG_NTP_PPS */
 
 #ifdef CONFIG_POSIX_PTP_CLOCKS
+#include "posix-timers.h"
 
 /* Bitmap for the activated PTP timekeepers */
 static unsigned long ptp_timekeepers;
@@ -2741,6 +2742,26 @@ bool ktime_get_ptp_ts64(clockid_t id, st
 	return true;
 }
 
+static int ptp_get_res(clockid_t id, struct timespec64 *tp)
+{
+	if (!ptp_valid_clockid(id))
+		return -ENODEV;
+
+	tp->tv_sec = 0;
+	tp->tv_nsec = 1;
+	return 0;
+}
+
+static int ptp_get_timespec(clockid_t id, struct timespec64 *tp)
+{
+	return ktime_get_ptp_ts64(id, tp) ? 0 : -ENODEV;
+}
+
+const struct k_clock clock_ptp = {
+	.clock_getres		= ptp_get_res,
+	.clock_get_timespec	= ptp_get_timespec,
+};
+
 static __init void tk_ptp_setup(void)
 {
 	for (int i = TIMEKEEPER_PTP; i <= TIMEKEEPER_PTP_LAST; i++)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ