diff mbox series

[bpf-next,3/4] bpf: export some cgroup storages allocation helpers for reusing

Message ID 20200713182520.97606-4-zeil@yandex-team.ru
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: cgroup skb improvements for bpf_prog_test_run | expand

Commit Message

Dmitry Yakunin July 13, 2020, 6:25 p.m. UTC
This patch exports bpf_cgroup_storages_alloc and bpf_cgroup_storages_free
helpers to the header file and reuses them in bpf_test_run.

Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
---
 include/linux/bpf-cgroup.h | 27 +++++++++++++++++++++++++++
 kernel/bpf/cgroup.c        | 25 -------------------------
 net/bpf/test_run.c         | 16 ++++------------
 3 files changed, 31 insertions(+), 37 deletions(-)

Comments

kernel test robot July 13, 2020, 10:17 p.m. UTC | #1
Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Dmitry-Yakunin/bpf-cgroup-skb-improvements-for-bpf_prog_test_run/20200714-022728
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: x86_64-rhel-7.6 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   net/bpf/test_run.c: In function 'bpf_test_run':
>> net/bpf/test_run.c:26:8: error: implicit declaration of function 'bpf_cgroup_storages_alloc'; did you mean 'bpf_cgroup_storage_alloc'? [-Werror=implicit-function-declaration]
      26 |  ret = bpf_cgroup_storages_alloc(storage, prog);
         |        ^~~~~~~~~~~~~~~~~~~~~~~~~
         |        bpf_cgroup_storage_alloc
>> net/bpf/test_run.c:68:2: error: implicit declaration of function 'bpf_cgroup_storages_free'; did you mean 'bpf_cgroup_storage_free'? [-Werror=implicit-function-declaration]
      68 |  bpf_cgroup_storages_free(storage);
         |  ^~~~~~~~~~~~~~~~~~~~~~~~
         |  bpf_cgroup_storage_free
   cc1: some warnings being treated as errors

vim +26 net/bpf/test_run.c

    17	
    18	static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
    19				u32 *retval, u32 *time, bool xdp)
    20	{
    21		struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = { NULL };
    22		u64 time_start, time_spent = 0;
    23		int ret = 0;
    24		u32 i;
    25	
  > 26		ret = bpf_cgroup_storages_alloc(storage, prog);
    27		if (ret)
    28			return ret;
    29	
    30		if (!repeat)
    31			repeat = 1;
    32	
    33		rcu_read_lock();
    34		migrate_disable();
    35		time_start = ktime_get_ns();
    36		for (i = 0; i < repeat; i++) {
    37			bpf_cgroup_storage_set(storage);
    38	
    39			if (xdp)
    40				*retval = bpf_prog_run_xdp(prog, ctx);
    41			else
    42				*retval = BPF_PROG_RUN(prog, ctx);
    43	
    44			if (signal_pending(current)) {
    45				ret = -EINTR;
    46				break;
    47			}
    48	
    49			if (need_resched()) {
    50				time_spent += ktime_get_ns() - time_start;
    51				migrate_enable();
    52				rcu_read_unlock();
    53	
    54				cond_resched();
    55	
    56				rcu_read_lock();
    57				migrate_disable();
    58				time_start = ktime_get_ns();
    59			}
    60		}
    61		time_spent += ktime_get_ns() - time_start;
    62		migrate_enable();
    63		rcu_read_unlock();
    64	
    65		do_div(time_spent, repeat);
    66		*time = time_spent > U32_MAX ? U32_MAX : (u32)time_spent;
    67	
  > 68		bpf_cgroup_storages_free(storage);
    69	
    70		return ret;
    71	}
    72	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot July 14, 2020, 3:25 a.m. UTC | #2
Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Dmitry-Yakunin/bpf-cgroup-skb-improvements-for-bpf_prog_test_run/20200714-022728
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: mips-randconfig-r034-20200713 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> net/bpf/test_run.c:26:8: error: implicit declaration of function 'bpf_cgroup_storages_alloc' [-Werror,-Wimplicit-function-declaration]
           ret = bpf_cgroup_storages_alloc(storage, prog);
                 ^
   net/bpf/test_run.c:26:8: note: did you mean 'bpf_cgroup_storage_alloc'?
   include/linux/bpf-cgroup.h:415:42: note: 'bpf_cgroup_storage_alloc' declared here
   static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(
                                            ^
>> net/bpf/test_run.c:68:2: error: implicit declaration of function 'bpf_cgroup_storages_free' [-Werror,-Wimplicit-function-declaration]
           bpf_cgroup_storages_free(storage);
           ^
   net/bpf/test_run.c:68:2: note: did you mean 'bpf_cgroup_storage_free'?
   include/linux/bpf-cgroup.h:417:20: note: 'bpf_cgroup_storage_free' declared here
   static inline void bpf_cgroup_storage_free(
                      ^
   net/bpf/test_run.c:112:14: warning: no previous prototype for function 'bpf_fentry_test1' [-Wmissing-prototypes]
   int noinline bpf_fentry_test1(int a)
                ^
   net/bpf/test_run.c:112:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_fentry_test1(int a)
   ^
   static 
   net/bpf/test_run.c:117:14: warning: no previous prototype for function 'bpf_fentry_test2' [-Wmissing-prototypes]
   int noinline bpf_fentry_test2(int a, u64 b)
                ^
   net/bpf/test_run.c:117:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_fentry_test2(int a, u64 b)
   ^
   static 
   net/bpf/test_run.c:122:14: warning: no previous prototype for function 'bpf_fentry_test3' [-Wmissing-prototypes]
   int noinline bpf_fentry_test3(char a, int b, u64 c)
                ^
   net/bpf/test_run.c:122:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_fentry_test3(char a, int b, u64 c)
   ^
   static 
   net/bpf/test_run.c:127:14: warning: no previous prototype for function 'bpf_fentry_test4' [-Wmissing-prototypes]
   int noinline bpf_fentry_test4(void *a, char b, int c, u64 d)
                ^
   net/bpf/test_run.c:127:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_fentry_test4(void *a, char b, int c, u64 d)
   ^
   static 
   net/bpf/test_run.c:132:14: warning: no previous prototype for function 'bpf_fentry_test5' [-Wmissing-prototypes]
   int noinline bpf_fentry_test5(u64 a, void *b, short c, int d, u64 e)
                ^
   net/bpf/test_run.c:132:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_fentry_test5(u64 a, void *b, short c, int d, u64 e)
   ^
   static 
   net/bpf/test_run.c:137:14: warning: no previous prototype for function 'bpf_fentry_test6' [-Wmissing-prototypes]
   int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
                ^
   net/bpf/test_run.c:137:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
   ^
   static 
   net/bpf/test_run.c:142:14: warning: no previous prototype for function 'bpf_modify_return_test' [-Wmissing-prototypes]
   int noinline bpf_modify_return_test(int a, int *b)
                ^
   net/bpf/test_run.c:142:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int noinline bpf_modify_return_test(int a, int *b)
   ^
   static 
   7 warnings and 2 errors generated.

vim +/bpf_cgroup_storages_alloc +26 net/bpf/test_run.c

    17	
    18	static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
    19				u32 *retval, u32 *time, bool xdp)
    20	{
    21		struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = { NULL };
    22		u64 time_start, time_spent = 0;
    23		int ret = 0;
    24		u32 i;
    25	
  > 26		ret = bpf_cgroup_storages_alloc(storage, prog);
    27		if (ret)
    28			return ret;
    29	
    30		if (!repeat)
    31			repeat = 1;
    32	
    33		rcu_read_lock();
    34		migrate_disable();
    35		time_start = ktime_get_ns();
    36		for (i = 0; i < repeat; i++) {
    37			bpf_cgroup_storage_set(storage);
    38	
    39			if (xdp)
    40				*retval = bpf_prog_run_xdp(prog, ctx);
    41			else
    42				*retval = BPF_PROG_RUN(prog, ctx);
    43	
    44			if (signal_pending(current)) {
    45				ret = -EINTR;
    46				break;
    47			}
    48	
    49			if (need_resched()) {
    50				time_spent += ktime_get_ns() - time_start;
    51				migrate_enable();
    52				rcu_read_unlock();
    53	
    54				cond_resched();
    55	
    56				rcu_read_lock();
    57				migrate_disable();
    58				time_start = ktime_get_ns();
    59			}
    60		}
    61		time_spent += ktime_get_ns() - time_start;
    62		migrate_enable();
    63		rcu_read_unlock();
    64	
    65		do_div(time_spent, repeat);
    66		*time = time_spent > U32_MAX ? U32_MAX : (u32)time_spent;
    67	
  > 68		bpf_cgroup_storages_free(storage);
    69	
    70		return ret;
    71	}
    72	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 2c6f266..8bde9bb 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -175,6 +175,33 @@  int bpf_percpu_cgroup_storage_copy(struct bpf_map *map, void *key, void *value);
 int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key,
 				     void *value, u64 flags);
 
