From: Vincent Choiniere <choi…@hydroquebec.com> ice_tx_hang_reporter_dump() always reads tx_ring->tx_buf[0].skb, regardless of next_to_clean. The Tx cleanup path frees the skb and marks the buffer empty without clearing the skb pointer, so slot 0 can hold a stale pointer. A NULL check alone does not cover this, and devlink_fmsg_dump_skb() can fault on the freed skb. Using tx_buf[next_to_clean] alone does not fix the lifetime issues. The dump runs from the service task without synchronization with Tx cleanup or ring replacement: - ice_clean_tx_irq() can free the skb at next_to_clean while the report is being prepared. It calls napi_consume_skb() before marking the buffer empty. - The ring saved by ice_tx_timeout() can be replaced or freed before the service task runs. ethtool -G replaces the ring contents and frees tx_buf and desc, while ethtool -L can free whole rings. Record the queue index, next_to_clean and next_to_use at timeout time. Before reporting, take RTNL and check that the timeout was on the PF VSI, that the VSI is up and that the timed-out queue still maps to the saved ring. A freed ring can be reused for another queue, so a pointer match alone is not enough. Copy the descriptors and IRQ name while the ring storage is protected against replacement. If the check fails or the copy cannot be made, report only the values recorded at timeout time. As before this patch, a successful snapshot shows the ring when the report is generated. A reset of the same queue after the timeout, for example by ethtool -G or an MTU change, is not detected. Tx cleanup can still run while the ring state is copied, so do not dereference the skb. Retain only its pointer value in the dump and remove the skb contents. Release RTNL before calling devlink_health_report(), which takes the devlink instance lock. Build the dump from the copied data and free the descriptor copy after reporting. This leaves devlink_fmsg_dump_skb() without users; its removal is left to a net-next follow-up. Observed on an E810 PF passed through to a KVM guest with Ubuntu kernel 7.0.0-14 (PREEMPT_RT and a local scheduler patch): a delayed queue IRQ led to a Tx timeout and a page fault in devlink_fmsg_dump_skb(): BUG: unable to handle page fault for address: 0000000004cd0c11 Workqueue: ice ice_service_task [ice] RIP: devlink_fmsg_dump_skb+0x2d8/0x5d0 Call Trace: ice_tx_hang_reporter_dump+0x1ce/0x210 [ice] devlink_health_do_dump+0xcc/0x190 devlink_health_report+0x1d7/0x260 ice_report_tx_hang+0x7d/0xa0 [ice] Fixes: 2a82874a3b7b ("ice: add Tx hang devlink health reporter") Link: https://lore.kernel.org/all/2026…@intel.com/ Cc: stab…@vger.kernel.org Reviewed-by: Przemek Kitszel <prze…@intel.com> Reviewed-by: Simon Horman <hor…@kernel.org> Acked-by: Tony Nguyen <anth…@intel.com> Tested-by: Matt Fleming <mfle…@cloudflare.com> Signed-off-by: Vincent Choiniere <choi…@hydroquebec.com> --- Tony, as requested in the v4 thread, this is sent directly to netdev. Simon's suggestion is taken: return early when next_to_clean is out of range, before the descriptor copy is allocated. Testing: checkpatch --strict clean; ice builds W=1 C=2 without warnings. Also tested on an E810 PF passed through to a KVM guest, on a net kernel (7.4.0-rc4, KASAN and lockdep enabled, threaded IRQs) with delays injected before the snapshot and before the dump. A Tx timeout was forced and ethtool -G was run during each delay: the dump was produced with no KASAN, lockdep or BUG report. Not covered: PREEMPT_RT and the ethtool -L case. Changes in v5: - Return early when ntc >= tx_ring->count, before kvmalloc(); drop the else/kvfree (suggested by Simon Horman). - Rebase on net (90ae4042bd9). - Collect Acked-by from Tony and Tested-by from Matt Fleming. - Link to v4: https://lore.kernel.org/netdev/2026…@hydroquebec.com/ --- drivers/net/ethernet/intel/ice/devlink/health.c | 114 +++++++++++++++++++++--- drivers/net/ethernet/intel/ice/devlink/health.h | 6 ++ 2 files changed, 106 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/devlink/health.c b/drivers/net/ethernet/intel/ice/devlink/health.c index 8e9a8a8178d..74c83ecf1ce 100644 --- a/drivers/net/ethernet/intel/ice/devlink/health.c +++ b/drivers/net/ethernet/intel/ice/devlink/health.c @@ -382,7 +382,13 @@ struct ice_tx_hang_event { u16 queue; u16 next_to_clean; u16 next_to_use; - struct ice_tx_ring *tx_ring; + /* the fields below are only valid if @desc is set */ + char irq_name[ICE_INT_NAME_STR_LEN]; + void *desc_ptr; + dma_addr_t dma; + void *desc; + u32 desc_size; + void *skb_ptr; /* pointer value only, never dereferenced */ }; static int ice_tx_hang_reporter_dump(struct devlink_health_reporter *reporter, @@ -390,12 +396,10 @@ static int ice_tx_hang_reporter_dump(struct devlink_health_reporter *reporter, struct netlink_ext_ack *extack) { struct ice_tx_hang_event *event = priv_ctx; - struct sk_buff *skb; if (!event) return 0; - skb = event->tx_ring->tx_buf->skb; devlink_fmsg_obj_nest_start(fmsg); ICE_DEVLINK_FMSG_PUT_FIELD(fmsg, event, head); ICE_DEVLINK_FMSG_PUT_FIELD(fmsg, event, intr); @@ -403,13 +407,14 @@ static int ice_tx_hang_reporter_dump(struct devlink_health_reporter *reporter, ICE_DEVLINK_FMSG_PUT_FIELD(fmsg, event, queue); ICE_DEVLINK_FMSG_PUT_FIELD(fmsg, event, next_to_clean); ICE_DEVLINK_FMSG_PUT_FIELD(fmsg, event, next_to_use); - devlink_fmsg_put(fmsg, "irq-mapping", event->tx_ring->q_vector->name); - ice_fmsg_put_ptr(fmsg, "desc-ptr", event->tx_ring->desc); - ice_fmsg_put_ptr(fmsg, "dma-ptr", (void *)(long)event->tx_ring->dma); - ice_fmsg_put_ptr(fmsg, "skb-ptr", skb); - devlink_fmsg_binary_pair_put(fmsg, "desc", event->tx_ring->desc, - event->tx_ring->count * sizeof(struct ice_tx_desc)); - devlink_fmsg_dump_skb(fmsg, skb); + if (event->desc) { + devlink_fmsg_put(fmsg, "irq-mapping", event->irq_name); + ice_fmsg_put_ptr(fmsg, "desc-ptr", event->desc_ptr); + ice_fmsg_put_ptr(fmsg, "dma-ptr", (void *)(long)event->dma); + ice_fmsg_put_ptr(fmsg, "skb-ptr", event->skb_ptr); + devlink_fmsg_binary_pair_put(fmsg, "desc", event->desc, + event->desc_size); + } devlink_fmsg_obj_nest_end(fmsg); return 0; @@ -424,6 +429,76 @@ void ice_prep_tx_hang_report(struct ice_pf *pf, struct ice_tx_ring *tx_ring, buf->vsi_num = vsi_num; buf->head = head; buf->intr = intr; + buf->queue = tx_ring->q_index; + buf->next_to_clean = tx_ring->next_to_clean; + buf->next_to_use = tx_ring->next_to_use; +} + +/** + * ice_tx_hang_snapshot - copy the timed-out queue's ring at report time + * @pf: PF on which the Tx hang was detected + * @tx_ring: ring saved by ice_tx_timeout(), possibly stale + * @ev: event to fill in + * + * The saved ring may have been freed or replaced since the timeout (e.g. by + * ethtool -G or -L), and a freed ring may be reused for another queue. Use it + * only if the timeout was on the PF VSI, that VSI is up and the timed-out + * queue still maps to it. Those paths, and the reset paths, replace or free + * the rings under RTNL or from the service task itself, so with RTNL held the + * accesses below are to live memory for them. The ring may still have been + * reset in place since the timeout (e.g. by ethtool -G or an MTU change); as + * before, its state is read when the report is generated. Driver removal and + * devlink reload tear the VSIs down before the service task is stopped and are + * not covered here. ice_clean_tx_irq() may still run and free the skb at + * next_to_clean at any time, so only the pointer value is recorded and the skb + * itself is never dereferenced. + */ +static void ice_tx_hang_snapshot(struct ice_pf *pf, struct ice_tx_ring *tx_ring, + struct ice_tx_hang_event *ev) +{ + struct ice_vsi *vsi = ice_get_main_vsi(pf); + struct ice_q_vector *q_vector; + struct ice_tx_buf *tx_buf; + u16 ntc, ntu; + void *desc; + u32 size; + + ASSERT_RTNL(); + + if (!tx_ring || !vsi || !vsi->tx_rings || + test_bit(ICE_VSI_DOWN, vsi->state)) + return; + + if (ev->vsi_num != vsi->vsi_num || ev->queue >= vsi->num_txq || + vsi->tx_rings[ev->queue] != tx_ring) + return; + + q_vector = tx_ring->q_vector; + if (!q_vector || !tx_ring->desc || !tx_ring->tx_buf || !tx_ring->count) + return; + + ntc = READ_ONCE(tx_ring->next_to_clean); + ntu = READ_ONCE(tx_ring->next_to_use); + if (ntc >= tx_ring->count) + return; + + size = tx_ring->count * sizeof(struct ice_tx_desc); + desc = kvmalloc(size, GFP_KERNEL); + if (!desc) + return; + + tx_buf = &tx_ring->tx_buf[ntc]; + if (tx_buf->type == ICE_TX_BUF_SKB) + ev->skb_ptr = READ_ONCE(tx_buf->skb); + + memcpy(desc, tx_ring->desc, size); + ev->next_to_clean = ntc; + ev->next_to_use = ntu; + strscpy(ev->irq_name, q_vector->name); + ev->desc_ptr = tx_ring->desc; + ev->dma = tx_ring->dma; + ev->desc_size = size; + ev->desc = desc; } void ice_report_tx_hang(struct ice_pf *pf) @@ -435,13 +510,24 @@ void ice_report_tx_hang(struct ice_pf *pf) .head = buf->head, .intr = buf->intr, .vsi_num = buf->vsi_num, - .queue = tx_ring->q_index, - .next_to_clean = tx_ring->next_to_clean, - .next_to_use = tx_ring->next_to_use, - .tx_ring = tx_ring, + .queue = buf->queue, + .next_to_clean = buf->next_to_clean, + .next_to_use = buf->next_to_use, }; + if (!pf->health_reporters.tx_hang) + return; + + rtnl_lock(); + ice_tx_hang_snapshot(pf, tx_ring, &ev); + rtnl_unlock(); + + /* devlink_health_report() takes the devlink instance lock, which nests + * outside RTNL, so only report once RTNL has been released. + */ ice_devlink_health_report(pf->health_reporters.tx_hang, "Tx hang", &ev); + + kvfree(ev.desc); } static struct devlink_health_reporter * diff --git a/drivers/net/ethernet/intel/ice/devlink/health.h b/drivers/net/ethernet/intel/ice/devlink/health.h index 5edfc4d2adc..508e4115db4 100644 --- a/drivers/net/ethernet/intel/ice/devlink/health.h +++ b/drivers/net/ethernet/intel/ice/devlink/health.h @@ -37,6 +37,9 @@ enum ice_mdd_src { * @head: descriptor head * @intr: interrupt register value * @vsi_num: VSI owning the queue that the hang occurred on + * @queue: index of the queue that the hang occurred on + * @next_to_clean: next_to_clean of the ring when the hang was detected + * @next_to_use: next_to_use of the ring when the hang was detected * @fw_status: buffer for last received FW Status event * @port_status: buffer for last received Port Status event */ @@ -50,6 +53,9 @@ struct ice_health { u32 head; u32 intr; u16 vsi_num; + u16 queue; + u16 next_to_clean; + u16 next_to_use; ); struct ice_aqc_health_status_elem fw_status; struct ice_aqc_health_status_elem port_status; --- base-commit: 90ae4042bd9f35a9098d14b1a12a43df9b326e2b change-id: 20261203-ice-tx-hang-dump-v5-6cc2b564e1fd Best regards, -- Vincent Choiniere <choi…@hydroquebec.com>