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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. commit 5142239a22219921a7863cf00c9ab853c00689d8
  2. Author: Lorenzo Bianconi <[email protected]>
  3. Date: Fri Mar 11 10:14:18 2022 +0100
  4. 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. --- a/drivers/net/veth.c
  17. +++ b/drivers/net/veth.c
  18. @@ -501,7 +501,7 @@ static int veth_xdp_xmit(struct net_devi
  19. struct xdp_frame *frame = frames[i];
  20. void *ptr = veth_xdp_to_ptr(frame);
  21. - if (unlikely(frame->len > max_len ||
  22. + if (unlikely(xdp_get_frame_len(frame) > max_len ||
  23. __ptr_ring_produce(&rq->xdp_ring, ptr)))
  24. break;
  25. nxmit++;
  26. @@ -862,7 +862,7 @@ static int veth_xdp_rcv(struct veth_rq *
  27. /* ndo_xdp_xmit */
  28. struct xdp_frame *frame = veth_ptr_to_xdp(ptr);
  29. - stats->xdp_bytes += frame->len;
  30. + stats->xdp_bytes += xdp_get_frame_len(frame);
  31. frame = veth_xdp_rcv_one(rq, frame, bq, stats);
  32. if (frame) {
  33. /* XDP_PASS */
  34. --- a/include/net/xdp.h
  35. +++ b/include/net/xdp.h
  36. @@ -295,6 +295,20 @@ out:
  37. __xdp_release_frame(xdpf->data, mem);
  38. }
  39. +static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf)
  40. +{
  41. + struct skb_shared_info *sinfo;
  42. + unsigned int len = xdpf->len;
  43. +
  44. + if (likely(!xdp_frame_has_frags(xdpf)))
  45. + goto out;
  46. +
  47. + sinfo = xdp_get_shared_info_from_frame(xdpf);
  48. + len += sinfo->xdp_frags_size;
  49. +out:
  50. + return len;
  51. +}
  52. +
  53. int xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
  54. struct net_device *dev, u32 queue_index, unsigned int napi_id);
  55. void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq);