Skip to content

Commit

Permalink
perf_event: Eliminate permission error for check_exclude_guest() with…
Browse files Browse the repository at this point in the history
… 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;
  • Loading branch information
willowec committed Jan 21, 2025
1 parent 2efc5af commit 1bce2af
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/perf_event/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ check_exclude_guest( void )
/* First check that we can open a plain instructions event */
memset(&attr, 0 , sizeof(attr));
attr.config = PERF_COUNT_HW_INSTRUCTIONS;
attr.exclude_kernel=1;

ev_fd = sys_perf_event_open( &attr, 0, -1, -1, 0 );
if ( ev_fd == -1 ) {
Expand All @@ -296,6 +297,7 @@ check_exclude_guest( void )
/* Now try again with excude_guest */
memset(&attr, 0 , sizeof(attr));
attr.config = PERF_COUNT_HW_INSTRUCTIONS;
attr.exclude_kernel=1;
attr.exclude_guest=1;

ev_fd = sys_perf_event_open( &attr, 0, -1, -1, 0 );
Expand Down

0 comments on commit 1bce2af

Please sign in to comment.