uprobe: uretprobe speed up
Subsystems (13)
Jiri Olsa
reviewerv8 cover uprobe: uretprobe speed up
hi,
as part of the effort on speeding up the uprobes [0] coming with return uprobe optimization by using syscall instead of the trap on the uretprobe trampoline.
The speed up depends on instruction type that uprobe is installed and depends on specific HW type, please check patch 1 for details.
Patches 1-8 are based on bpf-next/master, but patch 2 and 3 are apply-able on linux-trace.git tree probes/for-next branch. Patch 9 is based on man-pages master.
v8 changes:
- rebased (another new syscall got merged)
- added acks
Also available at:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
uretprobe_syscall
thanks,
jirka
Notes to check list items in Documentation/process/adding-syscalls.rst:
- System Call Alternatives
New syscall seems like the best way in here, because we need just to quickly enter kernel with no extra arguments processing, which we'd need to do if we decided to use another syscall.
- Designing the API: Planning for Extension
The uretprobe syscall is very specific and most likely won't be extended in the future.
At the moment it does not take any arguments and even if it does in future, it's allowed to be called only from trampoline prepared by kernel, so there'll be no broken user.
- Designing the API: Other Considerations
N/A because uretprobe syscall does not return reference to kernel object.
- Proposing the API
Wiring up of the uretprobe system call is in separate change, selftests and man page changes are part of the patchset.
- Generic System Call Implementation
There's no CONFIG option for the new functionality because it keeps the same behaviour from the user POV.
- x86 System Call Implementation
It's 64-bit syscall only.
- Compatibility System Calls (Generic)
N/A uretprobe syscall has no arguments and is not supported for compat processes.
- Compatibility System Calls (x86)
N/A uretprobe syscall is not supported for compat processes.
- System Calls Returning Elsewhere
N/A.
- Other Details
N/A.
- Testing
Adding new bpf selftests and ran ltp on top of this change.
- Man Page
Attached.
- Do not call System Calls in the Kernel
N/A.
[0] https://lore.kernel.org/bpf/ZeCXHKJ--iYYbmLj@krava/
---
Jiri Olsa (8):
x86/shstk: Make return uprobe work with shadow stack
uprobe: Wire up uretprobe system call
uprobe: Add uretprobe syscall to speed up return probe selftests/x86: Add return uprobe shadow stack test selftests/bpf: Add uretprobe syscall test for regs integrity selftests/bpf: Add uretprobe syscall test for regs changes selftests/bpf: Add uretprobe syscall call from user space test selftests/bpf: Add uretprobe shadow stack test
arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/x86/include/asm/shstk.h | 4 + arch/x86/kernel/shstk.c | 16 ++++ arch/x86/kernel/uprobes.c | 124 ++++++++++++++++++++++++++++- include/linux/syscalls.h | 2 + include/linux/uprobes.h | 3 + include/uapi/asm-generic/unistd.h | 5 +- kernel/events/uprobes.c | 24 ++++-- kernel/sys_ni.c | 2 + tools/include/linux/compiler.h | 4 + tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 123 ++++++++++++++++++++++++++++- tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 385 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/uprobe_syscall.c | 15 ++++ tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c | 17 ++++ tools/testing/selftests/x86/test_shadow_stack.c | 145 ++++++++++++++++++++++++++++++++++ 15 files changed, 860 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c
Jiri Olsa (1):
man2: Add uretprobe syscall page
man/man2/uretprobe.2 | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 man/man2/uretprobe.2
Jiri Olsa
reviewerPATCH v8 1/9 x86/shstk: Make return uprobe work with shadow stack
Currently the application with enabled shadow stack will crash if it sets up return uprobe. The reason is the uretprobe kernel code changes the user space task's stack, but does not update shadow stack accordingly.
Adding new functions to update values on shadow stack and using them in uprobe code to keep shadow stack in sync with uretprobe changes to user stack.
--- arch/x86/include/asm/shstk.h | 2 ++ arch/x86/kernel/shstk.c | 11 +++++++++++ arch/x86/kernel/uprobes.c | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-)
arch/x86/include/asm/shstk.h +2 -0
@@ -21,6 +21,7 @@ unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned long clonvoid shstk_free (struct task_struct *p);int setup_signal_shadow_stack (struct ksignal *ksig);int restore_signal_shadow_stack (void ); +int shstk_update_last_frame (unsigned long val);#else static inline long shstk_prctl (struct task_struct *task,int option,unsigned long arg2) {return -EINVAL ; }
@@ -31,6 +32,7 @@ static inline unsigned long shstk_alloc_thread_stack(struct task_struct *p,static inline void shstk_free (struct task_struct *p) {}static inline int setup_signal_shadow_stack (struct ksignal *ksig) {return 0 ; }static inline int restore_signal_shadow_stack (void ) {return 0 ; } +static inline int shstk_update_last_frame (unsigned long val) {return 0 ; }#endif /* CONFIG_X86_USER_SHADOW_STACK */ #endif /* __ASSEMBLY__ */
arch/x86/kernel/shstk.c +11 -0
@@ -577,3 +577,14 @@ long shstk_prctl(struct task_struct *task, int option, unsigned long arg2)return wrss_control (true);return -EINVAL ; } + +int shstk_update_last_frame (unsigned long val) +{ +unsigned long ssp; + +if (!features_enabled (ARCH_SHSTK_SHSTK )) +return 0 ; + + ssp =get_user_shstk_addr (); +return write_user_shstk_64 ((u64 __user *)ssp, (u64 )val); +}
arch/x86/kernel/uprobes.c +6 -1
@@ -1076,8 +1076,13 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regsreturn orig_ret_vaddr; nleft =copy_to_user ((void __user *)regs->sp, &trampoline_vaddr, rasize); -if (likely (!nleft)) +if (likely (!nleft)) { +if (shstk_update_last_frame (trampoline_vaddr)) { +force_sig (SIGSEGV ); +return -1 ; + }return orig_ret_vaddr; + }if (nleft != rasize) { pr_err("return address clobbered: pid=%d, %%sp=%#lx, %%ip=%#lx\n",
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 2/9 uprobe: Wire up uretprobe system call
In reply to Jiri OlsaWiring up uretprobe system call, which comes in following changes. We need to do the wiring before, because the uretprobe implementation needs the syscall number.
Note at the moment uretprobe syscall is supported only for native 64-bit process.
--- arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 2 ++ include/uapi/asm-generic/unistd.h | 5 ++++- kernel/sys_ni.c | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -384,6 +384,7 @@ 460 common lsm_set_self_attr sys_lsm_set_self_attr 461 common lsm_list_modules sys_lsm_list_modules 462 common mseal sys_mseal +463 64 uretprobe sys_uretprobe # # Due to a historical design error, certain syscalls are numbered differently
include/linux/syscalls.h +2 -0
@@ -973,6 +973,8 @@ asmlinkage long sys_lsm_list_modules(u64 *ids, u32 *size, u32 flags);/* x86 */ asmlinkage long sys_ioperm (unsigned long from,unsigned long num,int on); +asmlinkage long sys_uretprobe (void ); +/* pciconfig: alpha, arm, arm64, ia64, sparc */ asmlinkage long sys_pciconfig_read(unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
include/uapi/asm-generic/unistd.h +4 -1
@@ -845,8 +845,11 @@ __SYSCALL(__NR_lsm_list_modules, sys_lsm_list_modules)#define __NR_mseal 462 __SYSCALL(__NR_mseal, sys_mseal) +#define __NR_uretprobe 463 +__SYSCALL(__NR_uretprobe, sys_uretprobe) +#undef __NR_syscalls -#define __NR_syscalls 463 +#define __NR_syscalls 464/* * 32 bit systems traditionally used different
kernel/sys_ni.c +2 -0
@@ -392,3 +392,5 @@ COND_SYSCALL(setuid16);/* restartable sequence */ COND_SYSCALL (rseq); + +COND_SYSCALL (uretprobe);
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 3/9 uprobe: Add uretprobe syscall to speed up return probe
In reply to Jiri OlsaAdding uretprobe syscall instead of trap to speed up return probe.
At the moment the uretprobe setup/path is:
- install entry uprobe
- when the uprobe is hit, it overwrites probed function's return address on stack with address of the trampoline that contains breakpoint instruction
- the breakpoint trap code handles the uretprobe consumers execution and jumps back to original return address
This patch replaces the above trampoline's breakpoint instruction with new ureprobe syscall call. This syscall does exactly the same job as the trap with some more extra work:
- syscall trampoline must save original value for rax/r11/rcx registers on stack - rax is set to syscall number and r11/rcx are changed and used by syscall instruction
- the syscall code reads the original values of those registers and restore those values in task's pt_regs area
- only caller from trampoline exposed in '[uprobes]' is allowed, the process will receive SIGILL signal otherwise
Even with some extra work, using the uretprobes syscall shows speed improvement (compared to using standard breakpoint):
On Intel (11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz)
current:
uretprobe-nop : 1.498 ± 0.000M/s
uretprobe-push : 1.448 ± 0.001M/s
uretprobe-ret : 0.816 ± 0.001M/swith the fix:
uretprobe-nop : 1.969 ± 0.002M/s < 31% speed up
uretprobe-push : 1.910 ± 0.000M/s < 31% speed up
uretprobe-ret : 0.934 ± 0.000M/s < 14% speed upOn Amd (AMD Ryzen 7 5700U)
current:
uretprobe-nop : 0.778 ± 0.001M/s
uretprobe-push : 0.744 ± 0.001M/s
uretprobe-ret : 0.540 ± 0.001M/swith the fix:
uretprobe-nop : 0.860 ± 0.001M/s < 10% speed up
uretprobe-push : 0.818 ± 0.001M/s < 10% speed up
uretprobe-ret : 0.578 ± 0.000M/s < 7% speed upThe performance test spawns a thread that runs loop which triggers uprobe with attached bpf program that increments the counter that gets printed in results above.
The uprobe (and uretprobe) kind is determined by which instruction is being patched with breakpoint instruction. That's also important for uretprobes, because uprobe is installed for each uretprobe.
The performance test is part of bpf selftests:
tools/testing/selftests/bpf/run_bench_uprobes.sh
Note at the moment uretprobe syscall is supported only for native 64-bit process, compat process still uses standard breakpoint.
Note that when shadow stack is enabled the uretprobe syscall returns via iret, which is slower than return via sysret, but won't cause the shadow stack violation.
--- arch/x86/include/asm/shstk.h | 2 + arch/x86/kernel/shstk.c | 5 ++ arch/x86/kernel/uprobes.c | 117 +++++++++++++++++++++++++++++++++++ include/linux/uprobes.h | 3 + kernel/events/uprobes.c | 24 ++++--- 5 files changed, 144 insertions(+), 7 deletions(-)
arch/x86/include/asm/shstk.h +2 -0
@@ -22,6 +22,7 @@ void shstk_free(struct task_struct *p);int setup_signal_shadow_stack (struct ksignal *ksig);int restore_signal_shadow_stack (void );int shstk_update_last_frame (unsigned long val); +bool shstk_is_enabled (void );#else static inline long shstk_prctl (struct task_struct *task,int option,unsigned long arg2) {return -EINVAL ; }
@@ -33,6 +34,7 @@ static inline void shstk_free(struct task_struct *p) {}static inline int setup_signal_shadow_stack (struct ksignal *ksig) {return 0 ; }static inline int restore_signal_shadow_stack (void ) {return 0 ; }static inline int shstk_update_last_frame (unsigned long val) {return 0 ; } +static inline bool shstk_is_enabled (void ) {return false; }#endif /* CONFIG_X86_USER_SHADOW_STACK */ #endif /* __ASSEMBLY__ */
arch/x86/kernel/shstk.c +5 -0
@@ -588,3 +588,8 @@ int shstk_update_last_frame(unsigned long val) ssp =get_user_shstk_addr ();return write_user_shstk_64 ((u64 __user *)ssp, (u64 )val); } + +bool shstk_is_enabled (void ) +{ +return features_enabled (ARCH_SHSTK_SHSTK ); +}
arch/x86/kernel/uprobes.c +117 -0
129 lines not on this page · raw message
include/linux/uprobes.h +3 -0
@@ -138,6 +138,9 @@ extern bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check cextern bool arch_uprobe_ignore (struct arch_uprobe *aup,struct pt_regs *regs);extern void arch_uprobe_copy_ixol (struct page *page,unsigned long vaddr,void *src,unsigned long len); +extern void uprobe_handle_trampoline (struct pt_regs *regs); +extern void *arch_uprobe_trampoline (unsigned long *psize); +extern unsigned long uprobe_get_trampoline_vaddr (void );#else /* !CONFIG_UPROBES */ struct uprobes_state { };
kernel/events/uprobes.c +17 -7
@@ -1474,11 +1474,20 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)return ret; } +void *__weak arch_uprobe_trampoline (unsigned long *psize) +{ +static uprobe_opcode_t insn =UPROBE_SWBP_INSN ; + + *psize =UPROBE_SWBP_INSN_SIZE ; +return &insn; +} +static struct xol_area *__create_xol_area (unsigned long vaddr) {struct mm_struct *mm = current->mm; -uprobe_opcode_t insn =UPROBE_SWBP_INSN ; +unsigned long insns_size;struct xol_area *area; +void *insns; area =kmalloc (sizeof (*area),GFP_KERNEL );if (unlikely (!area))
@@ -1502,7 +1511,8 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)/* Reserve the 1st slot for get_trampoline_vaddr() */ set_bit (0 , area->bitmap);atomic_set (&area->slot_count,1 ); -arch_uprobe_copy_ixol (area->pages[0 ],0 , &insn,UPROBE_SWBP_INSN_SIZE ); + insns =arch_uprobe_trampoline (&insns_size); +arch_uprobe_copy_ixol (area->pages[0 ],0 , insns, insns_size);if (!xol_add_vma (mm, area))return area;
@@ -1827,7 +1837,7 @@ void uprobe_copy_process(struct task_struct *t, unsigned long flags)* * Returns -1 in case the xol_area is not allocated. */ -static unsigned long get_trampoline_vaddr (void ) +unsigned long uprobe_get_trampoline_vaddr (void ) {struct xol_area *area;unsigned long trampoline_vaddr =-1 ;
@@ -1878,7 +1888,7 @@ static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs)if (!ri)return ; - trampoline_vaddr =get_trampoline_vaddr (); + trampoline_vaddr =uprobe_get_trampoline_vaddr (); orig_ret_vaddr =arch_uretprobe_hijack_return_addr (trampoline_vaddr, regs);if (orig_ret_vaddr ==-1 ) goto fail;
@@ -2123,7 +2133,7 @@ static struct return_instance *find_next_ret_chain(struct return_instance *ri)return ri; } -static void handle_trampoline (struct pt_regs *regs) +void uprobe_handle_trampoline (struct pt_regs *regs) {struct uprobe_task *utask;struct return_instance *ri, *next;
@@ -2187,8 +2197,8 @@ static void handle_swbp(struct pt_regs *regs)int is_swbp; bp_vaddr =uprobe_get_swbp_addr (regs); -if (bp_vaddr ==get_trampoline_vaddr ()) -return handle_trampoline (regs); +if (bp_vaddr ==uprobe_get_trampoline_vaddr ()) +return uprobe_handle_trampoline (regs); uprobe =find_active_uprobe (bp_vaddr, &is_swbp);if (!uprobe) {
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 4/9 selftests/x86: Add return uprobe shadow stack test
In reply to Jiri OlsaAdding return uprobe test for shadow stack and making sure it's working properly. Borrowed some of the code from bpf selftests.
--- .../testing/selftests/x86/test_shadow_stack.c | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+)
tools/testing/selftests/x86/test_shadow_stack.c +145 -0
@@ -34,6 +34,7 @@#include <sys/ptrace.h> #include <sys/signal.h> #include <linux/elf.h> +#include <linux/perf_event.h> /* * Define the ABI defines if needed, so people can run the tests
@@ -734,6 +735,144 @@ int test_32bit(void)return !segv_triggered; } +static int parse_uint_from_file (const char *file,const char *fmt) +{ +int err, ret; +FILE *f; + + f =fopen (file,"re" ); +if (!f) { + err = -errno; +printf ("failed to open '%s': %d\n" , file, err); +return err; + } + err =fscanf (f, fmt, &ret); +if (err !=1 ) { + err = err ==EOF ? -EIO : -errno; +printf ("failed to parse '%s': %d\n" , file, err); +fclose (f); +return err; + } +fclose (f); +return ret; +} + +static int determine_uprobe_perf_type (void ) +{ +const char *file ="/sys/bus/event_source/devices/uprobe/type" ; + +return parse_uint_from_file (file,"%d\n" ); +} + +static int determine_uprobe_retprobe_bit (void ) +{ +const char *file ="/sys/bus/event_source/devices/uprobe/format/retprobe" ; + +return parse_uint_from_file (file,"config:%d\n" ); +} + +static ssize_t get_uprobe_offset (const void *addr) +{ +size_t start, end, base; +char buf[256 ]; +bool found = false; +FILE *f; + + f =fopen ("/proc/self/maps" ,"r" ); +if (!f) +return -errno; + +while (fscanf (f,"%zx-%zx %s %zx %*[^\n]\n" , &start, &end, buf, &base) ==4 ) { +if (buf[2 ] =='x' && (uintptr_t )addr >= start && (uintptr_t )addr < end) { + found = true; +break ; + } + } + +fclose (f); + +if (!found) +return -ESRCH ; + +return (uintptr_t )addr - start + base; +} + +static __attribute__((noinline))void uretprobe_trigger (void ) +{ + asmvolatile ("" ); +} + +/* +* This test setups return uprobe, which is sensitive to shadow stack +* (crashes without extra fix). After executing the uretprobe we fail +* the test if we receive SIGSEGV, no crash means we're good. +* +* Helper functions above borrowed from bpf selftests. +*/ +static int test_uretprobe (void ) +{ +const size_t attr_sz =sizeof (struct perf_event_attr ); +const char *file ="/proc/self/exe" ; +int bit, fd =0 , type, err =1 ; +struct perf_event_attr attr; +struct sigaction sa = {}; +ssize_t offset; + + type =determine_uprobe_perf_type (); +if (type <0 ) { +if (type == -ENOENT ) +printf ("[SKIP]\tUretprobe test, uprobes are not available\n" ); +return 0 ; + } + + offset =get_uprobe_offset (uretprobe_trigger); +if (offset <0 ) +return 1 ; + + bit =determine_uprobe_retprobe_bit (); +if (bit <0 ) +return 1 ; + + sa.sa_sigaction = segv_gp_handler; + sa.sa_flags =SA_SIGINFO ; +if (sigaction (SIGSEGV , &sa,NULL )) +return 1 ; + +/* Setup return uprobe through perf event interface. */ +memset (&attr,0 , attr_sz); + attr.size = attr_sz; + attr.type = type; + attr.config =1 << bit; + attr.config1 = (__u64 ) (unsigned long ) file; + attr.config2 = offset; + + fd =syscall (__NR_perf_event_open, &attr,0 /* pid */ ,-1 /* cpu */ , +-1 /* group_fd */ ,PERF_FLAG_FD_CLOEXEC ); +if (fd <0 ) + goto out; + +if (sigsetjmp (jmp_buffer,1 )) + goto out; + +ARCH_PRCTL (ARCH_SHSTK_ENABLE ,ARCH_SHSTK_SHSTK ); + +/* +* This either segfaults and goes through sigsetjmp above +* or succeeds and we're good. +*/ +uretprobe_trigger (); + +printf ("[OK]\tUretprobe test\n" ); + err =0 ; + +out: +ARCH_PRCTL (ARCH_SHSTK_DISABLE ,ARCH_SHSTK_SHSTK ); +signal (SIGSEGV ,SIG_DFL ); +if (fd) +close (fd); +return err; +} +void segv_handler_ptrace (int signum,siginfo_t *si,void *uc) {/* The SSP adjustment caused a segfault. */
@@ -926,6 +1065,12 @@ int main(int argc, char *argv[]) goto out; } +if (test_uretprobe ()) { + ret =1 ; +printf ("[FAIL]\turetprobe test\n" ); + goto out; + } +return ret; out:
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 5/9 selftests/bpf: Add uretprobe syscall test for regs integrity
In reply to Jiri OlsaAdd uretprobe syscall test that compares register values before and after the uretprobe is hit. It also compares the register values seen from attached bpf program.
--- tools/include/linux/compiler.h | 4 + .../selftests/bpf/prog_tests/uprobe_syscall.c | 163 ++++++++++++++++++ .../selftests/bpf/progs/uprobe_syscall.c | 15 ++ 3 files changed, 182 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall.c
tools/include/linux/compiler.h +4 -0
@@ -62,6 +62,10 @@#define __nocf_check __attribute__((nocf_check))#endif +#ifndef __naked +#define __naked __attribute__((__naked__)) +#endif +/* Are two types/vars the same type (ignoring qualifiers)? */ #ifndef __same_type# define __same_type (a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c new file +163 -0
163 lines not on this page · raw message
tools/testing/selftests/bpf/progs/uprobe_syscall.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "vmlinux.h" +#include <bpf/bpf_helpers.h> +#include <string.h> + +struct pt_regs regs; + +char _license[] SEC("license") = "GPL"; + +SEC("uretprobe//proc/self/exe:uretprobe_regs_trigger") +int uretprobe (struct pt_regs *ctx) +{ +__builtin_memcpy (®s, ctx,sizeof (regs)); +return 0 ; +}
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 6/9 selftests/bpf: Add uretprobe syscall test for regs changes
In reply to Jiri OlsaAdding test that creates uprobe consumer on uretprobe which changes some of the registers. Making sure the changed registers are propagated to the user space when the ureptobe syscall trampoline is used on x86_64.
To be able to do this, adding support to bpf_testmod to create uprobe via new attribute file:
/sys/kernel/bpf_testmod_uprobe
This file is expecting file offset and creates related uprobe on current process exe file and removes existing uprobe if offset is 0. The can be only single uprobe at any time.
The uprobe has specific consumer that changes registers used in ureprobe syscall trampoline and which are later checked in the test.
--- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 123 +++++++++++++++++- .../selftests/bpf/prog_tests/uprobe_syscall.c | 67 ++++++++++ 2 files changed, 189 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +122 -1
@@ -18,6 +18,7 @@#include <linux/in6.h> #include <linux/un.h> #include <net/sock.h> +#include <linux/namei.h> #include "bpf_testmod.h" #include "bpf_testmod_kfunc.h"
@@ -358,6 +359,119 @@ static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = { .write = bpf_testmod_test_write, }; +/* bpf_testmod_uprobe sysfs attribute is so far enabled for x86_64 only, +* please see test_uretprobe_regs_change test +*/ +#ifdef __x86_64__ + +static int +uprobe_ret_handler (struct uprobe_consumer *self,unsigned long func, +struct pt_regs *regs) + +{ + regs->ax =0x12345678deadbeef ; + regs->cx =0x87654321feebdaed ; + regs->r11 = (u64) -1 ; +return true; +} + +struct testmod_uprobe { +struct path path; +loff_t offset; +struct uprobe_consumer consumer; +}; + +static DEFINE_MUTEX (testmod_uprobe_mutex); + +static struct testmod_uprobe uprobe = { + .consumer.ret_handler = uprobe_ret_handler, +}; + +static int testmod_register_uprobe (loff_t offset) +{ +int err = -EBUSY ; + +if (uprobe.offset) +return -EBUSY ; + +mutex_lock (&testmod_uprobe_mutex); + +if (uprobe.offset) + goto out; + + err =kern_path ("/proc/self/exe" ,LOOKUP_FOLLOW , &uprobe.path); +if (err) + goto out; + + err =uprobe_register_refctr (d_real_inode (uprobe.path.dentry), + offset,0 , &uprobe.consumer); +if (err) +path_put (&uprobe.path); +else + uprobe.offset = offset; + +out: +mutex_unlock (&testmod_uprobe_mutex); +return err; +} + +static void testmod_unregister_uprobe (void ) +{ +mutex_lock (&testmod_uprobe_mutex); + +if (uprobe.offset) { +uprobe_unregister (d_real_inode (uprobe.path.dentry), + uprobe.offset, &uprobe.consumer); + uprobe.offset =0 ; + } + +mutex_unlock (&testmod_uprobe_mutex); +} + +static ssize_t +bpf_testmod_uprobe_write (struct file *file,struct kobject *kobj, +struct bin_attribute *bin_attr, +char *buf,loff_t off,size_t len) +{ +unsigned long offset =0 ; +int err =0 ; + +if (kstrtoul (buf,0 , &offset)) +return -EINVAL ; + +if (offset) + err =testmod_register_uprobe (offset); +else +testmod_unregister_uprobe (); + +return err ?:strlen (buf); +} + +static struct bin_attribute bin_attr_bpf_testmod_uprobe_file__ro_after_init = { + .attr = { .name ="bpf_testmod_uprobe" , .mode =0666 , }, + .write = bpf_testmod_uprobe_write, +}; + +static int register_bpf_testmod_uprobe (void ) +{ +return sysfs_create_bin_file (kernel_kobj, &bin_attr_bpf_testmod_uprobe_file); +} + +static void unregister_bpf_testmod_uprobe (void ) +{ +testmod_unregister_uprobe (); +sysfs_remove_bin_file (kernel_kobj, &bin_attr_bpf_testmod_uprobe_file); +} + +#else +static int register_bpf_testmod_uprobe (void ) +{ +return 0 ; +} + +static void unregister_bpf_testmod_uprobe (void ) { } +#endif + BTF_KFUNCS_START(bpf_testmod_common_kfunc_ids) BTF_ID_FLAGS(func, bpf_iter_testmod_seq_new, KF_ITER_NEW) BTF_ID_FLAGS(func, bpf_iter_testmod_seq_next, KF_ITER_NEXT | KF_RET_NULL)
@@ -912,7 +1026,13 @@ static int bpf_testmod_init(void)return -EINVAL ; sock =NULL ;mutex_init (&sock_lock); -return sysfs_create_bin_file (kernel_kobj, &bin_attr_bpf_testmod_file); + ret =sysfs_create_bin_file (kernel_kobj, &bin_attr_bpf_testmod_file); +if (ret <0 ) +return ret; + ret =register_bpf_testmod_uprobe (); +if (ret <0 ) +return ret; +return 0 ; }static void bpf_testmod_exit (void )
@@ -927,6 +1047,7 @@ static void bpf_testmod_exit(void)bpf_kfunc_close_sock ();sysfs_remove_bin_file (kernel_kobj, &bin_attr_bpf_testmod_file); +unregister_bpf_testmod_uprobe (); }module_init (bpf_testmod_init);
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +67 -0
82 lines not on this page · raw message
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 7/9 selftests/bpf: Add uretprobe syscall call from user space test
In reply to Jiri OlsaAdding test to verify that when called from outside of the trampoline provided by kernel, the uretprobe syscall will cause calling process to receive SIGILL signal and the attached bpf program is not executed.
--- .../selftests/bpf/prog_tests/uprobe_syscall.c | 95 +++++++++++++++++++ .../bpf/progs/uprobe_syscall_executed.c | 17 ++++ 2 files changed, 112 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +95 -0
@@ -7,7 +7,10 @@#include <unistd.h> #include <asm/ptrace.h> #include <linux/compiler.h> +#include <linux/stringify.h> +#include <sys/wait.h> #include "uprobe_syscall.skel.h" +#include "uprobe_syscall_executed.skel.h" __naked unsigned long uretprobe_regs_trigger (void ) {
@@ -209,6 +212,91 @@ static void test_uretprobe_regs_change(void) } } +#ifndef __NR_uretprobe +#define __NR_uretprobe 463 +#endif + +__naked unsigned long uretprobe_syscall_call_1 (void ) +{ +/* +* Pretend we are uretprobe trampoline to trigger the return +* probe invocation in order to verify we get SIGILL. +*/ + asmvolatile ( +"pushq %rax\n" +"pushq %rcx\n" +"pushq %r11\n" + "movq $" __stringify(__NR_uretprobe) ", %rax\n" +"syscall\n" +"popq %r11\n" +"popq %rcx\n" +"retq\n" + ); +} + +__naked unsigned long uretprobe_syscall_call (void ) +{ + asmvolatile ( +"call uretprobe_syscall_call_1\n" +"retq\n" + ); +} + +static void test_uretprobe_syscall_call (void ) +{ +LIBBPF_OPTS (bpf_uprobe_multi_opts, opts, + .retprobe = true, + ); +struct uprobe_syscall_executed *skel; +int pid, status, err, go[2 ], c; + +if (ASSERT_OK (pipe (go),"pipe" )) +return ; + + skel =uprobe_syscall_executed__open_and_load (); +if (!ASSERT_OK_PTR (skel,"uprobe_syscall_executed__open_and_load" )) + goto cleanup; + + pid =fork (); +if (!ASSERT_GE (pid,0 ,"fork" )) + goto cleanup; + +/* child */ +if (pid ==0 ) { +close (go[1 ]); + +/* wait for parent's kick */ + err =read (go[0 ], &c,1 ); +if (err !=1 ) +exit (-1 ); + +uretprobe_syscall_call (); +_exit (0 ); + } + + skel->links.test =bpf_program__attach_uprobe_multi (skel->progs.test, pid, +"/proc/self/exe" , +"uretprobe_syscall_call" , &opts); +if (!ASSERT_OK_PTR (skel->links.test,"bpf_program__attach_uprobe_multi" )) + goto cleanup; + +/* kick the child */ +write (go[1 ], &c,1 ); + err =waitpid (pid, &status,0 ); +ASSERT_EQ (err, pid,"waitpid" ); + +/* verify the child got killed with SIGILL */ +ASSERT_EQ (WIFSIGNALED (status),1 ,"WIFSIGNALED" ); +ASSERT_EQ (WTERMSIG (status),SIGILL ,"WTERMSIG" ); + +/* verify the uretprobe program wasn't called */ +ASSERT_EQ (skel->bss->executed,0 ,"executed" ); + +cleanup: +uprobe_syscall_executed__destroy (skel); +close (go[1 ]); +close (go[0 ]); +}#else static void test_uretprobe_regs_equal (void ) {
@@ -219,6 +307,11 @@ static void test_uretprobe_regs_change(void) {test__skip (); } + +static void test_uretprobe_syscall_call (void ) +{ +test__skip (); +}#endif void test_uprobe_syscall (void )
@@ -227,4 +320,6 @@ void test_uprobe_syscall(void)test_uretprobe_regs_equal ();if (test__start_subtest ("uretprobe_regs_change" ))test_uretprobe_regs_change (); +if (test__start_subtest ("uretprobe_syscall_call" )) +test_uretprobe_syscall_call (); }
tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "vmlinux.h" +#include <bpf/bpf_helpers.h> +#include <string.h> + +struct pt_regs regs; + +char _license[] SEC("license") = "GPL"; + +int executed =0 ; + +SEC("uretprobe.multi") +int test (struct pt_regs *regs) +{ + executed =1 ; +return 0 ; +}
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 8/9 selftests/bpf: Add uretprobe shadow stack test
In reply to Jiri OlsaAdding uretprobe shadow stack test that runs all existing uretprobe tests with shadow stack enabled if it's available.
--- .../selftests/bpf/prog_tests/uprobe_syscall.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+)
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +60 -0
@@ -9,6 +9,9 @@#include <linux/compiler.h> #include <linux/stringify.h> #include <sys/wait.h> +#include <sys/syscall.h> +#include <sys/prctl.h> +#include <asm/prctl.h> #include "uprobe_syscall.skel.h" #include "uprobe_syscall_executed.skel.h"
@@ -297,6 +300,56 @@ static void test_uretprobe_syscall_call(void)close (go[1 ]); close(go[0]); } + +/* +* Borrowed from tools/testing/selftests/x86/test_shadow_stack.c. +* +* For use in inline enablement of shadow stack. +* +* The program can't return from the point where shadow stack gets enabled +* because there will be no address on the shadow stack. So it can't use +* syscall() for enablement, since it is a function. +* +* Based on code from nolibc.h. Keep a copy here because this can't pull +* in all of nolibc.h. +*/ +#define ARCH_PRCTL (arg1, arg2) \ +({ \ + long _ret; \ + register long _num asm("eax") = __NR_arch_prctl; \ + register long _arg1 asm("rdi") = (long)(arg1); \ + register long _arg2 asm("rsi") = (long)(arg2); \ + \ + asm volatile ( \ + "syscall\n" \ + : "=a"(_ret) \ + : "r"(_arg1), "r"(_arg2), \ + "0"(_num) \ + : "rcx", "r11", "memory", "cc" \ + ); \ + _ret; \ +}) + +#ifndef ARCH_SHSTK_ENABLE +#define ARCH_SHSTK_ENABLE 0x5001 +#define ARCH_SHSTK_DISABLE 0x5002 +#define ARCH_SHSTK_SHSTK (1ULL << 0) +#endif + +static void test_uretprobe_shadow_stack (void ) +{ +if (ARCH_PRCTL (ARCH_SHSTK_ENABLE ,ARCH_SHSTK_SHSTK )) { +test__skip (); +return ; + } + +/* Run all of the uretprobe tests. */ +test_uretprobe_regs_equal (); +test_uretprobe_regs_change (); +test_uretprobe_syscall_call (); + +ARCH_PRCTL (ARCH_SHSTK_DISABLE ,ARCH_SHSTK_SHSTK ); +}#else static void test_uretprobe_regs_equal (void ) {
@@ -312,6 +365,11 @@ static void test_uretprobe_syscall_call(void) {test__skip (); } + +static void test_uretprobe_shadow_stack (void ) +{ +test__skip (); +}#endif void test_uprobe_syscall (void )
@@ -322,4 +380,6 @@ void test_uprobe_syscall(void)test_uretprobe_regs_change ();if (test__start_subtest ("uretprobe_syscall_call" ))test_uretprobe_syscall_call (); +if (test__start_subtest ("uretprobe_shadow_stack" )) +test_uretprobe_shadow_stack (); }
Signature · 1 line
2.45.1
Jiri Olsa
reviewerPATCH v8 9/9 man2: Add uretprobe syscall page
In reply to Jiri OlsaAdding man page for new uretprobe syscall.
--- man/man2/uretprobe.2 | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 man/man2/uretprobe.2
man/man2/uretprobe.2 new file +56 -0
@@ -0,0 +1,56 @@ +.\" Copyright (C) 2024, Jiri Olsa <[email protected]> +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH uretprobe 2 (date) "Linux man-pages (unreleased)" +.SH NAME +uretprobe \- execute pending return uprobes +.SH SYNOPSIS +.nf +.B int uretprobe(void) +.fi +.SH DESCRIPTION +The +.BR uretprobe () +system call is an alternative to breakpoint instructions for triggering return +uprobe consumers. +.P +Calls to +.BR uretprobe () +system call are only made from the user-space trampoline provided by the kernel. +Calls from any other place result in a +.BR SIGILL . +.SH RETURN VALUE +The +.BR uretprobe () +system call return value is architecture-specific. +.SH ERRORS +.TP +.B SIGILL +The +.BR uretprobe () +system call was called by a user-space program. +.SH VERSIONS +Details of the +.BR uretprobe () +system call behavior vary across systems. +.SH STANDARDS +None. +.SH HISTORY +TBD +.SH NOTES +The +.BR uretprobe () +system call was initially introduced for the x86_64 architecture +where it was shown to be faster than breakpoint traps. +It might be extended to other architectures. +.P +The +.BR uretprobe () +system call exists only to allow the invocation of return uprobe consumers. +It should +.B never +be called directly. +Details of the arguments (if any) passed to +.BR uretprobe () +and the return value are architecture-specific.
Signature · 1 line
2.45.1
Re: [PATCHv8 9/9] man2: Add uretprobe syscall page
Quoted 5 lines · On Tue, 11 Jun 2024 13:21:58 +0200 Jiri Olsa <[email protected]> wrote:
Adding man page for new uretprobe syscall.
Acked-by Andrii Nakryiko <[email protected]>Reviewed-by Alejandro Colomar <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
This looks good to me.
And this needs to be picked by linux-man@ project.
Thank you,
Quoted 70 lines
--- man/man2/uretprobe.2 | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 man/man2/uretprobe.2man/man2/uretprobe.2 new file +56
-0@@ -0,0 +1,56 @@ +.\" Copyright (C) 2024, Jiri Olsa <[email protected]> +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH uretprobe 2 (date) "Linux man-pages (unreleased)" +.SH NAME +uretprobe \- execute pending return uprobes +.SH SYNOPSIS +.nf +.B int uretprobe(void) +.fi +.SH DESCRIPTION +The +.BR uretprobe () +system call is an alternative to breakpoint instructions for triggering return +uprobe consumers. +.P +Calls to +.BR uretprobe () +system call are only made from the user-space trampoline provided by the kernel. +Calls from any other place result in a +.BR SIGILL . +.SH RETURN VALUE +The +.BR uretprobe () +system call return value is architecture-specific. +.SH ERRORS +.TP +.B SIGILL +The +.BR uretprobe () +system call was called by a user-space program. +.SH VERSIONS +Details of the +.BR uretprobe () +system call behavior vary across systems. +.SH STANDARDS +None. +.SH HISTORY +TBD +.SH NOTES +The +.BR uretprobe () +system call was initially introduced for the x86_64 architecture +where it was shown to be faster than breakpoint traps. +It might be extended to other architectures. +.P +The +.BR uretprobe () +system call exists only to allow the invocation of return uprobe consumers. +It should +.B never +be called directly. +Details of the arguments (if any) passed to +.BR uretprobe () +and the return value are architecture-specific.Signature · 1 line
2.45.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Alejandro Colomar
maintainerRe: [PATCHv8 9/9] man2: Add uretprobe syscall page
Hi,
Quoted 9 lines · Masami Hiramatsu
Quoted 5 lines · On Tue, 11 Jun 2024 13:21:58 +0200 Jiri Olsa <[email protected]> wrote:
Adding man page for new uretprobe syscall.
Acked-by Andrii Nakryiko <[email protected]>Reviewed-by Alejandro Colomar <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Quoted 5 lines
This looks good to me.
Reviewed-by Masami Hiramatsu (Google) <[email protected]>And this needs to be picked by linux-man@ project.
Yup; please ping me when the rest is merged and I should pick it.
Have a lovely day!
Alex
Quoted 78 lines
Thank you,
Quoted 70 lines
--- man/man2/uretprobe.2 | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 man/man2/uretprobe.2man/man2/uretprobe.2 new file +56
-0@@ -0,0 +1,56 @@ +.\" Copyright (C) 2024, Jiri Olsa <[email protected]> +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH uretprobe 2 (date) "Linux man-pages (unreleased)" +.SH NAME +uretprobe \- execute pending return uprobes +.SH SYNOPSIS +.nf +.B int uretprobe(void) +.fi +.SH DESCRIPTION +The +.BR uretprobe () +system call is an alternative to breakpoint instructions for triggering return +uprobe consumers. +.P +Calls to +.BR uretprobe () +system call are only made from the user-space trampoline provided by the kernel. +Calls from any other place result in a +.BR SIGILL . +.SH RETURN VALUE +The +.BR uretprobe () +system call return value is architecture-specific. +.SH ERRORS +.TP +.B SIGILL +The +.BR uretprobe () +system call was called by a user-space program. +.SH VERSIONS +Details of the +.BR uretprobe () +system call behavior vary across systems. +.SH STANDARDS +None. +.SH HISTORY +TBD +.SH NOTES +The +.BR uretprobe () +system call was initially introduced for the x86_64 architecture +where it was shown to be faster than breakpoint traps. +It might be extended to other architectures. +.P +The +.BR uretprobe () +system call exists only to allow the invocation of return uprobe consumers. +It should +.B never +be called directly. +Details of the arguments (if any) passed to +.BR uretprobe () +and the return value are architecture-specific.Signature · 1 line
2.45.1Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Signature · 1 line
<https://www.alejandro-colomar.es/>
Quoted 12 lines · On Tue, 11 Jun 2024 13:21:49 +0200 Jiri Olsa <[email protected]> wrote:
hi,
as part of the effort on speeding up the uprobes [0] coming with return uprobe optimization by using syscall instead of the trap on the uretprobe trampoline.The speed up depends on instruction type that uprobe is installed and depends on specific HW type, please check patch 1 for details.
Patches 1-8 are based on bpf-next/master, but patch 2 and 3 are apply-able on linux-trace.git tree probes/for-next branch. Patch 9 is based on man-pages master.
Quoted 7 lines
v8 changes:
- rebased (another new syscall got merged)
- added acksAlso available at:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
uretprobe_syscall
Applied patch [1/9] - [8/9] on probes/for-next in
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
Thank you!
Quoted 96 lines
thanks,
jirkaNotes to check list items in
Documentation/process/adding-syscalls.rst:- System Call Alternatives
New syscall seems like the best way in here, because we need just to quickly enter kernel with no extra arguments processing, which we'd need to do if we decided to use another syscall.- Designing the API: Planning for Extension
The uretprobe syscall is very specific and most likely won't be extended in the future.At the moment it does not take any arguments and even if it does in future, it's allowed to be called only from trampoline prepared by kernel, so there'll be no broken user.
- Designing the API: Other Considerations
N/A because uretprobe syscall does not return reference to kernel object.- Proposing the API
Wiring up of the uretprobe system call is in separate change, selftests and man page changes are part of the patchset.- Generic System Call Implementation
There's no CONFIG option for the new functionality because it keeps the same behaviour from the user POV.- x86 System Call Implementation
It's 64-bit syscall only.- Compatibility System Calls (Generic)
N/A uretprobe syscall has no arguments and is not supported for compat processes.- Compatibility System Calls (x86)
N/A uretprobe syscall is not supported for compat processes.- System Calls Returning Elsewhere
N/A.- Other Details
N/A.- Testing
Adding new bpf selftests and ran ltp on top of this change.- Man Page
Attached.- Do not call System Calls in the Kernel
N/A.[0] https://lore.kernel.org/bpf/ZeCXHKJ--iYYbmLj@krava/
---
Jiri Olsa (8):
x86/shstk: Make return uprobe work with shadow stack
uprobe: Wire up uretprobe system call
uprobe: Add uretprobe syscall to speed up return probe selftests/x86: Add return uprobe shadow stack test selftests/bpf: Add uretprobe syscall test for regs integrity selftests/bpf: Add uretprobe syscall test for regs changes selftests/bpf: Add uretprobe syscall call from user space test selftests/bpf: Add uretprobe shadow stack testarch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/x86/include/asm/shstk.h | 4 + arch/x86/kernel/shstk.c | 16 ++++ arch/x86/kernel/uprobes.c | 124 ++++++++++++++++++++++++++++- include/linux/syscalls.h | 2 + include/linux/uprobes.h | 3 + include/uapi/asm-generic/unistd.h | 5 +- kernel/events/uprobes.c | 24 ++++-- kernel/sys_ni.c | 2 + tools/include/linux/compiler.h | 4 + tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 123 ++++++++++++++++++++++++++++- tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 385 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/uprobe_syscall.c | 15 ++++ tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c | 17 ++++ tools/testing/selftests/x86/test_shadow_stack.c | 145 ++++++++++++++++++++++++++++++++++ 15 files changed, 860 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall_executed.cJiri Olsa (1):
man2: Add uretprobe syscall pageman/man2/uretprobe.2 | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 man/man2/uretprobe.2
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 20 lines · Masami Hiramatsu
Quoted 16 lines · On Tue, 11 Jun 2024 13:21:49 +0200 Jiri Olsa <[email protected]> wrote:
hi,
as part of the effort on speeding up the uprobes [0] coming with return uprobe optimization by using syscall instead of the trap on the uretprobe trampoline.The speed up depends on instruction type that uprobe is installed and depends on specific HW type, please check patch 1 for details.
Patches 1-8 are based on bpf-next/master, but patch 2 and 3 are apply-able on linux-trace.git tree probes/for-next branch. Patch 9 is based on man-pages master.
v8 changes:
- rebased (another new syscall got merged)
- added acks
Quoted 7 lines
Quoted 3 lines
Also available at:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
uretprobe_syscallApplied patch [1/9] - [8/9] on probes/for-next in
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
Thanks, Masami, looks good! I also confirmed that probes/for-next and bpf-next/master can be merged with no conflicts (hopefully it stays this way till the next merge window).
Quoted 102 lines
Thank you!
Quoted 90 lines
thanks,
jirkaNotes to check list items in
Documentation/process/adding-syscalls.rst:- System Call Alternatives
New syscall seems like the best way in here, because we need just to quickly enter kernel with no extra arguments processing, which we'd need to do if we decided to use another syscall.- Designing the API: Planning for Extension
The uretprobe syscall is very specific and most likely won't be extended in the future.At the moment it does not take any arguments and even if it does in future, it's allowed to be called only from trampoline prepared by kernel, so there'll be no broken user.
- Designing the API: Other Considerations
N/A because uretprobe syscall does not return reference to kernel object.- Proposing the API
Wiring up of the uretprobe system call is in separate change, selftests and man page changes are part of the patchset.- Generic System Call Implementation
There's no CONFIG option for the new functionality because it keeps the same behaviour from the user POV.- x86 System Call Implementation
It's 64-bit syscall only.- Compatibility System Calls (Generic)
N/A uretprobe syscall has no arguments and is not supported for compat processes.- Compatibility System Calls (x86)
N/A uretprobe syscall is not supported for compat processes.- System Calls Returning Elsewhere
N/A.- Other Details
N/A.- Testing
Adding new bpf selftests and ran ltp on top of this change.- Man Page
Attached.- Do not call System Calls in the Kernel
N/A.[0] https://lore.kernel.org/bpf/ZeCXHKJ--iYYbmLj@krava/
---
Jiri Olsa (8):
x86/shstk: Make return uprobe work with shadow stack
uprobe: Wire up uretprobe system call
uprobe: Add uretprobe syscall to speed up return probe selftests/x86: Add return uprobe shadow stack test selftests/bpf: Add uretprobe syscall test for regs integrity selftests/bpf: Add uretprobe syscall test for regs changes selftests/bpf: Add uretprobe syscall call from user space test selftests/bpf: Add uretprobe shadow stack testarch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/x86/include/asm/shstk.h | 4 + arch/x86/kernel/shstk.c | 16 ++++ arch/x86/kernel/uprobes.c | 124 ++++++++++++++++++++++++++++- include/linux/syscalls.h | 2 + include/linux/uprobes.h | 3 + include/uapi/asm-generic/unistd.h | 5 +- kernel/events/uprobes.c | 24 ++++-- kernel/sys_ni.c | 2 + tools/include/linux/compiler.h | 4 + tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 123 ++++++++++++++++++++++++++++- tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 385 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/uprobe_syscall.c | 15 ++++ tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c | 17 ++++ tools/testing/selftests/x86/test_shadow_stack.c | 145 ++++++++++++++++++++++++++++++++++ 15 files changed, 860 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall_executed.cQuoted 6 lines
Jiri Olsa (1):
man2: Add uretprobe syscall pageman/man2/uretprobe.2 | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 man/man2/uretprobe.2--
Masami Hiramatsu (Google) <[email protected]>
Re: [PATCHv8 bpf-next 3/9] uprobe: Add uretprobe syscall to speed up return probe
In reply to Jiri OlsaHi Jiri,
Quoted 1 line · Jiri Olsa
Adding uretprobe syscall instead of trap to speed up return probe.
...
kernel/events/uprobes.c static int xol_add_vma(struct mm_struct *mm, struct xol_area *area) · line 1479
Quoted 11 lines
kernel/events/uprobes.c +3
-0@@ -1474,11 +1474,20 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)return ret; } +void *__weak arch_uprobe_trampoline (unsigned long *psize) +{ +static uprobe_opcode_t insn =UPROBE_SWBP_INSN ;
This change as commit ff474a78cef5 ("uprobe: Add uretprobe syscall to speed up return probe") in -next causes the following build error for ARCH=loongarch allmodconfig:
In file included from include/linux/uprobes.h:49,
from include/linux/mm_types.h:16,
from include/linux/mmzone.h:22,
from include/linux/gfp.h:7,
from include/linux/xarray.h:16,
from include/linux/list_lru.h:14,
from include/linux/fs.h:13,
from include/linux/highmem.h:5,
from kernel/events/uprobes.c:13:
kernel/events/uprobes.c: In function 'arch_uprobe_trampoline':
arch/loongarch/include/asm/uprobes.h:12:33: error: initializer element is not constant
12 | #define UPROBE_SWBP_INSN larch_insn_gen_break(BRK_UPROBE_BP)
| ^~~~~~~~~~~~~~~~~~~~
kernel/events/uprobes.c:1479:39: note: in expansion of macro 'UPROBE_SWBP_INSN'
1479 | static uprobe_opcode_t insn = UPROBE_SWBP_INSN;
| ^~~~~~~~~~~~~~~~Quoted 65 lines
kernel/events/uprobes.c +13
-7+ *psize =UPROBE_SWBP_INSN_SIZE ; +return &insn; +} +static struct xol_area *__create_xol_area (unsigned long vaddr) {struct mm_struct *mm = current->mm; -uprobe_opcode_t insn =UPROBE_SWBP_INSN ; +unsigned long insns_size;struct xol_area *area; +void *insns; area =kmalloc (sizeof (*area),GFP_KERNEL );if (unlikely (!area))@@ -1502,7 +1511,8 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)/* Reserve the 1st slot for get_trampoline_vaddr() */ set_bit (0 , area->bitmap);atomic_set (&area->slot_count,1 ); -arch_uprobe_copy_ixol (area->pages[0 ],0 , &insn,UPROBE_SWBP_INSN_SIZE ); + insns =arch_uprobe_trampoline (&insns_size); +arch_uprobe_copy_ixol (area->pages[0 ],0 , insns, insns_size);if (!xol_add_vma (mm, area))return area;@@ -1827,7 +1837,7 @@ void uprobe_copy_process(struct task_struct *t, unsigned long flags)* * Returns -1 in case the xol_area is not allocated. */ -static unsigned long get_trampoline_vaddr (void ) +unsigned long uprobe_get_trampoline_vaddr (void ) {struct xol_area *area;unsigned long trampoline_vaddr =-1 ;@@ -1878,7 +1888,7 @@ static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs)if (!ri)return ; - trampoline_vaddr =get_trampoline_vaddr (); + trampoline_vaddr =uprobe_get_trampoline_vaddr (); orig_ret_vaddr =arch_uretprobe_hijack_return_addr (trampoline_vaddr, regs);if (orig_ret_vaddr ==-1 ) goto fail;@@ -2123,7 +2133,7 @@ static struct return_instance *find_next_ret_chain(struct return_instance *ri)return ri; } -static void handle_trampoline (struct pt_regs *regs) +void uprobe_handle_trampoline (struct pt_regs *regs) {struct uprobe_task *utask;struct return_instance *ri, *next;@@ -2187,8 +2197,8 @@ static void handle_swbp(struct pt_regs *regs)int is_swbp; bp_vaddr =uprobe_get_swbp_addr (regs); -if (bp_vaddr ==get_trampoline_vaddr ()) -return handle_trampoline (regs); +if (bp_vaddr ==uprobe_get_trampoline_vaddr ()) +return uprobe_handle_trampoline (regs); uprobe =find_active_uprobe (bp_vaddr, &is_swbp);if (!uprobe) {Signature · 1 line
2.45.1
Cheers,
Nathan
Re: [PATCHv8 bpf-next 3/9] uprobe: Add uretprobe syscall to speed up return probe
Quoted 34 lines · Nathan Chancellor
Hi Jiri,
Quoted 1 line · Jiri Olsa
Adding uretprobe syscall instead of trap to speed up return probe.
...
kernel/events/uprobes.c static int xol_add_vma(struct mm_struct *mm, struct xol_area *area) · line 1479
Quoted 11 lines
kernel/events/uprobes.c +3
-0@@ -1474,11 +1474,20 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)return ret; } +void *__weak arch_uprobe_trampoline (unsigned long *psize) +{ +static uprobe_opcode_t insn =UPROBE_SWBP_INSN ;This change as commit
ff474a78cef5("uprobe: Add uretprobe syscall to speed up return probe") in -next causes the following build error for ARCH=loongarch allmodconfig:In file included from
include/linux/uprobes.h:49,from include/linux/mm_types.h:16, from include/linux/mmzone.h:22, from include/linux/gfp.h:7, from include/linux/xarray.h:16, from include/linux/list_lru.h:14, from include/linux/fs.h:13, from include/linux/highmem.h:5, from kernel/events/uprobes.c:13: kernel/events/uprobes.c: In function 'arch_uprobe_trampoline': arch/loongarch/include/asm/uprobes.h:12:33: error: initializer element is not constant 12 | #define UPROBE_SWBP_INSN larch_insn_gen_break(BRK_UPROBE_BP) | ^~~~~~~~~~~~~~~~~~~~
Quoted 2 lines
kernel/events/uprobes.c:1479:39: note: in expansion of macro 'UPROBE_SWBP_INSN'
1479 | staticuprobe_opcode_tinsn =UPROBE_SWBP_INSN;
reproduced, could you please try the change below
thanks,
jirka
---
kernel/events/uprobes.c +2 -1
@@ -1476,8 +1476,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)void *__weak arch_uprobe_trampoline (unsigned long *psize) { -static uprobe_opcode_t insn =UPROBE_SWBP_INSN ; +static uprobe_opcode_t insn; + insn = insn ?:UPROBE_SWBP_INSN ; *psize =UPROBE_SWBP_INSN_SIZE ;return &insn; }
Nathan Chancellor
Tested-byRe: [PATCHv8 bpf-next 3/9] uprobe: Add uretprobe syscall to speed up return probe
Quoted 38 lines · Jiri Olsa
Quoted 34 lines · Nathan Chancellor
Hi Jiri,
Quoted 1 line · Jiri Olsa
Adding uretprobe syscall instead of trap to speed up return probe.
...
kernel/events/uprobes.c static int xol_add_vma(struct mm_struct *mm, struct xol_area *area) · line 1479
Quoted 11 lines
kernel/events/uprobes.c +3
-0@@ -1474,11 +1474,20 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)return ret; } +void *__weak arch_uprobe_trampoline (unsigned long *psize) +{ +static uprobe_opcode_t insn =UPROBE_SWBP_INSN ;This change as commit
ff474a78cef5("uprobe: Add uretprobe syscall to speed up return probe") in -next causes the following build error for ARCH=loongarch allmodconfig:In file included from
include/linux/uprobes.h:49,from include/linux/mm_types.h:16, from include/linux/mmzone.h:22, from include/linux/gfp.h:7, from include/linux/xarray.h:16, from include/linux/list_lru.h:14, from include/linux/fs.h:13, from include/linux/highmem.h:5, from kernel/events/uprobes.c:13: kernel/events/uprobes.c: In function 'arch_uprobe_trampoline': arch/loongarch/include/asm/uprobes.h:12:33: error: initializer element is not constant 12 | #define UPROBE_SWBP_INSN larch_insn_gen_break(BRK_UPROBE_BP) | ^~~~~~~~~~~~~~~~~~~~Quoted 2 lines
kernel/events/uprobes.c:1479:39: note: in expansion of macro 'UPROBE_SWBP_INSN'
1479 | staticuprobe_opcode_tinsn =UPROBE_SWBP_INSN;
Quoted 1 line
reproduced, could you please try the change below
Yeah, that fixes the issue for me.
Quoted 16 lines
---
kernel/events/uprobes.c +2
-1@@ -1476,8 +1476,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)void *__weak arch_uprobe_trampoline (unsigned long *psize) { -static uprobe_opcode_t insn =UPROBE_SWBP_INSN ; +static uprobe_opcode_t insn; + insn = insn ?:UPROBE_SWBP_INSN ; *psize =UPROBE_SWBP_INSN_SIZE ;return &insn; }
Re: [PATCHv8 bpf-next 3/9] uprobe: Add uretprobe syscall to speed up return probe
In reply to Jiri OlsaQuoted 2 lines · Jiri Olsa
Adding uretprobe syscall instead of trap to speed up return probe.
This patch results in:
Building loongarch:allmodconfig ... failed
--------------
Error log:
In file included from include/linux/uprobes.h:49,
from include/linux/mm_types.h:16,
from include/linux/mmzone.h:22,
from include/linux/gfp.h:7,
from include/linux/xarray.h:16,
from include/linux/list_lru.h:14,
from include/linux/fs.h:13,
from include/linux/highmem.h:5,
from kernel/events/uprobes.c:13:
kernel/events/uprobes.c: In function 'arch_uprobe_trampoline':
arch/loongarch/include/asm/uprobes.h:12:33: error: initializer element is not constant
12 | #define UPROBE_SWBP_INSN larch_insn_gen_break(BRK_UPROBE_BP)
| ^~~~~~~~~~~~~~~~~~~~
kernel/events/uprobes.c:1479:39: note: in expansion of macro 'UPROBE_SWBP_INSN'
1479 | static uprobe_opcode_t insn = UPROBE_SWBP_INSN;
| ^~~~~~~~~~~~~~~~Bisect log attached.
Guenter
---
# bad: [2102cb0d050d34d50b9642a3a50861787527e922] Add linux-next specific files for 20240619
# good: [6ba59ff4227927d3a8530fc2973b80e94b54d58f] Linux 6.10-rc4
git bisect start 'HEAD' 'v6.10-rc4'
# good: [a8fa5261ec87d5aafd3211548d93008d5739457d] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
git bisect good a8fa5261ec87d5aafd3211548d93008d5739457d
# good: [ee551f4db89753511a399b808db75654facec7c8] Merge branch 'for-linux-next' of https://gitlab.freedesktop.org/drm/i915/kernel
git bisect good ee551f4db89753511a399b808db75654facec7c8
# bad: [ec3557f4b791d72d93bfb69702d441d2c9f8cd0d] Merge branch 'next' of git://git.kernel.org/pub/scm/virt/kvm/kvm.git
git bisect bad ec3557f4b791d72d93bfb69702d441d2c9f8cd0d
# good: [29e7873afb5768f7af65802d021ee0c9bf2167be] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git
git bisect good 29e7873afb5768f7af65802d021ee0c9bf2167be
# good: [ffe376e4a4ec29bb29d97664b72ff607e86f5b02] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
git bisect good ffe376e4a4ec29bb29d97664b72ff607e86f5b02
# bad: [39264a48da368f5394289133802f7d105dd3a33c] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
git bisect bad 39264a48da368f5394289133802f7d105dd3a33c
# good: [8af40c77dfe215cb8ad60c221d8eb740b056460b] Merge ftrace/for-next
git bisect good 8af40c77dfe215cb8ad60c221d8eb740b056460b
# bad: [5dfebf3c26dc5fe0fe08a5b4f334922b650e43b9] Merge ring-buffer/for-next
git bisect bad 5dfebf3c26dc5fe0fe08a5b4f334922b650e43b9
# bad: [9172a2da3b4162b5af0d2b57a30e844c451e74b7] Merge probes/for-next
git bisect bad 9172a2da3b4162b5af0d2b57a30e844c451e74b7
# bad: [29edd8b003db897d81d82d950785327f164650d3] selftests/x86: Add return uprobe shadow stack test
git bisect bad 29edd8b003db897d81d82d950785327f164650d3
# good: [1b3c86eeea7594eeeb49b8d1c1db0a40f0ce7920] samples: kprobes: add missing MODULE_DESCRIPTION() macros
git bisect good 1b3c86eeea7594eeeb49b8d1c1db0a40f0ce7920
# good: [190fec72df4a5d4d98b1e783c333f471e5e5f344] uprobe: Wire up uretprobe system call
git bisect good 190fec72df4a5d4d98b1e783c333f471e5e5f344
# bad: [ff474a78cef5cb5f32be52fe25b78441327a2e7c] uprobe: Add uretprobe syscall to speed up return probe
git bisect bad ff474a78cef5cb5f32be52fe25b78441327a2e7c
# first bad commit: [ff474a78cef5cb5f32be52fe25b78441327a2e7c] uprobe: Add uretprobe syscall to speed up return probe
Oleg Nesterov
maintainerRe: [PATCHv8 bpf-next 3/9] uprobe: Add uretprobe syscall to speed up return probe
Quoted 19 lines · Guenter Roeck
Quoted 2 lines · Jiri Olsa
Adding uretprobe syscall instead of trap to speed up return probe.
This patch results in:
Building loongarch:allmodconfig ... failed
--------------
Error log:
In file included frominclude/linux/uprobes.h:49,from include/linux/mm_types.h:16, from include/linux/mmzone.h:22, from include/linux/gfp.h:7, from include/linux/xarray.h:16, from include/linux/list_lru.h:14, from include/linux/fs.h:13, from include/linux/highmem.h:5, from kernel/events/uprobes.c:13:
Quoted 2 lines
kernel/events/uprobes.c: In function 'arch_uprobe_trampoline':arch/loongarch/include/asm/uprobes.h:12:33: error: initializer element is not constant
should be fixed by https://lore.kernel.org/all/ZmyZgzqsowkGyqmH@krava/
in this thread.
but may be arch/loongarch should override __weak arch_uprobe_trampoline() ?
Oleg.
Steven Rostedt
maintainerRe: [PATCHv8 9/9] man2: Add uretprobe syscall page
In reply to Alejandro ColomarQuoted 12 lines · On Tue, 11 Jun 2024 16:49:24 +0200 Alejandro Colomar <[email protected]> wrote:
Hi,
Quoted 9 lines · Masami Hiramatsu
Quoted 5 lines · On Tue, 11 Jun 2024 13:21:58 +0200 Jiri Olsa <[email protected]> wrote:
Adding man page for new uretprobe syscall.
Acked-by Andrii Nakryiko <[email protected]>Reviewed-by Alejandro Colomar <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Quoted 7 lines
Quoted 5 lines
This looks good to me.
Reviewed-by Masami Hiramatsu (Google) <[email protected]>And this needs to be picked by linux-man@ project.
Yup; please ping me when the rest is merged and I should pick it.
Just in case nobody pinged you, the rest of the series is now in Linus's tree.
-- Steve
Quoted 4 lines
Have a lovely day!
Alex
Alejandro Colomar
maintainerRe: [PATCHv8 9/9] man2: Add uretprobe syscall page
Hi Steven, Jiri,
Quoted 2 lines · Steven Rostedt
Just in case nobody pinged you, the rest of the series is now in Linus's tree.
Thanks for the ping!
I have prepared some tweaks to the patch (see below).
Also, I have some doubts. The prototype shows that it has no arguments (void), but the text said that arguments, if any, are arch-specific. Does any arch have arguments? Should we use a variadic prototype (...)?
Please add the changes proposed below to your patch, tweak anything if you consider it appropriate) and send it as v10.
Have a lovely day!
Alex
man/man2/uretprobe.2 +16 -23
@@ -7,50 +7,43 @@ .SH NAME uretprobe \- execute pending return uprobes .SH SYNOPSIS .nf -.B int uretprobe(void) +.B int uretprobe(void); .fi .SH DESCRIPTION -The .BR uretprobe () -system call is an alternative to breakpoint instructions for triggering return -uprobe consumers. +is an alternative to breakpoint instructions +for triggering return uprobe consumers. .P Calls to .BR uretprobe () -system call are only made from the user-space trampoline provided by the kernel. +are only made from the user-space trampoline provided by the kernel. Calls from any other place result in a .BR SIGILL . -.SH RETURN VALUE -The +.P +Details of the arguments (if any) passed to .BR uretprobe () -system call return value is architecture-specific. +are architecture-specific. +.SH RETURN VALUE +The return value is architecture-specific. .SH ERRORS .TP .B SIGILL -The .BR uretprobe () -system call was called by a user-space program. +was called by a user-space program. .SH VERSIONS -Details of the -.BR uretprobe () -system call behavior vary across systems. +The behavior varies across systems. .SH STANDARDS None. .SH HISTORY -TBD -.SH NOTES -The +Linux 6.11. +.P .BR uretprobe () -system call was initially introduced for the x86_64 architecture +was initially introduced for the x86_64 architecture where it was shown to be faster than breakpoint traps. It might be extended to other architectures. -.P -The +.SH CAVEATS .BR uretprobe () -system call exists only to allow the invocation of return uprobe consumers. +exists only to allow the invocation of return uprobe consumers. It should .B never be called directly. -Details of the arguments (if any) passed to -.BR uretprobe () -and the return value are architecture-specific.
Signature · 1 line
<https://www.alejandro-colomar.es/>
Jiri Olsa
Acked-by From: Jiri OlsaRe: [PATCHv8 9/9] man2: Add uretprobe syscall page
Quoted 6 lines · Alejandro Colomar
Hi Steven, Jiri,
Quoted 2 lines · Steven Rostedt
Just in case nobody pinged you, the rest of the series is now in Linus's tree.
Quoted 6 lines
Thanks for the ping!
I have prepared some tweaks to the patch (see below).
Also, I have some doubts. The prototype shows that it has no arguments (void), but the text said that arguments, if any, are arch-specific. Does any arch have arguments? Should we use a variadic prototype (...)?
hi,
there are no args for x86.. it's there just to note that it might be different on other archs, so not sure what man page should say in such case.. keeping (void) is fine with me
Quoted 3 lines
Please add the changes proposed below to your patch, tweak anything if you consider it appropriate) and send it as v10.
it looks good to me, thanks a lot
jirka
Quoted 79 lines
Have a lovely day!
Alexman/man2/uretprobe.2 +16
-23@@ -7,50 +7,43 @@ .SH NAME uretprobe \- execute pending return uprobes .SH SYNOPSIS .nf -.B int uretprobe(void) +.B int uretprobe(void); .fi .SH DESCRIPTION -The .BR uretprobe () -system call is an alternative to breakpoint instructions for triggering return -uprobe consumers. +is an alternative to breakpoint instructions +for triggering return uprobe consumers. .P Calls to .BR uretprobe () -system call are only made from the user-space trampoline provided by the kernel. +are only made from the user-space trampoline provided by the kernel. Calls from any other place result in a .BR SIGILL . -.SH RETURN VALUE -The +.P +Details of the arguments (if any) passed to .BR uretprobe () -system call return value is architecture-specific. +are architecture-specific. +.SH RETURN VALUE +The return value is architecture-specific. .SH ERRORS .TP .B SIGILL -The .BR uretprobe () -system call was called by a user-space program. +was called by a user-space program. .SH VERSIONS -Details of the -.BR uretprobe () -system call behavior vary across systems. +The behavior varies across systems. .SH STANDARDS None. .SH HISTORY -TBD -.SH NOTES -The +Linux 6.11. +.P .BR uretprobe () -system call was initially introduced for the x86_64 architecture +was initially introduced for the x86_64 architecture where it was shown to be faster than breakpoint traps. It might be extended to other architectures. -.P -The +.SH CAVEATS .BR uretprobe () -system call exists only to allow the invocation of return uprobe consumers. +exists only to allow the invocation of return uprobe consumers. It should .B never be called directly. -Details of the arguments (if any) passed to -.BR uretprobe () -and the return value are architecture-specific.Signature · 2 lines
-- <https://www.alejandro-colomar.es/>
Alejandro Colomar
maintainerRe: [PATCHv8 9/9] man2: Add uretprobe syscall page
Quoted 14 lines · Jiri Olsa
Quoted 6 lines · Alejandro Colomar
Hi Steven, Jiri,
Quoted 2 lines · Steven Rostedt
Just in case nobody pinged you, the rest of the series is now in Linus's tree.
Quoted 6 lines
Thanks for the ping!
I have prepared some tweaks to the patch (see below).
Also, I have some doubts. The prototype shows that it has no arguments (void), but the text said that arguments, if any, are arch-specific. Does any arch have arguments? Should we use a variadic prototype (...)?
Quoted 4 lines
hi,
there are no args for x86.. it's there just to note that it might be different on other archs, so not sure what man page should say in such case.. keeping (void) is fine with me
Hmmm, then I'll remove that paragraph. If that function is implemented in another arch and the args are different, we can change the manual page then.
Quoted 8 lines
Quoted 4 lines
Please add the changes proposed below to your patch, tweak anything if you consider it appropriate) and send it as v10.
it looks good to me, thanks a lot
Acked-by From: Jiri Olsa <[email protected]>
Thanks!
Have a lovely day!
Alex
Quoted 83 lines
jirka
Quoted 79 lines
Have a lovely day!
Alexman/man2/uretprobe.2 +16
-23@@ -7,50 +7,43 @@ .SH NAME uretprobe \- execute pending return uprobes .SH SYNOPSIS .nf -.B int uretprobe(void) +.B int uretprobe(void); .fi .SH DESCRIPTION -The .BR uretprobe () -system call is an alternative to breakpoint instructions for triggering return -uprobe consumers. +is an alternative to breakpoint instructions +for triggering return uprobe consumers. .P Calls to .BR uretprobe () -system call are only made from the user-space trampoline provided by the kernel. +are only made from the user-space trampoline provided by the kernel. Calls from any other place result in a .BR SIGILL . -.SH RETURN VALUE -The +.P +Details of the arguments (if any) passed to .BR uretprobe () -system call return value is architecture-specific. +are architecture-specific. +.SH RETURN VALUE +The return value is architecture-specific. .SH ERRORS .TP .B SIGILL -The .BR uretprobe () -system call was called by a user-space program. +was called by a user-space program. .SH VERSIONS -Details of the -.BR uretprobe () -system call behavior vary across systems. +The behavior varies across systems. .SH STANDARDS None. .SH HISTORY -TBD -.SH NOTES -The +Linux 6.11. +.P .BR uretprobe () -system call was initially introduced for the x86_64 architecture +was initially introduced for the x86_64 architecture where it was shown to be faster than breakpoint traps. It might be extended to other architectures. -.P -The +.SH CAVEATS .BR uretprobe () -system call exists only to allow the invocation of return uprobe consumers. +exists only to allow the invocation of return uprobe consumers. It should .B never be called directly. -Details of the arguments (if any) passed to -.BR uretprobe () -and the return value are architecture-specific.Signature · 2 lines
-- <https://www.alejandro-colomar.es/>
Signature · 1 line
<https://www.alejandro-colomar.es/>
Alejandro Colomar
maintainerRe: [PATCHv8 9/9] man2: Add uretprobe syscall page
Hi Jiri, Steven,
Quoted 5 lines · Alejandro Colomar
Quoted 4 lines
hi,
there are no args for x86.. it's there just to note that it might be different on other archs, so not sure what man page should say in such case.. keeping (void) is fine with me
Quoted 12 lines
Hmmm, then I'll remove that paragraph. If that function is implemented in another arch and the args are different, we can change the manual page then.
Quoted 8 lines
Quoted 4 lines
Please add the changes proposed below to your patch, tweak anything if you consider it appropriate) and send it as v10.
it looks good to me, thanks a lot
Acked-by From: Jiri Olsa <[email protected]>
I have applied your patch with the tweaks I mentioned, and added several tags to the commit message.
It's currently here:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=977e3eecbb81b7398defc4e4f41810ca31d63c1b>
and will $soon be pushed to master.
Have a lovely night!
Alex
Signature · 1 line
<https://www.alejandro-colomar.es/>
Re: [PATCHv8 9/9] man2: Add uretprobe syscall page
Quoted 24 lines · Alejandro Colomar
Hi Jiri, Steven,
Quoted 5 lines · Alejandro Colomar
Quoted 4 lines
hi,
there are no args for x86.. it's there just to note that it might be different on other archs, so not sure what man page should say in such case.. keeping (void) is fine with meQuoted 12 lines
Hmmm, then I'll remove that paragraph. If that function is implemented in another arch and the args are different, we can change the manual page then.
Quoted 8 lines
Quoted 4 lines
Please add the changes proposed below to your patch, tweak anything if you consider it appropriate) and send it as v10.
it looks good to me, thanks a lot
Acked-by From: Jiri Olsa <[email protected]>I have applied your patch with the tweaks I mentioned, and added several tags to the commit message.
Quoted 7 lines
It's currently here:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=977e3eecbb81b7398defc4e4f41810ca31d63c1b>and will $soon be pushed to master.
Have a lovely night!
Alex
great, thanks
jirka