2023-06-09 05:39:21

by Naveen N Rao

[permalink] [raw]
Subject: [PATCH] trace/kprobe: Display the actual notrace function when rejecting a probe

Trying to probe update_sd_lb_stats() using perf results in the below
message in the kernel log:
trace_kprobe: Could not probe notrace function _text

This is because 'perf probe' specifies the kprobe location as an offset
from '_text':
$ sudo perf probe -D update_sd_lb_stats
p:probe/update_sd_lb_stats _text+1830728

However, the error message is misleading and doesn't help convey the
actual notrace function that is being probed. Fix this by looking up the
actual function name that is being probed. With this fix, we now get the
below message in the kernel log:
trace_kprobe: Could not probe notrace function update_sd_lb_stats.constprop.0

Signed-off-by: Naveen N Rao <[email protected]>
---
kernel/trace/trace_kprobe.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 74adb82331dd81..975daa66fcef59 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -449,9 +449,8 @@ static bool __within_notrace_func(unsigned long addr)
return !ftrace_location_range(addr, addr + size - 1);
}

-static bool within_notrace_func(struct trace_kprobe *tk)
+static bool within_notrace_func(struct trace_kprobe *tk, unsigned long addr)
{
- unsigned long addr = trace_kprobe_address(tk);
char symname[KSYM_NAME_LEN], *p;

if (!__within_notrace_func(addr))
@@ -477,6 +476,8 @@ static bool within_notrace_func(struct trace_kprobe *tk)
/* Internal register function - just handle k*probes and flags */
static int __register_trace_kprobe(struct trace_kprobe *tk)
{
+ unsigned long addr = trace_kprobe_address(tk);
+ char symname[KSYM_NAME_LEN];
int i, ret;

ret = security_locked_down(LOCKDOWN_KPROBES);
@@ -486,9 +487,9 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
if (trace_kprobe_is_registered(tk))
return -EINVAL;

- if (within_notrace_func(tk)) {
+ if (within_notrace_func(tk, addr)) {
pr_warn("Could not probe notrace function %s\n",
- trace_kprobe_symbol(tk));
+ lookup_symbol_name(addr, symname) ? trace_kprobe_symbol(tk) : symname);
return -EINVAL;
}


base-commit: e46ad59233cf16daf4f3b9dd080003f01ac940fe
--
2.40.1



2023-06-09 07:34:33

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] trace/kprobe: Display the actual notrace function when rejecting a probe

Hi Naveen,

kernel test robot noticed the following build errors:

[auto build test ERROR on e46ad59233cf16daf4f3b9dd080003f01ac940fe]

url: https://github.com/intel-lab-lkp/linux/commits/Naveen-N-Rao/trace-kprobe-Display-the-actual-notrace-function-when-rejecting-a-probe/20230609-125904
base: e46ad59233cf16daf4f3b9dd080003f01ac940fe
patch link: https://lore.kernel.org/r/20230609045545.418677-1-naveen%40kernel.org
patch subject: [PATCH] trace/kprobe: Display the actual notrace function when rejecting a probe
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20230609/[email protected]/config)
compiler: mips-linux-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout e46ad59233cf16daf4f3b9dd080003f01ac940fe
b4 shazam https://lore.kernel.org/r/[email protected]
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=mips olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash kernel/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

kernel/trace/trace_kprobe.c: In function '__register_trace_kprobe':
>> kernel/trace/trace_kprobe.c:490:41: error: macro "within_notrace_func" passed 2 arguments, but takes just 1
490 | if (within_notrace_func(tk, addr)) {
| ^
kernel/trace/trace_kprobe.c:473: note: macro "within_notrace_func" defined here
473 | #define within_notrace_func(tk) (false)
|
>> kernel/trace/trace_kprobe.c:490:13: error: 'within_notrace_func' undeclared (first use in this function)
490 | if (within_notrace_func(tk, addr)) {
| ^~~~~~~~~~~~~~~~~~~
kernel/trace/trace_kprobe.c:490:13: note: each undeclared identifier is reported only once for each function it appears in


vim +/within_notrace_func +490 kernel/trace/trace_kprobe.c

475
476 /* Internal register function - just handle k*probes and flags */
477 static int __register_trace_kprobe(struct trace_kprobe *tk)
478 {
479 unsigned long addr = trace_kprobe_address(tk);
480 char symname[KSYM_NAME_LEN];
481 int i, ret;
482
483 ret = security_locked_down(LOCKDOWN_KPROBES);
484 if (ret)
485 return ret;
486
487 if (trace_kprobe_is_registered(tk))
488 return -EINVAL;
489
> 490 if (within_notrace_func(tk, addr)) {
491 pr_warn("Could not probe notrace function %s\n",
492 lookup_symbol_name(addr, symname) ? trace_kprobe_symbol(tk) : symname);
493 return -EINVAL;
494 }
495
496 for (i = 0; i < tk->tp.nr_args; i++) {
497 ret = traceprobe_update_arg(&tk->tp.args[i]);
498 if (ret)
499 return ret;
500 }
501
502 /* Set/clear disabled flag according to tp->flag */
503 if (trace_probe_is_enabled(&tk->tp))
504 tk->rp.kp.flags &= ~KPROBE_FLAG_DISABLED;
505 else
506 tk->rp.kp.flags |= KPROBE_FLAG_DISABLED;
507
508 if (trace_kprobe_is_return(tk))
509 ret = register_kretprobe(&tk->rp);
510 else
511 ret = register_kprobe(&tk->rp.kp);
512
513 return ret;
514 }
515

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki