* [PATCH net v2 1/5] igb: reject invalid external timestamp requests for 82580-based HW
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
@ 2025-03-12 22:15 ` Jacob Keller
2025-03-18 14:06 ` Simon Horman
2025-03-12 22:15 ` [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported Jacob Keller
` (5 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Jacob Keller @ 2025-03-12 22:15 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc, Jacob Keller
The igb_ptp_feature_enable_82580 function correctly checks that unknown
flags are not passed to the function. However, it does not actually check
PTP_RISING_EDGE or PTP_FALLING_EDGE when configuring the external timestamp
function.
The data sheet for the 82580 product says:
Upon a change in the input level of one of the SDP pins that was
configured to detect Time stamp events using the TSSDP register, a time
stamp of the system time is captured into one of the two auxiliary time
stamp registers (AUXSTMPL/H0 or AUXSTMPL/H1).
For example to define timestamping of events in the AUXSTMPL0 and
AUXSTMPH0 registers, Software should:
1. Set the TSSDP.AUX0_SDP_SEL field to select the SDP pin that detects
the level change and set the TSSDP.AUX0_TS_SDP_EN bit to 1.
2. Set the TSAUXC.EN_TS0 bit to 1 to enable timestamping
The same paragraph is in the i350 and i354 data sheets.
The wording implies that the time stamps are captured at any level change.
There does not appear to be any way to only timestamp one edge of the
signal.
Reject requests which do not set both PTP_RISING_EDGE and PTP_FALLING_EDGE
when operating under PTP_STRICT_FLAGS mode via PTP_EXTTS_REQUEST2.
Fixes: 38970eac41db ("igb: support EXTTS on 82580/i354/i350")
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
Changes in v2:
- Fix the 82580 check to allow disabling the pin without flags set.
---
drivers/net/ethernet/intel/igb/igb_ptp.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index f9457055612004c10f74379122063e8136fe7d76..f323e1c1989f1bfbbf1f04043c2c0f14ae8c716f 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -509,6 +509,12 @@ static int igb_ptp_feature_enable_82580(struct ptp_clock_info *ptp,
PTP_STRICT_FLAGS))
return -EOPNOTSUPP;
+ /* Both the rising and falling edge are timestamped */
+ if (rq->extts.flags & PTP_STRICT_FLAGS &&
+ (rq->extts.flags & PTP_ENABLE_FEATURE) &&
+ (rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
+ return -EOPNOTSUPP;
+
if (on) {
pin = ptp_find_pin(igb->ptp_clock, PTP_PF_EXTTS,
rq->extts.index);
--
2.48.1.397.gec9d649cc640
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net v2 1/5] igb: reject invalid external timestamp requests for 82580-based HW
2025-03-12 22:15 ` [PATCH net v2 1/5] igb: reject invalid external timestamp requests for 82580-based HW Jacob Keller
@ 2025-03-18 14:06 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2025-03-18 14:06 UTC (permalink / raw)
To: Jacob Keller
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski, intel-wired-lan, netdev,
linux-renesas-soc
On Wed, Mar 12, 2025 at 03:15:50PM -0700, Jacob Keller wrote:
> The igb_ptp_feature_enable_82580 function correctly checks that unknown
> flags are not passed to the function. However, it does not actually check
> PTP_RISING_EDGE or PTP_FALLING_EDGE when configuring the external timestamp
> function.
>
> The data sheet for the 82580 product says:
>
> Upon a change in the input level of one of the SDP pins that was
> configured to detect Time stamp events using the TSSDP register, a time
> stamp of the system time is captured into one of the two auxiliary time
> stamp registers (AUXSTMPL/H0 or AUXSTMPL/H1).
>
> For example to define timestamping of events in the AUXSTMPL0 and
> AUXSTMPH0 registers, Software should:
>
> 1. Set the TSSDP.AUX0_SDP_SEL field to select the SDP pin that detects
> the level change and set the TSSDP.AUX0_TS_SDP_EN bit to 1.
>
> 2. Set the TSAUXC.EN_TS0 bit to 1 to enable timestamping
>
> The same paragraph is in the i350 and i354 data sheets.
>
> The wording implies that the time stamps are captured at any level change.
> There does not appear to be any way to only timestamp one edge of the
> signal.
>
> Reject requests which do not set both PTP_RISING_EDGE and PTP_FALLING_EDGE
> when operating under PTP_STRICT_FLAGS mode via PTP_EXTTS_REQUEST2.
>
> Fixes: 38970eac41db ("igb: support EXTTS on 82580/i354/i350")
> Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
2025-03-12 22:15 ` [PATCH net v2 1/5] igb: reject invalid external timestamp requests for 82580-based HW Jacob Keller
@ 2025-03-12 22:15 ` Jacob Keller
2025-03-13 9:45 ` Niklas Söderlund
2025-03-18 14:07 ` Simon Horman
2025-03-12 22:15 ` [PATCH net v2 3/5] net: lan743x: reject unsupported external timestamp requests Jacob Keller
` (4 subsequent siblings)
6 siblings, 2 replies; 15+ messages in thread
From: Jacob Keller @ 2025-03-12 22:15 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc, Jacob Keller
The ravb_ptp_extts() function checks the flags coming from the
PTP_EXTTS_REQUEST ioctl, to ensure that future flags are not accepted on
accident.
This was updated to 'honor' the PTP_STRICT_FLAGS in commit 6138e687c7b6
("ptp: Introduce strict checking of external time stamp options.").
However, the driver does not *actually* validate the flags.
I originally fixed this driver to reject future flags in commit
592025a03b34 ("renesas: reject unsupported external timestamp flags"). It
is still unclear whether this hardware timestamps the rising, falling, or
both edges of the input signal.
Accepting requests with PTP_STRICT_FLAGS is a bug, as this could lead to
users mistakenly assuming a request with PTP_RISING_EDGE actually
timestamps the rising edge only.
Reject requests with PTP_STRICT_FLAGS (and hence all PTP_EXTTS_REQUEST2
requests) until someone with access to the datasheet or hardware knowledge
can confirm the timestamping behavior and update this driver.
Fixes: 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/net/ethernet/renesas/ravb_ptp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index 6e4ef7af27bf31ab2aad8e06a65e0ede6046e3c0..b4365906669f3bd40953813e263aeaafd2e1eb70 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -179,8 +179,7 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,
/* Reject requests with unsupported flags */
if (req->flags & ~(PTP_ENABLE_FEATURE |
PTP_RISING_EDGE |
- PTP_FALLING_EDGE |
- PTP_STRICT_FLAGS))
+ PTP_FALLING_EDGE))
return -EOPNOTSUPP;
if (req->index)
--
2.48.1.397.gec9d649cc640
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported
2025-03-12 22:15 ` [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported Jacob Keller
@ 2025-03-13 9:45 ` Niklas Söderlund
2025-03-18 14:07 ` Simon Horman
1 sibling, 0 replies; 15+ messages in thread
From: Niklas Söderlund @ 2025-03-13 9:45 UTC (permalink / raw)
To: Jacob Keller
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Bryan Whitehead, UNGLinuxDriver,
Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, Jonathan Lemon,
Lasse Johnsen, Vadim Fedorenko, Michal Swiatkowski,
intel-wired-lan, netdev, linux-renesas-soc
Hi Jacob,
Thanks for your work.
On 2025-03-12 15:15:51 -0700, Jacob Keller wrote:
> The ravb_ptp_extts() function checks the flags coming from the
> PTP_EXTTS_REQUEST ioctl, to ensure that future flags are not accepted on
> accident.
>
> This was updated to 'honor' the PTP_STRICT_FLAGS in commit 6138e687c7b6
> ("ptp: Introduce strict checking of external time stamp options.").
> However, the driver does not *actually* validate the flags.
>
> I originally fixed this driver to reject future flags in commit
> 592025a03b34 ("renesas: reject unsupported external timestamp flags"). It
> is still unclear whether this hardware timestamps the rising, falling, or
> both edges of the input signal.
>
> Accepting requests with PTP_STRICT_FLAGS is a bug, as this could lead to
> users mistakenly assuming a request with PTP_RISING_EDGE actually
> timestamps the rising edge only.
>
> Reject requests with PTP_STRICT_FLAGS (and hence all PTP_EXTTS_REQUEST2
> requests) until someone with access to the datasheet or hardware knowledge
> can confirm the timestamping behavior and update this driver.
>
> Fixes: 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/net/ethernet/renesas/ravb_ptp.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
> index 6e4ef7af27bf31ab2aad8e06a65e0ede6046e3c0..b4365906669f3bd40953813e263aeaafd2e1eb70 100644
> --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
> @@ -179,8 +179,7 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,
> /* Reject requests with unsupported flags */
> if (req->flags & ~(PTP_ENABLE_FEATURE |
> PTP_RISING_EDGE |
> - PTP_FALLING_EDGE |
> - PTP_STRICT_FLAGS))
> + PTP_FALLING_EDGE))
> return -EOPNOTSUPP;
>
> if (req->index)
>
> --
> 2.48.1.397.gec9d649cc640
>
--
Kind Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported
2025-03-12 22:15 ` [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported Jacob Keller
2025-03-13 9:45 ` Niklas Söderlund
@ 2025-03-18 14:07 ` Simon Horman
1 sibling, 0 replies; 15+ messages in thread
From: Simon Horman @ 2025-03-18 14:07 UTC (permalink / raw)
To: Jacob Keller
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski, intel-wired-lan, netdev,
linux-renesas-soc
On Wed, Mar 12, 2025 at 03:15:51PM -0700, Jacob Keller wrote:
> The ravb_ptp_extts() function checks the flags coming from the
> PTP_EXTTS_REQUEST ioctl, to ensure that future flags are not accepted on
> accident.
>
> This was updated to 'honor' the PTP_STRICT_FLAGS in commit 6138e687c7b6
> ("ptp: Introduce strict checking of external time stamp options.").
> However, the driver does not *actually* validate the flags.
>
> I originally fixed this driver to reject future flags in commit
> 592025a03b34 ("renesas: reject unsupported external timestamp flags"). It
> is still unclear whether this hardware timestamps the rising, falling, or
> both edges of the input signal.
>
> Accepting requests with PTP_STRICT_FLAGS is a bug, as this could lead to
> users mistakenly assuming a request with PTP_RISING_EDGE actually
> timestamps the rising edge only.
>
> Reject requests with PTP_STRICT_FLAGS (and hence all PTP_EXTTS_REQUEST2
> requests) until someone with access to the datasheet or hardware knowledge
> can confirm the timestamping behavior and update this driver.
>
> Fixes: 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net v2 3/5] net: lan743x: reject unsupported external timestamp requests
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
2025-03-12 22:15 ` [PATCH net v2 1/5] igb: reject invalid external timestamp requests for 82580-based HW Jacob Keller
2025-03-12 22:15 ` [PATCH net v2 2/5] renesas: reject PTP_STRICT_FLAGS as unsupported Jacob Keller
@ 2025-03-12 22:15 ` Jacob Keller
2025-03-18 14:08 ` Simon Horman
2025-03-12 22:15 ` [PATCH net v2 4/5] broadcom: fix supported flag check in periodic output function Jacob Keller
` (3 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Jacob Keller @ 2025-03-12 22:15 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc, Jacob Keller
The lan743x_ptp_io_event_cap_en() function checks that the given request
sets only one of PTP_RISING_EDGE or PTP_FALLING_EDGE, but not both.
However, this driver does not check whether other flags (such as
PTP_EXT_OFF) are set, nor whether any future unrecognized flags are set.
Fix this by adding the appropriate check to the lan743x_ptp_io_extts()
function.
Fixes: 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/net/ethernet/microchip/lan743x_ptp.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
index 4a777b449ecd03ac0d7576f8570f1a7794fb3d06..0be44dcb339387e9756f36f909f65c20870bc49b 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.c
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
@@ -942,6 +942,12 @@ static int lan743x_ptp_io_extts(struct lan743x_adapter *adapter, int on,
extts = &ptp->extts[index];
+ if (extts_request->flags & ~(PTP_ENABLE_FEATURE |
+ PTP_RISING_EDGE |
+ PTP_FALLING_EDGE |
+ PTP_STRICT_FLAGS))
+ return -EOPNOTSUPP;
+
if (on) {
extts_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, index);
if (extts_pin < 0)
--
2.48.1.397.gec9d649cc640
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net v2 3/5] net: lan743x: reject unsupported external timestamp requests
2025-03-12 22:15 ` [PATCH net v2 3/5] net: lan743x: reject unsupported external timestamp requests Jacob Keller
@ 2025-03-18 14:08 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2025-03-18 14:08 UTC (permalink / raw)
To: Jacob Keller
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski, intel-wired-lan, netdev,
linux-renesas-soc
On Wed, Mar 12, 2025 at 03:15:52PM -0700, Jacob Keller wrote:
> The lan743x_ptp_io_event_cap_en() function checks that the given request
> sets only one of PTP_RISING_EDGE or PTP_FALLING_EDGE, but not both.
>
> However, this driver does not check whether other flags (such as
> PTP_EXT_OFF) are set, nor whether any future unrecognized flags are set.
>
> Fix this by adding the appropriate check to the lan743x_ptp_io_extts()
> function.
>
> Fixes: 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net v2 4/5] broadcom: fix supported flag check in periodic output function
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
` (2 preceding siblings ...)
2025-03-12 22:15 ` [PATCH net v2 3/5] net: lan743x: reject unsupported external timestamp requests Jacob Keller
@ 2025-03-12 22:15 ` Jacob Keller
2025-03-18 14:09 ` Simon Horman
2025-03-12 22:15 ` [PATCH net v2 5/5] ptp: ocp: reject unsupported periodic output flags Jacob Keller
` (2 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Jacob Keller @ 2025-03-12 22:15 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc, Jacob Keller
In bcm_ptp_perout_locked, the driver rejects requests which have
PTP_PEROUT_PHASE set. This appears to be an attempt to reject any
unsupported flags. Unfortunately, this only checks one flag, but does not
protect against PTP_PEROUT_ONE_SHOT, or any future flags which may be
added.
Fix the check to ensure that no flag other than the supported
PTP_PEROUT_DUTY_CYCLE is set.
Fixes: 7bfe91efd525 ("net: phy: Add support for 1PPS out and external timestamps")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/net/phy/bcm-phy-ptp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/bcm-phy-ptp.c b/drivers/net/phy/bcm-phy-ptp.c
index 208e8f561e0696e64bd5e842b66d88c65d70bfc0..eba8b5fb1365f4e43331e479e8e2f3c4b590ab96 100644
--- a/drivers/net/phy/bcm-phy-ptp.c
+++ b/drivers/net/phy/bcm-phy-ptp.c
@@ -597,7 +597,8 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv,
period = BCM_MAX_PERIOD_8NS; /* write nonzero value */
- if (req->flags & PTP_PEROUT_PHASE)
+ /* Reject unsupported flags */
+ if (req->flags & ~PTP_PEROUT_DUTY_CYCLE)
return -EOPNOTSUPP;
if (req->flags & PTP_PEROUT_DUTY_CYCLE)
--
2.48.1.397.gec9d649cc640
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net v2 4/5] broadcom: fix supported flag check in periodic output function
2025-03-12 22:15 ` [PATCH net v2 4/5] broadcom: fix supported flag check in periodic output function Jacob Keller
@ 2025-03-18 14:09 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2025-03-18 14:09 UTC (permalink / raw)
To: Jacob Keller
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski, intel-wired-lan, netdev,
linux-renesas-soc
On Wed, Mar 12, 2025 at 03:15:53PM -0700, Jacob Keller wrote:
> In bcm_ptp_perout_locked, the driver rejects requests which have
> PTP_PEROUT_PHASE set. This appears to be an attempt to reject any
> unsupported flags. Unfortunately, this only checks one flag, but does not
> protect against PTP_PEROUT_ONE_SHOT, or any future flags which may be
> added.
>
> Fix the check to ensure that no flag other than the supported
> PTP_PEROUT_DUTY_CYCLE is set.
>
> Fixes: 7bfe91efd525 ("net: phy: Add support for 1PPS out and external timestamps")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net v2 5/5] ptp: ocp: reject unsupported periodic output flags
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
` (3 preceding siblings ...)
2025-03-12 22:15 ` [PATCH net v2 4/5] broadcom: fix supported flag check in periodic output function Jacob Keller
@ 2025-03-12 22:15 ` Jacob Keller
2025-03-18 14:10 ` Simon Horman
2025-03-19 21:21 ` [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Paolo Abeni
2025-03-20 8:20 ` patchwork-bot+netdevbpf
6 siblings, 1 reply; 15+ messages in thread
From: Jacob Keller @ 2025-03-12 22:15 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc, Jacob Keller
The ptp_ocp_signal_from_perout() function supports PTP_PEROUT_DUTY_CYCLE
and PTP_PEROUT_PHASE. It does not support PTP_PEROUT_ONE_SHOT, but does not
reject a request with such an unsupported flag.
Add the appropriate check to ensure that unsupported requests are rejected
both for PTP_PEROUT_ONE_SHOT as well as any future flags.
Fixes: 1aa66a3a135a ("ptp: ocp: Program the signal generators via PTP_CLK_REQ_PEROUT")
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/ptp/ptp_ocp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index b651087f426f50a73229ca57634fc5d6912e0a87..4a87af0980d695a9ab1b23e2544f620759ccb892 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2090,6 +2090,10 @@ ptp_ocp_signal_from_perout(struct ptp_ocp *bp, int gen,
{
struct ptp_ocp_signal s = { };
+ if (req->flags & ~(PTP_PEROUT_DUTY_CYCLE |
+ PTP_PEROUT_PHASE))
+ return -EOPNOTSUPP;
+
s.polarity = bp->signal[gen].polarity;
s.period = ktime_set(req->period.sec, req->period.nsec);
if (!s.period)
--
2.48.1.397.gec9d649cc640
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net v2 5/5] ptp: ocp: reject unsupported periodic output flags
2025-03-12 22:15 ` [PATCH net v2 5/5] ptp: ocp: reject unsupported periodic output flags Jacob Keller
@ 2025-03-18 14:10 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2025-03-18 14:10 UTC (permalink / raw)
To: Jacob Keller
Cc: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski, intel-wired-lan, netdev,
linux-renesas-soc
On Wed, Mar 12, 2025 at 03:15:54PM -0700, Jacob Keller wrote:
> The ptp_ocp_signal_from_perout() function supports PTP_PEROUT_DUTY_CYCLE
> and PTP_PEROUT_PHASE. It does not support PTP_PEROUT_ONE_SHOT, but does not
> reject a request with such an unsupported flag.
>
> Add the appropriate check to ensure that unsupported requests are rejected
> both for PTP_PEROUT_ONE_SHOT as well as any future flags.
>
> Fixes: 1aa66a3a135a ("ptp: ocp: Program the signal generators via PTP_CLK_REQ_PEROUT")
> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
` (4 preceding siblings ...)
2025-03-12 22:15 ` [PATCH net v2 5/5] ptp: ocp: reject unsupported periodic output flags Jacob Keller
@ 2025-03-19 21:21 ` Paolo Abeni
2025-03-19 23:56 ` Jacob Keller
2025-03-20 8:20 ` patchwork-bot+netdevbpf
6 siblings, 1 reply; 15+ messages in thread
From: Paolo Abeni @ 2025-03-19 21:21 UTC (permalink / raw)
To: Jacob Keller, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc
On 3/12/25 11:15 PM, Jacob Keller wrote:
> 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>
I admit I'm the most significant source of latency, but this series is
IMHO a bit risky to land this late in the cycle in the net tree,
especially considering the lack of H/W testing for the BCM phy.
What about applying this to net-next instead?
Thanks,
Paolo
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks
2025-03-19 21:21 ` [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Paolo Abeni
@ 2025-03-19 23:56 ` Jacob Keller
0 siblings, 0 replies; 15+ messages in thread
From: Jacob Keller @ 2025-03-19 23:56 UTC (permalink / raw)
To: Paolo Abeni, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Richard Cochran,
Ruud Bos, Paul Barker, Niklas Söderlund, Bryan Whitehead,
UNGLinuxDriver, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, Jonathan Lemon, Lasse Johnsen,
Vadim Fedorenko, Michal Swiatkowski
Cc: intel-wired-lan, netdev, linux-renesas-soc
On 3/19/2025 2:21 PM, Paolo Abeni wrote:
> On 3/12/25 11:15 PM, Jacob Keller wrote:
>> 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>
>
> I admit I'm the most significant source of latency, but this series is
> IMHO a bit risky to land this late in the cycle in the net tree,
> especially considering the lack of H/W testing for the BCM phy.
>
> What about applying this to net-next instead?
>
> Thanks,
>
> Paolo
>
I am fine with that. I only sent to net originally because I thought
some folks might consider these worthy of backports due to the potential
for user-error. However, given the minimal testing it may make sense to
go ahead with next. Obviously no real users have complained about the
situation, and this is more in preparation to make the kernel more
resilient to such mistakes in the future with the .supported_*_flags
modifications coming next cycle.
Thanks,
Jake
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks
2025-03-12 22:15 [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Jacob Keller
` (5 preceding siblings ...)
2025-03-19 21:21 ` [PATCH net v2 0/5] net: ptp: fix egregious supported flag checks Paolo Abeni
@ 2025-03-20 8:20 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 15+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-20 8:20 UTC (permalink / raw)
To: Jacob Keller
Cc: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, richardcochran, kernel.hbk,
paul.barker.ct, niklas.soderlund, bryan.whitehead, UNGLinuxDriver,
florian.fainelli, bcm-kernel-feedback-list, andrew, hkallweit1,
linux, jonathan.lemon, l, vadim.fedorenko, michal.swiatkowski,
intel-wired-lan, netdev, linux-renesas-soc
Hello:
This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Wed, 12 Mar 2025 15:15:49 -0700 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [net,v2,1/5] igb: reject invalid external timestamp requests for 82580-based HW
https://git.kernel.org/netdev/net-next/c/5eada2aabf13
- [net,v2,2/5] renesas: reject PTP_STRICT_FLAGS as unsupported
https://git.kernel.org/netdev/net-next/c/51d58c0c7921
- [net,v2,3/5] net: lan743x: reject unsupported external timestamp requests
https://git.kernel.org/netdev/net-next/c/c0b4ddd30871
- [net,v2,4/5] broadcom: fix supported flag check in periodic output function
https://git.kernel.org/netdev/net-next/c/af2b428f7992
- [net,v2,5/5] ptp: ocp: reject unsupported periodic output flags
https://git.kernel.org/netdev/net-next/c/8dcfc910a81d
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] 15+ messages in thread