608-v5.18-net-veth-Account-total-xdp_frame-len-running-ndo_xdp.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. From 5142239a22219921a7863cf00c9ab853c00689d8 Mon Sep 17 00:00:00 2001
  2. From: Lorenzo Bianconi <[email protected]>
  3. Date: Fri, 11 Mar 2022 10:14:18 +0100
  4. Subject: [PATCH] net: veth: Account total xdp_frame len running ndo_xdp_xmit
  5. Even if this is a theoretical issue since it is not possible to perform
  6. XDP_REDIRECT on a non-linear xdp_frame, veth driver does not account
  7. paged area in ndo_xdp_xmit function pointer.
  8. Introduce xdp_get_frame_len utility routine to get the xdp_frame full
  9. length and account total frame size running XDP_REDIRECT of a
  10. non-linear xdp frame into a veth device.
  11. Signed-off-by: Lorenzo Bianconi <[email protected]>
  12. Signed-off-by: Daniel Borkmann <[email protected]>
  13. Acked-by: Toke Hoiland-Jorgensen <[email protected]>
  14. Acked-by: John Fastabend <[email protected]>
  15. Link: https://lore.kernel.org/bpf/54f9fd3bb65d190daf2c0bbae2f852ff16cfbaa0.1646989407.git.lorenzo@kernel.org
  16. ---
  17. drivers/net/veth.c | 4 ++--
  18. include/net/xdp.h | 14 ++++++++++++++
  19. 2 files changed, 16 insertions(+), 2 deletions(-)
  20. --- a/drivers/net/veth.c
  21. +++ b/drivers/net/veth.c
  22. @@ -501,7 +501,7 @@ static int veth_xdp_xmit(struct net_devi
  23. struct xdp_frame *frame = frames[i];
  24. void *ptr = veth_xdp_to_ptr(frame);
  25. - if (unlikely(frame->len > max_len ||
  26. + if (unlikely(xdp_get_frame_len(frame) > max_len ||
  27. __ptr_ring_produce(&rq->xdp_ring, ptr)))
  28. break;
  29. nxmit++;
  30. @@ -862,7 +862,7 @@ static int veth_xdp_rcv(struct veth_rq *
  31. /* ndo_xdp_xmit */
  32. struct xdp_frame *frame = veth_ptr_to_xdp(ptr);
  33. - stats->xdp_bytes += frame->len;
  34. + stats->xdp_bytes += xdp_get_frame_len(frame);
  35. frame = veth_xdp_rcv_one(rq, frame, bq, stats);
  36. if (frame) {
  37. /* XDP_PASS */
  38. --- a/include/net/xdp.h
  39. +++ b/include/net/xdp.h
  40. @@ -295,6 +295,20 @@ out:
  41. __xdp_release_frame(xdpf->data, mem);
  42. }
  43. +static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf)
  44. +{
  45. + struct skb_shared_info *sinfo;
  46. + unsigned int len = xdpf->len;
  47. +
  48. + if (likely(!xdp_frame_has_frags(xdpf)))
  49. + goto out;
  50. +
  51. + sinfo = xdp_get_shared_info_from_frame(xdpf);
  52. + len += sinfo->xdp_frags_size;
  53. +out:
  54. + return len;
  55. +}
  56. +
  57. int xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
  58. struct net_device *dev, u32 queue_index, unsigned int napi_id);
  59. void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq);