https://bugzilla.kernel.org/show_bug.cgi?id=195207 Bug ID: 195207 Summary: Kvmclock: Time warp when hotplug vcpu. Product: Virtualization Version: unspecified Kernel Version: ALL Hardware: All OS: Linux Tree: Mainline Status: NEW Severity: normal Priority: P1 Component: kvm Assignee: virtualization_kvm@xxxxxxxxxxxxxxxxxxxx Reporter: changlimin@xxxxxxx Regression: No 1. Both KVM and VM will use kvmclock asap, usually the use_master_clock is true, so all vcpus use the same base tsc and ns to calculate current ns. 2. When hotplug a vcpu to a VM, the use_master_clock will change to false, also KVM updates base tsc and ns to all vcpus periodically. 3. KVM uses clocksource_tsc to get current ns, while VM uses kvm_clock to get current ns. For the same delta_tsc, they will get different result. 4. After run for more than 10 hours on a 2.4Ghz host, a redhat 6.6 VM will panic when been hotpluged a vcpu. The reason is the time warp in VM timekeeping_get_ns cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; // cycle_now is less than clock->cycle_last 5. Redhat 6.7 doesn't have this issue when CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE=y #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask) { cycle_t ret = (now - last) & mask; return (s64) ret > 0 ? ret : 0; } #else static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask) { return (now - last) & mask; } #endif 6. It's better to fix it in KVM, when change base tsc and ns in kvmclock, also calculate ns using kvm_clock arithmetic, be sure no time warp. -- You are receiving this mail because: You are watching the assignee of the bug.