Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: anthony.l.nguyen@intel.com
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	edumazet@kernel.org, andrew+netdev@lunn.ch, willemb@google.com,
	netdev@vger.kernel.org, grzegorz.nitka@intel.com,
	przemyslaw.kitszel@intel.com, aaron.ma@canonical.com,
	maciej.machnikowski@intel.com, jacob.e.keller@intel.com,
	richardcochran@gmail.com, sergey.temerkhanov@intel.com,
	milena.olech@intel.com, horms@kernel.org,
	aleksandr.loktionov@intel.com, ayush1x.singh@intel.com
Subject: Re: [PATCH net 2/5] ice: clear Flow Director entries before reset cleanup
Date: Thu, 26 Nov 2026 23:00:04 +0000	[thread overview]
Message-ID: <179573400458.3135.13972640700220102761@kernel.org> (raw)
In-Reply-To: <20261125224428.4126195-3-anthony.l.nguyen@intel.com>

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

Critical: 0 · High: 1 (1) · Medium: 1 · Low: 1

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] The fix is incomplete: it clears the PF's Flow Director handles
  but leaves the VF Flow Director handles stale.
- [Medium] Holding hw->fdir_fltr_lock in ice_fdir_clear_flow_handles()
  does not stop concurrent writers of entry_h.
- [Low] ice_prepare_for_reset() now calls mutex_lock(&hw->fdir_fltr_lock)
  on every reset whenever hw->fdir_prof is non-NULL.

Pre-existing issues:
- [High] ice_fdir_replay_flows() ignores the return value of
  ice_flow_add_prof() and then always uses hw_prof->id.

--

ice: clear Flow Director entries before reset cleanup

This patch adds ice_fdir_clear_flow_handles(). The new helper zeroes the
PF Flow Director entry_h[][] handles under hw->fdir_fltr_lock.
ice_prepare_for_reset() calls it before ice_clear_hw_tbls() frees the
flow entries, so that a failed rebuild followed by driver removal does not
follow stale handles into ice_flow_rem_entry().

> diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c
> index 8805f0efe9773..3b77a3cf6c645 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c
> @@ -415,6 +415,32 @@ 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;
> +
> +	if (!hw->fdir_prof)
> +		return;
> +
> +	mutex_lock(&hw->fdir_fltr_lock);
> +	for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
> +		struct ice_fd_hw_prof *prof = hw->fdir_prof[flow];
> +		int tun, i;
> +
> +		if (!prof)
> +			continue;
> +
> +		for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++)
> +			for (i = 0; i < prof->cnt; i++)
> +				prof->entry_h[i][tun] = 0;
> +	}

[Severity: High]
Should this also clear the VF Flow Director handles?

This loop only walks hw->fdir_prof[]. The VF profiles in
vf->fdir.fdir_prof[flow] are also struct ice_fd_hw_prof. Their entry_h[][]
values are handles to ICE_BLK_FD entries that
ice_vc_fdir_write_flow_prof() creates on hw->fl_profs[ICE_BLK_FD].

ice_clear_hw_tbls()->ice_free_flow_profs(hw, ICE_BLK_FD) frees every entry
on that list, VF entries included. Nothing resets the VF entry_h[][] or
prof_entry_cnt[][], and VF FDIR profiles are not replayed.

After the rebuild, ice_reset_all_vfs() calls
ice_vf_fdir_exit()->ice_vc_fdir_rem_prof_all()->ice_vc_fdir_rem_prof().
That function still sees the stale handles:

