Two AF_XDP zero-copy fixes for virtio_net.
Patch 1: on arm64, binding a zero-copy socket fails with -ENOMEM and a
"rejecting DMA map of vmalloc memory" warning whenever the device uses
the DMA API (e.g. VIRTIO_F_ACCESS_PLATFORM), because the static TX
header lives in the kernel image, which arm64 maps in the vmalloc area.
Patch 2: removing XDP, explicitly or when the device is unregistered,
can leave a zero-copy pool bound to a queue above curr_queue_pairs.
Unbinding the socket then fails in the driver, and the queue is
refilled from the freed pool.
The suspend fix that was patch 3 in v2 is dropped from this series.
Review found problems with it for pools on queues above
curr_queue_pairs; it will be reworked and sent separately on top of
these two.
Testing used KASAN kernels in QEMU with virtio-net-pci and
iommu_platform=on:
- Patch 1 on arm64 (TCG, virt): binding an XDP_ZEROCOPY socket fails
without the patch and succeeds with it.
- Patch 2 on x86_64 (KVM, q35, intel-iommu, two queue pairs): with a
socket bound to an XDP queue, removing XDP and then closing the
socket gives "Failed to disable zero-copy!" and a KASAN
use-after-free in xp_alloc_batch() on net, and no warnings with this
series. Unbinding the device from virtio_net with XDP attached and a
socket on an XDP queue gives "Failed to disable zero-copy!" on net,
and no warning with this series. In both cases the unregister then
keeps waiting for eth0 to become free; that also happens with only
XDP attached and no socket, so it is a separate issue.
The issues were found with the help of an AI coding assistant.
Changes in v3:
- Drop patch 3, to be reworked and sent separately (Sashiko).
- Patch 2: mention the unregister path in the changelog (Sashiko).
- Rebased on net 1d5e2c57e9ff; the code of patches 1 and 2 is
unchanged.
Changes in v2:
- Patch 1: drop the sentence about cache lines from the changelog
(Sashiko).
- New patch 2, for a pool left on a queue above curr_queue_pairs
(Sashiko).
- Patch 3: rework (Sashiko).
v2: https://lore.kernel.org/netdev/20261108193845.73621-1-yanhaishuang@cmss.chinamobile.com/ (local)
v1: https://lore.kernel.org/netdev/20261107125723.33547-1-yanhaishuang@cmss.chinamobile.com/ (local)
Haishuang Yan (2):
virtio_net: Don't DMA map the kernel image for the AF_XDP TX header
virtio_net: Disable AF_XDP pools on queues above curr_queue_pairs
drivers/net/virtio_net.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
base-commit: 1d5e2c57e9ffc134e14b3f837c8d7c53b508bd22
--
2.43.0