* [PATCH net v3 1/2] ice: restore DDP state during PFR recovery
@ 2026-12-03 3:53 Aaron Ma
2026-12-03 3:53 ` [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup Aaron Ma
0 siblings, 1 reply; 2+ 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
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
This was reproduced during suspend/resume testing on Intel E810-XXV-2
(8086:159b) and E835-CC (8086:124a) adapters.
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.
Fixes: 462acf6aca85 ("ice: Enable DDP package download")
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
v2 -> v3:
- Scope rebuild_lock around ice_clear_pf_cfg(), DDP reload, and PFR UDP
tunnel replay inside ice_rebuild(), clearing PF config first.
- Defer ice_adapter_put() until after ice_deinit_dev() in ice_probe() and
ice_remove() instead of stopping the service task early.
- Preserve cached package hints on reload, clear cached tunnel ports under
hw->tnl_lock, and replay UDP tunnel ports via udp_tunnel_nic_reset_ntf()
under rtnl_lock().
- Restore DVM port parameters and default recipes when needed, skipping
firmware writes for matching recipes, and avoid Safe Mode log on PFR
failure.
- Drop Przemek's Reviewed-by due to substantial changes.
v1 -> v2:
- Stop service task early in ice_remove() to prevent use-after-free on
pf->adapter if rebuild is in flight.
drivers/net/ethernet/intel/ice/ice_adapter.c | 2 +
drivers/net/ethernet/intel/ice/ice_adapter.h | 4 +
drivers/net/ethernet/intel/ice/ice_ddp.c | 10 ++-
drivers/net/ethernet/intel/ice/ice_main.c | 78 +++++++++++++++----
drivers/net/ethernet/intel/ice/ice_switch.c | 15 +++-
.../net/ethernet/intel/ice/ice_vlan_mode.c | 2 +-
.../net/ethernet/intel/ice/ice_vlan_mode.h | 1 +
7 files changed, 95 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.c b/drivers/net/ethernet/intel/ice/ice_adapter.c
index aa2d8addae5be..9a7565a54c0fe 100644
--- a/drivers/net/ethernet/intel/ice/ice_adapter.c
+++ b/drivers/net/ethernet/intel/ice/ice_adapter.c
@@ -73,6 +73,7 @@ static struct ice_adapter *ice_adapter_new(struct pci_dev *pdev)
for (int i = 0; i < ARRAY_SIZE(adapter->cpi_phy_lock); i++)
mutex_init(&adapter->cpi_phy_lock[i]);
mutex_init(&adapter->cgu_synce_lock);
+ mutex_init(&adapter->rebuild_lock);
refcount_set(&adapter->refcount, 1);
spin_lock_init(&adapter->ports.lock);
@@ -87,6 +88,7 @@ static void ice_adapter_free(struct ice_adapter *adapter)
for (int i = 0; i < ARRAY_SIZE(adapter->cpi_phy_lock); i++)
mutex_destroy(&adapter->cpi_phy_lock[i]);
mutex_destroy(&adapter->cgu_synce_lock);
+ mutex_destroy(&adapter->rebuild_lock);
cleanup_srcu_struct(&adapter->ports.srcu);
diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h
index fd5585005d91b..18120432e1fd9 100644
--- a/drivers/net/ethernet/intel/ice/ice_adapter.h
+++ b/drivers/net/ethernet/intel/ice/ice_adapter.h
@@ -43,6 +43,8 @@ struct ice_port_list {
* Index 0 = PHY0, index 1 = PHY1. Used on E825C devices.
* @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11,
* which all PFs reach. Used on E825C devices.
+ * @rebuild_lock: Mutex serializing package and recipe rebuilds across PFs of
+ * the same adapter
* @ctrl_pf: Control PF of the adapter
* @ports: Ports list
* @index: 64-bit index cached for collision detection on 32bit systems
@@ -57,6 +59,8 @@ struct ice_adapter {
struct mutex cpi_phy_lock[ICE_E825_MAX_PHYS];
/* Serialize changes of the SyncE CGU registers (E825C only) */
struct mutex cgu_synce_lock;
+ /* Serialize package and recipe rebuilds across PFs */
+ struct mutex rebuild_lock;
struct ice_pf *ctrl_pf;
struct ice_port_list ports;
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
@@ -2204,6 +2204,7 @@ enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
enum ice_ddp_state state;
struct ice_pkg_hdr *pkg;
struct ice_seg *seg;
+ u16 i;
if (!buf || !len)
return ICE_DDP_PKG_ERR;
@@ -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 */
- 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);
+ }
state = ice_download_pkg(hw, pkg, seg);
if (state == ICE_DDP_PKG_ALREADY_LOADED) {
ice_debug(hw, ICE_DBG_INIT,
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 47c6798c97e8f..a664fbde49d17 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -4294,6 +4294,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)
+{
+ struct device *dev = ice_pf_to_dev(pf);
+ struct ice_hw *hw = &pf->hw;
+ enum ice_ddp_state state;
+ bool dvm;
+ int err;
+
+ 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;
+ }
+ 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);
+ }
+
+ if (dvm && !ice_is_dvm_ena(hw)) {
+ dev_err(dev, "failed to restore DVM mode during PFR\n");
+ return -EIO;
+ }
+
+ /* 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);
+ if (err) {
+ dev_err(dev, "failed to restore default DVM recipes: %d\n",
+ err);
+ return err;
+ }
+ }
+
+ return 0;
+}
+
/**
* ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
* @pf: pointer to the PF structure
@@ -5290,11 +5333,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;
}
@@ -5403,10 +5448,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);
ice_aq_cancel_waiting_tasks(pf);
set_bit(ICE_DOWN, pf->state);
}
@@ -7682,21 +7727,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();
+ }
+ } else {
/* Reload DDP Package after CORER/GLOBR reset */
ice_load_pkg(NULL, pf);
+ }
}
-
- 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;
- }
ice_clear_pxe_mode(hw);
diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c
index d873eda9af826..e6541cb8ea796 100644
--- a/drivers/net/ethernet/intel/ice/ice_switch.c
+++ b/drivers/net/ethernet/intel/ice/ice_switch.c
@@ -2066,6 +2066,7 @@ ice_update_recipe_lkup_idx(struct ice_hw *hw,
{
struct ice_aqc_recipe_data_elem *rcp_list;
u16 num_recps = ICE_MAX_NUM_RECIPES;
+ u8 lkup_val;
int status;
rcp_list = kzalloc_objs(*rcp_list, num_recps);
@@ -2078,9 +2079,19 @@ ice_update_recipe_lkup_idx(struct ice_hw *hw,
if (status) {
ice_debug(hw, ICE_DBG_SW, "Failed to get recipe %d, status %d\n",
params->rid, status);
- goto error_out;
+ goto out;
}
+ lkup_val = params->fv_idx;
+ if (params->ignore_valid)
+ lkup_val |= ICE_AQ_RECIPE_LKUP_IGNORE;
+
+ if (rcp_list->content.lkup_indx[params->lkup_idx] == lkup_val &&
+ (!params->mask_valid ||
+ rcp_list->content.mask[params->lkup_idx] ==
+ cpu_to_le16(params->mask)))
+ goto out;
+
/* only modify existing recipe's lkup_idx and mask if valid, while
* leaving all other fields the same, then update the recipe firmware
*/
@@ -2100,7 +2111,7 @@ ice_update_recipe_lkup_idx(struct ice_hw *hw,
params->mask, params->mask_valid ? "true" : "false",
status);
-error_out:
+out:
kfree(rcp_list);
return status;
}
diff --git a/drivers/net/ethernet/intel/ice/ice_vlan_mode.c b/drivers/net/ethernet/intel/ice/ice_vlan_mode.c
index 92c6f83a7efec..69dce2997845c 100644
--- a/drivers/net/ethernet/intel/ice/ice_vlan_mode.c
+++ b/drivers/net/ethernet/intel/ice/ice_vlan_mode.c
@@ -240,7 +240,7 @@ static struct ice_update_recipe_lkup_idx_params ice_dvm_dflt_recipes[] = {
* ice_dvm_update_dflt_recipes - update default switch recipes in DVM
* @hw: hardware structure used to update the recipes
*/
-static int ice_dvm_update_dflt_recipes(struct ice_hw *hw)
+int ice_dvm_update_dflt_recipes(struct ice_hw *hw)
{
unsigned long i;
diff --git a/drivers/net/ethernet/intel/ice/ice_vlan_mode.h b/drivers/net/ethernet/intel/ice/ice_vlan_mode.h
index a0fb743d08e20..5dc705435f56a 100644
--- a/drivers/net/ethernet/intel/ice/ice_vlan_mode.h
+++ b/drivers/net/ethernet/intel/ice/ice_vlan_mode.h
@@ -8,6 +8,7 @@ struct ice_hw;
bool ice_is_dvm_ena(struct ice_hw *hw);
int ice_set_vlan_mode(struct ice_hw *hw);
+int ice_dvm_update_dflt_recipes(struct ice_hw *hw);
void ice_post_pkg_dwnld_vlan_mode_cfg(struct ice_hw *hw);
#endif /* _ICE_VLAN_MODE_H */
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [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
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-12-03 3:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox