Page MenuHomeFreeBSD

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

Authored by grehan on May 14 2020, 5:17 AM.

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
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

grehan created this revision.May 14 2020, 5:17 AM
grehan requested review of this revision.May 14 2020, 5:17 AM
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.

grehan edited the summary of this revision. (Show Details)May 14 2020, 5:27 AM

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

emaste added a subscriber: emaste.May 14 2020, 2:05 PM
jhb accepted this revision.May 14 2020, 4:27 PM
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.

This revision was automatically updated to reflect the committed changes.