Page MenuHomeFreeBSD

vmm: Emulate CPUID leaf 1Fh for guests
AcceptedPublic

Authored by joneum on Mon, Aug 17, 6:52 AM.
Tags
None
Referenced Files
F167048179: D58885.diff
Tue, Aug 18, 7:42 PM
Unknown Object (File)
Mon, Aug 17, 1:26 PM
Unknown Object (File)
Mon, Aug 17, 1:25 PM
Unknown Object (File)
Mon, Aug 17, 8:31 AM
Unknown Object (File)
Mon, Aug 17, 8:31 AM

Details

Reviewers
markj
Group Reviewers
bhyve
Summary

On an Intel N150 host a guest started with sockets=1, cores=4,
threads=1 reports "1 package(s) x 2 core(s) x 2 hardware threads"
instead of four cores with one thread each, while the host itself
detects its topology correctly.

A FreeBSD guest picks the topology leaf in topo_probe_intel_0xb(),
sys/x86/x86/mp_x86.c, and since 6badb512a94d it prefers leaf 1Fh over
leaf 0Bh whenever cpu_high is 1Fh or higher. bhyve passes leaf 0
through unmodified, so the guest sees the maximum basic leaf of the
host, which is 1Fh or above on Alder Lake and newer, and takes that
path. x86_emulate_cpuid(), sys/amd64/vmm/x86.c, derives the topology
from vm_get_topology() for leaves 1, 4 and 0Bh, but has no case for
1Fh, so the request ends up in default_leaf and the host values are
returned verbatim. The guest therefore enumerates the topology of the
host: with an SMT shift of 1 in the host's leaf 1Fh and four vCPUs this
gives core_id_shift = 1 and pkg_id_shift = 2, which is exactly the
reported 2 cores x 2 threads. Hosts whose maximum basic leaf is below
1Fh are unaffected, as the request is clamped to cpu_high before the
switch statement.

Leaf 1Fh uses the same level encoding as leaf 0Bh for the SMT and the
core level, so handle both leaves in the same case. The module, tile
and die levels are not emulated and terminate the enumeration, exactly
as they already do for leaf 0Bh.

PR: 297475

Test Plan

Kernel builds on main (GENERIC, amd64).
The change only takes effect on hosts whose leaf 0 reports a maximum
basic leaf of 1Fh or higher. On older hosts the leaf is clamped to
cpu_high before the switch statement, so behaviour there is unchanged.
Not verified at runtime yet. On affected hardware, compare the line
"FreeBSD/SMP: N package(s) x N core(s) x N hardware threads" in the
guest dmesg against the topology passed to bhyve -c.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 75642
Build 72525: arc lint + arc unit