mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: ena: reset the device before freeing admin queues on restore error
@ 2026-11-30  0:06 Yuho Choi
  2026-11-30  0:08 ` netdev-bot+sinfo
  2026-12-01  0:09 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Yuho Choi @ 2026-11-30  0:06 UTC (permalink / raw)
  To: Arthur Kiyanovski, David Arinzon, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Yuho Choi

The ena_restore_device() error path frees the admin queues before it
resets the device, so the device can still write AENQ events, such as
the keep-alive, into freed memory. Reset the device first, as
ena_destroy_device() does.

Fixes: d7703ddbd7c9 ("net: ena: fix rare bug when failed restart/resume is followed by driver removal")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
I used an LLM to help write this patch and its changelog.

Compile-tested only: QEMU has no ENA device, and KASAN cannot see
writes made by the device.

 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 560b20a5861c..5ef9c0967bb4 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);
 	ena_phc_destroy(adapter);
 	ena_com_mmio_reg_read_request_destroy(ena_dev);
 err:

base-commit: fad0d57b12f6979bc0127f0a4f704c6d7177ca78
-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ena: reset the device before freeing admin queues on restore error
  2026-11-30  0:06 [PATCH net] net: ena: reset the device before freeing admin queues on restore error Yuho Choi
@ 2026-11-30  0:08 ` netdev-bot+sinfo
  2026-12-01  0:09 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-30  0:08 UTC (permalink / raw)
  To: Yuho Choi
  Cc: Arthur Kiyanovski, David Arinzon, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ena: reset the device before freeing admin queues on restore error
  2026-11-30  0:06 [PATCH net] net: ena: reset the device before freeing admin queues on restore error Yuho Choi
  2026-11-30  0:08 ` netdev-bot+sinfo
@ 2026-12-01  0:09 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01  0:09 UTC (permalink / raw)
  To: oss.patchbox
  Cc: akiyano, darinzon, andrew+netdev, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-01  0:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  0:06 [PATCH net] net: ena: reset the device before freeing admin queues on restore error Yuho Choi
2026-11-30  0:08 ` netdev-bot+sinfo
2026-12-01  0:09 ` netdev-bot+sashiko

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®