* [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started [not found] <20261204194642.3048406-1-anthony.l.nguyen@intel.com> @ 2026-12-04 19:46 ` Tony Nguyen 2026-12-05 20:47 ` netdev-bot+sashiko 2026-12-04 19:46 ` [PATCH net v2 3/6] idpf: ignore link events " Tony Nguyen 2026-12-04 19:46 ` [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen 2 siblings, 1 reply; 6+ messages in thread From: Tony Nguyen @ 2026-12-04 19:46 UTC (permalink / raw) To: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev Cc: Tian Xun Ng, anthony.l.nguyen, oss.patchbox, luckilystar08, emil.s.tantilov, richardcochran, milena.olech, konstantin.ilichev, stable, Samuel Salin From: Tian Xun Ng <tianxun.ng@bytedance.com> On remove, idpf_vc_core_deinit() keeps the virtchnl transaction manager up until the vports have been torn down, so mbx_task keeps processing replies while idpf_ptp_release() frees the Tx timestamp trackers. An async VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP reply handled in that window reaches idpf_ptp_get_tx_tstamp_async_handler(), which reads vport->tx_tstamp_caps and takes its lock after idpf_ptp_release_vport_tstamp() may already have freed it. Once IDPF_REMOVE_IN_PROG is set, wait for a mailbox task that may be running a callback before releasing anything, and make the Tx timestamp callback return when the bit is set. Matched replies to synchronous transactions are not affected, so the vport teardown still receives them; mbx_task is requeued straight away for that. The last patch of this series sets IDPF_REMOVE_IN_PROG on shutdown too, which would otherwise expose shutdown to the same window. Fixes: 1a49cf814fe1 ("idpf: add Tx timestamp flows") Cc: stable@vger.kernel.org Signed-off-by: Tian Xun Ng <tianxun.ng@bytedance.com> Reviewed-by: Emil Tantilov <emil.s.tantilov@intel.com> Tested-by: Samuel Salin <Samuel.salin@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> --- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 12 +++++++++++- drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index c89783966bae..348c7875134a 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -3262,8 +3262,18 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter) /* Avoid transaction timeouts when called during reset */ remove_in_prog = test_bit(IDPF_REMOVE_IN_PROG, adapter->flags); - if (!remove_in_prog) + if (!remove_in_prog) { libie_ctlq_xn_shutdown(adapter->xnm); + } else { + /* The transaction manager stays up for the teardown below, so + * async replies can still arrive. Wait for a mailbox task that + * may be running an async callback; callbacks that run later + * see IDPF_REMOVE_IN_PROG and leave the state released below + * alone. + */ + cancel_delayed_work_sync(&adapter->mbx_task); + queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0); + } idpf_ptp_release(adapter); idpf_deinit_task(adapter); diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c index 14dba40a993f..1422b30d09a3 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c @@ -550,7 +550,8 @@ idpf_ptp_get_tx_tstamp_async_handler(void *ctx, struct kvec *mem, int status) u16 num_latches; u32 vport_id; - if (status) + /* The Tx timestamp trackers are released on remove and shutdown */ + if (status || test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) return; recv_tx_tstamp_msg = mem->iov_base; -- 2.47.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started 2026-12-04 19:46 ` [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen @ 2026-12-05 20:47 ` netdev-bot+sashiko 0 siblings, 0 replies; 6+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 20:47 UTC (permalink / raw) To: anthony.l.nguyen Cc: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev, tianxun.ng, oss.patchbox, luckilystar08, emil.s.tantilov, richardcochran, milena.olech, konstantin.ilichev, stable, Samuel.salin Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 0 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). - [High] This patch closes only one of the paths that use the Tx timestamp trackers after they are freed on remove (and, once the later… -- idpf: ignore Tx timestamp replies once removal has started When IDPF_REMOVE_IN_PROG is set, this patch makes idpf_vc_core_deinit() wait for mbx_task to finish before releasing the PTP state. It then queues mbx_task again right away, so replies to synchronous transactions are still handled during vport teardown. It also makes idpf_ptp_get_tx_tstamp_async_handler() return early once IDPF_REMOVE_IN_PROG is set. > diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > index c89783966bae3..348c7875134ad 100644 > --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > @@ -3262,8 +3262,18 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter) > > /* Avoid transaction timeouts when called during reset */ > remove_in_prog = test_bit(IDPF_REMOVE_IN_PROG, adapter->flags); > - if (!remove_in_prog) > + if (!remove_in_prog) { > libie_ctlq_xn_shutdown(adapter->xnm); > + } else { > + /* The transaction manager stays up for the teardown below, so > + * async replies can still arrive. Wait for a mailbox task that > + * may be running an async callback; callbacks that run later > + * see IDPF_REMOVE_IN_PROG and leave the state released below > + * alone. > + */ > + cancel_delayed_work_sync(&adapter->mbx_task); > + queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0); > + } > > idpf_ptp_release(adapter); > idpf_deinit_task(adapter); [Severity: High] The mailbox async handler is gated now. Are other users of the Tx timestamp trackers still live at this point? idpf_ptp_release() still runs before idpf_deinit_task(). NAPI and xmit for the vports are stopped only later, in: idpf_deinit_task()->idpf_vport_dealloc()->idpf_vport_stop() Neither idpf_remove() nor idpf_shutdown() closes or detaches the netdevs before this. So the datapath can still be running while idpf_ptp_release_vport_tstamp() does this: cancel_work_sync(&vport->tstamp_task); ... kfree(vport->tx_tstamp_caps); vport->tx_tstamp_caps = NULL; Only the vport pointer is cleared. Each txq->cached_tstamp_caps, set in idpf_vport_init_fast_path_txqs(), still points at the freed object. On xmit, idpf_tx_tstamp()->idpf_ptp_get_txq_tstamp_capability() reads txq->cached_tstamp_caps->access. idpf_ptp_request_ts() then does: spin_lock(&tx_q->cached_tstamp_caps->latches_lock); head = &tx_q->cached_tstamp_caps->latches_free; ... Can this take the lock and move list entries in freed memory? On Tx completion, idpf_tx_clean_bufs() calls idpf_tx_read_tstamp() for an skb that has SKBTX_IN_PROGRESS set: tx_tstamp_caps = txq->cached_tstamp_caps; spin_lock_bh(&tx_tstamp_caps->status_lock); ... tx_tstamp_status->skb = skb; tx_tstamp_status->state = IDPF_PTP_REQUEST; ... queue_work(system_dfl_wq, txq->tstamp_task); Doesn't this write into the freed tracker? It also queues tstamp_task again after the only cancel_work_sync(). If tstamp_task runs again, idpf_tstamp_task()->idpf_ptp_get_tx_tstamp() has no NULL or IDPF_REMOVE_IN_PROG check: tx_tstamp_caps = vport->tx_tstamp_caps; head = &tx_tstamp_caps->latches_in_use; size = struct_size(send_tx_tstamp_msg, tstamp_latches, tx_tstamp_caps->num_entries); Would this oops on the NULL tx_tstamp_caps? Nothing cancels tstamp_task again before idpf_vport_dealloc()->idpf_vport_rel() frees the vport. Could a late run also reach the freed vport through container_of()? The commit message describes the bug as code that "reads vport->tx_tstamp_caps and takes its lock after idpf_ptp_release_vport_tstamp() may already have freed it". The new comment says later callbacks "leave the state released below alone". The xmit, Tx completion and tstamp_task paths reach the same object in the same window. The later patch in this series sets IDPF_REMOVE_IN_PROG on shutdown, so shutdown would be exposed to these paths too. This code is also unchanged at the end of the series. The order is still idpf_ptp_release() and then idpf_deinit_task(), cached_tstamp_caps is never cleared, and idpf_ptp_get_tx_tstamp() has no check. To trigger this, HW Tx timestamping has to be enabled (SIOCSHWTSTAMP) and SO_TIMESTAMPING traffic has to be flowing when the device is removed or shut down. Would it work better to quiesce Tx first, or to release the trackers only after idpf_deinit_task() has stopped the vports? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204194642.3048406-1-anthony.l.nguyen%40intel.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v2 3/6] idpf: ignore link events once removal has started [not found] <20261204194642.3048406-1-anthony.l.nguyen@intel.com> 2026-12-04 19:46 ` [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen @ 2026-12-04 19:46 ` Tony Nguyen 2026-12-05 20:47 ` netdev-bot+sashiko 2026-12-04 19:46 ` [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen 2 siblings, 1 reply; 6+ messages in thread From: Tony Nguyen @ 2026-12-04 19:46 UTC (permalink / raw) To: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev Cc: Tian Xun Ng, anthony.l.nguyen, oss.patchbox, luckilystar08, emil.s.tantilov, richardcochran, milena.olech, konstantin.ilichev, stable, Samuel Salin From: Tian Xun Ng <tianxun.ng@bytedance.com> mbx_task keeps handling mailbox events while idpf_deinit_task() releases the vports: it requeues itself, or is queued from the mailbox interrupt, until idpf_vc_core_deinit() cancels it once the vports are gone. A VIRTCHNL2_EVENT_LINK_CHANGE event handled in that window looks its vport up in adapter->vports[] without a lock, and idpf_vport_dealloc() releases the netdev and frees the vport before it clears that slot, so idpf_handle_event_link() can follow a NULL netdev pointer or use the freed vport. Make idpf_handle_event_link() return once IDPF_REMOVE_IN_PROG is set. The previous patch waits for a running mbx_task after the bit is set and before anything is released, so on remove a link event is either handled before the vports are torn down or ignored. Shutdown has the same window today; the last patch of this series sets the bit there as well. The window also remains on a hard reset, which tears the vports down without setting the bit; that path is not changed here. Fixes: 02cbfba1add5 ("idpf: add ethtool callbacks") Cc: stable@vger.kernel.org Signed-off-by: Tian Xun Ng <tianxun.ng@bytedance.com> Reviewed-by: Emil Tantilov <emil.s.tantilov@intel.com> Tested-by: Samuel Salin <Samuel.salin@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> --- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index 348c7875134a..854eb1f1ada4 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -41,6 +41,10 @@ static void idpf_handle_event_link(struct idpf_adapter *adapter, struct idpf_netdev_priv *np; struct idpf_vport *vport; + /* The vports are released on remove and shutdown */ + if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) + return; + vport = idpf_vid_to_vport(adapter, le32_to_cpu(v2e->vport_id)); if (!vport) { dev_err_ratelimited(&adapter->pdev->dev, "Failed to find vport_id %d for link event\n", -- 2.47.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 3/6] idpf: ignore link events once removal has started 2026-12-04 19:46 ` [PATCH net v2 3/6] idpf: ignore link events " Tony Nguyen @ 2026-12-05 20:47 ` netdev-bot+sashiko 0 siblings, 0 replies; 6+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 20:47 UTC (permalink / raw) To: anthony.l.nguyen Cc: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev, tianxun.ng, oss.patchbox, luckilystar08, emil.s.tantilov, richardcochran, milena.olech, konstantin.ilichev, stable, Samuel.salin Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] On remove, the fix only works together with the mbx_task drain added by the previous patch in the series ("idpf: ignore Tx timestamp… Pre-existing issues: - [High] This patch did not introduce the problem: the same link-event use-after-free stays reachable on teardown paths that do not set… - [High] This patch did not introduce the problem: a link event can see a vport before its netdev is set. - [High] This patch did not introduce the problem: idpf_handle_event_link() can wake the TX queues of a vport whose… -- idpf: ignore link events once removal has started This patch makes idpf_handle_event_link() return early once IDPF_REMOVE_IN_PROG is set. On remove, it relies on the mbx_task drain added by the previous patch, so a link event is either handled before the vports are torn down or ignored. The commit message notes that hard reset still has the window and that shutdown is handled later in the series. > diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > index 348c7875134ad..854eb1f1ada4c 100644 > --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > @@ -41,6 +41,10 @@ static void idpf_handle_event_link(struct idpf_adapter *adapter, > struct idpf_netdev_priv *np; > struct idpf_vport *vport; > > + /* The vports are released on remove and shutdown */ > + if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) > + return; > + [Severity: Low] On remove, this check only closes the window when combined with the mbx_task drain from the previous patch in the series ("idpf: ignore Tx timestamp replies once removal has started"). That drain is in idpf_vc_core_deinit(): } else { ... cancel_delayed_work_sync(&adapter->mbx_task); queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0); } Without the drain, this test_bit() is check-then-act. Suppose an mbx_task passed the check before idpf_remove() set IDPF_REMOVE_IN_PROG. It can still be inside idpf_handle_event_link() when idpf_deinit_task()->idpf_vport_dealloc() frees the vport. The previous patch has Fixes: 1a49cf814fe1. This patch has Fixes: 02cbfba1add5 and a plain Cc: stable, with no note about the prerequisite. Some stable trees have 02cbfba1add5 but not 1a49cf814fe1 (6.12.y, for example). Those trees would not pick up the previous patch, and its context (idpf_ptp_release()) does not exist there. In those trees this statement from the commit message would not hold: "on remove a link event is either handled before the vports are torn down or ignored" The race would only be narrowed. Could the stable tag get a "# depends on" note? Alternatively, the drain could be split out with a Fixes tag that covers 02cbfba1add5. > vport = idpf_vid_to_vport(adapter, le32_to_cpu(v2e->vport_id)); [Severity: High] This is a pre-existing issue and was not introduced by this patch. The same use-after-free can still happen on teardown paths that never set IDPF_REMOVE_IN_PROG. The commit message already mentions hard reset. idpf_init_hard_reset() calls idpf_vc_core_deinit() with remove_in_prog false. So mbx_task is not drained before idpf_deinit_task(), and it is only cancelled afterwards: idpf_ptp_release(adapter); idpf_deinit_task(adapter); ... cancel_delayed_work_sync(&adapter->serv_task); cancel_delayed_work_sync(&adapter->mbx_task); The commit message does not mention the unwind_vports error path in idpf_init_task(), which has the same problem. It frees the vports while mbx_task is live and cancels mbx_task only afterwards: unwind_vports: if (default_vport) { for (index = 0; index < adapter->max_vports; index++) { if (adapter->vports[index]) idpf_vport_dealloc(adapter->vports[index]); } } ... if (test_and_clear_bit(IDPF_HR_DRV_LOAD, adapter->flags)) { cancel_delayed_work_sync(&adapter->serv_task); cancel_delayed_work_sync(&adapter->mbx_task); } libie_ctlq_xn_shutdown() does not stop these events. libie_ctlq_xn_recv() still passes any message that libie_ctlq_xn_process_recv() does not claim to params->ctlq_msg_handler. So unsolicited VIRTCHNL2_EVENT_LINK_CHANGE messages keep arriving. IDPF_HR_RESET_IN_PROG is set on both paths, so idpf_vport_dealloc() skips idpf_decfg_netdev(). It then frees the vport before clearing its slot: idpf_vport_rel(vport); <-- kfree(vport) adapter->vports[i] = NULL; Can a concurrent link event get the vport from idpf_vid_to_vport() and then read vport->netdev and read/write vport->link_up after the kfree()? This could be triggered by a driver-initiated function reset (for example after a Tx timeout). It could also be triggered by an idpf_init_task() failure after at least one vport was allocated. The shutdown part of this is fixed later in the series by "idpf: keep the mailbox up while tearing down vports on shutdown". That patch sets IDPF_REMOVE_IN_PROG at the start of idpf_shutdown(). > if (!vport) { > dev_err_ratelimited(&adapter->pdev->dev, "Failed to find vport_id %d for link event\n", [Severity: High] This is also a pre-existing issue and was not introduced by this patch. Can a link event see a vport before its netdev has been set? idpf_vport_alloc() publishes the vport with plain stores: adapter->vports[idx] = vport; adapter->vport_ids[idx] = idpf_get_vport_id(vport); vport->netdev is only assigned later, when idpf_init_task() calls idpf_cfg_netdev(): if (idpf_cfg_netdev(vport)) goto unwind_vports; At that point mbx_task is already running and IDPF_REMOVE_IN_PROG is clear. Suppose a VIRTCHNL2_EVENT_LINK_CHANGE for the new vport_id arrives in that window. idpf_vid_to_vport() returns a vport whose netdev is still NULL, and idpf_handle_event_link() then does: np = netdev_priv(vport->netdev); np->link_speed_mbps = le32_to_cpu(v2e->link_speed); Would this write through netdev_priv(NULL) and oops? The window is open on every probe and after every hard reset. On the first probe it also includes the sleeping alloc_etherdev_mqs(). [Severity: High] This is another pre-existing race in this handler and was not introduced by this patch. Can a link event wake the TX queues of a vport while it is being stopped? idpf_handle_event_link() runs without rtnl or vport_ctrl_lock and does: vport->link_up = v2e->link_status; if (!test_bit(IDPF_VPORT_UP, np->state)) return; if (vport->link_up) { netif_tx_start_all_queues(vport->netdev); netif_carrier_on(vport->netdev); idpf_vport_stop() clears IDPF_VPORT_UP only after the queues are freed: vport->link_up = false; idpf_vport_intr_deinit(vport, rsrc); idpf_xdp_rxq_info_deinit_all(rsrc); idpf_vport_queues_rel(vport, rsrc); idpf_vport_intr_rel(rsrc); clear_bit(IDPF_VPORT_UP, np->state); Consider a link-up event handled between the link_up = false store and the clear_bit(). It would see link_up change and pass the IDPF_VPORT_UP test. It would then restart all TX queues and turn the carrier on. On the soft reset path (ethtool -L/-G or an MTU change on an up interface), the stack can then call idpf_tx_start(), which does: tx_q = vport->txqs[skb_get_queue_mapping(skb)]; After idpf_vport_queues_rel() that pointer is NULL. After this memcpy() in idpf_initiate_soft_reset() it is the stale, freed pointer: memcpy(vport, new_vport, offsetof(struct idpf_vport, link_up)); It stays that way until idpf_vport_open() reallocates the queues. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204194642.3048406-1-anthony.l.nguyen%40intel.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown [not found] <20261204194642.3048406-1-anthony.l.nguyen@intel.com> 2026-12-04 19:46 ` [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen 2026-12-04 19:46 ` [PATCH net v2 3/6] idpf: ignore link events " Tony Nguyen @ 2026-12-04 19:46 ` Tony Nguyen 2026-12-05 20:47 ` netdev-bot+sashiko 2 siblings, 1 reply; 6+ messages in thread From: Tony Nguyen @ 2026-12-04 19:46 UTC (permalink / raw) To: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev Cc: Tian Xun Ng, anthony.l.nguyen, oss.patchbox, luckilystar08, emil.s.tantilov, richardcochran, milena.olech, konstantin.ilichev, stable, Samuel Salin From: Tian Xun Ng <tianxun.ng@bytedance.com> Since commit 4c9106f4906a ("idpf: fix adapter NULL pointer dereference on reboot"), idpf_shutdown() calls idpf_vc_core_deinit() directly instead of idpf_remove(), so IDPF_REMOVE_IN_PROG is not set on shutdown. idpf_vc_core_deinit() uses that flag to decide when to shut the virtchnl transaction manager down. Without it, libie_ctlq_xn_shutdown() runs before idpf_deinit_task() tears the vports down, so every message sent during that teardown (disable vport, disable queues, destroy vport) fails at once, and the device is never told that the vports are gone. A reset should clear that state, but on the system where this was found the device kept the queues enabled across a warm reboot. The first queue reconfiguration in the next kernel (udev setting the MTU) sends VIRTCHNL2_OP_DEL_QUEUES, and the device then writes SW_MARKER TX completions to the previous kernel's completion rings. With the IOMMU translating, those writes fault about 19 s into every such boot: arm-smmu-v3 arm-smmu-v3.12.auto: event: F_TRANSLATION client: 0006:01:00.0 sid: 0x30100 ssid: 0x0 iova: 0x3ef60840 ipa: 0x0 In IOMMU pass-through mode they corrupt pages the new kernel has reused. Set IDPF_REMOVE_IN_PROG at the start of idpf_shutdown(), as idpf_remove() does, so that the event task cannot be requeued and the vports are destroyed while the mailbox is still up; the first two patches keep the Tx timestamp callback and the link event handler away from the state released on the way. So that an unresponsive control plane does not hold up a reboot for long, cap each transaction sent during the teardown at 500 ms instead of 60 s, through a new adapter->vc_xn_timeout_ms, and fail later synchronous ones at once after the first one times out. If the SW marker of one disabled Tx queue does not arrive, the remaining queues of that vport do not wait for theirs, but the mailbox messages that follow are still sent: the device has just answered DISABLE_QUEUES. A control plane that dies at that point costs one marker timeout per vport and one mailbox timeout. The statistics task stops sending once IDPF_REMOVE_IN_PROG is set. A request it already has waiting, or a reset already running in the event task, keeps its own timeouts, as bounding those would need support in libie. If the function has already been reset, for instance a VF whose PF went down first, idpf_is_reset_detected() fails the messages without waiting. Tested on two arm64 (64K pages) servers, each with two idpf PFs, with this series backported to a 6.17 kernel and the IOMMU translating: 20 warm reboots without a fault. Each PF's teardown took about 1.2 s for six mailbox transactions, with all 64 Tx queue markers received; the slowest transaction, VIRTCHNL2_OP_DEALLOC_VECTORS, took about 300 ms. With the first Tx queue marker treated as missing, the other 63 queues did not wait, all six transactions still completed, the teardown took about 2 s per PF, and 3 of 3 warm reboots were clean. With the driver made to skip sending the teardown messages, every reboot faulted again. Fixes: 4c9106f4906a ("idpf: fix adapter NULL pointer dereference on reboot") Cc: stable@vger.kernel.org Signed-off-by: Tian Xun Ng <tianxun.ng@bytedance.com> Reviewed-by: Emil Tantilov <emil.s.tantilov@intel.com> Tested-by: Samuel Salin <Samuel.salin@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> --- drivers/net/ethernet/intel/idpf/idpf.h | 5 ++- drivers/net/ethernet/intel/idpf/idpf_lib.c | 3 ++ drivers/net/ethernet/intel/idpf/idpf_main.c | 11 +++++++ .../net/ethernet/intel/idpf/idpf_virtchnl.c | 33 ++++++++++++++++--- .../net/ethernet/intel/idpf/idpf_virtchnl.h | 1 + 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf.h b/drivers/net/ethernet/intel/idpf/idpf.h index f214023095ee..533b069d97f9 100644 --- a/drivers/net/ethernet/intel/idpf/idpf.h +++ b/drivers/net/ethernet/intel/idpf/idpf.h @@ -85,7 +85,7 @@ enum idpf_state { * @IDPF_HR_FUNC_RESET: Hard reset when TxRx timeout * @IDPF_HR_DRV_LOAD: Set on driver load for a clean HW * @IDPF_HR_RESET_IN_PROG: Reset in progress - * @IDPF_REMOVE_IN_PROG: Driver remove in progress + * @IDPF_REMOVE_IN_PROG: Driver remove or shutdown in progress * @IDPF_MB_INTR_MODE: Mailbox in interrupt mode * @IDPF_VC_CORE_INIT: virtchnl core has been init * @IDPF_FLAGS_NBITS: Must be last @@ -635,6 +635,8 @@ struct idpf_edt_caps_ilog2 { * @asq: Send control queue info * @arq: Receive control queue info * @xnm: Xn transaction manager + * @vc_xn_timeout_ms: Upper bound for each Xn transaction timeout, shortened + * on shutdown and set to 0 once a shortened one timed out * @num_avail_msix: Available number of MSIX vectors * @num_msix_entries: Number of entries in MSIX table * @msix_entries: MSIX table @@ -695,6 +697,7 @@ struct idpf_adapter { struct libie_ctlq_info *asq; struct libie_ctlq_info *arq; struct libie_ctlq_xn_manager *xnm; + u32 vc_xn_timeout_ms; u16 num_avail_msix; u16 num_msix_entries; struct msix_entry *msix_entries; diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c index 523c0e0be884..062d2f540254 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c @@ -1377,6 +1377,9 @@ void idpf_statistics_task(struct work_struct *work) for (i = 0; i < adapter->max_vports; i++) { struct idpf_vport *vport = adapter->vports[i]; + if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) + return; + if (vport && !test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags)) idpf_send_get_stats_msg(netdev_priv(vport->netdev), &vport->port_stats); diff --git a/drivers/net/ethernet/intel/idpf/idpf_main.c b/drivers/net/ethernet/intel/idpf/idpf_main.c index 129bccaa6baa..21be83dc82b1 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_main.c +++ b/drivers/net/ethernet/intel/idpf/idpf_main.c @@ -194,8 +194,18 @@ static void idpf_shutdown(struct pci_dev *pdev) { struct idpf_adapter *adapter = pci_get_drvdata(pdev); + /* As in idpf_remove(): keep the event task from being requeued, and + * destroy the vports while the mailbox is still up. + */ + set_bit(IDPF_REMOVE_IN_PROG, adapter->flags); cancel_delayed_work_sync(&adapter->serv_task); cancel_delayed_work_sync(&adapter->vc_event_task); + + /* Bound the teardown transactions started from here on, so that an + * unresponsive control plane costs a single timeout. A reset or a + * transaction that is already running keeps its own timeouts. + */ + WRITE_ONCE(adapter->vc_xn_timeout_ms, IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC); idpf_vc_core_deinit(adapter); idpf_deinit_dflt_mbx(adapter); @@ -267,6 +277,7 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) adapter->req_rx_splitq = true; adapter->pdev = pdev; + adapter->vc_xn_timeout_ms = IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC; err = idpf_dev_init(adapter, ent); if (err) { diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c index 854eb1f1ada4..e7a8ccbc3585 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c @@ -195,20 +195,32 @@ static void idpf_prepare_ptp_mb_msg(struct idpf_adapter *adapter, u32 op, * Cleanup the mailbox queue entries of the previously sent message to * unmap and release the buffer. * + * The transaction timeout is capped at adapter->vc_xn_timeout_ms. Once a + * synchronous transaction with a shortened timeout times out, later ones + * fail at once instead of waiting again. + * * Return: 0 if the request was successful, -%EBUSY if reset is detected - * or Tx control queue is full, other negative error code on failure. + * or Tx control queue is full, -%ETIMEDOUT if a shortened transaction + * already timed out, other negative error code on failure. */ int idpf_send_mb_msg(struct idpf_adapter *adapter, struct libie_ctlq_xn_send_params *xn_params, void *send_buf, size_t send_buf_size) { + u32 timeout_ms = READ_ONCE(adapter->vc_xn_timeout_ms); struct libie_ctlq_msg ctlq_msg = {}; + int err = 0; - if (idpf_is_reset_detected(adapter)) { + if (idpf_is_reset_detected(adapter)) + err = -EBUSY; + else if (!timeout_ms) + err = -ETIMEDOUT; + + if (err) { if (!libie_cp_can_send_onstack(send_buf_size)) kfree(send_buf); - return -EBUSY; + return err; } idpf_prepare_ptp_mb_msg(adapter, xn_params->chnl_opcode, &ctlq_msg); @@ -219,10 +231,15 @@ int idpf_send_mb_msg(struct idpf_adapter *adapter, xn_params->xnm = adapter->xnm; xn_params->ctlq = xn_params->ctlq ? xn_params->ctlq : adapter->asq; xn_params->rel_tx_buf = kfree; + xn_params->timeout_ms = min_t(u64, xn_params->timeout_ms, timeout_ms); idpf_mb_clean(xn_params->ctlq, false); - return libie_ctlq_xn_send(xn_params); + err = libie_ctlq_xn_send(xn_params); + if (err == -ETIMEDOUT && timeout_ms < IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC) + WRITE_ONCE(adapter->vc_xn_timeout_ms, 0); + + return err; } /** @@ -372,6 +389,11 @@ static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs) struct net_device *netdev; struct idpf_tx_queue *txq; bool markers_rcvd = true; + bool wait_all; + + /* On shutdown, once one marker is missing, don't wait for the rest */ + wait_all = READ_ONCE(qs->adapter->vc_xn_timeout_ms) >= + IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC; for (u32 i = 0; i < qs->num; i++) { switch (qs->qs[i].type) { @@ -381,7 +403,8 @@ static int idpf_wait_for_marker_event_set(const struct idpf_queue_set *qs) netdev = txq->netdev; idpf_queue_set(SW_MARKER, txq); - idpf_wait_for_sw_marker_completion(txq); + if (markers_rcvd || wait_all) + idpf_wait_for_sw_marker_completion(txq); markers_rcvd &= !idpf_queue_has(SW_MARKER, txq); break; default: diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.h b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.h index 5d27805ff40f..911a25ad958b 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.h +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.h @@ -7,6 +7,7 @@ #include <linux/net/intel/virtchnl2.h> #define IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC (60 * 1000) +#define IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC 500 struct idpf_adapter; struct idpf_netdev_priv; -- 2.47.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown 2026-12-04 19:46 ` [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen @ 2026-12-05 20:47 ` netdev-bot+sashiko 0 siblings, 0 replies; 6+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 20:47 UTC (permalink / raw) To: anthony.l.nguyen Cc: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev, tianxun.ng, oss.patchbox, luckilystar08, emil.s.tantilov, richardcochran, milena.olech, konstantin.ilichev, stable, Samuel.salin Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 (1) · Low: 0 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] On shutdown, one slow mailbox reply makes the driver give up on the rest of the device teardown, which can bring back the bug this… - [Medium] When the control plane stops answering, shutdown can now hang for up to 60 s per PF. Pre-existing issues: - [Medium] idpf_mac_filter_async_handler() (idpf_virtchnl.c:3892) indexes adapter->vport_config[] with the vport_id the device assigned… -- idpf: keep the mailbox up while tearing down vports on shutdown This commit sets IDPF_REMOVE_IN_PROG at the start of idpf_shutdown(). With the flag set, idpf_vc_core_deinit() keeps the virtchnl transaction manager up while the vports are destroyed, so the device is told the vports and queues are gone before a warm reboot. It also caps each teardown transaction at 500 ms through a new adapter->vc_xn_timeout_ms, and fails later synchronous ones at once after the first shortened one times out. > diff --git a/drivers/net/ethernet/intel/idpf/idpf_main.c b/drivers/net/ethernet/intel/idpf/idpf_main.c > index 129bccaa6baa8..21be83dc82b1b 100644 > --- a/drivers/net/ethernet/intel/idpf/idpf_main.c > +++ b/drivers/net/ethernet/intel/idpf/idpf_main.c > @@ -194,8 +194,18 @@ static void idpf_shutdown(struct pci_dev *pdev) > { > struct idpf_adapter *adapter = pci_get_drvdata(pdev); > > + /* As in idpf_remove(): keep the event task from being requeued, and > + * destroy the vports while the mailbox is still up. > + */ > + set_bit(IDPF_REMOVE_IN_PROG, adapter->flags); > cancel_delayed_work_sync(&adapter->serv_task); > cancel_delayed_work_sync(&adapter->vc_event_task); [Severity: Medium] Can this make a reboot wait up to 60 s per PF when the control plane has stopped answering? With IDPF_REMOVE_IN_PROG set here, idpf_vc_core_deinit() takes the remove_in_prog branch. That branch runs libie_ctlq_xn_shutdown() only after idpf_deinit_task(). idpf_shutdown() does not cancel stats_task, and idpf_deinit_task() waits for it while the transaction manager is still up: idpf_shutdown() idpf_vc_core_deinit() idpf_deinit_task() cancel_delayed_work_sync(&adapter->stats_task); Suppose idpf_statistics_task() is already blocked in libie_ctlq_xn_send() on a GET_STATS that read vc_xn_timeout_ms before the WRITE_ONCE() below. It then waits in wait_for_completion_timeout() for the full IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC. Before this patch, shutdown took the !remove_in_prog branch, so libie_ctlq_xn_shutdown() ran first. That completes every waiting transaction, and the stats task returned at once. If the control plane is unresponsive, the stats task is blocked for most of each cycle (a 60 s wait plus the 10 s requeue). So it is likely to be in flight when shutdown starts. idpf_remove() already behaved this way. The commit message says "A request it already has waiting ... keeps its own timeouts". Is that meant to apply to shutdown too, given the stated goal that "an unresponsive control plane does not hold up a reboot for long"? > + > + /* Bound the teardown transactions started from here on, so that an > + * unresponsive control plane costs a single timeout. A reset or a > + * transaction that is already running keeps its own timeouts. > + */ > + WRITE_ONCE(adapter->vc_xn_timeout_ms, IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC); > idpf_vc_core_deinit(adapter); > idpf_deinit_dflt_mbx(adapter); [Severity: Medium] This is a pre-existing issue, not one introduced by this patch. Because the transaction manager now stays up during the shutdown teardown, async MAC filter error replies can be handled in a new window. idpf_vport_dealloc() also calls idpf_del_all_mac_filters() on shutdown now. In idpf_mac_filter_async_handler(), vport_config is indexed by the vport_id the device assigned, not by the driver's slot index: drivers/net/ethernet/intel/idpf/idpf_virtchnl.c:idpf_mac_filter_async_handler() { ... vport = idpf_vid_to_vport(adapter, le32_to_cpu(ma_list->vport_id)); if (!vport) goto invalid_payload; vport_config = adapter->vport_config[le32_to_cpu(ma_list->vport_id)]; ... } idpf_vid_to_vport() maps vport_id to a slot through adapter->vport_ids[]. Other users of the same list index by slot, for example idpf_del_all_mac_filters(): vport_config = vport->adapter->vport_config[vport->idx]; What happens if the device assigns a vport_id that differs from the slot index? The handler could work on the wrong mac_filter_list or hit a NULL vport_config. If vport_id >= max_vports, it could also read past the end of vport_config[] and then call list_del() through that pointer. Should this use vport->idx instead? [ ... ] > diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > index 854eb1f1ada4c..e7a8ccbc35857 100644 > --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c > +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c [ ... ] > int idpf_send_mb_msg(struct idpf_adapter *adapter, > struct libie_ctlq_xn_send_params *xn_params, > void *send_buf, size_t send_buf_size) > { > + u32 timeout_ms = READ_ONCE(adapter->vc_xn_timeout_ms); > struct libie_ctlq_msg ctlq_msg = {}; > + int err = 0; > > - if (idpf_is_reset_detected(adapter)) { > + if (idpf_is_reset_detected(adapter)) > + err = -EBUSY; > + else if (!timeout_ms) > + err = -ETIMEDOUT; > + > + if (err) { > if (!libie_cp_can_send_onstack(send_buf_size)) > kfree(send_buf); > > - return -EBUSY; > + return err; > } [ ... ] > @@ -219,10 +231,15 @@ int idpf_send_mb_msg(struct idpf_adapter *adapter, > xn_params->xnm = adapter->xnm; > xn_params->ctlq = xn_params->ctlq ? xn_params->ctlq : adapter->asq; > xn_params->rel_tx_buf = kfree; > + xn_params->timeout_ms = min_t(u64, xn_params->timeout_ms, timeout_ms); > > idpf_mb_clean(xn_params->ctlq, false); > > - return libie_ctlq_xn_send(xn_params); > + err = libie_ctlq_xn_send(xn_params); > + if (err == -ETIMEDOUT && timeout_ms < IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC) > + WRITE_ONCE(adapter->vc_xn_timeout_ms, 0); [Severity: Medium] Can one slow reply from a control plane that is still alive cancel the rest of the shutdown teardown? idpf_shutdown() sets vc_xn_timeout_ms to IDPF_VC_XN_SHUTDOWN_TIMEOUT_MSEC (500). The first -ETIMEDOUT under that cap sets it to 0. After that, every idpf_send_mb_msg() call fails the !timeout_ms check above and returns -ETIMEDOUT without putting anything on the ASQ. This happens even though idpf_is_reset_detected() still sees a live ARQ. DISABLE_VPORT is the first message sent from idpf_vport_stop(). If it takes longer than 500 ms, the rest of the teardown goes like this: idpf_shutdown() idpf_vc_core_deinit() idpf_deinit_task() idpf_vport_dealloc() idpf_vport_stop() idpf_send_disable_vport_msg() <- times out, cap set to 0 idpf_send_disable_queues_msg() <- not sent idpf_send_map_unmap_queue_vector_msg() <- not sent ... idpf_vport_queues_rel() <- rings freed idpf_vport_rel() idpf_send_destroy_vport_msg() <- not sent Every later vport is affected the same way. DEALLOC_VECTORS from idpf_intr_rel() is not sent either. idpf_vport_stop() ignores those return values. It frees the Tx, Rx and completion rings while the device may still have the queues enabled. Wouldn't that leave the device in the state the commit message describes, writing SW_MARKER completions into the next kernel's memory after a warm reboot? The commit message measured about 300 ms for DEALLOC_VECTORS on an idle control plane. That is 60% of the 500 ms budget, while the normal timeout is 60 s. Would a larger shutdown budget help here? Another option would be to set the cap to 0 only once the device also looks dead. Either would avoid dropping the teardown messages when the control plane is only slow. > + > + return err; > } [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204194642.3048406-1-anthony.l.nguyen%40intel.com ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-05 20:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261204194642.3048406-1-anthony.l.nguyen@intel.com>
2026-12-04 19:46 ` [PATCH net v2 2/6] idpf: ignore Tx timestamp replies once removal has started Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 3/6] idpf: ignore link events " Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
2026-12-04 19:46 ` [PATCH net v2 4/6] idpf: keep the mailbox up while tearing down vports on shutdown Tony Nguyen
2026-12-05 20:47 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox