]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
virtio_net: add page_pool support for buffer allocation
authorVishwanath Seshagiri <vishs@meta.com>
Tue, 10 Mar 2026 18:31:04 +0000 (11:31 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 17 Mar 2026 02:19:39 +0000 (19:19 -0700)
commit24fbd3967f3fdaad5f93e0d35ae870ed25fb2c3a
treef43d84cc5865cfa90729f203e55001c76122e208
parent5446b8691eb8278f10deca92048fad84ffd1e4d5
virtio_net: add page_pool support for buffer allocation

Use page_pool for RX buffer allocation in mergeable and small buffer
modes to enable page recycling and avoid repeated page allocator calls.
skb_mark_for_recycle() enables page reuse in the network stack.

Big packets mode is unchanged because it uses page->private for linked
list chaining of multiple pages per buffer, which conflicts with
page_pool's internal use of page->private.

Implement conditional DMA premapping using virtqueue_dma_dev():
- When non-NULL (vhost, virtio-pci): use PP_FLAG_DMA_MAP with page_pool
  handling DMA mapping, submit via virtqueue_add_inbuf_premapped()
- When NULL (VDUSE, direct physical): page_pool handles allocation only,
  submit via virtqueue_add_inbuf_ctx()

This preserves the DMA premapping optimization from commit 31f3cd4e5756b
("virtio-net: rq submits premapped per-buffer") while adding page_pool
support as a prerequisite for future zero-copy features (devmem TCP,
io_uring ZCRX).

Page pools are created in probe and destroyed in remove (not open/close),
following existing driver behavior where RX buffers remain in virtqueues
across interface state changes.

Signed-off-by: Vishwanath Seshagiri <vishs@meta.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20260310183107.2822016-1-vishs@meta.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/Kconfig
drivers/net/virtio_net.c