Skip to content

Commit 51205f8

Browse files
alobakinkuba-moo
authored andcommitted
xsk: make xsk_buff_add_frag() really add the frag via __xdp_buff_add_frag()
Currently, xsk_buff_add_frag() only adds the frag to pool's linked list, not doing anything with the &xdp_buff. The drivers do that manually and the logic is the same. Make it really add an skb frag, just like xdp_buff_add_frag() does that, and freeing frags on error if needed. This allows to remove repeating code from i40e and ice and not add the same code again and again. Acked-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Alexander Lobakin <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 539c1fb commit 51205f8

File tree

3 files changed

+20
-60
lines changed

3 files changed

+20
-60
lines changed

drivers/net/ethernet/intel/i40e/i40e_xsk.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -395,32 +395,6 @@ static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring,
395395
WARN_ON_ONCE(1);
396396
}
397397

398-
static int
399-
i40e_add_xsk_frag(struct i40e_ring *rx_ring, struct xdp_buff *first,
400-
struct xdp_buff *xdp, const unsigned int size)
401-
{
402-
struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(first);
403-
404-
if (!xdp_buff_has_frags(first)) {
405-
sinfo->nr_frags = 0;
406-
sinfo->xdp_frags_size = 0;
407-
xdp_buff_set_frags_flag(first);
408-
}
409-
410-
if (unlikely(sinfo->nr_frags == MAX_SKB_FRAGS)) {
411-
xsk_buff_free(first);
412-
return -ENOMEM;
413-
}
414-
415-
__skb_fill_page_desc_noacc(sinfo, sinfo->nr_frags++,
416-
virt_to_page(xdp->data_hard_start),
417-
XDP_PACKET_HEADROOM, size);
418-
sinfo->xdp_frags_size += size;
419-
xsk_buff_add_frag(xdp);
420-
421-
return 0;
422-
}
423-
424398
/**
425399
* i40e_clean_rx_irq_zc - Consumes Rx packets from the hardware ring
426400
* @rx_ring: Rx ring
@@ -486,8 +460,10 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)
486460

487461
if (!first)
488462
first = bi;
489-
else if (i40e_add_xsk_frag(rx_ring, first, bi, size))
463+
else if (!xsk_buff_add_frag(first, bi)) {
464+
xsk_buff_free(first);
490465
break;
466+
}
491467

492468
if (++next_to_process == count)
493469
next_to_process = 0;

drivers/net/ethernet/intel/ice/ice_xsk.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -801,35 +801,6 @@ ice_run_xdp_zc(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp,
801801
return result;
802802
}
803803

804-
static int
805-
ice_add_xsk_frag(struct ice_rx_ring *rx_ring, struct xdp_buff *first,
806-
struct xdp_buff *xdp, const unsigned int size)
807-
{
808-
struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(first);
809-
810-
if (!size)
811-
return 0;
812-
813-
if (!xdp_buff_has_frags(first)) {
814-
sinfo->nr_frags = 0;
815-
sinfo->xdp_frags_size = 0;
816-
xdp_buff_set_frags_flag(first);
817-
}
818-
819-
if (unlikely(sinfo->nr_frags == MAX_SKB_FRAGS)) {
820-
xsk_buff_free(first);
821-
return -ENOMEM;
822-
}
823-
824-
__skb_fill_page_desc_noacc(sinfo, sinfo->nr_frags++,
825-
virt_to_page(xdp->data_hard_start),
826-
XDP_PACKET_HEADROOM, size);
827-
sinfo->xdp_frags_size += size;
828-
xsk_buff_add_frag(xdp);
829-
830-
return 0;
831-
}
832-
833804
/**
834805
* ice_clean_rx_irq_zc - consumes packets from the hardware ring
835806
* @rx_ring: AF_XDP Rx ring
@@ -895,7 +866,8 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring,
895866

896867
if (!first) {
897868
first = xdp;
898-
} else if (ice_add_xsk_frag(rx_ring, first, xdp, size)) {
869+
} else if (likely(size) && !xsk_buff_add_frag(first, xdp)) {
870+
xsk_buff_free(first);
899871
break;
900872
}
901873

include/net/xdp_sock_drv.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,21 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
136136
xp_free(xskb);
137137
}
138138

139-
static inline void xsk_buff_add_frag(struct xdp_buff *xdp)
139+
static inline bool xsk_buff_add_frag(struct xdp_buff *head,
140+
struct xdp_buff *xdp)
140141
{
141-
struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp);
142+
const void *data = xdp->data;
143+
struct xdp_buff_xsk *frag;
144+
145+
if (!__xdp_buff_add_frag(head, virt_to_netmem(data),
146+
offset_in_page(data), xdp->data_end - data,
147+
xdp->frame_sz, false))
148+
return false;
142149

150+
frag = container_of(xdp, struct xdp_buff_xsk, xdp);
143151
list_add_tail(&frag->list_node, &frag->pool->xskb_list);
152+
153+
return true;
144154
}
145155

146156
static inline struct xdp_buff *xsk_buff_get_frag(const struct xdp_buff *first)
@@ -357,8 +367,10 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
357367
{
358368
}
359369

360-
static inline void xsk_buff_add_frag(struct xdp_buff *xdp)
370+
static inline bool xsk_buff_add_frag(struct xdp_buff *head,
371+
struct xdp_buff *xdp)
361372
{
373+
return false;
362374
}
363375

364376
static inline struct xdp_buff *xsk_buff_get_frag(const struct xdp_buff *first)

0 commit comments

Comments
 (0)