Netdev List
 help / color / mirror / Atom feed
From: Petr Oros <poros@redhat.com>
To: netdev@vger.kernel.org
Cc: Petr Oros <poros@redhat.com>,
	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>,
	Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
	Simon Horman <horms@kernel.org>,
	Michal Swiatkowski <michal.swiatkowski@linux.intel.com>,
	Grzegorz Nitka <grzegorz.nitka@intel.com>,
	Paul Menzel <pmenzel@molgen.mpg.de>,
	Wojciech Drewek <wojciech.drewek@intel.com>,
	Marcin Szycik <marcin.szycik@linux.intel.com>,
	Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>,
	Ivan Vecera <ivecera@redhat.com>,
	Alice Michael <alice.michael@intel.com>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Jesse Brandeburg <jbrandeb@kernel.org>,
	Patryk Holda <patryk.holda@intel.com>,
	Rinitha S <sx.rinitha@intel.com>,
	Aaron Ma <aaron.ma@canonical.com>,
	intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v7 1/4] ice: stop the service task before the PF is unloaded
Date: Wed,  2 Dec 2026 08:16:37 +0100	[thread overview]
Message-ID: <20261202071642.2527605-2-poros@redhat.com> (raw)
In-Reply-To: <20261202071642.2527605-1-poros@redhat.com>

Commit 8a37f9e2ff40 ("ice: move ice_deinit_dev() to the end of deinit
paths") moved the service task stop and the cancel of the AdminQ event
waiters from after ice_free_vfs() to the end of ice_remove(). Since then
a queued or running service task can still walk pf->vsi[] while
ice_remove_arfs(), ice_unload() and ice_deinit() free the aRFS filters,
the netdev, the LAG and the VSIs. A last run that takes longer than a
timer period also arms the service timer again after the stop at the
end has deleted it, and the timer then fires after the PF is freed.

Stop the service task and cancel the waiters after ice_free_vfs() again,
and make that stop final. The new ice_service_task_shutdown() also
disables the work and shuts the timer down, so a caller that passed the
ICE_SERVICE_DIS test before the stop can no longer queue the work, and
a run in progress can no longer arm the timer after its delete. The
recovery mode branch of ice_remove() gets the same final stop. The stop
in ice_deinit_dev() stays for its other callers. As
before that commit, a devlink flash that is still running when the
driver is removed fails, at the latest when its next AdminQ wait times
out.

This only hardens the removal path. ice_devlink_reinit_down() and the
error paths of ice_probe() and ice_devlink_reinit_up() also tear the PF
down before they stop the service task, all three are older than that
commit and are not changed here.

Found by AI code review. Validated on an E810-C (FW 8.1.1, ICE COMMS
package 1.3.55.0) with a test-only 12 s delay in ice_sync_fltr_subtask()
after it took the VSI pointer, armed right before a promisc change and
rmmod ice. Without this patch KASAN reports a slab-use-after-free in
ice_vsi_fltr_changed() on the freed main VSI, and the kernel then faults
in call_timer_fn() on the timer function of the unloaded module. With it
rmmod waits for the run and nothing is reported. Also tested by removing
the driver during switchdev sessions and with four VFs bound to iavf. No
kernel selftests cover this.

Fixes: 8a37f9e2ff40 ("ice: move ice_deinit_dev() to the end of deinit paths")
Signed-off-by: Petr Oros <poros@redhat.com>
---
v7:
- The stop after ice_free_vfs() is final now, it also disables the work
  and shuts the timer down, so the work can no longer be queued after
  the stop and the timer can no longer be armed. The recovery mode
  branch of ice_remove() gets the same final stop.
- The message no longer says the stop in ice_deinit_dev() deletes a
  timer, the shutdown already did, and it names the error path of
  ice_devlink_reinit_up() among the paths that are not changed here.
- Dropped the Reviewed-by tags because the code changed.

v6: https://lore.kernel.org/all/20261130132107.1177185-2-poros@redhat.com/
v5: https://lore.kernel.org/all/20261127085714.1207361-2-poros@redhat.com/
---
 drivers/net/ethernet/intel/ice/ice_main.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 47c6798c97e8f1..b05eda1bf50ae7 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -1707,6 +1707,22 @@ static int ice_service_task_stop(struct ice_pf *pf)
 	return ret;
 }
 
+/**
+ * ice_service_task_shutdown - stop the service task for PF removal
+ * @pf: board private structure
+ *
+ * A caller that passed the ICE_SERVICE_DIS test before the stop can
+ * still queue the work after it, and a run in progress can arm the
+ * timer after its delete. The PF is going away, so make both
+ * permanently dead, nothing restarts them.
+ */
+static void ice_service_task_shutdown(struct ice_pf *pf)
+{
+	ice_service_task_stop(pf);
+	disable_work_sync(&pf->serv_task);
+	timer_shutdown_sync(&pf->serv_tmr);
+}
+
 /**
  * ice_service_task_restart - restart service task and schedule works
  * @pf: board private structure
@@ -5375,7 +5391,7 @@ static void ice_remove(struct pci_dev *pdev)
 	}
 
 	if (ice_is_recovery_mode(&pf->hw)) {
-		ice_service_task_stop(pf);
+		ice_service_task_shutdown(pf);
 		scoped_guard(devl, priv_to_devlink(pf)) {
 			ice_deinit_devlink(pf);
 		}
@@ -5387,6 +5403,9 @@ static void ice_remove(struct pci_dev *pdev)
 		ice_free_vfs(pf);
 	}
 
+	ice_service_task_shutdown(pf);
+	ice_aq_cancel_waiting_tasks(pf);
+
 	if (!ice_is_safe_mode(pf))
 		ice_remove_arfs(pf);
 
@@ -5407,7 +5426,6 @@ static void ice_remove(struct pci_dev *pdev)
 	ice_deinit_hw(&pf->hw);
 
 	ice_deinit_dev(pf);
-	ice_aq_cancel_waiting_tasks(pf);
 	set_bit(ICE_DOWN, pf->state);
 }
 
-- 
2.56.1


  reply	other threads:[~2026-12-02  7:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:16 [PATCH net v7 0/4] ice: fix DFLT Rx rule handling for promisc and switchdev Petr Oros
2026-12-02  7:16 ` Petr Oros [this message]
2026-12-03  8:01   ` [PATCH net v7 1/4] ice: stop the service task before the PF is unloaded netdev-bot+sashiko
2026-12-02  7:16 ` [PATCH net v7 2/4] ice: do not leave switchdev mode while subfunction ports exist Petr Oros
2026-12-03  8:01   ` netdev-bot+sashiko
2026-12-02  7:16 ` [PATCH net v7 3/4] ice: resync uplink filters after a switchdev session Petr Oros
2026-12-03  8:01   ` netdev-bot+sashiko
2026-12-02  7:16 ` [PATCH net v7 4/4] ice: use a VLAN agnostic multicast promisc rule pair for PF VSIs Petr Oros

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=20261202071642.2527605-2-poros@redhat.com \
    --to=poros@redhat.com \
    --cc=aaron.ma@canonical.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=alice.michael@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=grzegorz.nitka@intel.com \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=ivecera@redhat.com \
    --cc=jacob.e.keller@intel.com \
    --cc=jbrandeb@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcin.szycik@linux.intel.com \
    --cc=martyna.szapar-mudlaw@linux.intel.com \
    --cc=michal.swiatkowski@linux.intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=patryk.holda@intel.com \
    --cc=pmenzel@molgen.mpg.de \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=sx.rinitha@intel.com \
    --cc=wojciech.drewek@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