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)
Thu, Nov 21, 11:16 AM
Unknown Object (File)
Oct 5 2024, 6:10 AM
Unknown Object (File)
Sep 29 2024, 1:00 PM
Unknown Object (File)
Sep 27 2024, 11:19 PM
Unknown Object (File)
Sep 23 2024, 2:52 AM
Unknown Object (File)
Sep 20 2024, 1:53 PM
Unknown Object (File)
Sep 20 2024, 1:53 PM
Unknown Object (File)
Sep 20 2024, 1:52 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.