๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26402

Re: [PATCH net 2/3] ice: lock VF config while changing its MSI-X vector count

#26402
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 13:31
215 lines
15626 bytes
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
Technical Details
Message-ID: <179630471576.3146.16306536090827178112@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376634-linux-kernel-netdev=dewy.ru
References: <20261202124956.18277-3-przemyslaw.kitszel@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376634-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179630471576.3146.16306536090827178112@kernel.org>
References: <20261202124956.18277-3-przemyslaw.kitszel@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2503196"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:bY3n4BhtGQBCXoD/bUUl5L92nrs= sha256:1EPjJGFKw6Ux3IEAPnkbsBk9EXI21d3TMSs2DeQsYR0=
	sha1:59n77nT24Fh/PGi/T8eNTggzuJY= sha256:xg5JVoe93g1/oo7PzHi41bfVBrxUqn3kwLkP2K50wE4=
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 5E2C2117966; Thu,  3 Dec 2026 16:32:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, 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] 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 dJLc97I285lN;
	Thu,  3 Dec 2026 16:32:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376634-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 AEEE2117963; Thu,  3 Dec 2026 16:32:05 +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 87A452B63F; Thu,  3 Dec 2026 13:31:58 +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=1796304718;
	b=Bg/UZOdKbgjtc7IV059UOTTFQRpqKQhOBnnJLdefP++GNaQ87R5W7++OOMwLxXy4axZk
	 IMQbFOVksOSzJZ864NgDbLbeETYVTRRgPGyI89AkJxxiU5kfOkySah3eAmzHlueBoj4ll
	 w7tuABbPB7HJCtA39m/cii2FWtg7wyxFSL8nnYJ4IfQrZ0Xzv3bkncA9HILQy6yANcF3d
	 RCEesbmilLabFCEZ44OW6Hj5FUPumCUbyGgbFkcIk/jCdtfO4rUmSQL+IEfN4qtheRJnZ
	 wEc2KhszTlFHR3gck5ZSN1Nju9XTzSTUIqsJJeLfeDyH2rUa3ppitEuDdjzVtaIrJug==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796304718;
	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=/orqf4QP7eP3A9Ra6U5oQRJIsFzW+Dm+g2KGqIKrZm8=;
	b=rKk7XieW3MDvA+B/BpFlECJHlksNvSREYiO+aMrcxYMiegBaZUCjY8flGcFI11sxNwOI
	 Q1HUwLp/qA8DA03f90gYmO/jJ+gT9DgMcaim7RVzPcL4BQz5JL2JPiB0CCQEc4kwDtwUD
	 7Eg7ZiWYgTqvS/nt3ZokcYkDPlwsUGr1nsNz0yDg75DbpEsWRBVmKOjlBx/9+AYPvwKGy
	 9xEcmWWlsH9jsgnRTR+3GZPdg8zRjL42s4V2oheAOqAf47RZPW5fAIIeVF6GqSsj+7kR7
	 Zr/pqL18FRv5JdqjaiDHn1eBZVFFoHMatKgNdqvUUqyIB8CN5QIYsrwPtbFH/8gRTeg==
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=F+Exjd4U;
	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 5FCFB606A333;
	Thu,  3 Dec 2026 13:31:58 +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=F+Exjd4U
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=1796304717;
	b=pA+XvskKJOFdVyfOx1h1hDF2QyChQR+oZ2IfOsC5oyJbVCNTUdzeMZCIk8bNh2BZYaxR
	 6cWSz0kG/VABHWhWJ/ijY9/OBiQec1VKAGWqaJNkJFk9LOSTne/T3GhzIZyziUC09i8bu
	 guYwb1N7RNyJP2VBGA+ftyPVmzjcr8rVyOs8prt4bMNPI+Xk1qMg+VcdG+hqwiRcukmTB
	 1caNBJsj9y9bS9W4BJx7lU4Vi2E1P6V5aJVOc2OIeztZqQJU/41xvUsPEpEq/Gpk6OvLJ
	 yr+qrdatk/2hjehawEr21dLu4DHM4qJlS3kC3KRp+HkTRpc6zvUBTn5cpjEMZuXukhA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796304717;
	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=/orqf4QP7eP3A9Ra6U5oQRJIsFzW+Dm+g2KGqIKrZm8=;
	b=GEd0UZQeLEnk2ILfr1M2P4wzziyJsh1QCNPYMnbO9I54UOwRszVCP01fS73w9l1jilSN
	 Gal8ULpRX4rZrEYoqQ3IpYYLWKgrgR1kxvELyqpld83z7SZxv6Q3qIKy2CdJU3LCXQrvs
	 0f7ZDMGXpcSFvo7Tn2dDwVU+xrx3mdtFzpZm+8MWgYX+dWWZlDVf9MIaO30wC5LQ/gHIH
	 wLXhdL4jZuqJbcGOMU7ExGtignlmfOwa2Jg7HNDHv6diHUvHbE+6fxa/y9Lkv0UuKtarD
	 9vv/R4bK1d4yOWYIQ3hmmzgTZn9p4G0GH4CRAdMEMSAVZo5/Blw39aY7O58iHwNDFkg==
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=F+Exjd4U;
	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 7D9A6606A322
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 13:31:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E721F000C1;
	Thu,  3 Dec 2026 13:31:56 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796304717;
	bh=/orqf4QP7eP3A9Ra6U5oQRJIsFzW+Dm+g2KGqIKrZm8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=F+Exjd4U5HDEQZMj2zWFSL2ZQaURHoG+Gw26QcGrDfyjKGCDg66o9jSenFcSd8BrD
	 +D4SkDpBIKU9kqEXtJFVZW3kZKD0wv+AzXy7E9SWP0eYQautxJBV9UgO5cXjkiLVW2
	 51FYd0kpwi6cC0iMxTvTv45To27cIHivcChXAZtennfiDkOkwFuju9PK9P0VE34qlK
	 XTGfG5A5TAYU+Pzah6KposogeDnInTr9NgndHphsSQ6Q7F+Jkyw914/gYu8965RuKz
	 yWMx7mgzyv7AlMzf7/zDc667i0FUzLB5qitLesvRnKEpricmYpwXnkkwC55B3r6c9w
	 XsgNgg/F/kXFw==
X-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
X-In-Reply-To: <20261202124956.18277-3-przemyslaw.kitszel@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