605-v5.18-xdp-introduce-flags-field-in-xdp_buff-xdp_frame.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. commit 2e88d4ff03013937028f5397268b21e10cf68713
  2. Author: Lorenzo Bianconi <[email protected]>
  3. Date: Fri Jan 21 11:09:45 2022 +0100
  4. xdp: introduce flags field in xdp_buff/xdp_frame
  5. Introduce flags field in xdp_frame and xdp_buffer data structures
  6. to define additional buffer features. At the moment the only
  7. supported buffer feature is frags bit (XDP_FLAGS_HAS_FRAGS).
  8. frags bit is used to specify if this is a linear buffer
  9. (XDP_FLAGS_HAS_FRAGS not set) or a frags frame (XDP_FLAGS_HAS_FRAGS
  10. set). In the latter case the driver is expected to initialize the
  11. skb_shared_info structure at the end of the first buffer to link together
  12. subsequent buffers belonging to the same frame.
  13. Acked-by: Toke Hoiland-Jorgensen <[email protected]>
  14. Acked-by: John Fastabend <[email protected]>
  15. Acked-by: Jesper Dangaard Brouer <[email protected]>
  16. Signed-off-by: Lorenzo Bianconi <[email protected]>
  17. Link: https://lore.kernel.org/r/e389f14f3a162c0a5bc6a2e1aa8dd01a90be117d.1642758637.git.lorenzo@kernel.org
  18. Signed-off-by: Alexei Starovoitov <[email protected]>
  19. --- a/include/net/xdp.h
  20. +++ b/include/net/xdp.h
  21. @@ -66,6 +66,10 @@ struct xdp_txq_info {
  22. struct net_device *dev;
  23. };
  24. +enum xdp_buff_flags {
  25. + XDP_FLAGS_HAS_FRAGS = BIT(0), /* non-linear xdp buff */
  26. +};
  27. +
  28. struct xdp_buff {
  29. void *data;
  30. void *data_end;
  31. @@ -74,13 +78,30 @@ struct xdp_buff {
  32. struct xdp_rxq_info *rxq;
  33. struct xdp_txq_info *txq;
  34. u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
  35. + u32 flags; /* supported values defined in xdp_buff_flags */
  36. };
  37. +static __always_inline bool xdp_buff_has_frags(struct xdp_buff *xdp)
  38. +{
  39. + return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
  40. +}
  41. +
  42. +static __always_inline void xdp_buff_set_frags_flag(struct xdp_buff *xdp)
  43. +{
  44. + xdp->flags |= XDP_FLAGS_HAS_FRAGS;
  45. +}
  46. +
  47. +static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)
  48. +{
  49. + xdp->flags &= ~XDP_FLAGS_HAS_FRAGS;
  50. +}
  51. +
  52. static __always_inline void
  53. xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
  54. {
  55. xdp->frame_sz = frame_sz;
  56. xdp->rxq = rxq;
  57. + xdp->flags = 0;
  58. }
  59. static __always_inline void
  60. @@ -122,8 +143,14 @@ struct xdp_frame {
  61. */
  62. struct xdp_mem_info mem;
  63. struct net_device *dev_rx; /* used by cpumap */
  64. + u32 flags; /* supported values defined in xdp_buff_flags */
  65. };
  66. +static __always_inline bool xdp_frame_has_frags(struct xdp_frame *frame)
  67. +{
  68. + return !!(frame->flags & XDP_FLAGS_HAS_FRAGS);
  69. +}
  70. +
  71. #define XDP_BULK_QUEUE_SIZE 16
  72. struct xdp_frame_bulk {
  73. int count;
  74. @@ -180,6 +207,7 @@ void xdp_convert_frame_to_buff(struct xd
  75. xdp->data_end = frame->data + frame->len;
  76. xdp->data_meta = frame->data - frame->metasize;
  77. xdp->frame_sz = frame->frame_sz;
  78. + xdp->flags = frame->flags;
  79. }
  80. static inline
  81. @@ -206,6 +234,7 @@ int xdp_update_frame_from_buff(struct xd
  82. xdp_frame->headroom = headroom - sizeof(*xdp_frame);
  83. xdp_frame->metasize = metasize;
  84. xdp_frame->frame_sz = xdp->frame_sz;
  85. + xdp_frame->flags = xdp->flags;
  86. return 0;
  87. }