drivers/net/ethernet/intel/ice/virt/fdir.c:ice_vc_fdir_rem_prof() {
    ...
	for (i = 0; i < fdir->prof_entry_cnt[flow][tun]; i++)
		if (vf_prof->entry_h[i][tun]) {
			...
			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 and runs
mutex_lock() and list_del() on it. Isn't this the same use-after-free that
the KASAN trace in the commit message shows?

If ice_check_reset() fails and ice_reset_all_vfs() is skipped, the stale
VF handles are followed later from
ice_free_vfs()->ice_free_vf_res()->ice_vf_fdir_exit(). That is the
rebuild-fails-then-remove case this patch is meant to fix.

The VF code predates this patch. Could the fix also invalidate the
vf->fdir.fdir_prof[] handles (or prof_entry_cnt) for each VF?

> +	mutex_unlock(&hw->fdir_fltr_lock);
> +}

[Severity: Medium]
Does holding hw->fdir_fltr_lock here serialize against the code that
writes entry_h[][]?

The main writer is ice_fdir_set_hw_fltr_rule(), reached through
ice_add_ntuple_ethtool()->ice_cfg_fdir_xtrct_seq(). That path runs after
a lockless reset check and before fdir_fltr_lock is taken:

drivers/net/ethernet/intel/ice/ice_ethtool_ntuple.c:ice_add_ntuple_ethtool() {
    ...
	if (ice_is_reset_in_progress(pf->state)) {
    ...
	ret = ice_cfg_fdir_xtrct_seq(pf, fsp, &userdata);
    ...
	mutex_lock(&hw->fdir_fltr_lock);
    ...
}

The stores themselves are not under the lock:

ice_fdir_set_hw_fltr_rule() {
    ...
	hw_prof->entry_h[0][tun] = entry1_h;
	hw_prof->entry_h[1][tun] = entry2_h;
    ...
}

The lock is also dropped here, before ice_prepare_for_reset() calls
ice_clear_hw_tbls() to free the entries. ice_reset_subtask() holds neither
rtnl nor any lock that the ethtool path shares.

Suppose an ethtool -N add gets a handle from ice_flow_add_entry() before
ice_free_flow_profs() runs, but stores it into entry_h[][] after this
function unlocks. If the rebuild then fails before ice_fdir_replay_flows(),
ice_deinit_fdir()->ice_fdir_rem_flow()->ice_fdir_erase_flow_from_hw()->
ice_flow_rem_entry() would follow that stale handle.

The race between ethtool and reset predates this patch. The commit message
reads as if the lock makes the clear safe, though:

  Clear the Flow Director handles while holding hw->fdir_fltr_lock before
  the hardware tables free their entries.

> +
>  /**
>   * ice_fdir_replay_flows - replay HW Flow Director filter info
>   * @hw: pointer to HW instance

[Severity: High]
This isn't a bug introduced by this patch, but the commit relies on
replay to install new handles. Is ice_fdir_replay_flows() safe when
ice_flow_add_prof() fails?

ice_fdir_replay_flows() {
    ...
			struct ice_flow_prof *hw_prof;
    ...
			ice_flow_add_prof(hw, ICE_BLK_FD, ICE_FLOW_RX,
					  prof->fdir_seg[tun], TNL_SEG_CNT(tun),
					  false, &hw_prof);
			for (j = 0; j < prof->cnt; j++) {
    ...
				err = ice_flow_add_entry(hw, ICE_BLK_FD,
							 hw_prof->id,
    ...
				prof->prof_id[tun] = hw_prof->id;
    ...
}

The return value is ignored, and hw_prof has no initializer.
ice_flow_add_prof() only sets *prof on success.

ice_cfg_fdir_xtrct_seq() treats a failed tunnel rule as a soft failure. It
frees tun_seg while the non-tunnel rule stays installed, which leaves
prof->cnt != 0 with prof->fdir_seg[ICE_FD_HW_SEG_TUN] == NULL. On the next
reset, replay calls ice_flow_add_prof() with segs == NULL, gets -EINVAL,
and then uses hw_prof->id anyway.

Can this oops in the rebuild path? With CONFIG_INIT_STACK_ALL_ZERO it would
be a NULL dereference. Otherwise it could reuse a stale pointer from the
previous tun iteration and record the wrong prof_id and entry_h values,
leading to later double frees.

-ENOSPC, -ENOMEM and AQ failures from ice_flow_add_prof() would reach the
same code.

> diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
> index f858473f6f532..706172e149b94 100644
> --- a/drivers/net/ethernet/intel/ice/ice_main.c
> +++ b/drivers/net/ethernet/intel/ice/ice_main.c
> @@ -601,6 +601,8 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
>  		netif_device_detach(vsi->netdev);
>  skip:
>  
> +	if (hw->fdir_prof)
> +		ice_fdir_clear_flow_handles(hw);

[Severity: Low]
With this change, ice_prepare_for_reset() takes hw->fdir_fltr_lock on
every reset once hw->fdir_prof is allocated. Can it end up locking a mutex
that has already been destroyed?

hw->fdir_prof is devm allocated, and ice_deinit_fdir() never clears it.
ice_deinit_fdir() does destroy the lock, though:

	mutex_destroy(&(&pf->hw)->fdir_fltr_lock);

During devlink reload, ice_devlink_reinit_down() calls ice_unload(), which
reaches ice_deinit_fdir() through ice_deinit_features(). Only after that
does ice_deinit_dev() stop the service task:

ice_devlink_reinit_down() {
	ice_unload(pf);
	...
	ice_deinit_dev(pf);
}

If a CORER, GLOBR or EMPR is handled in that window, the path is
ice_reset_subtask()->ice_prepare_for_reset()->ice_fdir_clear_flow_handles(),
which calls mutex_lock() on the destroyed lock. With CONFIG_DEBUG_MUTEXES
that triggers DEBUG_LOCKS_WARN_ON().

The same can happen if, on a later load, ice_init_fdir() fails before its
mutex_init() while hw->fdir_prof is still set.

Before this patch, the reset path only took this lock through
ice_remove_q_channels(), for non-PFR resets with TC_MQPRIO.

>  	/* clear SW filtering DB */
>  	ice_clear_hw_tbls(hw);
>  	/* disable the VSIs and their queues that are not already DOWN */

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125224428.4126195-2-anthony.l.nguyen%40intel.com

  reply	other threads:[~2026-11-26 23:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 22:44 [PATCH net 0/5][pull request] Intel Wired LAN Driver Updates 2026-11-25 (ice) Tony Nguyen
2026-11-25 22:44 ` [PATCH net 1/5] ice: restore DDP state during PFR recovery Tony Nguyen
2026-11-25 22:48   ` netdev-bot+sinfo
2026-11-26 23:00   ` netdev-bot+sashiko
2026-11-25 22:44 ` [PATCH net 2/5] ice: clear Flow Director entries before reset cleanup Tony Nguyen
2026-11-26 23:00   ` netdev-bot+sashiko [this message]
2026-11-25 22:44 ` [PATCH net 3/5] ice: ptp: serialize E825 PHY timer start with PTP lock and incval Tony Nguyen
2026-11-26  0:03   ` Jacob Keller
2026-11-26 23:00   ` netdev-bot+sashiko
2026-11-25 22:44 ` [PATCH net 4/5] ice: remove redundant cross-timestamp PTP command Tony Nguyen
2026-11-26 23:00   ` netdev-bot+sashiko
2026-11-25 22:44 ` [PATCH net 5/5] ice: fix computation of ETF timestamps for E830 Tony Nguyen

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=179573400458.3135.13972640700220102761@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=aaron.ma@canonical.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=ayush1x.singh@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=grzegorz.nitka@intel.com \
    --cc=horms@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=maciej.machnikowski@intel.com \
    --cc=milena.olech@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=richardcochran@gmail.com \
    --cc=sergey.temerkhanov@intel.com \
    --cc=willemb@google.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