From: Tianyi Liu <i.pear@outlook.com>
To: mark.rutland@arm.com
Cc: acme@kernel.org, adrian.hunter@intel.com,
alexander.shishkin@linux.intel.com, i.pear@outlook.com,
irogers@google.com, jolsa@kernel.org, kvm@vger.kernel.org,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
maz@kernel.org, mingo@redhat.com, namhyung@kernel.org,
pbonzini@redhat.com, peterz@infradead.org, seanjc@google.com,
x86@kernel.org
Subject: Re: [PATCH v2 0/5] perf: KVM: Enable callchains for guests
Date: Fri, 20 Oct 2023 17:21:14 +0800 [thread overview]
Message-ID: <SY4P282MB10848CE48E2605CFC347AD659DDBA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <ZSlNsn-f1j2bB8pW@FVFF77S0Q05N.cambridge.arm.com>
Hi Mark,
On Fri, 13 Oct 2023 15:01:22 +0100, Mark Rutland wrote:
> > > > The event processing flow is as follows (shown as backtrace):
> > > > #0 kvm_arch_vcpu_get_frame_pointer / kvm_arch_vcpu_read_virt (per arch)
> > > > #1 kvm_guest_get_frame_pointer / kvm_guest_read_virt
> > > > <callback function pointers in `struct perf_guest_info_callbacks`>
> > > > #2 perf_guest_get_frame_pointer / perf_guest_read_virt
> > > > #3 perf_callchain_guest
> > > > #4 get_perf_callchain
> > > > #5 perf_callchain
> > > >
> > > > Between #0 and #1 is the interface between KVM and the arch-specific
> > > > impl, while between #1 and #2 is the interface between Perf and KVM.
> > > > The 1st patch implements #0. The 2nd patch extends interfaces between #1
> > > > and #2, while the 3rd patch implements #1. The 4th patch implements #3
> > > > and modifies #4 #5. The last patch is for userspace utils.
> > > >
> > > > Since arm64 hasn't provided some foundational infrastructure (interface
> > > > for reading from a virtual address of guest), the arm64 implementation
> > > > is stubbed for now because it's a bit complex, and will be implemented
> > > > later.
> > >
> > > I hope you realise that such an "interface" would be, by definition,
> > > fragile and very likely to break in a subtle way. The only existing
> > > case where we walk the guest's page tables is for NV, and even that is
> > > extremely fragile.
> >
> > For walking the guest's page tables, yes, there're only very few
> > use cases. Most of them are used in nested virtualization and XEN.
>
> The key point isn't the lack of use cases; the key point is that *this is
> fragile*.
>
> Consider that walking guest page tables is only safe because:
>
> (a) The walks happen in the guest-physical / intermiediate-physical address
> space of the guest, and so are not themselves subject to translation via
> the guest's page tables.
>
> (b) Special traps were added to the architecture (e.g. for TLB invalidation)
> which allow the host to avoid race conditions when the guest modifies page
> tables.
>
> For unwind we'd have to walk structures in the guest's virtual address space,
> which can change under our feet at any time the guest is running, and handling
> that requires much more care.
>
> I think this needs a stronger justification, and an explanation of how you
> handle such races.
Yes, guests can modify the page tables at any time, so the page table
we obtain may be corrupted. We may not be able to complete the traversal
of the page table or may receive incorrect data.
However, these are not critical issues because we often encounter
incorrect stack unwinding results. In fact, here we assume that the
guest OS/program has stack frames (compiled with `fno-omit-frame-pointer`),
but many programs do not adhere to such an assumption, which often leads
to invalid results. This is almost unavoidable, especially when the
guest OS is running third-party programs. The unwind results we record
may be incorrect; if the unwind cannot continue, we only record the
existing results. Addresses that cannot be resolved to symbols will be
later marked as `[unknown]` by `perf kvm`, and this is very common.
Our unwind strategy is conservative to ensure safety and do our best in
readonly situations. If the guest page table is broken, or the address
to be read is somehow not in the guest page table, we will not inject a
page fault but simply stop the unwind. The function that walks the
page table is done entirely in software and is readonly, having no
additional impact on the guest. Some results could also be incorrect.
It is sufficient as long as most of the records are correct for profiling.
Do you think these address your concerns?
Thanks,
Tianyi Liu
prev parent reply other threads:[~2023-10-20 9:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-08 14:48 Tianyi Liu
2023-10-08 14:52 ` [PATCH v2 1/5] KVM: Add arch specific interfaces for sampling guest callchains Tianyi Liu
2023-10-08 21:12 ` kernel test robot
2023-10-08 21:32 ` kernel test robot
2023-10-08 22:25 ` kernel test robot
2023-10-09 3:17 ` Tianyi Liu
2023-10-08 14:53 ` [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains Tianyi Liu
2023-10-08 14:56 ` [PATCH v2 3/5] KVM: implement new perf interfaces Tianyi Liu
2023-10-08 14:57 ` [PATCH v2 4/5] perf kvm: Support sampling guest callchains Tianyi Liu
2023-10-08 19:57 ` kernel test robot
2023-10-10 16:12 ` Maxim Levitsky
2023-10-11 14:44 ` Tianyi Liu
2023-10-12 20:41 ` kernel test robot
2023-10-08 14:57 ` [PATCH v2 5/5] perf tools: Support PERF_CONTEXT_GUEST_* flags Tianyi Liu
2023-10-11 16:45 ` [PATCH v2 0/5] perf: KVM: Enable callchains for guests Marc Zyngier
2023-10-12 6:35 ` Tianyi Liu
2023-10-13 14:01 ` Mark Rutland
2023-10-20 9:21 ` Tianyi Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SY4P282MB10848CE48E2605CFC347AD659DDBA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM \
--to=i.pear@outlook.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®