arch/x86: kprobes: Remove MODULES dependency
Subsystems (7)
v4 cover arch/x86: kprobes: Remove MODULES dependency
Remove MODULES dependency by migrating from module_alloc() to the new text_alloc() API. Essentially these changes provide preliminaries for allowing to compile a static kernel with a proper tracing support.
The same API can be used later on in other sites that allocate space for trampolines, and trivially scaled to other arch's. An arch can inform with CONFIG_ARCH_HAS_TEXT_ALLOC that it's providing implementation for text_alloc().
I tested this by creating a trivial (x86_64_defconfig) kernel and initrd (BusyBox) and then run the most basic kprobe:
# ./kprobe p:do_sys_open
Tracing kprobe do_sys_open. Ctrl-C to end.
cat-1018 [000] .... 277.635966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.635966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.636966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.640966: do_sys_open: (do_sys_open+0x0/0x80)
cat-1018 [000] .... 277.654963: do_sys_open: (do_sys_open+0x0/0x80)I did only "sed -i 's/=m/=y/' .config" and disabled CONFIG_MODULES. The test was run under QEMU:
qemu-system-x86_64 -kernel output/images/bzImage \
-m 1G -initrd output/images/rootfs.cpio \
-append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" \
-serial stdio -display none
v3:
* Make text_alloc() API disjoint.
* Remove all the possible extra clutter not absolutely required and split into more logical pieces.
Jarkko Sakkinen (7):
module: Add lock_modules() and unlock_modules()
kprobes: Use lock_modules() and unlock_modules()
vmalloc: Add text_alloc() and text_free() arch/x86: Implement text_alloc() and text_free() arch/x86: kprobes: Use text_alloc() in alloc_insn_page()
kprobes: Use text_alloc() and text_free()
kprobes: Flag out CONFIG_MODULES dependent code
arch/Kconfig | 2 +- arch/x86/Kconfig | 3 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/kprobes/core.c | 8 +---- arch/x86/kernel/text_alloc.c | 41 ++++++++++++++++++++++++ include/linux/module.h | 32 ++++++++++++++----- include/linux/vmalloc.h | 23 ++++++++++++++ kernel/kprobes.c | 57 +++++++++++++++++++++------------- kernel/trace/trace_kprobe.c | 20 +++++++++--- 9 files changed, 146 insertions(+), 41 deletions(-) create mode 100644 arch/x86/kernel/text_alloc.c
Signature · 1 line
2.25.1
PATCH v4 1/7 module: Add lock_modules() and unlock_modules()
Add wrapper functions for acquiring module_mutex so that the locking can be implicitly compiled out when CONFIG_MODULES is not enabled.
--- include/linux/module.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/linux/module.h +18 -0
@@ -705,6 +705,16 @@ static inline bool is_livepatch_module(struct module *mod)bool is_module_sig_enforced (void );void set_module_sig_enforced (void ); +static inline void lock_modules (void ) +{ +mutex_lock (&module_mutex); +} + +static inline void unlock_modules (void ) +{ +mutex_unlock (&module_mutex); +} +#else /* !CONFIG_MODULES... */ static inline struct module *__module_address (unsigned long addr)
@@ -852,6 +862,14 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr) return ptr; } +static inline void lock_modules (void ) +{ +} + +static inline void unlock_modules (void ) +{ +} +#endif /* CONFIG_MODULES */ #ifdef CONFIG_SYSFS
Signature · 1 line
2.25.1
PATCH v4 2/7 kprobes: Use lock_modules() and unlock_modules()
In reply to Jarkko SakkinenUse lock_modules() and unlock_modules() in order to remove compile time dependency to the module subsystem.
--- kernel/kprobes.c | 4 ++-- kernel/trace/trace_kprobe.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/kprobes.c +2 -2
@@ -564,7 +564,7 @@ static void kprobe_optimizer(struct work_struct *work)cpus_read_lock ();mutex_lock (&text_mutex);/* Lock modules while optimizing kprobes */ -mutex_lock (&module_mutex); +lock_modules ();/* * Step 1: Unoptimize kprobes and collect cleaned (unused and disarmed)
@@ -589,7 +589,7 @@ static void kprobe_optimizer(struct work_struct *work)/* Step 4: Free cleaned kprobes after quiesence period */ do_free_cleaned_kprobes (); -mutex_unlock (&module_mutex); +unlock_modules ();mutex_unlock (&text_mutex);cpus_read_unlock ();
kernel/trace/trace_kprobe.c +2 -2
@@ -122,9 +122,9 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)if (!p)return true; *p ='\0' ; -mutex_lock (&module_mutex); +lock_modules (); ret = !!find_module (tk->symbol); -mutex_unlock (&module_mutex); +unlock_modules (); *p =':' ;return ret;
Signature · 1 line
2.25.1
PATCH v4 3/7 vmalloc: Add text_alloc() and text_free()
In reply to Jarkko SakkinenIntroduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrapping module_alloc() and module_memfree().
--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/linux/vmalloc.h +23 -0
@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h>
@@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region); +#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +} +#endif +#endif /* _LINUX_VMALLOC_H */
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
I love your patch! Yet something to improve:
Hi Jarkko,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc5 next-20200716]
[cannot apply to tip/x86/core tip/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jarkko-Sakkinen/arch-x86-kprobes-Remove-MODULES-dependency/20200717-110947 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 07a56bb875afbe39dabbf6ba7b83783d166863db config: ia64-allmodconfig (attached as .config) compiler: ia64-linux-gcc (GCC) 9.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
WARNING: unmet direct dependencies detected for FRAME_POINTER
Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
Selected by
- FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM && !ARC && !X86 scripts/Makefile.build:65: 'arch/ia64/kernel/palinfo.ko' 'arch/ia64/kernel/mca_recovery.ko' 'arch/ia64/kernel/err_inject.ko' will not be built even though obj-m is specified. scripts/Makefile.build:66: You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.
In file included from include/asm-generic/percpu.h:7,
from arch/ia64/include/asm/percpu.h:46,
from arch/ia64/include/asm/processor.h:76,
from arch/ia64/include/asm/thread_info.h:12,
from include/linux/thread_info.h:38,
from include/asm-generic/preempt.h:5,
from ./arch/ia64/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/rcupdate.h:27,
from include/linux/rculist.h:11,
from include/linux/sched/signal.h:5,
from arch/ia64/kernel/asm-offsets.c:10:
include/linux/topology.h: In function 'cpu_smt_mask':
>> arch/ia64/include/asm/topology.h:45:50: error: 'cpu_sibling_map' undeclared (first use in this function)
45 | #define topology_sibling_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu))
| ^~~~~~~~~~~~~~~
include/linux/percpu-defs.h:219:47: note: in definition of macro '__verify_pcpu_ptr'
219 | const void __percpu = (typeof((ptr) + 0))NULL; | ^~~
include/linux/percpu-defs.h:269:29: note: in expansion of macro 'per_cpu_ptr'
269 | #define per_cpu(var, cpu) cpu))
| ^~~~~~~~~~~
arch/ia64/include/asm/topology.h:45:42: note: in expansion of macro 'per_cpu'
45 | #define topology_sibling_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu))
| ^~~~~~~
include/linux/topology.h:204:9: note: in expansion of macro 'topology_sibling_cpumask'
204 | return topology_sibling_cpumask(cpu);
| ^~~~~~~~~~~~~~~~~~~~~~~~
arch/ia64/include/asm/topology.h:45:50: note: each undeclared identifier is reported only once for each function it appears in
45 | #define topology_sibling_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu))
| ^~~~~~~~~~~~~~~
include/linux/percpu-defs.h:219:47: note: in definition of macro '__verify_pcpu_ptr'
219 | const void __percpu = (typeof((ptr) + 0))NULL; | ^~~
include/linux/percpu-defs.h:269:29: note: in expansion of macro 'per_cpu_ptr'
269 | #define per_cpu(var, cpu) cpu))
| ^~~~~~~~~~~
arch/ia64/include/asm/topology.h:45:42: note: in expansion of macro 'per_cpu'
45 | #define topology_sibling_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu))
| ^~~~~~~
include/linux/topology.h:204:9: note: in expansion of macro 'topology_sibling_cpumask'
204 | return topology_sibling_cpumask(cpu);
| ^~~~~~~~~~~~~~~~~~~~~~~~
arch/ia64/kernel/asm-offsets.c: At top level:
arch/ia64/kernel/asm-offsets.c:23:6: warning: no previous prototype for 'foo'
23 | void foo(void)
| ^~~
Makefile arch block certs crypto drivers fs include init ipc kernel lib mm net scripts security sound source usr virt [scripts/Makefile.build:114: arch/ia64/kernel/asm-offsets.s] Error 1 Target '__build' not remade because of errors.
Makefile arch block certs crypto drivers fs include init ipc kernel lib mm net scripts security sound source usr virt [Makefile:1175: prepare0] Error 2 Target 'prepare' not remade because of errors.
make: Makefile arch block certs crypto drivers fs include init ipc kernel lib mm net scripts security sound source usr virt [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/cpu_sibling_map +45 arch/ia64/include/asm/topology.h
^1da177e4c3f41 include/asm-ia64/topology.h Linus Torvalds 2005-04-16 40 69dcc99199fe29 include/asm-ia64/topology.h Zhang, Yanmin 2006-02-03 41 #ifdef CONFIG_SMP 69dcc99199fe29 include/asm-ia64/topology.h Zhang, Yanmin 2006-02-03 42 #define topology_physical_package_id(cpu) (cpu_data(cpu)->socket_id) 69dcc99199fe29 include/asm-ia64/topology.h Zhang, Yanmin 2006-02-03 43 #define topology_core_id(cpu) (cpu_data(cpu)->core_id) 333af15341b2f6 arch/ia64/include/asm/topology.h Rusty Russell 2009-01-01 44 #define topology_core_cpumask(cpu) (&cpu_core_map[cpu]) 06931e62246844 arch/ia64/include/asm/topology.h Bartosz Golaszewski 2015-05-26 @45 #define topology_sibling_cpumask(cpu) (&per_cpu(cpu_sibling_map, cpu)) 69dcc99199fe29 include/asm-ia64/topology.h Zhang, Yanmin 2006-02-03 46 #endif 69dcc99199fe29 include/asm-ia64/topology.h Zhang, Yanmin 2006-02-03 47
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
In reply to Jarkko SakkinenI love your patch! Yet something to improve:
Hi Jarkko,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on jeyu/modules-next v5.8-rc5 next-20200716] [cannot apply to tip/x86/core tip/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jarkko-Sakkinen/arch-x86-kprobes-Remove-MODULES-dependency/20200717-110947 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 07a56bb875afbe39dabbf6ba7b83783d166863db config: sparc-randconfig-s031-20200717 (attached as .config) compiler: sparc64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-49-g707c5017-dirty
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from arch/sparc/include/asm/page.h:10,
from arch/sparc/include/asm/string_32.h:13,
from arch/sparc/include/asm/string.h:7,
from include/linux/string.h:20,
from include/linux/bitmap.h:9,
from include/linux/cpumask.h:12,
from arch/sparc/include/asm/smp_32.h:15,
from arch/sparc/include/asm/smp.h:7,
from arch/sparc/include/asm/switch_to_32.h:5,
from arch/sparc/include/asm/switch_to.h:7,
from arch/sparc/include/asm/ptrace.h:120,
from arch/sparc/include/asm/thread_info_32.h:19,
from arch/sparc/include/asm/thread_info.h:7,
from include/linux/thread_info.h:38,
from include/asm-generic/preempt.h:5,
from ./arch/sparc/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:16,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
>> include/linux/mmzone.h:1317:29: error: expected identifier or '(' before 'unsigned'
1317 | static inline int pfn_valid(unsigned long pfn)
| ^~~~~~~~
arch/sparc/include/asm/page_32.h:133:28: note: in definition of macro 'pfn_valid'
133 | #define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr))
| ^~~
>> arch/sparc/include/asm/page_32.h:133:33: error: expected ')' before '>=' token
133 | #define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr))
| ^~
include/linux/mmzone.h:1317:19: note: in expansion of macro 'pfn_valid'
1317 | static inline int pfn_valid(unsigned long pfn)
| ^~~~~~~~~
arch/sparc/include/asm/page_32.h:133:48: error: expected ')' before '&&' token
133 | #define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr))
| ^~
include/linux/mmzone.h:1317:19: note: in expansion of macro 'pfn_valid'
1317 | static inline int pfn_valid(unsigned long pfn)
| ^~~~~~~~~
In file included from include/linux/page-flags-layout.h:28,
from include/linux/mmzone.h:19,
from include/linux/gfp.h:6,
from include/linux/umh.h:4,
from include/linux/kmod.h:9,
from include/linux/module.h:16,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/mmzone.h: In function 'pfn_in_present_section':
>> arch/sparc/include/asm/sparsemem.h:11:33: error: 'MAX_PHYS_ADDRESS_BITS' undeclared (first use in this function); did you mean 'MAX_PHYSADDR_BITS'?
11 | #define MAX_PHYSMEM_BITS MAX_PHYS_ADDRESS_BITS
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/page-flags-layout.h:31:25: note: in expansion of macro 'MAX_PHYSMEM_BITS'
31 | #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
| ^~~~~~~~~~~~~~~~
include/linux/mmzone.h:1104:34: note: in expansion of macro 'SECTIONS_SHIFT'
1104 | #define NR_MEM_SECTIONS (1UL << SECTIONS_SHIFT)
| ^~~~~~~~~~~~~~
include/linux/mmzone.h:1336:32: note: in expansion of macro 'NR_MEM_SECTIONS'
1336 | if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
| ^~~~~~~~~~~~~~~
arch/sparc/include/asm/sparsemem.h:11:33: note: each undeclared identifier is reported only once for each function it appears in
11 | #define MAX_PHYSMEM_BITS MAX_PHYS_ADDRESS_BITS
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/page-flags-layout.h:31:25: note: in expansion of macro 'MAX_PHYSMEM_BITS'
31 | #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
| ^~~~~~~~~~~~~~~~
include/linux/mmzone.h:1104:34: note: in expansion of macro 'SECTIONS_SHIFT'
1104 | #define NR_MEM_SECTIONS (1UL << SECTIONS_SHIFT)
| ^~~~~~~~~~~~~~
include/linux/mmzone.h:1336:32: note: in expansion of macro 'NR_MEM_SECTIONS'
1336 | if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
| ^~~~~~~~~~~~~~~
In file included from include/linux/local_lock.h:5,
from include/linux/radix-tree.h:19,
from include/linux/idr.h:15,
from include/linux/kernfs.h:13,
from include/linux/sysfs.h:16,
from include/linux/kobject.h:20,
from include/linux/of.h:17,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/local_lock_internal.h: In function 'local_lock_acquire':
>> include/linux/local_lock_internal.h:41:13: error: 'current' undeclared (first use in this function)
41 | l->owner = current;
| ^~~~~~~
In file included from include/linux/kernel.h:11,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:15,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/local_lock_internal.h: In function 'local_lock_release':
include/linux/local_lock_internal.h:46:34: error: 'current' undeclared (first use in this function)
46 | DEBUG_LOCKS_WARN_ON(l->owner != current);
| ^~~~~~~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/local_lock_internal.h:46:2: note: in expansion of macro 'DEBUG_LOCKS_WARN_ON'
46 | DEBUG_LOCKS_WARN_ON(l->owner != current);
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/sched/signal.h:7,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/sched.h: In function 'is_percpu_thread':
>> include/linux/sched.h:1552:10: error: 'current' undeclared (first use in this function)
1552 | return (current->flags & PF_NO_SETAFFINITY) &&
| ^~~~~~~
include/linux/sched.h: In function 'current_restore_flags':
include/linux/sched.h:1613:2: error: 'current' undeclared (first use in this function)
1613 | current->flags &= ~flags;
| ^~~~~~~
In file included from arch/sparc/include/asm/uaccess.h:7,
from include/linux/uaccess.h:11,
from include/linux/sched/task.h:11,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
arch/sparc/include/asm/uaccess_32.h: In function 'clear_user':
>> arch/sparc/include/asm/uaccess_32.h:28:19: error: 'current' undeclared (first use in this function)
28 | #define get_fs() (current->thread.current_ds)
| ^~~~~~~
arch/sparc/include/asm/uaccess_32.h:38:49: note: in definition of macro '__user_ok'
38 | #define __user_ok(addr, size) ({ (void)(size); (addr) < STACK_TOP; })
| ^~~~
arch/sparc/include/asm/uaccess_32.h:40:53: note: in expansion of macro 'get_fs'
40 | #define __access_ok(addr, size) (__user_ok((addr) & get_fs().seg, (size)))
| ^~~~~~
arch/sparc/include/asm/uaccess_32.h:273:11: note: in expansion of macro '__access_ok'
273 | if (n && __access_ok((unsigned long) addr, n))
| ^~~~~~~~~~~
In file included from include/linux/kernel.h:11,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:15,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/uaccess.h: In function '_copy_from_user':
>> arch/sparc/include/asm/uaccess_32.h:28:19: error: 'current' undeclared (first use in this function)
28 | #define get_fs() (current->thread.current_ds)
| ^~~~~~~
include/linux/compiler.h:77:40: note: in definition of macro 'likely'
77 | # define likely(x) __builtin_expect(!!(x), 1)
| ^
arch/sparc/include/asm/uaccess_32.h:40:34: note: in expansion of macro '__user_ok'
40 | #define __access_ok(addr, size) (__user_ok((addr) & get_fs().seg, (size)))
| ^~~~~~~~~
arch/sparc/include/asm/uaccess_32.h:40:53: note: in expansion of macro 'get_fs'
40 | #define __access_ok(addr, size) (__user_ok((addr) & get_fs().seg, (size)))
| ^~~~~~
arch/sparc/include/asm/uaccess_32.h:41:31: note: in expansion of macro '__access_ok'
41 | #define access_ok(addr, size) __access_ok((unsigned long)(addr), size)
| ^~~~~~~~~~~
include/linux/uaccess.h:111:13: note: in expansion of macro 'access_ok'
111 | if (likely(access_ok(from, n))) {
| ^~~~~~~~~
In file included from arch/sparc/include/asm/uaccess.h:7,
from include/linux/uaccess.h:11,
from include/linux/sched/task.h:11,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/uaccess.h: In function '_copy_to_user':
>> arch/sparc/include/asm/uaccess_32.h:28:19: error: 'current' undeclared (first use in this function)
28 | #define get_fs() (current->thread.current_ds)
| ^~~~~~~
arch/sparc/include/asm/uaccess_32.h:38:49: note: in definition of macro '__user_ok'
38 | #define __user_ok(addr, size) ({ (void)(size); (addr) < STACK_TOP; })
| ^~~~
arch/sparc/include/asm/uaccess_32.h:40:53: note: in expansion of macro 'get_fs'
40 | #define __access_ok(addr, size) (__user_ok((addr) & get_fs().seg, (size)))
| ^~~~~~
arch/sparc/include/asm/uaccess_32.h:41:31: note: in expansion of macro '__access_ok'
41 | #define access_ok(addr, size) __access_ok((unsigned long)(addr), size)
| ^~~~~~~~~~~
include/linux/uaccess.h:129:6: note: in expansion of macro 'access_ok'
129 | if (access_ok(to, n)) {
| ^~~~~~~~~
include/linux/uaccess.h: In function 'copy_in_user':
>> arch/sparc/include/asm/uaccess_32.h:28:19: error: 'current' undeclared (first use in this function)
28 | #define get_fs() (current->thread.current_ds)
| ^~~~~~~
arch/sparc/include/asm/uaccess_32.h:38:49: note: in definition of macro '__user_ok'
38 | #define __user_ok(addr, size) ({ (void)(size); (addr) < STACK_TOP; })
| ^~~~
arch/sparc/include/asm/uaccess_32.h:40:53: note: in expansion of macro 'get_fs'
40 | #define __access_ok(addr, size) (__user_ok((addr) & get_fs().seg, (size)))
| ^~~~~~
arch/sparc/include/asm/uaccess_32.h:41:31: note: in expansion of macro '__access_ok'
41 | #define access_ok(addr, size) __access_ok((unsigned long)(addr), size)
| ^~~~~~~~~~~
include/linux/uaccess.h:160:6: note: in expansion of macro 'access_ok'
160 | if (access_ok(to, n) && access_ok(from, n))
| ^~~~~~~~~
In file included from include/linux/sched/task.h:11,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
>> include/linux/uaccess.h:161:7: error: implicit declaration of function 'raw_copy_in_user'; did you mean 'raw_copy_to_user'? [-Werror=implicit-function-declaration]
161 | n = raw_copy_in_user(to, from, n);
| ^~~~~~~~~~~~~~~~
| raw_copy_to_user
include/linux/uaccess.h: In function 'pagefault_disabled_inc':
>> include/linux/uaccess.h:168:2: error: 'current' undeclared (first use in this function)
168 | current->pagefault_disabled++;
| ^~~~~~~
include/linux/uaccess.h: In function 'pagefault_disabled_dec':
include/linux/uaccess.h:173:2: error: 'current' undeclared (first use in this function)
173 | current->pagefault_disabled--;
| ^~~~~~~
include/linux/uaccess.h: In function 'pagefault_disabled':
include/linux/uaccess.h:208:9: error: 'current' undeclared (first use in this function)
208 | return current->pagefault_disabled != 0;
| ^~~~~~~
In file included from include/linux/kernel.h:15,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:15,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/ratelimit.h: In function 'ratelimit_state_exit':
>> include/linux/ratelimit.h:63:4: error: 'current' undeclared (first use in this function)
63 | current->comm, rs->missed);
| ^~~~~~~
include/linux/printk.h:348:37: note: in definition of macro 'pr_warn'
348 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~
In file included from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/sched/signal.h: In function 'kernel_dequeue_signal':
>> include/linux/sched/signal.h:280:29: error: 'current' undeclared (first use in this function)
280 | struct task_struct *task = current;
| ^~~~~~~
include/linux/sched/signal.h: In function 'kernel_signal_stop':
include/linux/sched/signal.h:293:17: error: 'current' undeclared (first use in this function)
293 | spin_lock_irq(¤t->sighand->siglock);
| ^~~~~~~
include/linux/sched/signal.h: In function 'restart_syscall':
include/linux/sched/signal.h:352:22: error: 'current' undeclared (first use in this function)
352 | set_tsk_thread_flag(current, TIF_SIGPENDING);
| ^~~~~~~
In file included from include/linux/kernel.h:11,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:15,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/sched/signal.h: In function 'fault_signal_pending':
include/linux/sched/signal.h:391:26: error: 'current' undeclared (first use in this function)
391 | (fatal_signal_pending(current) ||
| ^~~~~~~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
In file included from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/sched/signal.h: In function 'restore_saved_sigmask':
include/linux/sched/signal.h:497:26: error: 'current' undeclared (first use in this function)
497 | __set_current_blocked(¤t->saved_sigmask);
| ^~~~~~~
include/linux/sched/signal.h: In function 'sigmask_to_save':
include/linux/sched/signal.h:512:19: error: 'current' undeclared (first use in this function)
512 | sigset_t *res = ¤t->blocked;
| ^~~~~~~
include/linux/sched/signal.h: In function 'on_sig_stack':
include/linux/sched/signal.h:541:6: error: 'current' undeclared (first use in this function)
541 | if (current->sas_ss_flags & SS_AUTODISARM)
| ^~~~~~~
include/linux/sched/signal.h: In function 'sas_ss_flags':
include/linux/sched/signal.h:555:7: error: 'current' undeclared (first use in this function)
555 | if (!current->sas_ss_size)
| ^~~~~~~
include/linux/sched/signal.h: In function 'sigsp':
include/linux/sched/signal.h:574:10: error: 'current' undeclared (first use in this function)
574 | return current->sas_ss_sp + current->sas_ss_size;
| ^~~~~~~
include/linux/sched/signal.h: In function 'rlimit':
include/linux/sched/signal.h:710:21: error: 'current' undeclared (first use in this function)
710 | return task_rlimit(current, limit);
| ^~~~~~~
include/linux/sched/signal.h: In function 'rlimit_max':
include/linux/sched/signal.h:715:25: error: 'current' undeclared (first use in this function)
715 | return task_rlimit_max(current, limit);
| ^~~~~~~
In file included from include/linux/rbtree.h:22,
from include/linux/vmalloc.h:10,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/rcuwait.h: In function 'prepare_to_rcuwait':
>> include/linux/rcuwait.h:47:30: error: 'current' undeclared (first use in this function)
47 | rcu_assign_pointer(w->task, current);
| ^~~~~~~
include/linux/rcupdate.h:409:36: note: in definition of macro 'rcu_assign_pointer'
409 | uintptr_t _r_a_p__v = (uintptr_t)(v); \
| ^
In file included from include/linux/sched/signal.h:7,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/rcuwait.h: In function 'finish_rcuwait':
include/linux/sched.h:133:3: error: 'current' undeclared (first use in this function)
133 | current->task_state_change = _THIS_IP_; \
| ^~~~~~~
include/linux/rcuwait.h:53:2: note: in expansion of macro '__set_current_state'
53 | __set_current_state(TASK_RUNNING);
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/fs.h:38,
from include/linux/proc_fs.h:10,
from arch/sparc/include/asm/prom.h:18,
from include/linux/of.h:250,
from arch/sparc/include/asm/openprom.h:15,
from arch/sparc/include/asm/oplib_32.h:12,
from arch/sparc/include/asm/oplib.h:7,
from arch/sparc/include/asm/pgtable_32.h:32,
from arch/sparc/include/asm/pgtable.h:7,
from arch/sparc/include/asm/viking.h:13,
from arch/sparc/include/asm/mbus.h:12,
from arch/sparc/include/asm/elf_32.h:94,
from arch/sparc/include/asm/elf.h:7,
from include/linux/elf.h:6,
from include/linux/module.h:18,
from include/linux/moduleloader.h:6,
from include/linux/vmalloc.h:12,
from include/asm-generic/io.h:911,
from arch/sparc/include/asm/io_32.h:14,
from arch/sparc/include/asm/io.h:7,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:18,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
include/linux/ioprio.h: In function 'get_current_ioprio':
>> include/linux/ioprio.h:79:27: error: 'current' undeclared (first use in this function)
79 | struct io_context *ioc = current->io_context;
| ^~~~~~~
In file included from arch/sparc/include/asm/page_32.h:136,
from arch/sparc/include/asm/page.h:10,
from arch/sparc/include/asm/string_32.h:13,
from arch/sparc/include/asm/string.h:7,
from include/linux/string.h:20,
from include/linux/bitmap.h:9,
from include/linux/cpumask.h:12,
from arch/sparc/include/asm/smp_32.h:15,
from arch/sparc/include/asm/smp.h:7,
from arch/sparc/include/asm/switch_to_32.h:5,
from arch/sparc/include/asm/switch_to.h:7,
from arch/sparc/include/asm/ptrace.h:120,
from arch/sparc/include/asm/thread_info_32.h:19,
from arch/sparc/include/asm/thread_info.h:7,
from include/linux/thread_info.h:38,
from include/asm-generic/preempt.h:5,
from ./arch/sparc/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:16,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
arch/sparc/include/asm/pgtable_32.h: In function 'pmd_page':
include/asm-generic/memory_model.h:54:29: error: 'vmemmap' undeclared (first use in this function); did you mean 'mem_map'?
54 | #define __pfn_to_page(pfn) (vmemmap + (pfn))
| ^~~~~~~
include/asm-generic/memory_model.h:82:21: note: in expansion of macro '__pfn_to_page'
82 | #define pfn_to_page __pfn_to_page
| ^~~~~~~~~~~~~
arch/sparc/include/asm/pgtable_32.h:135:9: note: in expansion of macro 'pfn_to_page'
135 | return pfn_to_page((pmd_val(pmd) & SRMMU_PTD_PMASK) >> (PAGE_SHIFT-4));
| ^~~~~~~~~~~
In file included from arch/sparc/include/asm/page.h:10,
from arch/sparc/include/asm/string_32.h:13,
from arch/sparc/include/asm/string.h:7,
from include/linux/string.h:20,
from include/linux/bitmap.h:9,
from include/linux/cpumask.h:12,
from arch/sparc/include/asm/smp_32.h:15,
from arch/sparc/include/asm/smp.h:7,
from arch/sparc/include/asm/switch_to_32.h:5,
from arch/sparc/include/asm/switch_to.h:7,
from arch/sparc/include/asm/ptrace.h:120,
from arch/sparc/include/asm/thread_info_32.h:19,
from arch/sparc/include/asm/thread_info.h:7,
from include/linux/thread_info.h:38,
from include/asm-generic/preempt.h:5,
from ./arch/sparc/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/seqlock.h:36,
from include/linux/time.h:6,
from arch/sparc/vdso/vdso32/../vclock_gettime.c:16,
from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
arch/sparc/include/asm/pgtable_32.h: In function 'mk_pte':
include/asm-generic/memory_model.h:55:54: error: 'vmemmap' undeclared (first use in this function); did you mean 'mem_map'?
55 | #define __page_to_pfn(page) (unsigned long)((page) - vmemmap)
| ^~~~~~~
arch/sparc/include/asm/page_32.h:99:19: note: in definition of macro '__pte'
99 | #define __pte(x) (x)
| ^
include/asm-generic/memory_model.h:81:21: note: in expansion of macro '__page_to_pfn'
81 | #define page_to_pfn __page_to_pfn
| ^~~~~~~~~~~~~
arch/sparc/include/asm/pgtable_32.h:297:16: note: in expansion of macro 'page_to_pfn'
297 | return __pte((page_to_pfn(page) << (PAGE_SHIFT-4)) | pgprot_val(pgprot));
| ^~~~~~~~~~~ In file included from arch/sparc/vdso/vdso32/vclock_gettime.c:22:
arch/sparc/vdso/vdso32/../vclock_gettime.c: At top level:
arch/sparc/vdso/vdso32/../vclock_gettime.c:254:1: warning: no previous prototype for '__vdso_clock_gettime' [-Wmissing-prototypes]
254 | __vdso_clock_gettime(clockid_t clock, struct __kernel_old_timespec *ts)
| ^~~~~~~~~~~~~~~~~~~~
arch/sparc/vdso/vdso32/../vclock_gettime.c:282:1: warning: no previous prototype for '__vdso_clock_gettime_stick' [-Wmissing-prototypes]
282 | __vdso_clock_gettime_stick(clockid_t clock, struct __kernel_old_timespec *ts)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/sparc/vdso/vdso32/../vclock_gettime.c:307:1: warning: no previous prototype for '__vdso_gettimeofday' [-Wmissing-prototypes]
307 | __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
| ^~~~~~~~~~~~~~~~~~~
arch/sparc/vdso/vdso32/../vclock_gettime.c:343:1: warning: no previous prototype for '__vdso_gettimeofday_stick' [-Wmissing-prototypes]
343 | __vdso_gettimeofday_stick(struct __kernel_old_timeval *tv, struct timezone *tz)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +1317 include/linux/mmzone.h
f46edbd1b1516d Dan Williams 2019-07-18 1315
7b7bf499f79de3 Will Deacon 2011-05-19 1316 #ifndef CONFIG_HAVE_ARCH_PFN_VALID
d41dee369bff3b Andy Whitcroft 2005-06-23 @1317 static inline int pfn_valid(unsigned long pfn)
d41dee369bff3b Andy Whitcroft 2005-06-23 1318 {
f46edbd1b1516d Dan Williams 2019-07-18 1319 struct mem_section *ms;
f46edbd1b1516d Dan Williams 2019-07-18 1320
d41dee369bff3b Andy Whitcroft 2005-06-23 1321 if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
d41dee369bff3b Andy Whitcroft 2005-06-23 1322 return 0;
f46edbd1b1516d Dan Williams 2019-07-18 1323 ms = __nr_to_section(pfn_to_section_nr(pfn));
f46edbd1b1516d Dan Williams 2019-07-18 1324 if (!valid_section(ms))
f46edbd1b1516d Dan Williams 2019-07-18 1325 return 0;
f46edbd1b1516d Dan Williams 2019-07-18 1326 /*
f46edbd1b1516d Dan Williams 2019-07-18 1327 * Traditionally early sections always returned pfn_valid() for
f46edbd1b1516d Dan Williams 2019-07-18 1328 * the entire section-sized span.
f46edbd1b1516d Dan Williams 2019-07-18 1329 */
f46edbd1b1516d Dan Williams 2019-07-18 1330 return early_section(ms) || pfn_section_valid(ms, pfn);
d41dee369bff3b Andy Whitcroft 2005-06-23 1331 }
7b7bf499f79de3 Will Deacon 2011-05-19 1332 #endif
d41dee369bff3b Andy Whitcroft 2005-06-23 1333 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Masami Hiramatsu
maintainerRe: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
In reply to Jarkko SakkinenQuoted 4 lines · On Fri, 17 Jul 2020 06:04:17 +0300 Jarkko Sakkinen…
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().
Doesn't it depend on CONFIG_MODULE?
Thank you,
Quoted 51 lines
Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +23
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region); +#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +} +#endif +#endif /* _LINUX_VMALLOC_H */ Signature · 1 line
2.25.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
Quoted 9 lines · Masami Hiramatsu
Quoted 4 lines · On Fri, 17 Jul 2020 06:04:17 +0300 Jarkko Sakkinen…
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Doesn't it depend on
CONFIG_MODULE?
The idea would be that arch specifically promotes that it has text allocator that is not dependent on module subsystem.
E.g. like the patch set does for x86.
/Jarkko
Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
In reply to Jarkko SakkinenQuoted 39 lines · Jarkko Sakkinen
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +11
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region);
include/linux/vmalloc.h pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · line 272
Quoted 10 lines
include/linux/vmalloc.h +10
-0+#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +}
Using module_alloc() as the default implementation of generic text_alloc() does not sound right to me.
I would suggest rename module_alloc() to text_alloc() on x86, as Peter proposed and then add text_alloc_kprobes() that can be overridden by the architectures. x86 could use text_alloc(), arm64 vmalloc() with options of their choice and the fallback would remain module_alloc(). Something like (untested) patch below:
From 928b6903e76ebf5790fc415f9eed390e400e5bc3 Mon Sep 17 00:00:00 2001
From: Mike Rapoport <[email protected]>
Date: Sat, 18 Jul 2020 19:13:02 +0300
Subject: [PATCH] kprobes: introduce text_alloc_kprobes() and
text_free_kprobes()
--- arch/Kconfig | 5 ++++- arch/arm64/Kconfig | 1 + arch/arm64/kernel/probes/kprobes.c | 10 ++++++++-- arch/x86/Kconfig | 3 ++- arch/x86/kernel/kprobes/core.c | 9 ++++----- include/linux/kprobes.h | 17 +++++++++++++++-- kernel/kprobes.c | 8 ++++---- 7 files changed, 38 insertions(+), 15 deletions(-)
arch/Kconfig +4 -1
@@ -61,7 +61,7 @@ config OPROFILE_NMI_TIMER config KPROBES bool "Kprobes" - depends on MODULES + depends on MODULES || HAVE_KPROBES_TEXT_ALLOC depends on HAVE_KPROBES select KALLSYMS help
@@ -186,6 +186,9 @@ config HAVE_IOREMAP_PROT config HAVE_KPROBES bool +config HAVE_KPROBES_TEXT_ALLOC + bool + config HAVE_KRETPROBES bool
arch/arm64/Kconfig +1 -0
@@ -177,6 +177,7 @@ config ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES + select HAVE_KPROBES_TEXT_ALLOC select HAVE_KRETPROBES select HAVE_GENERIC_VDSO select IOMMU_DMA if IOMMU_SUPPORT
arch/arm64/kernel/probes/kprobes.c +8 -2
@@ -118,13 +118,19 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)return 0 ; } -void *alloc_insn_page (void ) +void *text_alloc_kprobes (unsigned long size) { -return __vmalloc_node_range (PAGE_SIZE ,1 ,VMALLOC_START ,VMALLOC_END , +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL_ROX ,VM_FLUSH_RESET_PERMS ,NUMA_NO_NODE ,__builtin_return_address (0 )); } +void text_free_kprobes (void *mem) +{ +lockdep_assert_irqs_enabled (); +vfree (mem); +} +/* arm kprobe: install breakpoint in text */ void __kprobes arch_arm_kprobe (struct kprobe *p) {
arch/x86/Kconfig +1 -0
@@ -190,6 +190,7 @@ config X86 select HAVE_KERNEL_XZ select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE + select HAVE_KPROBES_TEXT_ALLOC select HAVE_FUNCTION_ERROR_INJECTION select HAVE_KRETPROBES select HAVE_KVM
arch/x86/kernel/kprobes/core.c +4 -5
@@ -418,12 +418,11 @@ static int prepare_boost(kprobe_opcode_t *buf, struct kprobe *p,return len; } -/* Make page to RO mode when allocate it */ -void *alloc_insn_page (void ) +void *text_alloc_kprobes (unsigned long size) {void *page; - page =module_alloc (PAGE_SIZE ); + page =text_alloc (size);if (!page)return NULL ;
@@ -444,9 +443,9 @@ void *alloc_insn_page(void) }/* Recover page to RW mode before releasing it */ -void free_insn_page (void *page) +void text_free_kprobes (void *page) { -module_memfree (page); +text_free (page); }static int arch_copy_kprobe (struct kprobe *p)
include/linux/kprobes.h +15 -2
@@ -27,6 +27,7 @@#include <linux/rcupdate.h> #include <linux/mutex.h> #include <linux/ftrace.h> +#include <linux/moduleloader.h> #include <asm/kprobes.h> #ifdef CONFIG_KPROBES
@@ -374,8 +375,20 @@ int enable_kprobe(struct kprobe *kp);void dump_kprobe (struct kprobe *kp); -void *alloc_insn_page (void ); -void free_insn_page (void *page); +#ifdef CONFIG_HAVE_KPROBES_TEXT_ALLOC +void *text_alloc_kprobes (unsigned long size); +void text_free_kprobes (void *page); +#else +static inline void *text_alloc_kprobes (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free_kprobes (void *page) +{ +module_memfree (page); +} +#endif #else /* !CONFIG_KPROBES: */
kernel/kprobes.c +4 -4
@@ -109,14 +109,14 @@ enum kprobe_slot_state { SLOT_USED = 2, }; -void __weak *alloc_insn_page (void ) +static void *alloc_insn_page (void ) { -return module_alloc (PAGE_SIZE ); +return text_alloc_kprobes (PAGE_SIZE ); } -void __weak free_insn_page (void *page) +static void free_insn_page (void *page) { -module_memfree (page); +text_free_kprobes (page); }struct kprobe_insn_cache kprobe_insn_slots = {
Signature · 1 line
2.26.2
Quoted 6 lines
include/linux/vmalloc.h +2
-0+#endif +#endif /* _LINUX_VMALLOC_H */ Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours, Mike.
Masami Hiramatsu
maintainerRe: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
Quoted 54 lines · On Sat, 18 Jul 2020 19:23:59 +0300 Mike Rapoport <[email protected]> wrote:
Quoted 39 lines · Jarkko Sakkinen
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +11
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region);include/linux/vmalloc.h pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · line 272
Quoted 10 lines
include/linux/vmalloc.h +10
-0+#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +}Using
module_alloc()as the default implementation of generictext_alloc()does not sound right to me.
Quoted 5 lines
I would suggest rename
module_alloc()totext_alloc()on x86, as Peter proposed and then addtext_alloc_kprobes()that can be overridden by the architectures. x86 could usetext_alloc(), arm64vmalloc()with options of their choice and the fallback would remainmodule_alloc(). Something like (untested) patch below:
Hmm, of course we need some more work on this patch (e.g. MODULE_STATE_* for callbacks), but basically, this direction seems good to me for the first step.
If other dynamic trampoline code (ftrace and bpf) are interested in replacing the module_alloc() with text_alloc_*(), we should revisit how we can unify it (or at least share the common parts.)
BTW, this changes CONFIG_MODULES dependency according to the architecture implementation. It also should be noted somewhere.
Thank you,
Quoted 193 lines
From
928b6903e76ebf5790fc415f9eed390e400e5bc3Mon Sep 17 00:00:00 2001
From: Mike Rapoport <[email protected]>
Date: Sat, 18 Jul 2020 19:13:02 +0300
Subject: [PATCH] kprobes: introducetext_alloc_kprobes()and
text_free_kprobes()Signed-off-by Mike Rapoport <[email protected]>--- arch/Kconfig | 5 ++++- arch/arm64/Kconfig | 1 + arch/arm64/kernel/probes/kprobes.c | 10 ++++++++-- arch/x86/Kconfig | 3 ++- arch/x86/kernel/kprobes/core.c | 9 ++++----- include/linux/kprobes.h | 17 +++++++++++++++-- kernel/kprobes.c | 8 ++++---- 7 files changed, 38 insertions(+), 15 deletions(-)arch/Kconfig +4
-1@@ -61,7 +61,7 @@ config OPROFILE_NMI_TIMER config KPROBES bool "Kprobes" - depends on MODULES + depends on MODULES || HAVE_KPROBES_TEXT_ALLOC depends on HAVE_KPROBES select KALLSYMS help@@ -186,6 +186,9 @@ config HAVE_IOREMAP_PROT config HAVE_KPROBES bool +config HAVE_KPROBES_TEXT_ALLOC + bool + config HAVE_KRETPROBES boolarch/arm64/Kconfig +1
-0@@ -177,6 +177,7 @@ config ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES + select HAVE_KPROBES_TEXT_ALLOC select HAVE_KRETPROBES select HAVE_GENERIC_VDSO select IOMMU_DMA if IOMMU_SUPPORTarch/arm64/kernel/probes/kprobes.c +8
-2@@ -118,13 +118,19 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)return 0 ; } -void *alloc_insn_page (void ) +void *text_alloc_kprobes (unsigned long size) { -return __vmalloc_node_range (PAGE_SIZE ,1 ,VMALLOC_START ,VMALLOC_END , +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL_ROX ,VM_FLUSH_RESET_PERMS ,NUMA_NO_NODE ,__builtin_return_address (0 )); } +void text_free_kprobes (void *mem) +{ +lockdep_assert_irqs_enabled (); +vfree (mem); +} +/* arm kprobe: install breakpoint in text */ void __kprobes arch_arm_kprobe (struct kprobe *p) {arch/x86/Kconfig +1
-0@@ -190,6 +190,7 @@ config X86 select HAVE_KERNEL_XZ select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE + select HAVE_KPROBES_TEXT_ALLOC select HAVE_FUNCTION_ERROR_INJECTION select HAVE_KRETPROBES select HAVE_KVMarch/x86/kernel/kprobes/core.c +4
-5@@ -418,12 +418,11 @@ static int prepare_boost(kprobe_opcode_t *buf, struct kprobe *p,return len; } -/* Make page to RO mode when allocate it */ -void *alloc_insn_page (void ) +void *text_alloc_kprobes (unsigned long size) {void *page; - page =module_alloc (PAGE_SIZE ); + page =text_alloc (size);if (!page)return NULL ;@@ -444,9 +443,9 @@ void *alloc_insn_page(void) }/* Recover page to RW mode before releasing it */ -void free_insn_page (void *page) +void text_free_kprobes (void *page) { -module_memfree (page); +text_free (page); }static int arch_copy_kprobe (struct kprobe *p)include/linux/kprobes.h +15
-2@@ -27,6 +27,7 @@#include <linux/rcupdate.h> #include <linux/mutex.h> #include <linux/ftrace.h> +#include <linux/moduleloader.h> #include <asm/kprobes.h> #ifdef CONFIG_KPROBES @@ -374,8 +375,20 @@ int enable_kprobe(struct kprobe *kp);void dump_kprobe (struct kprobe *kp); -void *alloc_insn_page (void ); -void free_insn_page (void *page); +#ifdef CONFIG_HAVE_KPROBES_TEXT_ALLOC +void *text_alloc_kprobes (unsigned long size); +void text_free_kprobes (void *page); +#else +static inline void *text_alloc_kprobes (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free_kprobes (void *page) +{ +module_memfree (page); +} +#endif #else /* !CONFIG_KPROBES: */ kernel/kprobes.c +4
-4@@ -109,14 +109,14 @@ enum kprobe_slot_state { SLOT_USED = 2, }; -void __weak *alloc_insn_page (void ) +static void *alloc_insn_page (void ) { -return module_alloc (PAGE_SIZE ); +return text_alloc_kprobes (PAGE_SIZE ); } -void __weak free_insn_page (void *page) +static void free_insn_page (void *page) { -module_memfree (page); +text_free_kprobes (page); }struct kprobe_insn_cache kprobe_insn_slots = {Signature · 1 line
2.26.2Quoted 6 lines
include/linux/vmalloc.h +2
-0+#endif +#endif /* _LINUX_VMALLOC_H */ Signature · 1 line
2.25.1Signature · 2 lines
Sincerely yours, Mike.
Signature · 1 line
Masami Hiramatsu <[email protected]>
Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
In reply to Mike RapoportQuoted 54 lines · Mike Rapoport
Quoted 39 lines · Jarkko Sakkinen
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +11
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region);include/linux/vmalloc.h pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · line 272
Quoted 10 lines
include/linux/vmalloc.h +10
-0+#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +}Using
module_alloc()as the default implementation of generictext_alloc()does not sound right to me.
Quoted 5 lines
I would suggest rename
module_alloc()totext_alloc()on x86, as Peter proposed and then addtext_alloc_kprobes()that can be overridden by the architectures. x86 could usetext_alloc(), arm64vmalloc()with options of their choice and the fallback would remainmodule_alloc(). Something like (untested) patch below:
I'm not exactly sure which of the below is relevant as the patch set includes the exact same changes with maybe different phrasing:
https://lore.kernel.org/lkml/[email protected]/
If there is something that these patches are missing, please do remark but these seven patches have been at least tested and split in reasonable manner.
/Jarkko
Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
Quoted 55 lines · Jarkko Sakkinen
Quoted 54 lines · Mike Rapoport
Quoted 39 lines · Jarkko Sakkinen
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +11
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region);include/linux/vmalloc.h pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · line 272
Quoted 10 lines
include/linux/vmalloc.h +10
-0+#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +}Using
module_alloc()as the default implementation of generictext_alloc()does not sound right to me.
Quoted 8 lines
Quoted 5 lines
I would suggest rename
module_alloc()totext_alloc()on x86, as Peter proposed and then addtext_alloc_kprobes()that can be overridden by the architectures. x86 could usetext_alloc(), arm64vmalloc()with options of their choice and the fallback would remainmodule_alloc(). Something like (untested) patch below:I'm not exactly sure which of the below is relevant as the patch set includes the exact same changes with maybe different phrasing:
The difference in parsing is what differentiates semantically clean code from duct tape.
As several people pointed out, a single text_alloc(), and apprently a single ARCH_HAS_TEXT_ALLOC, would not fit all architectures and some ground work required to implement a generic text allocation.
Your patch works aroung this for x86 with broken semantics of text_alloc() when ARCH_HAS_TEXT_ALLOC is not defined.
My suggestion does not make text_alloc() a special case of module_alloc() but rather makes text_alloc_kprobes() to fallback to module_alloc() when architecture does not provide its implementation.
Quoted 5 lines
https://lore.kernel.org/lkml/[email protected]/
If there is something that these patches are missing, please do remark but these seven patches have been at least tested and split in reasonable manner.
My patch is not tested because I only wanted to help with transiontion from module_alloc() in kprobes to a new clean interface, I don't really care if kprobes will depend on MODULES...
Quoted 1 line
/Jarkko
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
Quoted 72 lines · Mike Rapoport
Quoted 55 lines · Jarkko Sakkinen
Quoted 54 lines · Mike Rapoport
Quoted 39 lines · Jarkko Sakkinen
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +11
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region);include/linux/vmalloc.h pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · line 272
Quoted 10 lines
include/linux/vmalloc.h +10
-0+#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +}Using
module_alloc()as the default implementation of generictext_alloc()does not sound right to me.Quoted 8 lines
Quoted 5 lines
I would suggest rename
module_alloc()totext_alloc()on x86, as Peter proposed and then addtext_alloc_kprobes()that can be overridden by the architectures. x86 could usetext_alloc(), arm64vmalloc()with options of their choice and the fallback would remainmodule_alloc(). Something like (untested) patch below:I'm not exactly sure which of the below is relevant as the patch set includes the exact same changes with maybe different phrasing:
The difference in parsing is what differentiates semantically clean code from duct tape.
As several people pointed out, a single
text_alloc(), and apprently a singleARCH_HAS_TEXT_ALLOC, would not fit all architectures and some ground work required to implement a generic text allocation.
Quoted 6 lines
Your patch works aroung this for x86 with broken semantics of
text_alloc()whenARCH_HAS_TEXT_ALLOCis not defined.My suggestion does not make
text_alloc()a special case ofmodule_alloc()but rather makestext_alloc_kprobes()to fallback tomodule_alloc()when architecture does not provide its implementation.
OK, I see your point now. I'll response in detail to v5 comments.
Thank you.
/Jarkko
Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
Quoted 76 lines · Jarkko Sakkinen
Quoted 75 lines · Mike Rapoport
Quoted 55 lines · Jarkko Sakkinen
Quoted 54 lines · Mike Rapoport
Quoted 39 lines · Jarkko Sakkinen
Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with
CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation wrappingmodule_alloc()andmodule_memfree().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>--- include/linux/vmalloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)include/linux/vmalloc.h +11
-0@@ -9,6 +9,7 @@#include <asm/page.h> /* pgprot_t */ #include <linux/rbtree.h> #include <linux/overflow.h> +#include <linux/moduleloader.h> #include <asm/vmalloc.h> @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)int register_vmap_purge_notifier (struct notifier_block *nb);int unregister_vmap_purge_notifier (struct notifier_block *nb); +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* +* Allocate memory to be used for dynamic trampoline code. +*/ +void *text_alloc (unsigned long size); + +/* +* Free memory returned from text_alloc(). +*/ +void text_free (void *region);include/linux/vmalloc.h pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · line 272
Quoted 10 lines
include/linux/vmalloc.h +10
-0+#else +static inline void *text_alloc (unsigned long size) +{ +return module_alloc (size); +} + +static inline void text_free (void *region) +{ +module_memfree (region); +}Using
module_alloc()as the default implementation of generictext_alloc()does not sound right to me.Quoted 8 lines
Quoted 5 lines
I would suggest rename
module_alloc()totext_alloc()on x86, as Peter proposed and then addtext_alloc_kprobes()that can be overridden by the architectures. x86 could usetext_alloc(), arm64vmalloc()with options of their choice and the fallback would remainmodule_alloc(). Something like (untested) patch below:I'm not exactly sure which of the below is relevant as the patch set includes the exact same changes with maybe different phrasing:
The difference in parsing is what differentiates semantically clean code from duct tape.
As several people pointed out, a single
text_alloc(), and apprently a singleARCH_HAS_TEXT_ALLOC, would not fit all architectures and some ground work required to implement a generic text allocation.Your patch works aroung this for x86 with broken semantics of
text_alloc()whenARCH_HAS_TEXT_ALLOCis not defined.
Quoted 7 lines
Quoted 3 lines
My suggestion does not make
text_alloc()a special case ofmodule_alloc()but rather makestext_alloc_kprobes()to fallback tomodule_alloc()when architecture does not provide its implementation.OK, I see your point now. I'll response in detail to v5 comments.
Thank you.
I also extended the explicit CC list heavily for follow up version. Apologies if this have been somewhat confusing so far (e.g. getting only a subportion of patches).
/Jarkko
PATCH v4 4/7 arch/x86: Implement text_alloc() and text_free()
In reply to Jarkko SakkinenImplement text_alloc() and text_free() with vmalloc() and vfree(), thus dropping the dependency to the module subsystem.
--- arch/x86/Kconfig | 3 +++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/text_alloc.c | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 arch/x86/kernel/text_alloc.c
arch/x86/Kconfig +3 -0
@@ -2035,6 +2035,9 @@ config KEXEC_FILE config ARCH_HAS_KEXEC_PURGATORY def_bool KEXEC_FILE +config ARCH_HAS_TEXT_ALLOC + def_bool y + config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE
arch/x86/kernel/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-y += tsc.o tsc_msr.o io_delay.o rtc.o obj-y += pci-iommu_table.o obj-y += resource.o obj-y += irqflags.o +obj-y += text_alloc.o obj-y += process.o obj-y += fpu/
arch/x86/kernel/text_alloc.c new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 5/7 arch/x86: kprobes: Use text_alloc() in alloc_insn_page()
In reply to Jarkko SakkinenUse text_alloc() as part of the arch specific implementation for alloc_insn_page().
--- arch/x86/kernel/kprobes/core.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
arch/x86/kernel/kprobes/core.c +1 -7
@@ -423,7 +423,7 @@ void *alloc_insn_page(void) {void *page; - page =module_alloc (PAGE_SIZE ); + page =text_alloc (PAGE_SIZE );if (!page)return NULL ;
@@ -443,12 +443,6 @@ void *alloc_insn_page(void)return page; } -/* Recover page to RW mode before releasing it */ -void free_insn_page (void *page) -{ -module_memfree (page); -} -static int arch_copy_kprobe (struct kprobe *p) {struct insn insn;
Signature · 1 line
2.25.1
Re: [PATCH v4 5/7] arch/x86: kprobes: Use text_alloc() in alloc_insn_page()
Quoted 24 lines · Jarkko Sakkinen
Use
text_alloc()as part of the arch specific implementation foralloc_insn_page().Cc Andi Kleen <[email protected]>Cc Masami Hiramatsu <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>Im--- arch/x86/kernel/kprobes/core.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)arch/x86/kernel/kprobes/core.c +1
-1@@ -423,7 +423,7 @@ void *alloc_insn_page(void) {void *page; - page =module_alloc (PAGE_SIZE ); + page =text_alloc (PAGE_SIZE );if (!page)return NULL ;
arch/x86/kernel/kprobes/core.c void *alloc_insn_page(void) · line 449
Quoted 7 lines
arch/x86/kernel/kprobes/core.c +0
-4@@ -443,12 +443,6 @@ void *alloc_insn_page(void)return page; } -/* Recover page to RW mode before releasing it */ -void free_insn_page (void *page) -{ -module_memfree (page);
This must be a mistake. Should be just changed to call text_memfree().
Probably just my clumsiness when refactoring the series.
Quoted 8 lines
arch/x86/kernel/kprobes/core.c +0
-2-} -static int arch_copy_kprobe (struct kprobe *p) {struct insn insn;Signature · 1 line
2.25.1
/Jarkko
PATCH v4 6/7 kprobes: Use text_alloc() and text_free()
In reply to Jarkko SakkinenUse text_alloc() and text_free(). Those arch's that provide their allocators will benefit from this because they can provide their custom allocator and render out the compile time dep to the module subsystem. Other arch's will continue to work as the fallback implementations call module_alloc() and module_memfree().
--- kernel/kprobes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kprobes.c +3 -2
@@ -40,6 +40,7 @@#include <asm/cacheflush.h> #include <asm/errno.h> #include <linux/uaccess.h> +#include <linux/vmalloc.h> #define KPROBE_HASH_BITS 6#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
@@ -111,12 +112,12 @@ enum kprobe_slot_state {void __weak *alloc_insn_page (void ) { -return module_alloc (PAGE_SIZE ); +return text_alloc (PAGE_SIZE ); }void __weak free_insn_page (void *page) { -module_memfree (page); +text_free (page); }struct kprobe_insn_cache kprobe_insn_slots = {
Signature · 1 line
2.25.1
PATCH v4 7/7 kprobes: Flag out CONFIG_MODULES dependent code
In reply to Jarkko SakkinenRemove CONFIG_MODULES dependency by flagging out the dependent code. This allows to use kprobes in a kernel without support for loadable modules, which could be useful for a test kernel or perhaps an embedded kernel.
--- arch/Kconfig | 2 +- include/linux/module.h | 14 +++++------ kernel/kprobes.c | 48 +++++++++++++++++++++++-------------- kernel/trace/trace_kprobe.c | 16 +++++++++++-- 4 files changed, 52 insertions(+), 28 deletions(-)
arch/Kconfig +1 -1
@@ -61,7 +61,7 @@ config OPROFILE_NMI_TIMER config KPROBES bool "Kprobes" - depends on MODULES + depends on MODULES || ARCH_HAS_TEXT_ALLOC depends on HAVE_KPROBES select KALLSYMS help
include/linux/module.h +7 -7
@@ -290,6 +290,13 @@ extern typeof(name) __mod_##type##__##name##_device_table \struct notifier_block ; +enum module_state { +MODULE_STATE_LIVE ,/* Normal state. */ +MODULE_STATE_COMING ,/* Full formed, running module_init. */ +MODULE_STATE_GOING ,/* Going away. */ +MODULE_STATE_UNFORMED ,/* Still setting it up. */ +}; +#ifdef CONFIG_MODULES extern int modules_disabled;/* for sysctl */
@@ -305,13 +312,6 @@ struct module_use {struct module *source, *target; }; -enum module_state { -MODULE_STATE_LIVE ,/* Normal state. */ -MODULE_STATE_COMING ,/* Full formed, running module_init. */ -MODULE_STATE_GOING ,/* Going away. */ -MODULE_STATE_UNFORMED ,/* Still setting it up. */ -}; -struct mod_tree_node {struct module *mod;struct latch_tree_node node;
kernel/kprobes.c +30 -18
78 lines not on this page · raw message
kernel/trace/trace_kprobe.c +14 -2
@@ -103,8 +103,9 @@ static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk)return !!(kprobe_gone (&tk->rp.kp)); } +#ifdef CONFIG_MODULES static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, -struct module *mod) +struct module *mod) {int len =strlen (mod->name);const char *name =trace_kprobe_symbol (tk);
@@ -129,6 +130,17 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)return ret; } +#else +static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, +struct module *mod) +{ +return false; +} +static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) +{ +return false; +} +#endif static bool trace_kprobe_is_busy (struct dyn_event *ev) {
@@ -688,7 +700,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb,if (ret)pr_warn ("Failed to re-register probe %s on %s: %d\n" ,trace_probe_name (&tk->tp), - mod->name, ret); +module_name (mod), ret); } }mutex_unlock (&event_mutex);
Signature · 1 line
2.25.1