Skip to contentSkip to conversation

enic: retain admin DMA resources and identify V2 VFs

PATCH Applied Satish Kharat 3 participants 6 messages Nov 9 – Nov 16

Subsystems (3)
lore
Share & tools
lore

Satish Kharat

author maintainer
#0 lore raw

v7 cover enic: retain admin DMA resources and identify V2 VFs

Fix premature freeing of admin-channel buffers and set the correct V2 VF source ID in mailbox messages. This is v7 of the two-patch admin-only series. The generic datapath quarantine proposal withdrawn in v2 remains out of scope, including its page-pool/device lifetime problem.

The first patch releases the admin WQ/RQ/CQ allocation only after both complete queue-disable helpers succeed. Give both queues a first attempt, then retry once only a helper which timed out. The 500 ms polling bound is local to admin shutdown, and both RQ disable/check passes are preserved. Ordinary datapath and DEVCMD2 queue timeouts are unchanged. Admin receive buffers are driver-owned mappings, not page-pool pages returned later from the networking stack.

Keep PCI bus mastering enabled during runtime admin quarantine so command transport and ordinary teardown can continue. An affected V2 VF is closed and cannot reopen while its control channel is quarantined. Detach the netdev under RTNL during removal, then perform the VF unregister handshake and admin close after releasing RTNL. Skip admin reopen after a failed datapath open. Clear local VF registration after channel replies have been drained, including after a failed re-registration closes the channel.

Probe unwind and removal finish normal generic teardown and attempt CMD_CLOSE before one final direct admin queue check. If that check fails, retain the inert owner and unresolved DMA targets rather than free memory the device might still reference. This intentionally leaves allocations and a BAR reservation behind. It blocks ordinary reprobe while the PCI device remains enumerated; PCI remove/rescan is not a supported recovery method. Surprise removal can make the final queue state unreadable. PCI disconnect state alone is not treated as DMA-completion proof, so the control allocations and reservation are retained until reboot. A PCI-device reference keeps the reservation name valid, but does not preserve IOMMU attachment or establish that DMA stopped. No IRQ, work or other CPU callback may enter retained objects after module unload. DMA debugging can report pending allocations. Reboot is the supported recovery.

The second patch requires DEVCMD2 for SR-IOV V2 and obtains the VF source index from CMD_SRIOV_STATS_GET. Firmware vf_index and mailbox src_vnic_id use 0xffff for the PF and zero-based values for VFs. Hardware CQ sender metadata uses 0 for the PF and vf_index + 1 for a VF; receive handling converts it to the mailbox identity. PF messages also use the deployed 0xffff source value instead of the old zero-filled field. After QP enable, obtain and validate the ID while receive interrupts remain masked. Publish send readiness before unmasking, so queued notifications can be processed and acknowledged with a valid source. Sends remain disabled until the ID is valid, using the existing send gate. Notification handling does not rely on PF retransmission.

Keep the statistics target persistent and observe command completion separately from firmware status. A later blocking QP or close result fences earlier statistics DMA, including an error result. A pre-post failure, posted timeout or NOWAIT posting does not establish completion. This command ordering does not replace admin queue-stop proof.

Sashiko's feedback prompted this audit. The pre-existing failed-reset reopen lifecycle and generic queue-disable error paths remain separate follow-up work; this revision does not claim to fix them. Source review and testing were assisted by LLM tools. The author is responsible for the submitted changes.

Validation:

- V7 changes only public text; its code is identical to V6. V6 passed build and static checks at both patch boundaries. Sparse reported the same existing diagnostics as the public base.
- The uninstrumented V6 candidate successfully bound, opened and closed a V2 VF.
- A test-only overlay accepted statistics version 2 and rejected version 0 and 0xffff, which identifies the PF.
- A test-only overlay exercised admin quarantine during probe failure and removal. Generic teardown and CMD_CLOSE completed before the final queue check released the admin graph, and a clean reprobe succeeded. Keeping the synthetic timeout through that check exercised terminal retention. Guest reboot restored the original module and configuration, after which traffic passed.
- Full functional and interoperability tests on V4 passed with Cisco VIC PFs and V2 VFs, including a nonzero VF and all four combinations of the development ENIC and deployed async PF/VF drivers. Traffic covered bidirectional ICMP, TCP, UDP and jumbo frames.
- Tests covered station/address/filter and administrative-MAC policy changes, concurrent address updates and reopen, and multiple module reload, ring resize, interface reopen and VF destroy/recreate cycles.
- Earlier fault-injection tests covered admin queue retry, reset recovery, queued PF notification delivery after VF-ID discovery and completed-close statistics-buffer cleanup. They let real DMA complete; no test reproduced a physically stuck queue.

The functional and interoperability tests included later VF/PF feature patches. These two fixes alone do not enable in-tree PF SR-IOV support. Physical device removal was not tested; a physical DMA-engine failure was not reproduced.

---
Changes in v7:
- Correct the identity description: vf_index and src_vnic_id use 0xffff for
the PF and zero-based VF values, while CQ sender metadata uses 0 for the PF
and vf_index + 1 for VFs.
- Document the intentional 0xffff PF mailbox source and the common DEVCMD2
result-ordering barrier.
- Explain conservative retention after surprise removal rather than treating
PCI disconnect state as DMA-completion proof.
- Link to v6: https://patch.msgid.link/20261107-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v6-0-155d64f802e9@cisco.com

