* [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo
@ 2023-06-01 16:21 Jesper Dangaard Brouer
2023-06-01 20:34 ` Lorenzo Bianconi
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jesper Dangaard Brouer @ 2023-06-01 16:21 UTC (permalink / raw)
To: Tariq Toukan, Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko, bpf
Cc: Jesper Dangaard Brouer, Tariq Toukan, gal, lorenzo, netdev,
echaudro, andrew.gospodarek
Currently we observed a significant performance degradation in
samples/bpf xdp1 and xdp2, due XDP multibuffer "xdp.frags" handling,
added in commit 772251742262 ("samples/bpf: fixup some tools to be able
to support xdp multibuffer").
This patch reduce the overhead by avoiding to read/load shared_info
(sinfo) memory area, when XDP packet don't have any frags. This improves
performance because sinfo is located in another cacheline.
Function bpf_xdp_pointer() is used by BPF helpers bpf_xdp_load_bytes()
and bpf_xdp_store_bytes(). As a help to reviewers, xdp_get_buff_len() can
potentially access sinfo, but it uses xdp_buff_has_frags() flags bit check
to avoid accessing sinfo in no-frags case.
The likely/unlikely instrumentation lays out asm code such that sinfo
access isn't interleaved with no-frags case (checked on GCC 12.2.1-4).
The generated asm code is more compact towards the no-frags case.
The BPF kfunc bpf_dynptr_slice() also use bpf_xdp_pointer(). Thus, it
should also take effect for that.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
net/core/filter.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 968139f4a1ac..961db5bd2f94 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3948,20 +3948,21 @@ void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off,
void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
{
- struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
u32 size = xdp->data_end - xdp->data;
+ struct skb_shared_info *sinfo;
void *addr = xdp->data;
int i;
if (unlikely(offset > 0xffff || len > 0xffff))
return ERR_PTR(-EFAULT);
- if (offset + len > xdp_get_buff_len(xdp))
+ if (unlikely(offset + len > xdp_get_buff_len(xdp)))
return ERR_PTR(-EINVAL);
- if (offset < size) /* linear area */
+ if (likely((offset < size))) /* linear area */
goto out;
+ sinfo = xdp_get_shared_info_from_buff(xdp);
offset -= size;
for (i = 0; i < sinfo->nr_frags; i++) { /* paged area */
u32 frag_size = skb_frag_size(&sinfo->frags[i]);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo
2023-06-01 16:21 [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo Jesper Dangaard Brouer
@ 2023-06-01 20:34 ` Lorenzo Bianconi
2023-06-05 20:41 ` Alexei Starovoitov
2023-06-01 20:37 ` Toke Høiland-Jørgensen
2023-06-05 20:50 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Lorenzo Bianconi @ 2023-06-01 20:34 UTC (permalink / raw)
To: Jesper Dangaard Brouer
Cc: Tariq Toukan, Daniel Borkmann, Alexei Starovoitov,
Andrii Nakryiko, bpf, Tariq Toukan, gal, netdev, echaudro,
andrew.gospodarek
[-- Attachment #1: Type: text/plain, Size: 2407 bytes --]
> Currently we observed a significant performance degradation in
> samples/bpf xdp1 and xdp2, due XDP multibuffer "xdp.frags" handling,
> added in commit 772251742262 ("samples/bpf: fixup some tools to be able
> to support xdp multibuffer").
>
> This patch reduce the overhead by avoiding to read/load shared_info
> (sinfo) memory area, when XDP packet don't have any frags. This improves
> performance because sinfo is located in another cacheline.
>
> Function bpf_xdp_pointer() is used by BPF helpers bpf_xdp_load_bytes()
> and bpf_xdp_store_bytes(). As a help to reviewers, xdp_get_buff_len() can
> potentially access sinfo, but it uses xdp_buff_has_frags() flags bit check
> to avoid accessing sinfo in no-frags case.
>
> The likely/unlikely instrumentation lays out asm code such that sinfo
> access isn't interleaved with no-frags case (checked on GCC 12.2.1-4).
> The generated asm code is more compact towards the no-frags case.
>
> The BPF kfunc bpf_dynptr_slice() also use bpf_xdp_pointer(). Thus, it
> should also take effect for that.
>
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> ---
> net/core/filter.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 968139f4a1ac..961db5bd2f94 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3948,20 +3948,21 @@ void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off,
>
> void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
> {
> - struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
> u32 size = xdp->data_end - xdp->data;
> + struct skb_shared_info *sinfo;
> void *addr = xdp->data;
> int i;
>
> if (unlikely(offset > 0xffff || len > 0xffff))
> return ERR_PTR(-EFAULT);
>
> - if (offset + len > xdp_get_buff_len(xdp))
> + if (unlikely(offset + len > xdp_get_buff_len(xdp)))
> return ERR_PTR(-EINVAL);
>
> - if (offset < size) /* linear area */
> + if (likely((offset < size))) /* linear area */
nit: you can drop a round bracket here. Other than that:
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> goto out;
>
> + sinfo = xdp_get_shared_info_from_buff(xdp);
> offset -= size;
> for (i = 0; i < sinfo->nr_frags; i++) { /* paged area */
> u32 frag_size = skb_frag_size(&sinfo->frags[i]);
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo
2023-06-01 16:21 [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo Jesper Dangaard Brouer
2023-06-01 20:34 ` Lorenzo Bianconi
@ 2023-06-01 20:37 ` Toke Høiland-Jørgensen
2023-06-05 20:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Toke Høiland-Jørgensen @ 2023-06-01 20:37 UTC (permalink / raw)
To: Jesper Dangaard Brouer, Tariq Toukan, Daniel Borkmann,
Alexei Starovoitov, Andrii Nakryiko, bpf
Cc: Jesper Dangaard Brouer, Tariq Toukan, gal, lorenzo, netdev,
echaudro, andrew.gospodarek
Jesper Dangaard Brouer <brouer@redhat.com> writes:
> Currently we observed a significant performance degradation in
> samples/bpf xdp1 and xdp2, due XDP multibuffer "xdp.frags" handling,
> added in commit 772251742262 ("samples/bpf: fixup some tools to be able
> to support xdp multibuffer").
>
> This patch reduce the overhead by avoiding to read/load shared_info
> (sinfo) memory area, when XDP packet don't have any frags. This improves
> performance because sinfo is located in another cacheline.
>
> Function bpf_xdp_pointer() is used by BPF helpers bpf_xdp_load_bytes()
> and bpf_xdp_store_bytes(). As a help to reviewers, xdp_get_buff_len() can
> potentially access sinfo, but it uses xdp_buff_has_frags() flags bit check
> to avoid accessing sinfo in no-frags case.
>
> The likely/unlikely instrumentation lays out asm code such that sinfo
> access isn't interleaved with no-frags case (checked on GCC 12.2.1-4).
> The generated asm code is more compact towards the no-frags case.
>
> The BPF kfunc bpf_dynptr_slice() also use bpf_xdp_pointer(). Thus, it
> should also take effect for that.
>
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Thanks for fixing this!
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo
2023-06-01 20:34 ` Lorenzo Bianconi
@ 2023-06-05 20:41 ` Alexei Starovoitov
0 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2023-06-05 20:41 UTC (permalink / raw)
To: Lorenzo Bianconi
Cc: Jesper Dangaard Brouer, Tariq Toukan, Daniel Borkmann,
Alexei Starovoitov, Andrii Nakryiko, bpf, Tariq Toukan,
Gal Pressman, Network Development, Eelco Chaudron,
Andy Gospodarek
On Thu, Jun 1, 2023 at 1:34 PM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> > Currently we observed a significant performance degradation in
> > samples/bpf xdp1 and xdp2, due XDP multibuffer "xdp.frags" handling,
> > added in commit 772251742262 ("samples/bpf: fixup some tools to be able
> > to support xdp multibuffer").
> >
> > This patch reduce the overhead by avoiding to read/load shared_info
> > (sinfo) memory area, when XDP packet don't have any frags. This improves
> > performance because sinfo is located in another cacheline.
> >
> > Function bpf_xdp_pointer() is used by BPF helpers bpf_xdp_load_bytes()
> > and bpf_xdp_store_bytes(). As a help to reviewers, xdp_get_buff_len() can
> > potentially access sinfo, but it uses xdp_buff_has_frags() flags bit check
> > to avoid accessing sinfo in no-frags case.
> >
> > The likely/unlikely instrumentation lays out asm code such that sinfo
> > access isn't interleaved with no-frags case (checked on GCC 12.2.1-4).
> > The generated asm code is more compact towards the no-frags case.
> >
> > The BPF kfunc bpf_dynptr_slice() also use bpf_xdp_pointer(). Thus, it
> > should also take effect for that.
> >
> > Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> > ---
> > net/core/filter.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 968139f4a1ac..961db5bd2f94 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -3948,20 +3948,21 @@ void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off,
> >
> > void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
> > {
> > - struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
> > u32 size = xdp->data_end - xdp->data;
> > + struct skb_shared_info *sinfo;
> > void *addr = xdp->data;
> > int i;
> >
> > if (unlikely(offset > 0xffff || len > 0xffff))
> > return ERR_PTR(-EFAULT);
> >
> > - if (offset + len > xdp_get_buff_len(xdp))
> > + if (unlikely(offset + len > xdp_get_buff_len(xdp)))
> > return ERR_PTR(-EINVAL);
> >
> > - if (offset < size) /* linear area */
> > + if (likely((offset < size))) /* linear area */
>
> nit: you can drop a round bracket here. Other than that:
Fixed while applying. Thanks everyone.
> Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
>
> > goto out;
> >
> > + sinfo = xdp_get_shared_info_from_buff(xdp);
> > offset -= size;
> > for (i = 0; i < sinfo->nr_frags; i++) { /* paged area */
> > u32 frag_size = skb_frag_size(&sinfo->frags[i]);
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo
2023-06-01 16:21 [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo Jesper Dangaard Brouer
2023-06-01 20:34 ` Lorenzo Bianconi
2023-06-01 20:37 ` Toke Høiland-Jørgensen
@ 2023-06-05 20:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-05 20:50 UTC (permalink / raw)
To: Jesper Dangaard Brouer
Cc: ttoukan.linux, borkmann, ast, andrii.nakryiko, bpf, tariqt, gal,
lorenzo, netdev, echaudro, andrew.gospodarek
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Thu, 01 Jun 2023 18:21:54 +0200 you wrote:
> Currently we observed a significant performance degradation in
> samples/bpf xdp1 and xdp2, due XDP multibuffer "xdp.frags" handling,
> added in commit 772251742262 ("samples/bpf: fixup some tools to be able
> to support xdp multibuffer").
>
> This patch reduce the overhead by avoiding to read/load shared_info
> (sinfo) memory area, when XDP packet don't have any frags. This improves
> performance because sinfo is located in another cacheline.
>
> [...]
Here is the summary with links:
- [bpf-next,V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo
https://git.kernel.org/bpf/bpf-next/c/411486626e57
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] 5+ messages in thread
end of thread, other threads:[~2023-06-05 20:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 16:21 [PATCH bpf-next V2] bpf/xdp: optimize bpf_xdp_pointer to avoid reading sinfo Jesper Dangaard Brouer
2023-06-01 20:34 ` Lorenzo Bianconi
2023-06-05 20:41 ` Alexei Starovoitov
2023-06-01 20:37 ` Toke Høiland-Jørgensen
2023-06-05 20:50 ` 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).