Skip to content

Commit a20eac0

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix also no-alu32 strobemeta selftest
Previous fix aded bpf_clamp_umax() helper use to re-validate boundaries. While that works correctly, it introduces more branches, which blows up past 1 million instructions in no-alu32 variant of strobemeta selftests. Switching len variable from u32 to u64 also fixes the issue and reduces the number of validated instructions, so use that instead. Fix this patch and bpf_clamp_umax() removed, both alu32 and no-alu32 selftests pass. Fixes: 0133c20 ("selftests/bpf: Fix strobemeta selftest regression") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent ad10c38 commit a20eac0

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

tools/testing/selftests/bpf/progs/strobemeta.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
#include <linux/types.h>
1111
#include <bpf/bpf_helpers.h>
1212

13-
#define bpf_clamp_umax(VAR, UMAX) \
14-
asm volatile ( \
15-
"if %0 <= %[max] goto +1\n" \
16-
"%0 = %[max]\n" \
17-
: "+r"(VAR) \
18-
: [max]"i"(UMAX) \
19-
)
20-
2113
typedef uint32_t pid_t;
2214
struct task_struct {};
2315

@@ -366,7 +358,7 @@ static __always_inline uint64_t read_str_var(struct strobemeta_cfg *cfg,
366358
void *payload)
367359
{
368360
void *location;
369-
uint32_t len;
361+
uint64_t len;
370362

371363
data->str_lens[idx] = 0;
372364
location = calc_location(&cfg->str_locs[idx], tls_base);
@@ -398,7 +390,7 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
398390
struct strobe_map_descr* descr = &data->map_descrs[idx];
399391
struct strobe_map_raw map;
400392
void *location;
401-
uint32_t len;
393+
uint64_t len;
402394
int i;
403395

404396
descr->tag_len = 0; /* presume no tag is set */
@@ -421,7 +413,6 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
421413

422414
len = bpf_probe_read_user_str(payload, STROBE_MAX_STR_LEN, map.tag);
423415
if (len <= STROBE_MAX_STR_LEN) {
424-
bpf_clamp_umax(len, STROBE_MAX_STR_LEN);
425416
descr->tag_len = len;
426417
payload += len;
427418
}
@@ -439,15 +430,13 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
439430
len = bpf_probe_read_user_str(payload, STROBE_MAX_STR_LEN,
440431
map.entries[i].key);
441432
if (len <= STROBE_MAX_STR_LEN) {
442-
bpf_clamp_umax(len, STROBE_MAX_STR_LEN);
443433
descr->key_lens[i] = len;
444434
payload += len;
445435
}
446436
descr->val_lens[i] = 0;
447437
len = bpf_probe_read_user_str(payload, STROBE_MAX_STR_LEN,
448438
map.entries[i].val);
449439
if (len <= STROBE_MAX_STR_LEN) {
450-
bpf_clamp_umax(len, STROBE_MAX_STR_LEN);
451440
descr->val_lens[i] = len;
452441
payload += len;
453442
}

0 commit comments

Comments
 (0)