diff mbox series

[V2,5/6] perf kvm report: Add guest_code support

Message ID 20220517131011.6117-6-adrian.hunter@intel.com (mailing list archive)
State New, archived
Headers show
Series perf intel-pt: Add support for tracing KVM test programs | expand

Commit Message

Adrian Hunter May 17, 2022, 1:10 p.m. UTC
Add an option to indicate that guest code can be found in the hypervisor
process.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-kvm.txt | 3 +++
 tools/perf/builtin-kvm.c              | 2 ++
 2 files changed, 5 insertions(+)

Comments

Andi Kleen May 23, 2022, 3:54 p.m. UTC | #1
On 5/17/2022 6:10 AM, Adrian Hunter wrote:
> Add an option to indicate that guest code can be found in the hypervisor
> process

Sorry for harping on this, but is it correct that this assumes that the 
code is still at the original location at decode time?

If yes we need some warnings for this, something like:

This only works when the code is still available in the riginal memory 
location at decode time. This is typically the case for kernel code 
(unless modules are unloaded). For user programs it only works as long 
as there is no memory pressure which might cause the memory to be 
reused. For dynamically generated (JITed) code it might be rather 
unreliable unless the hypervisor is SIGSTOPed during decoding.
Adrian Hunter May 23, 2022, 5:56 p.m. UTC | #2
On 23/05/22 18:54, Andi Kleen wrote:
> 
> On 5/17/2022 6:10 AM, Adrian Hunter wrote:
>> Add an option to indicate that guest code can be found in the hypervisor
>> process
> 
> Sorry for harping on this, but is it correct that this assumes that the code is still at the original location at decode time?

No, at decode time, the code is found in the hypervisor dso.

> 
> If yes we need some warnings for this, something like:
> 
> This only works when the code is still available in the riginal memory location at decode time. This is typically the case for kernel code (unless modules are unloaded). 

In this scenario, the VM does not have a kernel.

Note, there is an existing method to trace a guest kernel as described here:

	https://www.man7.org/linux/man-pages/man1/perf-intel-pt.1.html#TRACING_VIRTUAL_MACHINES

For user programs it only works as long as there is no memory pressure which might cause the memory to be reused.

In this scenario, there are also no user programs in the VM, only functions from the hypervisor.

For dynamically generated (JITed) code it might be rather unreliable unless the hypervisor is SIGSTOPed during decoding.
>
diff mbox series

Patch

diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
index cf95baef7b61..83c742adf86e 100644
--- a/tools/perf/Documentation/perf-kvm.txt
+++ b/tools/perf/Documentation/perf-kvm.txt
@@ -94,6 +94,9 @@  OPTIONS
 	kernel module information. Users copy it out from guest os.
 --guestvmlinux=<path>::
 	Guest os kernel vmlinux.
+--guest-code::
+	Indicate that guest code can be found in the hypervisor process,
+	which is a common case for KVM test programs.
 -v::
 --verbose::
 	Be more verbose (show counter open errors, etc).
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 2fa687f73e5e..3696ae97f149 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1603,6 +1603,8 @@  int cmd_kvm(int argc, const char **argv)
 			   "file", "file saving guest os /proc/kallsyms"),
 		OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules,
 			   "file", "file saving guest os /proc/modules"),
+		OPT_BOOLEAN(0, "guest-code", &symbol_conf.guest_code,
+			    "Guest code can be found in hypervisor process"),
 		OPT_INCR('v', "verbose", &verbose,
 			    "be more verbose (show counter open errors, etc)"),
 		OPT_END()