diff mbox series

[bpf-next] selftests/bpf: Use prog_attach_type to attach in test_sockmap

Message ID e27d7d0c1e0e79b0acd22ac6ad5d8f9f00225303.1716372485.git.tanggeliang@kylinos.cn (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Use prog_attach_type to attach in test_sockmap | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
netdev/tree_selection success Clearly marked for bpf-next
netdev/apply fail Patch does not apply to bpf-next-0

Commit Message

Geliang Tang May 22, 2024, 10:08 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

Since prog_attach_type[] array is defined, it makes sense to use it paired
with prog_fd[] array for bpf_prog_attach() and bpf_prog_detach2() instead
of open-coding.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/test_sockmap.c | 44 +++++++++++-----------
 1 file changed, 22 insertions(+), 22 deletions(-)

Comments

Geliang Tang May 23, 2024, 7:03 a.m. UTC | #1
This patch is "Rejected", according to Jakub's comments:

https://lore.kernel.org/bpf/87zfsiw3a3.fsf@cloudflare.com/

Thanks,
-Geliang

On Wed, 2024-05-22 at 18:08 +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Since prog_attach_type[] array is defined, it makes sense to use it
> paired
> with prog_fd[] array for bpf_prog_attach() and bpf_prog_detach2()
> instead
> of open-coding.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  tools/testing/selftests/bpf/test_sockmap.c | 44 +++++++++++---------
> --
>  1 file changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/test_sockmap.c
> b/tools/testing/selftests/bpf/test_sockmap.c
> index 4499b3cfc3a6..8c8208b82c5e 100644
> --- a/tools/testing/selftests/bpf/test_sockmap.c
> +++ b/tools/testing/selftests/bpf/test_sockmap.c
> @@ -65,6 +65,18 @@ int map_fd[9];
>  struct bpf_map *maps[9];
>  int prog_fd[9];
>  
> +int prog_attach_type[] = {
> +	BPF_SK_SKB_STREAM_PARSER,
> +	BPF_SK_SKB_STREAM_VERDICT,
> +	BPF_SK_SKB_STREAM_VERDICT,
> +	BPF_CGROUP_SOCK_OPS,
> +	BPF_SK_MSG_VERDICT,
> +	BPF_SK_MSG_VERDICT,
> +	BPF_SK_MSG_VERDICT,
> +	BPF_SK_MSG_VERDICT,
> +	BPF_SK_MSG_VERDICT,
> +};
> +
>  int txmsg_pass;
>  int txmsg_redir;
>  int txmsg_drop;
> @@ -961,7 +973,7 @@ static int run_options(struct sockmap_options
> *options, int cg_fd,  int test)
>  	/* Attach programs to sockmap */
>  	if (!txmsg_omit_skb_parser) {
>  		err = bpf_prog_attach(prog_fd[0], map_fd[0],
> -				      BPF_SK_SKB_STREAM_PARSER, 0);
> +				      prog_attach_type[0], 0);
>  		if (err) {
>  			fprintf(stderr,
>  				"ERROR: bpf_prog_attach (sockmap %i-
> >%i): %d (%s)\n",
> @@ -971,7 +983,7 @@ static int run_options(struct sockmap_options
> *options, int cg_fd,  int test)
>  	}
>  
>  	err = bpf_prog_attach(prog_fd[1], map_fd[0],
> -				BPF_SK_SKB_STREAM_VERDICT, 0);
> +			      prog_attach_type[1], 0);
>  	if (err) {
>  		fprintf(stderr, "ERROR: bpf_prog_attach (sockmap):
> %d (%s)\n",
>  			err, strerror(errno));
> @@ -982,7 +994,7 @@ static int run_options(struct sockmap_options
> *options, int cg_fd,  int test)
>  	if (txmsg_ktls_skb) {
>  		if (!txmsg_omit_skb_parser) {
>  			err = bpf_prog_attach(prog_fd[0], map_fd[8],
> -					     
> BPF_SK_SKB_STREAM_PARSER, 0);
> +					      prog_attach_type[0],
> 0);
>  			if (err) {
>  				fprintf(stderr,
>  					"ERROR: bpf_prog_attach (TLS
> sockmap %i->%i): %d (%s)\n",
> @@ -992,7 +1004,7 @@ static int run_options(struct sockmap_options
> *options, int cg_fd,  int test)
>  		}
>  
>  		err = bpf_prog_attach(prog_fd[2], map_fd[8],
> -				      BPF_SK_SKB_STREAM_VERDICT, 0);
> +				      prog_attach_type[2], 0);
>  		if (err) {
>  			fprintf(stderr, "ERROR: bpf_prog_attach (TLS
> sockmap): %d (%s)\n",
>  				err, strerror(errno));
> @@ -1001,7 +1013,7 @@ static int run_options(struct sockmap_options
> *options, int cg_fd,  int test)
>  	}
>  
>  	/* Attach to cgroups */
> -	err = bpf_prog_attach(prog_fd[3], cg_fd,
> BPF_CGROUP_SOCK_OPS, 0);
> +	err = bpf_prog_attach(prog_fd[3], cg_fd,
> prog_attach_type[3], 0);
>  	if (err) {
>  		fprintf(stderr, "ERROR: bpf_prog_attach (groups): %d
> (%s)\n",
>  			err, strerror(errno));
> @@ -1279,11 +1291,11 @@ static int run_options(struct sockmap_options
> *options, int cg_fd,  int test)
>  		fprintf(stderr, "unknown test\n");
>  out:
>  	/* Detatch and zero all the maps */
> -	bpf_prog_detach2(prog_fd[3], cg_fd, BPF_CGROUP_SOCK_OPS);
> -	bpf_prog_detach2(prog_fd[0], map_fd[0],
> BPF_SK_SKB_STREAM_PARSER);
> -	bpf_prog_detach2(prog_fd[1], map_fd[0],
> BPF_SK_SKB_STREAM_VERDICT);
> -	bpf_prog_detach2(prog_fd[0], map_fd[8],
> BPF_SK_SKB_STREAM_PARSER);
> -	bpf_prog_detach2(prog_fd[2], map_fd[8],
> BPF_SK_SKB_STREAM_VERDICT);
> +	bpf_prog_detach2(prog_fd[3], cg_fd, prog_attach_type[3]);
> +	bpf_prog_detach2(prog_fd[0], map_fd[0],
> prog_attach_type[0]);
> +	bpf_prog_detach2(prog_fd[1], map_fd[0],
> prog_attach_type[1]);
> +	bpf_prog_detach2(prog_fd[0], map_fd[8],
> prog_attach_type[0]);
> +	bpf_prog_detach2(prog_fd[2], map_fd[8],
> prog_attach_type[2]);
>  
>  	if (tx_prog_fd >= 0)
>  		bpf_prog_detach2(tx_prog_fd, map_fd[1],
> BPF_SK_MSG_VERDICT);
> @@ -1783,18 +1795,6 @@ char *map_names[] = {
>  	"tls_sock_map",
>  };
>  
> -int prog_attach_type[] = {
> -	BPF_SK_SKB_STREAM_PARSER,
> -	BPF_SK_SKB_STREAM_VERDICT,
> -	BPF_SK_SKB_STREAM_VERDICT,
> -	BPF_CGROUP_SOCK_OPS,
> -	BPF_SK_MSG_VERDICT,
> -	BPF_SK_MSG_VERDICT,
> -	BPF_SK_MSG_VERDICT,
> -	BPF_SK_MSG_VERDICT,
> -	BPF_SK_MSG_VERDICT,
> -};
> -
>  int prog_type[] = {
>  	BPF_PROG_TYPE_SK_SKB,
>  	BPF_PROG_TYPE_SK_SKB,
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 4499b3cfc3a6..8c8208b82c5e 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -65,6 +65,18 @@  int map_fd[9];
 struct bpf_map *maps[9];
 int prog_fd[9];
 
+int prog_attach_type[] = {
+	BPF_SK_SKB_STREAM_PARSER,
+	BPF_SK_SKB_STREAM_VERDICT,
+	BPF_SK_SKB_STREAM_VERDICT,
+	BPF_CGROUP_SOCK_OPS,
+	BPF_SK_MSG_VERDICT,
+	BPF_SK_MSG_VERDICT,
+	BPF_SK_MSG_VERDICT,
+	BPF_SK_MSG_VERDICT,
+	BPF_SK_MSG_VERDICT,
+};
+
 int txmsg_pass;
 int txmsg_redir;
 int txmsg_drop;
@@ -961,7 +973,7 @@  static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 	/* Attach programs to sockmap */
 	if (!txmsg_omit_skb_parser) {
 		err = bpf_prog_attach(prog_fd[0], map_fd[0],
-				      BPF_SK_SKB_STREAM_PARSER, 0);
+				      prog_attach_type[0], 0);
 		if (err) {
 			fprintf(stderr,
 				"ERROR: bpf_prog_attach (sockmap %i->%i): %d (%s)\n",
@@ -971,7 +983,7 @@  static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 	}
 
 	err = bpf_prog_attach(prog_fd[1], map_fd[0],
-				BPF_SK_SKB_STREAM_VERDICT, 0);
+			      prog_attach_type[1], 0);
 	if (err) {
 		fprintf(stderr, "ERROR: bpf_prog_attach (sockmap): %d (%s)\n",
 			err, strerror(errno));
@@ -982,7 +994,7 @@  static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 	if (txmsg_ktls_skb) {
 		if (!txmsg_omit_skb_parser) {
 			err = bpf_prog_attach(prog_fd[0], map_fd[8],
-					      BPF_SK_SKB_STREAM_PARSER, 0);
+					      prog_attach_type[0], 0);
 			if (err) {
 				fprintf(stderr,
 					"ERROR: bpf_prog_attach (TLS sockmap %i->%i): %d (%s)\n",
@@ -992,7 +1004,7 @@  static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 		}
 
 		err = bpf_prog_attach(prog_fd[2], map_fd[8],
-				      BPF_SK_SKB_STREAM_VERDICT, 0);
+				      prog_attach_type[2], 0);
 		if (err) {
 			fprintf(stderr, "ERROR: bpf_prog_attach (TLS sockmap): %d (%s)\n",
 				err, strerror(errno));
@@ -1001,7 +1013,7 @@  static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 	}
 
 	/* Attach to cgroups */
-	err = bpf_prog_attach(prog_fd[3], cg_fd, BPF_CGROUP_SOCK_OPS, 0);
+	err = bpf_prog_attach(prog_fd[3], cg_fd, prog_attach_type[3], 0);
 	if (err) {
 		fprintf(stderr, "ERROR: bpf_prog_attach (groups): %d (%s)\n",
 			err, strerror(errno));
@@ -1279,11 +1291,11 @@  static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 		fprintf(stderr, "unknown test\n");
 out:
 	/* Detatch and zero all the maps */
-	bpf_prog_detach2(prog_fd[3], cg_fd, BPF_CGROUP_SOCK_OPS);
-	bpf_prog_detach2(prog_fd[0], map_fd[0], BPF_SK_SKB_STREAM_PARSER);
-	bpf_prog_detach2(prog_fd[1], map_fd[0], BPF_SK_SKB_STREAM_VERDICT);
-	bpf_prog_detach2(prog_fd[0], map_fd[8], BPF_SK_SKB_STREAM_PARSER);
-	bpf_prog_detach2(prog_fd[2], map_fd[8], BPF_SK_SKB_STREAM_VERDICT);
+	bpf_prog_detach2(prog_fd[3], cg_fd, prog_attach_type[3]);
+	bpf_prog_detach2(prog_fd[0], map_fd[0], prog_attach_type[0]);
+	bpf_prog_detach2(prog_fd[1], map_fd[0], prog_attach_type[1]);
+	bpf_prog_detach2(prog_fd[0], map_fd[8], prog_attach_type[0]);
+	bpf_prog_detach2(prog_fd[2], map_fd[8], prog_attach_type[2]);
 
 	if (tx_prog_fd >= 0)
 		bpf_prog_detach2(tx_prog_fd, map_fd[1], BPF_SK_MSG_VERDICT);
@@ -1783,18 +1795,6 @@  char *map_names[] = {
 	"tls_sock_map",
 };
 
-int prog_attach_type[] = {
-	BPF_SK_SKB_STREAM_PARSER,
-	BPF_SK_SKB_STREAM_VERDICT,
-	BPF_SK_SKB_STREAM_VERDICT,
-	BPF_CGROUP_SOCK_OPS,
-	BPF_SK_MSG_VERDICT,
-	BPF_SK_MSG_VERDICT,
-	BPF_SK_MSG_VERDICT,
-	BPF_SK_MSG_VERDICT,
-	BPF_SK_MSG_VERDICT,
-};
-
 int prog_type[] = {
 	BPF_PROG_TYPE_SK_SKB,
 	BPF_PROG_TYPE_SK_SKB,