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

perf_event: Eliminate paranoia error for check_exclude_guest() #257

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

willowec
Copy link
Contributor

@willowec willowec commented Oct 10, 2024

Pull Request Description

On systems with the kernel setting perf_event_paranoid>=2, userspace calls to perf_event_open() must set attr.exclude_kernel=1. Set exclude_kernel=1 in check_exclude_guest() to allow the function to execute successfully on systems with perf_event_paranoid>=2;

Author Checklist

  • Description
    Why this PR exists. Reference all relevant information, including background, issues, test failures, etc
  • Commits
    Commits are self contained and only do one thing
    Commits have a header of the form: module: short description
    Commits have a body (whenever relevant) containing a detailed description of the addressed problem and its solution
  • Tests
    The PR needs to pass all the tests

@Treece-Burgess
Copy link
Contributor

Hello @willowec, what error are you getting when you do not have exclude_kernel=1 set and when does it occur?

@willowec
Copy link
Contributor Author

willowec commented Dec 17, 2024

@Treece-Burgess I apologize for excluding that information previously. Without the fix introduced in this PR, the error occurs for nearly every test invoked by make fulltest. It does not appear to be affecting the tests, but I figure it probably shouldn't be happening. For example, here is some trimmed output from make fulltest:

...
Running ctests/calibrate:                                  PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
SKIPPED
Running ctests/case1:                                      PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
PASSED
Running ctests/case2:                                      PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
PASSED
Running ctests/child_overflow:                             PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
SKIPPED
...

This occurs on my machine running Debian 6.7.12-1~bpo12+1, kernel 6.7.12+bpo-amd64 with kernel.perf_event_paranoid=2, but not for kernel.perf_event_paranoid<2.

@Treece-Burgess Treece-Burgess added component-perf_event PRs and Issues related to the perf_event component status-ready-for-review PR is ready to be reviewed labels Dec 19, 2024
@Treece-Burgess
Copy link
Contributor

Treece-Burgess commented Dec 19, 2024

@willowec I tested the proposed changes on a machine where my paranoid level is set to 4 and I still get the output of Couldn't open hw_instructions in exclude_guest=0:

Running ctests/attach2:                                    PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
SKIPPED
Running ctests/attach3:                                    PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
SKIPPED
Running ctests/attach_cpu:                                 PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test
SKIPPED

I am on an Ubuntu machine with a kernel version of 5.15.0-87-generic.

I do think that the error makes sense if you have a paranoid level that does not permit you to access any hardware counters. However, the message could be a bit more explicit stating that you need to have your paranoid level set < 2.

@willowec
Copy link
Contributor Author

willowec commented Dec 20, 2024

@Treece-Burgess Interesting! The same thing happens for me on my Debian machine with perf_event_paranoid=4. Looking into it some more, it looks like the master branch of the linux kernel only defines paranoia levels up to 2 (see kernel/events/core.c). The comment documenting the levels is mirrored here:

/*
 * perf event paranoia level:
 *  -1 - not paranoid at all
 *   0 - disallow raw tracepoint access for unpriv
 *   1 - disallow cpu events for unpriv
 *   2 - disallow kernel profiling for unpriv
 */

It also looks like some distros like Debian and Ubuntu include patches that add an extra level that disallows all use of perf_event_open() for unprivileged users. For Debian, that patch is security,perf: Allow further restriction of perf_event_open.

Since paranoia level 2 only disallows kernel profiling for unprivileged users, from my understanding shouldn't check_exclude_guest() be able to execute without error when perf_event_paranoid=2? Either way, editing the error message to indicate the error is probably a paranoia issue would be helpful I think.

@Treece-Burgess
Copy link
Contributor

@willowec On a system where my perf_event_paranoid level is set to 2, I do get the output of PAPI Error: Couldn't open hw_instructions in exclude_guest=0 test when I run ./run_tests.sh. Even though the tests do seem to run as expected.
With your proposed changes this does not occur.

I think adding your suggested change and updating the error message would probably be the best course of action. Let me speak with another team member about it more.

@Treece-Burgess
Copy link
Contributor

Treece-Burgess commented Jan 17, 2025

@willowec Could you rebase your branch before I merge?

… paranoid kernel

On systems with perf_event_paranoid>=2, userspace calls to
perf_event_open() must set attr.exclude_kernel=1. Set exclude_kernel=1
in check_exclude_guest() to allow the function to execute successfully
on systems with perf_event_paranoid>=2;
@willowec willowec force-pushed the check-exclude-guest branch from bb6616a to 1bce2af Compare January 21, 2025 20:57
@willowec
Copy link
Contributor Author

@Treece-Burgess Sorry for the delay, re-based!

@adanalis adanalis merged commit b59cc5a into icl-utk-edu:master Jan 24, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-perf_event PRs and Issues related to the perf_event component status-ready-for-review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants