Skip to content

Commit a11cf16

Browse files
committed
tests: runtime: Use nf_tables_newtable for module tests
nft_trans_alloc_gfp() is a static function that's called from multiple locations. This means it can be partially inlined - inlined in some places but not others. This makes the tests unreliable between different kernel and compiler verisons. Switch to nf_tables_newtable() which is used as a callback. The compiler is forced to not inline this. However, the offset on x86_64 needs to be adjusted. Dissassembly shows: ``` 000000000000a7e0 <nf_tables_newtable>: a7e0: f3 0f 1e fa endbr64 a7e4: e8 00 00 00 00 call a7e9 <nf_tables_newtable+0x9> a7e9: 41 57 push %r15 a7eb: 41 56 push %r14 ``` where 0xa7e4 is the first aligned instruction. 0xa7e4 - 0xa7e0 = 0x4, so use that. On aarch64, it seems 0x8 is still valid: ``` 000000000000e080 <nf_tables_newtable>: e080: d503201f nop e084: d503201f nop e088: d503233f paciasp e08c: d10283ff sub sp, sp, #0xa0 e090: f800865e str x30, [x18], #0x8 ``` where 0xe088 - 0xe080 = 0x8. So leave that alone.
1 parent dd18fd8 commit a11cf16

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

tests/runtime/btf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ REQUIRES_FEATURE btf
3030
WILL_FAIL
3131

3232
NAME kernel_module_attach
33-
RUN {{BPFTRACE}} -e 'fentry:nft_trans_alloc_gfp { printf("hit\n"); exit(); }'
33+
RUN {{BPFTRACE}} -e 'fentry:nf_tables_newtable { printf("hit\n"); exit(); }'
3434
AFTER nft add table bpftrace
3535
EXPECT hit
3636
REQUIRES_FEATURE fentry
@@ -39,7 +39,7 @@ REQUIRES nft --help
3939
CLEANUP nft delete table bpftrace
4040

4141
NAME kernel_module_attach_wildcard
42-
RUN {{BPFTRACE}} -e 'fentry:nf_table*:nft_trans_alloc_gfp { printf("hit\n"); exit(); }'
42+
RUN {{BPFTRACE}} -e 'fentry:nf_table*:nf_tables_newtable { printf("hit\n"); exit(); }'
4343
AFTER nft add table bpftrace
4444
EXPECT hit
4545
REQUIRES_FEATURE fentry
@@ -48,18 +48,18 @@ REQUIRES nft --help
4848
CLEANUP nft delete table bpftrace
4949

5050
NAME kernel_module_args
51-
RUN {{BPFTRACE}} -e 'fentry:nft_trans_alloc_gfp { printf("size: %d\n", args.size); exit(); }'
51+
RUN {{BPFTRACE}} -e 'fentry:nf_tables_newtable { printf("skb: %p\n", args.skb); exit(); }'
5252
AFTER nft add table bpftrace
53-
EXPECT_REGEX size: [0-9]+
53+
EXPECT_REGEX ^skb: 0x[a-f0-9]+$
5454
REQUIRES_FEATURE fentry
5555
REQUIRES lsmod | grep '^nf_tables'
5656
REQUIRES nft --help
5757
CLEANUP nft delete table bpftrace
5858

5959
NAME kernel_module_types
60-
RUN {{BPFTRACE}} -e 'fentry:nft_trans_alloc_gfp { printf("portid: %d\n", args.ctx->portid); exit(); }'
60+
RUN {{BPFTRACE}} -e 'fentry:nf_tables_newtable { printf("skb len: %d\n", args.skb->len); exit(); }'
6161
AFTER nft add table bpftrace
62-
EXPECT_REGEX portid: [0-9]+
62+
EXPECT_REGEX ^skb len: [0-9]+$
6363
REQUIRES_FEATURE fentry
6464
REQUIRES lsmod | grep '^nf_tables'
6565
REQUIRES nft --help

tests/runtime/probe

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ EXPECT_REGEX progs: [1-9][0-9]+
179179
REQUIRES bpftool
180180

181181
NAME kprobe_offset_module
182-
RUN {{BPFTRACE}} -e 'kprobe:nft_trans_alloc_gfp+0x5 { printf("hit\n"); exit(); }'
182+
RUN {{BPFTRACE}} -e 'kprobe:nf_tables_newtable+0x4 { printf("hit\n"); exit(); }'
183183
AFTER nft add table bpftrace
184184
EXPECT hit
185185
ARCH x86_64
186186
REQUIRES lsmod | grep '^nf_tables'
187187
REQUIRES nft --help
188188
CLEANUP nft delete table bpftrace
189189

190-
# Local entry point to nft_trans_alloc_gfp is located at offset of 8 bytes in ppc64 and aarch64.
190+
# Local entry point to nf_tables_newtable is located at offset of 8 bytes in ppc64 and aarch64.
191191
NAME kprobe_offset_module
192-
RUN {{BPFTRACE}} -e 'kprobe:nft_trans_alloc_gfp+0x8 { printf("hit\n"); exit(); }'
192+
RUN {{BPFTRACE}} -e 'kprobe:nf_tables_newtable+0x8 { printf("hit\n"); exit(); }'
193193
AFTER nft add table bpftrace
194194
EXPECT hit
195195
ARCH ppc64|ppc64le|aarch64

0 commit comments

Comments
 (0)