]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/arm/imx8mp-evk: Fix guest time in KVM mode
authorBernhard Beschow <shentey@gmail.com>
Sat, 1 Nov 2025 12:01:30 +0000 (13:01 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 3 Nov 2025 10:48:17 +0000 (10:48 +0000)
The imx8mp DTB hardcodes the clock frequency of the system counter to 8MHz.
In KVM mode, the host CPU is used whose system counter runs at a different
frequency, resulting in the guest clock running slower or faster. Fix this
by not hardcoding the clock frequency which makes the Linux driver read
the real clock frequency from the register.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
Message-id: 20251101120130.236721-3-shentey@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/arm/imx8mp-evk.c

index 3ddcf1af5ace6d4d01abe1bcd5e06ff051851566..44e060196700a2c624764627f21d3f294c7a1d6c 100644 (file)
@@ -44,6 +44,15 @@ static void imx8mp_evk_modify_dtb(const struct arm_boot_info *info, void *fdt)
         fdt_nop_property(fdt, offset, "cpu-idle-states");
         offset = fdt_node_offset_by_compatible(fdt, offset, "arm,cortex-a53");
     }
+
+    if (kvm_enabled()) {
+        /* Use system counter frequency from host CPU to fix time in guest */
+        offset = fdt_node_offset_by_compatible(fdt, -1, "arm,armv8-timer");
+        while (offset >= 0) {
+            fdt_nop_property(fdt, offset, "clock-frequency");
+            offset = fdt_node_offset_by_compatible(fdt, offset, "arm,armv8-timer");
+        }
+    }
 }
 
 static void imx8mp_evk_init(MachineState *machine)