netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter
@ 2025-10-29  8:38 Carolina Jubran
  2025-10-29 10:09 ` Pavan Chebbi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Carolina Jubran @ 2025-10-29  8:38 UTC (permalink / raw)
  To: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Carolina Jubran, Dragos Tatulea,
	Tariq Toukan

The PTP core falls back to gettimex64 and getcrosststamp when
getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES
ioctls to retrieve PHC real time instead of free-running cycles.

Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without
free-running counter support since the result would represent PHC real
time and system time rather than cycles and system time.

Fixes: faf23f54d366 ("ptp: Add ioctl commands to expose raw cycle counter values")
Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/ptp/ptp_chardev.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index 8106eb617c8c..c61cf9edac48 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -561,10 +561,14 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
 		return ptp_mask_en_single(pccontext->private_clkdata, argptr);
 
 	case PTP_SYS_OFFSET_PRECISE_CYCLES:
+		if (!ptp->has_cycles)
+			return -EOPNOTSUPP;
 		return ptp_sys_offset_precise(ptp, argptr,
 					      ptp->info->getcrosscycles);
 
 	case PTP_SYS_OFFSET_EXTENDED_CYCLES:
+		if (!ptp->has_cycles)
+			return -EOPNOTSUPP;
 		return ptp_sys_offset_extended(ptp, argptr,
 					       ptp->info->getcyclesx64);
 	default:
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter
  2025-10-29  8:38 [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter Carolina Jubran
@ 2025-10-29 10:09 ` Pavan Chebbi
  2025-10-29 20:33 ` Vadim Fedorenko
  2025-10-31 23:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Pavan Chebbi @ 2025-10-29 10:09 UTC (permalink / raw)
  To: Carolina Jubran
  Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, Dragos Tatulea,
	Tariq Toukan

[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]

On Wed, Oct 29, 2025 at 2:39 PM Carolina Jubran <cjubran@nvidia.com> wrote:
>
> The PTP core falls back to gettimex64 and getcrosststamp when
> getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES
> ioctls to retrieve PHC real time instead of free-running cycles.
>
> Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without
> free-running counter support since the result would represent PHC real
> time and system time rather than cycles and system time.
>
> Fixes: faf23f54d366 ("ptp: Add ioctl commands to expose raw cycle counter values")
> Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> ---
>  drivers/ptp/ptp_chardev.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index 8106eb617c8c..c61cf9edac48 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -561,10 +561,14 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
>                 return ptp_mask_en_single(pccontext->private_clkdata, argptr);
>
>         case PTP_SYS_OFFSET_PRECISE_CYCLES:
> +               if (!ptp->has_cycles)
> +                       return -EOPNOTSUPP;
>                 return ptp_sys_offset_precise(ptp, argptr,
>                                               ptp->info->getcrosscycles);
>
>         case PTP_SYS_OFFSET_EXTENDED_CYCLES:
> +               if (!ptp->has_cycles)
> +                       return -EOPNOTSUPP;
>                 return ptp_sys_offset_extended(ptp, argptr,
>                                                ptp->info->getcyclesx64);
>         default:

LGTM.
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>

> --
> 2.38.1
>
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5469 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter
  2025-10-29  8:38 [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter Carolina Jubran
  2025-10-29 10:09 ` Pavan Chebbi
@ 2025-10-29 20:33 ` Vadim Fedorenko
  2025-10-31 23:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Fedorenko @ 2025-10-29 20:33 UTC (permalink / raw)
  To: Carolina Jubran, Richard Cochran, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Dragos Tatulea, Tariq Toukan

On 29/10/2025 08:38, Carolina Jubran wrote:
> The PTP core falls back to gettimex64 and getcrosststamp when
> getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES
> ioctls to retrieve PHC real time instead of free-running cycles.
> 
> Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without
> free-running counter support since the result would represent PHC real
> time and system time rather than cycles and system time.
> 
> Fixes: faf23f54d366 ("ptp: Add ioctl commands to expose raw cycle counter values")
> Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> ---
>   drivers/ptp/ptp_chardev.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index 8106eb617c8c..c61cf9edac48 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -561,10 +561,14 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
>   		return ptp_mask_en_single(pccontext->private_clkdata, argptr);
>   
>   	case PTP_SYS_OFFSET_PRECISE_CYCLES:
> +		if (!ptp->has_cycles)
> +			return -EOPNOTSUPP;
>   		return ptp_sys_offset_precise(ptp, argptr,
>   					      ptp->info->getcrosscycles);
>   
>   	case PTP_SYS_OFFSET_EXTENDED_CYCLES:
> +		if (!ptp->has_cycles)
> +			return -EOPNOTSUPP;
>   		return ptp_sys_offset_extended(ptp, argptr,
>   					       ptp->info->getcyclesx64);
>   	default:

Fair point.
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter
  2025-10-29  8:38 [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter Carolina Jubran
  2025-10-29 10:09 ` Pavan Chebbi
  2025-10-29 20:33 ` Vadim Fedorenko
@ 2025-10-31 23:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-31 23:40 UTC (permalink / raw)
  To: Carolina Jubran
  Cc: richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, dtatulea, tariqt

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 29 Oct 2025 10:38:13 +0200 you wrote:
> The PTP core falls back to gettimex64 and getcrosststamp when
> getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES
> ioctls to retrieve PHC real time instead of free-running cycles.
> 
> Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without
> free-running counter support since the result would represent PHC real
> time and system time rather than cycles and system time.
> 
> [...]

Here is the summary with links:
  - [net] ptp: Allow exposing cycles only for clocks with free-running counter
    https://git.kernel.org/netdev/net/c/5a89b27afd3d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-31 23:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29  8:38 [PATCH net] ptp: Allow exposing cycles only for clocks with free-running counter Carolina Jubran
2025-10-29 10:09 ` Pavan Chebbi
2025-10-29 20:33 ` Vadim Fedorenko
2025-10-31 23:40 ` patchwork-bot+netdevbpf

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