All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups
@ 2022-04-03 14:42 Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor Yafang Shao
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

We have switched to memcg based memory accouting and thus the rlimit is
not needn't any more. LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK is introduced in
libbpf for backward compatibility, so we can use it instead now.

v2: use libbpf_set_strict_mode instead. (Andrii)
v1: https://lore.kernel.org/bpf/20220320060815.7716-2-laoar.shao@gmail.com/

Yafang Shao (9):
  bpf: selftests: Use libbpf 1.0 API mode in bpf constructor
  bpf: selftests: Use bpf strict all ctor in xdping
  bpf: selftests: Use bpf strict all ctor in xdpxceiver
  bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in
    xdpsock_user
  bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xsk_fwd
  bpf: runqslower: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL
  bpf: bpftool: Remove useless return value of libbpf_set_strict_mode
  bpf: bpftool: Set LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK for legacy libbpf
  bpf: bpftool: Remove useless rlimit setting

 samples/bpf/xdpsock_user.c               |  9 ++------
 samples/bpf/xsk_fwd.c                    |  7 ++-----
 tools/bpf/bpftool/common.c               |  7 -------
 tools/bpf/bpftool/feature.c              |  2 --
 tools/bpf/bpftool/main.c                 |  6 +++---
 tools/bpf/bpftool/main.h                 |  2 --
 tools/bpf/bpftool/map.c                  |  2 --
 tools/bpf/bpftool/pids.c                 |  1 -
 tools/bpf/bpftool/prog.c                 |  3 ---
 tools/bpf/bpftool/struct_ops.c           |  2 --
 tools/bpf/runqslower/runqslower.c        | 17 ++--------------
 tools/testing/selftests/bpf/bpf_rlimit.h | 26 +++---------------------
 tools/testing/selftests/bpf/xdping.c     |  8 +-------
 tools/testing/selftests/bpf/xdpxceiver.c |  7 ++-----
 14 files changed, 15 insertions(+), 84 deletions(-)

-- 
2.17.1


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

* [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-04  1:24   ` Andrii Nakryiko
  2022-04-03 14:42 ` [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping Yafang Shao
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

In libbpf 1.0 API mode, it will bump rlimit automatically if there's no
memcg-basaed accounting, so we can use libbpf 1.0 API mode instead in case
we want to run it in an old kernel.

The constructor is renamed to bpf_strict_all_ctor().

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/testing/selftests/bpf/bpf_rlimit.h | 26 +++---------------------
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/tools/testing/selftests/bpf/bpf_rlimit.h b/tools/testing/selftests/bpf/bpf_rlimit.h
index 9dac9b30f8ef..d050f7d0bb5c 100644
--- a/tools/testing/selftests/bpf/bpf_rlimit.h
+++ b/tools/testing/selftests/bpf/bpf_rlimit.h
@@ -1,28 +1,8 @@
 #include <sys/resource.h>
 #include <stdio.h>
 
-static  __attribute__((constructor)) void bpf_rlimit_ctor(void)
+static  __attribute__((constructor)) void bpf_strict_all_ctor(void)
 {
-	struct rlimit rlim_old, rlim_new = {
-		.rlim_cur	= RLIM_INFINITY,
-		.rlim_max	= RLIM_INFINITY,
-	};
-
-	getrlimit(RLIMIT_MEMLOCK, &rlim_old);
-	/* For the sake of running the test cases, we temporarily
-	 * set rlimit to infinity in order for kernel to focus on
-	 * errors from actual test cases and not getting noise
-	 * from hitting memlock limits. The limit is on per-process
-	 * basis and not a global one, hence destructor not really
-	 * needed here.
-	 */
-	if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) {
-		perror("Unable to lift memlock rlimit");
-		/* Trying out lower limit, but expect potential test
-		 * case failures from this!
-		 */
-		rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
-		rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
-		setrlimit(RLIMIT_MEMLOCK, &rlim_new);
-	}
+	/* Use libbpf 1.0 API mode */
+	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
 }
-- 
2.17.1


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

* [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-04  1:26   ` Andrii Nakryiko
  2022-04-03 14:42 ` [PATCH bpf-next v2 3/9] bpf: selftests: Use bpf strict all ctor in xdpxceiver Yafang Shao
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

Aoid using the deprecated RLIMIT_MEMLOCK.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/testing/selftests/bpf/xdping.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/tools/testing/selftests/bpf/xdping.c b/tools/testing/selftests/bpf/xdping.c
index c567856fd1bc..46ba0d7f73e8 100644
--- a/tools/testing/selftests/bpf/xdping.c
+++ b/tools/testing/selftests/bpf/xdping.c
@@ -12,7 +12,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <libgen.h>
-#include <sys/resource.h>
 #include <net/if.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -20,6 +19,7 @@
 
 #include "bpf/bpf.h"
 #include "bpf/libbpf.h"
+#include "bpf_rlimit.h"
 
 #include "xdping.h"
 #include "testing_helpers.h"
@@ -89,7 +89,6 @@ int main(int argc, char **argv)
 {
 	__u32 mode_flags = XDP_FLAGS_DRV_MODE | XDP_FLAGS_SKB_MODE;
 	struct addrinfo *a, hints = { .ai_family = AF_INET };
-	struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
 	__u16 count = XDPING_DEFAULT_COUNT;
 	struct pinginfo pinginfo = { 0 };
 	const char *optstr = "c:I:NsS";
@@ -167,11 +166,6 @@ int main(int argc, char **argv)
 		freeaddrinfo(a);
 	}
 
-	if (setrlimit(RLIMIT_MEMLOCK, &r)) {
-		perror("setrlimit(RLIMIT_MEMLOCK)");
-		return 1;
-	}
-
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
 
 	if (bpf_prog_test_load(filename, BPF_PROG_TYPE_XDP, &obj, &prog_fd)) {
-- 
2.17.1


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

* [PATCH bpf-next v2 3/9] bpf: selftests: Use bpf strict all ctor in xdpxceiver
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 4/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xdpsock_user Yafang Shao
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

Avoid using the deprecated RLIMIT_MEMLOCK.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/testing/selftests/bpf/xdpxceiver.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index 5f8296d29e77..1be14e0c236e 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -90,13 +90,14 @@
 #include <string.h>
 #include <stddef.h>
 #include <sys/mman.h>
-#include <sys/resource.h>
 #include <sys/types.h>
 #include <sys/queue.h>
 #include <time.h>
 #include <unistd.h>
 #include <stdatomic.h>
 #include <bpf/xsk.h>
+
+#include "bpf_rlimit.h"
 #include "xdpxceiver.h"
 #include "../kselftest.h"
 
@@ -1448,15 +1449,11 @@ static void ifobject_delete(struct ifobject *ifobj)
 
 int main(int argc, char **argv)
 {
-	struct rlimit _rlim = { RLIM_INFINITY, RLIM_INFINITY };
 	struct pkt_stream *pkt_stream_default;
 	struct ifobject *ifobj_tx, *ifobj_rx;
 	struct test_spec test;
 	u32 i, j;
 
-	if (setrlimit(RLIMIT_MEMLOCK, &_rlim))
-		exit_with_error(errno);
-
 	ifobj_tx = ifobject_create();
 	if (!ifobj_tx)
 		exit_with_error(ENOMEM);
-- 
2.17.1


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

* [PATCH bpf-next v2 4/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xdpsock_user
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
                   ` (2 preceding siblings ...)
  2022-04-03 14:42 ` [PATCH bpf-next v2 3/9] bpf: selftests: Use bpf strict all ctor in xdpxceiver Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 5/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xsk_fwd Yafang Shao
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

Avoid using the deprecated RLIMIT_MEMLOCK.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 samples/bpf/xdpsock_user.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 6f3fe30ad283..be7d2572e3e6 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -25,7 +25,6 @@
 #include <string.h>
 #include <sys/capability.h>
 #include <sys/mman.h>
-#include <sys/resource.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
@@ -1886,7 +1885,6 @@ int main(int argc, char **argv)
 {
 	struct __user_cap_header_struct hdr = { _LINUX_CAPABILITY_VERSION_3, 0 };
 	struct __user_cap_data_struct data[2] = { { 0 } };
-	struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
 	bool rx = false, tx = false;
 	struct sched_param schparam;
 	struct xsk_umem_info *umem;
@@ -1917,11 +1915,8 @@ int main(int argc, char **argv)
 				data[1].effective, data[1].inheritable, data[1].permitted);
 		}
 	} else {
-		if (setrlimit(RLIMIT_MEMLOCK, &r)) {
-			fprintf(stderr, "ERROR: setrlimit(RLIMIT_MEMLOCK) \"%s\"\n",
-				strerror(errno));
-			exit(EXIT_FAILURE);
-		}
+		/* Use libbpf 1.0 API mode */
+		libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
 
 		if (opt_num_xsks > 1)
 			load_xdp_program(argv, &obj);
-- 
2.17.1


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

* [PATCH bpf-next v2 5/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xsk_fwd
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
                   ` (3 preceding siblings ...)
  2022-04-03 14:42 ` [PATCH bpf-next v2 4/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xdpsock_user Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 6/9] bpf: runqslower: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL Yafang Shao
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

Avoid using the deprecated RLIMIT_MEMLOCK.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 samples/bpf/xsk_fwd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/samples/bpf/xsk_fwd.c b/samples/bpf/xsk_fwd.c
index 2220509588a0..2324e18ccc7e 100644
--- a/samples/bpf/xsk_fwd.c
+++ b/samples/bpf/xsk_fwd.c
@@ -10,7 +10,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
-#include <sys/resource.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <time.h>
@@ -131,7 +130,6 @@ static struct bpool *
 bpool_init(struct bpool_params *params,
 	   struct xsk_umem_config *umem_cfg)
 {
-	struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
 	u64 n_slabs, n_slabs_reserved, n_buffers, n_buffers_reserved;
 	u64 slabs_size, slabs_reserved_size;
 	u64 buffers_size, buffers_reserved_size;
@@ -140,9 +138,8 @@ bpool_init(struct bpool_params *params,
 	u8 *p;
 	int status;
 
-	/* mmap prep. */
-	if (setrlimit(RLIMIT_MEMLOCK, &r))
-		return NULL;
+	/* Use libbpf 1.0 API mode */
+	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
 
 	/* bpool internals dimensioning. */
 	n_slabs = (params->n_buffers + params->n_buffers_per_slab - 1) /
-- 
2.17.1


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

* [PATCH bpf-next v2 6/9] bpf: runqslower: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
                   ` (4 preceding siblings ...)
  2022-04-03 14:42 ` [PATCH bpf-next v2 5/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xsk_fwd Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 7/9] bpf: bpftool: Remove useless return value of libbpf_set_strict_mode Yafang Shao
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

Avoid using the deprecated RLIMIT_MEMLOCK.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/bpf/runqslower/runqslower.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/tools/bpf/runqslower/runqslower.c b/tools/bpf/runqslower/runqslower.c
index d78f4148597f..3439ded327f8 100644
--- a/tools/bpf/runqslower/runqslower.c
+++ b/tools/bpf/runqslower/runqslower.c
@@ -88,16 +88,6 @@ int libbpf_print_fn(enum libbpf_print_level level,
 	return vfprintf(stderr, format, args);
 }
 
-static int bump_memlock_rlimit(void)
-{
-	struct rlimit rlim_new = {
-		.rlim_cur	= RLIM_INFINITY,
-		.rlim_max	= RLIM_INFINITY,
-	};
-
-	return setrlimit(RLIMIT_MEMLOCK, &rlim_new);
-}
-
 void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
 {
 	const struct runq_event *e = data;
@@ -133,11 +123,8 @@ int main(int argc, char **argv)
 
 	libbpf_set_print(libbpf_print_fn);
 
-	err = bump_memlock_rlimit();
-	if (err) {
-		fprintf(stderr, "failed to increase rlimit: %d", err);
-		return 1;
-	}
+	/* Use libbpf 1.0 API mode */
+	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
 
 	obj = runqslower_bpf__open();
 	if (!obj) {
-- 
2.17.1


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

* [PATCH bpf-next v2 7/9] bpf: bpftool: Remove useless return value of libbpf_set_strict_mode
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
                   ` (5 preceding siblings ...)
  2022-04-03 14:42 ` [PATCH bpf-next v2 6/9] bpf: runqslower: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-03 14:42 ` [PATCH bpf-next v2 8/9] bpf: bpftool: Set LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK for legacy libbpf Yafang Shao
  2022-04-03 14:43 ` [PATCH bpf-next v2 9/9] bpf: bpftool: Remove useless rlimit setting Yafang Shao
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

libbpf_set_strict_mode alwasy return 0, so we don't need to check whether
the return value is 0 or not.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/bpf/bpftool/main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index e81227761f5d..451cefc2d0da 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -507,9 +507,7 @@ int main(int argc, char **argv)
 		 * It will still be rejected if users use LIBBPF_STRICT_ALL
 		 * mode for loading generated skeleton.
 		 */
-		ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
-		if (ret)
-			p_err("failed to enable libbpf strict mode: %d", ret);
+		libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
 	}
 
 	argc -= optind;
-- 
2.17.1


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

* [PATCH bpf-next v2 8/9] bpf: bpftool: Set LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK for legacy libbpf
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
                   ` (6 preceding siblings ...)
  2022-04-03 14:42 ` [PATCH bpf-next v2 7/9] bpf: bpftool: Remove useless return value of libbpf_set_strict_mode Yafang Shao
@ 2022-04-03 14:42 ` Yafang Shao
  2022-04-03 14:43 ` [PATCH bpf-next v2 9/9] bpf: bpftool: Remove useless rlimit setting Yafang Shao
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:42 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK has already been set for non legacy
libbpf, let's also set it for legacy libbpf then we can avoid setting the
deprecatred RLIMIT_MEMLOCK directly.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/bpf/bpftool/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 451cefc2d0da..9062ef2b8767 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -508,6 +508,8 @@ int main(int argc, char **argv)
 		 * mode for loading generated skeleton.
 		 */
 		libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
+	} else {
+		libbpf_set_strict_mode(LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK);
 	}
 
 	argc -= optind;
-- 
2.17.1


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

* [PATCH bpf-next v2 9/9] bpf: bpftool: Remove useless rlimit setting
  2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
                   ` (7 preceding siblings ...)
  2022-04-03 14:42 ` [PATCH bpf-next v2 8/9] bpf: bpftool: Set LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK for legacy libbpf Yafang Shao
@ 2022-04-03 14:43 ` Yafang Shao
  8 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-03 14:43 UTC (permalink / raw)
  To: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh
  Cc: netdev, bpf, Yafang Shao

As we have already set LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK, we don't need to
bump RLIMIT_MEMLOCK any more.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/bpf/bpftool/common.c     | 7 -------
 tools/bpf/bpftool/feature.c    | 2 --
 tools/bpf/bpftool/main.h       | 2 --
 tools/bpf/bpftool/map.c        | 2 --
 tools/bpf/bpftool/pids.c       | 1 -
 tools/bpf/bpftool/prog.c       | 3 ---
 tools/bpf/bpftool/struct_ops.c | 2 --
 7 files changed, 19 deletions(-)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 0c1e06cf50b9..6b1e67851690 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -119,13 +119,6 @@ static bool is_bpffs(char *path)
 	return (unsigned long)st_fs.f_type == BPF_FS_MAGIC;
 }
 
-void set_max_rlimit(void)
-{
-	struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
-
-	setrlimit(RLIMIT_MEMLOCK, &rinf);
-}
-
 static int
 mnt_fs(const char *target, const char *type, char *buff, size_t bufflen)
 {
diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index 290998c82de1..19c484e63da4 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -1136,8 +1136,6 @@ static int do_probe(int argc, char **argv)
 	__u32 ifindex = 0;
 	char *ifname;
 
-	set_max_rlimit();
-
 	while (argc) {
 		if (is_prefix(*argv, "kernel")) {
 			if (target != COMPONENT_UNSPEC) {
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 6e9277ffc68c..aa99ffab451a 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -102,8 +102,6 @@ int detect_common_prefix(const char *arg, ...);
 void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
 void usage(void) __noreturn;
 
-void set_max_rlimit(void);
-
 int mount_tracefs(const char *target);
 
 struct obj_ref {
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index c26378f20831..877387ef79c7 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -1342,8 +1342,6 @@ static int do_create(int argc, char **argv)
 		goto exit;
 	}
 
-	set_max_rlimit();
-
 	fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr);
 	if (fd < 0) {
 		p_err("map create failed: %s", strerror(errno));
diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c
index bb6c969a114a..e2d00d3cd868 100644
--- a/tools/bpf/bpftool/pids.c
+++ b/tools/bpf/bpftool/pids.c
@@ -108,7 +108,6 @@ int build_obj_refs_table(struct hashmap **map, enum bpf_obj_type type)
 		p_err("failed to create hashmap for PID references");
 		return -1;
 	}
-	set_max_rlimit();
 
 	skel = pid_iter_bpf__open();
 	if (!skel) {
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index bc4e05542c2b..d5ba3b6f30ae 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -1603,8 +1603,6 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
 		}
 	}
 
-	set_max_rlimit();
-
 	if (verifier_logs)
 		/* log_level1 + log_level2 + stats, but not stable UAPI */
 		open_opts.kernel_log_level = 1 + 2 + 4;
@@ -2302,7 +2300,6 @@ static int do_profile(int argc, char **argv)
 		}
 	}
 
-	set_max_rlimit();
 	err = profiler_bpf__load(profile_obj);
 	if (err) {
 		p_err("failed to load profile_obj");
diff --git a/tools/bpf/bpftool/struct_ops.c b/tools/bpf/bpftool/struct_ops.c
index e08a6ff2866c..2535f079ed67 100644
--- a/tools/bpf/bpftool/struct_ops.c
+++ b/tools/bpf/bpftool/struct_ops.c
@@ -501,8 +501,6 @@ static int do_register(int argc, char **argv)
 	if (libbpf_get_error(obj))
 		return -1;
 
-	set_max_rlimit();
-
 	if (bpf_object__load(obj)) {
 		bpf_object__close(obj);
 		return -1;
-- 
2.17.1


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

* Re: [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor
  2022-04-03 14:42 ` [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor Yafang Shao
@ 2022-04-04  1:24   ` Andrii Nakryiko
  2022-04-04  1:26     ` Andrii Nakryiko
  2022-04-04  6:44     ` Yafang Shao
  0 siblings, 2 replies; 16+ messages in thread
From: Andrii Nakryiko @ 2022-04-04  1:24 UTC (permalink / raw)
  To: Yafang Shao
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Sun, Apr 3, 2022 at 7:43 AM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> In libbpf 1.0 API mode, it will bump rlimit automatically if there's no
> memcg-basaed accounting, so we can use libbpf 1.0 API mode instead in case
> we want to run it in an old kernel.
>
> The constructor is renamed to bpf_strict_all_ctor().
>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  tools/testing/selftests/bpf/bpf_rlimit.h | 26 +++---------------------
>  1 file changed, 3 insertions(+), 23 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/bpf_rlimit.h b/tools/testing/selftests/bpf/bpf_rlimit.h
> index 9dac9b30f8ef..d050f7d0bb5c 100644
> --- a/tools/testing/selftests/bpf/bpf_rlimit.h
> +++ b/tools/testing/selftests/bpf/bpf_rlimit.h
> @@ -1,28 +1,8 @@
>  #include <sys/resource.h>
>  #include <stdio.h>
>
> -static  __attribute__((constructor)) void bpf_rlimit_ctor(void)
> +static  __attribute__((constructor)) void bpf_strict_all_ctor(void)

well, no, let's get rid of bpf_rlimit.h altogether. There is no need
for constructor magic when you can have an explicit
libbpf_set_strict_mode(LIBBPF_STRICT_ALL).

>  {
> -       struct rlimit rlim_old, rlim_new = {
> -               .rlim_cur       = RLIM_INFINITY,
> -               .rlim_max       = RLIM_INFINITY,
> -       };
> -
> -       getrlimit(RLIMIT_MEMLOCK, &rlim_old);
> -       /* For the sake of running the test cases, we temporarily
> -        * set rlimit to infinity in order for kernel to focus on
> -        * errors from actual test cases and not getting noise
> -        * from hitting memlock limits. The limit is on per-process
> -        * basis and not a global one, hence destructor not really
> -        * needed here.
> -        */
> -       if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) {
> -               perror("Unable to lift memlock rlimit");
> -               /* Trying out lower limit, but expect potential test
> -                * case failures from this!
> -                */
> -               rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
> -               rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
> -               setrlimit(RLIMIT_MEMLOCK, &rlim_new);
> -       }
> +       /* Use libbpf 1.0 API mode */
> +       libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
>  }
> --
> 2.17.1
>

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

* Re: [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping
  2022-04-03 14:42 ` [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping Yafang Shao
@ 2022-04-04  1:26   ` Andrii Nakryiko
  2022-04-04  6:46     ` Yafang Shao
  0 siblings, 1 reply; 16+ messages in thread
From: Andrii Nakryiko @ 2022-04-04  1:26 UTC (permalink / raw)
  To: Yafang Shao
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Sun, Apr 3, 2022 at 7:43 AM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> Aoid using the deprecated RLIMIT_MEMLOCK.

typo: avoid

>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  tools/testing/selftests/bpf/xdping.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
>

[...]

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

* Re: [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor
  2022-04-04  1:24   ` Andrii Nakryiko
@ 2022-04-04  1:26     ` Andrii Nakryiko
  2022-04-04  6:45       ` Yafang Shao
  2022-04-04  6:44     ` Yafang Shao
  1 sibling, 1 reply; 16+ messages in thread
From: Andrii Nakryiko @ 2022-04-04  1:26 UTC (permalink / raw)
  To: Yafang Shao
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Sun, Apr 3, 2022 at 6:24 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sun, Apr 3, 2022 at 7:43 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > In libbpf 1.0 API mode, it will bump rlimit automatically if there's no
> > memcg-basaed accounting, so we can use libbpf 1.0 API mode instead in case

also very eye catching typo: basaed -> based

> > we want to run it in an old kernel.
> >
> > The constructor is renamed to bpf_strict_all_ctor().
> >
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> >  tools/testing/selftests/bpf/bpf_rlimit.h | 26 +++---------------------
> >  1 file changed, 3 insertions(+), 23 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/bpf_rlimit.h b/tools/testing/selftests/bpf/bpf_rlimit.h
> > index 9dac9b30f8ef..d050f7d0bb5c 100644
> > --- a/tools/testing/selftests/bpf/bpf_rlimit.h
> > +++ b/tools/testing/selftests/bpf/bpf_rlimit.h
> > @@ -1,28 +1,8 @@
> >  #include <sys/resource.h>
> >  #include <stdio.h>
> >
> > -static  __attribute__((constructor)) void bpf_rlimit_ctor(void)
> > +static  __attribute__((constructor)) void bpf_strict_all_ctor(void)
>
> well, no, let's get rid of bpf_rlimit.h altogether. There is no need
> for constructor magic when you can have an explicit
> libbpf_set_strict_mode(LIBBPF_STRICT_ALL).
>
> >  {
> > -       struct rlimit rlim_old, rlim_new = {
> > -               .rlim_cur       = RLIM_INFINITY,
> > -               .rlim_max       = RLIM_INFINITY,
> > -       };
> > -
> > -       getrlimit(RLIMIT_MEMLOCK, &rlim_old);
> > -       /* For the sake of running the test cases, we temporarily
> > -        * set rlimit to infinity in order for kernel to focus on
> > -        * errors from actual test cases and not getting noise
> > -        * from hitting memlock limits. The limit is on per-process
> > -        * basis and not a global one, hence destructor not really
> > -        * needed here.
> > -        */
> > -       if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) {
> > -               perror("Unable to lift memlock rlimit");
> > -               /* Trying out lower limit, but expect potential test
> > -                * case failures from this!
> > -                */
> > -               rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
> > -               rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
> > -               setrlimit(RLIMIT_MEMLOCK, &rlim_new);
> > -       }
> > +       /* Use libbpf 1.0 API mode */
> > +       libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
> >  }
> > --
> > 2.17.1
> >

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

* Re: [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor
  2022-04-04  1:24   ` Andrii Nakryiko
  2022-04-04  1:26     ` Andrii Nakryiko
@ 2022-04-04  6:44     ` Yafang Shao
  1 sibling, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-04  6:44 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Mon, Apr 4, 2022 at 9:24 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sun, Apr 3, 2022 at 7:43 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > In libbpf 1.0 API mode, it will bump rlimit automatically if there's no
> > memcg-basaed accounting, so we can use libbpf 1.0 API mode instead in case
> > we want to run it in an old kernel.
> >
> > The constructor is renamed to bpf_strict_all_ctor().
> >
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> >  tools/testing/selftests/bpf/bpf_rlimit.h | 26 +++---------------------
> >  1 file changed, 3 insertions(+), 23 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/bpf_rlimit.h b/tools/testing/selftests/bpf/bpf_rlimit.h
> > index 9dac9b30f8ef..d050f7d0bb5c 100644
> > --- a/tools/testing/selftests/bpf/bpf_rlimit.h
> > +++ b/tools/testing/selftests/bpf/bpf_rlimit.h
> > @@ -1,28 +1,8 @@
> >  #include <sys/resource.h>
> >  #include <stdio.h>
> >
> > -static  __attribute__((constructor)) void bpf_rlimit_ctor(void)
> > +static  __attribute__((constructor)) void bpf_strict_all_ctor(void)
>
> well, no, let's get rid of bpf_rlimit.h altogether. There is no need
> for constructor magic when you can have an explicit
> libbpf_set_strict_mode(LIBBPF_STRICT_ALL).
>

Sure, I will do it.

> >  {
> > -       struct rlimit rlim_old, rlim_new = {
> > -               .rlim_cur       = RLIM_INFINITY,
> > -               .rlim_max       = RLIM_INFINITY,
> > -       };
> > -
> > -       getrlimit(RLIMIT_MEMLOCK, &rlim_old);
> > -       /* For the sake of running the test cases, we temporarily
> > -        * set rlimit to infinity in order for kernel to focus on
> > -        * errors from actual test cases and not getting noise
> > -        * from hitting memlock limits. The limit is on per-process
> > -        * basis and not a global one, hence destructor not really
> > -        * needed here.
> > -        */
> > -       if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) {
> > -               perror("Unable to lift memlock rlimit");
> > -               /* Trying out lower limit, but expect potential test
> > -                * case failures from this!
> > -                */
> > -               rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
> > -               rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
> > -               setrlimit(RLIMIT_MEMLOCK, &rlim_new);
> > -       }
> > +       /* Use libbpf 1.0 API mode */
> > +       libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
> >  }
> > --
> > 2.17.1
> >

-- 
Thanks
Yafang

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

* Re: [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor
  2022-04-04  1:26     ` Andrii Nakryiko
@ 2022-04-04  6:45       ` Yafang Shao
  0 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-04  6:45 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Mon, Apr 4, 2022 at 9:27 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sun, Apr 3, 2022 at 6:24 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Sun, Apr 3, 2022 at 7:43 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> > >
> > > In libbpf 1.0 API mode, it will bump rlimit automatically if there's no
> > > memcg-basaed accounting, so we can use libbpf 1.0 API mode instead in case
>
> also very eye catching typo: basaed -> based

Thanks for pointing this out. I will be more careful.

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

* Re: [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping
  2022-04-04  1:26   ` Andrii Nakryiko
@ 2022-04-04  6:46     ` Yafang Shao
  0 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2022-04-04  6:46 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Mon, Apr 4, 2022 at 9:26 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sun, Apr 3, 2022 at 7:43 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > Aoid using the deprecated RLIMIT_MEMLOCK.
>
> typo: avoid

Thanks again.


-- 
Thanks
Yafang

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

end of thread, other threads:[~2022-04-04  6:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 14:42 [PATCH bpf-next v2 0/9] bpf: RLIMIT_MEMLOCK cleanups Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 1/9] bpf: selftests: Use libbpf 1.0 API mode in bpf constructor Yafang Shao
2022-04-04  1:24   ` Andrii Nakryiko
2022-04-04  1:26     ` Andrii Nakryiko
2022-04-04  6:45       ` Yafang Shao
2022-04-04  6:44     ` Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 2/9] bpf: selftests: Use bpf strict all ctor in xdping Yafang Shao
2022-04-04  1:26   ` Andrii Nakryiko
2022-04-04  6:46     ` Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 3/9] bpf: selftests: Use bpf strict all ctor in xdpxceiver Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 4/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xdpsock_user Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 5/9] bpf: samples: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL in xsk_fwd Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 6/9] bpf: runqslower: Replace RLIMIT_MEMLOCK with LIBBPF_STRICT_ALL Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 7/9] bpf: bpftool: Remove useless return value of libbpf_set_strict_mode Yafang Shao
2022-04-03 14:42 ` [PATCH bpf-next v2 8/9] bpf: bpftool: Set LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK for legacy libbpf Yafang Shao
2022-04-03 14:43 ` [PATCH bpf-next v2 9/9] bpf: bpftool: Remove useless rlimit setting Yafang Shao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.