Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66bd28d6 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Greg Kroah-Hartman
Browse files

selftests/bpf: Fix also no-alu32 strobemeta selftest



commit a20eac0af02810669e187cb623bc904908c423af upstream.

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: 0133c20480b1 ("selftests/bpf: Fix strobemeta selftest regression")
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211101230118.1273019-1-andrii@kernel.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e7ea088c
Loading
Loading
Loading
Loading
+2 −13
Original line number Original line Diff line number Diff line
@@ -10,14 +10,6 @@
#include <linux/types.h>
#include <linux/types.h>
#include "bpf_helpers.h"
#include "bpf_helpers.h"


#define bpf_clamp_umax(VAR, UMAX)					\
	asm volatile (							\
		"if %0 <= %[max] goto +1\n"				\
		"%0 = %[max]\n"						\
		: "+r"(VAR)						\
		: [max]"i"(UMAX)					\
	)

typedef uint32_t pid_t;
typedef uint32_t pid_t;
struct task_struct {};
struct task_struct {};


@@ -357,7 +349,7 @@ static __always_inline uint64_t read_str_var(struct strobemeta_cfg *cfg,
					     void *payload)
					     void *payload)
{
{
	void *location;
	void *location;
	uint32_t len;
	uint64_t len;


	data->str_lens[idx] = 0;
	data->str_lens[idx] = 0;
	location = calc_location(&cfg->str_locs[idx], tls_base);
	location = calc_location(&cfg->str_locs[idx], tls_base);
@@ -389,7 +381,7 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
	struct strobe_map_descr* descr = &data->map_descrs[idx];
	struct strobe_map_descr* descr = &data->map_descrs[idx];
	struct strobe_map_raw map;
	struct strobe_map_raw map;
	void *location;
	void *location;
	uint32_t len;
	uint64_t len;
	int i;
	int i;


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


	len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN, map.tag);
	len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN, map.tag);
	if (len <= STROBE_MAX_STR_LEN) {
	if (len <= STROBE_MAX_STR_LEN) {
		bpf_clamp_umax(len, STROBE_MAX_STR_LEN);
		descr->tag_len = len;
		descr->tag_len = len;
		payload += len;
		payload += len;
	}
	}
@@ -430,7 +421,6 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
		len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN,
		len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN,
					 map.entries[i].key);
					 map.entries[i].key);
		if (len <= STROBE_MAX_STR_LEN) {
		if (len <= STROBE_MAX_STR_LEN) {
			bpf_clamp_umax(len, STROBE_MAX_STR_LEN);
			descr->key_lens[i] = len;
			descr->key_lens[i] = len;
			payload += len;
			payload += len;
		}
		}
@@ -438,7 +428,6 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
		len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN,
		len = bpf_probe_read_str(payload, STROBE_MAX_STR_LEN,
					 map.entries[i].val);
					 map.entries[i].val);
		if (len <= STROBE_MAX_STR_LEN) {
		if (len <= STROBE_MAX_STR_LEN) {
			bpf_clamp_umax(len, STROBE_MAX_STR_LEN);
			descr->val_lens[i] = len;
			descr->val_lens[i] = len;
			payload += len;
			payload += len;
		}
		}