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=1796511970; b=OxejEAGKRYelR/CFHRvY1TqdyFXn9skrvUfrKQckt9WiNf98rcebAiH9Vw+MNQBpKzoJ lb/tHXuuH09dN2uyhgx/nLWjVmLkm05Z//pYk6mnK468wPafuaUTEy5PK/L+SuYLD+5Uk Oqm1saEQMgB6rmfJwc8Vaz4Qtoxgw9amJFvn2HXkSN0bB9M54WFK8a5nFHhZ3L+Ybo4YH zMyv7oNsi2KPTHE7YxcTLEdfYUb0ii02UoEc20i6oKPY8wpc7j6q9nQWfmeIdqGQOY/Ak xaThZTMY0l8cVNm8/QMWoFQAtS/RYU58En+wxL9IUPazTZdziJ08xBHC8GgAMiB6tZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796511970; 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=T3EFFJx0MrOYk0JCYt/5JDatmyZPHalNJYGGdWZE2e4=; b=Hx+rDogfOS0cESCviKATZfcevAutv07j8MlmtfdilGtjOVXndiRznUH4XEiiiz6ElzMf YudEBY681HFNi6PCye0Uyf4qkWXJmTQWK9CVGDO6nIohZWzwlZunAxnEQUPJBueEON0Dg 8qCS2jR3M9BV/yY3+1zMcS1JXFGH4Q2zkmWUBoWKVTwRyhF9nVq18bNk9LIMOT7Su6gRi s++7xjeAtHE9CYKAt0xG8Rcn2no+gTldGHmt5YgyMbvSUIE1OOc18td7GSUY9tGHBToh0 OHKzBZ0iSZf/Z1ZU+t8HQFL6OD00JhcqjIrPVKabhm0SaeS9hbRrWFq8GS5UmiDZC+Q== 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=hgVoa11m; 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 A10D9606A33C; Sat, 5 Dec 2026 23:06:10 +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=hgVoa11m Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79B471F00936; Sat, 5 Dec 2026 23:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796511970; bh=T3EFFJx0MrOYk0JCYt/5JDatmyZPHalNJYGGdWZE2e4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=hgVoa11m4Uf9rij6rEKo89JMkQ4yeS7b9qO0aBr+krIFVRs0JAErlZm/ukDyVv4f/ Um1axRsxiZ2xtNSJrCKDZGJjO/iSDZrNsGQt2xJcCJABewoX/x5VamjAyapOf+MUAX YrlcIrVcQ/QFeSoDRbOWZzV37srkYy+JnSccfp/vj2ja4rUb71kKf4hQ5Ch3YJ2em5 tpGZGDWnMmAZUwswojl4hraXXECHeTtTQMc93I3BFhURZG9cMS9im5VhFlAk6rb9vI WnIDO3c10pQ3dYX9yaU6X6x49te6632btFerA9xOVWCVU18l8ZSieNHuwafixXyiHS cXkq/kumJoBwg== Subject: Re: [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown 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:09 +0000 Message-ID: <179651196901.3148.6541276687307414833@kernel.org> In-Reply-To: <20261204-b4-pr60-v2-5-9e0b5408a68e@amd.com> References: <20261204-b4-pr60-v2-5-9e0b5408a68e@amd.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@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 2 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 1 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's stated claim, "Cancel the work once NAPI is disabled, when no poll can queue it again", does not hold for ionic,… - [Low] When cancel_work_sync(&qcq->dim.work) in ionic_qcq_disable() drops a pending ionic_dim_work(), the patch copies only the handler's… -- ionic: fix DIM work racing the queue teardown This moves cancel_work_sync(&qcq->dim.work) in ionic_qcq_disable() so it runs after napi_disable(). The goal is that a NAPI poll can no longer requeue the DIM work on a queue that is about to be freed. It also resets qcq->dim.state to DIM_START_MEASURE in place of a dropped work item. Closes: https://lore.kernel.org/netdev/179625854521.3146.11030796304497825514@kernel.org/ > diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c > index 339a3c4c5b432..909781f064967 100644 > --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c > +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c > @@ -358,13 +358,14 @@ static int ionic_qcq_disable(struct ionic_lif *lif, struct ionic_qcq *qcq, int f > > if (lif->doorbell_wa) > cancel_work_sync(&qcq->doorbell_napi_work); > - cancel_work_sync(&qcq->dim.work); > ionic_intr_mask(idev->intr_ctrl, qcq->intr.index, > IONIC_INTR_MASK_SET); > synchronize_irq(qcq->intr.vector); > irq_set_affinity_notifier(qcq->intr.vector, NULL); > irq_set_affinity_hint(qcq->intr.vector, NULL); > napi_disable(&qcq->napi); > + cancel_work_sync(&qcq->dim.work); [Severity: High] The commit message says: Cancel the work once NAPI is disabled, when no poll can queue it again. Does that hold for ionic? In ionic_tx_napi(), ionic_rx_napi() and ionic_txrx_napi(), ionic_dim_update() is only called after napi_complete_done() has returned true: drivers/net/ethernet/pensando/ionic/ionic_txrx.c:ionic_tx_napi() { ... if (work_done < budget && napi_complete_done(napi, work_done)) { ionic_dim_update(qcq, IONIC_LIF_F_TX_DIM_INTR); ... } At that point napi_complete_done() has already cleared NAPIF_STATE_SCHED. napi_disable_locked() only waits while NAPIF_STATE_SCHED or NAPIF_STATE_NPSVC is set. So napi_disable() can return while the poll is still running on another CPU. That poll may not yet have reached ionic_dim_update()->net_dim(), which calls schedule_work(&dim->work). Could this interleaving happen? CPU0 (NAPI poll) CPU1 (ionic_qcq_disable) napi_complete_done() clears NAPIF_STATE_SCHED ionic_intr_mask() synchronize_irq() napi_disable() /* returns */ cancel_work_sync(&qcq->dim.work) qcq->dim.state = DIM_START_MEASURE ionic_dim_update() net_dim() dim->state = DIM_APPLY_NEW_PROFILE schedule_work(&dim->work) This is the only cancel of dim.work in the driver. Teardown then goes through ionic_txrx_deinit()->ionic_lif_qcq_deinit(). There, netif_napi_del() waits for the poll to return, but by then the work is already queued. After that, ionic_txrx_free()->ionic_qcq_free() and devm_kfree() free the qcq that embeds dim.work. On the PCI reset path, ionic_reset_prepare() also reaches ionic_clear_pci(), which does: ionic->idev.intr_ctrl = NULL; synchronize_rcu(); ionic_unmap_bars(ionic); A late ionic_dim_work() would then use container_of() to get back to the freed qcq. It could also call ionic_intr_coal_init() through a NULL or unmapped intr_ctrl. Isn't that the same use-after-free and unmapped BAR write this patch is meant to fix? The window is short on non-RT kernels. A hardirq on CPU0 makes it wider, and on PREEMPT_RT the NAPI poll can be preempted. Would either of these close it? - Cancel dim.work and reset the DIM state only once the poll is known to have returned, for example after netif_napi_del() in ionic_lif_qcq_deinit(). - Add synchronize_net() between napi_disable() and cancel_work_sync(). > + qcq->dim.state = DIM_START_MEASURE; [Severity: Low] When cancel_work_sync() drops a pending ionic_dim_work(), this line copies only the handler's last step. Is resetting dim.state alone enough to keep DIM consistent with the hardware? net_dim_decision() has already moved dim->profile_ix forward before net_dim() sets DIM_APPLY_NEW_PROFILE and queues the work. ionic_dim_work() is the only place where profile_ix is written to the hardware: drivers/net/ethernet/pensando/ionic/ionic_lif.c:ionic_dim_work() { ... intr = &qcq->intr; if (intr->dim_coal_hw != new_coal) { intr->dim_coal_hw = new_coal; ionic_intr_coal_init(lif->ionic->idev.intr_ctrl, intr->index, intr->dim_coal_hw); } dim->state = DIM_START_MEASURE; } After the drop, the coalesce register and intr->dim_coal_hw still hold the old profile's value, while profile_ix names the new profile. The coalesce value is also not reapplied when the queues restart on the same qcq. The path ionic_stop_queues(), then ionic_start_queues() and ionic_qcq_enable(), never writes it. If DIM then parks on top with steady traffic, it will not change profile again. The hardware could stay on the value DIM decided to leave until DIM changes profile again. Would flush_work() here, or rolling profile_ix back, keep DIM in sync with the hardware? flush_work() should still be safe at this point, because ionic_intr_mask() earlier in the same block already writes through intr_ctrl. [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-pr60-v2-0-9e0b5408a68e%40amd.com