Article View: linux.kernel.netdev
Article #23262Re: [PATCH net 2/5] ice: clear Flow Director entries before reset cleanup
From: netdev-bot+sashiko
Date: Thu, 26 Nov 2026 23:00
Date: Thu, 26 Nov 2026 23:00
240 lines
16905 bytes
16905 bytes
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
Technical Details
Message-ID:
<179573400458.3135.13972640700220102761@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372379-linux-kernel-netdev=dewy.ruReferences:
<20261125224428.4126195-3-anthony.l.nguyen@intel.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372379-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net 2/5] ice: clear Flow Director entries before reset cleanup Date: Thu, 26 Nov 2026 23:00:04 +0000 Organization: Usenet Network Message-ID: <179573400458.3135.13972640700220102761@kernel.org> References: <20261125224428.4126195-3-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="588662"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:/cL7oVD8mXGyL/9rr11GXTsHgfo= sha256:zGVfEGUkmTojUNxsY33BhvHSrUSssBJ/bUqUYXdt14g= sha1:iL43D7PPC80qwkKaaU+jl1uzMxw= sha256:nM7/zDHxLkwcMFSDJJebCxHKsKXdl9IngGyUZRVHP7Y= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 166EE125F0A; Fri, 27 Nov 2026 02:00:24 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lV3GsXMc7YkZ; Fri, 27 Nov 2026 02:00:20 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372379-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id E92BB125F0E; Fri, 27 Nov 2026 02:00:10 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 5218D2B3F8; Thu, 26 Nov 2026 23:00:07 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795734007; b=RFBVJbJtyLF89UyiZI5U7gBspq9GPIlglqSj/jrnyjOU6oaCLJwzeoap7UJvSojJPxfc ga7lUTmPP0uz2/2vQuPd2tarA7QyhEP3cHVgew9MiqkqrjtlqijwMg8UZB9m5A3lWWlaq FpCSfiP/0JnWc4Lja2qFY7W3sL4BLYRIMJ3bPfjE+/zdMboi/VpN78aFIGKVCq+G9ZU4C WMpMr1IFtZ/PZ7yCW7nKY21iYmF4/5Z/w4PIjaIUOe1rF49o0gmVSS0QJxyCfvukqcm/8 TbrBVgFjU5LFLumtxCiidwwNoCEEEAH1cUE6+jg84cUbU43sXBW74FKDvq4CimE6teg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795734007; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=92vgyNPrH++jcWuR0VMUywQ7eHqaJpZ7EPqphaUh+zc=; b=UuTqPkj8gjzsrpeeuohN7C1WCXi8MwWo6FjXTYxpK90MJoNQzuy2SqSQUfC62XCWEDmz N+hj1rQO9t0bVAIQ0CMLC1rQGLCh+/5VUGULnvMRSES5KEzNQ2iVHojC8pkuh6twLyfrg duwtt+AvfE0USgQ8NFtntmVpbPkQ+sqort7ty9ZDZcePtWgQO36xk4SB58GpaXRHunWXe 8mQ2ilDohLQjYbux1f8be3YbayV+yswCeJ9qTQlEaRGIXG5cQc97++zxrOMl/ckzUCg70 ZO05FJsDC3wDJTK+DRI9Tim8gZ1MtXZl9pFD0uunZONUsl2iROHz0JmVqDIyq3+WKrA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oG6QqPnb; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A94E606A324; Thu, 26 Nov 2026 23:00:07 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oG6QqPnb X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795734006; b=13um0fBm6B2sZB2Htfs3deMSnmlgDbyz3w3iAlkuvVmcO8eT9po0arNFg+SVUpxttfti 1Jt9XfTmvvdjpYQ9nhqrjPH3eIKBEIJW0aiE5nlAUCpJ9LQ4r7teXrdMWDI/5erbXpg3i v1dfjCBSgCFiSU+xkf3qc6ggUwG15JMOOcE5fOheNqheR+ld/pUbIwW9r5wuCYn6hMM+8 L1as/XXuTmEWwk3cYn8ZiFS7Ix+SSvoXerkWd9dYtX6nq23s4nQpwbterI0M/Gu/msnmG pp8cJCOmI5uMiNDuKMbBvuF9PIqlTKsApksIKrIJ9grTmt895elOX5Nzea2HvDBCAAg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795734006; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=92vgyNPrH++jcWuR0VMUywQ7eHqaJpZ7EPqphaUh+zc=; b=QbNYAOOdQgJMYURVTCm0zIAYQ22u917EWP1KN8MgN1S+U07GQuA5cuLxMz6JegC8QLKW sLyD92gJaPUCTtNtRINqV4Xg63m9kbJcMQTmGcfRPlcxYHt3ImeGIc1ABqXV0DiVeHn0e +lu89MYS6h8CNNF2pKj1+NJHlMCAUmB01U/KZy4xqsCHv94OrhYBNw7UR58GzGgUN0Ep5 jaXlk+fZpo6wZm5JekFkzR3glomWOMczEyQOz5PJwuOTejz1PIzgLuBP/Drxx9RedxMBz HFvXGC4fxQAqJ2/k7qe+COSx4fuPHip3zP6PzVHsd7IxURSW4RgS42P37kXU9yoP6NA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oG6QqPnb; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49EEE606A329 for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 23:00:06 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02B0C1F000C1; Thu, 26 Nov 2026 23:00:04 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795734005; bh=92vgyNPrH++jcWuR0VMUywQ7eHqaJpZ7EPqphaUh+zc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=oG6QqPnbkjcadYUvQLB+oyLqNX5DtPhOOV05mN8rE0mMxl9PhIdiYMUyKNHEBt/x2 H6D8b8Hi4MttNEKI0a4OUomcqHueMqjqOsMbLXRBZm0jqIa57oApudS0RIwigQh/QV jMN9tfj6zcZ3AwZuAenOnmJVBMSTq+qjT5H16/fDpNuba02n/4J6bTbEt3V7JHloaC C8ehX2rcAiQtFNgJGuO074EP5SgJOeCscS4lzke9h5ktCqTrY5yjG6qN0wmGzs7Pml +HUQ5ih44+7cb+9yx0Wzu70N580CTLbXkcLq5fC+NCJttMbwQb+MHH1dGy8Y5B4QVB ydFKbhzs7zQdg== X-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 X-In-Reply-To: <20261125224428.4126195-3-anthony.l.nguyen@intel.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list