mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: poros@redhat.com
Cc: netdev@vger.kernel.org, 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, aleksandr.loktionov@intel.com,
	horms@kernel.org, michal.swiatkowski@linux.intel.com,
	grzegorz.nitka@intel.com, pmenzel@molgen.mpg.de,
	wojciech.drewek@intel.com, marcin.szycik@linux.intel.com,
	martyna.szapar-mudlaw@linux.intel.com, ivecera@redhat.com,
	alice.michael@intel.com, jacob.e.keller@intel.com,
	jbrandeb@kernel.org, patryk.holda@intel.com,
	sx.rinitha@intel.com, aaron.ma@canonical.com,
	intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v6 1/4] ice: stop the service task before the PF is unloaded
Date: Tue, 01 Dec 2026 13:23:01 +0000	[thread overview]
Message-ID: <179613138179.3146.62995099966356105@kernel.org> (raw)
In-Reply-To: <20261130132107.1177185-2-poros@redhat.com>

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

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

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 new early ice_service_task_stop() in ice_remove() does not
  keep the service work from being queued again during teardown.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a high-
  severity sibling of the timer use-after-free the patch fixes, in the…

--

ice: stop the service task before the PF is unloaded

This patch moves ice_service_task_stop() and ice_aq_cancel_waiting_tasks()
in ice_remove() back to right after ice_free_vfs(). Commit 8a37f9e2ff40
had moved them to the end of ice_remove(). The goal is to keep the service
task from walking pf->vsi[] while aRFS, the netdev, the LAG and the VSIs
are freed.

> diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
> index 47c6798c97e8f..6dede87b78944 100644
> --- a/drivers/net/ethernet/intel/ice/ice_main.c
> +++ b/drivers/net/ethernet/intel/ice/ice_main.c
> @@ -5387,6 +5387,9 @@ static void ice_remove(struct pci_dev *pdev)
>  		ice_free_vfs(pf);
>  	}
>  
> +	ice_service_task_stop(pf);
> +	ice_aq_cancel_waiting_tasks(pf);
> +

[Severity: High]
Does this stop keep the service work from being queued again during the
rest of ice_remove()?

ice_service_task_schedule() checks ICE_SERVICE_DIS without a lock. Only
after that does it do the SCHED test_and_set and the queue_work():

void ice_service_task_schedule(struct ice_pf *pf)
{
	if (!test_bit(ICE_SERVICE_DIS, pf->state) &&
	    !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) &&
	    !test_bit(ICE_NEEDS_RESTART, pf->state))
		queue_work(ice_wq, &pf->serv_task);
}

ice_service_task_stop() clears SCHED at the end:

	if (pf->serv_task.func)
		cancel_work_sync(&pf->serv_task);

	clear_bit(ICE_SERVICE_SCHED, pf->state);

Several callers of ice_service_task_schedule() are still live at this
point:

  - ice_misc_intr(). The misc IRQ is not freed until
    ice_deinit()->ice_deinit_pf().
  - ice_set_rx_mode() and ice_rx_flow_steer(). The netdev stays
    registered until ice_unload().

Can this sequence happen?

CPU1 (e.g. ice_set_rx_mode())
ice_service_task_schedule()
  test_bit(ICE_SERVICE_DIS) == 0

                          CPU0 ice_remove()
                          ice_service_task_stop()
                            set ICE_SERVICE_DIS
                            timer_delete_sync()
                            cancel_work_sync()   /* nothing pending */
                            clear_bit(ICE_SERVICE_SCHED)

  test_and_set_bit(ICE_SERVICE_SCHED) succeeds
  queue_work(ice_wq, &pf->serv_task)

                          ice_remove_arfs()
                          ice_unload()
                          ice_deinit()
                          ice_vsi_release_all()

ice_service_task() would then walk pf->vsi[] through
ice_sync_fltr_subtask(), ice_check_for_hang_subtask(),
ice_sync_arfs_fltrs() and so on, while CPU0 frees those structures. The
mod_timer() at the end of that run can also arm serv_tmr again. The only
later cancel is the one in ice_deinit_dev(), which runs after the VSIs are
freed.

On non-RT kernels the window is a few instructions. On PREEMPT_RT,
threaded IRQs and softirqs can be preempted, so the window can be much
longer.

The commit message says that "a caller that passed the ICE_SERVICE_DIS
test before a stop can still queue the work after it". This fix depends on
ice_service_task_stop() keeping the task out of the teardown, though.

Would a final stop be needed here to fully close the use-after-free on
pf->vsi[]? For example, disable_work_sync() plus timer_shutdown_sync(), or
rechecking DIS under a lock that ice_service_task_stop() also takes.

[Severity: High]
This is a pre-existing issue, not one introduced by this patch. The
recovery mode branch earlier in ice_remove() seems to have the same timer
use-after-free that the commit message describes:

	if (ice_is_recovery_mode(&pf->hw)) {
		ice_service_task_stop(pf);
		scoped_guard(devl, priv_to_devlink(pf)) {
			ice_deinit_devlink(pf);
		}
		return;
	}

This branch calls ice_service_task_stop() once and returns. It never
reaches the second stop in ice_deinit_dev().

The recovery mode work always arms the timer again, and it does not check
ICE_SERVICE_DIS:

static void ice_service_task_recovery_mode(struct work_struct *work)
{
	...
	ice_service_task_complete(pf);

	mod_timer(&pf->serv_tmr, jiffies + msecs_to_jiffies(100));
}

ice_service_task_stop() deletes the timer before it waits for the work:

	if (pf->serv_tmr.function)
		timer_delete_sync(&pf->serv_tmr);
	if (pf->serv_task.func)
		cancel_work_sync(&pf->serv_task);

If ice_service_task_recovery_mode() is running while cancel_work_sync()
waits, it arms serv_tmr again after the delete.

ice_service_timer() then arms itself again on every expiry. Its
mod_timer() runs before the DIS check in ice_service_task_schedule(),
and that check only blocks queue_work().

After ice_remove() returns, devres frees the devlink allocation that holds
pf, because ice_allocate_pf() registers ice_devlink_free(). Can the timer
then fire on freed memory, or in unloaded module text after rmmod?

The recovery work arms the timer again every 100ms, so this looks easier to
hit than the long last run that the commit message describes. The commit
message mentions "a path that calls ice_service_task_stop() only once" in
general terms. It does not mention this branch in ice_remove() itself.

Would one of these fix it?

  - a second ice_service_task_stop() on this branch
  - making ice_service_task_stop() cancel the work before it deletes the
    timer
  - using timer_shutdown_sync() on the remove paths

>  	if (!ice_is_safe_mode(pf))
>  		ice_remove_arfs(pf);
>  

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130132107.1177185-1-poros%40redhat.com

  reply	other threads:[~2026-12-01 13:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 13:21 [PATCH net v6 0/4] ice: fix DFLT Rx rule handling for promisc and switchdev Petr Oros
2026-11-30 13:21 ` [PATCH net v6 1/4] ice: stop the service task before the PF is unloaded Petr Oros
2026-12-01 13:23   ` netdev-bot+sashiko [this message]
2026-11-30 13:21 ` [PATCH net v6 2/4] ice: do not leave switchdev mode while subfunction ports exist Petr Oros
2026-11-30 13:21 ` [PATCH net v6 3/4] ice: resync uplink filters after a switchdev session Petr Oros
2026-12-01 13:23   ` netdev-bot+sashiko
2026-11-30 13:21 ` [PATCH net v6 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=179613138179.3146.62995099966356105@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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=poros@redhat.com \
    --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

all inboxes | Powered by JetHome®