diff mbox series

[v2,bpf-next,8/8] bpf: simplify select_bpf_prog_pack_size

Message ID 20220519202037.2401584-9-song@kernel.org (mailing list archive)
State New
Headers show
Series bpf_prog_pack followup | expand

Commit Message

Song Liu May 19, 2022, 8:20 p.m. UTC
Use huge_vmalloc_supported to simplify select_bpf_prog_pack_size, so that
we don't allocate some huge pages and free them immediately.

Suggested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

kernel test robot May 20, 2022, 1:57 a.m. UTC | #1
Hi Song,

I love your patch! Perhaps something to improve:

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

url:    https://github.com/intel-lab-lkp/linux/commits/Song-Liu/bpf_prog_pack-followup/20220520-043417
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: i386-randconfig-a003 (https://download.01.org/0day-ci/archive/20220520/202205200913.DnvvOaAw-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/2d5d4beb45be09f3130b694f49ab1b1fd1aa4470
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Song-Liu/bpf_prog_pack-followup/20220520-043417
        git checkout 2d5d4beb45be09f3130b694f49ab1b1fd1aa4470
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/bpf/

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

All warnings (new ones prefixed by >>):

   kernel/bpf/core.c: In function 'select_bpf_prog_pack_size':
>> kernel/bpf/core.c:857:15: warning: unused variable 'ptr' [-Wunused-variable]
     857 |         void *ptr;
         |               ^~~


vim +/ptr +857 kernel/bpf/core.c

e581094167beb6 Song Liu 2022-03-21  853  
ef078600eec20f Song Liu 2022-03-11  854  static size_t select_bpf_prog_pack_size(void)
ef078600eec20f Song Liu 2022-03-11  855  {
ef078600eec20f Song Liu 2022-03-11  856  	size_t size;
ef078600eec20f Song Liu 2022-03-11 @857  	void *ptr;
ef078600eec20f Song Liu 2022-03-11  858  
2d5d4beb45be09 Song Liu 2022-05-19  859  	if (huge_vmalloc_supported()) {
e581094167beb6 Song Liu 2022-03-21  860  		size = BPF_HPAGE_SIZE * num_online_nodes();
2d5d4beb45be09 Song Liu 2022-05-19  861  		bpf_prog_pack_mask = BPF_HPAGE_MASK;
2d5d4beb45be09 Song Liu 2022-05-19  862  	} else {
ef078600eec20f Song Liu 2022-03-11  863  		size = PAGE_SIZE;
96805674e5624b Song Liu 2022-03-21  864  		bpf_prog_pack_mask = PAGE_MASK;
96805674e5624b Song Liu 2022-03-21  865  	}
ef078600eec20f Song Liu 2022-03-11  866  
ef078600eec20f Song Liu 2022-03-11  867  	return size;
ef078600eec20f Song Liu 2022-03-11  868  }
ef078600eec20f Song Liu 2022-03-11  869
kernel test robot May 20, 2022, 2:53 a.m. UTC | #2
Hi Song,

I love your patch! Perhaps something to improve:

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

url:    https://github.com/intel-lab-lkp/linux/commits/Song-Liu/bpf_prog_pack-followup/20220520-043417
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: x86_64-randconfig-a005 (https://download.01.org/0day-ci/archive/20220520/202205201001.kKBulowq-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project e00cbbec06c08dc616a0d52a20f678b8fbd4e304)
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
        # https://github.com/intel-lab-lkp/linux/commit/2d5d4beb45be09f3130b694f49ab1b1fd1aa4470
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Song-Liu/bpf_prog_pack-followup/20220520-043417
        git checkout 2d5d4beb45be09f3130b694f49ab1b1fd1aa4470
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash kernel/bpf/

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

All warnings (new ones prefixed by >>):

>> kernel/bpf/core.c:857:8: warning: unused variable 'ptr' [-Wunused-variable]
           void *ptr;
                 ^
   kernel/bpf/core.c:1656:12: warning: no previous prototype for function 'bpf_probe_read_kernel' [-Wmissing-prototypes]
   u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
              ^
   kernel/bpf/core.c:1656:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
   ^
   static 
   kernel/bpf/core.c:2099:6: warning: no previous prototype for function 'bpf_patch_call_args' [-Wmissing-prototypes]
   void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth)
        ^
   kernel/bpf/core.c:2099:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth)
   ^
   static 
   3 warnings generated.


vim +/ptr +857 kernel/bpf/core.c

e581094167beb6 Song Liu 2022-03-21  853  
ef078600eec20f Song Liu 2022-03-11  854  static size_t select_bpf_prog_pack_size(void)
ef078600eec20f Song Liu 2022-03-11  855  {
ef078600eec20f Song Liu 2022-03-11  856  	size_t size;
ef078600eec20f Song Liu 2022-03-11 @857  	void *ptr;
ef078600eec20f Song Liu 2022-03-11  858  
2d5d4beb45be09 Song Liu 2022-05-19  859  	if (huge_vmalloc_supported()) {
e581094167beb6 Song Liu 2022-03-21  860  		size = BPF_HPAGE_SIZE * num_online_nodes();
2d5d4beb45be09 Song Liu 2022-05-19  861  		bpf_prog_pack_mask = BPF_HPAGE_MASK;
2d5d4beb45be09 Song Liu 2022-05-19  862  	} else {
ef078600eec20f Song Liu 2022-03-11  863  		size = PAGE_SIZE;
96805674e5624b Song Liu 2022-03-21  864  		bpf_prog_pack_mask = PAGE_MASK;
96805674e5624b Song Liu 2022-03-21  865  	}
ef078600eec20f Song Liu 2022-03-11  866  
ef078600eec20f Song Liu 2022-03-11  867  	return size;
ef078600eec20f Song Liu 2022-03-11  868  }
ef078600eec20f Song Liu 2022-03-11  869
diff mbox series

Patch

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index b64d91fcb0ba..62c8632a59a2 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -856,20 +856,14 @@  static size_t select_bpf_prog_pack_size(void)
 	size_t size;
 	void *ptr;
 
-	size = BPF_HPAGE_SIZE * num_online_nodes();
-	ptr = module_alloc_huge(size);
-
-	/* Test whether we can get huge pages. If not just use PAGE_SIZE
-	 * packs.
-	 */
-	if (!ptr || !is_vm_area_hugepages(ptr)) {
+	if (huge_vmalloc_supported()) {
+		size = BPF_HPAGE_SIZE * num_online_nodes();
+		bpf_prog_pack_mask = BPF_HPAGE_MASK;
+	} else {
 		size = PAGE_SIZE;
 		bpf_prog_pack_mask = PAGE_MASK;
-	} else {
-		bpf_prog_pack_mask = BPF_HPAGE_MASK;
 	}
 
-	vfree(ptr);
 	return size;
 }