+static inline void bpf_cgroup_storages_free(struct bpf_cgroup_storage
+					    *storage[MAX_BPF_CGROUP_STORAGE_TYPE])
+{
+	enum bpf_cgroup_storage_type stype;
+
+	for_each_cgroup_storage_type(stype)
+		bpf_cgroup_storage_free(storage[stype]);
+}
+
+static inline int bpf_cgroup_storages_alloc(struct bpf_cgroup_storage
+					    *storage[MAX_BPF_CGROUP_STORAGE_TYPE],
+					    struct bpf_prog *prog)
+{
+	enum bpf_cgroup_storage_type stype;
+
+	for_each_cgroup_storage_type(stype) {
+		storage[stype] = bpf_cgroup_storage_alloc(prog, stype);
+		if (IS_ERR(storage[stype])) {
+			storage[stype] = NULL;
+			bpf_cgroup_storages_free(storage);
+			return -ENOMEM;
+		}
+	}
+
+	return 0;
+}
+
 /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */
 #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb)			      \
 ({									      \
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index ac53102..e4c2792 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -28,31 +28,6 @@  void cgroup_bpf_offline(struct cgroup *cgrp)
 	percpu_ref_kill(&cgrp->bpf.refcnt);
 }
 
-static void bpf_cgroup_storages_free(struct bpf_cgroup_storage *storages[])
-{
-	enum bpf_cgroup_storage_type stype;
-
-	for_each_cgroup_storage_type(stype)
-		bpf_cgroup_storage_free(storages[stype]);
-}
-
-static int bpf_cgroup_storages_alloc(struct bpf_cgroup_storage *storages[],
-				     struct bpf_prog *prog)
-{
-	enum bpf_cgroup_storage_type stype;
-
-	for_each_cgroup_storage_type(stype) {
-		storages[stype] = bpf_cgroup_storage_alloc(prog, stype);
-		if (IS_ERR(storages[stype])) {
-			storages[stype] = NULL;
-			bpf_cgroup_storages_free(storages);
-			return -ENOMEM;
-		}
-	}
-
-	return 0;
-}
-
 static void bpf_cgroup_storages_assign(struct bpf_cgroup_storage *dst[],
 				       struct bpf_cgroup_storage *src[])
 {
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 1e10a7e..5c4835c 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -19,20 +19,13 @@  static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
 			u32 *retval, u32 *time, bool xdp)
 {
 	struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = { NULL };
-	enum bpf_cgroup_storage_type stype;
 	u64 time_start, time_spent = 0;
 	int ret = 0;
 	u32 i;
 
-	for_each_cgroup_storage_type(stype) {
-		storage[stype] = bpf_cgroup_storage_alloc(prog, stype);
-		if (IS_ERR(storage[stype])) {
-			storage[stype] = NULL;
-			for_each_cgroup_storage_type(stype)
-				bpf_cgroup_storage_free(storage[stype]);
-			return -ENOMEM;
-		}
-	}
+	ret = bpf_cgroup_storages_alloc(storage, prog);
+	if (ret)
+		return ret;
 
 	if (!repeat)
 		repeat = 1;
@@ -72,8 +65,7 @@  static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
 	do_div(time_spent, repeat);
 	*time = time_spent > U32_MAX ? U32_MAX : (u32)time_spent;
 
-	for_each_cgroup_storage_type(stype)
-		bpf_cgroup_storage_free(storage[stype]);
+	bpf_cgroup_storages_free(storage);
 
 	return ret;
 }