mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-23 23:50:51 +07:00
kernel-clone-v5.9
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCXz5bNAAKCRCRxhvAZXjc opfjAP9R/J72yxdd2CLGNZ96hyiRX1NgFDOVUhscOvujYJf8ZwD+OoLmKMvAyFW6 hnMhT1n9Q+aq194hyzChOLQaBTejBQ8= =4WCX -----END PGP SIGNATURE----- Merge tag 'kernel-clone-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux Pull kernel_clone() updates from Christian Brauner: "During the v5.9 merge window we reworked the process creation codepaths across multiple architectures. After this work we were only left with the _do_fork() helper based on the struct kernel_clone_args calling convention. As was pointed out _do_fork() isn't valid kernelese especially for a helper that isn't just static. This series removes the _do_fork() helper and introduces the new kernel_clone() helper. The process creation cleanup didn't change the name to something more reasonable mainly because _do_fork() was used in quite a few places. So sending this as a separate series seemed the better strategy. I originally intended to send this early in the v5.9 development cycle after the merge window had closed but given that this was touching quite a few places I decided to defer this until the v5.10 merge window" * tag 'kernel-clone-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux: sched: remove _do_fork() tracing: switch to kernel_clone() kgdbts: switch to kernel_clone() kprobes: switch to kernel_clone() x86: switch to kernel_clone() sparc: switch to kernel_clone() nios2: switch to kernel_clone() m68k: switch to kernel_clone() ia64: switch to kernel_clone() h8300: switch to kernel_clone() fork: introduce kernel_clone()
This commit is contained in:
commit
612e7a4c16
@ -1495,7 +1495,7 @@ Extended error information
|
|||||||
#
|
#
|
||||||
|
|
||||||
{ stacktrace:
|
{ stacktrace:
|
||||||
_do_fork+0x18e/0x330
|
kernel_clone+0x18e/0x330
|
||||||
kernel_thread+0x29/0x30
|
kernel_thread+0x29/0x30
|
||||||
kthreadd+0x154/0x1b0
|
kthreadd+0x154/0x1b0
|
||||||
ret_from_fork+0x3f/0x70
|
ret_from_fork+0x3f/0x70
|
||||||
@ -1588,7 +1588,7 @@ Extended error information
|
|||||||
SYSC_sendto+0xef/0x170
|
SYSC_sendto+0xef/0x170
|
||||||
} hitcount: 88
|
} hitcount: 88
|
||||||
{ stacktrace:
|
{ stacktrace:
|
||||||
_do_fork+0x18e/0x330
|
kernel_clone+0x18e/0x330
|
||||||
SyS_clone+0x19/0x20
|
SyS_clone+0x19/0x20
|
||||||
entry_SYSCALL_64_fastpath+0x12/0x6a
|
entry_SYSCALL_64_fastpath+0x12/0x6a
|
||||||
} hitcount: 244
|
} hitcount: 244
|
||||||
|
@ -172,5 +172,5 @@ asmlinkage int sys_clone(unsigned long __user *args)
|
|||||||
kargs.exit_signal = (lower_32_bits(clone_flags) & CSIGNAL);
|
kargs.exit_signal = (lower_32_bits(clone_flags) & CSIGNAL);
|
||||||
kargs.stack = newsp;
|
kargs.stack = newsp;
|
||||||
|
|
||||||
return _do_fork(&kargs);
|
return kernel_clone(&kargs);
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ ia64_load_extra (struct task_struct *task)
|
|||||||
*
|
*
|
||||||
* <clone syscall> <some kernel call frames>
|
* <clone syscall> <some kernel call frames>
|
||||||
* sys_clone :
|
* sys_clone :
|
||||||
* _do_fork _do_fork
|
* kernel_clone kernel_clone
|
||||||
* copy_thread copy_thread
|
* copy_thread copy_thread
|
||||||
*
|
*
|
||||||
* This means that the stack layout is as follows:
|
* This means that the stack layout is as follows:
|
||||||
@ -411,7 +411,7 @@ asmlinkage long ia64_clone(unsigned long clone_flags, unsigned long stack_start,
|
|||||||
.tls = tls,
|
.tls = tls,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -107,10 +107,10 @@ void flush_thread(void)
|
|||||||
* on top of pt_regs, which means that sys_clone() arguments would be
|
* on top of pt_regs, which means that sys_clone() arguments would be
|
||||||
* buried. We could, of course, copy them, but it's too costly for no
|
* buried. We could, of course, copy them, but it's too costly for no
|
||||||
* good reason - generic clone() would have to copy them *again* for
|
* good reason - generic clone() would have to copy them *again* for
|
||||||
* _do_fork() anyway. So in this case it's actually better to pass pt_regs *
|
* kernel_clone() anyway. So in this case it's actually better to pass pt_regs *
|
||||||
* and extract arguments for _do_fork() from there. Eventually we might
|
* and extract arguments for kernel_clone() from there. Eventually we might
|
||||||
* go for calling _do_fork() directly from the wrapper, but only after we
|
* go for calling kernel_clone() directly from the wrapper, but only after we
|
||||||
* are finished with _do_fork() prototype conversion.
|
* are finished with kernel_clone() prototype conversion.
|
||||||
*/
|
*/
|
||||||
asmlinkage int m68k_clone(struct pt_regs *regs)
|
asmlinkage int m68k_clone(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
@ -125,7 +125,7 @@ asmlinkage int m68k_clone(struct pt_regs *regs)
|
|||||||
.tls = regs->d5,
|
.tls = regs->d5,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -266,5 +266,5 @@ asmlinkage int nios2_clone(unsigned long clone_flags, unsigned long newsp,
|
|||||||
.tls = tls,
|
.tls = tls,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ asmlinkage long sparc_fork(struct pt_regs *regs)
|
|||||||
.stack = regs->u_regs[UREG_FP],
|
.stack = regs->u_regs[UREG_FP],
|
||||||
};
|
};
|
||||||
|
|
||||||
ret = _do_fork(&args);
|
ret = kernel_clone(&args);
|
||||||
|
|
||||||
/* If we get an error and potentially restart the system
|
/* If we get an error and potentially restart the system
|
||||||
* call, we're screwed because copy_thread() clobbered
|
* call, we're screwed because copy_thread() clobbered
|
||||||
@ -50,7 +50,7 @@ asmlinkage long sparc_vfork(struct pt_regs *regs)
|
|||||||
.stack = regs->u_regs[UREG_FP],
|
.stack = regs->u_regs[UREG_FP],
|
||||||
};
|
};
|
||||||
|
|
||||||
ret = _do_fork(&args);
|
ret = kernel_clone(&args);
|
||||||
|
|
||||||
/* If we get an error and potentially restart the system
|
/* If we get an error and potentially restart the system
|
||||||
* call, we're screwed because copy_thread() clobbered
|
* call, we're screwed because copy_thread() clobbered
|
||||||
@ -96,7 +96,7 @@ asmlinkage long sparc_clone(struct pt_regs *regs)
|
|||||||
else
|
else
|
||||||
args.stack = regs->u_regs[UREG_FP];
|
args.stack = regs->u_regs[UREG_FP];
|
||||||
|
|
||||||
ret = _do_fork(&args);
|
ret = kernel_clone(&args);
|
||||||
|
|
||||||
/* If we get an error and potentially restart the system
|
/* If we get an error and potentially restart the system
|
||||||
* call, we're screwed because copy_thread() clobbered
|
* call, we're screwed because copy_thread() clobbered
|
||||||
|
@ -251,6 +251,6 @@ COMPAT_SYSCALL_DEFINE5(ia32_clone, unsigned long, clone_flags,
|
|||||||
.tls = tls_val,
|
.tls = tls_val,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_IA32_EMULATION */
|
#endif /* CONFIG_IA32_EMULATION */
|
||||||
|
@ -33,16 +33,16 @@
|
|||||||
* You can also specify optional tests:
|
* You can also specify optional tests:
|
||||||
* N## = Go to sleep with interrupts of for ## seconds
|
* N## = Go to sleep with interrupts of for ## seconds
|
||||||
* to test the HW NMI watchdog
|
* to test the HW NMI watchdog
|
||||||
* F## = Break at do_fork for ## iterations
|
* F## = Break at kernel_clone for ## iterations
|
||||||
* S## = Break at sys_open for ## iterations
|
* S## = Break at sys_open for ## iterations
|
||||||
* I## = Run the single step test ## iterations
|
* I## = Run the single step test ## iterations
|
||||||
*
|
*
|
||||||
* NOTE: that the do_fork and sys_open tests are mutually exclusive.
|
* NOTE: that the kernel_clone and sys_open tests are mutually exclusive.
|
||||||
*
|
*
|
||||||
* To invoke the kgdb test suite from boot you use a kernel start
|
* To invoke the kgdb test suite from boot you use a kernel start
|
||||||
* argument as follows:
|
* argument as follows:
|
||||||
* kgdbts=V1 kgdbwait
|
* kgdbts=V1 kgdbwait
|
||||||
* Or if you wanted to perform the NMI test for 6 seconds and do_fork
|
* Or if you wanted to perform the NMI test for 6 seconds and kernel_clone
|
||||||
* test for 100 forks, you could use:
|
* test for 100 forks, you could use:
|
||||||
* kgdbts=V1N6F100 kgdbwait
|
* kgdbts=V1N6F100 kgdbwait
|
||||||
*
|
*
|
||||||
@ -74,7 +74,7 @@
|
|||||||
* echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts
|
* echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts
|
||||||
* fg # and hit control-c
|
* fg # and hit control-c
|
||||||
* fg # and hit control-c
|
* fg # and hit control-c
|
||||||
* ## This tests break points on do_fork
|
* ## This tests break points on kernel_clone
|
||||||
* while [ 1 ] ; do date > /dev/null ; done &
|
* while [ 1 ] ; do date > /dev/null ; done &
|
||||||
* while [ 1 ] ; do date > /dev/null ; done &
|
* while [ 1 ] ; do date > /dev/null ; done &
|
||||||
* echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts
|
* echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts
|
||||||
@ -209,8 +209,8 @@ static unsigned long lookup_addr(char *arg)
|
|||||||
addr = (unsigned long)kgdbts_break_test;
|
addr = (unsigned long)kgdbts_break_test;
|
||||||
else if (!strcmp(arg, "sys_open"))
|
else if (!strcmp(arg, "sys_open"))
|
||||||
addr = (unsigned long)do_sys_open;
|
addr = (unsigned long)do_sys_open;
|
||||||
else if (!strcmp(arg, "do_fork"))
|
else if (!strcmp(arg, "kernel_clone"))
|
||||||
addr = (unsigned long)_do_fork;
|
addr = (unsigned long)kernel_clone;
|
||||||
else if (!strcmp(arg, "hw_break_val"))
|
else if (!strcmp(arg, "hw_break_val"))
|
||||||
addr = (unsigned long)&hw_break_val;
|
addr = (unsigned long)&hw_break_val;
|
||||||
addr = (unsigned long) dereference_function_descriptor((void *)addr);
|
addr = (unsigned long) dereference_function_descriptor((void *)addr);
|
||||||
@ -310,7 +310,7 @@ static int check_and_rewind_pc(char *put_str, char *arg)
|
|||||||
|
|
||||||
if (arch_needs_sstep_emulation && sstep_addr &&
|
if (arch_needs_sstep_emulation && sstep_addr &&
|
||||||
ip + offset == sstep_addr &&
|
ip + offset == sstep_addr &&
|
||||||
((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) {
|
((!strcmp(arg, "sys_open") || !strcmp(arg, "kernel_clone")))) {
|
||||||
/* This is special case for emulated single step */
|
/* This is special case for emulated single step */
|
||||||
v2printk("Emul: rewind hit single step bp\n");
|
v2printk("Emul: rewind hit single step bp\n");
|
||||||
restart_from_top_after_write = 1;
|
restart_from_top_after_write = 1;
|
||||||
@ -596,19 +596,19 @@ static struct test_struct singlestep_break_test[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test for hitting a breakpoint at do_fork for what ever the number
|
* Test for hitting a breakpoint at kernel_clone for what ever the number
|
||||||
* of iterations required by the variable repeat_test.
|
* of iterations required by the variable repeat_test.
|
||||||
*/
|
*/
|
||||||
static struct test_struct do_fork_test[] = {
|
static struct test_struct do_kernel_clone_test[] = {
|
||||||
{ "?", "S0*" }, /* Clear break points */
|
{ "?", "S0*" }, /* Clear break points */
|
||||||
{ "do_fork", "OK", sw_break, }, /* set sw breakpoint */
|
{ "kernel_clone", "OK", sw_break, }, /* set sw breakpoint */
|
||||||
{ "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
|
{ "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
|
||||||
{ "do_fork", "OK", sw_rem_break }, /*remove breakpoint */
|
{ "kernel_clone", "OK", sw_rem_break }, /*remove breakpoint */
|
||||||
{ "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */
|
{ "g", "kernel_clone", NULL, check_and_rewind_pc }, /* check location */
|
||||||
{ "write", "OK", write_regs, emul_reset }, /* Write registers */
|
{ "write", "OK", write_regs, emul_reset }, /* Write registers */
|
||||||
{ "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
|
{ "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
|
||||||
{ "g", "do_fork", NULL, check_single_step },
|
{ "g", "kernel_clone", NULL, check_single_step },
|
||||||
{ "do_fork", "OK", sw_break, }, /* set sw breakpoint */
|
{ "kernel_clone", "OK", sw_break, }, /* set sw breakpoint */
|
||||||
{ "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
|
{ "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
|
||||||
{ "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
|
{ "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
|
||||||
{ "", "", get_cont_catch, put_cont_catch },
|
{ "", "", get_cont_catch, put_cont_catch },
|
||||||
@ -935,11 +935,11 @@ static void run_bad_read_test(void)
|
|||||||
kgdb_breakpoint();
|
kgdb_breakpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_do_fork_test(void)
|
static void run_kernel_clone_test(void)
|
||||||
{
|
{
|
||||||
init_simple_test();
|
init_simple_test();
|
||||||
ts.tst = do_fork_test;
|
ts.tst = do_kernel_clone_test;
|
||||||
ts.name = "do_fork_test";
|
ts.name = "do_kernel_clone_test";
|
||||||
/* Activate test with initial breakpoint */
|
/* Activate test with initial breakpoint */
|
||||||
kgdb_breakpoint();
|
kgdb_breakpoint();
|
||||||
}
|
}
|
||||||
@ -967,7 +967,7 @@ static void run_singlestep_break_test(void)
|
|||||||
static void kgdbts_run_tests(void)
|
static void kgdbts_run_tests(void)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int fork_test = 0;
|
int clone_test = 0;
|
||||||
int do_sys_open_test = 0;
|
int do_sys_open_test = 0;
|
||||||
int sstep_test = 1000;
|
int sstep_test = 1000;
|
||||||
int nmi_sleep = 0;
|
int nmi_sleep = 0;
|
||||||
@ -981,7 +981,7 @@ static void kgdbts_run_tests(void)
|
|||||||
|
|
||||||
ptr = strchr(config, 'F');
|
ptr = strchr(config, 'F');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
fork_test = simple_strtol(ptr + 1, NULL, 10);
|
clone_test = simple_strtol(ptr + 1, NULL, 10);
|
||||||
ptr = strchr(config, 'S');
|
ptr = strchr(config, 'S');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
|
do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
|
||||||
@ -1025,16 +1025,16 @@ static void kgdbts_run_tests(void)
|
|||||||
run_nmi_sleep_test(nmi_sleep);
|
run_nmi_sleep_test(nmi_sleep);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the do_fork test is run it will be the last test that is
|
/* If the kernel_clone test is run it will be the last test that is
|
||||||
* executed because a kernel thread will be spawned at the very
|
* executed because a kernel thread will be spawned at the very
|
||||||
* end to unregister the debug hooks.
|
* end to unregister the debug hooks.
|
||||||
*/
|
*/
|
||||||
if (fork_test) {
|
if (clone_test) {
|
||||||
repeat_test = fork_test;
|
repeat_test = clone_test;
|
||||||
printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n",
|
printk(KERN_INFO "kgdbts:RUN kernel_clone for %i breakpoints\n",
|
||||||
repeat_test);
|
repeat_test);
|
||||||
kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
|
kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
|
||||||
run_do_fork_test();
|
run_kernel_clone_test();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ extern void do_group_exit(int);
|
|||||||
extern void exit_files(struct task_struct *);
|
extern void exit_files(struct task_struct *);
|
||||||
extern void exit_itimers(struct signal_struct *);
|
extern void exit_itimers(struct signal_struct *);
|
||||||
|
|
||||||
extern long _do_fork(struct kernel_clone_args *kargs);
|
extern pid_t kernel_clone(struct kernel_clone_args *kargs);
|
||||||
struct task_struct *fork_idle(int);
|
struct task_struct *fork_idle(int);
|
||||||
struct mm_struct *copy_init_mm(void);
|
struct mm_struct *copy_init_mm(void);
|
||||||
extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
|
extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
|
||||||
|
@ -2412,14 +2412,14 @@ struct mm_struct *copy_init_mm(void)
|
|||||||
*
|
*
|
||||||
* args->exit_signal is expected to be checked for sanity by the caller.
|
* args->exit_signal is expected to be checked for sanity by the caller.
|
||||||
*/
|
*/
|
||||||
long _do_fork(struct kernel_clone_args *args)
|
pid_t kernel_clone(struct kernel_clone_args *args)
|
||||||
{
|
{
|
||||||
u64 clone_flags = args->flags;
|
u64 clone_flags = args->flags;
|
||||||
struct completion vfork;
|
struct completion vfork;
|
||||||
struct pid *pid;
|
struct pid *pid;
|
||||||
struct task_struct *p;
|
struct task_struct *p;
|
||||||
int trace = 0;
|
int trace = 0;
|
||||||
long nr;
|
pid_t nr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For legacy clone() calls, CLONE_PIDFD uses the parent_tid argument
|
* For legacy clone() calls, CLONE_PIDFD uses the parent_tid argument
|
||||||
@ -2505,7 +2505,7 @@ pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
|
|||||||
.stack_size = (unsigned long)arg,
|
.stack_size = (unsigned long)arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __ARCH_WANT_SYS_FORK
|
#ifdef __ARCH_WANT_SYS_FORK
|
||||||
@ -2516,7 +2516,7 @@ SYSCALL_DEFINE0(fork)
|
|||||||
.exit_signal = SIGCHLD,
|
.exit_signal = SIGCHLD,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
#else
|
#else
|
||||||
/* can not support in nommu mode */
|
/* can not support in nommu mode */
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -2532,7 +2532,7 @@ SYSCALL_DEFINE0(vfork)
|
|||||||
.exit_signal = SIGCHLD,
|
.exit_signal = SIGCHLD,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2570,7 +2570,7 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
|
|||||||
.tls = tls,
|
.tls = tls,
|
||||||
};
|
};
|
||||||
|
|
||||||
return _do_fork(&args);
|
return kernel_clone(&args);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2728,7 +2728,7 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
|
|||||||
if (!clone3_args_valid(&kargs))
|
if (!clone3_args_valid(&kargs))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return _do_fork(&kargs);
|
return kernel_clone(&kargs);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2891,7 +2891,7 @@ int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,
|
|||||||
/*
|
/*
|
||||||
* unshare allows a process to 'unshare' part of the process
|
* unshare allows a process to 'unshare' part of the process
|
||||||
* context which was originally shared using clone. copy_*
|
* context which was originally shared using clone. copy_*
|
||||||
* functions used by _do_fork() cannot be used here directly
|
* functions used by kernel_clone() cannot be used here directly
|
||||||
* because they modify an inactive task_struct that is being
|
* because they modify an inactive task_struct that is being
|
||||||
* constructed. Here we are modifying the current, active,
|
* constructed. Here we are modifying the current, active,
|
||||||
* task_struct.
|
* task_struct.
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
/*
|
/*
|
||||||
* NOTE: This example is works on x86 and powerpc.
|
* NOTE: This example is works on x86 and powerpc.
|
||||||
* Here's a sample kernel module showing the use of kprobes to dump a
|
* Here's a sample kernel module showing the use of kprobes to dump a
|
||||||
* stack trace and selected registers when _do_fork() is called.
|
* stack trace and selected registers when kernel_clone() is called.
|
||||||
*
|
*
|
||||||
* For more information on theory of operation of kprobes, see
|
* For more information on theory of operation of kprobes, see
|
||||||
* Documentation/trace/kprobes.rst
|
* Documentation/trace/kprobes.rst
|
||||||
*
|
*
|
||||||
* You will see the trace data in /var/log/messages and on the console
|
* You will see the trace data in /var/log/messages and on the console
|
||||||
* whenever _do_fork() is invoked to create a new process.
|
* whenever kernel_clone() is invoked to create a new process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
#include <linux/kprobes.h>
|
#include <linux/kprobes.h>
|
||||||
|
|
||||||
#define MAX_SYMBOL_LEN 64
|
#define MAX_SYMBOL_LEN 64
|
||||||
static char symbol[MAX_SYMBOL_LEN] = "_do_fork";
|
static char symbol[MAX_SYMBOL_LEN] = "kernel_clone";
|
||||||
module_param_string(symbol, symbol, sizeof(symbol), 0644);
|
module_param_string(symbol, symbol, sizeof(symbol), 0644);
|
||||||
|
|
||||||
/* For each probe you need to allocate a kprobe structure */
|
/* For each probe you need to allocate a kprobe structure */
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* usage: insmod kretprobe_example.ko func=<func_name>
|
* usage: insmod kretprobe_example.ko func=<func_name>
|
||||||
*
|
*
|
||||||
* If no func_name is specified, _do_fork is instrumented
|
* If no func_name is specified, kernel_clone is instrumented
|
||||||
*
|
*
|
||||||
* For more information on theory of operation of kretprobes, see
|
* For more information on theory of operation of kretprobes, see
|
||||||
* Documentation/trace/kprobes.rst
|
* Documentation/trace/kprobes.rst
|
||||||
@ -26,7 +26,7 @@
|
|||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
|
|
||||||
static char func_name[NAME_MAX] = "_do_fork";
|
static char func_name[NAME_MAX] = "kernel_clone";
|
||||||
module_param_string(func, func_name, NAME_MAX, S_IRUGO);
|
module_param_string(func, func_name, NAME_MAX, S_IRUGO);
|
||||||
MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the"
|
MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the"
|
||||||
" function's execution time");
|
" function's execution time");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
echo 0 > events/enable
|
echo 0 > events/enable
|
||||||
echo > dynamic_events
|
echo > dynamic_events
|
||||||
|
|
||||||
PLACE=_do_fork
|
PLACE=kernel_clone
|
||||||
|
|
||||||
echo "p:myevent1 $PLACE" >> dynamic_events
|
echo "p:myevent1 $PLACE" >> dynamic_events
|
||||||
echo "r:myevent2 $PLACE" >> dynamic_events
|
echo "r:myevent2 $PLACE" >> dynamic_events
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
echo 0 > events/enable
|
echo 0 > events/enable
|
||||||
echo > dynamic_events
|
echo > dynamic_events
|
||||||
|
|
||||||
PLACE=_do_fork
|
PLACE=kernel_clone
|
||||||
|
|
||||||
setup_events() {
|
setup_events() {
|
||||||
echo "p:myevent1 $PLACE" >> dynamic_events
|
echo "p:myevent1 $PLACE" >> dynamic_events
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
echo 0 > events/enable
|
echo 0 > events/enable
|
||||||
echo > dynamic_events
|
echo > dynamic_events
|
||||||
|
|
||||||
PLACE=_do_fork
|
PLACE=kernel_clone
|
||||||
|
|
||||||
setup_events() {
|
setup_events() {
|
||||||
echo "p:myevent1 $PLACE" >> dynamic_events
|
echo "p:myevent1 $PLACE" >> dynamic_events
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
# requires: set_ftrace_filter
|
# requires: set_ftrace_filter
|
||||||
# flags: instance
|
# flags: instance
|
||||||
|
|
||||||
echo _do_fork:stacktrace >> set_ftrace_filter
|
echo kernel_clone:stacktrace >> set_ftrace_filter
|
||||||
|
|
||||||
grep -q "_do_fork:stacktrace:unlimited" set_ftrace_filter
|
grep -q "kernel_clone:stacktrace:unlimited" set_ftrace_filter
|
||||||
|
|
||||||
(echo "forked"; sleep 1)
|
(echo "forked"; sleep 1)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# description: Kprobe dynamic event - adding and removing
|
# description: Kprobe dynamic event - adding and removing
|
||||||
# requires: kprobe_events
|
# requires: kprobe_events
|
||||||
|
|
||||||
echo p:myevent _do_fork > kprobe_events
|
echo p:myevent kernel_clone > kprobe_events
|
||||||
grep myevent kprobe_events
|
grep myevent kprobe_events
|
||||||
test -d events/kprobes/myevent
|
test -d events/kprobes/myevent
|
||||||
echo > kprobe_events
|
echo > kprobe_events
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# description: Kprobe dynamic event - busy event check
|
# description: Kprobe dynamic event - busy event check
|
||||||
# requires: kprobe_events
|
# requires: kprobe_events
|
||||||
|
|
||||||
echo p:myevent _do_fork > kprobe_events
|
echo p:myevent kernel_clone > kprobe_events
|
||||||
test -d events/kprobes/myevent
|
test -d events/kprobes/myevent
|
||||||
echo 1 > events/kprobes/myevent/enable
|
echo 1 > events/kprobes/myevent/enable
|
||||||
echo > kprobe_events && exit_fail # this must fail
|
echo > kprobe_events && exit_fail # this must fail
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
# description: Kprobe dynamic event with arguments
|
# description: Kprobe dynamic event with arguments
|
||||||
# requires: kprobe_events
|
# requires: kprobe_events
|
||||||
|
|
||||||
echo 'p:testprobe _do_fork $stack $stack0 +0($stack)' > kprobe_events
|
echo 'p:testprobe kernel_clone $stack $stack0 +0($stack)' > kprobe_events
|
||||||
grep testprobe kprobe_events | grep -q 'arg1=\$stack arg2=\$stack0 arg3=+0(\$stack)'
|
grep testprobe kprobe_events | grep -q 'arg1=\$stack arg2=\$stack0 arg3=+0(\$stack)'
|
||||||
test -d events/kprobes/testprobe
|
test -d events/kprobes/testprobe
|
||||||
|
|
||||||
echo 1 > events/kprobes/testprobe/enable
|
echo 1 > events/kprobes/testprobe/enable
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
grep testprobe trace | grep '_do_fork' | \
|
grep testprobe trace | grep 'kernel_clone' | \
|
||||||
grep -q 'arg1=0x[[:xdigit:]]* arg2=0x[[:xdigit:]]* arg3=0x[[:xdigit:]]*$'
|
grep -q 'arg1=0x[[:xdigit:]]* arg2=0x[[:xdigit:]]* arg3=0x[[:xdigit:]]*$'
|
||||||
|
|
||||||
echo 0 > events/kprobes/testprobe/enable
|
echo 0 > events/kprobes/testprobe/enable
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
grep -A1 "fetcharg:" README | grep -q "\$comm" || exit_unsupported # this is too old
|
grep -A1 "fetcharg:" README | grep -q "\$comm" || exit_unsupported # this is too old
|
||||||
|
|
||||||
echo 'p:testprobe _do_fork comm=$comm ' > kprobe_events
|
echo 'p:testprobe kernel_clone comm=$comm ' > kprobe_events
|
||||||
grep testprobe kprobe_events | grep -q 'comm=$comm'
|
grep testprobe kprobe_events | grep -q 'comm=$comm'
|
||||||
test -d events/kprobes/testprobe
|
test -d events/kprobes/testprobe
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@ esac
|
|||||||
: "Test get argument (1)"
|
: "Test get argument (1)"
|
||||||
echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
|
echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string" > kprobe_events
|
||||||
echo 1 > events/kprobes/testprobe/enable
|
echo 1 > events/kprobes/testprobe/enable
|
||||||
echo "p:test _do_fork" >> kprobe_events
|
echo "p:test kernel_clone" >> kprobe_events
|
||||||
grep -qe "testprobe.* arg1=\"test\"" trace
|
grep -qe "testprobe.* arg1=\"test\"" trace
|
||||||
|
|
||||||
echo 0 > events/kprobes/testprobe/enable
|
echo 0 > events/kprobes/testprobe/enable
|
||||||
: "Test get argument (2)"
|
: "Test get argument (2)"
|
||||||
echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
|
echo "p:testprobe tracefs_create_dir arg1=+0(${ARG1}):string arg2=+0(${ARG1}):string" > kprobe_events
|
||||||
echo 1 > events/kprobes/testprobe/enable
|
echo 1 > events/kprobes/testprobe/enable
|
||||||
echo "p:test _do_fork" >> kprobe_events
|
echo "p:test kernel_clone" >> kprobe_events
|
||||||
grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
|
grep -qe "testprobe.* arg1=\"test\" arg2=\"test\"" trace
|
||||||
|
|
||||||
|
@ -14,12 +14,12 @@ elif ! grep "$SYMBOL\$" /proc/kallsyms; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
: "Test get basic types symbol argument"
|
: "Test get basic types symbol argument"
|
||||||
echo "p:testprobe_u _do_fork arg1=@linux_proc_banner:u64 arg2=@linux_proc_banner:u32 arg3=@linux_proc_banner:u16 arg4=@linux_proc_banner:u8" > kprobe_events
|
echo "p:testprobe_u kernel_clone arg1=@linux_proc_banner:u64 arg2=@linux_proc_banner:u32 arg3=@linux_proc_banner:u16 arg4=@linux_proc_banner:u8" > kprobe_events
|
||||||
echo "p:testprobe_s _do_fork arg1=@linux_proc_banner:s64 arg2=@linux_proc_banner:s32 arg3=@linux_proc_banner:s16 arg4=@linux_proc_banner:s8" >> kprobe_events
|
echo "p:testprobe_s kernel_clone arg1=@linux_proc_banner:s64 arg2=@linux_proc_banner:s32 arg3=@linux_proc_banner:s16 arg4=@linux_proc_banner:s8" >> kprobe_events
|
||||||
if grep -q "x8/16/32/64" README; then
|
if grep -q "x8/16/32/64" README; then
|
||||||
echo "p:testprobe_x _do_fork arg1=@linux_proc_banner:x64 arg2=@linux_proc_banner:x32 arg3=@linux_proc_banner:x16 arg4=@linux_proc_banner:x8" >> kprobe_events
|
echo "p:testprobe_x kernel_clone arg1=@linux_proc_banner:x64 arg2=@linux_proc_banner:x32 arg3=@linux_proc_banner:x16 arg4=@linux_proc_banner:x8" >> kprobe_events
|
||||||
fi
|
fi
|
||||||
echo "p:testprobe_bf _do_fork arg1=@linux_proc_banner:b8@4/32" >> kprobe_events
|
echo "p:testprobe_bf kernel_clone arg1=@linux_proc_banner:b8@4/32" >> kprobe_events
|
||||||
echo 1 > events/kprobes/enable
|
echo 1 > events/kprobes/enable
|
||||||
(echo "forked")
|
(echo "forked")
|
||||||
echo 0 > events/kprobes/enable
|
echo 0 > events/kprobes/enable
|
||||||
@ -27,7 +27,7 @@ grep "testprobe_[usx]:.* arg1=.* arg2=.* arg3=.* arg4=.*" trace
|
|||||||
grep "testprobe_bf:.* arg1=.*" trace
|
grep "testprobe_bf:.* arg1=.*" trace
|
||||||
|
|
||||||
: "Test get string symbol argument"
|
: "Test get string symbol argument"
|
||||||
echo "p:testprobe_str _do_fork arg1=@linux_proc_banner:string" > kprobe_events
|
echo "p:testprobe_str kernel_clone arg1=@linux_proc_banner:string" > kprobe_events
|
||||||
echo 1 > events/kprobes/enable
|
echo 1 > events/kprobes/enable
|
||||||
(echo "forked")
|
(echo "forked")
|
||||||
echo 0 > events/kprobes/enable
|
echo 0 > events/kprobes/enable
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# requires: kprobe_events "x8/16/32/64":README
|
# requires: kprobe_events "x8/16/32/64":README
|
||||||
|
|
||||||
gen_event() { # Bitsize
|
gen_event() { # Bitsize
|
||||||
echo "p:testprobe _do_fork \$stack0:s$1 \$stack0:u$1 \$stack0:x$1 \$stack0:b4@4/$1"
|
echo "p:testprobe kernel_clone \$stack0:s$1 \$stack0:u$1 \$stack0:x$1 \$stack0:b4@4/$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_types() { # s-type u-type x-type bf-type width
|
check_types() { # s-type u-type x-type bf-type width
|
||||||
|
@ -5,29 +5,29 @@
|
|||||||
|
|
||||||
# prepare
|
# prepare
|
||||||
echo nop > current_tracer
|
echo nop > current_tracer
|
||||||
echo _do_fork > set_ftrace_filter
|
echo kernel_clone > set_ftrace_filter
|
||||||
echo 'p:testprobe _do_fork' > kprobe_events
|
echo 'p:testprobe kernel_clone' > kprobe_events
|
||||||
|
|
||||||
# kprobe on / ftrace off
|
# kprobe on / ftrace off
|
||||||
echo 1 > events/kprobes/testprobe/enable
|
echo 1 > events/kprobes/testprobe/enable
|
||||||
echo > trace
|
echo > trace
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
grep testprobe trace
|
grep testprobe trace
|
||||||
! grep '_do_fork <-' trace
|
! grep 'kernel_clone <-' trace
|
||||||
|
|
||||||
# kprobe on / ftrace on
|
# kprobe on / ftrace on
|
||||||
echo function > current_tracer
|
echo function > current_tracer
|
||||||
echo > trace
|
echo > trace
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
grep testprobe trace
|
grep testprobe trace
|
||||||
grep '_do_fork <-' trace
|
grep 'kernel_clone <-' trace
|
||||||
|
|
||||||
# kprobe off / ftrace on
|
# kprobe off / ftrace on
|
||||||
echo 0 > events/kprobes/testprobe/enable
|
echo 0 > events/kprobes/testprobe/enable
|
||||||
echo > trace
|
echo > trace
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
! grep testprobe trace
|
! grep testprobe trace
|
||||||
grep '_do_fork <-' trace
|
grep 'kernel_clone <-' trace
|
||||||
|
|
||||||
# kprobe on / ftrace on
|
# kprobe on / ftrace on
|
||||||
echo 1 > events/kprobes/testprobe/enable
|
echo 1 > events/kprobes/testprobe/enable
|
||||||
@ -35,11 +35,11 @@ echo function > current_tracer
|
|||||||
echo > trace
|
echo > trace
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
grep testprobe trace
|
grep testprobe trace
|
||||||
grep '_do_fork <-' trace
|
grep 'kernel_clone <-' trace
|
||||||
|
|
||||||
# kprobe on / ftrace off
|
# kprobe on / ftrace off
|
||||||
echo nop > current_tracer
|
echo nop > current_tracer
|
||||||
echo > trace
|
echo > trace
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
grep testprobe trace
|
grep testprobe trace
|
||||||
! grep '_do_fork <-' trace
|
! grep 'kernel_clone <-' trace
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# requires: kprobe_events "Create/append/":README
|
# requires: kprobe_events "Create/append/":README
|
||||||
|
|
||||||
# Choose 2 symbols for target
|
# Choose 2 symbols for target
|
||||||
SYM1=_do_fork
|
SYM1=kernel_clone
|
||||||
SYM2=do_exit
|
SYM2=do_exit
|
||||||
EVENT_NAME=kprobes/testevent
|
EVENT_NAME=kprobes/testevent
|
||||||
|
|
||||||
|
@ -86,15 +86,15 @@ esac
|
|||||||
|
|
||||||
# multiprobe errors
|
# multiprobe errors
|
||||||
if grep -q "Create/append/" README && grep -q "imm-value" README; then
|
if grep -q "Create/append/" README && grep -q "imm-value" README; then
|
||||||
echo 'p:kprobes/testevent _do_fork' > kprobe_events
|
echo 'p:kprobes/testevent kernel_clone' > kprobe_events
|
||||||
check_error '^r:kprobes/testevent do_exit' # DIFF_PROBE_TYPE
|
check_error '^r:kprobes/testevent do_exit' # DIFF_PROBE_TYPE
|
||||||
|
|
||||||
# Explicitly use printf "%s" to not interpret \1
|
# Explicitly use printf "%s" to not interpret \1
|
||||||
printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
|
printf "%s" 'p:kprobes/testevent kernel_clone abcd=\1' > kprobe_events
|
||||||
check_error 'p:kprobes/testevent _do_fork ^bcd=\1' # DIFF_ARG_TYPE
|
check_error 'p:kprobes/testevent kernel_clone ^bcd=\1' # DIFF_ARG_TYPE
|
||||||
check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8' # DIFF_ARG_TYPE
|
check_error 'p:kprobes/testevent kernel_clone ^abcd=\1:u8' # DIFF_ARG_TYPE
|
||||||
check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE
|
check_error 'p:kprobes/testevent kernel_clone ^abcd=\"foo"' # DIFF_ARG_TYPE
|
||||||
check_error '^p:kprobes/testevent _do_fork abcd=\1' # SAME_PROBE
|
check_error '^p:kprobes/testevent kernel_clone abcd=\1' # SAME_PROBE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
# requires: kprobe_events
|
# requires: kprobe_events
|
||||||
|
|
||||||
# Add new kretprobe event
|
# Add new kretprobe event
|
||||||
echo 'r:testprobe2 _do_fork $retval' > kprobe_events
|
echo 'r:testprobe2 kernel_clone $retval' > kprobe_events
|
||||||
grep testprobe2 kprobe_events | grep -q 'arg1=\$retval'
|
grep testprobe2 kprobe_events | grep -q 'arg1=\$retval'
|
||||||
test -d events/kprobes/testprobe2
|
test -d events/kprobes/testprobe2
|
||||||
|
|
||||||
echo 1 > events/kprobes/testprobe2/enable
|
echo 1 > events/kprobes/testprobe2/enable
|
||||||
( echo "forked")
|
( echo "forked")
|
||||||
|
|
||||||
cat trace | grep testprobe2 | grep -q '<- _do_fork'
|
cat trace | grep testprobe2 | grep -q '<- kernel_clone'
|
||||||
|
|
||||||
echo 0 > events/kprobes/testprobe2/enable
|
echo 0 > events/kprobes/testprobe2/enable
|
||||||
echo '-:testprobe2' >> kprobe_events
|
echo '-:testprobe2' >> kprobe_events
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# requires: kprobe_events
|
# requires: kprobe_events
|
||||||
|
|
||||||
! grep -q 'myevent' kprobe_profile
|
! grep -q 'myevent' kprobe_profile
|
||||||
echo p:myevent _do_fork > kprobe_events
|
echo p:myevent kernel_clone > kprobe_events
|
||||||
grep -q 'myevent[[:space:]]*0[[:space:]]*0$' kprobe_profile
|
grep -q 'myevent[[:space:]]*0[[:space:]]*0$' kprobe_profile
|
||||||
echo 1 > events/kprobes/myevent/enable
|
echo 1 > events/kprobes/myevent/enable
|
||||||
( echo "forked" )
|
( echo "forked" )
|
||||||
|
Loading…
Reference in New Issue
Block a user