fix(minvmd): sync time for guests on MacOS - #961
Conversation
📝 WalkthroughWalkthroughAdds guest time synchronization over an AF_VSOCK datagram listener, conditionally starts it from minimald, enables required ChangesGuest timekeeping
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant LibkrunTimesyncWorker
participant MinimaldListener
participant GuestClock
LibkrunTimesyncWorker->>MinimaldListener: Send host nanoseconds over vsock
MinimaldListener->>GuestClock: Read current CLOCK_REALTIME
MinimaldListener->>GuestClock: Step clock when drift exceeds threshold
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
msample
left a comment
There was a problem hiding this comment.
Nice. Where did the 80ms threshold come from?
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/minimald/src/guest.rs`:
- Around line 723-725: Update the ready.try_io receive logic in the guest
time-update path to use recvfrom instead of recv, retaining the peer address
returned by the kernel. Reject datagrams whose reported AF_VSOCK peer CID is not
VMADDR_CID_HOST before decoding the 8-byte payload, and only process
authenticated host packets.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a2652a37-90e9-4447-a1be-cd1f176c0d3a
📒 Files selected for processing (3)
Cargo.tomlcrates/minimald/src/guest.rscrates/minimald/src/main.rs
I pulled it out of the aether, basic logic was we needed to make it long enough that the delay is unlikely to be caused by vsock or scheduling latency, and 80ms is a solid 6.5 typical timeslices. |
KVM has a paravirt clock that keeps everything in check, so no issue on Linux hosts. For MacOS hosts, libkrun has its own solution but the guest side only runs if you use
libkrunfw/ their init, which we dont.So we do the same thing: listen on their magic vsock timekeeping port
123when we are an arch that could be macOS, and update the guest clock when we get a periodic message or the time has drifted due to system power states.Summary by CodeRabbit
New Features
Bug Fixes
Note
Sync guest CLOCK_REALTIME from host time updates over vsock in minimald
run_timekeep_listenerin guest.rs that opens an AF_VSOCK datagram socket and receives 8-byte little-endian host nanosecond timestamps on the configured port.CLOCK_REALTIMEviaclock_settimewhen drift exceeds 80ms; skips malformed packets and logs a one-time warning ifCAP_SYS_TIMEis missing.--timekeep-listener-portis set.clock_settimecauses a discrete clock step (not a slew), which may affect time-sensitive applications running in the guest.Macroscope summarized a27200f.