Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf intel-pt: Fix exclude_guest setting

In the past, the exclude_guest setting has had no effect on Intel PT
tracing, but that may not be the case in the future.

Set the flag correctly based upon whether KVM is using Intel PT
"Host/Guest" mode, which is determined by the kvm_intel module
parameter pt_mode:

pt_mode=0 System-wide mode : host and guest output to host buffer
pt_mode=1 Host/Guest mode : host/guest output to host/guest
buffers respectively

Fixes: 6e86bfdc4a60 ("perf intel-pt: Support decoding of guest kernel")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20240625104532.11990-3-adrian.hunter@intel.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Adrian Hunter and committed by
Namhyung Kim
b40934ae 36b4cd99

+12
+12
tools/perf/arch/x86/util/intel-pt.c
··· 32 32 #include "../../../util/tsc.h" 33 33 #include <internal/lib.h> // page_size 34 34 #include "../../../util/intel-pt.h" 35 + #include <api/fs/fs.h> 35 36 36 37 #define KiB(x) ((x) * 1024) 37 38 #define MiB(x) ((x) * 1024 * 1024) ··· 429 428 } 430 429 #endif 431 430 431 + static bool intel_pt_exclude_guest(void) 432 + { 433 + int pt_mode; 434 + 435 + if (sysfs__read_int("module/kvm_intel/parameters/pt_mode", &pt_mode)) 436 + pt_mode = 0; 437 + 438 + return pt_mode == 1; 439 + } 440 + 432 441 static void intel_pt_valid_str(char *str, size_t len, u64 valid) 433 442 { 434 443 unsigned int val, last = 0, state = 1; ··· 631 620 } 632 621 evsel->core.attr.freq = 0; 633 622 evsel->core.attr.sample_period = 1; 623 + evsel->core.attr.exclude_guest = intel_pt_exclude_guest(); 634 624 evsel->no_aux_samples = true; 635 625 evsel->needs_auxtrace_mmap = true; 636 626 intel_pt_evsel = evsel;