netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers
@ 2023-01-04 13:57 Lorenzo Bianconi
  2023-01-04 13:57 ` [PATCH v2 net-next 1/3] net: ethernet: " Lorenzo Bianconi
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Lorenzo Bianconi @ 2023-01-04 13:57 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, lorenzo.bianconi, vladimir.oltean,
	claudiu.manoil

Unlock XDP_REDIRECT for S/G XDP buffer and rely on XDP stack to properly
take care of the frames.
Rely on XDP_FLAGS_HAS_FRAGS flag to check if it really necessary to access
non-linear part of the xdp_buff/xdp_frame.

Changes since v1:
- rebase on top of net-next

Lorenzo Bianconi (3):
  net: ethernet: enetc: unlock XDP_REDIRECT for XDP non-linear buffers
  net: ethernet: enetc: get rid of xdp_redirect_sg counter
  net: ethernet: enetc: do not always access skb_shared_info in the XDP
    path

 drivers/net/ethernet/freescale/enetc/enetc.c  | 38 +++++++++----------
 drivers/net/ethernet/freescale/enetc/enetc.h  |  1 -
 .../ethernet/freescale/enetc/enetc_ethtool.c  |  2 -
 3 files changed, 18 insertions(+), 23 deletions(-)

-- 
2.39.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 net-next 1/3] net: ethernet: enetc: unlock XDP_REDIRECT for XDP non-linear buffers
  2023-01-04 13:57 [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers Lorenzo Bianconi
@ 2023-01-04 13:57 ` Lorenzo Bianconi
  2023-01-05  9:07   ` Leon Romanovsky
  2023-01-04 13:57 ` [PATCH v2 net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter Lorenzo Bianconi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Lorenzo Bianconi @ 2023-01-04 13:57 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, lorenzo.bianconi, vladimir.oltean,
	claudiu.manoil

Even if full XDP_REDIRECT is not supported yet for non-linear XDP buffers
since we allow redirecting just into CPUMAPs, unlock XDP_REDIRECT for
S/G XDP buffer and rely on XDP stack to properly take care of the
frames.

Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/freescale/enetc/enetc.c | 24 ++++++++------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 3a79ead5219a..18a01f6282b6 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1412,6 +1412,16 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
 	/* 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;
+	} else {
+		shinfo->xdp_frags_size += size;
+	}
+
+	if (page_is_pfmemalloc(rx_swbd->page))
+		xdp_buff_set_frag_pfmemalloc(xdp_buff);
+
 	skb_frag_off_set(frag, rx_swbd->page_offset);
 	skb_frag_size_set(frag, size);
 	__skb_frag_set_page(frag, rx_swbd->page);
@@ -1584,20 +1594,6 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,
 			}
 			break;
 		case XDP_REDIRECT:
-			/* xdp_return_frame does not support S/G in the sense
-			 * that it leaks the fragments (__xdp_return should not
-			 * call page_frag_free only for the initial buffer).
-			 * Until XDP_REDIRECT gains support for S/G let's keep
-			 * the code structure in place, but dead. We drop the
-			 * S/G frames ourselves to avoid memory leaks which
-			 * would otherwise leave the kernel OOM.
-			 */
-			if (unlikely(cleaned_cnt - orig_cleaned_cnt != 1)) {
-				enetc_xdp_drop(rx_ring, orig_i, i);
-				rx_ring->stats.xdp_redirect_sg++;
-				break;
-			}
-
 			err = xdp_do_redirect(rx_ring->ndev, &xdp_buff, prog);
 			if (unlikely(err)) {
 				enetc_xdp_drop(rx_ring, orig_i, i);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter
  2023-01-04 13:57 [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers Lorenzo Bianconi
  2023-01-04 13:57 ` [PATCH v2 net-next 1/3] net: ethernet: " Lorenzo Bianconi
@ 2023-01-04 13:57 ` Lorenzo Bianconi
  2023-01-05  9:07   ` Leon Romanovsky
  2023-01-04 13:57 ` [PATCH v2 net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path Lorenzo Bianconi
  2023-01-06  5:50 ` [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers patchwork-bot+netdevbpf
  3 siblings, 1 reply; 8+ messages in thread
From: Lorenzo Bianconi @ 2023-01-04 13:57 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, lorenzo.bianconi, vladimir.oltean,
	claudiu.manoil

Remove xdp_redirect_sg counter and the related ethtool entry since it is
no longer used.

Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/freescale/enetc/enetc.h         | 1 -
 drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 2 --
 2 files changed, 3 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index c6d8cc15c270..416e4138dbaf 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -70,7 +70,6 @@ struct enetc_ring_stats {
 	unsigned int xdp_tx_drops;
 	unsigned int xdp_redirect;
 	unsigned int xdp_redirect_failures;
-	unsigned int xdp_redirect_sg;
 	unsigned int recycles;
 	unsigned int recycle_failures;
 	unsigned int win_drop;
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
index c8369e3752b0..d45f305eb03c 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c
@@ -197,7 +197,6 @@ static const char rx_ring_stats[][ETH_GSTRING_LEN] = {
 	"Rx ring %2d recycle failures",
 	"Rx ring %2d redirects",
 	"Rx ring %2d redirect failures",
-	"Rx ring %2d redirect S/G",
 };
 
 static const char tx_ring_stats[][ETH_GSTRING_LEN] = {
@@ -291,7 +290,6 @@ static void enetc_get_ethtool_stats(struct net_device *ndev,
 		data[o++] = priv->rx_ring[i]->stats.recycle_failures;
 		data[o++] = priv->rx_ring[i]->stats.xdp_redirect;
 		data[o++] = priv->rx_ring[i]->stats.xdp_redirect_failures;
-		data[o++] = priv->rx_ring[i]->stats.xdp_redirect_sg;
 	}
 
 	if (!enetc_si_is_pf(priv->si))
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path
  2023-01-04 13:57 [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers Lorenzo Bianconi
  2023-01-04 13:57 ` [PATCH v2 net-next 1/3] net: ethernet: " Lorenzo Bianconi
  2023-01-04 13:57 ` [PATCH v2 net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter Lorenzo Bianconi
@ 2023-01-04 13:57 ` Lorenzo Bianconi
  2023-01-05  9:07   ` Leon Romanovsky
  2023-01-06  5:50 ` [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers patchwork-bot+netdevbpf
  3 siblings, 1 reply; 8+ messages in thread
From: Lorenzo Bianconi @ 2023-01-04 13:57 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, lorenzo.bianconi, vladimir.oltean,
	claudiu.manoil

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>
---
 drivers/net/ethernet/freescale/enetc/enetc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 18a01f6282b6..5ad0b259e623 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -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);
@@ -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;
 
@@ -1390,16 +1394,12 @@ 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,
@@ -1407,7 +1407,7 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
 {
 	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;
@@ -1415,6 +1415,7 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
 	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;
 	}
@@ -1422,6 +1423,7 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i,
 	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);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 net-next 1/3] net: ethernet: enetc: unlock XDP_REDIRECT for XDP non-linear buffers
  2023-01-04 13:57 ` [PATCH v2 net-next 1/3] net: ethernet: " Lorenzo Bianconi
@ 2023-01-05  9:07   ` Leon Romanovsky
  0 siblings, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2023-01-05  9:07 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: netdev, davem, edumazet, kuba, pabeni, lorenzo.bianconi,
	vladimir.oltean, claudiu.manoil

On Wed, Jan 04, 2023 at 02:57:10PM +0100, Lorenzo Bianconi wrote:
> Even if full XDP_REDIRECT is not supported yet for non-linear XDP buffers
> since we allow redirecting just into CPUMAPs, unlock XDP_REDIRECT for
> S/G XDP buffer and rely on XDP stack to properly take care of the
> frames.
> 
> Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/freescale/enetc/enetc.c | 24 ++++++++------------
>  1 file changed, 10 insertions(+), 14 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter
  2023-01-04 13:57 ` [PATCH v2 net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter Lorenzo Bianconi
@ 2023-01-05  9:07   ` Leon Romanovsky
  0 siblings, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2023-01-05  9:07 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: netdev, davem, edumazet, kuba, pabeni, lorenzo.bianconi,
	vladimir.oltean, claudiu.manoil

On Wed, Jan 04, 2023 at 02:57:11PM +0100, Lorenzo Bianconi wrote:
> Remove xdp_redirect_sg counter and the related ethtool entry since it is
> no longer used.
> 
> Tested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/freescale/enetc/enetc.h         | 1 -
>  drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 2 --
>  2 files changed, 3 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path
  2023-01-04 13:57 ` [PATCH v2 net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path Lorenzo Bianconi
@ 2023-01-05  9:07   ` Leon Romanovsky
  0 siblings, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2023-01-05  9:07 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: netdev, davem, edumazet, kuba, pabeni, lorenzo.bianconi,
	vladimir.oltean, claudiu.manoil

On Wed, Jan 04, 2023 at 02:57:12PM +0100, Lorenzo Bianconi wrote:
> 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>
> ---
>  drivers/net/ethernet/freescale/enetc/enetc.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers
  2023-01-04 13:57 [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2023-01-04 13:57 ` [PATCH v2 net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path Lorenzo Bianconi
@ 2023-01-06  5:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-06  5:50 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: netdev, davem, edumazet, kuba, pabeni, lorenzo.bianconi,
	vladimir.oltean, claudiu.manoil

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  4 Jan 2023 14:57:09 +0100 you wrote:
> Unlock XDP_REDIRECT for S/G XDP buffer and rely on XDP stack to properly
> take care of the frames.
> Rely on XDP_FLAGS_HAS_FRAGS flag to check if it really necessary to access
> non-linear part of the xdp_buff/xdp_frame.
> 
> Changes since v1:
> - rebase on top of net-next
> 
> [...]

Here is the summary with links:
  - [v2,net-next,1/3] net: ethernet: enetc: unlock XDP_REDIRECT for XDP non-linear buffers
    https://git.kernel.org/netdev/net-next/c/8feb020f92a5
  - [v2,net-next,2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter
    https://git.kernel.org/netdev/net-next/c/59cc773a352c
  - [v2,net-next,3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path
    https://git.kernel.org/netdev/net-next/c/c7030d14c78e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-06  5:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 13:57 [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers Lorenzo Bianconi
2023-01-04 13:57 ` [PATCH v2 net-next 1/3] net: ethernet: " Lorenzo Bianconi
2023-01-05  9:07   ` Leon Romanovsky
2023-01-04 13:57 ` [PATCH v2 net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter Lorenzo Bianconi
2023-01-05  9:07   ` Leon Romanovsky
2023-01-04 13:57 ` [PATCH v2 net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path Lorenzo Bianconi
2023-01-05  9:07   ` Leon Romanovsky
2023-01-06  5:50 ` [PATCH v2 net-next 0/3] enetc: unlock XDP_REDIRECT for XDP non-linear buffers patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).