All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 bpf-next 0/8] bpf_prog_pack followup
@ 2022-05-19 20:20 Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 1/8] bpf: fill new bpf_prog_pack with illegal instructions Song Liu
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

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

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

* [PATCH v2 bpf-next 1/8] bpf: fill new bpf_prog_pack with illegal instructions
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 2/8] x86/alternative: introduce text_poke_set Song Liu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

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.

Fixes: 57631054fae6 ("bpf: Introduce bpf_prog_pack allocator")
Fixes: 33c9805860e5 ("bpf: Introduce bpf_jit_binary_pack_[alloc|finalize|free]")
Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 9cc91f0f3115..2d0c9d4696ad 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -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;
-- 
2.30.2


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

* [PATCH v2 bpf-next 2/8] x86/alternative: introduce text_poke_set
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 1/8] bpf: fill new bpf_prog_pack with illegal instructions Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 3/8] bpf: introduce bpf_arch_text_invalidate for bpf_prog_pack Song Liu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

Introduce a memset like API for text_poke. This will be used to fill the
unused RX memory with illegal instructions.

Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Song Liu <song@kernel.org>
---
 arch/x86/include/asm/text-patching.h |  1 +
 arch/x86/kernel/alternative.c        | 67 +++++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/text-patching.h
index d20ab0921480..1cc15528ce29 100644
--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -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);
 
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index d374cb3cf024..7563b5bc8328 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -994,7 +994,21 @@ static inline void unuse_temporary_mm(temp_mm_state_t prev_state)
 __ro_after_init struct mm_struct *poking_mm;
 __ro_after_init unsigned long poking_addr;
 
-static void *__text_poke(void *addr, const void *opcode, size_t len)
+static void text_poke_memcpy(void *dst, const void *src, size_t len)
+{
+	memcpy(dst, src, len);
+}
+
+static void text_poke_memset(void *dst, const void *src, size_t len)
+{
+	int c = *(const int *)src;
+
+	memset(dst, c, len);
+}
+
+typedef void text_poke_f(void *dst, const void *src, size_t len);
+
+static void *__text_poke(text_poke_f func, void *addr, const void *src, size_t len)
 {
 	bool cross_page_boundary = offset_in_page(addr) + len > PAGE_SIZE;
 	struct page *pages[2] = {NULL};
@@ -1059,7 +1073,7 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	prev = use_temporary_mm(poking_mm);
 
 	kasan_disable_current();
-	memcpy((u8 *)poking_addr + offset_in_page(addr), opcode, len);
+	func((u8 *)poking_addr + offset_in_page(addr), src, len);
 	kasan_enable_current();
 
 	/*
@@ -1087,11 +1101,13 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 			   (cross_page_boundary ? 2 : 1) * PAGE_SIZE,
 			   PAGE_SHIFT, false);
 
-	/*
-	 * If the text does not match what we just wrote then something is
-	 * fundamentally screwy; there's nothing we can really do about that.
-	 */
-	BUG_ON(memcmp(addr, opcode, len));
+	if (func == text_poke_memcpy) {
+		/*
+		 * If the text does not match what we just wrote then something is
+		 * fundamentally screwy; there's nothing we can really do about that.
+		 */
+		BUG_ON(memcmp(addr, src, len));
+	}
 
 	local_irq_restore(flags);
 	pte_unmap_unlock(ptep, ptl);
@@ -1118,7 +1134,7 @@ void *text_poke(void *addr, const void *opcode, size_t len)
 {
 	lockdep_assert_held(&text_mutex);
 
-	return __text_poke(addr, opcode, len);
+	return __text_poke(text_poke_memcpy, addr, opcode, len);
 }
 
 /**
@@ -1137,7 +1153,7 @@ void *text_poke(void *addr, const void *opcode, size_t len)
  */
 void *text_poke_kgdb(void *addr, const void *opcode, size_t len)
 {
-	return __text_poke(addr, opcode, len);
+	return __text_poke(text_poke_memcpy, addr, opcode, len);
 }
 
 /**
@@ -1167,7 +1183,38 @@ void *text_poke_copy(void *addr, const void *opcode, size_t len)
 
 		s = min_t(size_t, PAGE_SIZE * 2 - offset_in_page(ptr), len - patched);
 
-		__text_poke((void *)ptr, opcode + patched, s);
+		__text_poke(text_poke_memcpy, (void *)ptr, opcode + patched, s);
+		patched += s;
+	}
+	mutex_unlock(&text_mutex);
+	return addr;
+}
+
+/**
+ * text_poke_set - memset into (an unused part of) RX memory
+ * @addr: address to modify
+ * @c: the byte to fill the area with
+ * @len: length to copy, could be more than 2x PAGE_SIZE
+ *
+ * This is useful to overwrite unused regions of RX memory with illegal
+ * instructions.
+ */
+void *text_poke_set(void *addr, int c, size_t len)
+{
+	unsigned long start = (unsigned long)addr;
+	size_t patched = 0;
+
+	if (WARN_ON_ONCE(core_kernel_text(start)))
+		return NULL;
+
+	mutex_lock(&text_mutex);
+	while (patched < len) {
+		unsigned long ptr = start + patched;
+		size_t s;
+
+		s = min_t(size_t, PAGE_SIZE * 2 - offset_in_page(ptr), len - patched);
+
+		__text_poke(text_poke_memset, (void *)ptr, (void *)&c, s);
 		patched += s;
 	}
 	mutex_unlock(&text_mutex);
-- 
2.30.2


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

* [PATCH v2 bpf-next 3/8] bpf: introduce bpf_arch_text_invalidate for bpf_prog_pack
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 1/8] bpf: fill new bpf_prog_pack with illegal instructions Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 2/8] x86/alternative: introduce text_poke_set Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 4/8] module: introduce module_alloc_huge Song Liu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

Introduce 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.

Signed-off-by: Song Liu <song@kernel.org>
---
 arch/x86/net/bpf_jit_comp.c | 5 +++++
 include/linux/bpf.h         | 1 +
 kernel/bpf/core.c           | 8 ++++++++
 3 files changed, 14 insertions(+)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index a2b6d197c226..f298b18a9a3d 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -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 */
 
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index c107392b0ba7..f6dfa416f892 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -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);
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 2d0c9d4696ad..cacd8684c3c4 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -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);
 
-- 
2.30.2


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

* [PATCH v2 bpf-next 4/8] module: introduce module_alloc_huge
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
                   ` (2 preceding siblings ...)
  2022-05-19 20:20 ` [PATCH v2 bpf-next 3/8] bpf: introduce bpf_arch_text_invalidate for bpf_prog_pack Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 5/8] bpf: use module_alloc_huge for bpf_prog_pack Song Liu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu, Stephen Rothwell

Introduce 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).

Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Song Liu <song@kernel.org>

---
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(+)

diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index b98ffcf4d250..63f6a16c70dc 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -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,
diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
index 9e09d11ffe5b..d34743a88938 100644
--- a/include/linux/moduleloader.h
+++ b/include/linux/moduleloader.h
@@ -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);
 
diff --git a/kernel/module.c b/kernel/module.c
index 6cea788fd965..2af20ac3209c 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -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");
-- 
2.30.2



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

* [PATCH v2 bpf-next 5/8] bpf: use module_alloc_huge for bpf_prog_pack
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
                   ` (3 preceding siblings ...)
  2022-05-19 20:20 ` [PATCH v2 bpf-next 4/8] module: introduce module_alloc_huge Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 6/8] vmalloc: WARN for set_vm_flush_reset_perms() on huge pages Song Liu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

Use 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/aeeeaf0b7ec63fdba55d4834d2f524d8bf05b71b.camel@intel.com/
Suggested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index cacd8684c3c4..b64d91fcb0ba 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -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_ins
 	bitmap_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_insn
 
 	if (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);
 	}
-- 
2.30.2


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

