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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-ptp-fix-egregious-supported-flag-checks'

Jacob Keller says:

====================
net: ptp: fix egregious supported flag checks

In preparation for adding .supported_extts_flags and
.supported_perout_flags to the ptp_clock_info structure, fix a couple of
places where drivers get existing flag gets grossly incorrect.

The igb driver claims 82580 supports strictly validating PTP_RISING_EDGE
and PTP_FALLING_EDGE, but doesn't actually check the flags. Fix the driver
to require that the request match both edges, as this is implied by the
datasheet description.

The renesas driver also claims to support strict flag checking, but does
not actually check the flags either. I do not have the data sheet for this
device, so I do not know what edge it timestamps. For simplicity, just
reject all requests with PTP_STRICT_FLAGS. This essentially prevents the
PTP_EXTTS_REQUEST2 ioctl from working. Updating to correctly validate the
flags will require someone who has the hardware to confirm the behavior.

The lan743x driver supports (and strictly validates) that the request is
either PTP_RISING_EDGE or PTP_FALLING_EDGE but not both. However, it does
not check the flags are one of the known valid flags. Thus, requests for
PTP_EXT_OFF (and any future flag) will be accepted and misinterpreted. Add
the appropriate check to reject unsupported PTP_EXT_OFF requests and future
proof against new flags.

The broadcom PHY driver checks that PTP_PEROUT_PHASE is not set. This
appears to be an attempt at rejecting unsupported flags. It is not robust
against flag additions such as the PTP_PEROUT_ONE_SHOT, or anything added
in the future. Fix this by instead checking against the negation of the
supported PTP_PEROUT_DUTY_CYCLE instead.

The ptp_ocp driver supports PTP_PEROUT_PHASE and PTP_PEROUT_DUTY_CYCLE, but
does not check unsupported flags. Add the appropriate check to ensure
PTP_PEROUT_ONE_SHOT and any future flags are rejected as unsupported.

These are changes compile-tested, but I do not have hardware to validate the
behavior.

There are a number of other drivers which enable periodic output or
external timestamp requests, but which do not check flags at all. We could
go through each of these drivers one-by-one and meticulously add a flag
check. Instead, these drivers will be covered only by the upcoming
.supported_extts_flags and .supported_perout_flags checks in a net-next
series.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
====================

Link: https://patch.msgid.link/20250312-jk-net-fixes-supported-extts-flags-v2-0-ea930ba82459@intel.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+19 -3
+6
drivers/net/ethernet/intel/igb/igb_ptp.c
··· 509 509 PTP_STRICT_FLAGS)) 510 510 return -EOPNOTSUPP; 511 511 512 + /* Both the rising and falling edge are timestamped */ 513 + if (rq->extts.flags & PTP_STRICT_FLAGS && 514 + (rq->extts.flags & PTP_ENABLE_FEATURE) && 515 + (rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES) 516 + return -EOPNOTSUPP; 517 + 512 518 if (on) { 513 519 pin = ptp_find_pin(igb->ptp_clock, PTP_PF_EXTTS, 514 520 rq->extts.index);
+6
drivers/net/ethernet/microchip/lan743x_ptp.c
··· 942 942 943 943 extts = &ptp->extts[index]; 944 944 945 + if (extts_request->flags & ~(PTP_ENABLE_FEATURE | 946 + PTP_RISING_EDGE | 947 + PTP_FALLING_EDGE | 948 + PTP_STRICT_FLAGS)) 949 + return -EOPNOTSUPP; 950 + 945 951 if (on) { 946 952 extts_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, index); 947 953 if (extts_pin < 0)
+1 -2
drivers/net/ethernet/renesas/ravb_ptp.c
··· 179 179 /* Reject requests with unsupported flags */ 180 180 if (req->flags & ~(PTP_ENABLE_FEATURE | 181 181 PTP_RISING_EDGE | 182 - PTP_FALLING_EDGE | 183 - PTP_STRICT_FLAGS)) 182 + PTP_FALLING_EDGE)) 184 183 return -EOPNOTSUPP; 185 184 186 185 if (req->index)
+2 -1
drivers/net/phy/bcm-phy-ptp.c
··· 597 597 598 598 period = BCM_MAX_PERIOD_8NS; /* write nonzero value */ 599 599 600 - if (req->flags & PTP_PEROUT_PHASE) 600 + /* Reject unsupported flags */ 601 + if (req->flags & ~PTP_PEROUT_DUTY_CYCLE) 601 602 return -EOPNOTSUPP; 602 603 603 604 if (req->flags & PTP_PEROUT_DUTY_CYCLE)
+4
drivers/ptp/ptp_ocp.c
··· 2090 2090 { 2091 2091 struct ptp_ocp_signal s = { }; 2092 2092 2093 + if (req->flags & ~(PTP_PEROUT_DUTY_CYCLE | 2094 + PTP_PEROUT_PHASE)) 2095 + return -EOPNOTSUPP; 2096 + 2093 2097 s.polarity = bp->signal[gen].polarity; 2094 2098 s.period = ktime_set(req->period.sec, req->period.nsec); 2095 2099 if (!s.period)