Skip to contentSkip to conversation

idpf: disable PTM on probe failure and on remove

PATCH In review Myeonghun Pak 4 participants 6 messages Jul 20 – Aug 14

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

PATCH v3 1/1 idpf: disable PTM on probe failure and on remove

idpf_probe() enables PCIe Precision Time Measurement with pci_enable_ptm(), which takes a reference on the device and on every PTM-capable device up the path to the PTM Root.

Neither the probe error path nor idpf_remove() drops that reference, so the PTM enable counts of this device and of its upstream path stay elevated with no bound driver, and the device's PTM control bits remain set. pcim_enable_device() only arranges for pci_disable_device() and does not undo the PTM enable.

Add the matching pci_disable_ptm() to the common probe unwind and to idpf_remove(). pci_enable_ptm() failure is not fatal here, so guard both calls with pcie_ptm_enabled(): pci_disable_ptm() decrements dev->ptm_enable_cnt unconditionally and then recurses upstream, so calling it after a failed enable would drive this device's count negative and wrongly decrement parents shared with other endpoints.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 8d5e12c5921c ("idpf: add initial PTP support")

---
Changes in v3:
- Rebased; aa8671af0c38 ("PCI/PTM: Drop pci_enable_ptm() granularity parameter") changed the call signature, so v2 no longer applied.
- Guard both pci_disable_ptm() calls with pcie_ptm_enabled(), as pci_disable_ptm() is refcounted and recurses upstream since e1092d5e15e6 ("PCI/PTM: Do not enable PTM automatically for Root and Switch Upstream Ports"). Raised by Tony Nguyen.
- Dropped the v2 claim that pci_disable_ptm() is a no-op when PTM was not enabled; that is no longer true.

Changes in v2:
- Disable PTM in the probe error path, as requested by Emil Tantilov.

 drivers/net/ethernet/intel/idpf/idpf_main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +7 -2
index ab3c409..97bafeb 100644
@@ -159,6 +159,8 @@ destroy_wqs:
 	mutex_destroy(&adapter->queue_lock);
 	mutex_destroy(&adapter->vc_buf_lock);
 
+	if (pcie_ptm_enabled(pdev))
+		pci_disable_ptm(pdev);
 	pci_set_drvdata(pdev, NULL);
 	kfree(adapter);
 }
@@ -266,7 +268,7 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (err) {
 		pci_err(pdev, "DMA configuration failed: %pe\n", ERR_PTR(err));
 
-		goto err_free;
+		goto err_disable_ptm;
 	}
 
 	pci_set_master(pdev);
