Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tun: remove unnecessary tun_xdp_hdr structure

With f95f0f95cfb7("net, xdp: Introduce xdp_init_buff utility routine"),
buffer length could be stored as frame size so there's no need to have
a dedicated tun_xdp_hdr structure. We can simply store virtio net
header instead.

Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Link: https://patch.msgid.link/20250701010352.74515-1-jasowang@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jason Wang and committed by
Jakub Kicinski
4d313f2b 285c895f

+6 -17
+2 -3
drivers/net/tap.c
··· 1044 1044 1045 1045 static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) 1046 1046 { 1047 - struct tun_xdp_hdr *hdr = xdp->data_hard_start; 1048 - struct virtio_net_hdr *gso = &hdr->gso; 1049 - int buflen = hdr->buflen; 1047 + struct virtio_net_hdr *gso = xdp->data_hard_start; 1048 + int buflen = xdp->frame_sz; 1050 1049 int vnet_hdr_len = 0; 1051 1050 struct tap_dev *tap; 1052 1051 struct sk_buff *skb;
+2 -3
drivers/net/tun.c
··· 2356 2356 struct tun_page *tpage) 2357 2357 { 2358 2358 unsigned int datasize = xdp->data_end - xdp->data; 2359 - struct tun_xdp_hdr *hdr = xdp->data_hard_start; 2360 - struct virtio_net_hdr *gso = &hdr->gso; 2359 + struct virtio_net_hdr *gso = xdp->data_hard_start; 2361 2360 struct bpf_prog *xdp_prog; 2362 2361 struct sk_buff *skb = NULL; 2363 2362 struct sk_buff_head *queue; 2364 2363 u32 rxhash = 0, act; 2365 - int buflen = hdr->buflen; 2364 + int buflen = xdp->frame_sz; 2366 2365 int metasize = 0; 2367 2366 int ret = 0; 2368 2367 bool skb_xdp = false;
+2 -6
drivers/vhost/net.c
··· 668 668 struct socket *sock = vhost_vq_get_backend(vq); 669 669 struct virtio_net_hdr *gso; 670 670 struct xdp_buff *xdp = &nvq->xdp[nvq->batched_xdp]; 671 - struct tun_xdp_hdr *hdr; 672 671 size_t len = iov_iter_count(from); 673 672 int headroom = vhost_sock_xdp(sock) ? XDP_PACKET_HEADROOM : 0; 674 673 int buflen = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); ··· 690 691 if (unlikely(!buf)) 691 692 return -ENOMEM; 692 693 693 - copied = copy_from_iter(buf + offsetof(struct tun_xdp_hdr, gso), 694 - sock_hlen, from); 694 + copied = copy_from_iter(buf, sock_hlen, from); 695 695 if (copied != sock_hlen) { 696 696 ret = -EFAULT; 697 697 goto err; 698 698 } 699 699 700 - hdr = buf; 701 - gso = &hdr->gso; 700 + gso = buf; 702 701 703 702 if (!sock_hlen) 704 703 memset(buf, 0, pad); ··· 724 727 725 728 xdp_init_buff(xdp, buflen, NULL); 726 729 xdp_prepare_buff(xdp, buf, pad, len, true); 727 - hdr->buflen = buflen; 728 730 729 731 ++nvq->batched_xdp; 730 732
-5
include/linux/if_tun.h
··· 19 19 void *ptr; 20 20 }; 21 21 22 - struct tun_xdp_hdr { 23 - int buflen; 24 - struct virtio_net_hdr gso; 25 - }; 26 - 27 22 #if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE) 28 23 struct socket *tun_get_socket(struct file *); 29 24 struct ptr_ring *tun_get_tx_ring(struct file *file);