From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Thu, 3 Dec 2026 13:31:57 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E721F000C1; Thu, 3 Dec 2026 13:31:56 +0000 (UTC) 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== Subject: Re: [PATCH net 2/3] ice: lock VF config while changing its MSI-X vector count 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 Date: Thu, 03 Dec 2026 13:31:55 +0000 Message-ID: <179630471576.3146.16306536090827178112@kernel.org> In-Reply-To: <20261202124956.18277-3-przemyslaw.kitszel@intel.com> References: <20261202124956.18277-3-przemyslaw.kitszel@intel.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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