This patch writes 0 (actually, what really matters is that the LSB is cleared) to the system time msr before rebooting/shutting down the machine.
Without it, we can have a random memory location being written when the guest comes back Signed-off-by: Glauber Costa <[EMAIL PROTECTED]> --- arch/x86/kernel/kvmclock.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index f654a12..5c9ff8d 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -21,6 +21,7 @@ #include <linux/kvm_para.h> #include <asm/arch_hooks.h> #include <asm/msr.h> #include <linux/percpu.h> +#include <asm/reboot.h> #define KVM_SCALE 22 @@ -142,6 +143,32 @@ static void kvm_setup_secondary_clock(vo setup_secondary_APIC_clock(); } +/* + * After the clock is registered, the host will keep writing to the + * registered memory location. If the guest happens to shutdown, or restart, + * this memory won't be valid. In cases like kexec, in which you install a new kernel, + * this will mean a random memory location will be kept being written. So before + * any kind of shutdown from our side, we unregister the clock by writting anything + * that does not have the 'enable' bit set in the msr + */ +static void kvm_restart(char *unused) { + native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0); + native_machine_restart(unused); +} + +/* Forgive me dear lord, for my laziness */ +#define kvm_reboot_fn(x) \ +static void kvm_##x(void) { \ + native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0); \ + native_machine_##x(); \ +} + +kvm_reboot_fn(emergency_restart) +kvm_reboot_fn(shutdown) +kvm_reboot_fn(halt) +kvm_reboot_fn(power_off) +#undef kvm_reboot_fn + void __init kvmclock_init(void) { if (!kvm_para_available()) @@ -154,6 +181,11 @@ void __init kvmclock_init(void) pv_time_ops.set_wallclock = kvm_set_wallclock; pv_time_ops.sched_clock = kvm_clock_read; pv_apic_ops.setup_secondary_clock = kvm_setup_secondary_clock; + machine_ops.emergency_restart = kvm_emergency_restart; + machine_ops.shutdown = kvm_shutdown; + machine_ops.restart = kvm_restart; + machine_ops.halt = kvm_halt; + machine_ops.power_off = kvm_power_off; clocksource_register(&kvm_clock); } } -- 1.4.2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel