Martin Vegter
Martin Vegter

Reputation: 527

perf: Couldn't record kernel reference relocation symbol

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?

Upvotes: 37

Views: 29502

Answers (3)

Hari
Hari

Reputation: 1801

@osgx and @Kelly have already given the solution.

In order to make the change to kptr_restrict permanent, one could do the following:

sudo sh -c 'echo "kernel.kptr_restrict=0" >> /etc/sysctl.conf'
sudo sysctl -p

Note: The above worked on my machine, the sysctl configuration file could be located elsewhere in other machines. For e.g., /etc/sysctl.d.

Inspired by this tutorial.

Upvotes: 3

Kelly
Kelly

Reputation: 121

This tutorial worked perfectly for me!

http://lost-and-found-narihiro.blogspot.com/2012/06/how-to-install-perf-kernel-performance.html

Copied from the tutorial:

$ cat /proc/sys/kernel/kptr_restrict
1
$ echo 0 > /proc/sys/kernel/kptr_restrict
$ cat /proc/sys/kernel/kptr_restrict
0

Upvotes: 8

osgx
osgx

Reputation: 94225

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)

Upvotes: 52

Related Questions