Changes in v6:
- Accept statistics ABI version 1 or later because newer versions preserve
the version-1 prefix.
- Document that the statistics command is mandatory for V2 VF probe and
correct the reset and DMA-fence comments.
- Link to v5: https://patch.msgid.link/20261103-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v5-0-2501d1223eff@cisco.com

Changes in v5:
- Remove the redundant mbox_tx_poisoned flag. The channel state owns the
allocation lifetime, while mbox_send_disabled gates new sends.
- Run the final direct admin queue recheck after generic teardown and
CMD_CLOSE in both probe unwind and removal.
- Keep all-ones MMIO reads and recoverable PCI channel-offline states
conservative; neither is accepted as queue-stop proof.
- Validate final release and terminal retention on the exact V5 tree.
- Link to v4: https://patch.msgid.link/20261101-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v4-0-a7e209210453@cisco.com

Changes in v4:
- Clear vf_registered after closing the channel on both failed VF
re-registration paths; a late reply may have set it before the send
reported a timeout.
- Hold RTNL only while detaching the netdev during removal. Perform the VF
unregister handshake and admin close after releasing RTNL.
- Keep the valid pre-existing generic datapath repeated-stop problem as
separate follow-up work rather than adding a partial fix to this series.
- Link to v3: https://patch.msgid.link/20261027-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v3-0-ba237ed71241@cisco.com

Changes in v3:
- Use observed blocking CMD_CLOSE completion, including an error result,
to fence earlier statistics DMA in probe unwind and removal.
- Obtain the VF source ID after QP enable but before receive interrupts
are unmasked, and permit sends before delivering queued notifications.
Use the existing send gate instead of a redundant invalid-ID check.
- Validate delayed notifications, discovery failures and completed-close
cleanup on a VF.
- Rerun the full functional suite and all four PF/VF driver pairings
with the v3 fixes in the later VF/PF feature compositions.
- Clear local VF registration after channel close in both reset workers.
- Correct comments and explain quarantine, recovery and retention limits.
- Link to v2: https://patch.msgid.link/20261022-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v2-0-8db19b4a714e@cisco.com

Changes in v2:
- Withdraw v1 patch 1's generic datapath quarantine proposal. Rewrite v1
patch 2 as the first patch here, followed by the VF mailbox-source fix.
- Keep the admin buffers' lifetime separate from generic page pools and
notification teardown. Keep bus mastering enabled at runtime.
- Bound longer polling to the two admin queues, preserve both RQ passes,
and retry only a complete disable helper returning -ETIMEDOUT.
- Serialize remove/open and skip admin reopen after datapath-open failure.
- Observe DEVCMD2 transport completion independently of command success,
including a completed QP error, without treating pre-post errors or
NOWAIT posting as a fence.
- Clarify final remove recheck, terminal retention and reprobe limits.
- Link to v1: https://patch.msgid.link/20261016-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v1-0-d27b55f69883@cisco.com

To: [email protected]
Cc: Sesidhar Baddela <[email protected]>
Cc: Aravind Dhanasekaran <[email protected]>
Cc: Reese Faucette <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>

---
Satish Kharat (2):
enic: retain admin-channel DMA until queues stop
enic: require DEVCMD2 and set the V2 VF mailbox source

 drivers/net/ethernet/cisco/enic/enic.h        |  21 ++-
 drivers/net/ethernet/cisco/enic/enic_admin.c  | 240 ++++++++++++++++++++------
 drivers/net/ethernet/cisco/enic/enic_admin.h  |   4 +-
 drivers/net/ethernet/cisco/enic/enic_dev.c    |  44 +++++
 drivers/net/ethernet/cisco/enic/enic_dev.h    |   3 +
 drivers/net/ethernet/cisco/enic/enic_main.c   | 129 ++++++++++++--
 drivers/net/ethernet/cisco/enic/enic_mbox.c   |  12 +-
 drivers/net/ethernet/cisco/enic/vnic_dev.c    |  85 ++++++++-
 drivers/net/ethernet/cisco/enic/vnic_dev.h    |  15 ++
 drivers/net/ethernet/cisco/enic/vnic_devcmd.h |  34 ++++
 10 files changed, 512 insertions(+), 75 deletions(-)

---
base-commit: 0df412012a26389582b120844d098e1e961f10a6
change-id: 20261010-b4-enic-dma-vf-index-net-generic-first-v1-20261010-d9abf4510335

Best regards,

Signature · 1 line
Satish Kharat <[email protected]>
author maintainer
#1 lore raw

PATCH v7 1/2 enic: retain admin-channel DMA until queues stop

Admin close and the partial-open unwind currently free the admin WQ/RQ/CQ allocation even when disabling one of the queues times out. A posted WQ message or an RQ buffer can then remain reachable by the device after its mapping and allocation have been released.

Track the channel as DOWN, LIVE or QUARANTINED. Stop its IRQ and work, block new sends and join an in-flight sender before queue shutdown. Give both queues a first disable attempt, then retry only a complete helper that timed out. Poll for up to 500 ms per pass locally to the admin path, preserving the RQ's two disable/check passes. Ordinary datapath and DEVCMD2 queue timeouts are unchanged.

