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=1796083768; b=bzaYTbqghsMRFg1gBPSaAEtiZYDmwJs7PJl77gnCkK1CswQcxKqgBROWxivnsvICGRDi eO0ILOWoptz8qljeoRx4G4EY1LquqaKRwmVgPg+ol+I4cpWRx9ys3v0Gj9Y1bNo2JN+qr jwqoC35hQRr04JybkY62v4GcBI9liFSzSEHw97WKKhoyhp0WXwlf3nTF0BDvaMbImMbI4 2NAS5fqD5dz6PcbImOInzyJ7r+vHbyCxBJ4KOobVrgNVLHQh/xLcDCOS2oGEbcYkmiZ2Z vB+Ipm8rhss9asO/LfjPAKMhkBe16udoHvUAzUvXV7Bq5zkQ+DKfaQfK1UGUIdNc3Ww== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2560C1F00893; Tue, 1 Dec 2026 00:09:27 +0000 (UTC) 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== Subject: Re: [PATCH net] net: ena: reset the device before freeing admin queues on restore error 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 Date: Tue, 01 Dec 2026 00:09:26 +0000 Message-ID: <179608376666.3146.5277556012958365078@kernel.org> In-Reply-To: <20261130000647.1158646-2-oss.patchbox@gmail.com> References: <20261130000647.1158646-2-oss.patchbox@gmail.com> X-sashiko-severity: Medium 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 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