Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect when perf is permission denied and give the user a helpful message #17

Open
andrewrk opened this issue Jun 14, 2023 · 7 comments · May be fixed by #64
Open

detect when perf is permission denied and give the user a helpful message #17

andrewrk opened this issue Jun 14, 2023 · 7 comments · May be fixed by #64
Labels
enhancement New feature or request

Comments

@andrewrk
Copy link
Owner

https://unix.stackexchange.com/questions/14227/do-i-need-root-admin-permissions-to-run-userspace-perf-tool-perf-events-ar

#16 (comment)

poop should inform the user how to configure their system to make it work without root access.

@andrewrk andrewrk added the enhancement New feature or request label Jun 14, 2023
@dweiller
Copy link

We can use something similar to perf's message:

Error:
Access to performance monitoring and observability operations is limited.
Consider adjusting /proc/sys/kernel/perf_event_paranoid setting to open
access to performance monitoring and observability operations for processes
without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability.
More information can be found at 'Perf events and tool security' document:
https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html
perf_event_paranoid setting is 4:
  -1: Allow use of (almost) all events by all users
      Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>= 0: Disallow raw and ftrace function tracepoint access
>= 1: Disallow CPU event access
>= 2: Disallow kernel profiling
To make the adjusted perf_event_paranoid setting permanent preserve it
in /etc/sysctl.conf (e.g. kernel.perf_event_paranoid = <setting>)

In particular we could include a shell command to make an non-permanent change in the setting, either:
sudo echo 1 > /proc/sys/kernel/perf_event_paranoid or sudo sysctl kernel.perf_event_paranoid=1.
I'm not 100% if 1 is the correct setting, but it seems to run for me with that.

@dweiller
Copy link

dweiller commented Jun 19, 2023

On my system sysctl kernel.perf_event_paranoid=3 is good enough (default value is 4) to let poop work, despite what the message from perf (above) and my system's man pages say about the different levels...

@kassane
Copy link

kassane commented Aug 11, 2023

Sadly, perf_event_open turns out unable test run on isolated VMs as it happens from GH actions, even using setcap.

ChristopherRabotin added a commit to nyx-space/nyx that referenced this issue Sep 1, 2023
Last try to get enough permissions to run perf... otherwise it means andrewrk/poop#17 (comment) is blocking it.
@moderation
Copy link
Contributor

sysctl kernel.perf_event_paranoid=3 is working for me too. Xubuntu 23.04 x86_64

@kassane
Copy link

kassane commented Sep 12, 2023

sysctl kernel.perf_event_paranoid=3 is working for me too. Xubuntu 23.04 x86_64

On CI/CD test poop (release-safe build) not working:

 /home/runner/work/zig-http-benchmarks/zig-http-benchmarks/poop/src/main.zig:0:0: 0x2248f1 in main (poop)
/opt/hostedtoolcache/zig/master/x64/lib/std/start.zig:370:37: 0x218777 in posixCallMainAndExit (poop)
            var i: usize = 0;
                                    ^
/opt/hostedtoolcache/zig/master/x64/lib/std/start.zig:243:5: 0x2181b1 in _start (poop)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0xa in ??? (???)
Unwind information for `???:0xa` was not available, trace may be incomplete

./bench.sh: line 76:  5138 Aborted                 (core dumped) poop -d 100 "${commands[@]}"

output: https://github.com/kassane/zig-http-benchmarks/actions/runs/6159000724/job/16712925109#step:7:213
CI config: https://github.com/kassane/zig-http-benchmarks/blob/f79cf863f35598c81e5f696921e2d3551c71ad63/.github/workflows/benchmark.yml#L21-L27

@sdqri
Copy link

sdqri commented Nov 27, 2024

I ran into this error on x86_64 Ubuntu 24.04.1 LTS:

thread 36985 panic: unable to open perf event: PermissionDenied

Running sysctl kernel.perf_event_paranoid=3 fixed it for me. It might be a good idea to document this somewhere accessible to help other users troubleshoot this problem.

@bg-thompson
Copy link

I ran into this error on x86_64 Ubuntu 24.04.1 LTS:

thread 36985 panic: unable to open perf event: PermissionDenied

Running sysctl kernel.perf_event_paranoid=3 fixed it for me. It might be a good idea to document this somewhere accessible to help other users troubleshoot this problem.

I got the same panic on the same OS, and running sudo sysctl kernel.perf_event_paranoid=3 worked for me too.

@dweiller dweiller linked a pull request Jan 3, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants