🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24859

Re: [PATCH net] net: ena: reset the device before freeing admin queues on restore error

#24859
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 00:09
188 lines
14668 bytes
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
Technical Details
Message-ID: <179608376666.3146.5277556012958365078@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374546-linux-kernel-netdev=dewy.ru
References: <20261130000647.1158646-2-oss.patchbox@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374546-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179608376666.3146.5277556012958365078@kernel.org>
References: <20261130000647.1158646-2-oss.patchbox@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1572047"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Gz5dsvtAapbiOPvi/n95aQue5P8= sha256:dhnpq0drJjZe/icW7YwOrVr/T9LBRrLf/HUK+22bqHs=
	sha1:GmuYcE/Dwl7C4By8kHCJIzV1e0s= sha256:g897TUMf0xsZFxj4T9v6Y2ohdRozi4MrzHPk//pVx8A=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 6DE59126017; Tue,  1 Dec 2026 03:09:58 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Xb8sxOYCtMyz;
	Tue,  1 Dec 2026 03:09:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374546-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E1634126015; Tue,  1 Dec 2026 03:09:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 33F932AD78; Tue,  1 Dec 2026 00:09:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796083779;
	b=yKVayva0A62GKQbcC4Il9IBOo7Dy4X93gWnOaTt6H4GiikBuJpy0kJgmEsf9VZXQT3+x
	 0rUspclIC5cYqyDe/dliuwcpeP++csuBAwSbiKvohS97jtNkFMz1Myawb/hG7XnNHJ1hp
	 DpS/YqWBziSKfrXm3aV7MAI0FbKU9xGsZCn+uiVaHZcKXsBD9YV86s6B4JUadPiyWNLne
	 zCZsnk5MRU75WK46KMUM7bqfxEq7FF0aMvr5gDx5ZkQhU6HZqqgIyDaRQik7ACX3PBo2M
	 5sDrybngZzkV7nlztsjVLjsHZxeA41K+mfcsYjWSExPhiri9Kes8N2Fdcktmg2KkyrA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796083779;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=zbR9Yw6yxKy0m5I1xUBRAmQj9JuKcF40fIWFklmBS9g=;
	b=Z36wZum+ocstNNu4NG7yUI06dwh7K0G1D3w+g6CbEqR9c/Ag39F2px+JCijfQKevoYUV
	 5MIKWhkGW1XuosXsYS4tLOm5rwLct5lDl0ZJMpD81RSD4ogInLr9tKTxUQ8hpun94q/zf
	 /bH1c3AaLStAjXLKAZqrU0z0wiA6rxaM7F7tgQfh40atMKdZm3xjG6izAHK3FASuaNyGo
	 MH99rQHA0BldTUS7lHG4wbBUV3ivwc+5hEt+nRC2o+hLKss8jhlcGs5YQGWnfmcxyqeqa
	 romrtkHZigc2E0EvUA1rHt/Dc/+zsgyucW1KdtHGccQjMXxoiI3Ma1vct3hQmMHbgVw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CT7BlAFk;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 09DF6606A32A;
	Tue,  1 Dec 2026 00:09:39 +0000 (UTC)
X-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=CT7BlAFk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796083768;
	b=bzaYTbqghsMRFg1gBPSaAEtiZYDmwJs7PJl77gnCkK1CswQcxKqgBROWxivnsvICGRDi
	 eO0ILOWoptz8qljeoRx4G4EY1LquqaKRwmVgPg+ol+I4cpWRx9ys3v0Gj9Y1bNo2JN+qr
	 jwqoC35hQRr04JybkY62v4GcBI9liFSzSEHw97WKKhoyhp0WXwlf3nTF0BDvaMbImMbI4
	 2NAS5fqD5dz6PcbImOInzyJ7r+vHbyCxBJ4KOobVrgNVLHQh/xLcDCOS2oGEbcYkmiZ2Z
	 vB+Ipm8rhss9asO/LfjPAKMhkBe16udoHvUAzUvXV7Bq5zkQ+DKfaQfK1UGUIdNc3Ww==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796083768;
	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=zbR9Yw6yxKy0m5I1xUBRAmQj9JuKcF40fIWFklmBS9g=;
	b=igEB+FD0YcflPC6Qbb8rlAaTRPL4K+MN7kP3ep632D8It06vfEKCP1VzabyoiCOGc3gt
	 3ayVoH0q1Qmr1sLGJdv+U2EujvsChKhMfwQYGLcbx9WTiWFYAuyM3wsW5RsxJmWbb3HBd
	 t+BduUINcedzgu8su6vYL9jgYYRlOw5j+0ouvs/iIf8DNU/E8oVRB7RjCoHG6EnWQwCrU
	 NNl4rROoKM2CDk94Cd+j0h4Jt7H/+i1FtlFdI6/+21SNJ5iv4uyDwYF7HuQe53TTTYwUv
	 dvDNyk2/N15UHCUitwDn/DP/OII7Ci8Q8dusGOsL1i5N9d/fjgkjUYS3PrvugXOYMAA==
X-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=CT7BlAFk;
	arc=none smtp.remote-ip=100.103.45.18
X-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 2410E606A31A;
	Tue,  1 Dec 2026 00:09:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2560C1F00893;
	Tue,  1 Dec 2026 00:09:27 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796083767;
	bh=zbR9Yw6yxKy0m5I1xUBRAmQj9JuKcF40fIWFklmBS9g=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=CT7BlAFkgjy28ri+TQ/FgzP0KdghyDwSLprNKltmxf8ECE1eh+TgtVuxlr47Ljm3D
	 k2cOXVQHxpPM6mtHl8G0CohfXaH1SefWbiyBDdLovyzCxk6IZfaBtq2QvKqfYKktSl
	 t3tz45KLpTpVPyUoq4TLcIRIgP7eqi3XoJcda1ihoUJjHHab4gahNLeogXyUTIo/VZ
	 BgpnEDY0LxhBxLx5fYFLj/1zoh/qFGFN43Mo832jIyZzZYld5bUoR5A5xN+g2XekUJ
	 qoqcpXLOifT1hdXSeWle4xn9KuDf1GY0+fNTvDyDl0SV5BJ2E0uZTVxzlVnu8M5Am9
	 XW7YmS9lpcdOQ==
X-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
X-In-Reply-To: <20261130000647.1158646-2-oss.patchbox@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list