From: Maxim Levitsky <mlevitsk@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Cc: x86@kernel.org, Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@redhat.com>,
Sean Christopherson <seanjc@google.com>,
"H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 3/3] KVM: x86: add new nested vmexit tracepoints
Date: Thu, 19 Dec 2024 12:49:46 -0500 [thread overview]
Message-ID: <4c1c999c29809c683cc79bc8c77cbe5d7eca37b7.camel@redhat.com> (raw)
In-Reply-To: <9ff2be87-117a-4f96-af3b-dacb55467449@redhat.com>
On Thu, 2024-12-19 at 18:33 +0100, Paolo Bonzini wrote:
> On 9/10/24 22:03, Maxim Levitsky wrote:
> > Add 3 new tracepoints for nested VM exits which are intended
> > to capture extra information to gain insights about the nested guest
> > behavior.
> >
> > The new tracepoints are:
> >
> > - kvm_nested_msr
> > - kvm_nested_hypercall
> >
> > These tracepoints capture extra register state to be able to know
> > which MSR or which hypercall was done.
> >
> > - kvm_nested_page_fault
> >
> > This tracepoint allows to capture extra info about which host pagefault
> > error code caused the nested page fault.
> >
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> > ---
> > arch/x86/kvm/svm/nested.c | 22 +++++++++++
> > arch/x86/kvm/trace.h | 82 +++++++++++++++++++++++++++++++++++++--
> > arch/x86/kvm/vmx/nested.c | 27 +++++++++++++
> > arch/x86/kvm/x86.c | 3 ++
> > 4 files changed, 131 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> > index 6f704c1037e51..2020307481553 100644
> > --- a/arch/x86/kvm/svm/nested.c
> > +++ b/arch/x86/kvm/svm/nested.c
> > @@ -38,6 +38,8 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
> > {
> > struct vcpu_svm *svm = to_svm(vcpu);
> > struct vmcb *vmcb = svm->vmcb;
> > + u64 host_error_code = vmcb->control.exit_info_1;
> > +
> >
> > if (vmcb->control.exit_code != SVM_EXIT_NPF) {
> > /*
> > @@ -48,11 +50,15 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
> > vmcb->control.exit_code_hi = 0;
> > vmcb->control.exit_info_1 = (1ULL << 32);
> > vmcb->control.exit_info_2 = fault->address;
> > + host_error_code = 0;
> > }
> >
> > vmcb->control.exit_info_1 &= ~0xffffffffULL;
> > vmcb->control.exit_info_1 |= fault->error_code;
> >
> > + trace_kvm_nested_page_fault(fault->address, host_error_code,
> > + fault->error_code);
> > +
>
> I disagree with Sean about trace_kvm_nested_page_fault. It's a useful
> addition and it is easier to understand what's happening with a
> dedicated tracepoint (especially on VMX).
>
> Tracepoint are not an exact science and they aren't entirely kernel API.
> At least they can just go away at any time (changing them is a lot
> more tricky, but their presence is not guaranteed). The one below has
> the slight ugliness of having to do some computation in
> nested_svm_vmexit(), this one should go in.
>
> > nested_svm_vmexit(svm);
> > }
> >
> > @@ -1126,6 +1132,22 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
> > vmcb12->control.exit_int_info_err,
> > KVM_ISA_SVM);
> >
> > + /* Collect some info about nested VM exits */
> > + switch (vmcb12->control.exit_code) {
> > + case SVM_EXIT_MSR:
> > + trace_kvm_nested_msr(vmcb12->control.exit_info_1 == 1,
> > + kvm_rcx_read(vcpu),
> > + (vmcb12->save.rax & 0xFFFFFFFFull) |
> > + (((u64)kvm_rdx_read(vcpu) << 32)));
> > + break;
> > + case SVM_EXIT_VMMCALL:
> > + trace_kvm_nested_hypercall(vmcb12->save.rax,
> > + kvm_rbx_read(vcpu),
> > + kvm_rcx_read(vcpu),
> > + kvm_rdx_read(vcpu));
> > + break;
>
> Here I probably would have preferred an unconditional tracepoint giving
> RAX/RBX/RCX/RDX after a nested vmexit. This is not exactly what Sean
> wanted but perhaps it strikes a middle ground? I know you wrote this
> for a debugging tool, do you really need to have everything in a single
> tracepoint, or can you correlate the existing exit tracepoint with this
> hypothetical trace_kvm_nested_exit_regs, to pick RDMSR vs. WRMSR?
Hi!
If the new trace_kvm_nested_exit_regs tracepoint has a VM exit number argument, then
I can enable this new tracepoint twice with a different filter (vm_exit_num number == msr and vm_exit_num == vmcall),
and each instance will count the events that I need.
So this can work.
Thanks!
Best regards,
Maxim Levitsky
>
> Paolo
>
next prev parent reply other threads:[~2024-12-19 17:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 20:03 [PATCH v5 0/3] KVM: x86: tracepoint updates Maxim Levitsky
2024-09-10 20:03 ` [PATCH v5 1/3] KVM: x86: add more information to the kvm_entry tracepoint Maxim Levitsky
2024-12-18 20:53 ` Sean Christopherson
2024-09-10 20:03 ` [PATCH v5 2/3] KVM: x86: add information about pending requests to kvm_exit tracepoint Maxim Levitsky
2024-09-10 20:03 ` [PATCH v5 3/3] KVM: x86: add new nested vmexit tracepoints Maxim Levitsky
2024-12-18 21:14 ` [PATCH v5 3/3] KVM: x86: add new nested vmexit tracepointsg Sean Christopherson
2024-12-19 17:33 ` [PATCH v5 3/3] KVM: x86: add new nested vmexit tracepoints Paolo Bonzini
2024-12-19 17:49 ` Maxim Levitsky [this message]
2024-12-19 18:02 ` Paolo Bonzini
2025-01-16 22:53 ` Sean Christopherson
2024-10-30 21:21 ` [PATCH v5 0/3] KVM: x86: tracepoint updates Maxim Levitsky
2024-11-22 1:04 ` Maxim Levitsky
2024-12-19 2:40 ` Sean Christopherson
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=4c1c999c29809c683cc79bc8c77cbe5d7eca37b7.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--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®