xsk: Simplify xp_aligned_validate_desc implementation
Subsystems (4)
PATCH 1/1 xsk: Simplify xp_aligned_validate_desc implementation
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.
--- net/xdp/xsk_queue.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
net/xdp/xsk_queue.h +4 -8
@@ -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)
Signature · 1 line
2.39.2
Quoted 4 lines · Kal Conley
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.
Quoted 33 lines
Signed-off-by Kal Conley <[email protected]>--- net/xdp/xsk_queue.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)net/xdp/xsk_queue.h +4
-9@@ -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
Quoted 9 lines
Quoted 3 lines
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_DESCtest? If so, then you have my ack below.Acked-by Magnus Karlsson <[email protected]>
Yes, I ran the XSK selftests and they all PASSED.
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 8 lines · 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 <[email protected]>--- 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html