Page MenuHomeFreeBSD

vmm: Consolidate vm and vcpu definitions
Needs ReviewPublic

Authored by markj on Nov 4 2025, 4:40 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 30, 1:39 PM
Unknown Object (File)
Fri, Nov 28, 2:14 PM
Unknown Object (File)
Wed, Nov 19, 7:21 PM
Unknown Object (File)
Mon, Nov 17, 4:26 PM
Unknown Object (File)
Sun, Nov 16, 5:00 PM
Unknown Object (File)
Nov 6 2025, 6:30 AM
Unknown Object (File)
Nov 6 2025, 6:30 AM
Unknown Object (File)
Nov 6 2025, 4:41 AM

Details

Reviewers
andrew
manu
Group Reviewers
bhyve
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 Skipped
Unit
Tests Skipped
Build Status
Buildable 68415
Build 65298: arc lint + arc unit

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.