Skip to contentSkip to conversation

net: ionic: free VF resources on remove

PATCH Applied Guangshuo Li 4 participants 4 messages Sep 16 – Sep 21

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

PATCH 1/1 net: ionic: free VF resources on remove

ionic_probe() allocates VF tracking data and maps a statistics buffer for each already enabled VF with ionic_vf_alloc().

The probe failure path releases these resources with ionic_vf_dealloc(). However, after a successful probe, ionic_remove() tears down the LIF and device without releasing the VF resources.

This leaves the VF tracking allocation and statistics DMA mappings behind when the PF driver is removed.

Call ionic_vf_dealloc() before deinitializing the LIF so the VF statistics addresses can be cleared and the associated DMA mappings and tracking data released.

This issue was found by manual code inspection.

Fixes fbb39807e9ae ("ionic: support sr-iov operations")
---
 drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1 -0
index 05f19489ec5c..666efe972de7 100644
@@ -424,6 +424,7 @@ static void ionic_remove(struct pci_dev *pdev)
 		ionic_auxbus_unregister(ionic->lif);
 		ionic_lif_unregister(ionic->lif);
 		ionic_devlink_unregister(ionic);
+		ionic_vf_dealloc(ionic);
 		ionic_lif_deinit(ionic->lif);
 		ionic_lif_free(ionic->lif);
 		ionic->lif = NULL;
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0

- [Medium] The newly added ionic_vf_dealloc() call in ionic_remove() (ionic_bus_pci.c:427) reaches ionic_vf_dealloc_locked()…

Pre-existing issues:
- [Medium] ionic_vf_start() (drivers/net/ethernet/pensando/ionic/ionic_dev.c:804-816) issues a…

--

net: ionic: free VF resources on remove

The patch adds a call to ionic_vf_dealloc() in ionic_remove() so that the VF tracking array and the per-VF statistics DMA mappings created by ionic_vf_alloc() during probe are released when the PF driver is removed. Previously only the probe failure path did this.

drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static void ionic_remove(struct pci_dev *pdev) · line 427

Quoted 9 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1 -0
index 05f19489ec5c8..666efe972de78 100644
@@ -424,6 +424,7 @@ static void ionic_remove(struct pci_dev *pdev)
 		ionic_auxbus_unregister(ionic->lif);
 		ionic_lif_unregister(ionic->lif);
 		ionic_devlink_unregister(ionic);
+		ionic_vf_dealloc(ionic);

[Severity: Medium]
Can the device still be DMAing into the VF statistics buffers at this point? ionic_vf_dealloc() -> ionic_vf_dealloc_locked() asks the firmware to un-arm each buffer but drops the result:

drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c:ionic_vf_dealloc_locked() {
	...
		if (v->stats_pa) {
			vfc.stats_pa = 0;
			ionic_set_vf_config(ionic, i, &vfc);
			dma_unmap_single(ionic->dev, v->stats_pa,
					 sizeof(v->stats), DMA_FROM_DEVICE);
			v->stats_pa = 0;
		}
	...
	kfree(ionic->vfs);
}

ionic_set_vf_config() is a synchronous devcmd that can fail. __ionic_dev_cmd_wait() returns -ENXIO when ionic_is_fw_running() reports the firmware down, and on a stalled firmware it returns -ETIMEDOUT after calling ionic_dev_cmd_clean(), which zeroes the doorbell and command area:

drivers/net/ethernet/pensando/ionic/ionic_main.c:__ionic_dev_cmd_wait() {
	...
		ionic_dev_cmd_clean(ionic);
		dev_warn(ionic->dev, "DEVCMD %s (%d) timeout after %ld secs\n",
			 ionic_opcode_to_str(opcode), opcode, max_seconds);
		return -ETIMEDOUT;
	...
}

In that case the firmware never sees the clear request, yet the mapping is unmapped and ionic->vfs is freed anyway. Does anything stop DMA before this? SR-IOV is still enabled here (ionic_remove() never calls pci_disable_sriov(), and pci_iov_remove() only prints "driver left SR-IOV enabled after remove"), and ionic_port_reset(), ionic_reset() and ionic_clear_pci() run afterwards, each of the preceding devcmds able to block for DEVCMD_TIMEOUT first. Can a later stats DMA then land on an unmapped IOVA, or on recycled memory when no IOMMU is present?