RUNNING == 0 proves that queue DMA has stopped. A nonzero value leaves ownership unresolved; it does not establish that DMA is active. An all-ones MMIO read or a recoverable PCI channel-offline state is not accepted as queue-stop proof. Surprise removal can therefore leave the graph retained when queue state is no longer readable. PCI disconnect state alone is not treated as DMA-completion proof. Release the admin graph only when both complete disable helpers succeed. Retain the graph otherwise and refuse to reopen it. Keep bus mastering enabled at runtime so command transport and ordinary teardown can continue. A V2 VF with a quarantined control channel is closed and cannot reopen. Reset callers must not reset or reopen a retained admin graph, or reopen admin queues after a failed datapath open. Clear local VF registration after draining channel replies, including when recovery exits early. Clear it again after a failed re-registration closes the channel because a late REGISTER_REPLY may have set it before the WQ completion timed out.

Check that an internal datapath open still has a present device. Recheck the running state under RTNL in reset workers. During removal, detach the netdev under RTNL and then release RTNL before the VF unregister handshake and admin close. The detach and present-device checks exclude a concurrent new open without holding the global lock across protocol and queue waits.

Probe unwind and removal finish ordinary generic teardown and attempt CMD_CLOSE before making one final direct admin queue check. If that check still fails, clear bus mastering and disable the PCI function. Keep the inert netdev, vnic_dev, admin allocations and control targets rather than freeing device-owned memory. Admin buffers use driver-owned mappings, never page pools or pages returned later from sockets. This patch does not repair the separate generic datapath queue-disable error path.

Keep the BAR reservation to block an ordinary rebind while the PCI device remains enumerated. Use the PCI device name for the reservation and hold a PCI-device reference so the owner-name pointer remains valid after module unload. That reference does not preserve the IOMMU attachment or prove DMA stopped. No IRQ, work or other CPU callback may use the retained objects. DMA debugging can report the deliberately pending allocations; reboot is the supported terminal recovery.

Fixes 3258931d4052 ("enic: add admin channel open and close for SR-IOV")
---
 drivers/net/ethernet/cisco/enic/enic.h       |  15 ++-
 drivers/net/ethernet/cisco/enic/enic_admin.c | 188 +++++++++++++++++++++------
 drivers/net/ethernet/cisco/enic/enic_admin.h |   4 +-
 drivers/net/ethernet/cisco/enic/enic_main.c  | 104 +++++++++++++--
 4 files changed, 249 insertions(+), 62 deletions(-)
drivers/net/ethernet/cisco/enic/enic.h +9 -6
index 7a509a056990..ebe617e752c7 100644
@@ -238,6 +238,12 @@ enum enic_vf_type {
 	ENIC_VF_TYPE_V2,
 };
 
+enum enic_admin_chan_state {
+	ENIC_ADMIN_CHAN_DOWN,
+	ENIC_ADMIN_CHAN_LIVE,
+	ENIC_ADMIN_CHAN_QUARANTINED,
+};
+
 /* Per-instance private data structure */
 struct enic {
 	struct net_device *netdev;
@@ -298,12 +304,9 @@ struct enic {
 
 	/* Admin channel resources for SR-IOV MBOX */
 	bool has_admin_channel;
-	/* true only while the admin WQ/RQ/CQ are allocated and enabled; gates
-	 * enic_admin_channel_close() so it is a no-op after a failed (re)open
-	 * left the resources freed.
-	 */
-	bool admin_chan_up;
-	/* set on send timeout; cleared on channel re-open */
+	/* QUARANTINED retains admin DMA until a final teardown recheck. */
+	enum enic_admin_chan_state admin_chan_state;
+	/* Blocks sends throughout close, partial open and timeout recovery. */
 	bool mbox_send_disabled;
 	struct vnic_wq admin_wq;
 	struct vnic_rq admin_rq;
drivers/net/ethernet/cisco/enic/enic_admin.c +146 -42

235 lines not on this page · raw message

drivers/net/ethernet/cisco/enic/enic_admin.h +3 -1
index 62c80220b0ca..1fe747c3dd35 100644
@@ -20,7 +20,9 @@ struct enic_admin_msg {
 };
 
 int enic_admin_channel_open(struct enic *enic);
-void enic_admin_channel_close(struct enic *enic);
+int enic_admin_channel_close(struct enic *enic);
+int enic_admin_channel_final_recheck(struct enic *enic);
+bool enic_admin_channel_is_quarantined(const struct enic *enic);
 unsigned int enic_admin_wq_cq_service(struct enic *enic);
 unsigned int enic_admin_rq_cq_service(struct enic *enic);
 
drivers/net/ethernet/cisco/enic/enic_main.c +91 -13

217 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH net v7 1/2] enic: retain admin-channel DMA until queues stop

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

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

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

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] When the admin channel is quarantined, the reset workers close the netdev for every device type, but the enic_open() refusal only…
- [Low] enic_admin_channel_close() returns a nonzero value with two different meanings.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch rewrites the same branch and leaves it in place.

--

enic: retain admin-channel DMA until queues stop

