xen-netfront: unregister the XDP rxq before destroying its page_pool
Subsystems (5)
PATCH 1/1 xen-netfront: unregister the XDP rxq before destroying its page_pool
Each receive queue registers its page_pool as the XDP memory model, which takes a second reference on the pool. On disconnect, xennet_disconnect_backend() calls page_pool_destroy() but never unregisters the rxq, so the pool's user count never reaches zero and the pool is never released, together with the receive buffers that xennet_release_rx_bufs() has just recycled into it. Every suspend/resume or backend reconnect therefore leaks one pool per receive queue. The pool never begins shutdown, so the page_pool stall warning does not fire and the leak is silent.
Unregister the rxq before destroying the pool, and clear the pointer so that a second disconnect without a reconnect is harmless.
The leak was observed in CI testing: in XenServer suspend/resume stress runs, HVM guests lost available memory on every cycle until they stalled. Over 100 suspend/resume cycles the loss scaled with the number of VIFs, on Debian 12 (6.1.0-50) and Ubuntu 26.04 (7.0.0-30) guests alike; the missing unregister was then found by code inspection. Reproducing it needs no kernel modification: suspend and resume a guest repeatedly and compare MemAvailable.
Tested on Debian 12 HVM guests on XenServer 9 (Xen 4.21, AMD EPYC), running two builds of the same 6.1.192 source with and without this patch. Over 100 suspend/resume cycles the unpatched kernel lost 1107 KiB per cycle with one VIF and 2279 KiB with two; the patched kernel lost 51 and 42 KiB. On current mainline the patch builds without warnings at W=1 but was not boot-tested, and kernel selftests were not run.
An AI coding assistant (Claude Code) was used to locate the cause, write the fix and draft this changelog.
--- drivers/net/xen-netfront.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/xen-netfront.c +3 -0
@@ -1860,7 +1860,10 @@ static void xennet_disconnect_backend(struct netfront_info *info) queue->tx.sring =NULL ; queue->rx.sring =NULL ; +if (xdp_rxq_info_is_reg (&queue->xdp_rxq)) +xdp_rxq_info_unreg (&queue->xdp_rxq);page_pool_destroy (queue->page_pool); + queue->page_pool =NULL ; } }
Signature · 1 line
2.56.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] xen-netfront: use-after-free in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] xen-netfront: use-after-free in talk_to_netback() [1] --
commit 28bf900783c8239db158b535f3cda9d162761b0d
Author: Mark Syms <[email protected]>
xen-netfront: unregister the XDP rxq before destroying its page_pool
This commit unregisters each queue's XDP rxq before destroying its page_pool in xennet_disconnect_backend() and clears queue->page_pool so that the pool and its recycled receive buffers are not leaked on backend disconnect.
Quoted 5 lines
drivers/net/xen-netfront.c +0
-0
drivers/net/xen-netfront.c static void xennet_disconnect_backend(struct netfront_info *info) · line 1868
Quoted 9 lines
drivers/net/xen-netfront.c +3
-0@@ -1860,7 +1860,10 @@ static void xennet_disconnect_backend(struct netfront_info *info) queue->tx.sring =NULL ; queue->rx.sring =NULL ; +if (xdp_rxq_info_is_reg (&queue->xdp_rxq)) +xdp_rxq_info_unreg (&queue->xdp_rxq);page_pool_destroy (queue->page_pool); + queue->page_pool =NULL ; } }
[Severity: Critical]
This problem wasn't introduced by this patch, but can talk_to_netback() trigger a use-after-free on info->queues and leak page pools [1] when xennet_create_page_pool() fails on a queue after the first?
In xennet_create_queues(), each initialized queue registers its page_pool and links &queue->napi into netdev->napi_list via netif_napi_add(). If xennet_create_page_pool() fails on a later queue, talk_to_netback() frees info->queues directly without calling xennet_destroy_queues():
drivers/net/xen-netfront.c:xennet_create_queues() {
...
ret = xennet_create_page_pool(queue);
if (ret < 0) {
dev_err(&info->xbdev->dev, "can't allocate page pool\n");
*num_queues = i;
return ret;
}
netif_napi_add(queue->info->netdev, &queue->napi, xennet_poll);
...
}drivers/net/xen-netfront.c:talk_to_netback() {
...
err = xennet_create_queues(info, &num_queues);
if (err < 0) {
xenbus_dev_fatal(dev, err, "creating queues");
kfree(info->queues);
info->queues = NULL;
goto out;
}
...
}The earlier queues' NAPI instances remain on netdev->napi_list after info->queues is freed, causing a use-after-free when netdev->napi_list is later traversed, and their page pools are leaked.
[1] https://sashiko.dev/#/bug/linux-22a8f703-85e5-42c6-864c-250ab284af6d
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Tue, 24 Nov 2026 09:18:06 +0000 you wrote:
Each receive queue registers its
page_poolas the XDP memory model, which takes a second reference on the pool. On disconnect,xennet_disconnect_backend()callspage_pool_destroy()but never unregisters the rxq, so the pool's user count never reaches zero and the pool is never released, together with the receive buffers thatxennet_release_rx_bufs()has just recycled into it. Every suspend/resume or backend reconnect therefore leaks one pool per receive queue. The pool never begins shutdown, so thepage_poolstall warning does not fire and the leak is silent.[...]
Here is the summary with links:
- [net] xen-netfront: unregister the XDP rxq before destroying its page_pool
https://git.kernel.org/netdev/net/c/98a283a1f3d6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html