From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:19
This is an interpolation of [0] to other Intel Ethernet drivers
(and is (re)based on its code).
The main aim is to keep XDP metadata not only in case with
build_skb(), but also when we do napi_alloc_skb() + memcpy().
All Intel drivers suffers from the same here:
- metadata gets lost on XDP_PASS in legacy-rx;
- excessive headroom allocation on XSK Rx to skbs;
- metadata gets lost on XSK Rx to skbs.
Those get especially actual in XDP Hints upcoming.
I couldn't have addressed the first one for all Intel drivers due to
that they don't reserve any headroom for now in legacy-rx mode even
with XDP enabled. This is hugely wrong, but requires quite a bunch
of work and a separate series. Luckily, ice doesn't suffer from
that.
igc has 1 and 3 already fixed in [0].
From v2 (unreleased upstream):
- tweaked 007 to pass bi->xdp directly and simplify code (Maciej);
- picked Michal's Reviewed-by.
From v1 (unreleased upstream):
- drop "fixes" of legacy-rx for i40e, igb and ixgbe since they have
another flaw regarding headroom (see above);
- drop igc cosmetic fixes since they landed upstream incorporated
into Jesper's commits;
- picked one Acked-by from Maciej.
[0] https://lore.kernel.org/netdev/163700856423.565980.10162564921347693758.stgit@firesoul
Alexander Lobakin (9):
i40e: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
i40e: respect metadata on XSK Rx to skb
ice: respect metadata in legacy-rx/ice_construct_skb()
ice: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
ice: respect metadata on XSK Rx to skb
igc: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
ixgbe: pass bi->xdp to ixgbe_construct_skb_zc() directly
ixgbe: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
i40e: respect metadata on XSK Rx to skb
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 16 +++++++-----
drivers/net/ethernet/intel/ice/ice_txrx.c | 15 ++++++++---
drivers/net/ethernet/intel/ice/ice_xsk.c | 16 +++++++-----
drivers/net/ethernet/intel/igc/igc_main.c | 13 +++++-----
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 27 ++++++++++++--------
5 files changed, 54 insertions(+), 33 deletions(-)
--
Testing hints:
Setup an XDP and AF_XDP program which will prepend metadata at the
front of the frames and return XDP_PASS, then check that metadata
is present after frames reach kernel network stack.
--
2.33.1
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:26
{__,}napi_alloc_skb() allocates and reserves additional NET_SKB_PAD
+ NET_IP_ALIGN for any skb.
OTOH, i40e_construct_skb_zc() currently allocates and reserves
additional `xdp->data - xdp->data_hard_start`, which is
XDP_PACKET_HEADROOM for XSK frames.
There's no need for that at all as the frame is post-XDP and will
go only to the networking stack core.
Pass the size of the actual data only to __napi_alloc_skb() and
don't reserve anything. This will give enough headroom for stack
processing.
Fixes: 0a714186d3c0 ("i40e: add AF_XDP zero-copy Rx support")
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
@@ -245,13 +245,11 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring,structsk_buff*skb;/* allocate a skb to store the frags */-skb=__napi_alloc_skb(&rx_ring->q_vector->napi,-xdp->data_end-xdp->data_hard_start,+skb=__napi_alloc_skb(&rx_ring->q_vector->napi,datasize,GFP_ATOMIC|__GFP_NOWARN);if(unlikely(!skb))gotoout;-skb_reserve(skb,xdp->data-xdp->data_hard_start);memcpy(__skb_put(skb,datasize),xdp->data,datasize);if(metasize)skb_metadata_set(skb,metasize);
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:30
In "legacy-rx" mode represented by ice_construct_skb(), we can
still use XDP (and XDP metadata), but after XDP_PASS the metadata
will be lost as it doesn't get copied to the skb.
Copy it along with the frame headers. Account its size on skb
allocation, and when copying just treat it as a part of the frame
and do a pull after to "move" it to the "reserved" zone.
Point net_prefetch() to xdp->data_meta instead of data. This won't
change anything when the meta is not here, but will save some cache
misses otherwise.
Suggested-by: Jesper Dangaard Brouer <redacted>
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/ice/ice_txrx.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
@@ -968,15 +968,17 @@ static struct sk_buff *ice_construct_skb(structice_rx_ring*rx_ring,structice_rx_buf*rx_buf,structxdp_buff*xdp){+unsignedintmetasize=xdp->data-xdp->data_meta;unsignedintsize=xdp->data_end-xdp->data;unsignedintheadlen;structsk_buff*skb;/* prefetch first cache line of first page */-net_prefetch(xdp->data);+net_prefetch(xdp->data_meta);/* allocate a skb to store the frags */-skb=__napi_alloc_skb(&rx_ring->q_vector->napi,ICE_RX_HDR_SIZE,+skb=__napi_alloc_skb(&rx_ring->q_vector->napi,+ICE_RX_HDR_SIZE+metasize,GFP_ATOMIC|__GFP_NOWARN);if(unlikely(!skb))returnNULL;
@@ -988,8 +990,13 @@ ice_construct_skb(struct ice_rx_ring *rx_ring, struct ice_rx_buf *rx_buf,headlen=eth_get_headlen(skb->dev,xdp->data,ICE_RX_HDR_SIZE);/* align pull length to size of long to optimize memcpy performance */-memcpy(__skb_put(skb,headlen),xdp->data,ALIGN(headlen,-sizeof(long)));+memcpy(__skb_put(skb,headlen+metasize),xdp->data_meta,+ALIGN(headlen+metasize,sizeof(long)));++if(metasize){+skb_metadata_set(skb,metasize);+__skb_pull(skb,metasize);+}/* if we exhaust the linear part then add what is left as a frag */size-=headlen;
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:33
For now, if the XDP prog returns XDP_PASS on XSK, the metadata will
be lost as it doesn't get copied to the skb.
Copy it along with the frame headers. Account its size on skb
allocation, and when copying just treat it as a part of the frame
and do a pull after to "move" it to the "reserved" zone.
net_prefetch() xdp->data_meta and align the copy size to speed-up
memcpy() a little and better match ice_costruct_skb().
Fixes: 2d4238f55697 ("ice: Add support for AF_XDP")
Suggested-by: Jesper Dangaard Brouer <redacted>
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/ice/ice_xsk.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:35
For now, if the XDP prog returns XDP_PASS on XSK, the metadata will
be lost as it doesn't get copied to the skb.
Copy it along with the frame headers. Account its size on skb
allocation, and when copying just treat it as a part of the frame
and do a pull after to "move" it to the "reserved" zone.
net_prefetch() xdp->data_meta and align the copy size to speed-up
memcpy() a little and better match i40e_costruct_skb().
Fixes: 0a714186d3c0 ("i40e: add AF_XDP zero-copy Rx support")
Suggested-by: Jesper Dangaard Brouer <redacted>
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
@@ -240,19 +240,25 @@ bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count)staticstructsk_buff*i40e_construct_skb_zc(structi40e_ring*rx_ring,structxdp_buff*xdp){+unsignedinttotalsize=xdp->data_end-xdp->data_meta;unsignedintmetasize=xdp->data-xdp->data_meta;-unsignedintdatasize=xdp->data_end-xdp->data;structsk_buff*skb;+net_prefetch(xdp->data_meta);+/* allocate a skb to store the frags */-skb=__napi_alloc_skb(&rx_ring->q_vector->napi,datasize,+skb=__napi_alloc_skb(&rx_ring->q_vector->napi,totalsize,GFP_ATOMIC|__GFP_NOWARN);if(unlikely(!skb))gotoout;-memcpy(__skb_put(skb,datasize),xdp->data,datasize);-if(metasize)+memcpy(__skb_put(skb,totalsize),xdp->data_meta,+ALIGN(totalsize,sizeof(long)));++if(metasize){skb_metadata_set(skb,metasize);+__skb_pull(skb,metasize);+}out:xsk_buff_free(xdp);
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:38
To not dereference bi->xdp each time in ixgbe_construct_skb_zc(),
pass bi->xdp as an argument instead of bi. We can also call
xsk_buff_free() outside of the function as well as assign bi->xdp
to NULL, which seems to make it closer to its name.
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexander Lobakin <redacted>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
@@ -207,26 +207,24 @@ bool ixgbe_alloc_rx_buffers_zc(struct ixgbe_ring *rx_ring, u16 count)}staticstructsk_buff*ixgbe_construct_skb_zc(structixgbe_ring*rx_ring,-structixgbe_rx_buffer*bi)+conststructxdp_buff*xdp){-unsignedintmetasize=bi->xdp->data-bi->xdp->data_meta;-unsignedintdatasize=bi->xdp->data_end-bi->xdp->data;+unsignedintmetasize=xdp->data-xdp->data_meta;+unsignedintdatasize=xdp->data_end-xdp->data;structsk_buff*skb;/* allocate a skb to store the frags */skb=__napi_alloc_skb(&rx_ring->q_vector->napi,-bi->xdp->data_end-bi->xdp->data_hard_start,+xdp->data_end-xdp->data_hard_start,GFP_ATOMIC|__GFP_NOWARN);if(unlikely(!skb))returnNULL;-skb_reserve(skb,bi->xdp->data-bi->xdp->data_hard_start);-memcpy(__skb_put(skb,datasize),bi->xdp->data,datasize);+skb_reserve(skb,xdp->data-xdp->data_hard_start);+memcpy(__skb_put(skb,datasize),xdp->data,datasize);if(metasize)skb_metadata_set(skb,metasize);-xsk_buff_free(bi->xdp);-bi->xdp=NULL;returnskb;}
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:40
{__,}napi_alloc_skb() allocates and reserves additional NET_SKB_PAD
+ NET_IP_ALIGN for any skb.
OTOH, ixgbe_construct_skb_zc() currently allocates and reserves
additional `xdp->data - xdp->data_hard_start`, which is
XDP_PACKET_HEADROOM for XSK frames.
There's no need for that at all as the frame is post-XDP and will
go only to the networking stack core.
Pass the size of the actual data only to __napi_alloc_skb() and
don't reserve anything. This will give enough headroom for stack
processing.
Fixes: d0bcacd0a130 ("ixgbe: add AF_XDP zero-copy Rx support")
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
@@ -214,13 +214,11 @@ static struct sk_buff *ixgbe_construct_skb_zc(struct ixgbe_ring *rx_ring,structsk_buff*skb;/* allocate a skb to store the frags */-skb=__napi_alloc_skb(&rx_ring->q_vector->napi,-xdp->data_end-xdp->data_hard_start,+skb=__napi_alloc_skb(&rx_ring->q_vector->napi,datasize,GFP_ATOMIC|__GFP_NOWARN);if(unlikely(!skb))returnNULL;-skb_reserve(skb,xdp->data-xdp->data_hard_start);memcpy(__skb_put(skb,datasize),xdp->data,datasize);if(metasize)skb_metadata_set(skb,metasize);
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:43
For now, if the XDP prog returns XDP_PASS on XSK, the metadata will
be lost as it doesn't get copied to the skb.
Copy it along with the frame headers. Account its size on skb
allocation, and when copying just treat it as a part of the frame
and do a pull after to "move" it to the "reserved" zone.
net_prefetch() xdp->data_meta and align the copy size to speed-up
memcpy() a little and better match ixgbee_costruct_skb().
Fixes: d0bcacd0a130 ("ixgbe: add AF_XDP zero-copy Rx support")
Suggested-by: Jesper Dangaard Brouer <redacted>
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
@@ -209,19 +209,25 @@ bool ixgbe_alloc_rx_buffers_zc(struct ixgbe_ring *rx_ring, u16 count)staticstructsk_buff*ixgbe_construct_skb_zc(structixgbe_ring*rx_ring,conststructxdp_buff*xdp){+unsignedinttotalsize=xdp->data_end-xdp->data_meta;unsignedintmetasize=xdp->data-xdp->data_meta;-unsignedintdatasize=xdp->data_end-xdp->data;structsk_buff*skb;+net_prefetch(xdp->data_meta);+/* allocate a skb to store the frags */-skb=__napi_alloc_skb(&rx_ring->q_vector->napi,datasize,+skb=__napi_alloc_skb(&rx_ring->q_vector->napi,totalsize,GFP_ATOMIC|__GFP_NOWARN);if(unlikely(!skb))returnNULL;-memcpy(__skb_put(skb,datasize),xdp->data,datasize);-if(metasize)+memcpy(__skb_put(skb,totalsize),xdp->data_meta,+ALIGN(totalsize,sizeof(long)));++if(metasize){skb_metadata_set(skb,metasize);+__skb_pull(skb,metasize);+}returnskb;}
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:56:44
{__,}napi_alloc_skb() allocates and reserves additional NET_SKB_PAD
+ NET_IP_ALIGN for any skb.
OTOH, igc_construct_skb_zc() currently allocates and reserves
additional `xdp->data_meta - xdp->data_hard_start`, which is about
XDP_PACKET_HEADROOM for XSK frames.
There's no need for that at all as the frame is post-XDP and will
go only to the networking stack core.
Pass the size of the actual data only (+ meta) to
__napi_alloc_skb() and don't reserve anything. This will give
enough headroom for stack processing.
Also, net_prefetch() xdp->data_meta and align the copy size to
speed-up memcpy() a little and better match igc_costruct_skb().
Fixes: fc9df2a0b520 ("igc: Enable RX via AF_XDP zero-copy")
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/igc/igc_main.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
From: Alexander Lobakin <hidden> Date: 2021-12-07 20:57:00
{__,}napi_alloc_skb() allocates and reserves additional NET_SKB_PAD
+ NET_IP_ALIGN for any skb.
OTOH, ice_construct_skb_zc() currently allocates and reserves
additional `xdp->data - xdp->data_hard_start`, which is
XDP_PACKET_HEADROOM for XSK frames.
There's no need for that at all as the frame is post-XDP and will
go only to the networking stack core.
Pass the size of the actual data only to __napi_alloc_skb() and
don't reserve anything. This will give enough headroom for stack
processing.
Fixes: 2d4238f55697 ("ice: Add support for AF_XDP")
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/ice/ice_xsk.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
For now, if the XDP prog returns XDP_PASS on XSK, the metadata will
be lost as it doesn't get copied to the skb.
Copy it along with the frame headers. Account its size on skb
allocation, and when copying just treat it as a part of the frame
and do a pull after to "move" it to the "reserved" zone.
net_prefetch() xdp->data_meta and align the copy size to speed-up
memcpy() a little and better match ixgbee_costruct_skb().
-----Original Message-----
From: Intel-wired-lan <redacted> On Behalf Of
Lobakin, Alexandr
Sent: Wednesday, December 8, 2021 2:25 AM
To: intel-wired-lan@lists.osuosl.org
Cc: Andre Guedes <redacted>; Jesper Dangaard Brouer
[off-list ref]; Daniel Borkmann [off-list ref];
netdev@vger.kernel.org; Krzysztof Kazimierczak
[off-list ref]; bpf@vger.kernel.org; John Fastabend
[off-list ref]; Alexei Starovoitov [off-list ref]; Brouer,
Jesper [off-list ref]; Björn Töpel [off-list ref]; Jeff Kirsher
[off-list ref]; Jakub Kicinski [off-list ref]; linux-
kernel@vger.kernel.org; David S. Miller [off-list ref]; Vedang
Patel [off-list ref]
Subject: [Intel-wired-lan] [PATCH v3 net-next 2/9] i40e: respect metadata on
XSK Rx to skb
For now, if the XDP prog returns XDP_PASS on XSK, the metadata will be lost
as it doesn't get copied to the skb.
Copy it along with the frame headers. Account its size on skb allocation, and
when copying just treat it as a part of the frame and do a pull after to "move"
it to the "reserved" zone.
net_prefetch() xdp->data_meta and align the copy size to speed-up
memcpy() a little and better match i40e_costruct_skb().
Fixes: 0a714186d3c0 ("i40e: add AF_XDP zero-copy Rx support")
Suggested-by: Jesper Dangaard Brouer <redacted>
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexander Lobakin <redacted>
Reviewed-by: Michal Swiatkowski <redacted>
---
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
Tested-by: Kiran Bhandare <redacted> A Contingent Worker at Intel