The patch tracks the enic admin channel as DOWN, LIVE or QUARANTINED. The admin WQ/RQ/CQ graph is released only after both queues report RUNNING == 0; otherwise it is retained and reopening is refused. The reset workers now abandon the reset and close the netdev when the channel is quarantined. Probe unwind and remove keep the retained resources and the BAR reservation until reboot.

Quoted 4 lines
drivers/net/ethernet/cisco/enic/enic_admin.c +0 -0
index 61c82b48044d0..8a063c563a41e 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/cisco/enic/enic_admin.c +0 -0
@@ -662,6 +661,111 @@ void enic_admin_channel_close(struct enic *enic)

[ ... ]

Quoted 2 lines
drivers/net/ethernet/cisco/enic/enic_admin.c +2 -0
+int enic_admin_channel_close(struct enic *enic)
+{

[ ... ]

Quoted 5 lines
drivers/net/ethernet/cisco/enic/enic_admin.c +5 -0
+	if (wq_err || rq_err) {
+		WRITE_ONCE(enic->admin_chan_state, ENIC_ADMIN_CHAN_QUARANTINED);
+		mutex_unlock(&enic->mbox_lock);
+		/* Retained targets remain valid for late DMA. Keep bus mastering
+		 * enabled for the independent datapath and command transport.

drivers/net/ethernet/cisco/enic/enic_admin.c void enic_admin_channel_close(struct enic *enic) · line 738

Quoted 10 lines
drivers/net/ethernet/cisco/enic/enic_admin.c +10 -0
+		 */
+		return wq_err ?: rq_err;
+	}
+
+	enic_admin_channel_release(enic);
+	mutex_unlock(&enic->mbox_lock);
+
+	/* Firmware rejection does not undermine the WQ/RQ proof. */
+	return qp_err;
+}

[Severity: Low]
By this point the graph has been released and the state is DOWN, but the function still returns qp_err. The only caller that checks the return value is the disable_queues path in enic_admin_channel_open():

	close_err = enic_admin_channel_close(enic);
	if (close_err)
		netdev_err(enic->netdev,
			   "Failed to close partial admin channel: %d\n",
			   close_err);

In the partial-open cases, firmware is likely to reject QP_DISABLE. One case is enic_admin_rq_fill() failing before QP_ENABLE was ever sent. Another is QP_ENABLE itself failing.

Would open then log a close failure even though the channel was fully released?

Right now a nonzero return from enic_admin_channel_close() has two meanings:

- the channel is quarantined and the graph retained (-ETIMEDOUT or -EBUSY)
- the channel was released, but firmware rejected QP_DISABLE

Could the return value tell these two cases apart?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/cisco/enic/enic_main.c +0 -0
index 6b5824f45a14c..899e0b1e14be2 100644

[ ... ]

Quoted 10 lines
drivers/net/ethernet/cisco/enic/enic_main.c +3 -0
@@ -2264,17 +2276,27 @@ static void enic_reset(struct work_struct *work)
 
 	rtnl_lock();
 
+	if (!netif_running(enic->netdev))
+		goto unlock;
+
 	/* Stop any activity from infiniband */
 	enic_set_api_busy(enic, true);
 

[ ... ]

drivers/net/ethernet/cisco/enic/enic_main.c static void enic_reset(struct work_struct *work) · line 2299

Quoted 12 lines
drivers/net/ethernet/cisco/enic/enic_main.c +10 -1
-	if (enic_has_admin_chan(enic))
+	if (enic_has_admin_chan(enic)) {
 		enic_admin_channel_close(enic);
+		/* Channel close has drained registration replies. */
+		if (enic_is_sriov_vf_v2(enic))
+			WRITE_ONCE(enic->vf_registered, false);
+	}
+	if (enic_admin_channel_is_quarantined(enic)) {
+		/* Core close excludes netpoll and clears __LINK_STATE_START first. */
+		dev_close(enic->netdev);
+		goto reset_out;
+	}

[Severity: Medium]
This check does not look at the device type, and it runs even when enic_has_admin_chan() returned false. Can it close a PF and skip the soft reset?

The other two quarantine checks apply only to a V2 VF. One is the post-reopen check later in this function:

	if (enic_is_sriov_vf_v2(enic) &&
	    enic_admin_channel_is_quarantined(enic))
		dev_close(enic->netdev);

The other is the refusal in enic_open():

	if (enic_is_sriov_vf_v2(enic) &&
	    enic_admin_channel_is_quarantined(enic))
		return -EBUSY;

A PF admin channel can become quarantined in two ways. One is enic_admin_channel_close() timing out here while SR-IOV V2 is enabled. The other is enic_sriov_v2_disable(), which clears ENIC_SRIOV_ENABLED before the close:

	enic->priv_flags &= ~ENIC_SRIOV_ENABLED;
	cancel_work_sync(&enic->link_notify_work);

	pci_disable_sriov(enic->pdev);
	enic_admin_channel_close(enic);

After that, every soft reset would dev_close() the PF uplink and skip enic_dev_soft_reset(). The same check in enic_tx_hang_reset() would skip enic_dev_hang_notify() and enic_dev_hang_reset().

enic_open() still allows the PF to come back up, but without the reset it needed. The next queue error or tx hang would then close it again.

The commit message describes only the VF policy:

"A V2 VF with a quarantined control channel is closed and cannot reopen."

Is closing the PF here intended? If it is, should enic_open() and the commit message describe the same PF behaviour?

This looks latent for now. enic_sriov_v2_enable() is __maybe_unused and .sriov_configure is not wired up yet, so a PF admin channel cannot be opened today. It would become reachable when the follow-up series wires up .sriov_configure.

drivers/net/ethernet/cisco/enic/enic_main.c static void enic_reset(struct work_struct *work) · line 2313

Quoted 10 lines
drivers/net/ethernet/cisco/enic/enic_main.c +2 -1
 	enic_stop(enic->netdev);
 	if (enic_is_sriov_vf_v2(enic))
@@ -2287,7 +2309,8 @@ static void enic_reset(struct work_struct *work)
 	enic_dev_set_ig_vlan_rewrite_mode(enic);
 	enic_ext_cq(enic);
 
-	enic_open(enic->netdev);
+	if (enic_open(enic->netdev))
+		goto reset_out;

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but the patch rewrites this branch. When enic_open() fails, the worker jumps to reset_out and the netdev keeps IFF_UP and __LINK_STATE_START. Can that leave NAPI disabled on a device the core still treats as running?

enic_stop() above has already called napi_disable() on every RQ and WQ NAPI, and every failure exit in enic_open() leaves them disabled. enic_request_intr(), enic_dev_notify_set(), page_pool_create() and the RQ fill all fail before napi_enable(). The err_out_dev_enable path calls napi_disable() again.

One way to hit this is in enic_tx_hang_reset(). If vnic_wq_disable() times out, enic_stop() returns early without freeing the IRQs. enic_request_intr() then fails with -EBUSY.

The next ndo_stop then runs this chain. That can be a user ifdown, the enic_stop() in a later reset, or unregister_netdev() in enic_remove():

enic_stop()
napi_disable()
napi_disable_locked()

napi_disable_locked() waits on a NAPI that still has NAPIF_STATE_SCHED and NAPIF_STATE_NPSVC set:

	while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
		usleep_range(20, 200);
		val = READ_ONCE(n->state);
	}

Would this loop forever while RTNL is held?

enic_stop() would also run enic_dev_notify_unset() a second time, and disable and clean the WQs and RQs a second time, after they have already been torn down.

The quarantine branch added above uses dev_close() to reach a consistent closed state. Does the failed-open branch need a similar way out, both here and in enic_tx_hang_reset()?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109-b4-enic-dma-vf-index-net-generic-first-v1-20261010-v7-0-30ca6f467673%40cisco.com
author maintainer
#3 lore raw

Re: [PATCH net v7 1/2] enic: retain admin-channel DMA until queues stop

Thanks for the review.

Quoted 1 line

enic_admin_channel_close() can return an error after releasing the graph.

Agreed. The QP_DISABLE result and the direct queue-stop checks describe different outcomes. If both complete disable helpers succeed, the resources are released and the state becomes DOWN, even when firmware rejected QP_DISABLE. The partial-open caller can therefore print a misleading close-failure message. The queue-stop proof and resource handling remain correct.

Quoted 1 line

The quarantine check can close a PF and prevent its reset.

The ownership check deliberately remains outside enic_has_admin_chan(). Disabling SR-IOV clears ENIC_SRIOV_ENABLED but can leave retained admin resources with unresolved DMA ownership. Clearing that flag must not bypass the reset guard.

I agree that PF reset and reopen policy need to be consistent. PF admin-channel activation is dormant in this series because .sriov_configure is not registered.

Quoted 2 lines

A failed internal reopen can leave the interface marked up and allow repeated NAPI teardown.

Agreed. This is the pre-existing datapath lifecycle issue acknowledged in my earlier replies. Adding dev_close() directly after failed reopen would invoke another stop and can encounter the same problem.

I will handle the pre-existing datapath lifecycle issue in a separate fix. The PF quarantine and recovery policy will be addressed before PF SR-IOV activation, and I will follow up separately on the close-status diagnostic.

If there are no further concerns with the two fixes in V7, would you please consider applying the series to net?

Regards,
Satish

author maintainer
#4 lore raw

PATCH v7 2/2 enic: require DEVCMD2 and set the V2 VF mailbox source

In reply to Satish Kharat

V2 VFs currently transmit mailbox source zero. A deployed async PF checks that field against the sender identity obtained from CQ metadata, so VFs other than VF zero cannot register with that PF.

Require DEVCMD2 for V2 PF support and V2 VF probe, preserving the DEVCMD1 fallback for ordinary PF Ethernet, V1 and usNIC. Enable the admin QP, then query CMD_SRIOV_STATS_GET while its receive interrupt is still masked. The version-1 statistics prefix is stable, so accept that version or later. Firmware vf_index and mailbox src_vnic_id use 0xffff for the PF and zero-based values for VFs. Hardware CQ sender metadata uses 0 for the PF and vf_index + 1 for a VF; receive handling converts it to the mailbox identity. Reject a returned 0xffff and publish the VF index as the mailbox source. For PF messages, use the deployed 0xffff source value instead of the old zero-filled field. Permit sends before unmasking the interrupt so queued notifications can be processed and acknowledged with a valid source. Sends remain disabled until the ID is valid, without a separate unknown-ID send check or reliance on PF retransmission. Query failures use the partial-open close path and its existing ownership checks.

