Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: przemyslaw.kitszel@intel.com
Cc: netdev@vger.kernel.org, pabeni@redhat.com, willemb@google.com,
	donald.hunter@gmail.com, jiri@resnulli.us,
	intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	horms@kernel.org, andrew+netdev@lunn.ch, poros@redhat.com
Subject: Re: [PATCH net 2/3] ice: lock VF config while changing its MSI-X vector count
Date: Thu, 03 Dec 2026 13:31:55 +0000	[thread overview]
Message-ID: <179630471576.3146.16306536090827178112@kernel.org> (raw)
In-Reply-To: <20261202124956.18277-3-przemyslaw.kitszel@intel.com>

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

Critical: 0 · High: 1 (2) · 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 patch serializes ice_sriov_set_msix_vec_count() against
  resets of the target VF only.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a memory
  corruption bug on the same function's error path.
- [High] This problem wasn't introduced by this patch, but it is a NULL-
  pointer oops on the error path the patch now wraps in cfg_lock.

--

ice: lock VF config while changing its MSI-X vector count

This patch holds vf->cfg_lock for the whole of
ice_sriov_set_msix_vec_count(). That serializes the VF VSI rebuild and
the rewrite of its queue and interrupt mappings against PF-initiated
resets of the same VF, such as ndo_set_vf_mac(). It fixes a NULL pointer
dereference in ice_free_q_vector() that shows up when the MSI-X count and
the VF MAC are changed at the same time.

Closes: https://lore.kernel.org/netdev/20261126094321.40071-1-poros@redhat.com

> diff --git a/drivers/net/ethernet/intel/ice/ice_sriov.c b/drivers/net/ethernet/intel/ice/ice_sriov.c
> index c49f48b5ae38c..5916cf7bf914e 100644
> --- a/drivers/net/ethernet/intel/ice/ice_sriov.c
> +++ b/drivers/net/ethernet/intel/ice/ice_sriov.c
> @@ -957,14 +957,18 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
>  	if (!vf)
>  		return -ENOENT;
>  
> +	mutex_lock(&vf->cfg_lock);
> +

[Severity: High]
This serializes against resets of the target VF. Does it leave the same
race open for every other VF?

With only vf->cfg_lock held, ice_sriov_set_msix_vec_count() then calls
ice_sriov_remap_vectors(pf, vf->vf_id). That function reconfigures every
other VF that does not have ICE_VF_STATE_ACTIVE set:

ice_sriov_remap_vectors() {
	ice_for_each_vf(pf, bkt, tmp_vf) {
		...
		ice_dis_vf_mappings(tmp_vf);
		ice_virt_free_irqs(pf, tmp_vf->first_vector_idx,
				   tmp_vf->num_msix);
		...
	}

	for (int i = 0; i < to_remap; i++) {
		...
		tmp_vf->first_vector_idx =
			ice_virt_get_irqs(pf, tmp_vf->num_msix);
		...
		ice_ena_vf_mappings(tmp_vf);
		...
	}
}

None of this holds tmp_vf->cfg_lock. The ice_for_each_vf() walk also
does not hold pf->vfs.table_lock, which ice_for_each_vf() documents as
required.

Meanwhile the PF can reset that other VF under its own cfg_lock, for
example with "ip link set $PF vf 1 mac ...":

__ice_set_vf_mac()
  ice_reset_vf()
    ice_vf_reconfig_vsi()
      ice_vsi_decfg()
        ice_vsi_free_arrays()
          devm_kfree(dev, vsi->txq_map);
          vsi->txq_map = NULL;

Can the remap path then reach
ice_ena_vf_mappings(tmp_vf)->ice_ena_vf_q_mappings() and dereference a
NULL or freed vsi->txq_map[0]?

The window looks wide. ice_fltr_remove_all() and ice_vsi_cfg() both issue
AdminQ commands before the arrays are allocated again.

The ICE_VF_STATE_ACTIVE filter also does not seem to exclude VFs that are
in the middle of a reset. ice_trigger_vf_reset() clears the bit at the
start of every reset:

	clear_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);

So the remap can also pick up a VF that has a driver bound, while that VF
is being reset.

Separately, the remap rewrites tmp_vf->first_vector_idx while the reset
path's ice_sriov_post_vsi_rebuild()->ice_ena_vf_mappings() programs
VPINT_ALLOC and GLINT_VECT2FUNC from that same field. Could the HW vector
routing end up disagreeing with the irq bitmap?

Here the PCI core holds only device_lock() of the PF and of the target
VF. The reset of the other VF holds rtnl, that VF's cfg_lock and
pf->lag_mutex. The two paths share no lock.

Would it make sense to also take the cfg_lock of each remapped VF? Taking
table_lock and then cfg_lock would match the order used in
ice_reset_all_vfs() and ice_free_vfs(). The other option is to not touch
other VFs here at all.

