Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 125240
b: refs/heads/master
c: d176720
h: refs/heads/master
v: v3
  • Loading branch information
Eduardo Habkost authored and Avi Kivity committed Dec 31, 2008
1 parent 3f4a5d5 commit 67aabdf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2340b62f77c782c305e6ae7748675a638436d1ef
refs/heads/master: d176720d34c72f7a8474a12204add93e54fe3ef1
62 changes: 60 additions & 2 deletions trunk/arch/x86/kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <asm/proto.h>
#include <asm/reboot_fixups.h>
#include <asm/reboot.h>
#include <asm/virtext.h>

#ifdef CONFIG_X86_32
# include <linux/dmi.h>
Expand Down Expand Up @@ -39,6 +40,12 @@ int reboot_force;
static int reboot_cpu = -1;
#endif

/* This is set if we need to go through the 'emergency' path.
* When machine_emergency_restart() is called, we may be on
* an inconsistent state and won't be able to do a clean cleanup
*/
static int reboot_emergency;

/* This is set by the PCI code if either type 1 or type 2 PCI is detected */
bool port_cf9_safe = false;

Expand Down Expand Up @@ -368,6 +375,48 @@ static inline void kb_wait(void)
}
}

static void vmxoff_nmi(int cpu, struct die_args *args)
{
cpu_emergency_vmxoff();
}

/* Use NMIs as IPIs to tell all CPUs to disable virtualization
*/
static void emergency_vmx_disable_all(void)
{
/* Just make sure we won't change CPUs while doing this */
local_irq_disable();

/* We need to disable VMX on all CPUs before rebooting, otherwise
* we risk hanging up the machine, because the CPU ignore INIT
* signals when VMX is enabled.
*
* We can't take any locks and we may be on an inconsistent
* state, so we use NMIs as IPIs to tell the other CPUs to disable
* VMX and halt.
*
* For safety, we will avoid running the nmi_shootdown_cpus()
* stuff unnecessarily, but we don't have a way to check
* if other CPUs have VMX enabled. So we will call it only if the
* CPU we are running on has VMX enabled.
*
* We will miss cases where VMX is not enabled on all CPUs. This
* shouldn't do much harm because KVM always enable VMX on all
* CPUs anyway. But we can miss it on the small window where KVM
* is still enabling VMX.
*/
if (cpu_has_vmx() && cpu_vmx_enabled()) {
/* Disable VMX on this CPU.
*/
cpu_vmxoff();

/* Halt and disable VMX on the other CPUs */
nmi_shootdown_cpus(vmxoff_nmi);

}
}


void __attribute__((weak)) mach_reboot_fixups(void)
{
}
Expand All @@ -376,6 +425,9 @@ static void native_machine_emergency_restart(void)
{
int i;

if (reboot_emergency)
emergency_vmx_disable_all();

/* Tell the BIOS if we want cold or warm reboot */
*((unsigned short *)__va(0x472)) = reboot_mode;

Expand Down Expand Up @@ -482,13 +534,19 @@ void native_machine_shutdown(void)
#endif
}

static void __machine_emergency_restart(int emergency)
{
reboot_emergency = emergency;
machine_ops.emergency_restart();
}

static void native_machine_restart(char *__unused)
{
printk("machine restart\n");

if (!reboot_force)
machine_shutdown();
machine_emergency_restart();
__machine_emergency_restart(0);
}

static void native_machine_halt(void)
Expand Down Expand Up @@ -532,7 +590,7 @@ void machine_shutdown(void)

void machine_emergency_restart(void)
{
machine_ops.emergency_restart();
__machine_emergency_restart(1);
}

void machine_restart(char *cmd)
Expand Down

0 comments on commit 67aabdf

Please sign in to comment.