Message ID | 20230615172606.349557-2-maciej.fijalkowski@intel.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | xsk: multi-buffer support | expand |
On 2023-06-15 19:25 +0200, Maciej Fijalkowski wrote: > From: Tirthendu Sarkar <tirthendu.sarkar@intel.com> > > Use the 'options' field in xdp_desc as a packet continuity marker. Since > 'options' field was unused till now and was expected to be set to 0, the > 'eop' descriptor will have it set to 0, while the non-eop descriptors > will have to set it to 1. This ensures legacy applications continue to > work without needing any change for single-buffer packets. > > Add helper functions and extend xskq_prod_reserve_desc() to use the > 'options' field. > > Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com> > --- > include/uapi/linux/if_xdp.h | 7 +++++++ > net/xdp/xsk.c | 8 ++++---- > net/xdp/xsk_queue.h | 12 +++++++++--- > 3 files changed, 20 insertions(+), 7 deletions(-) > [...] > diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h > index 6d40a77fccbe..ad81b19e6fdf 100644 > --- a/net/xdp/xsk_queue.h > +++ b/net/xdp/xsk_queue.h > @@ -130,6 +130,11 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) > return false; > } > > +static inline bool xp_unused_options_set(u16 options) ^ To match struct xdp_desc, this should be u32, no?
On Thu, Jun 22, 2023 at 03:02:21PM -0400, Benjamin Poirier wrote: > On 2023-06-15 19:25 +0200, Maciej Fijalkowski wrote: > > From: Tirthendu Sarkar <tirthendu.sarkar@intel.com> > > > > Use the 'options' field in xdp_desc as a packet continuity marker. Since > > 'options' field was unused till now and was expected to be set to 0, the > > 'eop' descriptor will have it set to 0, while the non-eop descriptors > > will have to set it to 1. This ensures legacy applications continue to > > work without needing any change for single-buffer packets. > > > > Add helper functions and extend xskq_prod_reserve_desc() to use the > > 'options' field. > > > > Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com> > > --- > > include/uapi/linux/if_xdp.h | 7 +++++++ > > net/xdp/xsk.c | 8 ++++---- > > net/xdp/xsk_queue.h | 12 +++++++++--- > > 3 files changed, 20 insertions(+), 7 deletions(-) > > > [...] > > diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h > > index 6d40a77fccbe..ad81b19e6fdf 100644 > > --- a/net/xdp/xsk_queue.h > > +++ b/net/xdp/xsk_queue.h > > @@ -130,6 +130,11 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) > > return false; > > } > > > > +static inline bool xp_unused_options_set(u16 options) > ^ > To match struct xdp_desc, this should be u32, no? Of course. Good catch. It's going to be fixed in next revision.
diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h index a78a8096f4ce..434f313dc26c 100644 --- a/include/uapi/linux/if_xdp.h +++ b/include/uapi/linux/if_xdp.h @@ -108,4 +108,11 @@ struct xdp_desc { /* UMEM descriptor is __u64 */ +/* Flag indicating that the packet continues with the buffer pointed out by the + * next frame in the ring. The end of the packet is signalled by setting this + * bit to zero. For single buffer packets, every descriptor has 'options' set + * to 0 and this maintains backward compatibility. + */ +#define XDP_PKT_CONTD (1 << 0) + #endif /* _LINUX_IF_XDP_H */ diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index cc1e7f15fa73..99f90a0d04ae 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -135,14 +135,14 @@ int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool, return 0; } -static int __xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len) +static int __xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len, u32 flags) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); u64 addr; int err; addr = xp_get_handle(xskb); - err = xskq_prod_reserve_desc(xs->rx, addr, len); + err = xskq_prod_reserve_desc(xs->rx, addr, len, flags); if (err) { xs->rx_queue_full++; return err; @@ -189,7 +189,7 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) } xsk_copy_xdp(xsk_xdp, xdp, len); - err = __xsk_rcv_zc(xs, xsk_xdp, len); + err = __xsk_rcv_zc(xs, xsk_xdp, len, 0); if (err) { xsk_buff_free(xsk_xdp); return err; @@ -259,7 +259,7 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL) { len = xdp->data_end - xdp->data; - return __xsk_rcv_zc(xs, xdp, len); + return __xsk_rcv_zc(xs, xdp, len, 0); } err = __xsk_rcv(xs, xdp); diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index 6d40a77fccbe..ad81b19e6fdf 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -130,6 +130,11 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) return false; } +static inline bool xp_unused_options_set(u16 options) +{ + return options & ~XDP_PKT_CONTD; +} + static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) { @@ -141,7 +146,7 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, if (desc->addr >= pool->addrs_cnt) return false; - if (desc->options) + if (xp_unused_options_set(desc->options)) return false; return true; } @@ -158,7 +163,7 @@ static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool, xp_desc_crosses_non_contig_pg(pool, addr, desc->len)) return false; - if (desc->options) + if (xp_unused_options_set(desc->options)) return false; return true; } @@ -360,7 +365,7 @@ static inline void xskq_prod_write_addr_batch(struct xsk_queue *q, struct xdp_de } static inline int xskq_prod_reserve_desc(struct xsk_queue *q, - u64 addr, u32 len) + u64 addr, u32 len, u32 flags) { struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring; u32 idx; @@ -372,6 +377,7 @@ static inline int xskq_prod_reserve_desc(struct xsk_queue *q, idx = q->cached_prod++ & q->ring_mask; ring->desc[idx].addr = addr; ring->desc[idx].len = len; + ring->desc[idx].options = flags; return 0; }