perf: Couldn't record kernel reference relocation symbol

Martin Vegter picture Martin Vegter · Jan 22, 2014 · Viewed 16.5k times · Source

I have compiled perf for my kernel (3.11.10). During the compilation, some libraries were missing, so I have installed those.

But now when I run perf, I get following message:

Couldn't record kernel reference relocation symbol
Symbol resolution may be skewed if relocation was used (e.g. kexec).
Check /proc/kallsyms permission or run as root.

Kernel address maps (/proc/{kallsyms,modules}) were restricted.
Check /proc/sys/kernel/kptr_restrict before running 'perf record'
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.

Since I am using custom build kernel, the most obvious explanation to me is, that some option is missing from my kernel. If so, how can I find out what is missing?

I am not sure what exactly perf is complaining about. How can I fix this?

EDIT:

/proc/kallsyms does not exist and /proc/sys/kernel/kptr_restrict contains 0:

$ cat /proc/sys/kernel/kptr_restrict
0

I have compiled the kernel myself, and it is possible that it is missing some option. What is this /proc/kallsyms ? How can I enable it in my kernel?

Answer

osgx picture osgx · Feb 5, 2014

What is your kernel? Is it from the linux distributive you use or is it compiled by you (how did you install it)?

First part of warning says about /proc/kallsyms - can you show output of the command (started from the same user you used to run perf)

ls -l  /proc/kallsyms
cat /proc/kallsyms | head

Second part of the perf message says about kptr_restrict sysctl setting. Can you do

cat /proc/sys/kernel/kptr_restrict

to check the setting. Basically, to profile the kernel symbols you should either disable kptr_restrict by setting it to zero (as described in https://lwn.net/Articles/420403/ or https://code.google.com/p/dart/wiki/Profiling):

# Run as root user - e.g. after doing "sudo bash"
echo 0 > /proc/sys/kernel/kptr_restrict

or (https://stackoverflow.com/a/20391360/196561)

sudo sh -c " echo 0 > /proc/sys/kernel/kptr_restrict"

or

echo 0 | sudo tee /proc/sys/kernel/kptr_restrict

or you can always run the perf from root user.

After setting kptr_restrict to zero or when running perf from root you should get no warning about kallsyms and will be able to profile kernel functions.

Update: seems that perf record always want access to kallsyms/restricted kptrs, even with userspace-only event (-e cycles:u)