On Thu, May 15, 2025 at 5:13 AM Jiri Olsa <jo...@kernel.org> wrote: > > Adding support to add special mapping for user space trampoline with > following functions: > > uprobe_trampoline_get - find or add uprobe_trampoline > uprobe_trampoline_put - remove or destroy uprobe_trampoline > > The user space trampoline is exported as arch specific user space special > mapping through tramp_mapping, which is initialized in following changes > with new uprobe syscall. > > The uprobe trampoline needs to be callable/reachable from the probed address, > so while searching for available address we use is_reachable_by_call function > to decide if the uprobe trampoline is callable from the probe address. > > All uprobe_trampoline objects are stored in uprobes_state object and are > cleaned up when the process mm_struct goes down. Adding new arch hooks > for that, because this change is x86_64 specific. > > Locking is provided by callers in following changes. > > Signed-off-by: Jiri Olsa <jo...@kernel.org> > --- > arch/x86/kernel/uprobes.c | 115 ++++++++++++++++++++++++++++++++++++++ > include/linux/uprobes.h | 6 ++ > kernel/events/uprobes.c | 10 ++++ > kernel/fork.c | 1 + > 4 files changed, 132 insertions(+) >
[...] > +static unsigned long find_nearest_page(unsigned long vaddr) > +{ > + struct vm_unmapped_area_info info = { > + .length = PAGE_SIZE, > + .align_mask = ~PAGE_MASK, > + .flags = VM_UNMAPPED_AREA_TOPDOWN, > + .low_limit = 0, would this, technically, allow to allocate memory at NULL (0x0000) address? should this start at PAGE_SIZE? > + .high_limit = ULONG_MAX, > + }; > + unsigned long limit, call_end = vaddr + 5; > + > + if (!check_add_overflow(call_end, INT_MIN, &limit)) > + info.low_limit = limit; > + if (!check_add_overflow(call_end, INT_MAX, &limit)) > + info.high_limit = limit; > + return vm_unmapped_area(&info); > +} [...]