The FW-down case looks anticipated by ionic_remove() itself, which turns IONIC_LIF_F_FW_RESET into IONIC_LIF_F_FW_STOPPING just above, and ionic_lif_reset() guards its devcmd with ionic_is_fw_running() for the same reason. Would it make sense to check the ionic_set_vf_config() return value, or to skip the clear when the firmware is not running, before unmapping?

The commit message says the call is made:

"so the VF statistics addresses can be cleared"

On the failure paths above they are not cleared, although the mapping and the tracking array are released regardless. Could the message mention that?

drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static void ionic_remove(struct pci_dev *pdev) · line 430

Quoted 3 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +0 -0
 		ionic_lif_deinit(ionic->lif);
 		ionic_lif_free(ionic->lif);
 		ionic->lif = NULL;

[Severity: Medium]
This isn't a bug introduced by this patch, but while looking at the VF devcmd paths: ionic_vf_start() in ionic_dev.c issues a devcmd without holding ionic->dev_cmd_lock, unlike ionic_set_vf_config() right above it in the same file:

drivers/net/ethernet/pensando/ionic/ionic_dev.c:ionic_set_vf_config() {
	...
	mutex_lock(&ionic->dev_cmd_lock);
	ionic_dev_cmd_go(&ionic->idev, &cmd);
	err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
	mutex_unlock(&ionic->dev_cmd_lock);
	...
}
drivers/net/ethernet/pensando/ionic/ionic_dev.c:ionic_vf_start() {
	...
	ionic_dev_cmd_go(&ionic->idev, &cmd);
	ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
}

The only caller, ionic_vf_attr_replay() in ionic_lif.c, drops vf_op_lock and then calls it with no lock held:

	up_read(&ionic->vf_op_lock);

	ionic_vf_start(ionic);

Since idev->dev_cmd_regs->cmd/done/comp and idev->opcode are a single shared window, can two unserialized sequences overwrite each other's command and consume each other's completion? The replay runs from ionic_lif_deferred_work() -> ionic_lif_handle_fw_up() -> ionic_restart_lif() -> ionic_vf_attr_replay(), before clear_bit(IONIC_LIF_F_FW_RESET, ...), and ionic_firmware_update() in ionic_fw.c takes dev_cmd_lock for its own commands without testing IONIC_LIF_F_FW_RESET, so a concurrent devlink flash seems able to overlap. This behaviour predates this patch (it goes back to the VF start control change), and this patch does not touch ionic_vf_start().

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260916053117.2906446-1-lgs201920130244%40gmail.com
#2 lore raw
In reply to Guangshuo Li
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 16 Sep 2026 13:31:17 +0800 you wrote:

ionic_probe() allocates VF tracking data and maps a statistics buffer for each already enabled VF with ionic_vf_alloc().

The probe failure path releases these resources with ionic_vf_dealloc(). However, after a successful probe, ionic_remove() tears down the LIF and device without releasing the VF resources.

[...]

Here is the summary with links:
- net: ionic: free VF resources on remove

    https://git.kernel.org/netdev/net-next/c/9f1c440f9283

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Reviewed-by Brett Creeley on v1 1/1
#3 lore raw
In reply to Guangshuo Li
Quoted 31 lines · Guangshuo Li

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

ionic_probe() allocates VF tracking data and maps a statistics buffer for each already enabled VF with ionic_vf_alloc().

The probe failure path releases these resources with ionic_vf_dealloc(). However, after a successful probe, ionic_remove() tears down the LIF and device without releasing the VF resources.

This leaves the VF tracking allocation and statistics DMA mappings behind when the PF driver is removed.

Call ionic_vf_dealloc() before deinitializing the LIF so the VF statistics addresses can be cleared and the associated DMA mappings and tracking data released.

This issue was found by manual code inspection.

Fixes fbb39807e9ae ("ionic: support sr-iov operations")
---
  drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +0 -0
index 05f19489ec5c..666efe972de7 100644

drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static void ionic_remove(struct pci_dev *pdev) · line 427

Quoted 4 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1 -0
@@ -424,6 +424,7 @@ static void ionic_remove(struct pci_dev *pdev)
                 ionic_auxbus_unregister(ionic->lif);
                 ionic_lif_unregister(ionic->lif);
                 ionic_devlink_unregister(ionic);
+               ionic_vf_dealloc(ionic);

I meant to respond, but didn't. Anyway this LGTM, thanks for the patch.

At this point it's not worth anything, but still:

Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +0 -1
                 ionic_lif_deinit(ionic->lif);
                 ionic_lif_free(ionic->lif);
                 ionic->lif = NULL;
--

2.43.0