Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS guest time becomes out of sync #4644

Open
ghost opened this issue Nov 10, 2022 · 18 comments
Open

macOS guest time becomes out of sync #4644

ghost opened this issue Nov 10, 2022 · 18 comments
Labels
bug Something isn't working macOS macOS issues

Comments

@ghost
Copy link

ghost commented Nov 10, 2022

guest time can desync from the host os. this issue is valid for a few versions back.

  • UTM Version: 4.1.0
  • macOS Version: host 12.5, guest 13.1
  • Mac Chip (Intel, M1, ...): m1
@conath conath added the macOS macOS issues label Nov 13, 2022
@conath conath changed the title guest time is out of sync in case of macos 13.1 guest macOS guest time becomes out of sync Nov 13, 2022
@conath
Copy link
Contributor

conath commented Nov 13, 2022

Could you please add more information about the issue? Especially need the guest configuration file:

right-click the VM in UTM and choose "Show in Finder". Then right-click the selected file in Finder and choose "Show Package Contents". The config.plist file is now visible

How long after you turn on the VM does it take until the issue occurs? Are all of your macOS VMs affected or only a specific configuration? (please provide!)

@ghost
Copy link
Author

ghost commented Nov 13, 2022

config.plist.zip

I only have this VM. This happened to me a few times, and it seems to be fixing itself after a while. Definitely not an easy 1/1 repro, but it does happen and it was happening before 4.1.0.

@conath
Copy link
Contributor

conath commented Nov 13, 2022

Thanks. Config looks good to me. You could potentially test this further by turning off "Set date and time automatically" in the guest's System Settings. That would in theory prevent the guest time from fixing itself by using the internet time, and force it to rely on the time information it receives from the Apple virtualization backend.

@ghost
Copy link
Author

ghost commented Nov 14, 2022

Done. Monitoring the issue.

@ghost
Copy link
Author

ghost commented Nov 14, 2022

@conath since I wrote the above comment the time slipped 3 minutes today. So with the time sync set to off in the guest, it is continuously slipping.

@jtran19
Copy link

jtran19 commented Nov 14, 2022

Having the same issue here with macOS 13 host and guest. I've noticed the VM time slips when the host is suspended due to no activity (i.e. "falls asleep"). An easy way to force the issue is pausing the VM for a few minutes. When you resume, the time will be out of sync.

@conath conath added the bug Something isn't working label Nov 14, 2022
@osy
Copy link
Contributor

osy commented Nov 23, 2022

Seems like something we'll have to report to Apple: FB11815959

@krypu
Copy link

krypu commented Jan 16, 2023

Using latest release 4.1.5, it's also happening while actively using a MacOS guest VM.

@tenedor
Copy link

tenedor commented Nov 1, 2023

I regularly hit a similar issue, maybe the same issue. I'm a first-time UTM user as of a couple weeks ago on my new M2 laptop, using UTM 4.4.4 and MacOS Ventura 13.5.2. My guest VM's time constantly falls days behind when not in use despite the Date & Time settings being configured to set the time automatically from the Apple time server.

I can reset the clock to the exact time by opening Date & Time settings and toggling "Set time and date automatically" off and then back on. The time is correct for as long as I am actively using the VM, and then it falls behind again.

@antonkratz
Copy link

antonkratz commented Dec 26, 2023

I observe the same issue, has been ongoing for about a year for me, currently with this config.

  • UTM Version: Version 4.4.4 (92)
  • macOS Version: 14.2.1 (23C71)
  • Mac Chip: M2

Guest system is Ubuntu 23.04 (lunar).

@kenji21
Copy link

kenji21 commented Jun 19, 2024

Fixed for Qemu, no APIs from Apple for Virtualization.framework

@kenji21
Copy link

kenji21 commented Jun 21, 2024

Found AppleVirtualPlatformRTCPlugin in Console.app logs when switching on and off the syncing to time.apple.com in Date & Time settings :

Screenshot 36

@kenji21
Copy link

kenji21 commented Jul 18, 2024

I checked the binary /System//Library/PrivateFrameworks/CoreTime.framework/TimeSources/AppleVirtualPlatformRTCPlugin.bundle/Contents/MacOS/AppleVirtualPlatformRTCPlugin which only uses IOKit to get notified about the change

 r0 = IONotificationPortCreate(*(int32_t *)*_kIOMainPortDefault);
[...]
    r0 = IOServiceNameMatching("AppleVirtualPlatformRTC");
    r0 = IOServiceGetMatchingService(r20, r0);
[...]
r0 = IOServiceAddInterestNotification(r0, r1, "IOGeneralInterest", 0x34bc, r19, r19 + 0x18);
[...]

with the 0x34bc method:

int sub_34bc(int arg0, int arg1, int arg2, int arg3) {
[...]
    r0 = os_log_type_enabled(r20, 0x0);
    if (arg2 == 0xe0000230) {
            if (r0 != 0x0) {
                    _os_log_impl(0x0, r20, 0x0, "Avp rtc state notification received", &var_30, 0x2);
            }
            if (r8 != 0x0) {
                    if (r8 == 0x1) {
                            r20 = *(r19 + 0x10);
                            if (os_log_type_enabled(r20, 0x0) != 0x0) {
                                    _os_log_impl(0x0, r20, 0x0, "Reset time", &var_40, 0x2);
                            }
                            sub_38c0();
                    }
            }
            else {
                    r20 = *(r19 + 0x10);
                    if (os_log_type_enabled(r20, 0x0) != 0x0) {
                            _os_log_impl(0x0, r20, 0x0, "Resync Time", &var_50, 0x2);
                    }
                    sub_38e0();
            }
    }
    else {
            if (r0 != 0x0) {
                    _os_log_impl(0x0, r20, 0x0, "Avp rtc unknown notification received", &var_60, 0x2);
            }
    }
    r0 = [r19 release];
    return r0;
}

@kenji21
Copy link

kenji21 commented Jul 18, 2024

No clue about how the host macOS send such an IOKit notification to the guest macOS

@antonkratz
Copy link

I do not know if my comment helps or not, but I noticed that the time drift certainly appears with Ubuntu guests (many versions tested) but does not seem to appear if the guest is openSUSE LEAP 15.5

@kenji21
Copy link

kenji21 commented Jul 24, 2024

maybe you are running the openSUSE guest with QEMU (which time sync is supported)

@kenji21
Copy link

kenji21 commented Jul 24, 2024

Finally found a way to solve this, a macOS LaunchAgent with the swift code like the fix for QEMU, but to make the VM aware of the drift => a Wake On LAN magic packet (reading the UTM config.plist)
A launchd service on the VM listens to the WOL packet and run systemctl restart networking & systemctl restart ntp
My VM has network in bridge mode, so I lose network connectivity when closing my laptop, moving home, opening it. Hence the WakeOnLAN packet ^^

@kenji21
Copy link

kenji21 commented Jul 24, 2024

Microsoft solves this issue on their Hypervisor with a RTC device /dev/ptp_hyperv, and configuring chrony to use it, see https://learn.microsoft.com/en-us/azure/virtual-machines/linux/time-sync#chrony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macOS macOS issues
Projects
None yet
Development

No branches or pull requests

7 participants