bpf_prog_pack followup
Subsystems (7)
Song Liu
reviewerv2 cover bpf_prog_pack followup
Changes v1 => v2:
1. Add WARN to set_vm_flush_reset_perms() on huge pages. (Rick Edgecombe)
2. Simplify select_bpf_prog_pack_size. (Rick Edgecombe)
As of 5.18-rc6, x86_64 uses bpf_prog_pack on 4kB pages. This set contains a few followups:
1/8 - 3/8 fills unused part of bpf_prog_pack with illegal instructions. 4/8 - 5/8 enables bpf_prog_pack on 2MB pages.
The primary goal of bpf_prog_pack is to reduce iTLB miss rate and reduce direct memory mapping fragmentation. This leads to non-trivial performance improvements.
For our web service production benchmark, bpf_prog_pack on 4kB pages gives 0.5% to 0.7% more throughput than not using bpf_prog_pack. bpf_prog_pack on 2MB pages 0.6% to 0.9% more throughput than not using bpf_prog_pack. Note that 0.5% is a huge improvement for our fleet. I believe this is also significant for other companies with many thousand servers.
bpf_prog_pack on 2MB pages may use slightly more memory for systems without many BPF programs. However, such waste in memory (<2MB) is within noisy for modern x86_64 systems.
Song Liu (8):
bpf: fill new bpf_prog_pack with illegal instructions x86/alternative: introduce text_poke_set
bpf: introduce bpf_arch_text_invalidate for bpf_prog_pack
module: introduce module_alloc_huge
bpf: use module_alloc_huge for bpf_prog_pack
vmalloc: WARN for set_vm_flush_reset_perms() on huge pages
vmalloc: introduce huge_vmalloc_supported
bpf: simplify select_bpf_prog_pack_size
arch/x86/include/asm/text-patching.h | 1 + arch/x86/kernel/alternative.c | 67 +++++++++++++++++++++++----- arch/x86/kernel/module.c | 21 +++++++++ arch/x86/net/bpf_jit_comp.c | 5 +++ include/linux/bpf.h | 1 + include/linux/moduleloader.h | 5 +++ include/linux/vmalloc.h | 3 ++ kernel/bpf/core.c | 42 +++++++++-------- kernel/module.c | 8 ++++ mm/vmalloc.c | 5 +++ 10 files changed, 130 insertions(+), 28 deletions(-)
--
2.30.2
Song Liu
reviewerPATCH v2 1/8 bpf: fill new bpf_prog_pack with illegal instructions
bpf_prog_pack enables sharing huge pages among multiple BPF programs. These pages are marked as executable before the JIT engine fill it with BPF programs. To make these pages safe, fill the hole bpf_prog_pack with illegal instructions before making it executable.
--- kernel/bpf/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/bpf/core.c +6 -4
@@ -873,7 +873,7 @@ static size_t select_bpf_prog_pack_size(void)return size; } -static struct bpf_prog_pack *alloc_new_pack (void ) +static struct bpf_prog_pack *alloc_new_pack (bpf_jit_fill_hole_t bpf_fill_ill_insns) {struct bpf_prog_pack *pack;
@@ -886,6 +886,7 @@ static struct bpf_prog_pack *alloc_new_pack(void)kfree (pack);return NULL ; } +bpf_fill_ill_insns (pack->ptr, bpf_prog_pack_size);bitmap_zero (pack->bitmap, bpf_prog_pack_size /BPF_PROG_CHUNK_SIZE );list_add_tail (&pack->list, &pack_list);
@@ -895,7 +896,7 @@ static struct bpf_prog_pack *alloc_new_pack(void)return pack; } -static void *bpf_prog_pack_alloc (u32 size) +static void *bpf_prog_pack_alloc (u32 size,bpf_jit_fill_hole_t bpf_fill_ill_insns) {unsigned int nbits =BPF_PROG_SIZE_TO_NBITS (size);struct bpf_prog_pack *pack;
@@ -910,6 +911,7 @@ static void *bpf_prog_pack_alloc(u32 size) size =round_up (size,PAGE_SIZE ); ptr =module_alloc (size);if (ptr) { +bpf_fill_ill_insns (ptr, size);set_vm_flush_reset_perms (ptr);set_memory_ro ((unsigned long )ptr, size /PAGE_SIZE );set_memory_x ((unsigned long )ptr, size /PAGE_SIZE );
@@ -923,7 +925,7 @@ static void *bpf_prog_pack_alloc(u32 size) goto found_free_area; } - pack =alloc_new_pack (); + pack =alloc_new_pack (bpf_fill_ill_insns);if (!pack) goto out;
@@ -1102,7 +1104,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **image_ptr,if (bpf_jit_charge_modmem (size))return NULL ; - ro_header =bpf_prog_pack_alloc (size); + ro_header =bpf_prog_pack_alloc (size, bpf_fill_ill_insns);if (!ro_header) {bpf_jit_uncharge_modmem (size);return NULL ;
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 2/8 x86/alternative: introduce text_poke_set
In reply to Song LiuIntroduce a memset like API for text_poke. This will be used to fill the unused RX memory with illegal instructions.
--- arch/x86/include/asm/text-patching.h | 1 + arch/x86/kernel/alternative.c | 67 +++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 10 deletions(-)
arch/x86/include/asm/text-patching.h +1 -0
@@ -45,6 +45,7 @@ extern void *text_poke(void *addr, const void *opcode, size_t len);extern void text_poke_sync (void );extern void *text_poke_kgdb (void *addr,const void *opcode,size_t len);extern void *text_poke_copy (void *addr,const void *opcode,size_t len); +extern void *text_poke_set (void *addr,int c,size_t len);extern int poke_int3_handler (struct pt_regs *regs);extern void text_poke_bp (void *addr,const void *opcode,size_t len,const void *emulate);
arch/x86/kernel/alternative.c +57 -10
103 lines not on this page · raw message
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 3/8 bpf: introduce bpf_arch_text_invalidate for bpf_prog_pack
In reply to Song LiuIntroduce bpf_arch_text_invalidate and use it to fill unused part of the bpf_prog_pack with illegal instructions when a BPF program is freed.
--- arch/x86/net/bpf_jit_comp.c | 5 +++++ include/linux/bpf.h | 1 + kernel/bpf/core.c | 8 ++++++++ 3 files changed, 14 insertions(+)
arch/x86/net/bpf_jit_comp.c +5 -0
@@ -228,6 +228,11 @@ static void jit_fill_hole(void *area, unsigned int size)memset (area,0xcc , size); } +int bpf_arch_text_invalidate (void *dst,size_t len) +{ +return IS_ERR_OR_NULL (text_poke_set (dst,0xcc , len)); +} +struct jit_context {int cleanup_addr;/* Epilogue code offset */
include/linux/bpf.h +1 -0
@@ -2364,6 +2364,7 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, void *addr1, void *addr2);void *bpf_arch_text_copy (void *dst,void *src,size_t len); +int bpf_arch_text_invalidate (void *dst,size_t len);struct btf_id_set ;bool btf_id_set_contains (const struct btf_id_set *set,u32 id);
kernel/bpf/core.c +8 -0
@@ -968,6 +968,9 @@ static void bpf_prog_pack_free(struct bpf_binary_header *hdr) nbits =BPF_PROG_SIZE_TO_NBITS (hdr->size); pos = ((unsigned long )hdr - (unsigned long )pack_ptr) >>BPF_PROG_CHUNK_SHIFT ; +WARN_ONCE (bpf_arch_text_invalidate (hdr, hdr->size), +"bpf_prog_pack bug: missing bpf_arch_text_invalidate?\n" ); +bitmap_clear (pack->bitmap, pos, nbits);if (bitmap_find_next_zero_area (pack->bitmap,bpf_prog_chunk_count (),0 ,bpf_prog_chunk_count (),0 ) ==0 ) {
@@ -2740,6 +2743,11 @@ void * __weak bpf_arch_text_copy(void *dst, void *src, size_t len)return ERR_PTR (-ENOTSUPP ); } +int __weak bpf_arch_text_invalidate (void *dst,size_t len) +{ +return -ENOTSUPP ; +} +DEFINE_STATIC_KEY_FALSE (bpf_stats_enabled_key);EXPORT_SYMBOL (bpf_stats_enabled_key);
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 4/8 module: introduce module_alloc_huge
In reply to Song LiuIntroduce module_alloc_huge, which allocates huge page backed memory in module memory space. The primary user of this memory is bpf_prog_pack (multiple BPF programs sharing a huge page).
---
Note: This conflicts with the module.c => module/ split in modules-next. Current patch is for module.c in the bpf-next tree. After the split, __weak module_alloc_huge() should be added to kernel/module/main.c.
--- arch/x86/kernel/module.c | 21 +++++++++++++++++++++ include/linux/moduleloader.h | 5 +++++ kernel/module.c | 8 ++++++++ 3 files changed, 34 insertions(+)
arch/x86/kernel/module.c +21 -0
@@ -86,6 +86,27 @@ void *module_alloc(unsigned long size)return p; } +void *module_alloc_huge (unsigned long size) +{ +gfp_t gfp_mask =GFP_KERNEL ; +void *p; + +if (PAGE_ALIGN (size) >MODULES_LEN ) +return NULL ; + + p =__vmalloc_node_range (size,MODULE_ALIGN , +MODULES_VADDR +get_module_load_offset (), +MODULES_END , gfp_mask,PAGE_KERNEL , +VM_DEFER_KMEMLEAK |VM_ALLOW_HUGE_VMAP , +NUMA_NO_NODE ,__builtin_return_address (0 )); +if (p && (kasan_alloc_module_shadow (p, size, gfp_mask) <0 )) { +vfree (p); +return NULL ; + } + +return p; +} +#ifdef CONFIG_X86_32 int apply_relocate(Elf32_Shdr *sechdrs, const char *strtab,
include/linux/moduleloader.h +5 -0
@@ -26,6 +26,11 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);sections. Returns NULL on failure. */ void *module_alloc (unsigned long size); +/* Allocator used for allocating memory in module memory space. If size is +* greater than PMD_SIZE, allow using huge pages. Returns NULL on failure. +*/ +void *module_alloc_huge (unsigned long size); +/* Free memory returned from module_alloc. */ void module_memfree (void *module_region);
kernel/module.c +8 -0
@@ -2839,6 +2839,14 @@ void * __weak module_alloc(unsigned long size) NUMA_NO_NODE, __builtin_return_address(0)); } +void *__weak module_alloc_huge (unsigned long size) +{ +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END , +GFP_KERNEL ,PAGE_KERNEL_EXEC , +VM_FLUSH_RESET_PERMS |VM_ALLOW_HUGE_VMAP , +NUMA_NO_NODE ,__builtin_return_address (0 )); +} +bool __weak module_init_section (const char *name) {return strstarts (name,".init" );
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 5/8 bpf: use module_alloc_huge for bpf_prog_pack
In reply to Song LiuUse module_alloc_huge for bpf_prog_pack so that BPF programs sit on PMD_SIZE pages. This benefits system performance by reducing iTLB miss rate. Benchmark of a real web service workload shows this change gives another ~0.2% performance boost on top of PAGE_SIZE bpf_prog_pack (which improve system throughput by ~0.5%).
Also, remove set_vm_flush_reset_perms() from alloc_new_pack() and use set_memory_[nx|rw] in bpf_prog_pack_free(). This is because VM_FLUSH_RESET_PERMS does not work with huge pages yet. [1]
[1] https://lore.kernel.org/bpf/[email protected]/
--- kernel/bpf/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
kernel/bpf/core.c +7 -5
@@ -857,7 +857,7 @@ static size_t select_bpf_prog_pack_size(void)void *ptr; size =BPF_HPAGE_SIZE *num_online_nodes (); - ptr =module_alloc (size); + ptr =module_alloc_huge (size);/* Test whether we can get huge pages. If not just use PAGE_SIZE * packs.
@@ -881,7 +881,7 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_ill_ins GFP_KERNEL);if (!pack)return NULL ; - pack->ptr =module_alloc (bpf_prog_pack_size); + pack->ptr =module_alloc_huge (bpf_prog_pack_size);if (!pack->ptr) {kfree (pack);return NULL ;
@@ -890,7 +890,6 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_ill_insbitmap_zero (pack->bitmap, bpf_prog_pack_size /BPF_PROG_CHUNK_SIZE );list_add_tail (&pack->list, &pack_list); -set_vm_flush_reset_perms (pack->ptr);set_memory_ro ((unsigned long )pack->ptr, bpf_prog_pack_size /PAGE_SIZE );set_memory_x ((unsigned long )pack->ptr, bpf_prog_pack_size /PAGE_SIZE );return pack;
@@ -909,10 +908,9 @@ static void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insnif (size > bpf_prog_pack_size) { size =round_up (size,PAGE_SIZE ); - ptr =module_alloc (size); + ptr =module_alloc_huge (size);if (ptr) {bpf_fill_ill_insns (ptr, size); -set_vm_flush_reset_perms (ptr);set_memory_ro ((unsigned long )ptr, size /PAGE_SIZE );set_memory_x ((unsigned long )ptr, size /PAGE_SIZE ); }
@@ -949,6 +947,8 @@ static void bpf_prog_pack_free(struct bpf_binary_header *hdr)mutex_lock (&pack_mutex);if (hdr->size > bpf_prog_pack_size) { +set_memory_nx ((unsigned long )hdr, hdr->size /PAGE_SIZE ); +set_memory_rw ((unsigned long )hdr, hdr->size /PAGE_SIZE );module_memfree (hdr); goto out; }
@@ -975,6 +975,8 @@ static void bpf_prog_pack_free(struct bpf_binary_header *hdr)if (bitmap_find_next_zero_area (pack->bitmap,bpf_prog_chunk_count (),0 ,bpf_prog_chunk_count (),0 ) ==0 ) {list_del (&pack->list); +set_memory_nx ((unsigned long )pack->ptr, bpf_prog_pack_size /PAGE_SIZE ); +set_memory_rw ((unsigned long )pack->ptr, bpf_prog_pack_size /PAGE_SIZE );module_memfree (pack->ptr);kfree (pack); }
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 6/8 vmalloc: WARN for set_vm_flush_reset_perms() on huge pages
In reply to Song LiuVM_FLUSH_RESET_PERMS is not yet ready for huge pages, add a WARN to catch misuse soon.
--- include/linux/vmalloc.h | 1 + 1 file changed, 1 insertion(+)
include/linux/vmalloc.h +1 -0
@@ -238,6 +238,7 @@ static inline void set_vm_flush_reset_perms(void *addr) {struct vm_struct *vm =find_vm_area (addr); +WARN_ON_ONCE (is_vm_area_hugepages (addr));if (vm) vm->flags |=VM_FLUSH_RESET_PERMS ; }
Signature · 1 line
2.30.2
Song Liu
reviewerPATCH v2 7/8 vmalloc: introduce huge_vmalloc_supported
In reply to Song Liuhuge_vmalloc_supported() exposes vmap_allow_huge so that users of vmalloc APIs could know whether vmalloc will return huge pages.
--- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 5 +++++ 2 files changed, 7 insertions(+)
include/linux/vmalloc.h +2 -0
@@ -242,11 +242,13 @@ static inline void set_vm_flush_reset_perms(void *addr)if (vm) vm->flags |= VM_FLUSH_RESET_PERMS; } +bool huge_vmalloc_supported (void );#else static inline void set_vm_flush_reset_perms (void *addr) { } +bool huge_vmalloc_supported (void ) {return false; }#endif /* for /proc/kcore */
mm/vmalloc.c +5 -0
@@ -72,6 +72,11 @@ early_param("nohugevmalloc", set_nohugevmalloc);static const bool vmap_allow_huge = false;#endif /* CONFIG_HAVE_ARCH_HUGE_VMALLOC */ +bool huge_vmalloc_supported (void ) +{ +return vmap_allow_huge; +} +bool is_vmalloc_addr (const void *x) {unsigned long addr = (unsigned long )kasan_reset_tag (x);
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported
I love your patch! Yet something to improve:
Hi Song,
I love your patch! Yet something to improve:
[auto build test ERROR 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: sh-randconfig-r024-20220519 (https://download.01.org/0day-ci/archive/20220520/[email protected]/config) compiler: sh4-linux-gcc (GCC) 11.3.0
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/f1d2b40a3e45708f74228a552a43399b20c71954
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 f1d2b40a3e45708f74228a552a43399b20c71954
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
sh4-linux-ld: drivers/firewire/core-iso.o: in function `huge_vmalloc_supported':
>> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/firewire/core-cdev.o:include/linux/vmalloc.h:251: first defined here -- sh4-linux-ld: drivers/mtd/ubi/vmt.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/upd.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/build.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/cdev.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/kapi.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/eba.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/io.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/wl.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/attach.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/misc.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/mtd/ubi/debug.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/mtd/ubi/vtbl.o:include/linux/vmalloc.h:251: first defined here -- sh4-linux-ld: drivers/usb/gadget/function/uvc_queue.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/usb/gadget/function/f_uvc.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: drivers/usb/gadget/function/uvc_v4l2.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/usb/gadget/function/f_uvc.o:include/linux/vmalloc.h:251: first defined here -- sh4-linux-ld: drivers/hid/hid-picolcd_cir.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; drivers/hid/hid-picolcd_core.o:include/linux/vmalloc.h:251: first defined here -- sh4-linux-ld: fs/jffs2/read.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/write.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/gc.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/build.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/fs.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/super.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/compr_rtime.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/compr_zlib.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/jffs2/compr_lzo.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/jffs2/compr.o:include/linux/vmalloc.h:251: first defined here -- sh4-linux-ld: fs/ubifs/journal.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/file.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/dir.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/super.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/sb.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/io.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/tnc.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/master.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/scan.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/replay.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/log.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/commit.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/gc.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/orphan.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/budget.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/find.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/tnc_commit.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/compress.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/lpt.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here sh4-linux-ld: fs/ubifs/lprops.o: in function `huge_vmalloc_supported': >> include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/recovery.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/ioctl.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/lpt_commit.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/tnc_misc.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/debug.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/misc.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/sysfs.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/crypto.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/xattr.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
sh4-linux-ld: fs/ubifs/auth.o: in function `huge_vmalloc_supported':
include/linux/vmalloc.h:251: multiple definition of `huge_vmalloc_supported'; fs/ubifs/shrinker.o:include/linux/vmalloc.h:251: first defined here
vim +251 include/linux/vmalloc.h
246
247 #else
248 static inline void set_vm_flush_reset_perms(void *addr)
249 {
250 }
> 251 bool huge_vmalloc_supported(void) { return false; } 252 #endif
253
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Song Liu
reviewerPATCH v2 8/8 bpf: simplify select_bpf_prog_pack_size
In reply to Song LiuUse huge_vmalloc_supported to simplify select_bpf_prog_pack_size, so that we don't allocate some huge pages and free them immediately.
--- kernel/bpf/core.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
kernel/bpf/core.c +4 -10
@@ -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; }
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size
I love your patch! Perhaps something to improve:
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/[email protected]/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
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 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botRe: [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size
In reply to Song LiuI love your patch! Perhaps something to improve:
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/[email protected]/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
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 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp