Skip to contentSkip to conversation

vdpa/octeon_ep: Control PCI dev enabling manually

PATCH Superseded Philipp Stanner 2 participants 2 messages Apr 24, 2025 – Apr 25, 2025

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 vdpa/octeon_ep: Control PCI dev enabling manually

PCI region request functions such as pci_request_region() currently have the problem of becoming sometimes managed functions, if pcim_enable_device() instead of pci_enable_device() was called. The PCI subsystem wants to remove this deprecated behavior from its interfaces.

octeopn_ep enables its device with pcim_enable_device() (for AF. PF uses manual management), but does so only to get automatic disablement. The driver wants to manage its PCI resources for AF manually, without devres.

The easiest way not to use automatic resource management at all is by also handling device enable- and disablement manually.

Replace pcim_enable_device() with pci_enable_device(). Add the necessary calls to pci_disable_device().

---
Changes in v3:
- Only call pci_disable_device() for the PF version. For AF it would cause a WARN_ON because pcim_enable_device()'s callback will also try to disable.

---
 drivers/vdpa/octeon_ep/octep_vdpa_main.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/vdpa/octeon_ep/octep_vdpa_main.c +12 -5
index f3d4dda4e04c..9b49efd24391 100644
@@ -454,6 +454,9 @@ static void octep_vdpa_remove_pf(struct pci_dev *pdev)
 		octep_iounmap_region(pdev, octpf->base, OCTEP_HW_MBOX_BAR);
 
 	octep_vdpa_pf_bar_expand(octpf);
+
+	/* The pf version does not use managed PCI. */
+	pci_disable_device(pdev);
 }
 
 static void octep_vdpa_vf_bar_shrink(struct pci_dev *pdev)
@@ -825,7 +828,7 @@ static int octep_vdpa_probe_pf(struct pci_dev *pdev)
 	struct octep_pf *octpf;
 	int ret;
 
-	ret = pcim_enable_device(pdev);
+	ret = pci_enable_device(pdev);
 	if (ret) {
 		dev_err(dev, "Failed to enable device\n");
 		return ret;
@@ -834,15 +837,17 @@ static int octep_vdpa_probe_pf(struct pci_dev *pdev)
 	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
 	if (ret) {
 		dev_err(dev, "No usable DMA configuration\n");
-		return ret;
+		goto disable_pci;
 	}
 	octpf = devm_kzalloc(dev, sizeof(*octpf), GFP_KERNEL);
-	if (!octpf)
-		return -ENOMEM;
+	if (!octpf) {
+		ret = -ENOMEM;
+		goto disable_pci;
+	}
 
 	ret = octep_iomap_region(pdev, octpf->base, OCTEP_HW_MBOX_BAR);
 	if (ret)
-		return ret;
+		goto disable_pci;
 
 	pci_set_master(pdev);
 	pci_set_drvdata(pdev, octpf);
@@ -856,6 +861,8 @@ static int octep_vdpa_probe_pf(struct pci_dev *pdev)
 
 unmap_region:
 	octep_iounmap_region(pdev, octpf->base, OCTEP_HW_MBOX_BAR);
+disable_pci:
+	pci_disable_device(pdev);
 	return ret;
 }
 
Signature · 1 line
2.48.1
reviewer Acked-by on v3 1/1
#1 lore raw
Quoted 29 lines

-----Original Message-----
From: Philipp Stanner <[email protected]>
Sent: Thursday, April 24, 2025 5:19 PM
To: Srujana Challa <[email protected]>; Vamsi Krishna Attunuru <[email protected]>; Michael S. Tsirkin <[email protected]>; Jason Wang <[email protected]>; Xuan Zhuo <[email protected]>; Eugenio Pérez <[email protected]>; Shijith Thotton <[email protected]>; Dan Carpenter <[email protected]>; Philipp Stanner <[email protected]>; Satha Koteswara Rao Kottidi <[email protected]>
Cc: [email protected]; [email protected]
Subject: [EXTERNAL] [PATCH v3] vdpa/octeon_ep: Control PCI dev enabling manually

PCI region request functions such as pci_request_region() currently have the problem of becoming sometimes managed functions, if pcim_enable_device() instead of pci_enable_device() was called. The PCI subsystem wants to remove this deprecated
PCI region request functions such as pci_request_region() currently have the problem of becoming sometimes managed functions, if pcim_enable_device() instead of pci_enable_device() was called. The PCI subsystem wants to remove this deprecated behavior from its interfaces.

octeopn_ep enables its device with pcim_enable_device() (for AF. PF uses manual management), but does so only to get automatic disablement. The driver wants to manage its PCI resources for AF manually, without devres.

Quoted 7 lines

The easiest way not to use automatic resource management at all is by also handling device enable- and disablement manually.

Replace pcim_enable_device() with pci_enable_device(). Add the necessary calls to pci_disable_device().

Thanks, Philipp, for the patch. Patch looks good, minor nit AF --> VF

Quoted 70 lines

---
Changes in v3:
- Only call pci_disable_device() for the PF version. For AF it would cause a WARN_ON because pcim_enable_device()'s callback will also try to disable.
---
drivers/vdpa/octeon_ep/octep_vdpa_main.c | 17 ++++++++++++-----

1 file changed, 12 insertions(+), 5 deletions(-)
drivers/vdpa/octeon_ep/octep_vdpa_main.c +3 -0
index f3d4dda4e04c..9b49efd24391 100644
@@ -454,6 +454,9 @@ static void octep_vdpa_remove_pf(struct pci_dev
 *pdev)
 		octep_iounmap_region(pdev, octpf->base,
 OCTEP_HW_MBOX_BAR);
 
 	octep_vdpa_pf_bar_expand(octpf);
+
+	/* The pf version does not use managed PCI. */
+	pci_disable_device(pdev);
 }

static void octep_vdpa_vf_bar_shrink(struct pci_dev *pdev) @@ -825,7 +828,7 @@ static int octep_vdpa_probe_pf(struct pci_dev *pdev)

	struct octep_pf *octpf;
	int ret;
drivers/vdpa/octeon_ep/octep_vdpa_main.c +1 -1
-	ret = pcim_enable_device(pdev);
+	ret = pci_enable_device(pdev);
	if (ret) {
		dev_err(dev, "Failed to enable device\n");
		return ret;
drivers/vdpa/octeon_ep/octep_vdpa_main.c +6 -4
@@ -834,15 +837,17 @@ static int octep_vdpa_probe_pf(struct pci_dev
 *pdev)
 	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
 	if (ret) {
 		dev_err(dev, "No usable DMA configuration\n");
-		return ret;
+		goto disable_pci;
 	}
 	octpf = devm_kzalloc(dev, sizeof(*octpf), GFP_KERNEL);
-	if (!octpf)
-		return -ENOMEM;
+	if (!octpf) {
+		ret = -ENOMEM;
+		goto disable_pci;
+	}
 
 	ret = octep_iomap_region(pdev, octpf->base,
 OCTEP_HW_MBOX_BAR);
 	if (ret)
-		return ret;
+		goto disable_pci;
 
	pci_set_master(pdev);
	pci_set_drvdata(pdev, octpf);
drivers/vdpa/octeon_ep/octep_vdpa_main.c +0 -0
@@ -856,6 +861,8 @@ static int octep_vdpa_probe_pf(struct pci_dev *pdev)
 

unmap_region:

	octep_iounmap_region(pdev, octpf->base, OCTEP_HW_MBOX_BAR);
drivers/vdpa/octeon_ep/octep_vdpa_main.c +2 -0
+disable_pci:
+	pci_disable_device(pdev);
	return ret;
}

--
2.48.1