Page MenuHomeFreeBSD

Hide host CPUID 0x15 TSC/Crystal ratio/freq info from guest.
ClosedPublic

Authored by grehan on May 14 2020, 5:17 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 8, 1:51 AM
Unknown Object (File)
Feb 6 2024, 8:18 AM
Unknown Object (File)
Feb 2 2024, 5:47 PM
Unknown Object (File)
Jan 22 2024, 1:08 PM
Unknown Object (File)
Dec 23 2023, 8:16 AM
Unknown Object (File)
Dec 20 2023, 7:11 AM
Unknown Object (File)
Dec 14 2023, 11:26 PM
Unknown Object (File)
Nov 5 2023, 7:14 PM

Details

Summary

In recent Linux (5.3+) and OpenBSD (6.6+) kernels, and with hosts that
support CPUID 0x15, the local APIC frequency is determined directly
from the reported crystal clock to avoid calibration against the 8254
timer.

However, the local APIC frequency implemented by bhyve is 128MHz, where
most h/w systems report frequencies around 25MHz. This shows up on
OpenBSD guests as repeated keystrokes on the emulated PS2 keyboard
when using VNC, since the kernel's timers are now much shorter.

Fix by reporting all-zeroes for CPUID 0x15. This allows guests to fall
back to using the 8254 to calibrate the local APIC frequency.

Future work could be to compute values returned for 0x15 that would
match the host TSC and bhyve local APIC frequency, though all dependencies
on this would need to be examined (for example, Linux will start using
0x16 for some hosts).

Reported (and tested) by: Jason Tubnor.

Test Plan

Verify OpenBSD guests 6.6+ report a local APIC frequency close to 128MHz,
instead of 24MHz.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

grehan retitled this revision from Hide host CPUID 0x15 TSC/Crystal ration/freq info from guest. to Hide host CPUID 0x15 TSC/Crystal ratio/freq info from guest..May 14 2020, 5:25 AM

Confirmed working ok in 11.3-RELEASE+patches with OpenBSD 6.6/6.7-current, Windows Server 2016 and Ubuntu 20.04 in single socket or SMP configurations.

Testing still on-going (reverting to earlier revision) in -HEAD after issues found when launching a Windows or Ubuntu guest with more than 1 vCPU. OpenBSD working OK.

Reverting to 13-HEAD (360647) and applying this patch, OpenBSD UEFI console works as per bare metal and the same as the 11.3 test above. Additional testing of other SMP guests such as Windows Server 2016 and Ubuntu 20.04/18.04 work and perform as intended.

This fixes bug 246321 as described in: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=246321

FreeBSD 13.0-CURRENT #3 r360647: Thu May 14 16:03:38 AEST 2020 root@myhost:/usr/obj/usr/src/amd64.amd64/sys/GENERIC

jhb added a subscriber: jhb.

Nice sleuthing

This revision is now accepted and ready to land.May 14 2020, 4:27 PM

Ideally we can get this committed and MFC'd, with a goal of including it in 11.4.