Skip to content

qemu: support nestedVirtualization with HVF (QEMU 11.1 or later) - #5443

Open
sharanrajt wants to merge 1 commit into
lima-vm:masterfrom
sharanrajt:nested-virt-qemu
Open

qemu: support nestedVirtualization with HVF (QEMU 11.1 or later)#5443
sharanrajt wants to merge 1 commit into
lima-vm:masterfrom
sharanrajt:nested-virt-qemu

Conversation

@sharanrajt

Copy link
Copy Markdown
Contributor

What This PR Changes

QEMU 11.1 added nested virtualization support to the HVF accelerator for the aarch64 virt machine (https://wiki.qemu.org/ChangeLog/11.1).

This PR adds support for nested virtualization in the QEMU driver:

  • Passes virtualization=on to the virt machine (-machine virt,...,virtualization=on) for aarch64 and armv7l when nestedVirtualization: true.
  • Enforces QEMU 11.1.0 or later and macOS 15 or later when using the hvf accelerator (since QEMU relies on macOS 15's hv_vm_config_set_el2_enabled).
  • Emits a warning and ignores nestedVirtualization for architectures other than aarch64 and armv7l.
  • Updates templates/default.yaml comments to document vmType: qemu support on Apple M3+ / macOS 15+.

Linked Issue (Required in most cases)

Closes #5419

How I Tested This

  • Manual Testing: Tested on Apple M4 / macOS 26.5 with QEMU 11.1.0: verified that the guest kernel initializes KVM in nVHE mode and a nested KVM VM boots EDK2 to the UEFI shell.
  • Unit Tests: Added TestValidateConfigNestedVirtualization to pkg/driver/qemu/qemu_test.go and ran go test -v ./pkg/driver/qemu/....
  • Build Verification: Built successfully with make minimal and verified go test ./....

AI Usage

Assisted-by: Antigravity

Comment thread templates/default.yaml Outdated
Comment thread pkg/driver/qemu/qemu.go
case limatype.ARMV7L:
machine := "virt,accel=" + accel
if y.NestedVirtualization != nil && *y.NestedVirtualization {
machine += ",virtualization=on"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test this configuration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test it. I added it because the virt machine accepts virtualization=on for 32-bit too. But armv7l guests aretcg-only in Lima and Linux dropped kvm on 32-bit ARM hosts in 5.7, so a guest couldn't use it anyway. I'll remove the armv7l case and keep this PR to aarch64.

}
}

if cfg.NestedVirtualization != nil && *cfg.NestedVirtualization {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we support Linux hosts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For aarch64 the same code path applies on Linux/KVM, the macOS version check is darwin-only, and virtualization=on works with KVM given QEMU ≥ 10.1 and a ≥ 6.16 host kernel booted with kvm-arm.mode=nested (FEAT_NV hardware); otherwise QEMU fails with a clear "host kernel KVM does not support providing Virtualization extensions" error. I don't have such hardware, so this part is untested.
For x86_64/KVM, nested virt is a host-side setting exposed through -cpu host, which Lima already uses. I'll change the x86_64 path to check /sys/module/kvm_{intel,amd}/parameters/nested and error only when it's disabled, instead of warning "unsupported". I'll also document the Linux requirements in default.yaml.

@AkihiroSuda AkihiroSuda added this to the v2.3.0 milestone Aug 26, 2026
QEMU 11.1 added nested virtualization support to the HVF accelerator
for the aarch64 `virt` machine (https://wiki.qemu.org/ChangeLog/11.1).

Enable it by passing `virtualization=on` to the `virt` machine when
`nestedVirtualization: true`. With HVF, require QEMU 11.1.0 or later and
macOS 15 or later (QEMU relies on `hv_vm_config_set_el2_enabled`).
The field is ignored with a warning for architectures other than
aarch64 and armv7l.

Tested on Apple M4 / macOS 26.5 with QEMU 11.1.0: the guest kernel
initializes KVM in nVHE mode and a nested KVM VM boots EDK2 to the
UEFI shell.

Fix lima-vm#5419

Signed-off-by: Sharan Raj T <sharanrajtm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nestedVirtualization: support QEMU

2 participants