drivers/ptp/ptp_chardev.c | 4 ++++ 1 file changed, 4 insertions(+)
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
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>
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
>
>
© 2016 - 2025 Red Hat, Inc.