Page MenuHomeFreeBSD

vmm: Consolidate vm and vcpu definitions
ClosedPublic

Authored by markj on Nov 4 2025, 4:40 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 16, 4:48 PM
Unknown Object (File)
Fri, Apr 10, 1:42 PM
Unknown Object (File)
Tue, Apr 7, 9:42 PM
Unknown Object (File)
Sat, Apr 4, 12:34 PM
Unknown Object (File)
Sat, Apr 4, 6:40 AM
Unknown Object (File)
Mar 27 2026, 4:52 PM
Unknown Object (File)
Mar 21 2026, 12:02 AM
Unknown Object (File)
Mar 18 2026, 12:41 AM

Details

Summary

There is quite a lot of duplication of code between amd64, arm64 and
riscv with respect to VM and vCPU state management. This is a bit
tricky to resolve since struct vm and struct vcpu are private to vmm.c
and both structures contain a mix of machine-dependent and
machine-independent fields.

To allow deduplication without also introducing a lot of churn, follow
the approach of struct pcpu and 1) lift the definitions of those
structures into a new header, sys/dev/vmm/vmm_vm.h, and 2) define
machine-dependent macros, VMM_VM_MD_FIELDS and VMM_VCPU_MD_FIELDS which
lay out the machine-dependent fields.

One disadvantage of this approach is that the two structures are now
exposed to other compilation units, but I think this is not a major
problem.

No functional change intended. A follow-up change will move a good deal
of machine/vmm/vmm.c into sys/dev/vmm/vmm_vm.c.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Nov 4 2025, 4:40 PM

Does anyone have feedback on this patch or the others in the series? If there is no objection I'd like to land them.

I tried a similar "way/hack" for LinuxKPI USB code. I didn't particularly like it there but here it seems way more clean.

The code is not my area of expertise but I scrolled through the 3 changes of the stack and they seem reasonable.
As I said before, if Phabricator had a "Ship it" in addition to "Accept Revision" in order to say "I have not reviewed this but think you should go ahead" I would press that.

This revision was not accepted when it landed; it landed in state Needs Review.Jan 8 2026, 9:58 PM
This revision was automatically updated to reflect the committed changes.