155 /* 156 * After the clock is registered, the host will keep writing to the 157 * registered memory location. If the guest happens to shutdown, this memory 158 * won't be valid. In cases like kexec, in which you install a new kernel, this 159 * means a random memory location will be kept being written. So before any 160 * kind of shutdown from our side, we unregister the clock by writting anything 161 * that does not have the 'enable' bit set in the msr 162 */ 163 #ifdef CONFIG_KEXEC 164 static void kvm_crash_shutdown(struct pt_regs *regs) 165 { 166 native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0); 167 native_machine_crash_shutdown(regs); 168 } 169 #endif 170 171 static void kvm_shutdown(void) 172 { 173 native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0); 174 native_machine_shutdown(); 175 } 176 177 void __init kvmclock_init(void) 178 { 179 if (!kvm_para_available()) 180 return; 181 182 if (kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)) { 183 if (kvm_register_clock("boot clock")) 184 return; 185 pv_time_ops.get_wallclock = kvm_get_wallclock; 186 pv_time_ops.set_wallclock = kvm_set_wallclock; 187 pv_time_ops.sched_clock = kvm_clock_read; 188 pv_time_ops.get_tsc_khz = kvm_get_tsc_khz; 189 #ifdef CONFIG_X86_LOCAL_APIC 190 pv_apic_ops.setup_secondary_clock = kvm_setup_secondary_clock; 191 #endif 192 #ifdef CONFIG_SMP 193 smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; 194 #endif 195 machine_ops.shutdown = kvm_shutdown; 196 #ifdef CONFIG_KEXEC 197 machine_ops.crash_shutdown = kvm_crash_shutdown; 198 #endif 199 kvm_get_preset_lpj(); 200 clocksource_register(&kvm_clock); 201 pv_info.paravirt_enabled = 1; 202 pv_info.name = "KVM"; 203 } 204 } |