Skip to contentSkip to conversation

ice: be consistent around PTP de-registration

PATCH In review Jesse Brandeburg 5 participants 5 messages Apr 7, 2025 – Apr 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: be consistent around PTP de-registration

From: Jesse Brandeburg <[email protected]>

The driver was being inconsistent when de-registering its PTP clock. Make sure to NULL out the pointer once it is freed in all cases. The driver was mostly already doing so, but a couple spots were missed.

---
NOTE: we saw some odd behavior on one or two machines where the ports completed init, PTP completed init, then port 0 was "hot removed" via sysfs, and later panics on ptp->index being 1 while being called by ethtool. This caused me to look over this area and see this inconsistency. I wasn't able to confirm any for-sure bug.

---
 drivers/net/ethernet/intel/ice/ice_main.c | 5 ++++-
 drivers/net/ethernet/intel/ice/ice_ptp.c  | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +4 -1
index 049edeb60104..8c1b496e84ef 100644
@@ -3968,8 +3968,11 @@ static void ice_deinit_pf(struct ice_pf *pf)
 		pf->avail_rxqs = NULL;
 	}
 
-	if (pf->ptp.clock)
+	if (pf->ptp.clock) {
 		ptp_clock_unregister(pf->ptp.clock);
+		pf->ptp.clock = NULL;
+	}
+	pf->ptp.state = ICE_PTP_UNINIT;
 
 	xa_destroy(&pf->dyn_ports);
 	xa_destroy(&pf->sf_nums);
drivers/net/ethernet/intel/ice/ice_ptp.c +2 -2
index 1fd1ae03eb90..d7a5c3fb7948 100644
@@ -3407,9 +3407,9 @@ void ice_ptp_init(struct ice_pf *pf)
 
 err_exit:
 	/* If we registered a PTP clock, release it */
-	if (pf->ptp.clock) {
+	if (ptp->clock) {
 		ptp_clock_unregister(ptp->clock);
-		pf->ptp.clock = NULL;
+		ptp->clock = NULL;
 	}
 	ptp->state = ICE_PTP_ERROR;
 	dev_err(ice_pf_to_dev(pf), "PTP failed %d\n", err);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Jesse Brandeburg
Sent: Tuesday, April 8, 2025 1:20 AM
To: [email protected]
Cc: [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Dumazet, Eric <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Richard Cochran <[email protected]>; Brandeburg, Jesse <[email protected]>
Subject: [Intel-wired-lan] [PATCH intel-next v1] ice: be consistent around PTP de-registration

Quoted 7 lines

From: Jesse Brandeburg <[email protected]>

The driver was being inconsistent when de-registering its PTP clock. Make sure to NULL out the pointer once it is freed in all cases. The driver was mostly already doing so, but a couple spots were missed.

Quoted 48 lines

---
NOTE: we saw some odd behavior on one or two machines where the ports completed init, PTP completed init, then port 0 was "hot removed" via sysfs, and later panics on ptp->index being 1 while being called by ethtool. This caused me to look over this area and see this inconsistency.
I wasn't able to confirm any for-sure bug.

---
 drivers/net/ethernet/intel/ice/ice_main.c | 5 ++++-
drivers/net/ethernet/intel/ice/ice_ptp.c  | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +4 -1
index 049edeb60104..8c1b496e84ef 100644
@@ -3968,8 +3968,11 @@ static void ice_deinit_pf(struct ice_pf *pf)
 		pf->avail_rxqs = NULL;
 	}
 
-	if (pf->ptp.clock)
+	if (pf->ptp.clock) {
 		ptp_clock_unregister(pf->ptp.clock);
+		pf->ptp.clock = NULL;
+	}
+	pf->ptp.state = ICE_PTP_UNINIT;
 
 	xa_destroy(&pf->dyn_ports);
 	xa_destroy(&pf->sf_nums);
drivers/net/ethernet/intel/ice/ice_ptp.c +2 -3
index 1fd1ae03eb90..d7a5c3fb7948 100644
@@ -3407,9 +3407,9 @@ void ice_ptp_init(struct ice_pf *pf)
 
 err_exit:
 	/* If we registered a PTP clock, release it */
-	if (pf->ptp.clock) {
+	if (ptp->clock) {
 		ptp_clock_unregister(ptp->clock);
-		pf->ptp.clock = NULL;
+		ptp->clock = NULL;
 	}
 	ptp->state = ICE_PTP_ERROR;
 	dev_err(ice_pf_to_dev(pf), "PTP failed %d\n", err);
--

2.43.0

maintainer
#2 lore raw
In reply to Jesse Brandeburg

On 4/7/2025 4:20 PM, Jesse Brandeburg wrote:

iwl-next, not intel-next :)

Quoted 23 lines

From: Jesse Brandeburg <[email protected]>

The driver was being inconsistent when de-registering its PTP clock. Make sure to NULL out the pointer once it is freed in all cases. The driver was mostly already doing so, but a couple spots were missed.

---
NOTE: we saw some odd behavior on one or two machines where the ports completed init, PTP completed init, then port 0 was "hot removed" via sysfs, and later panics on ptp->index being 1 while being called by ethtool. This caused me to look over this area and see this inconsistency. I wasn't able to confirm any for-sure bug.

---
  drivers/net/ethernet/intel/ice/ice_main.c | 5 ++++-
  drivers/net/ethernet/intel/ice/ice_ptp.c  | 4 ++--
  2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
index 049edeb60104..8c1b496e84ef 100644

drivers/net/ethernet/intel/ice/ice_main.c static void ice_deinit_pf(struct ice_pf *pf) · line 3975

Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_main.c +4 -1
@@ -3968,8 +3968,11 @@ static void ice_deinit_pf(struct ice_pf *pf)
  		pf->avail_rxqs = NULL;
  	}
 
-	if (pf->ptp.clock)
+	if (pf->ptp.clock) {
  		ptp_clock_unregister(pf->ptp.clock);
+		pf->ptp.clock = NULL;
+	}
+	pf->ptp.state = ICE_PTP_UNINIT;

Hi Jesse,

It looks like we get a proper removal/unregister in ice_ptp_release() which is called from ice_deinit_features(). From what I'm seeing, I don't think the unregister should be done here at all.

Thanks,
Tony

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
  	xa_destroy(&pf->dyn_ports);
  	xa_destroy(&pf->sf_nums);
#3 lore raw
Quoted 41 lines · Tony Nguyen

On 4/7/2025 4:20 PM, Jesse Brandeburg wrote:

iwl-next, not intel-next :)

Quoted 23 lines

From: Jesse Brandeburg <[email protected]>

The driver was being inconsistent when de-registering its PTP clock. Make sure to NULL out the pointer once it is freed in all cases. The driver was mostly already doing so, but a couple spots were missed.

---
NOTE: we saw some odd behavior on one or two machines where the ports completed init, PTP completed init, then port 0 was "hot removed" via sysfs, and later panics on ptp->index being 1 while being called by ethtool. This caused me to look over this area and see this inconsistency. I wasn't able to confirm any for-sure bug.

---
  drivers/net/ethernet/intel/ice/ice_main.c | 5 ++++-
  drivers/net/ethernet/intel/ice/ice_ptp.c  | 4 ++--
  2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
index 049edeb60104..8c1b496e84ef 100644

drivers/net/ethernet/intel/ice/ice_main.c static void ice_deinit_pf(struct ice_pf *pf) · line 3975

Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_main.c +4 -1
@@ -3968,8 +3968,11 @@ static void ice_deinit_pf(struct ice_pf *pf)
  		pf->avail_rxqs = NULL;
  	}
 
-	if (pf->ptp.clock)
+	if (pf->ptp.clock) {
  		ptp_clock_unregister(pf->ptp.clock);
+		pf->ptp.clock = NULL;
+	}
+	pf->ptp.state = ICE_PTP_UNINIT;

Hi Jesse,

Quoted 7 lines

It looks like we get a proper removal/unregister in ice_ptp_release() which is called from ice_deinit_features(). From what I'm seeing, I don't think the unregister should be done here at all.

Thanks,
Tony

+1, I think a v2 should just remove the entire call to ptp_clock_unregister here. It's the wrong place to do it. It causing problems is further evidence of this.

Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
  	xa_destroy(&pf->dyn_ports);
  	xa_destroy(&pf->sf_nums);
#4 lore raw
Quoted 4 lines · Jacob Keller
Quoted 3 lines · Tony Nguyen

On 4/7/2025 4:20 PM, Jesse Brandeburg wrote:

iwl-next, not intel-next :)

The brain rot on unused cells is severe it seems :-)

Quoted 13 lines
Quoted 13 lines

drivers/net/ethernet/intel/ice/ice_main.c static void ice_deinit_pf(struct ice_pf *pf) · line 3975

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_main.c +4 -1
-    if (pf->ptp.clock)
+    if (pf->ptp.clock) {
             ptp_clock_unregister(pf->ptp.clock);
+            pf->ptp.clock = NULL;
+    }
+    pf->ptp.state = ICE_PTP_UNINIT;

Hi Jesse,

It looks like we get a proper removal/unregister in ice_ptp_release() which is called from ice_deinit_features(). From what I'm seeing, I don't think the unregister should be done here at all.

Quoted 7 lines
Quoted 3 lines

Thanks,
Tony

+1, I think a v2 should just remove the entire call to ptp_clock_unregister here. It's the wrong place to do it. It causing problems is further evidence of this.

Ok, thanks to both, I'll see if I can spin a v2 and eliminate the extra cruft. This might also explain why a second load of the driver fails to register the clock after the double unregister.