mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Anselm Busse <abusse@amazon.com>
Cc: dwmw@amazon.co.uk, hborghor@amazon.de, sironi@amazon.de,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Add a vCPU stat for #AC exceptions
Date: Wed, 26 Apr 2023 23:19:17 +0800	[thread overview]
Message-ID: <3a71a01f-4c3d-f92c-58d7-2c124a0efa94@intel.com> (raw)
In-Reply-To: <20230426082601.85372-1-abusse@amazon.com>

On 4/26/2023 4:26 PM, Anselm Busse wrote:
> This patch adds a KVM vCPU stat that reflects the number of #AC
> exceptions caused by a guest. This improves the identification and
> debugging of issues that are possibly caused by guests triggering
> split-locks and allows more insides compared to the current situation
> of having only a warning printed when an #AC exception is raised.

Note, on Intel platform, #AC exception has three sources according to 
the latest spec:

1. violation on alignment check when CPL = 3, while CR0.AM and EFLAG.AC 
are set;

2. split lock, when MSR_MEMORY_CTRL.[29] is set;

3. UC lock, when CPUID.0x7_0x2:EDX[16] is 1 and 
MSR_MEMORY_CTRL(0x33).[28] is 1. (see ISE version 048);

you cannot treat every #AC as split lock #AC.

> Signed-off-by: Anselm Busse <abusse@amazon.com>
> ---
>   arch/x86/include/asm/kvm_host.h | 1 +
>   arch/x86/kvm/vmx/vmx.c          | 2 ++
>   arch/x86/kvm/x86.c              | 1 +
>   3 files changed, 4 insertions(+)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 808c292ad3f4..b4ab719fbc69 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1523,6 +1523,7 @@ struct kvm_vcpu_stat {
>   	u64 preemption_other;
>   	u64 guest_mode;
>   	u64 notify_window_exits;
> +	u64 split_lock_exceptions;
>   };
>   
>   struct x86_instruction_info;
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index d2d6e1b6c788..8f48fd8ddead 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -5309,6 +5309,8 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
>   		kvm_run->debug.arch.exception = ex_no;
>   		break;
>   	case AC_VECTOR:
> +		vmx->vcpu.stat.split_lock_exceptions++;
> +
>   		if (vmx_guest_inject_ac(vcpu)) {
>   			kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
>   			return 1;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 3d852ce84920..416a1ed6c423 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -297,6 +297,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
>   	STATS_DESC_COUNTER(VCPU, preemption_other),
>   	STATS_DESC_IBOOLEAN(VCPU, guest_mode),
>   	STATS_DESC_COUNTER(VCPU, notify_window_exits),
> +	STATS_DESC_COUNTER(VCPU, split_lock_exceptions),
>   };
>   
>   const struct kvm_stats_header kvm_vcpu_stats_header = {


  reply	other threads:[~2023-04-26 15:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  8:26 Anselm Busse
2023-04-26 15:19 ` Xiaoyao Li [this message]
2023-04-26 16:56 ` 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=3a71a01f-4c3d-f92c-58d7-2c124a0efa94@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=abusse@amazon.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hborghor@amazon.de \
    --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=sironi@amazon.de \
    --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®