[ ... ]

> @@ -1012,6 +1017,7 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
>  
>  	vf->first_vector_idx = ice_virt_get_irqs(pf, vf->num_msix);
>  	if (vf->first_vector_idx < 0) {
> +		mutex_unlock(&vf->cfg_lock);
>  		ice_put_vf(vf);
>  		return -EINVAL;
>  	}

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. What
state is the VF left in when this fallback ice_virt_get_irqs() fails?

The function returns -EINVAL and leaves things as follows:

- vf->first_vector_idx is -ENOENT
- VPINT_ALLOC and VPINT_ALLOC_PCI are cleared
- GLINT_VECT2FUNC has been handed back to the PF
- the VSI is still configured

This fallback can fail fairly easily. The old range was freed by
ice_virt_free_irqs() before the remap, and after that either of these can
happen:

- ice_sriov_remap_vectors() refits the other inactive VFs first-fit, and
  one of them moves into the freed region.
- The new range from the first ice_virt_get_irqs(pf, vf->num_msix) lands
  on top of the old region. When ice_vsi_rebuild() fails, that range
  leaks, because the unroll path overwrites first_vector_idx without
  calling ice_virt_free_irqs().

ice_sriov_remap_vectors() has the same unchecked pattern. It stores a
possibly negative ice_virt_get_irqs() result in tmp_vf->first_vector_idx
and then calls ice_ena_vf_mappings(tmp_vf) right away.

>From then on the negative index is used without checks:

- ice_ena_vf_msix_mappings() and ice_dis_vf_mappings() do
  wr32(hw, GLINT_VECT2FUNC(v), reg) for negative v.
- ice_free_vf_res() writes GLINT_DYN_CTL(i) for negative i.

The next MSI-X change, or ice_free_vfs(), then calls:

void ice_virt_free_irqs(struct ice_pf *pf, u32 index, u32 irqs)
{
	bitmap_clear(pf->virt_irq_tracker.bm, index - pf->virt_irq_tracker.base,
		     irqs);
}

Here index is (u32)-ENOENT. Does bitmap_clear() then write far outside
pf->virt_irq_tracker.bm?

> @@ -1024,6 +1030,7 @@ int ice_sriov_set_msix_vec_count(struct pci_dev *vf_dev, int msix_vec_count)
>  	}
>  
>  	ice_ena_vf_mappings(vf);
> +	mutex_unlock(&vf->cfg_lock);
>  	ice_put_vf(vf);
>  
>  	return -EINVAL;

[Severity: High]
This is also a pre-existing issue that was not introduced by this patch.
Is it safe to call ice_ena_vf_mappings() here when the fallback
ice_vsi_rebuild() just above it may have failed?

The unroll path ignores the return value of that rebuild:

	if (needs_rebuild) {
		vsi->req_txq = prev_queues;
		vsi->req_rxq = prev_queues;

		ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT);
	}

ice_vsi_rebuild() always runs ice_vsi_decfg() first. That frees the
q_vectors, the rings and txq_map/rxq_map.

If ice_vsi_cfg_def() then fails, its unwind ends in ice_vsi_free_arrays(),
which sets txq_map/rxq_map to NULL. If the coalesce allocation fails
instead, ice_vsi_decfg() runs a second time.

In either case, ice_ena_vf_mappings() programs VPINT_ALLOC and
GLINT_VECT2FUNC for a VF that has no q_vectors. ice_ena_vf_q_mappings()
then writes VPLAN_TXQ_MAPENA and dereferences:

		reg = FIELD_PREP(VPLAN_TX_QBASE_VFFIRSTQ_M, vsi->txq_map[0]) |

Can this oops on a NULL vsi->txq_map?

This path only runs after the first rebuild has already failed
(needs_rebuild == true). That usually means queues or memory have run
out, so a second failure seems plausible.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202124956.18277-1-przemyslaw.kitszel%40intel.com

  reply	other threads:[~2026-12-03 13:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:48 [PATCH net 0/3] ice, devlink: fixes needed for XLVF Przemek Kitszel
2026-12-02 12:48 ` [PATCH net 1/3] ice: move only the valid VF queues on LAG reclaim and reset rebuild Przemek Kitszel
2026-12-02 12:48 ` [PATCH net 2/3] ice: lock VF config while changing its MSI-X vector count Przemek Kitszel
2026-12-03 13:31   ` netdev-bot+sashiko [this message]
2026-12-02 12:48 ` [PATCH net 3/3] devlink: make room for many nested instances in a dev message Przemek Kitszel
2026-12-03 13:31   ` netdev-bot+sashiko
2026-12-02 12:54 ` [PATCH net 0/3] ice, devlink: fixes needed for XLVF netdev-bot+sinfo

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=179630471576.3146.16306536090827178112@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=poros@redhat.com \
    --cc=przemyslaw.kitszel@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