kvm: x86: fix reversed timespec values in PV wall clock
Subsystems (4)
PATCH 1/1 kvm: x86: fix reversed timespec values in PV wall clock
commit 8171cd68806b ("KVM: x86: use raw clock values consistently") causes KVM to accidentally write seconds to the nanoseconds field (and vice versa) in the KVM wall clock. Fix it by reversing this accidental switch. Modulo the written nanoseconds value by NSEC_PER_SEC to correct for the amount of time represented as seconds.
---
Parent commit: c34b26b98cac ("KVM: MIPS: clean up redundant 'kvm_run' parameters")
arch/x86/kvm/x86.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +3 -2
@@ -1809,8 +1809,9 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)*/ wall_nsec =ktime_get_real_ns () -get_kvmclock_ns (kvm); - wc.nsec =do_div (wall_nsec,1000000000 ); - wc.sec = (u32 )wall_nsec;/* overflow in 2106 guest time */ +/* overflow in 2106 guest time */ + wc.sec = (u32 )do_div (wall_nsec,NSEC_PER_SEC ); + wc.nsec = wall_nsec %NSEC_PER_SEC ; wc.version = version;kvm_write_guest (kvm, wall_clock, &wc,sizeof (wc));
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
Quoted 35 lines · Oliver Upton
commit
8171cd68806b("KVM: x86: use raw clock values consistently") causes KVM to accidentally write seconds to the nanoseconds field (and vice versa) in the KVM wall clock. Fix it by reversing this accidental switch. Modulo the written nanoseconds value byNSEC_PER_SECto correct for the amount of time represented as seconds.Fixes 8171cd68806b ("KVM: x86: use raw clock values consistently")Reviewed-by Jim Mattson <[email protected]>Reviewed-by Peter Shier <[email protected]>Signed-off-by Oliver Upton <[email protected]>---
Parent commit:c34b26b98cac("KVM: MIPS: clean up redundant 'kvm_run' parameters")arch/x86/kvm/x86.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/x86.c +3
-3@@ -1809,8 +1809,9 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)*/ wall_nsec =ktime_get_real_ns () -get_kvmclock_ns (kvm); - wc.nsec =do_div (wall_nsec,1000000000 ); - wc.sec = (u32 )wall_nsec;/* overflow in 2106 guest time */ +/* overflow in 2106 guest time */ + wc.sec = (u32 )do_div (wall_nsec,NSEC_PER_SEC ); + wc.nsec = wall_nsec %NSEC_PER_SEC ; wc.version = version;kvm_write_guest (kvm, wall_clock, &wc,sizeof (wc)); --
Quoted 2 lines
2.28.0.rc0.142.g3c755180ce-goog
Disregard, I crossed wires in my reading of do_div().