* [PATCH 0/2] KVM: x86: Fastpath accounting fixes
@ 2023-06-02 1:19 Sean Christopherson
2023-06-02 1:19 ` [PATCH 1/2] KVM: x86: Account fastpath-only VM-Exits in vCPU stats Sean Christopherson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-06-02 1:19 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Fix two bugs where KVM fails to account/trace exits that are handled
in the super fast fastpath. SVM doesn't actually utilize the super fast
fastpath, i.e. patch 1 only affects VMX and the bug fixed by patch 2 is
benign in the current code base.
Found by inspection, confirmed by hacking together a small selftest and
manually verifying the stats via sysfs.
Sean Christopherson (2):
KVM: x86: Account fastpath-only VM-Exits in vCPU stats
KVM: SVM: Invoke trace_kvm_exit() for fastpath VM-Exits
arch/x86/kvm/svm/svm.c | 4 ++--
arch/x86/kvm/x86.c | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
base-commit: 39428f6ea9eace95011681628717062ff7f5eb5f
--
2.41.0.rc2.161.g9c6817b8e7-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] KVM: x86: Account fastpath-only VM-Exits in vCPU stats
2023-06-02 1:19 [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
@ 2023-06-02 1:19 ` Sean Christopherson
2023-06-02 1:19 ` [PATCH 2/2] KVM: SVM: Invoke trace_kvm_exit() for fastpath VM-Exits Sean Christopherson
2023-06-03 0:52 ` [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-06-02 1:19 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Increment vcpu->stat.exits when handling a fastpath VM-Exit without
going through any part of the "slow" path. Not bumping the exits stat
can result in wildly misleading exit counts, e.g. if the primary reason
the guest is exiting is to program the TSC deadline timer.
Fixes: 404d5d7bff0d ("KVM: X86: Introduce more exit_fastpath_completion enum values")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ceb7c5e9cf9e..a609e39b2cb8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10754,6 +10754,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
exit_fastpath = EXIT_FASTPATH_EXIT_HANDLED;
break;
}
+
+ /* Note, VM-Exits that go down the "slow" path are accounted below. */
+ ++vcpu->stat.exits;
}
/*
--
2.41.0.rc2.161.g9c6817b8e7-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/2] KVM: SVM: Invoke trace_kvm_exit() for fastpath VM-Exits
2023-06-02 1:19 [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
2023-06-02 1:19 ` [PATCH 1/2] KVM: x86: Account fastpath-only VM-Exits in vCPU stats Sean Christopherson
@ 2023-06-02 1:19 ` Sean Christopherson
2023-06-03 0:52 ` [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-06-02 1:19 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Move SVM's call to trace_kvm_exit() from the "slow" VM-Exit handler to
svm_vcpu_run() so that KVM traces fastpath VM-Exits that re-enter the
guest without bouncing through the slow path. This bug is benign in the
current code base as KVM doesn't currently support any such exits on SVM.
Fixes: a9ab13ff6e84 ("KVM: X86: Improve latency for single target IPI fastpath")
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/svm/svm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index ca32389f3c36..6845f4f2dc33 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3418,8 +3418,6 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
struct kvm_run *kvm_run = vcpu->run;
u32 exit_code = svm->vmcb->control.exit_code;
- trace_kvm_exit(vcpu, KVM_ISA_SVM);
-
/* SEV-ES guests must use the CR write traps to track CR registers. */
if (!sev_es_guest(vcpu->kvm)) {
if (!svm_is_intercept(svm, INTERCEPT_CR0_WRITE))
@@ -4156,6 +4154,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
SVM_EXIT_EXCP_BASE + MC_VECTOR))
svm_handle_mce(vcpu);
+ trace_kvm_exit(vcpu, KVM_ISA_SVM);
+
svm_complete_interrupts(vcpu);
if (is_guest_mode(vcpu))
--
2.41.0.rc2.161.g9c6817b8e7-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] KVM: x86: Fastpath accounting fixes
2023-06-02 1:19 [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
2023-06-02 1:19 ` [PATCH 1/2] KVM: x86: Account fastpath-only VM-Exits in vCPU stats Sean Christopherson
2023-06-02 1:19 ` [PATCH 2/2] KVM: SVM: Invoke trace_kvm_exit() for fastpath VM-Exits Sean Christopherson
@ 2023-06-03 0:52 ` Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-06-03 0:52 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
On Thu, 01 Jun 2023 18:19:18 -0700, Sean Christopherson wrote:
> Fix two bugs where KVM fails to account/trace exits that are handled
> in the super fast fastpath. SVM doesn't actually utilize the super fast
> fastpath, i.e. patch 1 only affects VMX and the bug fixed by patch 2 is
> benign in the current code base.
>
> Found by inspection, confirmed by hacking together a small selftest and
> manually verifying the stats via sysfs.
>
> [...]
Applied patch 1 to kvm-x86 fixes (for 6.4), and patch 2 to kvm-x86 svm (for 6.5).
Should have posted these separately...
[1/2] KVM: x86: Account fastpath-only VM-Exits in vCPU stats
https://github.com/kvm-x86/linux/commit/8b703a49c9df
[2/2] KVM: SVM: Invoke trace_kvm_exit() for fastpath VM-Exits
https://github.com/kvm-x86/linux/commit/791a089861fc
--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes
https://github.com/kvm-x86/linux/tree/svm
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-03 0:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-02 1:19 [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
2023-06-02 1:19 ` [PATCH 1/2] KVM: x86: Account fastpath-only VM-Exits in vCPU stats Sean Christopherson
2023-06-02 1:19 ` [PATCH 2/2] KVM: SVM: Invoke trace_kvm_exit() for fastpath VM-Exits Sean Christopherson
2023-06-03 0:52 ` [PATCH 0/2] KVM: x86: Fastpath accounting fixes Sean Christopherson
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®