All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm/x86: clear hlt for intel cpu when resetting vcpu
@ 2023-06-30  7:26 Qi Ai
  2023-06-30 10:14 ` Chao Gao
  0 siblings, 1 reply; 8+ messages in thread
From: Qi Ai @ 2023-06-30  7:26 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, hpa, kvm
  Cc: fengzhimin, cenjiahui, fangying.tommy, dengqiao.joey, Qi Ai

when cpu-pm=on is set in qemu, if a crash occurs within the guest,
after kdump has collected the vmcore, the system will be reset.
the ActivityState in the VMCS is set to HLT, because the guest executed
the halt instruction. however, ActivityState is not set to Active
before the restart, resulting in the cpu being in an inactive state
where it doesn't execute instructions.

in the __set_regs function, check whether a reset will occurs.
if it is, set the ActivityState to Active, which ensures that the cpu will
be executing instructions normally.

Signed-off-by: Qi Ai <aiqi.i7@bytedance.com>
---
 arch/x86/include/asm/kvm_host.h | 2 ++
 arch/x86/kvm/vmx/vmx.c          | 2 ++
 arch/x86/kvm/x86.c              | 6 ++++++
 3 files changed, 10 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index fb9d1f2d6136..db5a47500b08 100644
--- 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);
 };
 
 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 &&
+				!is_protmode(vcpu))
+			kvm_x86_ops.clear_hlt(vcpu);
+	}
 }
 
 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-31 19:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.