BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v4 0/2] Allow data_meta size > 32
@ 2023-12-06 20:59 Larysa Zaremba
  2023-12-06 20:59 ` [PATCH bpf-next v4 1/2] selftests/bpf: increase invalid metadata size Larysa Zaremba
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Larysa Zaremba @ 2023-12-06 20:59 UTC (permalink / raw)
  To: bpf
  Cc: Larysa Zaremba, netdev, Alexei Starovoitov, Daniel Borkmann,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	Eric Dumazet, Magnus Karlsson, Willem de Bruijn, Yunsheng Lin,
	Maciej Fijalkowski, John Fastabend, Aleksander Lobakin

Currently, there is no reason for data_meta to be limited to 32 bytes.
Loosen this limitation and make maximum meta size 252 (max value of u8,
aligned to 4). Details in the second patch.

Also, modify the selftest, so test_xdp_context_error does not complain
about the unexpected success.

v3->v4:
* Explain limit of 252 in cover letter and commit message

v2->v3:
* Fix main patch author
* Add selftests path

v1->v2:
* replace 'typeof(metalen)' with the actual type

Aleksander Lobakin (1):
  net, xdp: allow metadata > 32

Larysa Zaremba (1):
  selftests/bpf: increase invalid metadata size

 include/linux/skbuff.h                              | 13 ++++++++-----
 include/net/xdp.h                                   |  7 ++++++-
 .../selftests/bpf/prog_tests/xdp_context_test_run.c |  4 ++--
 3 files changed, 16 insertions(+), 8 deletions(-)

-- 
2.41.0


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

* [PATCH bpf-next v4 1/2] selftests/bpf: increase invalid metadata size
  2023-12-06 20:59 [PATCH bpf-next v4 0/2] Allow data_meta size > 32 Larysa Zaremba
@ 2023-12-06 20:59 ` Larysa Zaremba
  2023-12-06 20:59 ` [PATCH bpf-next v4 2/2] net, xdp: allow metadata > 32 Larysa Zaremba
  2023-12-11 15:20 ` [PATCH bpf-next v4 0/2] Allow data_meta size " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Larysa Zaremba @ 2023-12-06 20:59 UTC (permalink / raw)
  To: bpf
  Cc: Larysa Zaremba, netdev, Alexei Starovoitov, Daniel Borkmann,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	Eric Dumazet, Magnus Karlsson, Willem de Bruijn, Yunsheng Lin,
	Maciej Fijalkowski, John Fastabend, Aleksander Lobakin

Changed check expects passed data meta to be deemed invalid.
After loosening the requirement, the size of 36 bytes becomes valid.
Therefore, increase tested meta size to 256, so we do not get an unexpected
success.

Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
 tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c b/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c
index ab4952b9fb1d..e6a783c7f5db 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c
@@ -77,8 +77,8 @@ void test_xdp_context_test_run(void)
 	test_xdp_context_error(prog_fd, opts, 4, sizeof(__u32), sizeof(data),
 			       0, 0, 0);
 
