Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: Qi Ai <aiqi.i7@bytedance.com>
Cc: <seanjc@google.com>, <pbonzini@redhat.com>, <tglx@linutronix.de>,
	<mingo@redhat.com>, <bp@alien8.de>, <dave.hansen@linux.intel.com>,
	<hpa@zytor.com>, <kvm@vger.kernel.org>,
	<fengzhimin@bytedance.com>, <cenjiahui@bytedance.com>,
	<fangying.tommy@bytedance.com>, <dengqiao.joey@bytedance.com>
Subject: Re: [PATCH] kvm/x86: clear hlt for intel cpu when resetting vcpu
Date: Fri, 30 Jun 2023 18:14:31 +0800	[thread overview]
Message-ID: <ZJ6rBwy9p5bbdWrs@chao-email> (raw)
In-Reply-To: <20230630072612.1106705-1-aiqi.i7@bytedance.com>

On Fri, Jun 30, 2023 at 03:26:12PM +0800, Qi Ai wrote:
>--- a/arch/x86/include/asm/kvm_host.h
>+++ b/arch/x86/include/asm/kvm_host.h
>@@ -1731,6 +1731,8 @@ struct kvm_x86_ops {
> 	 * Returns vCPU specific APICv inhibit reasons
> 	 */
> 	unsigned long (*vcpu_get_apicv_inhibit_reasons)(struct kvm_vcpu *vcpu);
>+
>+	void (*clear_hlt)(struct kvm_vcpu *vcpu);

add this new ops to arch/x86/include/asm/kvm-x86-ops.h, and declare it
optional, i.e.,

KVM_X86_OP_OPTIONAL(...)


> };
> 
> struct kvm_x86_nested_ops {
>diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>index 44fb619803b8..11c2fde1ad98 100644
>--- a/arch/x86/kvm/vmx/vmx.c
>+++ b/arch/x86/kvm/vmx/vmx.c
>@@ -8266,6 +8266,8 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = {
> 	.complete_emulated_msr = kvm_complete_insn_gp,
> 
> 	.vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector,
>+
>+	.clear_hlt = vmx_clear_hlt,
> };
> 
> static unsigned int vmx_handle_intel_pt_intr(void)
>diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>index 7f70207e8689..21360f5ed006 100644
>--- a/arch/x86/kvm/x86.c
>+++ b/arch/x86/kvm/x86.c
>@@ -11258,6 +11258,12 @@ static void __set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
> 	vcpu->arch.exception_vmexit.pending = false;
> 
> 	kvm_make_request(KVM_REQ_EVENT, vcpu);
>+
>+	if (kvm_x86_ops.clear_hlt) {
>+		if (kvm_vcpu_is_bsp(vcpu) && regs->rip == 0xfff0 &&

it is weird this applies to BSP only.

>+				!is_protmode(vcpu))
>+			kvm_x86_ops.clear_hlt(vcpu);

Use static_call_cond(kvm_x86_clear_hlt)(vcpu) instead.

It looks incorrect that we add this side-effect heuristically here. I
am wondering if we can link vcpu->arch.mp_state to VMCS activity state,
i.e., when mp_state is set to RUNNABLE in KVM_SET_MP_STATE ioctl, KVM
sets VMCS activity state to active.

>+	}
> }
> 
> int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
>-- 
>2.20.1
>

  reply	other threads:[~2023-06-30 10:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30  7:26 [PATCH] kvm/x86: clear hlt for intel cpu when resetting vcpu Qi Ai
2023-06-30 10:14 ` Chao Gao [this message]
2023-06-30 22:23   ` Isaku Yamahata
2023-06-30 22:56   ` Sean Christopherson
2023-07-04 11:34     ` Qi Ai
2023-07-05  8:40       ` Chao Gao
2023-07-05  9:04     ` Chao Gao
2023-07-31 19:15       ` 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=ZJ6rBwy9p5bbdWrs@chao-email \
    --to=chao.gao@intel.com \
    --cc=aiqi.i7@bytedance.com \
    --cc=bp@alien8.de \
    --cc=cenjiahui@bytedance.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dengqiao.joey@bytedance.com \
    --cc=fangying.tommy@bytedance.com \
    --cc=fengzhimin@bytedance.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    /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