qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bernhard Beschow <shentey@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Bernhard Beschow <shentey@gmail.com>
Subject: [PATCH v2 2/2] hw/arm/imx8mp-evk: Fix guest time in KVM mode
Date: Wed, 29 Oct 2025 15:23:11 +0100	[thread overview]
Message-ID: <20251029142311.2986-3-shentey@gmail.com> (raw)
In-Reply-To: <20251029142311.2986-1-shentey@gmail.com>

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.

Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 hw/arm/imx8mp-evk.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c
index 80036f8589..e26c62aee1 100644
--- a/hw/arm/imx8mp-evk.c
+++ b/hw/arm/imx8mp-evk.c
@@ -43,6 +43,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)
-- 
2.51.2



  parent reply	other threads:[~2025-10-29 14:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 14:23 [PATCH v2 0/2] KVM Support for imx8mp-evk Machine Bernhard Beschow
2025-10-29 14:23 ` [PATCH v2 1/2] hw/arm/imx8mp-evk: Add KVM support Bernhard Beschow
2025-10-29 14:23 ` Bernhard Beschow [this message]
2025-10-31 14:03   ` [PATCH v2 2/2] hw/arm/imx8mp-evk: Fix guest time in KVM mode Philippe Mathieu-Daudé
2025-10-31 11:16 ` [PATCH v2 0/2] KVM Support for imx8mp-evk Machine Bernhard Beschow
2025-10-31 16:57 ` Peter Maydell
2025-10-31 17:12   ` Peter Maydell
2025-10-31 18:18     ` Philippe Mathieu-Daudé
2025-10-31 18:30       ` Peter Maydell
2025-11-01 12:09         ` Bernhard Beschow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251029142311.2986-3-shentey@gmail.com \
    --to=shentey@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).