@@ -279,7 +281,7 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (!adapter->init_wq) {
 		dev_err(dev, "Failed to allocate init workqueue\n");
 		err = -ENOMEM;
-		goto err_free;
+		goto err_disable_ptm;
 	}
 
 	adapter->serv_wq = alloc_workqueue("%s-%s-service",
@@ -366,6 +368,9 @@ err_mbx_wq_alloc:
 	destroy_workqueue(adapter->serv_wq);
 err_serv_wq_alloc:
 	destroy_workqueue(adapter->init_wq);
+err_disable_ptm:
+	if (pcie_ptm_enabled(pdev))
+		pci_disable_ptm(pdev);
 err_free:
 	kfree(adapter);
 	return err;
Signature · 1 line
2.47.1
maintainer
#1 lore raw
Quoted 1 line · On Mon, 20 Jul 2026 23:35:10 +0900 Myeonghun Pak wrote:

Subject: [PATCH v3 net] idpf: disable PTM on probe failure and on remove

Please try not to change the subject of your patches when you respin. It breaks version tracking. Ideally you'd tag this as iwl not net. We don't apply intel NIC patches directly.

maintainer
#2 lore raw
Quoted 6 lines · On Tue, 21 Jul 2026 17:46:42 -0700 Jakub Kicinski wrote:
Quoted 1 line · On Mon, 20 Jul 2026 23:35:10 +0900 Myeonghun Pak wrote:

Subject: [PATCH v3 net] idpf: disable PTM on probe failure and on remove

Please try not to change the subject of your patches when you respin. It breaks version tracking. Ideally you'd tag this as iwl not net. We don't apply intel NIC patches directly.

Of course this is for future reference. Do not repost this unless someone gives you real feedback.

Reviewed-by on v3 1/1
#3 lore raw
In reply to Myeonghun Pak
Quoted 107 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Myeonghun Pak
Sent: Monday, July 20, 2026 4:35 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; intel-wired- [email protected]
Cc: Olech, Milena <[email protected]>; Tantilov, Emil S <[email protected]>; Mina Almasry <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; Myeonghun Pak <[email protected]>; Ijae Kim <[email protected]>
Subject: [Intel-wired-lan] [PATCH v3 net] idpf: disable PTM on probe failure and on remove

idpf_probe() enables PCIe Precision Time Measurement with pci_enable_ptm(), which takes a reference on the device and on every PTM-capable device up the path to the PTM Root.

Neither the probe error path nor idpf_remove() drops that reference, so the PTM enable counts of this device and of its upstream path stay elevated with no bound driver, and the device's PTM control bits remain set. pcim_enable_device() only arranges for pci_disable_device() and does not undo the PTM enable.

Add the matching pci_disable_ptm() to the common probe unwind and to idpf_remove(). pci_enable_ptm() failure is not fatal here, so guard both calls with pcie_ptm_enabled(): pci_disable_ptm() decrements dev->ptm_enable_cnt unconditionally and then recurses upstream, so calling it after a failed enable would drive this device's count negative and wrongly decrement parents shared with other endpoints.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 8d5e12c5921c ("idpf: add initial PTP support")

---
Changes in v3:
- Rebased; aa8671af0c38 ("PCI/PTM: Drop pci_enable_ptm() granularity parameter") changed the call signature, so v2 no longer applied.
- Guard both pci_disable_ptm() calls with pcie_ptm_enabled(), as pci_disable_ptm() is refcounted and recurses upstream since e1092d5e15e6 ("PCI/PTM: Do not enable PTM automatically for Root and Switch Upstream Ports"). Raised by Tony Nguyen.
- Dropped the v2 claim that pci_disable_ptm() is a no-op when PTM was not
enabled; that is no longer true.

Changes in v2:
- Disable PTM in the probe error path, as requested by Emil Tantilov.

 drivers/net/ethernet/intel/idpf/idpf_main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +3 -1
index ab3c409..97bafeb 100644
@@ -159,6 +159,8 @@ destroy_wqs:
 	mutex_destroy(&adapter->queue_lock);
 	mutex_destroy(&adapter->vc_buf_lock);
 
+	if (pcie_ptm_enabled(pdev))
+		pci_disable_ptm(pdev);
 	pci_set_drvdata(pdev, NULL);
 	kfree(adapter);
 }
@@ -266,7 +268,7 @@ static int idpf_probe(struct pci_dev *pdev, const
 struct pci_device_id *ent)
 	if (err) {
 		pci_err(pdev, "DMA configuration failed: %pe\n",
 ERR_PTR(err));
 
-		goto err_free;
+		goto err_disable_ptm;
 	}
drivers/net/ethernet/intel/idpf/idpf_main.c +1 -1
 	pci_set_master(pdev);
@@ -279,7 +281,7 @@ static int idpf_probe(struct pci_dev *pdev, const
 struct pci_device_id *ent)
 	if (!adapter->init_wq) {
 		dev_err(dev, "Failed to allocate init workqueue\n");
 		err = -ENOMEM;
-		goto err_free;
+		goto err_disable_ptm;
 	}
 