* [PATCH v2 bpf-next 6/8] vmalloc: WARN for set_vm_flush_reset_perms() on huge pages
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
                   ` (4 preceding siblings ...)
  2022-05-19 20:20 ` [PATCH v2 bpf-next 5/8] bpf: use module_alloc_huge for bpf_prog_pack Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported Song Liu
  2022-05-19 20:20 ` [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size Song Liu
  7 siblings, 0 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

VM_FLUSH_RESET_PERMS is not yet ready for huge pages, add a WARN to
catch misuse soon.

Suggested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Song Liu <song@kernel.org>
---
 include/linux/vmalloc.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index b159c2789961..5e0d0a60d9d5 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -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;
 }
-- 
2.30.2


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

* [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
                   ` (5 preceding siblings ...)
  2022-05-19 20:20 ` [PATCH v2 bpf-next 6/8] vmalloc: WARN for set_vm_flush_reset_perms() on huge pages Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-20  0:52   ` kernel test robot
  2022-05-19 20:20 ` [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size Song Liu
  7 siblings, 1 reply; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

huge_vmalloc_supported() exposes vmap_allow_huge so that users of vmalloc
APIs could know whether vmalloc will return huge pages.

Suggested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Song Liu <song@kernel.org>
---
 include/linux/vmalloc.h | 2 ++
 mm/vmalloc.c            | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 5e0d0a60d9d5..3268e7e875ff 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -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 */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 07da85ae825b..d3b11317b025 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -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);
-- 
2.30.2


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

* [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size
  2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
                   ` (6 preceding siblings ...)
  2022-05-19 20:20 ` [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported Song Liu
@ 2022-05-19 20:20 ` Song Liu
  2022-05-20  1:57   ` kernel test robot
  2022-05-20  2:53   ` kernel test robot
  7 siblings, 2 replies; 12+ messages in thread
From: Song Liu @ 2022-05-19 20:20 UTC (permalink / raw)
  To: linux-kernel, bpf, linux-mm
  Cc: ast, daniel, peterz, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

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(-)

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;
 }
 
-- 
2.30.2


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

* Re: [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported
  2022-05-19 20:20 ` [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported Song Liu
@ 2022-05-20  0:52   ` kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2022-05-20  0:52 UTC (permalink / raw)
  To: Song Liu, linux-kernel, bpf, linux-mm
  Cc: kbuild-all, ast, daniel, peterz, mcgrof, torvalds,
	rick.p.edgecombe, kernel-team, Song Liu

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/202205200826.fu46joi3-lkp@intel.com/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
Reported-by: kernel test robot <lkp@intel.com>

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	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size
  2022-05-19 20:20 ` [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size Song Liu
@ 2022-05-20  1:57   ` kernel test robot
  2022-05-20  2:53   ` kernel test robot
  1 sibling, 0 replies; 12+ messages in thread
From: kernel test robot @ 2022-05-20  1:57 UTC (permalink / raw)
  To: Song Liu, linux-kernel, bpf, linux-mm
  Cc: kbuild-all, ast, daniel, mcgrof, torvalds, rick.p.edgecombe,
	kernel-team, Song Liu

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  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size
  2022-05-19 20:20 ` [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size Song Liu
  2022-05-20  1:57   ` kernel test robot
@ 2022-05-20  2:53   ` kernel test robot
  1 sibling, 0 replies; 12+ messages in thread
From: kernel test robot @ 2022-05-20  2:53 UTC (permalink / raw)
  To: Song Liu, linux-kernel, bpf, linux-mm
  Cc: llvm, kbuild-all, ast, daniel, mcgrof, torvalds,
	rick.p.edgecombe, kernel-team, Song Liu

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  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-05-20  2:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 20:20 [PATCH v2 bpf-next 0/8] bpf_prog_pack followup Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 1/8] bpf: fill new bpf_prog_pack with illegal instructions Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 2/8] x86/alternative: introduce text_poke_set Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 3/8] bpf: introduce bpf_arch_text_invalidate for bpf_prog_pack Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 4/8] module: introduce module_alloc_huge Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 5/8] bpf: use module_alloc_huge for bpf_prog_pack Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 6/8] vmalloc: WARN for set_vm_flush_reset_perms() on huge pages Song Liu
2022-05-19 20:20 ` [PATCH v2 bpf-next 7/8] vmalloc: introduce huge_vmalloc_supported Song Liu
2022-05-20  0:52   ` kernel test robot
2022-05-19 20:20 ` [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size Song Liu
2022-05-20  1:57   ` kernel test robot
2022-05-20  2:53   ` kernel test robot

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.