BPF Archive on lore.kernel.org
 help / Atom feed
* [PATCH bpf] tools/bpftool: move set_max_rlimit() before __bpf_object__open_xattr()
@ 2019-05-16 17:17 Yonghong Song
  2019-05-16 18:46 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Song @ 2019-05-16 17:17 UTC (permalink / raw)
  To: bpf, netdev
  Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Yonghong Song

For a host which has a lower rlimit for max locked memory (e.g., 64KB),
the following error occurs in one of our production systems:
  # /usr/sbin/bpftool prog load /paragon/pods/52877437/home/mark.o \
    /sys/fs/bpf/paragon_mark_21 type cgroup/skb \
    map idx 0 pinned /sys/fs/bpf/paragon_map_21
  libbpf: Error in bpf_object__probe_name():Operation not permitted(1).
    Couldn't load basic 'r0 = 0' BPF program.
  Error: failed to open object file

The reason is due to low locked memory during bpf_object__probe_name()
which probes whether program name is supported in kernel or not
during __bpf_object__open_xattr().

bpftool program load already tries to relax mlock rlimit before
bpf_object__load(). Let us move set_max_rlimit() before
__bpf_object__open_xattr(), which fixed the issue here.

Fixes: 47eff61777c7 ("bpf, libbpf: introduce bpf_object__probe_caps to test BPF capabilities")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/bpf/bpftool/prog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index fc495b27f0fc..26336bad0442 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -879,6 +879,8 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
 		}
 	}
 
+	set_max_rlimit();
+
 	obj = __bpf_object__open_xattr(&attr, bpf_flags);
 	if (IS_ERR_OR_NULL(obj)) {
 		p_err("failed to open object file");
@@ -958,8 +960,6 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
 		goto err_close_obj;
 	}
 
-	set_max_rlimit();
-
 	err = bpf_object__load(obj);
 	if (err) {
 		p_err("failed to load object file");
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf] tools/bpftool: move set_max_rlimit() before __bpf_object__open_xattr()
  2019-05-16 17:17 [PATCH bpf] tools/bpftool: move set_max_rlimit() before __bpf_object__open_xattr() Yonghong Song
@ 2019-05-16 18:46 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2019-05-16 18:46 UTC (permalink / raw)
  To: Yonghong Song
  Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
	Kernel Team

On Thu, May 16, 2019 at 11:31 AM Yonghong Song <yhs@fb.com> wrote:
>
> For a host which has a lower rlimit for max locked memory (e.g., 64KB),
> the following error occurs in one of our production systems:
>   # /usr/sbin/bpftool prog load /paragon/pods/52877437/home/mark.o \
>     /sys/fs/bpf/paragon_mark_21 type cgroup/skb \
>     map idx 0 pinned /sys/fs/bpf/paragon_map_21
>   libbpf: Error in bpf_object__probe_name():Operation not permitted(1).
>     Couldn't load basic 'r0 = 0' BPF program.
>   Error: failed to open object file
>
> The reason is due to low locked memory during bpf_object__probe_name()
> which probes whether program name is supported in kernel or not
> during __bpf_object__open_xattr().
>
> bpftool program load already tries to relax mlock rlimit before
> bpf_object__load(). Let us move set_max_rlimit() before
> __bpf_object__open_xattr(), which fixed the issue here.
>
> Fixes: 47eff61777c7 ("bpf, libbpf: introduce bpf_object__probe_caps to test BPF capabilities")
> Signed-off-by: Yonghong Song <yhs@fb.com>

Applied. Thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16 17:17 [PATCH bpf] tools/bpftool: move set_max_rlimit() before __bpf_object__open_xattr() Yonghong Song
2019-05-16 18:46 ` Alexei Starovoitov

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org bpf@archiver.kernel.org
	public-inbox-index bpf


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/ public-inbox