Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: aaron.ma@canonical.com
Cc: anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	henry.w.tieman@intel.com, intel-wired-lan@lists.osuosl.org
Subject: Re: [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup
Date: Fri, 04 Dec 2026 04:27:15 +0000	[thread overview]
Message-ID: <179635843579.3146.11258874149190474073@kernel.org> (raw)
In-Reply-To: <20261203035320.187412-2-aaron.ma@canonical.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

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] If ice_flow_add_prof() fails in ice_fdir_replay_flows(), the
  new error path only logs and continues.
- [Low] The commit message understates the VF half of the use-after-free.
- [Low] The patch makes ice_vsi_manage_fdir() return int and adds kernel-
  doc saying 'Return: 0 on success, negative errno on failure.' The…

--

ice: clear Flow Director entries before reset cleanup

Before ice_clear_hw_tbls() runs during reset, this patch frees the VF
Flow Director profiles and invalidates the PF Flow Director entry handles
and profile IDs. It also serializes PF Flow Director updates, reset
cleanup and replay with hw->fdir_fltr_lock, and checks the return value
of ice_flow_add_prof() during replay.

> 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:

[ ... ]

> 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().

[Severity: Low]
Does this understate the VF side of the use-after-free? Before this
patch, the VF part did not seem to need a rebuild failure, a resume or a
driver unload. Any PFR, CORER, GLOBR or EMPR reset with VF Flow Director
rules installed looks like enough to trigger it:

ice_prepare_for_reset()
  ice_clear_hw_tbls()
    ice_free_flow_profs()
      frees every ice_flow_prof and ice_flow_entry on
      hw->fl_profs[ICE_BLK_FD], including the entries referenced by
      vf->fdir.fdir_prof[flow]->entry_h[][]

ice_do_reset() or ice_reset_subtask()
  ice_rebuild()
  ice_reset_all_vfs()
    ice_vf_fdir_exit()
      ice_vc_fdir_rem_prof_all()
        ice_vc_fdir_rem_prof()
          ice_flow_rem_entry(hw, ICE_BLK_FD, vf_prof->entry_h[i][tun])

ice_flow_rem_entry() then reads entry->prof from the freed entry. It
also calls list_del() and devm_kfree() on it a second time.

The new ice_vc_fdir_free_prof_all() call in ice_prepare_for_reset() is
what fixes this common path. The message presents it as an extra found
by code inspection.

Could the commit message describe the VF trigger? Would a Fixes: tag for
the commit that added VF Flow Director support also make sense? The
current tag only points at the PF Flow Director init commit.

> 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

[ ... ]

> @@ -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;
> +			}

[Severity: Medium]
If ice_flow_add_prof() fails here, can the Flow Director state for this
flow get stuck? For example, ice_flow_add_prof_sync() can return -ENOSPC
or -ENOMEM.

ice_fdir_clear_flow_handles() zeroed entry_h[] and set prof_id[] to all
0xff. It left prof->fdir_seg[tun] and prof->cnt unchanged. After this
continue, software still holds a segment for a profile that no longer
exists in hardware.

A later ethtool -N with the same input set goes through:

ice_add_ntuple_ethtool()
  ice_cfg_fdir_xtrct_seq()
    ice_fdir_set_hw_fltr_rule()

That function finds the leftover segment:

ice_fdir_set_hw_fltr_rule() {
    ...
	old_seg = hw_prof->fdir_seg[tun];
	if (old_seg) {
		...
		if (!memcmp(old_seg, seg, sizeof(*seg)))
			return -EEXIST;
    ...
}

ice_cfg_fdir_xtrct_seq() then turns that into success:

	if (ret == -EEXIST) {
		/* Rule already exists, free memory and count as success */
		ret = 0;

The filter is added to the SW list and programmed through the control
VSI. However, no HW flow profile or entry backs it for this flow type,
so it would never match. Filters that ice_fdir_replay_fltrs() replays
for that flow seem to end up the same way.

Nothing appears to re-create the profile until the input set changes,
which is only allowed once fdir_fltr_cnt[flow] is 0, or until ntuple is
turned off and on again.

The ice_flow_add_entry() failure branch later in this loop seems to have
the same problem. Both are an improvement over the old code, which used
an uninitialized hw_prof.

Would clearing prof->fdir_seg[tun], or calling ice_fdir_rem_flow() for
this flow on replay failure, let a later add re-create the profile?

[ ... ]

> @@ -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;
> +	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);
> -		return;
> +		goto release_lock;
>  	}

[Severity: Low]
The new kernel-doc says this returns a negative errno on failure. Should
the result of ice_fdir_create_dflt_rules() be passed back here?

Through ice_create_init_fdir_rule(), ice_fdir_create_dflt_rules() can
fail with -EOPNOTSUPP, -ENOMEM or -EINVAL. ice_init_fdir() treats that
failure as fatal and calls ice_fdir_release_flows().

In this branch ret stays 0, so on enable the only error ice_set_features()
can see is -EBUSY:

ice_set_features() {
    ...
		ret = ice_vsi_manage_fdir(vsi, ena);
		if (ret)
			return ret;
		ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi);
    ...
}

A failed default rule setup therefore looks like success, with
ICE_FLAG_FD_ENA set and profiles only partly created. The runtime
behavior is the same as the old void version. The documented return
contract now says otherwise, though.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203035320.187412-1-aaron.ma%40canonical.com

  reply	other threads:[~2026-12-04  4:27 UTC|newest]

Thread overview: 5+ 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 ` [PATCH net v3 2/2] ice: clear Flow Director entries before reset cleanup Aaron Ma
2026-12-04  4:27   ` netdev-bot+sashiko [this message]
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

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=179635843579.3146.11258874149190474073@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=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