All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jing Zhang <jingzhangos@google.com>
Cc: KVM <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
	David Matlack <dmatlack@google.com>,
	Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>,
	Peter Feiner <pfeiner@google.com>,
	Jim Mattson <jmattson@google.com>
Subject: Re: [PATCH 2/2] KVM: stats: Add counters for SVM exit reasons
Date: Fri, 27 Aug 2021 20:12:27 +0000	[thread overview]
Message-ID: <YSlHK+ZZFuokMa4S@google.com> (raw)
In-Reply-To: <20210827174110.3723076-2-jingzhangos@google.com>

On Fri, Aug 27, 2021, Jing Zhang wrote:
> Three different exit code ranges are named as low, high and vmgexit,
> which start from 0x0, 0x400 and 0x80000000.
> 
> Original-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Jing Zhang <jingzhangos@google.com>
> ---
>  arch/x86/include/asm/kvm_host.h |  7 +++++++
>  arch/x86/include/uapi/asm/svm.h |  7 +++++++
>  arch/x86/kvm/svm/svm.c          | 21 +++++++++++++++++++++
>  arch/x86/kvm/x86.c              |  9 +++++++++
>  4 files changed, 44 insertions(+)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index dd2380c9ea96..6e3c11a29afe 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -35,6 +35,7 @@
>  #include <asm/kvm_vcpu_regs.h>
>  #include <asm/hyperv-tlfs.h>
>  #include <asm/vmx.h>
> +#include <asm/svm.h>
>  
>  #define __KVM_HAVE_ARCH_VCPU_DEBUGFS
>  
> @@ -1261,6 +1262,12 @@ struct kvm_vcpu_stat {
>  	u64 vmx_all_exits[EXIT_REASON_NUM];
>  	u64 vmx_l2_exits[EXIT_REASON_NUM];
>  	u64 vmx_nested_exits[EXIT_REASON_NUM];
> +	u64 svm_exits_low[SVM_EXIT_LOW_END - SVM_EXIT_LOW_START];
> +	u64 svm_exits_high[SVM_EXIT_HIGH_END - SVM_EXIT_HIGH_START];
> +	u64 svm_vmgexits[SVM_VMGEXIT_END - SVM_VMGEXIT_START];

This is, for lack of a better word, a very lazy approach.  With a bit more (ok,
probably a lot more) effort and abstraction, we can have parity between VMX and
SVM, and eliminate a bunch of dead weight.  Having rough parity would likely be
quite helpful for the end user, e.g. reduces/eliminates vendor specific userspace
code.

E.g. this more or less doubles the memory footprint due to tracking VMX and SVM
separately, SVM has finer granularity than VMX (often too fine),  VMX tracks nested
exits but SVM does not, etc...

If we use KVM-defined exit reasons, then we can omit the exits that should never
happen (SVM has quite a few), and consolidate the ones no one should ever care
about, e.g. DR0..DR4 and DR6 can be collapsed (if I'm remembering my DR aliases
correctly).  And on the VMX side we can provide better granularity than the raw
exit reason, e.g. VMX's bundling of NMIs and exceptions is downright gross.

	#define KVM_GUEST_EXIT_READ_CR0
	#define KVM_GUEST_EXIT_READ_CR3
	#define KVM_GUEST_EXIT_READ_CR4
	#define KVM_GUEST_EXIT_READ_CR8
	#define KVM_GUEST_EXIT_DR_READ
	#define KVM_GUEST_EXIT_DR_WRITE
	#define KVM_GUEST_EXIT_DB_EXCEPTION
	#define KVM_GUEST_EXIT_BP_EXCEPTION
	#define KVM_GUEST_EXIT_UD_EXCEPTION

	...
	#define KVM_NR_GUEST_EXIT_REASONS

	u64 l1_exits[KVM_NR_GUEST_EXIT_REASONS];
	u64 l2_exits[KVM_NR_GUEST_EXIT_REASONS];
	u64 nested_exits[KVM_NR_GUEST_EXIT_REASONS];


The downside is that it will require KVM-defined exit reasons and will have a
slightly higher maintenance cost because of it, but I think overall it would be
a net positive.  Paolo can probably even concoct some clever arithmetic to avoid
conditionals when massaging SVM exits reasons.  VMX will require a bit more
manual effort, especially to play nice with nested, but in the end I think we'll
be happier.

> +	u64 svm_vmgexit_unsupported_event;
> +	u64 svm_exit_sw;
> +	u64 svm_exit_err;
>  };

  reply	other threads:[~2021-08-27 20:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 17:41 [PATCH 1/2] KVM: stats: Add counters for VMX all/L2/nested exit reasons Jing Zhang
2021-08-27 17:41 ` [PATCH 2/2] KVM: stats: Add counters for SVM " Jing Zhang
2021-08-27 20:12   ` Sean Christopherson [this message]
2021-08-31 17:27     ` Jing Zhang

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=YSlHK+ZZFuokMa4S@google.com \
    --to=seanjc@google.com \
    --cc=dmatlack@google.com \
    --cc=jingzhangos@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    --cc=pfeiner@google.com \
    --cc=pshier@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.