CMD_SRIOV_STATS_GET is mandatory for V2 VF probe. Firmware which does not implement it fails probe because the mailbox source ID cannot otherwise be determined safely. Do not fall back to source zero, which would identify only VF zero correctly.

Keep the coherent statistics target for the vNIC lifetime. Extend the DEVCMD2 transport with an optional per-call observation of NOT_POSTED, POSTED or COMPLETED. In the common result path, read the completion color with READ_ONCE() and use dma_rmb() before consuming device-written result fields. A posted statistics command without a result leaves its target unresolved. A later blocking QP or close command result fences that target through command ordering, including a firmware error result. Observe close completion in both probe unwind and removal so a completed close does not leave the statistics target unnecessarily retained. Pre-submission errors, posted timeouts and NOWAIT posting do not establish completion. This keeps transport completion separate from command success and admin WQ/RQ queue-stop proof.

On an unresolved probe failure retain the inert control owner and target through final containment instead of freeing memory which the command may still write. Refuse reuse of an unresolved statistics target.

Fixes 1f0c856b5963 ("enic: add MBOX core send and receive for admin channel")
---
 drivers/net/ethernet/cisco/enic/enic.h        |  6 ++
 drivers/net/ethernet/cisco/enic/enic_admin.c  | 52 ++++++++++++++--
 drivers/net/ethernet/cisco/enic/enic_dev.c    | 44 ++++++++++++++
 drivers/net/ethernet/cisco/enic/enic_dev.h    |  3 +
 drivers/net/ethernet/cisco/enic/enic_main.c   | 29 +++++++--
 drivers/net/ethernet/cisco/enic/enic_mbox.c   | 12 +++-
 drivers/net/ethernet/cisco/enic/vnic_dev.c    | 85 ++++++++++++++++++++++++++-
 drivers/net/ethernet/cisco/enic/vnic_dev.h    | 15 +++++
 drivers/net/ethernet/cisco/enic/vnic_devcmd.h | 34 +++++++++++
 9 files changed, 265 insertions(+), 15 deletions(-)
drivers/net/ethernet/cisco/enic/enic.h +6 -0
index ebe617e752c7..a4f9f58c1adf 100644
@@ -271,6 +271,12 @@ struct enic {
 	u16 num_vfs;
 	enum enic_vf_type vf_type;
 	bool vf_registered;
+	u16 vf_id;
+	/* A statistics-command timeout leaves its persistent coherent target
+	 * device-owned until completion of a blocking QP or close command is
+	 * observed.
+	 */
+	bool sriov_stats_dma_unresolved;
 	u32 pf_cap_version;
 	unsigned int enable_count;
 	spinlock_t enic_api_lock;
drivers/net/ethernet/cisco/enic/enic_admin.c +46 -6

85 lines not on this page · raw message

drivers/net/ethernet/cisco/enic/enic_dev.c +44 -0

50 lines not on this page · raw message

drivers/net/ethernet/cisco/enic/enic_dev.h +3 -0
index 698d0cb02064..eed1674ff30f 100644
@@ -40,6 +40,9 @@ int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic);
 int enic_dev_enable(struct enic *enic);
 int enic_dev_disable(struct enic *enic);
 int enic_dev_intr_coal_timer_info(struct enic *enic);
+int enic_dev_close(struct enic *enic);
+int enic_dev_sriov_stats(struct enic *enic,
+			 struct vnic_sriov_stats **stats);
 int enic_dev_status_to_errno(int devcmd_status);
 
 #endif /* _ENIC_DEV_H_ */
drivers/net/ethernet/cisco/enic/enic_main.c +25 -4
index 899e0b1e14be..6d49d7105a0d 100644
@@ -2203,6 +2203,12 @@ static bool enic_has_admin_chan(struct enic *enic)
 	       (enic_sriov_enabled(enic) && enic->vf_type == ENIC_VF_TYPE_V2);
 }
 
+static bool enic_control_dma_unresolved(struct enic *enic)
+{
+	return enic_admin_channel_is_quarantined(enic) ||
+	       READ_ONCE(enic->sriov_stats_dma_unresolved);
+}
+
 /* Re-establish the admin/MBOX channel after a reset has re-created the data
  * path.  Mirrors the relevant part of the probe / SR-IOV-enable sequence:
  * reinitialise MBOX and reopen the channel, then for a VF re-run the PF
@@ -2886,6 +2892,12 @@ static void enic_sriov_detect_vf_type(struct enic *enic)
 
 	if (enic->vf_type != ENIC_VF_TYPE_V2)
 		return;
+	if (!vnic_dev_uses_devcmd2(enic->vdev)) {
+		dev_warn(&pdev->dev,
+			 "SR-IOV V2 requires DEVCMD2; disabling V2 support\n");
+		enic->vf_type = ENIC_VF_TYPE_NONE;
+		return;
+	}
 
 	/* A successful command means firmware recognizes
 	 * VIC_FEATURE_SRIOV; supported_versions is available
@@ -3070,6 +3082,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	enic = netdev_priv(netdev);
 	enic->netdev = netdev;
 	enic->pdev = pdev;
+	WRITE_ONCE(enic->vf_id, ENIC_MBOX_DST_PF);
 	spin_lock_init(&enic->vf_link_state_lock);
 
 	/* Setup PCI resources
@@ -3137,6 +3150,12 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	if (err)
 		goto err_out_vnic_unregister;
+	if (enic_is_sriov_vf_v2(enic) &&
+	    !vnic_dev_uses_devcmd2(enic->vdev)) {
+		dev_err(dev, "SR-IOV V2 VF requires DEVCMD2\n");
+		err = -EOPNOTSUPP;
+		goto err_out_vnic_unregister;
+	}
 
 #ifdef CONFIG_PCI_IOV
 	enic_sriov_detect_vf_type(enic);
@@ -3265,6 +3284,8 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 				"MBOX VF registration failed: %d\n", err);
 			goto err_out_admin_close;
 		}
+		dev_info(dev, "V2 VF registered, VF index %u\n",
+			 READ_ONCE(enic->vf_id));
 	}
 
 	netif_set_real_num_tx_queues(netdev, enic->wq_count);
@@ -3409,7 +3430,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 err_out_dev_deinit:
 	enic_dev_deinit(enic);
 err_out_dev_close:
-	vnic_dev_close(enic->vdev);
+	enic_dev_close(enic);
 	if (enic_admin_channel_is_quarantined(enic))
 		enic_admin_channel_final_recheck(enic);
 err_out_disable_sriov:
@@ -3422,7 +3443,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 #endif
 err_out_vnic_unregister:
-	if (enic_admin_channel_is_quarantined(enic)) {
+	if (enic_control_dma_unresolved(enic)) {
 		/* Normal generic cleanup and CMD_CLOSE have already run. Retain
 		 * only the inert admin/control owners and their PCI reservation.
 		 */
@@ -3492,11 +3513,11 @@ static void enic_remove(struct pci_dev *pdev)
 		}
 #endif
 		enic_dev_deinit(enic);
-		vnic_dev_close(enic->vdev);
+		enic_dev_close(enic);
 		if (enic_admin_channel_is_quarantined(enic))
 			enic_admin_channel_final_recheck(enic);
 		kfree(enic->pp);
-		if (enic_admin_channel_is_quarantined(enic)) {
+		if (enic_control_dma_unresolved(enic)) {
 			/* All generic queues and CPU entry points followed ordinary
 			 * teardown. No admin buffer can return from the network stack.
 			 * Pin the PCI object for the reservation's owner-name pointer;
drivers/net/ethernet/cisco/enic/enic_mbox.c +10 -2
index 5c93ca49552a..a1f8138d0bbd 100644
@@ -18,10 +18,17 @@
 #define ENIC_MBOX_POLL_TIMEOUT_US	5000000
 #define ENIC_MBOX_POLL_INTERVAL_US	100
 
-static void enic_mbox_fill_hdr(struct enic_mbox_hdr *hdr, u8 msg_type,
+static void enic_mbox_fill_hdr(struct enic *enic, struct enic_mbox_hdr *hdr,
+			       u8 msg_type,
 			       u16 dst_vnic_id, u16 msg_len, u64 msg_num)
 {
+	u16 src_vnic_id = ENIC_MBOX_DST_PF;
+
+	if (enic_is_sriov_vf_v2(enic))
+		src_vnic_id = READ_ONCE(enic->vf_id);
+
 	memset(hdr, 0, sizeof(*hdr));
+	hdr->src_vnic_id = cpu_to_le16(src_vnic_id);
 	hdr->dst_vnic_id = cpu_to_le16(dst_vnic_id);
 	hdr->msg_type = msg_type;
 	hdr->msg_len = cpu_to_le16(msg_len);
@@ -85,7 +92,8 @@ static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
 		reply_expected = true;
 	}
 
-	enic_mbox_fill_hdr(buf, msg_type, dst_vnic_id, total_len, msg_num);
+	enic_mbox_fill_hdr(enic, buf, msg_type, dst_vnic_id, total_len,
+			   msg_num);
 	if (payload_len) {
 		void *dst = buf + sizeof(struct enic_mbox_hdr);
 
drivers/net/ethernet/cisco/enic/vnic_dev.c +82 -3

130 lines not on this page · raw message

drivers/net/ethernet/cisco/enic/vnic_dev.h +15 -0
index 7fdd8c661c99..6a4d7ce3b636 100644
@@ -93,6 +93,8 @@ struct vnic_dev {
 	dma_addr_t linkstatus_pa;
 	struct vnic_stats *stats;
 	dma_addr_t stats_pa;
+	struct vnic_sriov_stats *sriov_stats;
+	dma_addr_t sriov_stats_pa;
 	struct vnic_devcmd_fw_info *fw_info;
 	dma_addr_t fw_info_pa;
 	enum vnic_proxy_type proxy;
@@ -106,6 +108,12 @@ struct vnic_dev {
 
 struct vnic_stats;
 
+enum vnic_devcmd2_status {
+	VNIC_DEVCMD2_NOT_POSTED,
+	VNIC_DEVCMD2_POSTED,
+	VNIC_DEVCMD2_COMPLETED,
+};
+
 void *vnic_dev_priv(struct vnic_dev *vdev);
 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
 	enum vnic_res_type type);
@@ -118,6 +126,9 @@ void vnic_dev_free_desc_ring(struct vnic_dev *vdev,
 	struct vnic_dev_ring *ring);
 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
 	u64 *a0, u64 *a1, int wait);
+int vnic_dev_cmd2_status(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
+			 u64 *a0, u64 *a1, int wait,
+			 enum vnic_devcmd2_status *status);
 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, u16 index);
 void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev);
 int vnic_dev_fw_info(struct vnic_dev *vdev,
@@ -163,6 +174,7 @@ struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
 	void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar,
 	unsigned int num_bars);
 struct pci_dev *vnic_dev_get_pdev(struct vnic_dev *vdev);
+bool vnic_dev_uses_devcmd2(struct vnic_dev *vdev);
 int vnic_dev_init_prov2(struct vnic_dev *vdev, u8 *buf, u32 len);
 int vnic_dev_enable2(struct vnic_dev *vdev, int active);
 int vnic_dev_enable2_done(struct vnic_dev *vdev, int *status);
@@ -177,5 +189,8 @@ int vnic_dev_overlay_offload_cfg(struct vnic_dev *vdev, u8 overlay,
 int vnic_dev_get_supported_feature_ver(struct vnic_dev *vdev, u8 feature,
 				       u64 *supported_versions, u64 *a1);
 int vnic_dev_capable_rss_hash_type(struct vnic_dev *vdev, u8 *rss_hash_type);
+int vnic_dev_sriov_stats(struct vnic_dev *vdev,
+			 struct vnic_sriov_stats **stats,
+			 enum vnic_devcmd2_status *status);
 
 #endif /* _VNIC_DEV_H_ */
drivers/net/ethernet/cisco/enic/vnic_devcmd.h +34 -0
index 90ca06691ebd..9f397df88c50 100644
@@ -461,6 +461,14 @@ enum vnic_devcmd_cmd {
 	 * in: (u32) a1 = enable (1) / disable (0)
 	 */
 	CMD_QP_TYPE_SET = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 97),
+
+	/*
+	 * Get SR-IOV capabilities, resource usage, and this function's logical
+	 * VF index.
+	 * in: (u64) a0 = DMA address of struct vnic_sriov_stats
+	 * in: (u32) a1 = length of the buffer
+	 */
+	CMD_SRIOV_STATS_GET = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 98),
 };
 
 #define QP_TYPE_ADMIN	0
@@ -468,6 +476,32 @@ enum vnic_devcmd_cmd {
 #define QP_ENABLE	1
 #define QP_DISABLE	0
 
+#define VNIC_SRIOV_STATS_VERSION	1
+
+struct vnic_sriov_stats {
+	__le32 ver;
+	u8 sriov_vlan_membership_cap;
+	u8 sriov_vlan_membership_enabled;
+	u8 sriov_rss_vf_full_cap;
+	u8 sriov_host_rx_stats;
+	__le32 ig_classifier0_tcam_cfg;
+	__le32 ig_classifier0_tcam_free;
+	__le32 eg_classifier0_tcam_cfg;
+	__le32 eg_classifier0_tcam_free;
+	__le32 ig_classifier1_tcam_cfg;
+	__le32 ig_classifier1_tcam_free;
+	__le32 eg_classifier1_tcam_cfg;
+	__le32 eg_classifier1_tcam_free;
+	__le32 sriov_ig_flow_table_cfg;
+	__le32 sriov_ig_flow_table_free;
+	__le32 sriov_eg_flow_table_cfg;
+	__le32 sriov_eg_flow_table_free;
+	u8 admin_qp_ready[32];
+	__le16 vf_index;
+	__le16 reserved1;
+	__le32 reserved2[256 - 23];
+};
+
 /* CMD_ENABLE2 flags */
 #define CMD_ENABLE2_STANDBY 0x0
 #define CMD_ENABLE2_ACTIVE  0x1
Signature · 1 line
2.43.0
#5 lore raw
In reply to Satish Kharat
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 13 lines · On Mon, 09 Nov 2026 12:39:33 -0800 you wrote:

Fix premature freeing of admin-channel buffers and set the correct V2 VF source ID in mailbox messages. This is v7 of the two-patch admin-only series. The generic datapath quarantine proposal withdrawn in v2 remains out of scope, including its page-pool/device lifetime problem.

The first patch releases the admin WQ/RQ/CQ allocation only after both complete queue-disable helpers succeed. Give both queues a first attempt, then retry once only a helper which timed out. The 500 ms polling bound is local to admin shutdown, and both RQ disable/check passes are preserved. Ordinary datapath and DEVCMD2 queue timeouts are unchanged. Admin receive buffers are driver-owned mappings, not page-pool pages returned later from the networking stack.

Quoted 1 line

[...]

Here is the summary with links:
- [net,v7,1/2] enic: retain admin-channel DMA until queues stop

    https://git.kernel.org/netdev/net-next/c/b3ae89a2e167
  - [net,v7,2/2] enic: require DEVCMD2 and set the V2 VF mailbox source
    https://git.kernel.org/netdev/net-next/c/65230b3ffd75

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html