Commit 128dac5f authored by Andrii Nakryiko's avatar Andrii Nakryiko

Merge branch 'bpf: Fix strict mode calculation'

Mauricio Vásquez <mauricio@kinvolk.io> says:

====================

This series fixes a bad calculation of strict mode in two places. It
also updates libbpf to make it easier for the users to disable a
specific LIBBPF_STRICT_* flag.

v1 -> v2:
- remove check in libbpf_set_strict_mode()
- split in different commits

v1: https://lore.kernel.org/bpf/20220204220435.301896-1-mauricio@kinvolk.io/
====================
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parents e91d280c 2b9e2ead
......@@ -478,14 +478,11 @@ int main(int argc, char **argv)
}
if (!legacy_libbpf) {
enum libbpf_strict_mode mode;
/* Allow legacy map definitions for skeleton generation.
* It will still be rejected if users use LIBBPF_STRICT_ALL
* mode for loading generated skeleton.
*/
mode = (__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
ret = libbpf_set_strict_mode(mode);
ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
if (ret)
p_err("failed to enable libbpf strict mode: %d", ret);
}
......
......@@ -156,14 +156,6 @@ enum libbpf_strict_mode libbpf_mode = LIBBPF_STRICT_NONE;
int libbpf_set_strict_mode(enum libbpf_strict_mode mode)
{
/* __LIBBPF_STRICT_LAST is the last power-of-2 value used + 1, so to
* get all possible values we compensate last +1, and then (2*x - 1)
* to get the bit mask
*/
if (mode != LIBBPF_STRICT_ALL
&& (mode & ~((__LIBBPF_STRICT_LAST - 1) * 2 - 1)))
return errno = EINVAL, -EINVAL;
libbpf_mode = mode;
return 0;
}
......
......@@ -4580,7 +4580,7 @@ static void do_test_file(unsigned int test_num)
btf_ext__free(btf_ext);
/* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
libbpf_set_strict_mode((__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS);
libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
obj = bpf_object__open(test->file);
err = libbpf_get_error(obj);
if (CHECK(err, "obj: %d", err))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment