Browse Source

bpf: add support for new fields in BPF_PROG_TEST_RUN

* bpf_attr.h (struct BPF_PROG_TEST_RUN_struct): Add ctx_size_in,
ctx_size_out, ctx_in, and ctx_out fields.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN)): Decode these fields
introduced by Linux kernel commit v5.2-rc1~133^2~193^2~6.
* tests/bpf.c (BPF_PROG_TEST_RUN_checks): Check it.
Dmitry V. Levin 4 months ago
parent
commit
20e2868813
3 changed files with 42 additions and 1 deletions
  1. 10
    0
      bpf.c
  2. 5
    1
      bpf_attr.h
  3. 27
    0
      tests/bpf.c

+ 10
- 0
bpf.c View File

@@ -387,6 +387,16 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN)
387 387
 	PRINT_FIELD_ADDR64(", ", attr, data_out);
388 388
 	PRINT_FIELD_U(", ", attr, repeat);
389 389
 	PRINT_FIELD_U(", ", attr, duration);
390
+	/*
391
+	 * The following four fields were introduced by Linux commit
392
+	 * v5.2-rc1~133^2~193^2~6.
393
+	 */
394
+	if (len > offsetof(struct BPF_PROG_TEST_RUN_struct, ctx_size_in)) {
395
+		PRINT_FIELD_U(", ", attr, ctx_size_in);
396
+		PRINT_FIELD_U(", ", attr, ctx_size_out);
397
+		PRINT_FIELD_ADDR64(", ", attr, ctx_in);
398
+		PRINT_FIELD_ADDR64(", ", attr, ctx_out);
399
+	}
390 400
 	tprints("}");
391 401
 }
392 402
 END_BPF_CMD_DECODER(RVAL_DECODED)

+ 5
- 1
bpf_attr.h View File

@@ -172,11 +172,15 @@ struct BPF_PROG_TEST_RUN_struct /* test */ {
172 172
 	uint64_t ATTRIBUTE_ALIGNED(8) data_out;
173 173
 	uint32_t repeat;
174 174
 	uint32_t duration;
175
+	uint32_t ctx_size_in;
176
+	uint32_t ctx_size_out;
177
+	uint64_t ATTRIBUTE_ALIGNED(8) ctx_in;
178
+	uint64_t ATTRIBUTE_ALIGNED(8) ctx_out;
175 179
 };
176 180
 
177 181
 # define BPF_PROG_TEST_RUN_struct_size \
178 182
 	sizeof(struct BPF_PROG_TEST_RUN_struct)
179
-# define expected_BPF_PROG_TEST_RUN_struct_size 40
183
+# define expected_BPF_PROG_TEST_RUN_struct_size 64
180 184
 
181 185
 struct BPF_PROG_GET_NEXT_ID_struct {
182 186
 	uint32_t start_id;

+ 27
- 0
tests/bpf.c View File

@@ -819,6 +819,33 @@ static const struct bpf_attr_check BPF_PROG_TEST_RUN_checks[] = {
819 819
 		       ", data_in=0xfacef11dbadc2ded"
820 820
 		       ", data_out=0xfacef33dbadc4ded"
821 821
 		       ", repeat=4207410904, duration=4207541978}"
822
+	},
823
+	{
824
+		.data = { .BPF_PROG_TEST_RUN_data = {
825
+			.prog_fd = -1,
826
+			.retval = 0xfac1fed2,
827
+			.data_size_in = 0xfac3fed4,
828
+			.data_size_out = 0xfac5fed6,
829
+			.data_in = (uint64_t) 0xfacef11dbadc2dedULL,
830
+			.data_out = (uint64_t) 0xfacef33dbadc4dedULL,
831
+			.repeat = 0xfac7fed8,
832
+			.duration = 0xfac9feda,
833
+			.ctx_size_in = 0xfacbfedc,
834
+			.ctx_size_out = 0xfacdfede,
835
+			.ctx_in = (uint64_t) 0xfacef55dbadc6dedULL,
836
+			.ctx_out = (uint64_t) 0xfacef77dbadc8dedULL
837
+		} },
838
+		.size = offsetofend(struct BPF_PROG_TEST_RUN_struct, ctx_out),
839
+		.str = "test={prog_fd=-1, retval=4207017682"
840
+		       ", data_size_in=4207148756, data_size_out=4207279830"
841
+		       ", data_in=0xfacef11dbadc2ded"
842
+		       ", data_out=0xfacef33dbadc4ded"
843
+		       ", repeat=4207410904"
844
+		       ", duration=4207541978"
845
+		       ", ctx_size_in=4207673052"
846
+		       ", ctx_size_out=4207804126"
847
+		       ", ctx_in=0xfacef55dbadc6ded"
848
+		       ", ctx_out=0xfacef77dbadc8ded}"
822 849
 	}
823 850
 };
824 851
 

Loading…
Cancel
Save