Skip to content

Commit

Permalink
check permission before nullifying type_id's in bcc_map_create_xattr
Browse files Browse the repository at this point in the history
In the latest kernel, before trying to copy map_name and check map
key/value type id, the kernel first tried to allocate map
which may hit permission deny error due to unsufficiently
charged memory. Let us amend the retry sequence in
bcc_map_create_xattr to reflect what kernel does.

Note that retry logic can be made simpler if libbpf provides
probe logic and stores the result somewhere and bcc can examine
these results to tailor parameters without excessive retries.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Feb 16, 2019
1 parent e16aa5b commit 7d6be4f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/cc/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ int bcc_create_map_xattr(struct bpf_create_map_attr *attr, bool allow_rlimit)
attr->name = map_name;
int ret = bpf_create_map_xattr(attr);

if (ret < 0 && errno == EPERM) {
if (!allow_rlimit)
return ret;

// see note below about the rationale for this retry
struct rlimit rl = {};
if (getrlimit(RLIMIT_MEMLOCK, &rl) == 0) {
rl.rlim_max = RLIM_INFINITY;
rl.rlim_cur = rl.rlim_max;
if (setrlimit(RLIMIT_MEMLOCK, &rl) == 0)
ret = bpf_create_map_xattr(attr);
}
}

// kernel already supports btf if its loading is successful,
// but this map type may not support pretty print yet.
if (ret < 0 && attr->btf_key_type_id && errno == 524 /* ENOTSUPP */) {
Expand Down

0 comments on commit 7d6be4f

Please sign in to comment.