drivers/net/ethernet/intel/idpf/idpf_main.c +4 -1
 	adapter->serv_wq = alloc_workqueue("%s-%s-service", @@ -366,6
+368,9 @@ err_mbx_wq_alloc:
 	destroy_workqueue(adapter->serv_wq);
 err_serv_wq_alloc:
 	destroy_workqueue(adapter->init_wq);
+err_disable_ptm:
+	if (pcie_ptm_enabled(pdev))
+		pci_disable_ptm(pdev);
 err_free:
 	kfree(adapter);
 	return err;
--
Quoted 1 line

2.47.1

#4 lore raw

Understood. I won’t repost it unless I receive concrete feedback.

Thanks for the clarification.

Best regards,
Myeonghun Park

2026년 7월 23일 (목) 오후 6:17, Loktionov, Aleksandr
<[email protected]>님이 작성:

Quoted 111 lines
Quoted 108 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Myeonghun Pak
Sent: Monday, July 20, 2026 4:35 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; intel-wired- [email protected]
Cc: Olech, Milena <[email protected]>; Tantilov, Emil S <[email protected]>; Mina Almasry <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; Myeonghun Pak <[email protected]>; Ijae Kim <[email protected]>
Subject: [Intel-wired-lan] [PATCH v3 net] idpf: disable PTM on probe failure and on remove

idpf_probe() enables PCIe Precision Time Measurement with pci_enable_ptm(), which takes a reference on the device and on every PTM-capable device up the path to the PTM Root.

Neither the probe error path nor idpf_remove() drops that reference, so the PTM enable counts of this device and of its upstream path stay elevated with no bound driver, and the device's PTM control bits remain set. pcim_enable_device() only arranges for pci_disable_device() and does not undo the PTM enable.

Add the matching pci_disable_ptm() to the common probe unwind and to idpf_remove(). pci_enable_ptm() failure is not fatal here, so guard both calls with pcie_ptm_enabled(): pci_disable_ptm() decrements dev->ptm_enable_cnt unconditionally and then recurses upstream, so calling it after a failed enable would drive this device's count negative and wrongly decrement parents shared with other endpoints.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 8d5e12c5921c ("idpf: add initial PTP support")

---
Changes in v3:
- Rebased; aa8671af0c38 ("PCI/PTM: Drop pci_enable_ptm() granularity parameter") changed the call signature, so v2 no longer applied.
- Guard both pci_disable_ptm() calls with pcie_ptm_enabled(), as pci_disable_ptm() is refcounted and recurses upstream since e1092d5e15e6 ("PCI/PTM: Do not enable PTM automatically for Root and Switch Upstream Ports"). Raised by Tony Nguyen.
- Dropped the v2 claim that pci_disable_ptm() is a no-op when PTM was not
enabled; that is no longer true.

Changes in v2:
- Disable PTM in the probe error path, as requested by Emil Tantilov.

 drivers/net/ethernet/intel/idpf/idpf_main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +3 -1
index ab3c409..97bafeb 100644
@@ -159,6 +159,8 @@ destroy_wqs:
      mutex_destroy(&adapter->queue_lock);
      mutex_destroy(&adapter->vc_buf_lock);
 
+     if (pcie_ptm_enabled(pdev))
+             pci_disable_ptm(pdev);
      pci_set_drvdata(pdev, NULL);
      kfree(adapter);
 }
@@ -266,7 +268,7 @@ static int idpf_probe(struct pci_dev *pdev, const
 struct pci_device_id *ent)
      if (err) {
              pci_err(pdev, "DMA configuration failed: %pe\n",
 ERR_PTR(err));
 
-             goto err_free;
+             goto err_disable_ptm;
      }
      pci_set_master(pdev);
drivers/net/ethernet/intel/idpf/idpf_main.c +1 -1
@@ -279,7 +281,7 @@ static int idpf_probe(struct pci_dev *pdev, const
 struct pci_device_id *ent)
      if (!adapter->init_wq) {
              dev_err(dev, "Failed to allocate init workqueue\n");
              err = -ENOMEM;
-             goto err_free;
+             goto err_disable_ptm;
      }
 
      adapter->serv_wq = alloc_workqueue("%s-%s-service", @@ -366,6
+368,9 @@ err_mbx_wq_alloc:
      destroy_workqueue(adapter->serv_wq);
 err_serv_wq_alloc:
      destroy_workqueue(adapter->init_wq);
drivers/net/ethernet/intel/idpf/idpf_main.c +3 -1
+err_disable_ptm:
+     if (pcie_ptm_enabled(pdev))
+             pci_disable_ptm(pdev);
 err_free:
      kfree(adapter);
      return err;
--
Quoted 1 line

2.47.1

Tested-by
#5 lore raw
Quoted 77 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Myeonghun Pak
Sent: Saturday, July 25, 2026 6:55 AM
To: Loktionov, Aleksandr <[email protected]>
Cc: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; Olech, Milena <[email protected]>; Tantilov, Emil S <[email protected]>; Mina Almasry <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH v3 net] idpf: disable PTM on probe failure and on remove

Understood. I won’t repost it unless I receive concrete feedback.

Thanks for the clarification.

Best regards,
Myeonghun Park

2026년 7월 23일 (목) 오후 6:17, Loktionov, Aleksandr
<[email protected]>님이 작성:

Quoted 40 lines
Quoted 40 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Myeonghun Pak
Sent: Monday, July 20, 2026 4:35 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; intel-wired- [email protected]
Cc: Olech, Milena <[email protected]>; Tantilov, Emil S <[email protected]>; Mina Almasry <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; Myeonghun Pak <[email protected]>; Ijae Kim <[email protected]>
Subject: [Intel-wired-lan] [PATCH v3 net] idpf: disable PTM on probe failure and on remove

idpf_probe() enables PCIe Precision Time Measurement with pci_enable_ptm(), which takes a reference on the device and on every PTM-capable device up the path to the PTM Root.

Neither the probe error path nor idpf_remove() drops that reference, so the PTM enable counts of this device and of its upstream path stay elevated with no bound driver, and the device's PTM control bits remain set. pcim_enable_device() only arranges for pci_disable_device() and does not undo the PTM enable.

Add the matching pci_disable_ptm() to the common probe unwind and to idpf_remove(). pci_enable_ptm() failure is not fatal here, so guard both calls with pcie_ptm_enabled(): pci_disable_ptm() decrements dev->ptm_enable_cnt unconditionally and then recurses upstream, so calling it after a failed enable would drive this device's count negative and wrongly decrement parents shared with other endpoints.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Quoted 11 lines
Quoted 11 lines
Fixes 8d5e12c5921c ("idpf: add initial PTP support")

---
Changes in v3:
- Rebased; aa8671af0c38 ("PCI/PTM: Drop pci_enable_ptm() granularity parameter") changed the call signature, so v2 no longer applied.
- Guard both pci_disable_ptm() calls with pcie_ptm_enabled(), as pci_disable_ptm() is refcounted and recurses upstream since e1092d5e15e6 ("PCI/PTM: Do not enable PTM automatically for Root

Quoted 61 lines

and

Quoted 60 lines
Quoted 57 lines

Switch Upstream Ports"). Raised by Tony Nguyen.
- Dropped the v2 claim that pci_disable_ptm() is a no-op when PTM was not
enabled; that is no longer true.

Changes in v2:
- Disable PTM in the probe error path, as requested by Emil Tantilov.

 drivers/net/ethernet/intel/idpf/idpf_main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +3 -1
index ab3c409..97bafeb 100644
@@ -159,6 +159,8 @@ destroy_wqs:
      mutex_destroy(&adapter->queue_lock);
      mutex_destroy(&adapter->vc_buf_lock);
 
+     if (pcie_ptm_enabled(pdev))
+             pci_disable_ptm(pdev);
      pci_set_drvdata(pdev, NULL);
      kfree(adapter);
 }
@@ -266,7 +268,7 @@ static int idpf_probe(struct pci_dev *pdev,
 const struct pci_device_id *ent)
      if (err) {
              pci_err(pdev, "DMA configuration failed: %pe\n",
 ERR_PTR(err));
 
-             goto err_free;
+             goto err_disable_ptm;
      }
      pci_set_master(pdev);
drivers/net/ethernet/intel/idpf/idpf_main.c +1 -1
@@ -279,7 +281,7 @@ static int idpf_probe(struct pci_dev *pdev,
 const struct pci_device_id *ent)
      if (!adapter->init_wq) {
              dev_err(dev, "Failed to allocate init workqueue\n");
              err = -ENOMEM;
-             goto err_free;
+             goto err_disable_ptm;
      }
 
      adapter->serv_wq = alloc_workqueue("%s-%s-service", @@ -366,6
+368,9 @@ err_mbx_wq_alloc:
      destroy_workqueue(adapter->serv_wq);
 err_serv_wq_alloc:
      destroy_workqueue(adapter->init_wq);
drivers/net/ethernet/intel/idpf/idpf_main.c +3 -1
+err_disable_ptm:
+     if (pcie_ptm_enabled(pdev))
+             pci_disable_ptm(pdev);
 err_free:
      kfree(adapter);
      return err;
--
Quoted 1 line

2.47.1