mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
vhost-net: reduce one userspace copy when building XDP buff
We used to do twice copy_from_iter() to copy virtio-net and packet separately. This introduce overheads for userspace access hardening as well as SMAP (for x86 it's stac/clac). So this patch tries to use one copy_from_iter() to copy them once and move the virtio-net header afterwards to reduce overheads. Testpmd + vhost_net shows 10% improvement from 5.45Mpps to 6.0Mpps. Signed-off-by: Jason Wang <jasowang@redhat.com> Link: https://patch.msgid.link/20250701010352.74515-2-jasowang@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
4d313f2bd2
commit
97b2409f28
|
|
@ -690,13 +690,13 @@ static int vhost_net_build_xdp(struct vhost_net_virtqueue *nvq,
|
||||||
if (unlikely(!buf))
|
if (unlikely(!buf))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
copied = copy_from_iter(buf, sock_hlen, from);
|
copied = copy_from_iter(buf + pad - sock_hlen, len, from);
|
||||||
if (copied != sock_hlen) {
|
if (copied != len) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
gso = buf;
|
gso = buf + pad - sock_hlen;
|
||||||
|
|
||||||
if (!sock_hlen)
|
if (!sock_hlen)
|
||||||
memset(buf, 0, pad);
|
memset(buf, 0, pad);
|
||||||
|
|
@ -715,15 +715,11 @@ static int vhost_net_build_xdp(struct vhost_net_virtqueue *nvq,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
len -= sock_hlen;
|
/* pad contains sock_hlen */
|
||||||
copied = copy_from_iter(buf + pad, len, from);
|
memcpy(buf, buf + pad - sock_hlen, sock_hlen);
|
||||||
if (copied != len) {
|
|
||||||
ret = -EFAULT;
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
xdp_init_buff(xdp, buflen, NULL);
|
xdp_init_buff(xdp, buflen, NULL);
|
||||||
xdp_prepare_buff(xdp, buf, pad, len, true);
|
xdp_prepare_buff(xdp, buf, pad, len - sock_hlen, true);
|
||||||
|
|
||||||
++nvq->batched_xdp;
|
++nvq->batched_xdp;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user