Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: Allow exposing cycles only for clocks with free-running counter

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>
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20251029083813.2276997-1-cjubran@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Carolina Jubran and committed by
Jakub Kicinski
5a89b27a 01534d73

+4
+4
drivers/ptp/ptp_chardev.c
··· 561 561 return ptp_mask_en_single(pccontext->private_clkdata, argptr); 562 562 563 563 case PTP_SYS_OFFSET_PRECISE_CYCLES: 564 + if (!ptp->has_cycles) 565 + return -EOPNOTSUPP; 564 566 return ptp_sys_offset_precise(ptp, argptr, 565 567 ptp->info->getcrosscycles); 566 568 567 569 case PTP_SYS_OFFSET_EXTENDED_CYCLES: 570 + if (!ptp->has_cycles) 571 + return -EOPNOTSUPP; 568 572 return ptp_sys_offset_extended(ptp, argptr, 569 573 ptp->info->getcyclesx64); 570 574 default: