* [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup
2026-12-03 3:53 [PATCH net v3 1/2] ice: restore DDP state during PFR recovery Aaron Ma
@ 2026-12-03 3:53 ` Aaron Ma
2026-12-04 4:27 ` netdev-bot+sashiko
2026-12-04 3:54 ` [PATCH net v3 1/2] ice: restore DDP state during PFR recovery sashiko-bot
2026-12-04 4:27 ` netdev-bot+sashiko
2 siblings, 1 reply; 5+ messages in thread
From: Aaron Ma @ 2026-12-03 3:53 UTC (permalink / raw)
To: Tony Nguyen, Przemek Kitszel, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev
Cc: Henry Tieman, intel-wired-lan
PF and VF Flow Director profiles keep handles to flow entries freed by
ice_clear_hw_tbls() during reset. If PF rebuild fails during system
resume before replay replaces them, driver unload dereferences a freed
entry:
KASAN: maybe wild-memory-access in range [0xdead000000000108-...]
RIP: ice_flow_rem_entry+0xaf/0x170 [ice]
ice_fdir_erase_flow_from_hw+0x1ee/0x420 [ice]
By code inspection, VF Flow Director profiles are not replayed across
reset, and ice_fdir_replay_flows() uses hw_prof without checking
ice_flow_add_prof().
Free VF Flow Director profiles under vf->cfg_lock and invalidate PF
flow handles and profile IDs before ice_clear_hw_tbls(). Serialize PF
Flow Director updates, reset cleanup, and replay with hw->fdir_fltr_lock
across the service task lifetime, and check ice_flow_add_prof() during
replay.
Fixes: 148beb612031 ("ice: Initialize Flow Director resources")
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
v2 -> v3:
- Free VF Flow Director profiles under vf->cfg_lock before
ice_clear_hw_tbls().
- Invalidate full prof->entry_h and prof->prof_id, and check
ice_flow_add_prof() in ice_fdir_replay_flows().
- Hold hw->fdir_fltr_lock across PF Flow Director init, updates, reset
cleanup, and replay, and tie its lifetime to ice_init_dev() and
ice_deinit_dev().
- Drop Przemek's Reviewed-by due to substantial changes.
v1 -> v2:
- Acquire hw->fdir_fltr_lock in ice_fdir_clear_flow_handles() to
synchronize with concurrent ethtool filter add/del.
drivers/net/ethernet/intel/ice/ice.h | 3 +-
.../ethernet/intel/ice/ice_ethtool_ntuple.c | 109 +++++++++++++-----
drivers/net/ethernet/intel/ice/ice_main.c | 32 +++--
drivers/net/ethernet/intel/ice/virt/fdir.c | 16 ++-
drivers/net/ethernet/intel/ice/virt/fdir.h | 2 +
5 files changed, 119 insertions(+), 43 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h
index 432da05c48c08..9c43b7b530b96 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -1023,7 +1023,7 @@ void ice_fdir_del_all_fltrs(struct ice_vsi *vsi);
int
ice_fdir_write_fltr(struct ice_pf *pf, struct ice_ntuple_fltr *input, bool add,
bool is_tun);
-void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena);
+int ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena);
int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd);
int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd);
int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd);
@@ -1032,6 +1032,7 @@ ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd,
u32 *rule_locs);
void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx);
void ice_fdir_release_flows(struct ice_hw *hw);
+void ice_fdir_clear_flow_handles(struct ice_hw *hw);
void ice_fdir_replay_flows(struct ice_hw *hw);
void ice_fdir_replay_fltrs(struct ice_pf *pf);
int ice_fdir_create_dflt_rules(struct ice_pf *pf);
diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c
index 8805f0efe9773..38d7aea103ee6 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c
@@ -286,8 +286,9 @@ void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx)
{
int status, flow;
+ mutex_lock(&hw->fdir_fltr_lock);
if (!hw->fdir_prof)
- return;
+ goto release_lock;
for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
struct ice_fd_hw_prof *prof = hw->fdir_prof[flow];
@@ -322,6 +323,8 @@ void ice_fdir_rem_adq_chnl(struct ice_hw *hw, u16 vsi_idx)
}
prof->cnt--;
}
+release_lock:
+ mutex_unlock(&hw->fdir_fltr_lock);
}
/**
@@ -415,6 +418,25 @@ void ice_fdir_release_flows(struct ice_hw *hw)
ice_fdir_erase_flow_from_hw(hw, ICE_BLK_FD, flow);
}
+/**
+ * ice_fdir_clear_flow_handles - clear handles freed during reset
+ * @hw: pointer to HW instance
+ */
+void ice_fdir_clear_flow_handles(struct ice_hw *hw)
+{
+ int flow;
+
+ for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
+ struct ice_fd_hw_prof *prof = hw->fdir_prof[flow];
+
+ if (!prof)
+ continue;
+
+ memset(prof->entry_h, 0, sizeof(prof->entry_h));
+ memset(prof->prof_id, 0xff, sizeof(prof->prof_id));
+ }
+}
+
/**
* ice_fdir_replay_flows - replay HW Flow Director filter info
* @hw: pointer to HW instance
@@ -431,16 +453,25 @@ void ice_fdir_replay_flows(struct ice_hw *hw)
for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
struct ice_flow_prof *hw_prof;
struct ice_fd_hw_prof *prof;
- int j;
+ int err, j;
prof = hw->fdir_prof[flow];
- ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX,
- prof->fdir_seg[tun], TNL_SEG_CNT(tun),
- false, &hw_prof);
+ if (!prof->fdir_seg[tun])
+ continue;
+
+ err = ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX,
+ prof->fdir_seg[tun],
+ TNL_SEG_CNT(tun), false,
+ &hw_prof);
+ if (err) {
+ dev_err(ice_hw_to_dev(hw), "Could not replay Flow Director, flow type %d\n",
+ flow);
+ continue;
+ }
+ prof->prof_id[tun] = hw_prof->id;
for (j = 0; j < prof->cnt; j++) {
enum ice_flow_priority prio;
u64 entry_h = 0;
- int err;
prio = ICE_FLOW_PRIO_NORMAL;
err = ice_flow_add_entry(hw, ICE_BLK_FD,
@@ -454,7 +485,6 @@ void ice_fdir_replay_flows(struct ice_hw *hw)
flow);
continue;
}
- prof->prof_id[tun] = hw_prof->id;
prof->entry_h[j][tun] = entry_h;
}
}
@@ -1636,20 +1666,27 @@ void ice_fdir_del_all_fltrs(struct ice_vsi *vsi)
* ice_vsi_manage_fdir - turn on/off flow director
* @vsi: the VSI being changed
* @ena: boolean value indicating if this is an enable or disable request
+ *
+ * Return: 0 on success, negative errno on failure.
*/
-void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena)
+int ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena)
{
struct ice_pf *pf = vsi->back;
struct ice_hw *hw = &pf->hw;
enum ice_fltr_ptype flow;
-
- if (ena) {
- set_bit(ICE_FLAG_FD_ENA, pf->flags);
- ice_fdir_create_dflt_rules(pf);
- return;
- }
+ int ret = 0;
mutex_lock(&hw->fdir_fltr_lock);
+ if (ena) {
+ if (ice_is_reset_in_progress(pf->state)) {
+ ret = -EBUSY;
+ goto release_lock;
+ }
+ set_bit(ICE_FLAG_FD_ENA, pf->flags);
+ ice_fdir_create_dflt_rules(pf);
+ goto release_lock;
+ }
+
if (!test_and_clear_bit(ICE_FLAG_FD_ENA, pf->flags))
goto release_lock;
@@ -1663,6 +1700,7 @@ void ice_vsi_manage_fdir(struct ice_vsi *vsi, bool ena)
release_lock:
mutex_unlock(&hw->fdir_fltr_lock);
+ return ret;
}
/**
@@ -1758,13 +1796,14 @@ int ice_del_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
return -EOPNOTSUPP;
+ mutex_lock(&hw->fdir_fltr_lock);
/* Do not delete filters during reset */
if (ice_is_reset_in_progress(pf->state)) {
+ mutex_unlock(&hw->fdir_fltr_lock);
dev_err(ice_pf_to_dev(pf), "Device is resetting - deleting Flow Director filters not supported during reset\n");
return -EBUSY;
}
- mutex_lock(&hw->fdir_fltr_lock);
val = ice_ntuple_update_list_entry(pf, NULL, fsp->location);
mutex_unlock(&hw->fdir_fltr_lock);
@@ -1986,29 +2025,36 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
return -EOPNOTSUPP;
+ mutex_lock(&hw->fdir_fltr_lock);
/* Do not program filters during reset */
if (ice_is_reset_in_progress(pf->state)) {
dev_err(dev, "Device is resetting - adding Flow Director filters not supported during reset\n");
- return -EBUSY;
+ ret = -EBUSY;
+ goto release_lock;
}
fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
- if (ice_parse_rx_flow_user_data(fsp, &userdata))
- return -EINVAL;
+ if (ice_parse_rx_flow_user_data(fsp, &userdata)) {
+ ret = -EINVAL;
+ goto release_lock;
+ }
- if (fsp->flow_type & FLOW_MAC_EXT)
- return -EINVAL;
+ if (fsp->flow_type & FLOW_MAC_EXT) {
+ ret = -EINVAL;
+ goto release_lock;
+ }
ret = ice_cfg_fdir_xtrct_seq(pf, fsp, &userdata);
if (ret)
- return ret;
+ goto release_lock;
max_location = ice_get_fdir_cnt_all(hw);
if (fsp->location >= max_location) {
dev_err(dev, "Failed to add filter. The number of ntuple filters or provided location exceed max %d.\n",
max_location);
- return -ENOSPC;
+ ret = -ENOSPC;
+ goto release_lock;
}
/* return error if not an update and no available filters */
@@ -2016,21 +2062,23 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
if (!ice_fdir_find_fltr_by_idx(hw, fsp->location) &&
ice_fdir_num_avail_fltr(hw, pf->vsi[vsi->idx]) < fltrs_needed) {
dev_err(dev, "Failed to add filter. The maximum number of flow director filters has been reached.\n");
- return -ENOSPC;
+ ret = -ENOSPC;
+ goto release_lock;
}
input = devm_kzalloc_obj(dev, *input);
- if (!input)
- return -ENOMEM;
+ if (!input) {
+ ret = -ENOMEM;
+ goto release_lock;
+ }
ret = ice_ntuple_set_input_set(vsi, fsp, input);
if (ret)
goto free_input;
- mutex_lock(&hw->fdir_fltr_lock);
if (ice_fdir_is_dup_fltr(hw, input)) {
ret = -EINVAL;
- goto release_lock;
+ goto free_input;
}
if (userdata.flex_fltr) {
@@ -2046,7 +2094,7 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
/* input struct is added to the HW filter list */
ret = ice_ntuple_update_list_entry(pf, input, fsp->location);
if (ret)
- goto release_lock;
+ goto free_input;
ret = ice_fdir_write_all_fltr(pf, input, true);
if (ret)
@@ -2059,11 +2107,10 @@ int ice_add_ntuple_ethtool(struct ice_vsi *vsi, struct ethtool_rxnfc *cmd)
/* update sb-filters count, specific to ring->channel */
ice_update_per_q_fltr(vsi, input->orig_q_index, false);
list_del(&input->fltr_node);
+free_input:
+ devm_kfree(dev, input);
release_lock:
mutex_unlock(&hw->fdir_fltr_lock);
-free_input:
- if (ret)
- devm_kfree(dev, input);
return ret;
}
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index a664fbde49d17..a21b505395d9f 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -556,8 +556,12 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
/* Disable VFs until reset is completed */
mutex_lock(&pf->vfs.table_lock);
- ice_for_each_vf(pf, bkt, vf)
+ ice_for_each_vf(pf, bkt, vf) {
+ mutex_lock(&vf->cfg_lock);
ice_set_vf_state_dis(vf);
+ ice_vc_fdir_free_prof_all(vf);
+ mutex_unlock(&vf->cfg_lock);
+ }
mutex_unlock(&pf->vfs.table_lock);
if (ice_is_eswitch_mode_switchdev(pf)) {
@@ -602,7 +606,11 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
skip:
/* clear SW filtering DB */
+ mutex_lock(&hw->fdir_fltr_lock);
+ if (hw->fdir_prof)
+ ice_fdir_clear_flow_handles(hw);
ice_clear_hw_tbls(hw);
+ mutex_unlock(&hw->fdir_fltr_lock);
/* disable the VSIs and their queues that are not already DOWN */
set_bit(ICE_VSI_REBUILD_PENDING, ice_get_main_vsi(pf)->state);
ice_pf_dis_all_vsi(pf, false);
@@ -4398,16 +4406,18 @@ static int ice_init_fdir(struct ice_pf *pf)
goto err_vsi_open;
}
- mutex_init(&pf->hw.fdir_fltr_lock);
-
+ mutex_lock(&pf->hw.fdir_fltr_lock);
err = ice_fdir_create_dflt_rules(pf);
- if (err)
+ if (err) {
+ ice_fdir_release_flows(&pf->hw);
goto err_fdir_rule;
+ }
+ mutex_unlock(&pf->hw.fdir_fltr_lock);
return 0;
err_fdir_rule:
- ice_fdir_release_flows(&pf->hw);
+ mutex_unlock(&pf->hw.fdir_fltr_lock);
ice_vsi_close(ctrl_vsi);
err_vsi_open:
ice_vsi_release(ctrl_vsi);
@@ -4431,8 +4441,6 @@ static void ice_deinit_fdir(struct ice_pf *pf)
pf->vsi[pf->ctrl_vsi_idx] = NULL;
pf->ctrl_vsi_idx = ICE_NO_VSI;
}
-
- mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
}
/**
@@ -4746,6 +4754,7 @@ int ice_init_dev(struct ice_pf *pf)
return -EIO;
}
+ mutex_init(&pf->hw.fdir_fltr_lock);
ice_start_service_task(pf);
return 0;
@@ -4754,6 +4763,7 @@ int ice_init_dev(struct ice_pf *pf)
void ice_deinit_dev(struct ice_pf *pf)
{
ice_service_task_stop(pf);
+ mutex_destroy(&pf->hw.fdir_fltr_lock);
/* Service task is already stopped, so call reset directly. */
ice_reset(&pf->hw, ICE_RESET_PFR);
@@ -6544,7 +6554,9 @@ ice_set_features(struct net_device *netdev, netdev_features_t features)
if (changed & NETIF_F_NTUPLE) {
bool ena = !!(features & NETIF_F_NTUPLE);
- ice_vsi_manage_fdir(vsi, ena);
+ ret = ice_vsi_manage_fdir(vsi, ena);
+ if (ret)
+ return ret;
ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi);
}
@@ -7840,11 +7852,13 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
}
/* replay HW Flow Director recipes */
+ mutex_lock(&hw->fdir_fltr_lock);
if (hw->fdir_prof)
ice_fdir_replay_flows(hw);
/* replay Flow Director filters */
ice_fdir_replay_fltrs(pf);
+ mutex_unlock(&hw->fdir_fltr_lock);
ice_rebuild_arfs(pf);
}
@@ -8591,6 +8605,7 @@ static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi)
return -EINVAL;
hw = &pf->hw;
+ mutex_lock(&hw->fdir_fltr_lock);
for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
struct ice_fd_hw_prof *prof;
int tun, status;
@@ -8628,6 +8643,7 @@ static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi)
dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx,
flow);
}
+ mutex_unlock(&hw->fdir_fltr_lock);
if (!added)
dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx);
diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.c b/drivers/net/ethernet/intel/ice/virt/fdir.c
index aeddb91528224..fca78c3ff2dd8 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.c
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.c
@@ -200,14 +200,24 @@ static void
ice_vc_fdir_free_prof(struct ice_vf *vf, enum ice_fltr_ptype flow)
{
struct ice_vf_fdir *fdir = &vf->fdir;
+ struct ice_fd_hw_prof *vf_prof;
+ struct device *dev;
+ int tun;
if (!fdir->fdir_prof)
return;
- if (!fdir->fdir_prof[flow])
+ vf_prof = fdir->fdir_prof[flow];
+ if (!vf_prof)
return;
- devm_kfree(ice_pf_to_dev(vf->pf), fdir->fdir_prof[flow]);
+ dev = ice_pf_to_dev(vf->pf);
+ for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
+ devm_kfree(dev, vf_prof->fdir_seg[tun]);
+ fdir->prof_entry_cnt[flow][tun] = 0;
+ }
+
+ devm_kfree(dev, vf_prof);
fdir->fdir_prof[flow] = NULL;
}
@@ -215,7 +225,7 @@ ice_vc_fdir_free_prof(struct ice_vf *vf, enum ice_fltr_ptype flow)
* ice_vc_fdir_free_prof_all - free all the profile for this VF
* @vf: pointer to the VF structure
*/
-static void ice_vc_fdir_free_prof_all(struct ice_vf *vf)
+void ice_vc_fdir_free_prof_all(struct ice_vf *vf)
{
struct ice_vf_fdir *fdir = &vf->fdir;
enum ice_fltr_ptype flow;
diff --git a/drivers/net/ethernet/intel/ice/virt/fdir.h b/drivers/net/ethernet/intel/ice/virt/fdir.h
index ac6dcab454b49..1d72522f2339a 100644
--- a/drivers/net/ethernet/intel/ice/virt/fdir.h
+++ b/drivers/net/ethernet/intel/ice/virt/fdir.h
@@ -45,6 +45,7 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg);
int ice_vc_del_fdir_fltr(struct ice_vf *vf, u8 *msg);
void ice_vf_fdir_init(struct ice_vf *vf);
void ice_vf_fdir_exit(struct ice_vf *vf);
+void ice_vc_fdir_free_prof_all(struct ice_vf *vf);
void
ice_vc_fdir_irq_handler(struct ice_vsi *ctrl_vsi,
union ice_32b_rx_flex_desc *rx_desc);
@@ -53,5 +54,6 @@ void ice_flush_fdir_ctx(struct ice_pf *pf);
static inline void
ice_vc_fdir_irq_handler(struct ice_vsi *ctrl_vsi, union ice_32b_rx_flex_desc *rx_desc) { }
static inline void ice_flush_fdir_ctx(struct ice_pf *pf) { }
+static inline void ice_vc_fdir_free_prof_all(struct ice_vf *vf) { }
#endif /* CONFIG_PCI_IOV */
#endif /* _ICE_VIRTCHNL_FDIR_H_ */
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net v3 1/2] ice: restore DDP state during PFR recovery
2026-12-03 3:53 [PATCH net v3 1/2] ice: restore DDP state during PFR recovery Aaron Ma
2026-12-03 3:53 ` [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup Aaron Ma
2026-12-04 3:54 ` [PATCH net v3 1/2] ice: restore DDP state during PFR recovery sashiko-bot
@ 2026-12-04 4:27 ` netdev-bot+sashiko
2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 4:27 UTC (permalink / raw)
To: aaron.ma
Cc: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, netdev, henry.w.tieman, intel-wired-lan
Thank you for your contribution! Sashiko AI review found 13 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 6 · Low: 5
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] When PFR is promoted to CORER, UDP tunnel ports are never
replayed.
- [High] Teardown still frees hw and netdev state before the service task
is stopped, and the new PFR rebuild code uses that state.
- [Medium] The adapter-lifetime fix carries the wrong Fixes: tag.
- [Medium] Every PFR now re-runs DDP initialisation and can hard-fail the
rebuild, which the commit message does not say.
- [Medium] The "restore DVM mode" branch in ice_reload_pkg_pfr() probably
cannot restore device DVM.
- [Medium] If ice_reload_pkg_pfr() fails, ice_rebuild() leaves the
driver's tunnel ports zeroed while the udp_tunnel_nic core still holds…
- [Medium] During a successful PFR, a tunnel delete can race with the
window in which ports are zeroed.
- [Medium] ice_rebuild() checks vsi->netdev before taking rtnl but uses
it after.
- [Low] The permanent commit body omits several behaviour changes outside
PFR; they appear only in the v2->v3 notes below '---'.
- [Low] The failure log quoted in the commit message cannot come from the
pre-patch PFR path that the message blames.
- [Low] Two kernel-doc blocks no longer match their functions.
- [Low] The new PFR path rewrites device-global default recipes without
any firmware lock.
- [Low] On a PFR package-load error, the wait for the firmware-initiated
reset is skipped.
--
ice: restore DDP state during PFR recovery
This patch adds a per-adapter rebuild_lock in ice_rebuild() that
serializes ice_clear_pf_cfg(), the DDP reload and the UDP tunnel replay.
On PFR, a new ice_reload_pkg_pfr() helper reloads the cached DDP package
and restores DVM mode and default recipes, and ice_rebuild() then replays
the UDP tunnel ports with udp_tunnel_nic_reset_ntf(). The patch also moves
ice_adapter_put() after ice_deinit_dev() in the ice_probe() unwind and in
ice_remove().
> During system suspend and resume, affected adapters lose firmware DDP,
> DVM, and UDP tunnel state, while PFR recovery only rebuilds software
> tables and runs concurrently across PFs of the same adapter:
>
> ice 0000:04:00.0: Update pkg failed: err -5
> ice 0000:04:00.0: package load failed, -12
> ice 0000:04:00.0: Rebuild failed, unload and reload driver
[Severity: Low]
Could this log have come from the PFR path described here?
"Update pkg failed" and "package load failed" are ice_debug() prints from
the package download path and ice_init_pkg(). Before this patch,
ice_rebuild() only reached ice_init_pkg() for non-PFR resets:
if (!ice_is_safe_mode(pf)) {
/* reload the SW DB of filter tables */
if (reset_type == ICE_RESET_PFR)
ice_fill_blk_tbls(hw);
else
/* Reload DDP Package after CORER/GLOBR reset */
ice_load_pkg(NULL, pf);
}
So the log seems to come from a CORER/GLOBR/EMPR rebuild, or from an
earlier version of this patch. One example would be a resume PFR that was
promoted to CORER on a bonded PF. With this patch, a PFR failure would
print "failed to reload DDP package during PFR" instead.
> Serialize PF configuration clearing, package reload, and PFR UDP tunnel
> replay per adapter in ice_rebuild(). On PFR, reload the cached package
> without rescanning hints, restore DVM mode and default recipes, and
> reprogram offloaded UDP tunnel ports under rtnl_lock(). Release the
> adapter reference after stopping the service task in probe error unwind
> and driver removal, found by code inspection.
[Severity: Low]
This isn't a bug, but the commit message leaves out several changes that
go beyond PFR. They only appear in the v2->v3 notes below the --- line:
- ice_clear_pf_cfg() now runs before the DDP reload for every reset type,
including CORER/GLOBR/EMPR. Before, ice_load_pkg() ran first.
- The hint-skip and tunnel port clear logic lives in the shared
ice_init_pkg(), so CORER/GLOBR reloads through ice_load_pkg(NULL, pf)
also take the new hw->seg == seg branch. It is not limited to PFR.
- ice_update_recipe_lkup_idx() now skips the Add Recipe write when the
recipe already matches. This changes ice_set_dvm() on every package
download, including at probe.
Could these be described in the commit message?
> Fixes: 462acf6aca85 ("ice: Enable DDP package download")
[Severity: Medium]
Is this the right Fixes: tag for the ice_adapter_put() reordering?
That part looks like a fix for 8a37f9e2ff40 ("ice: move ice_deinit_dev()
to the end of deinit paths"). That commit moved ice_service_task_stop() out
of the early part of ice_remove() and into ice_deinit_dev(), which runs
after ice_adapter_put(). The service task could then use pf->adapter after
the last PF had freed it.
Also, struct ice_adapter was only added by 0e2bddf9e5f9 in 2024. Stable
trees selected by 462acf6aca85 have no adapter to hold the new
rebuild_lock.
Should 8a37f9e2ff40 be referenced in a Fixes: tag here?
> diff --git a/drivers/net/ethernet/intel/ice/ice_ddp.c b/drivers/net/ethernet/intel/ice/ice_ddp.c
> index d50c555851fbd..bedb9362d4098 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ddp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ddp.c
[ ... ]
> @@ -2234,7 +2235,14 @@ enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
> return state;
>
> /* initialize package hints and then download package */
[Severity: Low]
This isn't a bug, but this comment no longer matches the code. The
ice_init_pkg() kernel-doc ("Next, the function will cache any hints from
the package, followed by downloading the package itself") is also out of
date.
Both describe unconditional hint caching. Hints are now cached only when
hw->seg != seg. Otherwise the tunnel ports are zeroed, and neither comment
mentions that.
The ice_update_recipe_lkup_idx() kernel-doc ("Finally, use the add recipe
AQ to update the pre-existing recipe with the modifications") also doesn't
mention the new early return when the lookup index and mask already match.
> - ice_init_pkg_hints(hw, seg);
> + if (hw->seg != seg) {
> + ice_init_pkg_hints(hw, seg);
> + } else {
> + mutex_lock(&hw->tnl_lock);
> + for (i = 0; i < hw->tnl.count; i++)
> + hw->tnl.tbl[i].port = 0;
> + mutex_unlock(&hw->tnl_lock);
> + }
[Severity: Medium]
Can a tunnel delete race with this window during a PFR that succeeds?
The ports are zeroed here under hw->tnl_lock only. At this point
ice_rebuild() holds adapter->rebuild_lock but not rtnl.
The udp_tunnel_nic core isn't resynced until much later. That only happens
after the download, the pkg info query, the table fill, the DVM restore and
the recipe read-back, when ice_rebuild() calls udp_tunnel_nic_reset_ntf()
under rtnl_lock().
If a VXLAN or Geneve device is removed in that window, the sync work takes
rtnl and utn->lock and calls:
udp_tunnel_nic_device_sync_work()
ice_udp_tunnel_unset_port()
ice_destroy_tunnel()
if (WARN_ON(!hw->tnl.tbl[index].valid ||
hw->tnl.tbl[index].type != type ||
hw->tnl.tbl[index].port != port)) {
valid and type still match, but port is now 0. Wouldn't this WARN_ON fire
and the removal fail with -EIO?
> state = ice_download_pkg(hw, pkg, seg);
[ ... ]
> diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
> index 9644b25e79355..179516e4c419c 100644
> --- a/drivers/net/ethernet/intel/ice/ice_main.c
> +++ b/drivers/net/ethernet/intel/ice/ice_main.c
> @@ -4296,6 +4296,49 @@ ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
> set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
> }
>
> +static int ice_reload_pkg_pfr(struct ice_pf *pf)
> +{
[ ... ]
> + dvm = ice_is_dvm_ena(hw);
> + state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
> + if (!ice_is_init_pkg_successful(state)) {
> + dev_err(dev, "failed to reload DDP package during PFR: %d\n",
> + state);
> + return -EIO;
> + }
[Severity: Low]
If ice_init_pkg() returns ICE_DDP_PKG_LOAD_ERROR here, is the wait for the
firmware-initiated reset skipped? ice_log_pkg_init() is the only code that
handles that state:
case ICE_DDP_PKG_LOAD_ERROR:
dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
/* poll for reset to complete */
if (ice_check_reset(hw))
Returning -EIO before that call sends ice_rebuild() straight to
err_init_ctrlq. ice_shutdown_all_ctrlq() then runs while the firmware reset
may still be in progress.
The CORER/GLOBR path through ice_load_pkg() still does the poll.
> + ice_log_pkg_init(hw, state);
> +
> + if (state != ICE_DDP_PKG_SUCCESS && dvm && !ice_is_dvm_ena(hw)) {
> + err = ice_aq_set_port_params(hw->port_info, true, NULL);
> + if (!err)
> + ice_post_pkg_dwnld_vlan_mode_cfg(hw);
> + }
[Severity: Medium]
Can this branch actually restore DVM on the device?
It only sends Set Port Params. After that,
ice_post_pkg_dwnld_vlan_mode_cfg()->ice_cache_vlan_mode() reads the device
mode again with Get VLAN Mode:
hw->dvm_ena = ice_aq_is_dvm_ena(hw) ? true : false;
The existing DVM bring-up in ice_set_dvm() calls ice_aq_set_vlan_mode(),
ice_dvm_update_dflt_recipes(), ice_aq_set_port_params() and
ice_set_dvm_boost_entries(). It does this under the global config lock on
the PF that downloads the package. This path never sends Set VLAN Mode and
skips the boost entries.
If firmware reports SVM, won't the re-read still report SVM? The check
below would then return -EIO and the rebuild would fail, and the port
DOUBLE_VLAN_ENA write would stay in place.
ice_aq_is_dvm_ena() also returns false when the AQ command fails, so an AQ
error is treated the same as firmware being in SVM.
ice_rebuild() also calls ice_aq_set_port_params(pf->hw.port_info, dvm, NULL)
later, so the extra port params write here doesn't seem to add anything.
> +
> + if (dvm && !ice_is_dvm_ena(hw)) {
> + dev_err(dev, "failed to restore DVM mode during PFR\n");
> + return -EIO;
> + }
[Severity: Medium]
What happens to the tunnel state if this return, or another error return
in ice_reload_pkg_pfr(), is taken?
By then ice_init_pkg() has already zeroed hw->tnl.tbl[].port, but
ice_rebuild() skips udp_tunnel_nic_reset_ntf() because of its !err check.
The udp_tunnel_nic core still has these entries in use, while the driver
now has port 0 for them.
The "Rebuild failed, unload and reload driver" message tells the user to
unload the driver, which gives:
ice_unload()
unregister_netdev()
udp_tunnel_nic_unregister()
udp_tunnel_nic_flush()
__udp_tunnel_nic_device_sync()
ice_udp_tunnel_unset_port()
ice_destroy_tunnel()
Wouldn't the WARN_ON(hw->tnl.tbl[index].port != port) in
ice_destroy_tunnel() then fire once for each offloaded tunnel port?
> +
> + /* PFR can lose DVM recipes after system suspend when the
> + * package itself remained loaded in firmware.
> + */
> + if (state != ICE_DDP_PKG_SUCCESS && ice_is_dvm_ena(hw)) {
> + err = ice_dvm_update_dflt_recipes(hw);
[Severity: Low]
Should this recipe update hold a firmware lock?
On this path ice_download_pkg() returned an already-loaded state because
the global config lock wasn't granted, so no firmware lock is held.
ice_dvm_update_dflt_recipes() does a Get Recipe / Add Recipe
read-modify-write through ice_update_recipe_lkup_idx().
Normally this runs from ice_set_dvm() under the global config lock. Also,
ice_add_sw_recipe() wraps ice_aq_add_recipe() in ice_acquire_change_lock().
adapter->rebuild_lock only covers PFs owned by this driver instance. A
function driven elsewhere, such as one passed through to a guest, could
write the same recipes at the same time.
> + if (err) {
> + dev_err(dev, "failed to restore default DVM recipes: %d\n",
> + err);
> + return err;
> + }
> + }
[ ... ]
> @@ -5292,11 +5335,13 @@ ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
> unroll_dev_init:
> need_dev_deinit = true;
> unroll_adapter:
> - ice_adapter_put(pdev);
> -unroll_hw_init:
> ice_deinit_hw(hw);
> if (need_dev_deinit)
> ice_deinit_dev(pf);
> + ice_adapter_put(pdev);
> + return err;
> +unroll_hw_init:
> + ice_deinit_hw(hw);
> return err;
> }
>
> @@ -5405,10 +5450,10 @@ static void ice_remove(struct pci_dev *pdev)
> ice_setup_mc_magic_wake(pf);
> ice_set_wake(pf);
>
> - ice_adapter_put(pdev);
> ice_deinit_hw(&pf->hw);
>
> ice_deinit_dev(pf);
> + ice_adapter_put(pdev);
[Severity: High]
This keeps pf->adapter alive until ice_deinit_dev() stops the service
task. Isn't the other state that the new PFR code uses still freed before
that point?
In ice_remove(), ice_unload()->ice_decfg_netdev() frees vsi->netdev. Then
ice_deinit_hw() calls ice_free_seg() (which frees pkg_copy),
ice_free_hw_tbls() and mutex_destroy(&hw->tnl_lock). All of this happens
before ice_deinit_dev()->ice_service_task_stop().
The new PFR path uses exactly these objects:
ice_rebuild()
ice_reload_pkg_pfr()
ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size)
mutex_lock(&hw->tnl_lock)
ice_fill_blk_tbls()
udp_tunnel_nic_reset_ntf(vsi->netdev)
ice_remove() only waits ICE_MAX_RESET_WAIT x 100ms for a reset in
progress. A reset can also start after that wait and before ice_deinit()
sets ICE_SERVICE_DIS and ICE_DOWN. ice_rebuild() only checks ICE_DOWN on
entry.
Can a rebuild that is already running then use pkg_copy, the HW tables or
the netdev after they are freed? The probe unroll_adapter path above has
the same ordering, with ice_deinit_hw() before ice_deinit_dev().
Running ice_deinit_hw() before the service task stop predates this patch.
However, the patch targets this window and adds new accesses inside it.
Would stopping the service task before teardown be a better fix?
> ice_aq_cancel_waiting_tasks(pf);
> set_bit(ICE_DOWN, pf->state);
> }
> @@ -7684,21 +7729,28 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
> goto err_init_ctrlq;
> }
>
> + mutex_lock(&pf->adapter->rebuild_lock);
> + err = ice_clear_pf_cfg(hw);
> + if (err)
> + dev_err(dev, "clear PF configuration failed %d\n", err);
> +
> /* if DDP was previously loaded successfully */
> - if (!ice_is_safe_mode(pf)) {
> - /* reload the SW DB of filter tables */
> - if (reset_type == ICE_RESET_PFR)
> - ice_fill_blk_tbls(hw);
> - else
> + if (!err && !ice_is_safe_mode(pf)) {
> + if (reset_type == ICE_RESET_PFR) {
> + err = ice_reload_pkg_pfr(pf);
> + if (!err && vsi && vsi->netdev) {
> + rtnl_lock();
> + udp_tunnel_nic_reset_ntf(vsi->netdev);
> + rtnl_unlock();
> + }
[Severity: Medium]
Is vsi->netdev stable across rtnl_lock() here? It is checked before rtnl
is taken and read again afterwards.
ice_decfg_netdev() runs from ice_unload() without rtnl or rebuild_lock.
That covers ice_remove() and devlink DRIVER_REINIT:
free_netdev(vsi->netdev);
vsi->netdev = NULL;
ice_unload() calls unregister_netdev() first, and that holds rtnl. This
thread can therefore block in rtnl_lock() just as teardown is about to
free the netdev.
Once rtnl is released, couldn't udp_tunnel_nic_reset_ntf() get a NULL or
freed net_device? ice_devlink_reload_down() doesn't check for a reset in
progress either.
> + } else {
> /* Reload DDP Package after CORER/GLOBR reset */
> ice_load_pkg(NULL, pf);
> + }
[Severity: High]
Does the CORER/GLOBR/EMPR branch need the same UDP tunnel replay?
ice_load_pkg(NULL, pf) calls ice_init_pkg(hw, hw->pkg_copy, ...), where
hw->seg == seg, so the new else branch zeroes every hw->tnl.tbl[i].port.
The full re-download also drops the boost TCAM tunnel entries. Nothing
notifies the udp_tunnel_nic core, which still counts those ports as
offloaded.
This branch is also reached on resume. ice_resume() schedules a PFR, but
ice_do_reset() promotes it to CORER on a bonded PF:
if (pf->lag && pf->lag->bonded && reset_type == ICE_RESET_PFR) {
dev_dbg(dev, "PFR on a bonded interface, promoting to CORER\n");
reset_type = ICE_RESET_CORER;
}
In that case, isn't VXLAN/Geneve offload silently lost after resume? A
later tunnel delete or netdev unregister would then hit the
WARN_ON(hw->tnl.tbl[index].port != port) in ice_destroy_tunnel() and
return -EIO.
The global reset gap existed before this patch, because
ice_init_pkg_hints() memsets hw->tnl. But the commit message says this
patch restores the UDP tunnel state lost across suspend/resume. Should the
replay run after every package reload, not only for PFR?
> }
> -
> - err = ice_clear_pf_cfg(hw);
> - if (err) {
> - dev_err(dev, "clear PF configuration failed %d\n", err);
> + mutex_unlock(&pf->adapter->rebuild_lock);
> + if (err)
> goto err_init_ctrlq;
> - }
[Severity: Medium]
With this change, every PFR runs ice_reload_pkg_pfr() instead of the void
ice_fill_blk_tbls(). That includes TX timeout recovery, ethtool and
devlink resets and VF-driven resets, not only resume. It reruns
ice_init_pkg(), the VLAN mode query, the DVM recipe read-back and the
tunnel replay.
Any failure in those steps now jumps to err_init_ctrlq, which sets
ICE_RESET_FAILED and ICE_NEEDS_RESTART, so the driver has to be reloaded.
Possible failures include a transient AQ error reported as
ICE_DDP_PKG_ERR, a VLAN mode mismatch, or a recipe read or write error.
The CORER path falls back to Safe Mode instead.
Is it intended that a routine PFR, which used to recover the device, can
now leave it unusable until a driver reload? The commit message doesn't
mention this change in behaviour.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203035320.187412-1-aaron.ma%40canonical.com
^ permalink raw reply [flat|nested] 5+ messages in thread