From: Aaron Ma <aaron.ma@canonical.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Cc: Henry Tieman <henry.w.tieman@intel.com>,
intel-wired-lan@lists.osuosl.org
Subject: [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup
Date: Thu, 3 Dec 2026 11:53:20 +0800 [thread overview]
Message-ID: <20261203035320.187412-2-aaron.ma@canonical.com> (raw)
In-Reply-To: <20261203035320.187412-1-aaron.ma@canonical.com>
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
prev parent reply other threads:[~2026-12-03 3:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203035320.187412-2-aaron.ma@canonical.com \
--to=aaron.ma@canonical.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=henry.w.tieman@intel.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox