public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix reboot on non-preemptible kernels
@ 2010-12-02 16:00 Avi Kivity
  2010-12-02 16:00 ` [PATCH 1/2] KVM: Don't spin on virt instruction faults during reboot Avi Kivity
  2010-12-02 16:00 ` [PATCH 2/2] KVM: VMX: Return 0 from a failed VMREAD Avi Kivity
  0 siblings, 2 replies; 3+ messages in thread
From: Avi Kivity @ 2010-12-02 16:00 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

Reboot with guests running, on Intel hosts, with a non-preemptible host
kernel is broken.  This patchset fixes the issue.

Avi Kivity (2):
  KVM: Don't spin on virt instruction faults during reboot
  KVM: VMX: Return 0 from a failed VMREAD

 arch/x86/include/asm/kvm_host.h |    8 ++++++--
 arch/x86/kvm/vmx.c              |    4 ++--
 virt/kvm/kvm_main.c             |   13 ++++---------
 3 files changed, 12 insertions(+), 13 deletions(-)


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

* [PATCH 1/2] KVM: Don't spin on virt instruction faults during reboot
  2010-12-02 16:00 [PATCH 0/2] Fix reboot on non-preemptible kernels Avi Kivity
@ 2010-12-02 16:00 ` Avi Kivity
  2010-12-02 16:00 ` [PATCH 2/2] KVM: VMX: Return 0 from a failed VMREAD Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2010-12-02 16:00 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

Since vmx blocks INIT signals, we disable virtualization extensions during
reboot.  This leads to virtualization instructions faulting; we trap these
faults and spin while the reboot continues.

Unfortunately spinning on a non-preemptible kernel may block a task that
reboot depends on; this causes the reboot to hang.

Fix by skipping over the instruction and hoping for the best.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/include/asm/kvm_host.h |    8 ++++++--
 virt/kvm/kvm_main.c             |   13 ++++---------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 0e64a39..3987e1f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -790,14 +790,18 @@ enum {
  * reboot turns off virtualization while processes are running.
  * Trap the fault and ignore the instruction if that happens.
  */
-asmlinkage void kvm_handle_fault_on_reboot(void);
+asmlinkage void kvm_spurious_fault(void);
+extern bool kvm_rebooting;
 
 #define __kvm_handle_fault_on_reboot(insn) \
 	"666: " insn "\n\t" \
+	"668: \n\t"                           \
 	".pushsection .fixup, \"ax\" \n" \
 	"667: \n\t" \
+	"cmpb $0, kvm_rebooting \n\t"	      \
+	"jne 668b \n\t"      		      \
 	__ASM_SIZE(push) " $666b \n\t"	      \
-	"jmp kvm_handle_fault_on_reboot \n\t" \
+	"call kvm_spurious_fault \n\t"	      \
 	".popsection \n\t" \
 	".pushsection __ex_table, \"a\" \n\t" \
 	_ASM_PTR " 666b, 667b \n\t" \
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c4ee364..83f5bf6 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -90,7 +90,8 @@ static void hardware_disable_all(void);
 
 static void kvm_io_bus_destroy(struct kvm_io_bus *bus);
 
-static bool kvm_rebooting;
+bool kvm_rebooting;
+EXPORT_SYMBOL_GPL(kvm_rebooting);
 
 static bool largepages_enabled = true;
 
@@ -2179,18 +2180,12 @@ static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
 }
 
 
-asmlinkage void kvm_handle_fault_on_reboot(void)
+asmlinkage void kvm_spurious_fault(void)
 {
-	if (kvm_rebooting) {
-		/* spin while reset goes on */
-		local_irq_enable();
-		while (true)
-			cpu_relax();
-	}
 	/* Fault while not rebooting.  We want the trace. */
 	BUG();
 }
-EXPORT_SYMBOL_GPL(kvm_handle_fault_on_reboot);
+EXPORT_SYMBOL_GPL(kvm_spurious_fault);
 
 static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
 		      void *v)
-- 
1.7.1


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

* [PATCH 2/2] KVM: VMX: Return 0 from a failed VMREAD
  2010-12-02 16:00 [PATCH 0/2] Fix reboot on non-preemptible kernels Avi Kivity
  2010-12-02 16:00 ` [PATCH 1/2] KVM: Don't spin on virt instruction faults during reboot Avi Kivity
@ 2010-12-02 16:00 ` Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2010-12-02 16:00 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

If we execute VMREAD during reboot we'll just skip over it.  Instead of
returning garbage, return 0, which has a much smaller chance of confusing
the code.  Otherwise we risk a flood of debug printk()s which block the
reboot process if a serial console or netconsole is enabled.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/kvm/vmx.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index caa967e..72cfdb7 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -565,10 +565,10 @@ static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
 
 static unsigned long vmcs_readl(unsigned long field)
 {
-	unsigned long value;
+	unsigned long value = 0;
 
 	asm volatile (__ex(ASM_VMX_VMREAD_RDX_RAX)
-		      : "=a"(value) : "d"(field) : "cc");
+		      : "+a"(value) : "d"(field) : "cc");
 	return value;
 }
 
-- 
1.7.1


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

end of thread, other threads:[~2010-12-02 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-02 16:00 [PATCH 0/2] Fix reboot on non-preemptible kernels Avi Kivity
2010-12-02 16:00 ` [PATCH 1/2] KVM: Don't spin on virt instruction faults during reboot Avi Kivity
2010-12-02 16:00 ` [PATCH 2/2] KVM: VMX: Return 0 from a failed VMREAD Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox