Netdev List
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset
Date: Sat, 05 Dec 2026 23:06:07 +0000	[thread overview]
Message-ID: <179651196781.3148.9629649457918353005@kernel.org> (raw)
In-Reply-To: <20261204-b4-pr60-v2-4-9e0b5408a68e@amd.com>

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

  reply	other threads:[~2026-12-05 23:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
2026-12-05 23:06   ` netdev-bot+sashiko
2026-12-04 22:04 ` [PATCH net v2 2/5] ionic: fix device info register reads " Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 3/5] ionic: fix PHC " Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset Nikhil P. Rao
2026-12-05 23:06   ` netdev-bot+sashiko [this message]
2026-12-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
2026-12-05 23:06   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179651196781.3148.9629649457918353005@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=abhijit.gangurde@amd.com \
    --cc=allen.hubbe@amd.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=brett.creeley@amd.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eric.joyner@amd.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikhil.rao@amd.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox