From nobody Wed Oct 8 16:03:41 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 383FE21CC62; Thu, 26 Jun 2025 13:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944454; cv=none; b=A48wmNYSe0siT/kNr7LZt6/OVkz9DFC529TeB/i653fxvnFur+SlzYRIAeIKp7rQWbHLOPYoEOT6BY/JOh9hYDGjyVaK+Fc+j1TsBG2wt7m7Y6YdXlOmbNmUYpEVKSYlWHgTD3eLTBQO69yZsqZ1z74DOmrUSzaPbHVKFywepZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944454; c=relaxed/simple; bh=iPQitKJaOAw1dcX7ZOo2cTMoyJ5pc70J9AQA/1gmZz8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=GKYGfddl1zh/Ittcaz9OzKCt98UoVLY9Tzb5pMxVcp9ld3rQuozF0qkdGoMo7DLAZSxocpxOr3yieVp1Td46lkXqVPP+ftji+3A36IF9eTgIa/v6WxN0kstP9XePelWBTdHK0N0+liycbA5ywGCjeYBS5Gls/oPGR2wvCQy4BdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=45OeGOvb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=E6GZZrhE; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="45OeGOvb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E6GZZrhE" Message-ID: <20250626131708.419101339@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750944451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3g83WUkcahA98tSAvTQ+7u+GY59xMVQMWbvReg+4HxI=; b=45OeGOvbc1FQu84tfTVe0f2noUtdJYd9OuBPXbg6cB8GmCirEgGwogjyC+D9dYYo0qlTlj FBSdahHr8QXontgg1UjT/tV6dgwkbqbtIRFjHs8AbUxqywoKG/DZNWmWlwQmYbHUX0IMZR /hIfxxipeXHmkhiyj5D/2/p7VJk3sx7TCq0mwqNVSJL1WMKQyxAQQblzw3bJySGFYqcwyk NHfTyX5j7/MrAtI1IqjYJ9K/kL3GmnoL8foFJgkxM27C7CMfUykryIgzJ3nA1uayXw6kIP /cKsMCEwg/XCsX2gLDKci8qi453Nv/BqYZXXciFtBKNyAfkLlFXOZYECKyYtgg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750944451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3g83WUkcahA98tSAvTQ+7u+GY59xMVQMWbvReg+4HxI=; b=E6GZZrhErWzckN9MDzfoFmzVq1fkYY5lUJ56uKMVLqh8VpHKQQ6YLFPym0ZOSff2+iNP2D dTZ1yNIN+8+FeoDw== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , John Stultz , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Kurt Kanzenbach , Nam Cao , Antoine Tenart Subject: [patch 1/3] timekeeping: Provide ktime_get_clock_ts64() References: <20250626124327.667087805@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 26 Jun 2025 15:27:30 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" PTP implements an inline switch case for taking timestamps from various POSIX clock IDs, which already consumes quite some text space. Expanding it for auxiliary clocks really becomes too big for inlining. Provide a out of line version.=20 The function invalidates the timestamp in case the clock is invalid. The invalidation allows to implement a validation check without the need to propagate a return value through deep existing call chains. Signed-off-by: Thomas Gleixner Acked-by: John Stultz Reviewed-by: Vadim Fedorenko --- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -44,6 +44,7 @@ extern void ktime_get_ts64(struct timesp extern void ktime_get_real_ts64(struct timespec64 *tv); extern void ktime_get_coarse_ts64(struct timespec64 *ts); extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); +extern void ktime_get_clock_ts64(clockid_t id, struct timespec64 *ts); =20 /* Multigrain timestamp interfaces */ extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts); --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1636,6 +1636,40 @@ void ktime_get_raw_ts64(struct timespec6 EXPORT_SYMBOL(ktime_get_raw_ts64); =20 /** + * ktime_get_clock_ts64 - Returns time of a clock in a timespec + * @id: POSIX clock ID of the clock to read + * @ts: Pointer to the timespec64 to be set + * + * The timestamp is invalidated (@ts->sec is set to -1) if the + * clock @id is not available. + */ +void ktime_get_clock_ts64(clockid_t id, struct timespec64 *ts) +{ + /* Invalidate time stamp */ + ts->tv_sec =3D -1; + ts->tv_nsec =3D 0; + + switch (id) { + case CLOCK_REALTIME: + ktime_get_real_ts64(ts); + return; + case CLOCK_MONOTONIC: + ktime_get_ts64(ts); + return; + case CLOCK_MONOTONIC_RAW: + ktime_get_raw_ts64(ts); + return; + case CLOCK_AUX ... CLOCK_AUX_LAST: + if (IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS)) + ktime_get_aux_ts64(id, ts); + return; + default: + WARN_ON_ONCE(1); + } +} +EXPORT_SYMBOL_GPL(ktime_get_clock_ts64); + +/** * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres */ int timekeeping_valid_for_hres(void) From nobody Wed Oct 8 16:03:41 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F0A82E62AD; Thu, 26 Jun 2025 13:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944457; cv=none; b=ZBh/GCh1SLn0vX8iZICAlhtEI+rve1FG/bodbGAO2NS4GhGLZWYWJ92T46CSQ0THuTb0gIpiXLD3zEWipIEcHbdo9x2fSwf9jHz9CcItKkVdKBX0TvJVdYv50807pVGpKNDj4fdPT9XCLv8RxUYkd1uu2wOlUu3Tprhj4yO0thg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944457; c=relaxed/simple; bh=hdkXS2zPS05MylX9NsfoU4bC44QsxXSw2hQjbhoIp0g=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=VymoUWJ8i8gBqelkpTuooeeY2HgtQFI/fPudeogfv+XkYwFeWD732cKgi9dQMBr/2VQMIN9cENYevSpbPp1q5ksqPKq8I5Ih5wQCwJKLcGk8csfjJ/0gJwt6MtBjkaWphhOD78cmPBoXK98pjgu9dhpqOHk9MZNbh7BV51VNKm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QwyLPdFw; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Lz0sz8iw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QwyLPdFw"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Lz0sz8iw" Message-ID: <20250626131708.482362835@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750944453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=2B6a0np2Ef6lES3YZRHCRVSuzy1PUmYaASOyD3FWdbM=; b=QwyLPdFw1sCXqR0yjB4jgTFo1nJbpeCD+OAqbRc4sf5OMfih3v6uQpDuxqc0qWYjYyQF9O tfz8oxh2adtkxN0V8w3/jvD7hpiQ8rGUErsKywmF3JaM5G4u/9eMzZGSbANWgZcB3btK2/ /1p0pvjqhaFf8geW9XSbYg+Bigc1wISh3fbsLvGLCCmK6rZym2kgS9mbvjD+W7YGflV1XO ImFVjDd/uwI3/ZLiFc4B/uNgdiuzIBWo3sEs6Ei1TzJE49vkmXYmWW/6JbzZ9X7JpY+XBh 3SKsYhiAzVyDKfO6dO+ZsqL59FQ3V4WmjISKdUxzURa5RaohqiVpl3CJirFYgA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750944453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=2B6a0np2Ef6lES3YZRHCRVSuzy1PUmYaASOyD3FWdbM=; b=Lz0sz8iwXNkxkzVTQWEdYBXu2OEMFQGeXzwgLkwuPGn1aMAwksv6hQkU0ucjeh3uYBgGU6 n/q/JB160dmY0RDw== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , John Stultz , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Kurt Kanzenbach , Nam Cao , Antoine Tenart Subject: [patch 2/3] ptp: Use ktime_get_clock_ts64() for timestamping References: <20250626124327.667087805@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 26 Jun 2025 15:27:32 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The inlined ptp_read_system_[pre|post]ts() switch cases expand to a copious amount of text in drivers, e.g. ~500 bytes in e1000e. Adding auxiliary clock support to the inlines would increase it further. Replace the inline switch case with a call to ktime_get_clock_ts64(), which reduces the code size in drivers and allows to access auxiliary clocks once they are enabled in the IOCTL parameter filter. No functional change. Signed-off-by: Thomas Gleixner Acked-by: John Stultz Reviewed-by: Vadim Fedorenko --- include/linux/ptp_clock_kernel.h | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -477,40 +477,14 @@ static inline ktime_t ptp_convert_timest =20 static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts) { - if (sts) { - switch (sts->clockid) { - case CLOCK_REALTIME: - ktime_get_real_ts64(&sts->pre_ts); - break; - case CLOCK_MONOTONIC: - ktime_get_ts64(&sts->pre_ts); - break; - case CLOCK_MONOTONIC_RAW: - ktime_get_raw_ts64(&sts->pre_ts); - break; - default: - break; - } - } + if (sts) + ktime_get_clock_ts64(sts->clockid, &sts->pre_ts); } =20 static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) { - if (sts) { - switch (sts->clockid) { - case CLOCK_REALTIME: - ktime_get_real_ts64(&sts->post_ts); - break; - case CLOCK_MONOTONIC: - ktime_get_ts64(&sts->post_ts); - break; - case CLOCK_MONOTONIC_RAW: - ktime_get_raw_ts64(&sts->post_ts); - break; - default: - break; - } - } + if (sts) + ktime_get_clock_ts64(sts->clockid, &sts->post_ts); } =20 #endif From nobody Wed Oct 8 16:03:41 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E7EB2E7196; Thu, 26 Jun 2025 13:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944459; cv=none; b=lCijEpVzESiqk+EyghwJkpW7wu9Y9J4/vqLBrqwCl8/g5xSd0zfvQrWCKHpSCf52eF1XotzkeoUT2AKGczZ4917wS666KShIgCI6yeqAmaiWsq83UqMIcSluRSYlDk8uJrHFkQ5MWTuWewZvS1nQnV0IRFjbebD/TLUDiYX752Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944459; c=relaxed/simple; bh=LQCtlrijMtzrLcCN//EaLeGrkvgwl9q1RRfITmiG/B8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=p6Yx9oF3KghzFbojxKkle3pmO0uyLyaroGkMD0ltuzONuiDhkSWUu5raqUXPBAZVXkkoM5cui42tTCdR7huhgRCQL2n+BGohEAGFngtFcCDmtgMYktBYdXYGKGrLhRy8s8830M8C4SEaAqxInt0T5ZselKxHHQfqgO0IoMpv5wk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YRmchcvM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pvzwNVKE; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YRmchcvM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pvzwNVKE" Message-ID: <20250626131708.544227586@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750944455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=+23L/t+gK242K9oPEMEakcO6Zj9GwQnHSFFMgTm1G8c=; b=YRmchcvMjps2ADVLc2TaFrDyPuu15ZB7cri1Wsf7hDlY0q1PORGhE60Q6zjou10sHU2rsr Iww9aBaZtelcPeYTtB5egj1FczH0VkkoUXe/fOPOQhc46z7EqTnlyUujo/YXp+Hsi4UUpB t6JIxxGnYtGRMjseJfM4X0pUidBK4X7Bj4L0hZVTq7srSL3HCARk8RfDiTUk3fOng3Louk ZFDD29CxKE3kCWDXLdXVvLdvJvoc2Mah2durEecNxcZ7kO5Q1hZP7MzucqQeUXb6DrSzU/ /yKRToHAhIeERxoO5XcBCwRFoTrE6sAB+UH2Zkhm2ks1OQaVPb5mlcrwezHodQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750944455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=+23L/t+gK242K9oPEMEakcO6Zj9GwQnHSFFMgTm1G8c=; b=pvzwNVKEmDQDkK1zRoegaqYZWFHX7QzZppx2NTRNgkaJN0s8RZe1oNRYByTSrhq1L0hKBo g5F5fjvstS0ANoDw== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , John Stultz , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Kurt Kanzenbach , Nam Cao , Antoine Tenart Subject: [patch 3/3] ptp: Enable auxiliary clocks for PTP_SYS_OFFSET_EXTENDED References: <20250626124327.667087805@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 26 Jun 2025 15:27:34 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow ioctl(PTP_SYS_OFFSET_EXTENDED*) to select CLOCK_AUX clock ids for generating the pre and post hardware readout timestamps. Aside of adding these clocks to the clock ID validation, this also requires to check the timestamp to be valid, i.e. the seconds value being greater than or equal zero. This is necessary because AUX clocks can be asynchronously enabled or disabled, so there is no way to validate the availability upfront. The same could have been achieved by handing the return value of ktime_get_aux_ts64() all the way down to the IOCTL call site, but that'd require to modify all existing ptp::gettimex64() callbacks and their inner call chains. The timestamp check achieves the same with less churn and less complicated code all over the place. Signed-off-by: Thomas Gleixner Reviewed-by: Vadim Fedorenko --- drivers/ptp/ptp_chardev.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -325,13 +325,19 @@ static long ptp_sys_offset_extended(stru if (IS_ERR(extoff)) return PTR_ERR(extoff); =20 - if (extoff->n_samples > PTP_MAX_SAMPLES || - extoff->rsv[0] || extoff->rsv[1] || - (extoff->clockid !=3D CLOCK_REALTIME && - extoff->clockid !=3D CLOCK_MONOTONIC && - extoff->clockid !=3D CLOCK_MONOTONIC_RAW)) + if (extoff->n_samples > PTP_MAX_SAMPLES || extoff->rsv[0] || extoff->rsv[= 1]) return -EINVAL; =20 + switch (extoff->clockid) { + case CLOCK_REALTIME: + case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC_RAW: + case CLOCK_AUX ... CLOCK_AUX_LAST: + break; + default: + return -EINVAL; + } + sts.clockid =3D extoff->clockid; for (unsigned int i =3D 0; i < extoff->n_samples; i++) { struct timespec64 ts; @@ -340,6 +346,11 @@ static long ptp_sys_offset_extended(stru err =3D ptp->info->gettimex64(ptp->info, &ts, &sts); if (err) return err; + + /* Filter out disabled or unavailable clocks */ + if (sts.pre_ts.tv_sec < 0 || sts.post_ts.tv_sec < 0) + return -EINVAL; + extoff->ts[i][0].sec =3D sts.pre_ts.tv_sec; extoff->ts[i][0].nsec =3D sts.pre_ts.tv_nsec; extoff->ts[i][1].sec =3D ts.tv_sec;