[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 11/30] KVM: x86: Add WARN and restructure get_kvmclock()



From: David Woodhouse <dwmw@xxxxxxxxxxxx>

Add the same WARN_ON_ONCE for unexpected kvm_get_walltime_and_clockread()
failure as in kvm_get_wall_clock_epoch().

Move get/put_cpu inside the use_master_clock branch since they are only
needed there (for RDTSC and get_cpu_tsc_khz() to be on the same CPU).

Also simplify the use_master_clock condition: the open-coded
CONSTANT_TSC || cpu_tsc_khz check is unnecessary since use_master_clock
can only be true when the TSC is usable.

Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 arch/x86/kvm/x86.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6f660c3210ee..9b395c00ccf2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3209,21 +3209,27 @@ static void get_kvmclock(struct kvm *kvm, struct 
kvm_clock_data *data)
        do {
                seq = read_seqcount_begin(&ka->pvclock_sc);
 
-               /* both __this_cpu_read() and rdtsc() should be on the same cpu 
*/
-               get_cpu();
-
                data->flags = 0;
-               if (ka->use_master_clock &&
-                   (static_cpu_has(X86_FEATURE_CONSTANT_TSC) || 
__this_cpu_read(cpu_tsc_khz))) {
+               if (ka->use_master_clock) {
 #ifdef CONFIG_X86_64
                        struct timespec64 ts;
+#endif
+                       /*
+                        * The RDTSC and get_cpu_tsc_khz() must happen on
+                        * the same CPU.
+                        */
+                       get_cpu();
 
+#ifdef CONFIG_X86_64
                        if (kvm_get_walltime_and_clockread(&ts, 
&data->host_tsc)) {
                                data->realtime = ts.tv_nsec + NSEC_PER_SEC * 
ts.tv_sec;
                                data->flags |= KVM_CLOCK_REALTIME | 
KVM_CLOCK_HOST_TSC;
-                       } else
-#endif
+                       } else if 
(WARN_ON_ONCE(!read_seqcount_retry(&ka->pvclock_sc, seq))) {
+                               data->host_tsc = rdtsc();
+                       }
+#else
                        data->host_tsc = rdtsc();
+#endif
 
                        data->flags |= KVM_CLOCK_TSC_STABLE;
                        hv_clock.tsc_timestamp = ka->master_cycle_now;
@@ -3232,11 +3238,11 @@ static void get_kvmclock(struct kvm *kvm, struct 
kvm_clock_data *data)
                                           &hv_clock.tsc_shift,
                                           &hv_clock.tsc_to_system_mul);
                        data->clock = __pvclock_read_cycles(&hv_clock, 
data->host_tsc);
+
+                       put_cpu();
                } else {
                        data->clock = get_kvmclock_base_ns() + 
ka->kvmclock_offset;
                }
-
-               put_cpu();
        } while (read_seqcount_retry(&ka->pvclock_sc, seq));
 }
 
-- 
2.51.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.