Re: pvclock time drifting backward

From: Ming Lin
Date: Wed Mar 26 2025 - 11:55:44 EST


On Tue, Mar 25, 2025 at 4:07 AM David Woodhouse <dwmw2@xxxxxxxxxxxxx> wrote:
>
> On Mon, 2025-03-24 at 15:54 -0700, Sean Christopherson wrote:
> >
> > David can confirm, but I'm pretty sure the drift you are observing is addressed
> > by David's series to fix a plethora of kvmclock warts.
> >
> > https://lore.kernel.org/all/20240522001817.619072-1-dwmw2@xxxxxxxxxxxxx
>
> Yes, that looks like exactly the problem my series is addressing. We
> shouldn't update the pvclock so often. And if/when we do, we shouldn't
> clamp it to some *other* clock which progresses at a different rate to
> the pvclock, because that causes steps in the pvclock.

I applied the patch series on top of 6.9 cleanly and tested it with my
debug tool patch.
But it seems the time drift still increased monotonically.

Would you help take a look if the tool patch makes sense?
https://github.com/minggr/linux/commit/5284a211b6bdc9f9041b669539558a6a858e88d0

The tool patch adds a KVM debugfs entry to trigger time calculations
and print the results.
See my first email for more detail.

Test Script:
#!/bin/bash

qemu_pid=$(pidof qemu-system-x86_64)

while [ 1 ] ; do
echo "====================================="
echo "Guest OS running time: $(ps -p $qemu_pid -o etime= | awk
'{print $1}')"
cat /sys/kernel/debug/kvm/*/pvclock
echo
sleep 10
done

Thanks,
Ming