Skip to content

Commit

Permalink
net: ethernet: enetc: do not always access skb_shared_info in the XDP…
Browse files Browse the repository at this point in the history
… path

Move XDP skb_shared_info structure initialization in from
enetc_map_rx_buff_to_xdp() to enetc_add_rx_buff_to_xdp() and do not always
access skb_shared_info in the xdp_buff/xdp_frame since it is located in a
different cacheline with respect to hard_start and data xdp pointers.
Rely on XDP_FLAGS_HAS_FRAGS flag to check if it really necessary to access
non-linear part of the xdp_buff/xdp_frame.

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Lorenzo Bianconi authored and Jakub Kicinski committed Jan 6, 2023
1 parent 59cc773 commit c7030d1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/net/ethernet/freescale/enetc/enetc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,10 @@ static int enetc_xdp_frame_to_xdp_tx_swbd(struct enetc_bdr *tx_ring,
xdp_tx_swbd->xdp_frame = NULL;

n++;

if (!xdp_frame_has_frags(xdp_frame))
goto out;

xdp_tx_swbd = &xdp_tx_arr[n];

shinfo = xdp_get_shared_info_from_frame(xdp_frame);
Expand Down Expand Up @@ -1334,7 +1338,7 @@ static int enetc_xdp_frame_to_xdp_tx_swbd(struct enetc_bdr *tx_ring,
n++;
xdp_tx_swbd = &xdp_tx_arr[n];
}

out:
xdp_tx_arr[n - 1].is_eof = true;
xdp_tx_arr[n - 1].xdp_frame = xdp_frame;

Expand Down Expand Up @@ -1390,38 +1394,36 @@ static void enetc_map_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
{
struct enetc_rx_swbd *rx_swbd = enetc_get_rx_buff(rx_ring, i, size);
void *hard_start = page_address(rx_swbd->page) + rx_swbd->page_offset;
struct skb_shared_info *shinfo;

/* To be used for XDP_TX */
rx_swbd->len = size;

xdp_prepare_buff(xdp_buff, hard_start - rx_ring->buffer_offset,
rx_ring->buffer_offset, size, false);

shinfo = xdp_get_shared_info_from_buff(xdp_buff);
shinfo->nr_frags = 0;
}

static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
u16 size, struct xdp_buff *xdp_buff)
{
struct skb_shared_info *shinfo = xdp_get_shared_info_from_buff(xdp_buff);
struct enetc_rx_swbd *rx_swbd = enetc_get_rx_buff(rx_ring, i, size);
skb_frag_t *frag = &shinfo->frags[shinfo->nr_frags];
skb_frag_t *frag;

/* To be used for XDP_TX */
rx_swbd->len = size;

if (!xdp_buff_has_frags(xdp_buff)) {
xdp_buff_set_frags_flag(xdp_buff);
shinfo->xdp_frags_size = size;
shinfo->nr_frags = 0;
} else {
shinfo->xdp_frags_size += size;
}

if (page_is_pfmemalloc(rx_swbd->page))
xdp_buff_set_frag_pfmemalloc(xdp_buff);

frag = &shinfo->frags[shinfo->nr_frags];
skb_frag_off_set(frag, rx_swbd->page_offset);
skb_frag_size_set(frag, size);
__skb_frag_set_page(frag, rx_swbd->page);
Expand Down

0 comments on commit c7030d1

Please sign in to comment.