Commit 838815a7 authored by Glauber Costa's avatar Glauber Costa Committed by Avi Kivity

x86: KVM guest: Try using new kvm clock msrs

We now added a new set of clock-related msrs in replacement of the old
ones. In theory, we could just try to use them and get a return value
indicating they do not exist, due to our use of kvm_write_msr_save.

However, kvm clock registration happens very early, and if we ever
try to write to a non-existant MSR, we raise a lethal #GP, since our
idt handlers are not in place yet.

So this patch tests for a cpuid feature exported by the host to
decide which set of msrs are supported.
Signed-off-by: default avatarGlauber Costa <glommer@redhat.com>
Acked-by: default avatarZachary Amsden <zamsden@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent 84478c82
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#define KVM_SCALE 22 #define KVM_SCALE 22
static int kvmclock = 1; static int kvmclock = 1;
static int msr_kvm_system_time = MSR_KVM_SYSTEM_TIME;
static int msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK;
static int parse_no_kvmclock(char *arg) static int parse_no_kvmclock(char *arg)
{ {
...@@ -54,7 +56,8 @@ static unsigned long kvm_get_wallclock(void) ...@@ -54,7 +56,8 @@ static unsigned long kvm_get_wallclock(void)
low = (int)__pa_symbol(&wall_clock); low = (int)__pa_symbol(&wall_clock);
high = ((u64)__pa_symbol(&wall_clock) >> 32); high = ((u64)__pa_symbol(&wall_clock) >> 32);
native_write_msr(MSR_KVM_WALL_CLOCK, low, high);
native_write_msr(msr_kvm_wall_clock, low, high);
vcpu_time = &get_cpu_var(hv_clock); vcpu_time = &get_cpu_var(hv_clock);
pvclock_read_wallclock(&wall_clock, vcpu_time, &ts); pvclock_read_wallclock(&wall_clock, vcpu_time, &ts);
...@@ -130,7 +133,8 @@ static int kvm_register_clock(char *txt) ...@@ -130,7 +133,8 @@ static int kvm_register_clock(char *txt)
high = ((u64)__pa(&per_cpu(hv_clock, cpu)) >> 32); high = ((u64)__pa(&per_cpu(hv_clock, cpu)) >> 32);
printk(KERN_INFO "kvm-clock: cpu %d, msr %x:%x, %s\n", printk(KERN_INFO "kvm-clock: cpu %d, msr %x:%x, %s\n",
cpu, high, low, txt); cpu, high, low, txt);
return native_write_msr_safe(MSR_KVM_SYSTEM_TIME, low, high);
return native_write_msr_safe(msr_kvm_system_time, low, high);
} }
#ifdef CONFIG_X86_LOCAL_APIC #ifdef CONFIG_X86_LOCAL_APIC
...@@ -165,14 +169,14 @@ static void __init kvm_smp_prepare_boot_cpu(void) ...@@ -165,14 +169,14 @@ static void __init kvm_smp_prepare_boot_cpu(void)
#ifdef CONFIG_KEXEC #ifdef CONFIG_KEXEC
static void kvm_crash_shutdown(struct pt_regs *regs) static void kvm_crash_shutdown(struct pt_regs *regs)
{ {
native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0); native_write_msr(msr_kvm_system_time, 0, 0);
native_machine_crash_shutdown(regs); native_machine_crash_shutdown(regs);
} }
#endif #endif
static void kvm_shutdown(void) static void kvm_shutdown(void)
{ {
native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0); native_write_msr(msr_kvm_system_time, 0, 0);
native_machine_shutdown(); native_machine_shutdown();
} }
...@@ -181,7 +185,15 @@ void __init kvmclock_init(void) ...@@ -181,7 +185,15 @@ void __init kvmclock_init(void)
if (!kvm_para_available()) if (!kvm_para_available())
return; return;
if (kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)) { if (kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) {
msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW;
msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW;
} else if (!(kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)))
return;
printk(KERN_INFO "kvm-clock: Using msrs %x and %x",
msr_kvm_system_time, msr_kvm_wall_clock);
if (kvm_register_clock("boot clock")) if (kvm_register_clock("boot clock"))
return; return;
pv_time_ops.sched_clock = kvm_clock_read; pv_time_ops.sched_clock = kvm_clock_read;
...@@ -203,5 +215,4 @@ void __init kvmclock_init(void) ...@@ -203,5 +215,4 @@ void __init kvmclock_init(void)
clocksource_register(&kvm_clock); clocksource_register(&kvm_clock);
pv_info.paravirt_enabled = 1; pv_info.paravirt_enabled = 1;
pv_info.name = "KVM"; pv_info.name = "KVM";
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment