Merge branch 'bpftool: fix feature output when helper probes fail'
Milan Landaverde says: ==================== Currently in bpftool's feature probe, we incorrectly tell the user that all of the helper functions are supported for program types where helper probing fails or is explicitly unsupported[1]: $ bpftool feature probe ... eBPF helpers supported for program type tracing: - bpf_map_lookup_elem - bpf_map_update_elem - bpf_map_delete_elem ... - bpf_redirect_neigh - bpf_check_mtu - bpf_sys_bpf - bpf_sys_close This patch adjusts bpftool to relay to the user when helper support can't be determined: $ bpftool feature probe ... eBPF helpers supported for program type lirc_mode2: Program type not supported eBPF helpers supported for program type tracing: Could not determine which helpers are available eBPF helpers supported for program type struct_opts: Could not determine which helpers are available eBPF helpers supported for program type ext: Could not determine which helpers are available Rather than imply that no helpers are available for the program type, we let the user know that helper function probing failed entirely. [1] https://lore.kernel.org/bpf/20211217171202.3352835-2-andrii@kernel.org/ ==================== Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
This commit is contained in:
commit
bfa92e0bdc
|
@ -638,7 +638,7 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,
|
||||||
|
|
||||||
res = probe_map_type_ifindex(map_type, ifindex);
|
res = probe_map_type_ifindex(map_type, ifindex);
|
||||||
} else {
|
} else {
|
||||||
res = libbpf_probe_bpf_map_type(map_type, NULL);
|
res = libbpf_probe_bpf_map_type(map_type, NULL) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Probe result depends on the success of map creation, no additional
|
/* Probe result depends on the success of map creation, no additional
|
||||||
|
@ -690,7 +690,7 @@ probe_helper_ifindex(enum bpf_func_id id, enum bpf_prog_type prog_type,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
||||||
const char *define_prefix, unsigned int id,
|
const char *define_prefix, unsigned int id,
|
||||||
const char *ptype_name, __u32 ifindex)
|
const char *ptype_name, __u32 ifindex)
|
||||||
|
@ -701,7 +701,7 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
||||||
if (ifindex)
|
if (ifindex)
|
||||||
res = probe_helper_ifindex(id, prog_type, ifindex);
|
res = probe_helper_ifindex(id, prog_type, ifindex);
|
||||||
else
|
else
|
||||||
res = libbpf_probe_bpf_helper(prog_type, id, NULL);
|
res = libbpf_probe_bpf_helper(prog_type, id, NULL) > 0;
|
||||||
#ifdef USE_LIBCAP
|
#ifdef USE_LIBCAP
|
||||||
/* Probe may succeed even if program load fails, for
|
/* Probe may succeed even if program load fails, for
|
||||||
* unprivileged users check that we did not fail because of
|
* unprivileged users check that we did not fail because of
|
||||||
|
@ -723,6 +723,8 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
||||||
if (res)
|
if (res)
|
||||||
printf("\n\t- %s", helper_name[id]);
|
printf("\n\t- %s", helper_name[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -732,6 +734,7 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
||||||
const char *ptype_name = prog_type_name[prog_type];
|
const char *ptype_name = prog_type_name[prog_type];
|
||||||
char feat_name[128];
|
char feat_name[128];
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
|
bool probe_res = false;
|
||||||
|
|
||||||
if (ifindex)
|
if (ifindex)
|
||||||
/* Only test helpers for offload-able program types */
|
/* Only test helpers for offload-able program types */
|
||||||
|
@ -764,7 +767,7 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
||||||
continue;
|
continue;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
default:
|
default:
|
||||||
probe_helper_for_progtype(prog_type, supported_type,
|
probe_res |= probe_helper_for_progtype(prog_type, supported_type,
|
||||||
define_prefix, id, ptype_name,
|
define_prefix, id, ptype_name,
|
||||||
ifindex);
|
ifindex);
|
||||||
}
|
}
|
||||||
|
@ -772,8 +775,17 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type,
|
||||||
|
|
||||||
if (json_output)
|
if (json_output)
|
||||||
jsonw_end_array(json_wtr);
|
jsonw_end_array(json_wtr);
|
||||||
else if (!define_prefix)
|
else if (!define_prefix) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
if (!probe_res) {
|
||||||
|
if (!supported_type)
|
||||||
|
printf("\tProgram type not supported\n");
|
||||||
|
else
|
||||||
|
printf("\tCould not determine which helpers are available\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue