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=1796258546; b=XdQCCpWakChUAPruxe1Vnt9WaQFqmMlVxIutJdGjxomnf88eCTd1i0Qj0s0TqQ14CK93 VVOEtEny3QrwDgtHiO0vqlkhb5AUkVqXaI3ii29DxHwAvcMPChBmS+xZtQzuGKtmSTcMu xX8B0JJFZkAsuNO8kSSfi2wXRNSw0zugUmyRglFQbnW+Et3WS4eY25IoQ4A9fLqiQmf73 e86Eg/yay+sTzewWr1LF0tiOH86j7+7YVnAtK3p6igQR7Nz90xH69UToZL1qGIl6E6+6f 0WZMubtijWCueVHxNRMxfnLfMoQh+AknCD67DSYOUO04EPwTdSvfTit4rcQBX4GG+rw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796258546; 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=7K5o/BsigUxSL9lUP71NUtE/Eksgq7UuqSS8FoA+6qI=; b=D2iJIuk3wTO7+9E+2TyGI6Wg+p+ps9utAsXRD4wVYc4t1/eHH9u6r1IO9LsB0yTH8ibX BqT8iaAUESQ31QmraJGC6CjnbyXrloxEgiaEkfvZduK1t61HEdbZM4FMR6Ww36a99LSra LWUcr+nHJ/I+2V8LQStmUriMVu38H2f2XyfA1AojXeFNY9ahn0UXRHmAo35nJ/kzik+yI qpH1lxqf91T85rrl6PxY0IS8ZrBNZlYla5OiOp9aWHqTYSoPIBOiCvMGr+qZJE9GZzTcx qoEQKFOHsJDgL6+FP53YBRs8cRvWoEnmJy8drHz5n7Resn3+gmZwSUjgW/KH1p1Eafg== 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=CYtIOiVu; 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 673AB606A33A; Thu, 3 Dec 2026 00:42:26 +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=CYtIOiVu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99A921F000C1; Thu, 3 Dec 2026 00:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796258546; bh=7K5o/BsigUxSL9lUP71NUtE/Eksgq7UuqSS8FoA+6qI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=CYtIOiVuj8Nyzrhc0sjBf90p4NhiWoA6RSAvz6ekZMi0SH2M+V+xsdsKzxsHI6Gai t4rpqDuiH2jKQHgIpXCY+W6/w7W656cuP2DuuX72vuaGNhwfIoLL8dbPU3R9CBBmGb Yq2yng9dZT0MvWHeEV8jQlTTkM1y9Rcx/MH9XpXtPze6EHR7AvOInq70CC5/TtET5k 6wHMTqLdGD9e1V6oBxtQ+B3g0qW4TGD8D6C871/CW9/VtH87c12Foi9uYnkkadoVKP hX75Dob5g9LufPUmM8mJl1IoFU3UQyEJNi7S5sXVEMAuGAsHJ0WHSX0IUO+1Bpnwe7 ifLdOXpdQwIcQ== Subject: Re: [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a PCI reset From: netdev-bot+sashiko@kernel.org To: nikhil.rao@amd.com Cc: brett.creeley@amd.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, eric.joyner@amd.com, abhijit.gangurde@amd.com, allen.hubbe@amd.com Date: Thu, 03 Dec 2026 00:42:25 +0000 Message-ID: <179625854521.3146.11030796304497825514@kernel.org> In-Reply-To: <20261202-b4-pr60-v1-4-b1f6706e065b@amd.com> References: <20261202-b4-pr60-v1-4-b1f6706e065b@amd.com> X-sashiko-severity: Medium 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: 0 (2) · Medium: 1 · 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). - [Medium] The commit message and the Fixes: tag cover only the PCI reset (FLR) path: ionic_reset_prepare()/ionic_reset_done(), added by… Pre-existing issues: - [High] This problem wasn't introduced by this patch, but ionic_get_stats() (ethtool -S) has the same check-then-use race with… - [High] This problem wasn't introduced by this patch, but ionic_qcq_disable() cancels the DIM work before it quiesces the… -- ionic: fix ethtool coalesce updates racing a PCI reset This patch holds lif->queue_lock for all of the update in ionic_set_coalesce(). The PCI reset teardown frees the queues and unmaps BAR0 under queue_lock without rtnl, and the restart reprograms the queues from the saved coalesce settings. With the lock held, the ethtool update can no longer race with either of them. > A PCI reset clears LIF_F_UP, frees the queues and unmaps BAR0 > without rtnl, so an update that passed the test just before the reset > reads freed queues and writes the unmapped BAR. [ ... ] > Fixes: a79b559e99be ("ionic: add FLR recovery support") [Severity: Medium] Is the PCI reset the only path where this race happens? The firmware reset path does the same teardown, also without rtnl: ionic_lif_deferred_work() ionic_lif_handle_fw_down() mutex_lock(&lif->queue_lock); ionic_stop_queues(lif) <- clears IONIC_LIF_F_UP ionic_txrx_free(lif) <- devm_kfree(lif->rxqcqs[i]), sets it NULL ionic_qcqs_free(lif) <- frees the rxqcqs/txqcqs arrays mutex_unlock(&lif->queue_lock); Suppose an ionic_set_coalesce() call has already passed the test_bit(IONIC_LIF_F_UP) check. It would then read lif->rxqcqs[i]->flags after the qcq has been freed or set to NULL. The fw_down teardown dates from c672412f6172 ("ionic: remove lifs on fw reset"). ionic_lif_handle_fw_down() has held queue_lock since 2624d95972db ("ionic: widen queue_lock use around lif init and deinit"). So this patch closes the firmware reset race as well. Could the commit message describe the firmware reset path too? Would it be more accurate for the Fixes: tag to point at the commit that opened that race? With only the FLR commit in the tag, stable trees that have queue_lock in fw_down but not FLR recovery, such as 6.1.y, won't pick this fix up automatically. > diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c > index 1360a3dfb7c66..bc0601dbcf63a 100644 > --- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c > +++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c > @@ -555,6 +555,8 @@ static int ionic_set_coalesce(struct net_device *netdev, > tx_coal > IONIC_INTR_CTRL_COAL_MAX) > return -ERANGE; > > + mutex_lock(&lif->queue_lock); > + > /* Save the new values */ > lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs; > lif->rx_coalesce_hw = rx_coal; [ ... ] > @@ -598,6 +600,7 @@ static int ionic_set_coalesce(struct net_device *netdev, > } > } > } > + mutex_unlock(&lif->queue_lock); > > return 0; > } [Severity: High] This is a pre-existing issue, but does ionic_get_stats() have the same check-then-use race with PCI reset and firmware reset? It runs under rtnl only and tests the flag without any lock: drivers/net/ethernet/pensando/ionic/ionic_ethtool.c:ionic_get_stats() { ... if (test_bit(IONIC_LIF_F_FW_RESET, lif->state)) return; memset(buf, 0, stats->n_stats * sizeof(*buf)); for (i = 0; i < ionic_num_stats_grps; i++) ionic_stats_groups[i].get_values(lif, &buf); } The get_values path goes through ionic_sw_stats_get_values() into two groups of helpers: - ionic_get_lif_stats() dereferences lif->hwstamp_txq->q.index and lif->hwstamp_rxq->q.index. - ionic_sw_stats_get_txq_values() and ionic_sw_stats_get_rxq_values() index &lif->txqstats[q_num] and &lif->rxqstats[q_num]. Meanwhile, ionic_reset_prepare() sets IONIC_LIF_F_FW_RESET and then does this under queue_lock only: ionic_reset_prepare() set_bit(IONIC_LIF_F_FW_RESET, lif->state); ... mutex_lock(&lif->queue_lock); ionic_txrx_free(lif) <- devm_kfree() of hwstamp_txq/hwstamp_rxq ionic_qcqs_free(lif) <- devm_kfree(dev, lif->rxqstats); lif->rxqstats = NULL; (same for txqstats) ionic_lif_handle_fw_down() does the same after test_and_set_bit() of IONIC_LIF_F_FW_RESET. Suppose an ETHTOOL_GSTATS request passes the flag test just before a reset. Can it copy freed stats memory into the user's ethtool buffer, or oops on a NULL lif->txqstats or lif->rxqstats? [Severity: High] This isn't a bug introduced by this patch, but ionic_dim_work() also writes this coalesce register, and queue_lock doesn't serialize it. Can it run on a freed qcq after BAR0 has been unmapped? ionic_qcq_disable() cancels the DIM work before it masks the interrupt and disables NAPI: drivers/net/ethernet/pensando/ionic/ionic_lif.c:ionic_qcq_disable() { ... cancel_work_sync(&qcq->dim.work); ionic_intr_mask(idev->intr_ctrl, qcq->intr.index, IONIC_INTR_MASK_SET); synchronize_irq(qcq->intr.vector); ... napi_disable(&qcq->napi); ... } At the cancel, the queue is still enabled in hardware and the interrupt is still unmasked. A NAPI poll can complete between cancel_work_sync() and napi_disable() and queue the work again: ionic_rx_napi() / ionic_tx_napi() / ionic_txrx_napi() ionic_dim_update() net_dim() dim->state = DIM_APPLY_NEW_PROFILE; schedule_work(&dim->work); DIM is on by default, since ionic_lif_alloc() sets IONIC_LIF_F_RX_DIM_INTR and IONIC_LIF_F_TX_DIM_INTR. Nothing cancels or flushes dim.work after this point. ionic_stop(), ionic_reset_prepare() and ionic_lif_handle_fw_down() then call ionic_txrx_free(). It devm_kfree()s the qcq that contains the still queued work_struct. When ionic_dim_work() runs later, it does this on the freed qcq: ionic_intr_coal_init(lif->ionic->idev.intr_ctrl, intr->index, intr->dim_coal_hw); In the PCI reset case, ionic_reset_prepare() has also called ionic_dev_teardown() and ionic_clear_pci() by then. That would make this iowrite32 hit the unmapped BAR0. This ordering seems to date back to 04a834592bf5 ("ionic: dynamic interrupt moderation"). Should cancel_work_sync(&qcq->dim.work) be moved after napi_disable()? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-b4-pr60-v1-0-b1f6706e065b%40amd.com