-	/* Meta data must be 32 bytes or smaller */
-	test_xdp_context_error(prog_fd, opts, 0, 36, sizeof(data), 0, 0, 0);
+	/* Meta data must be 255 bytes or smaller */
+	test_xdp_context_error(prog_fd, opts, 0, 256, sizeof(data), 0, 0, 0);
 
 	/* Total size of data must match data_end - data_meta */
 	test_xdp_context_error(prog_fd, opts, 0, sizeof(__u32),
-- 
2.41.0


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

* [PATCH bpf-next v4 2/2] net, xdp: allow metadata > 32
  2023-12-06 20:59 [PATCH bpf-next v4 0/2] Allow data_meta size > 32 Larysa Zaremba
  2023-12-06 20:59 ` [PATCH bpf-next v4 1/2] selftests/bpf: increase invalid metadata size Larysa Zaremba
@ 2023-12-06 20:59 ` Larysa Zaremba
  2023-12-11 15:20 ` [PATCH bpf-next v4 0/2] Allow data_meta size " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Larysa Zaremba @ 2023-12-06 20:59 UTC (permalink / raw)
  To: bpf
  Cc: Larysa Zaremba, netdev, Alexei Starovoitov, Daniel Borkmann,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	Eric Dumazet, Magnus Karlsson, Willem de Bruijn, Yunsheng Lin,
	Maciej Fijalkowski, John Fastabend, Aleksander Lobakin

From: Aleksander Lobakin <aleksander.lobakin@intel.com>

32 bytes may be not enough for some custom metadata. Relax the restriction,
allow metadata larger than 32 bytes and make __skb_metadata_differs() work
with bigger lengths.

Now size of metadata is only limited by the fact it is stored as u8
in skb_shared_info, so maximum possible value is 255. Size still has to be
aligned to 4, so the actual upper limit becomes 252. Most driver
implementations will offer less, none can offer more.

Other important conditions, such as having enough space for xdp_frame
building, are already checked in bpf_xdp_adjust_meta().

Signed-off-by: Aleksander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
 include/linux/skbuff.h | 13 ++++++++-----
 include/net/xdp.h      |  7 ++++++-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index b370eb8d70f7..df6ef42639d8 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -4247,10 +4247,13 @@ static inline bool __skb_metadata_differs(const struct sk_buff *skb_a,
 {
 	const void *a = skb_metadata_end(skb_a);
 	const void *b = skb_metadata_end(skb_b);
-	/* Using more efficient varaiant than plain call to memcmp(). */
-#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
 	u64 diffs = 0;
 
+	if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ||
+	    BITS_PER_LONG != 64)
+		goto slow;
+
+	/* Using more efficient variant than plain call to memcmp(). */
 	switch (meta_len) {
 #define __it(x, op) (x -= sizeof(u##op))
 #define __it_diff(a, b, op) (*(u##op *)__it(a, op)) ^ (*(u##op *)__it(b, op))
@@ -4270,11 +4273,11 @@ static inline bool __skb_metadata_differs(const struct sk_buff *skb_a,
 		fallthrough;
 	case  4: diffs |= __it_diff(a, b, 32);
 		break;
+	default:
+slow:
+		return memcmp(a - meta_len, b - meta_len, meta_len);
 	}
 	return diffs;
-#else
-	return memcmp(a - meta_len, b - meta_len, meta_len);
-#endif
 }
 
 static inline bool skb_metadata_differs(const struct sk_buff *skb_a,
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 349c36fb5fd8..5d3673afc037 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -369,7 +369,12 @@ xdp_data_meta_unsupported(const struct xdp_buff *xdp)
 
 static inline bool xdp_metalen_invalid(unsigned long metalen)
 {
-	return (metalen & (sizeof(__u32) - 1)) || (metalen > 32);
+	unsigned long meta_max;
+
+	meta_max = type_max(typeof_member(struct skb_shared_info, meta_len));
+	BUILD_BUG_ON(!__builtin_constant_p(meta_max));
+
+	return !IS_ALIGNED(metalen, sizeof(u32)) || metalen > meta_max;
 }
 
 struct xdp_attachment_info {
-- 
2.41.0


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

* Re: [PATCH bpf-next v4 0/2] Allow data_meta size > 32
  2023-12-06 20:59 [PATCH bpf-next v4 0/2] Allow data_meta size > 32 Larysa Zaremba
  2023-12-06 20:59 ` [PATCH bpf-next v4 1/2] selftests/bpf: increase invalid metadata size Larysa Zaremba
  2023-12-06 20:59 ` [PATCH bpf-next v4 2/2] net, xdp: allow metadata > 32 Larysa Zaremba
@ 2023-12-11 15:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-11 15:20 UTC (permalink / raw)
  To: Larysa Zaremba
  Cc: bpf, netdev, ast, daniel, davem, kuba, hawk, edumazet,
	magnus.karlsson, willemdebruijn.kernel, linyunsheng,
	maciej.fijalkowski, john.fastabend, aleksander.lobakin

Hello:

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

On Wed,  6 Dec 2023 21:59:17 +0100 you wrote:
> Currently, there is no reason for data_meta to be limited to 32 bytes.
> Loosen this limitation and make maximum meta size 252 (max value of u8,
> aligned to 4). Details in the second patch.
> 
> Also, modify the selftest, so test_xdp_context_error does not complain
> about the unexpected success.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v4,1/2] selftests/bpf: increase invalid metadata size
    https://git.kernel.org/bpf/bpf-next/c/15c79c6507c0
  - [bpf-next,v4,2/2] net, xdp: allow metadata > 32
    https://git.kernel.org/bpf/bpf-next/c/2ebe81c81435

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-12-11 15:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 20:59 [PATCH bpf-next v4 0/2] Allow data_meta size > 32 Larysa Zaremba
2023-12-06 20:59 ` [PATCH bpf-next v4 1/2] selftests/bpf: increase invalid metadata size Larysa Zaremba
2023-12-06 20:59 ` [PATCH bpf-next v4 2/2] net, xdp: allow metadata > 32 Larysa Zaremba
2023-12-11 15:20 ` [PATCH bpf-next v4 0/2] Allow data_meta size " 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