From: netdev-bot+sashiko@kernel.org
To: oss.patchbox@gmail.com
Cc: akiyano@amazon.com, darinzon@amazon.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] net: ena: reset the device before freeing admin queues on restore error
Date: Tue, 01 Dec 2026 00:09:26 +0000 [thread overview]
Message-ID: <179608376666.3146.5277556012958365078@kernel.org> (raw)
In-Reply-To: <20261130000647.1158646-2-oss.patchbox@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (2) · 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 patch is titled "reset the device before freeing admin
queues on restore error", but one restore failure still frees the…
Pre-existing issues:
- [Medium] In the err_device_destroy path of ena_restore_device()
(ena_netdev.c:3373-3374), the return value of ena_com_dev_reset() is…
- [Medium] Each ena_destroy_device() -> ena_restore_device() cycle leaks
the 4 KiB coherent DMA host_info buffer.
--
net: ena: reset the device before freeing admin queues on restore error
This patch moves the ena_com_dev_reset() call in the err_device_destroy
path of ena_restore_device() so that it runs before
ena_com_admin_destroy(). The goal is to stop the device from writing
AENQ events into admin queue memory that has already been freed. This
matches the order used in ena_destroy_device().
> diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> index 560b20a5861c8..5ef9c0967bb4a 100644
> --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
> +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> @@ -3370,8 +3370,8 @@ int ena_restore_device(struct ena_adapter *adapter)
> err_device_destroy:
> ena_com_abort_admin_commands(ena_dev);
> ena_com_wait_for_abort_completion(ena_dev);
> - ena_com_admin_destroy(ena_dev);
> ena_com_dev_reset(ena_dev, ENA_REGS_RESET_DRIVER_INVALID_STATE);
> + ena_com_admin_destroy(ena_dev);
[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch. The
return value of ena_com_dev_reset() is ignored here. The AQ, ACQ and
AENQ rings are freed whether or not the reset actually happened.
ena_com_dev_reset() can return before it writes the reset bit:
drivers/net/ethernet/amazon/ena/ena_com.c:ena_com_dev_reset() {
...
if (unlikely((stat == ENA_MMIO_READ_TIMEOUT) || (cap == ENA_MMIO_READ_TIMEOUT))) {
netdev_err(ena_dev->net_device, "Reg read32 timeout occurred\n");
return -ETIME;
}
if ((stat & ENA_REGS_DEV_STS_READY_MASK) == 0) {
...
return -EINVAL;
}
...
if (timeout == 0) {
...
return -EINVAL;
}
...
}
It can also fail if the reset indication never turns on or never turns
off.
In those cases the device still has the old ring base addresses
programmed. There is no fallback here, such as pci_clear_master().
Could the device then DMA into the freed coherent rings? This error path
can be reached when ena_up() fails because of admin timeouts. That is
also when the device is most likely to be unhealthy.
ena_destroy_device() follows the same pattern. It stores rc from
ena_com_dev_reset() but frees the rings anyway.
> ena_phc_destroy(adapter);
> ena_com_mmio_reg_read_request_destroy(ena_dev);
[Severity: Medium]
This isn't a bug introduced by this patch, but does each
ena_destroy_device() -> ena_restore_device() cycle leak the 4 KiB
host_info DMA buffer?
Every call to ena_device_init() goes through ena_config_host_info(),
which calls ena_com_allocate_host_info(). That function overwrites the
previous pointer without checking it:
drivers/net/ethernet/amazon/ena/ena_com.c:ena_com_allocate_host_info() {
...
host_attr->host_info = dma_alloc_coherent(ena_dev->dmadev, SZ_4K,
&host_attr->host_info_dma_addr, GFP_KERNEL);
...
}
Neither ena_destroy_device() nor this err_device_destroy path calls
ena_com_delete_host_info(), so the old buffer is orphaned at the next
restore.
The only callers of ena_com_delete_host_info() are:
- the ena_config_host_info() error path
- err_admin_init in ena_device_init()
- err_device_destroy in ena_probe()
- __ena_shutoff()
__ena_shutoff() only frees the most recent buffer.
The cycle can be triggered by any of these:
- the reset task (ena_fw_reset_device())
- suspend/resume
- devlink reload
- the XDP setup failure path
- toggling the large LLQ header through the ethtool ring parameters
> err:
[Severity: Medium]
When ena_device_init() fails, does ena_restore_device() still free the
admin queues on a device that was never reset?
On that failure ena_restore_device() jumps straight to err:
rc = ena_device_init(adapter, adapter->pdev, &get_feat_ctx, &wd_state);
if (rc) {
dev_err(&pdev->dev, "Can not initialize device\n");
goto err;
}
The err label only clears flags.
Inside ena_device_init(), the only ena_com_dev_reset() runs before
ena_com_admin_init(), which writes the AQ, ACQ and AENQ base addresses
into the device. After that, ena_com_get_dev_attr_feat(),
ena_com_set_aenq_config(), ena_set_queues_placement_policy() and
ena_calc_io_queue_size() can each fail and jump to err_admin_init:
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_device_init() {
...
err_admin_init:
ena_com_abort_admin_commands(ena_dev);
ena_com_wait_for_abort_completion(ena_dev);
ena_com_delete_host_info(ena_dev);
ena_com_admin_destroy(ena_dev);
...
}
That path frees the rings without resetting the device first. The
kernel-doc for ena_com_admin_destroy() in ena_com.h says:
* @note: Before calling this method, the caller must validate that the device
* won't send any additional admin completions/aenq.
* To achieve that, a FLR is recommended.
One way to get there is an admin command in polling mode that times
out. Examples are set_host_attributes from ena_config_host_info() or one
of the get_feature commands. On timeout,
ena_com_wait_and_process_admin_cq_polling() releases the comp_ctx.
outstanding_cmds then drops to 0, so ena_com_wait_for_abort_completion()
returns immediately.
Could the device then post the late completion into the freed ACQ, or
read the freed host_info buffer?
The device is not reset later on this path either. A subsequent
ena_destroy_device() returns early because ENA_FLAG_DEVICE_RUNNING is
clear.
The AENQ keep-alive case from the commit message should not apply here,
because ena_com_admin_aenq_enable() has not run yet. The concern is late
admin completions.
ena_probe() has the same gap at its err_device_destroy label. It is
reached from earlier probe failures and through err_worker_destroy.
Neither route passes through the ena_com_dev_reset() in err_free_msix.
Would it make sense to also call ena_com_dev_reset() before
ena_com_admin_destroy() in err_admin_init?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130000647.1158646-2-oss.patchbox%40gmail.com
prev parent reply other threads:[~2026-12-01 0:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 0:06 Yuho Choi
2026-11-30 0:08 ` netdev-bot+sinfo
2026-12-01 0:09 ` netdev-bot+sashiko [this message]
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=179608376666.3146.5277556012958365078@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=akiyano@amazon.com \
--cc=andrew+netdev@lunn.ch \
--cc=darinzon@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oss.patchbox@gmail.com \
--cc=pabeni@redhat.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
all inboxes | Powered by JetHome®