public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation
@ 2023-04-10 12:18 Kal Conley
  2023-04-12 12:23 ` Magnus Karlsson
  2023-04-13 13:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Kal Conley @ 2023-04-10 12:18 UTC (permalink / raw)
  To: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend
  Cc: Kal Conley, netdev, bpf, linux-kernel

Perform the chunk boundary check like the page boundary check in
xp_desc_crosses_non_contig_pg(). This simplifies the implementation and
reduces the number of branches.

Signed-off-by: Kal Conley <kal.conley@dectris.com>
---
 net/xdp/xsk_queue.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
index dea4f378327d..6d40a77fccbe 100644
--- a/net/xdp/xsk_queue.h
+++ b/net/xdp/xsk_queue.h
@@ -133,16 +133,12 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)
 static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
 					    struct xdp_desc *desc)
 {
-	u64 chunk, chunk_end;
+	u64 offset = desc->addr & (pool->chunk_size - 1);
 
-	chunk = xp_aligned_extract_addr(pool, desc->addr);
-	if (likely(desc->len)) {
-		chunk_end = xp_aligned_extract_addr(pool, desc->addr + desc->len - 1);
-		if (chunk != chunk_end)
-			return false;
-	}
+	if (offset + desc->len > pool->chunk_size)
+		return false;
 
-	if (chunk >= pool->addrs_cnt)
+	if (desc->addr >= pool->addrs_cnt)
 		return false;
 
 	if (desc->options)
-- 
2.39.2


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

* Re: [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation
  2023-04-10 12:18 [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation Kal Conley
@ 2023-04-12 12:23 ` Magnus Karlsson
  2023-04-12 12:34   ` Kal Cutter Conley
  2023-04-13 13:00 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Magnus Karlsson @ 2023-04-12 12:23 UTC (permalink / raw)
  To: Kal Conley
  Cc: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, netdev, bpf, linux-kernel

On Mon, 10 Apr 2023 at 14:24, Kal Conley <kal.conley@dectris.com> wrote:
>
> Perform the chunk boundary check like the page boundary check in
> xp_desc_crosses_non_contig_pg(). This simplifies the implementation and
> reduces the number of branches.

Thanks for this simplification Kal. Just to check, does your change
pass the xsk selftests, especially the INV_DESC test? If so, then you
have my ack below.

Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

> Signed-off-by: Kal Conley <kal.conley@dectris.com>
> ---
>  net/xdp/xsk_queue.h | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
> index dea4f378327d..6d40a77fccbe 100644
> --- a/net/xdp/xsk_queue.h
> +++ b/net/xdp/xsk_queue.h
> @@ -133,16 +133,12 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)
>  static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
>                                             struct xdp_desc *desc)
>  {
> -       u64 chunk, chunk_end;
> +       u64 offset = desc->addr & (pool->chunk_size - 1);
>
> -       chunk = xp_aligned_extract_addr(pool, desc->addr);
> -       if (likely(desc->len)) {
> -               chunk_end = xp_aligned_extract_addr(pool, desc->addr + desc->len - 1);
> -               if (chunk != chunk_end)
> -                       return false;
> -       }
> +       if (offset + desc->len > pool->chunk_size)
> +               return false;
>
> -       if (chunk >= pool->addrs_cnt)
> +       if (desc->addr >= pool->addrs_cnt)
>                 return false;
>
>         if (desc->options)
> --
> 2.39.2
>

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

* Re: [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation
  2023-04-12 12:23 ` Magnus Karlsson
@ 2023-04-12 12:34   ` Kal Cutter Conley
  0 siblings, 0 replies; 4+ messages in thread
From: Kal Cutter Conley @ 2023-04-12 12:34 UTC (permalink / raw)
  To: Magnus Karlsson
  Cc: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, netdev, bpf, linux-kernel

> > Perform the chunk boundary check like the page boundary check in
> > xp_desc_crosses_non_contig_pg(). This simplifies the implementation and
> > reduces the number of branches.
>
> Thanks for this simplification Kal. Just to check, does your change
> pass the xsk selftests, especially the INV_DESC test? If so, then you
> have my ack below.
>
> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

Yes, I ran the XSK selftests and they all PASSED.

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

* Re: [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation
  2023-04-10 12:18 [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation Kal Conley
  2023-04-12 12:23 ` Magnus Karlsson
@ 2023-04-13 13:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-13 13:00 UTC (permalink / raw)
  To: Kal Cutter Conley
  Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon, davem,
	edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend, netdev,
	bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Mon, 10 Apr 2023 14:18:41 +0200 you wrote:
> Perform the chunk boundary check like the page boundary check in
> xp_desc_crosses_non_contig_pg(). This simplifies the implementation and
> reduces the number of branches.
> 
> Signed-off-by: Kal Conley <kal.conley@dectris.com>
> ---
>  net/xdp/xsk_queue.h | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)

Here is the summary with links:
  - [bpf-next] xsk: Simplify xp_aligned_validate_desc implementation
    https://git.kernel.org/bpf/bpf-next/c/0c5f48599bed

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] 4+ messages in thread

end of thread, other threads:[~2023-04-13 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-10 12:18 [PATCH bpf-next] xsk: Simplify xp_aligned_validate_desc implementation Kal Conley
2023-04-12 12:23 ` Magnus Karlsson
2023-04-12 12:34   ` Kal Cutter Conley
2023-04-13 13:00 ` 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