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=1796511969; b=oTNRNBUVwuaXt9T/aSffMB/4+RC6ZR8CTSng1pEMBIMh8fOMX9+F9jOpns2LuxhNz6yQ QZXH76B378SupvLq8xIHqgEwHmJSqC8bpXuc+rd5EPdKW7+vGNDICpwAoIKQWdrjh/9bs bNUfOFzH6XXJtBsUsTHU23LRHWTcpYfySggYrSwmICTsJJcf1eJZOZW8oRkMWc68Z4QQL o/SDYC7YLjZjtYvVN95qfyuIECg3Yxqkecg8B43RP0CTu2BJFPB3AxjUPzWwmDRK4pLII wMIp6wuyvYCh9rRjvBN1tleae3kFh0bp7Dlzc4TVk/9TYCkoVL1bSxao+CDGUmx7yWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796511969; 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=xnh3c4uJ4tb9exw+JE/xfZQCmS4eJfEE2aJUGgPUejs=; b=lVP3Q74I212YL2JF4P5M0LMiqtNhYOk5f/MVrwclntmN8zokuXGjHRwOF4mAq78mjUmn pU92XDZJnt627lSP8QaIGSWinkK+ebl1ZOsHa/ZY5x2U+tB3a/ALXGueVOhQtYzDiT3iA 8nADSE6vgMyKOBrwSnMft7d3p+jtJDYy/HtGRYBhF1kGmsRYSMd/fvKB8BoOoO0clB/Zb SIZaco4qwQnTiJR8cZT76H/gYTZxHEpdGqrxVdO3U5Kt+KNouG4/rAF7abTrikLzHlon3 3aTPJwe6f26bfOJMqBozGoQIKIRF0+j5hodq/DOKOLK+Rwj5y73bjuteED2PR4PO4YQ== 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=O7TtcWfj; 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 38A9A606A330; Sat, 5 Dec 2026 23:06:08 +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=O7TtcWfj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3846A1F0092B; Sat, 5 Dec 2026 23:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796511968; bh=xnh3c4uJ4tb9exw+JE/xfZQCmS4eJfEE2aJUGgPUejs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=O7TtcWfj/YQzu5hjFAHLqd6BEkhuUa32mBRUWbzohYWPWYXe88rfE0Yi2xTsJCw3t BuCRdWYcALJOdfgsEizIM0IT9lvgPDa8E94MMfcbDb6enSI3KXxtVBcijoFyBkfurf 3jg8HUxY1B3ZIf66ZgTqCDOPD7zwryqoonTtuhdsZibgBpYf6s3L2pvbVt9+Qhs1Yh 4Dqy4HlqQ3LRIi3MbhshbboEkpnjVviSKxAM+azDGuf4I+Za/v7cTsZZELrK4OLOg+ FeyuqKyadaXHwb+jh9eKilO5k2LId37HQrD4M+wB5g2yC7bn4W/ssnHuetnkMnTL0b lYcI7R0TQ/21Q== Subject: Re: [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a 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: Sat, 05 Dec 2026 23:06:07 +0000 Message-ID: <179651196781.3148.9629649457918353005@kernel.org> In-Reply-To: <20261204-b4-pr60-v2-4-9e0b5408a68e@amd.com> References: <20261204-b4-pr60-v2-4-9e0b5408a68e@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 (1) · 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] ionic_set_coalesce() (drivers/net/ethernet/pensando/ionic/ionic_ethtool.c) reads… Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the ethtool -S callback in the same file has the same race the patch fixes for… -- ionic: fix ethtool coalesce updates racing a reset This patch holds lif->queue_lock across the whole update in ionic_set_coalesce(). That covers saving the new settings and writing each queue's interrupt control register. The PCI and firmware reset paths tear down and restart the queues under queue_lock without rtnl, so the lock keeps the coalesce update from racing them. > 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; [Severity: Medium] Can rx_coal and tx_coal still be computed from a half-rewritten ident during a reset? ionic_set_coalesce() reads the ident values and does the conversions before it takes the lock: ident = &lif->ionic->ident; if (ident->dev.intr_coal_div == 0) { ... rx_coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->rx_coalesce_usecs); if (!rx_coal && coalesce->rx_coalesce_usecs) rx_coal = 1; During PCI reset recovery, ionic_reset_done()->ionic_setup_one()-> ionic_identify() rewrites ident. It holds neither rtnl nor queue_lock: ionic_identify() { memset(ident, 0, sizeof(*ident)); ... err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); if (!err) { sz = min(sizeof(ident->dev), sizeof(idev->dev_cmd_regs->data)); memcpy_fromio(&ident->dev, &idev->dev_cmd_regs->data, sz); } ... } The firmware-up path does the same through ionic_lif_handle_fw_up()-> ionic_identify(). ionic_reset_prepare() doesn't call netif_device_detach(), so ethtool -C can run during this window. Nothing in ionic_set_coalesce() checks IONIC_LIF_F_FW_RESET. If ethtool -C reads the zeroed divisor, it returns a spurious -EIO. It can also pass the divisor check just before the memset, or read mult and div at different points in the rewrite. In both cases ionic_coal_usec_to_hw() returns 0: if (!div || !mult) return 0; Any non-zero request is then forced to 1. Under the new lock, that 1 is stored in lif->rx_coalesce_hw and lif->tx_coalesce_hw. Then ionic_restart_lif()->ionic_txrx_alloc() programs it into every new queue. The commit message says the restart "can pick up a half-written update" and that taking queue_lock for the whole update fixes this. Is that fully covered while the inputs are still read outside the lock, from state the reset rewrites? Would it help to move the conversion under queue_lock and return -EBUSY while IONIC_LIF_F_FW_RESET is set, as ionic_set_channels() already does? > @@ -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 and was not introduced by this patch. ionic_get_stats() in the same file looks like it has the same check-then-use race against the reset paths: 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); } This runs under rtnl only. The get_values callbacks reach these functions: ionic_sw_stats_get_values()->ionic_get_lif_stats()-> ionic_add_lif_txq_stats() / ionic_add_lif_rxq_stats() ionic_sw_stats_get_txq_values() / ionic_sw_stats_get_rxq_values() All of them index &lif->txqstats[q_num] and &lif->rxqstats[q_num] for each queue. ionic_reset_prepare() and ionic_lif_handle_fw_down() both set IONIC_LIF_F_FW_RESET. They then call ionic_qcqs_free() under queue_lock, without rtnl: ionic_qcqs_free() { ... if (lif->rxqcqs) { devm_kfree(dev, lif->rxqstats); lif->rxqstats = NULL; ... if (lif->txqcqs) { devm_kfree(dev, lif->txqstats); lif->txqstats = NULL; ... } ionic_reset_prepare() never calls netif_device_detach(), so the netif_device_present() check in the ethtool core doesn't block callers during a PCI reset. In the firmware reset path, the detach happens after a caller may already have passed that check. Suppose ethtool -S passes the IONIC_LIF_F_FW_RESET test just before the reset sets the bit. Can it still be in the read loop when these arrays are freed? It would then copy freed memory into the user's stats buffer, or read through a NULL base and oops. Does ionic_get_stats() need the same queue_lock treatment as ionic_set_coalesce()? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-pr60-v2-0-9e0b5408a68e%40amd.com