[PATCH v2 2/2] bpf: update BPF constants

Paul Chaignon paul.chaignon at gmail.com
Wed Nov 27 14:16:21 UTC 2019


* xlat/bpf_prog_types.in (BPF_PROG_TYPE_CGROUP_SOCK_ADDR): New constant
introduced by Linux commit v4.17-rc1~148^2~19^2^2~6.
(BPF_PROG_TYPE_LWT_SEG6LOCAL, BPF_PROG_TYPE_LIRC_MODE2,
BPF_PROG_TYPE_LIRC_MODE2, BPF_PROG_TYPE_FLOW_DISSECTOR,
BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
BPF_PROG_TYPE_CGROUP_SOCKOPT): Update constant values following missing
entry in enum.
* tests/bpf.c (BPF_PROG_LOAD_checks): Update expected outputs and add test.
* tests/kernel_version.c (print_bpf_attr, main): Likewise.

Fixes: v4.24~49 "xlat: update bpf(2)-related constants"
Fixes: v4.25~58 "xlat: add BPF_PROG_TYPE_SK_REUSEPORT to bpf_prog_types.in"
Fixes: v4.26~12 "xlat: add flow dissector bpf program type constants"
Fixes: v5.2~38 "xlat: update BPF_* constants"
Fixes: v5.3~60 "xlat: update BPF_* constants"
Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
---
Changelogs:
  Changes in v2:
    - Add new test on last program type.
    - Fix commit message.

 tests/bpf.c            | 33 ++++++++++++++++++++++++++++++---
 tests/kernel_version.c |  6 +++---
 xlat/bpf_prog_types.in | 15 ++++++++-------
 3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/tests/bpf.c b/tests/bpf.c
index a1dad79a..9e5f9f5c 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -27,6 +27,7 @@
 
 #include "xlat.h"
 #include "xlat/bpf_commands.h"
+#include "xlat/bpf_prog_types.h"
 
 #if defined MPERS_IS_m32 || SIZEOF_KERNEL_LONG_T > 4
 # define BIG_ADDR(addr64_, addr32_) addr64_
@@ -600,6 +601,8 @@ print_BPF_PROG_LOAD_attr4(const struct bpf_attr_check *check, unsigned long addr
 	       license, IFINDEX_LO_STR);
 }
 
+static_assert(ARRAY_SIZE(bpf_prog_types_xdata) == 26,
+	      "The prog_type for test 5 below needs to be updated");
 static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
 	{
 		.data = { .BPF_PROG_LOAD_data = { .prog_type = 1 } },
@@ -609,7 +612,7 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
 	},
 	{ /* 1 */
 		.data = { .BPF_PROG_LOAD_data = {
-			.prog_type = 25,
+			.prog_type = 26,
 			.insn_cnt = 0xbadc0ded,
 			.insns = 0,
 			.license = 0,
@@ -620,7 +623,7 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
 			.prog_flags = 0,
 		} },
 		.size = offsetofend(struct BPF_PROG_LOAD_struct, prog_flags),
-		.str = "prog_type=0x19 /* BPF_PROG_TYPE_??? */"
+		.str = "prog_type=0x1a /* BPF_PROG_TYPE_??? */"
 		       ", insn_cnt=3134983661, insns=NULL, license=NULL"
 		       ", log_level=42, log_size=3141592653, log_buf=NULL"
 		       ", kern_version=KERNEL_VERSION(51966, 240, 13)"
@@ -640,7 +643,7 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
 			.prog_name = "fedcba987654321",
 		} },
 		.size = offsetofend(struct BPF_PROG_LOAD_struct, prog_name),
-		.str = "prog_type=BPF_PROG_TYPE_SK_REUSEPORT"
+		.str = "prog_type=BPF_PROG_TYPE_LIRC_MODE2"
 		       ", insn_cnt=3134983661"
 		       ", insns=" BIG_ADDR("0xffffffff00000000", "NULL")
 		       ", license=" BIG_ADDR("0xffffffff00000000", "NULL")
@@ -682,6 +685,30 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
 		.print_fn = print_BPF_PROG_LOAD_attr4
 	},
 	{ /* 5 */
+		.data = { .BPF_PROG_LOAD_data = {
+			.prog_type = 25,
+			.insn_cnt = 0xbadc0ded,
+			.insns = 0xffffffff00000000,
+			.license = 0xffffffff00000000,
+			.log_level = 2718281828U,
+			.log_size = log_buf_size,
+			.log_buf = 0xffffffff00000000,
+			.kern_version = 0xcafef00d,
+			.prog_flags = 1,
+			.prog_name = "fedcba987654321",
+		} },
+		.size = offsetofend(struct BPF_PROG_LOAD_struct, prog_name),
+		.str = "prog_type=BPF_PROG_TYPE_CGROUP_SOCKOPT"
+		       ", insn_cnt=3134983661"
+		       ", insns=" BIG_ADDR("0xffffffff00000000", "NULL")
+		       ", license=" BIG_ADDR("0xffffffff00000000", "NULL")
+		       ", log_level=2718281828, log_size=4096"
+		       ", log_buf=" BIG_ADDR("0xffffffff00000000", "NULL")
+		       ", kern_version=KERNEL_VERSION(51966, 240, 13)"
+		       ", prog_flags=BPF_F_STRICT_ALIGNMENT"
+		       ", prog_name=\"fedcba987654321\"",
+	},
+	{ /* 6 */
 		.data = { .BPF_PROG_LOAD_data = {
 			.prog_flags = 2,
 			.expected_attach_type = 17,
diff --git a/tests/kernel_version.c b/tests/kernel_version.c
index e82095c6..cfe75ade 100644
--- a/tests/kernel_version.c
+++ b/tests/kernel_version.c
@@ -34,9 +34,9 @@ static void
 print_bpf_attr(void)
 {
 #if XLAT_RAW
-	printf("{prog_type=0x19"
+	printf("{prog_type=0x1a"
 #else
-	printf("{prog_type=0x19 /* BPF_PROG_TYPE_??? */"
+	printf("{prog_type=0x1a /* BPF_PROG_TYPE_??? */"
 #endif
 		", insn_cnt=3134983661"
 		", insns=NULL"
@@ -77,7 +77,7 @@ main(void)
 {
 	long ret;
 	struct BPF_PROG_LOAD_struct prog = {
-		.prog_type = 25,
+		.prog_type = 26,
 		.insn_cnt = 0xbadc0ded,
 		.insns = 0,
 		.license = 0,
diff --git a/xlat/bpf_prog_types.in b/xlat/bpf_prog_types.in
index 2d81d82d..a72f5b52 100644
--- a/xlat/bpf_prog_types.in
+++ b/xlat/bpf_prog_types.in
@@ -17,10 +17,11 @@ BPF_PROG_TYPE_SK_SKB 14
 BPF_PROG_TYPE_CGROUP_DEVICE 15
 BPF_PROG_TYPE_SK_MSG 16
 BPF_PROG_TYPE_RAW_TRACEPOINT 17
-BPF_PROG_TYPE_LWT_SEG6LOCAL 18
-BPF_PROG_TYPE_LIRC_MODE2 19
-BPF_PROG_TYPE_SK_REUSEPORT 20
-BPF_PROG_TYPE_FLOW_DISSECTOR 21
-BPF_PROG_TYPE_CGROUP_SYSCTL 22
-BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE 23
-BPF_PROG_TYPE_CGROUP_SOCKOPT 24
+BPF_PROG_TYPE_CGROUP_SOCK_ADDR 18
+BPF_PROG_TYPE_LWT_SEG6LOCAL 19
+BPF_PROG_TYPE_LIRC_MODE2 20
+BPF_PROG_TYPE_SK_REUSEPORT 21
+BPF_PROG_TYPE_FLOW_DISSECTOR 22
+BPF_PROG_TYPE_CGROUP_SYSCTL 23
+BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE 24
+BPF_PROG_TYPE_CGROUP_SOCKOPT 25
-- 
2.17.1



More information about the Strace-devel mailing list