diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index 625146a415..405bfc6d01 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/BurntSushi/toml" + govmmQemu "github.com/intel/govmm/qemu" vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental" @@ -626,6 +627,14 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { kernelParams := h.kernelParams() machineType := h.machineType() + // The "microvm" machine type doesn't support NVDIMM so override the + // config setting to explicitly disable it (i.e. don't require the + // user to add 'disable_image_nvdimm = true' in the .toml file). + if machineType == govmmQemu.MachineTypeMicrovm && !h.DisableImageNvdimm { + h.DisableImageNvdimm = true + kataUtilsLogger.Info("Setting 'disable_image_nvdimm = true' as microvm does not support NVDIMM") + } + blockDriver, err := h.blockDeviceDriver() if err != nil { return vc.HypervisorConfig{}, err diff --git a/src/runtime/virtcontainers/qemu_amd64.go b/src/runtime/virtcontainers/qemu_amd64.go index b8e49683c4..1f559d9e91 100644 --- a/src/runtime/virtcontainers/qemu_amd64.go +++ b/src/runtime/virtcontainers/qemu_amd64.go @@ -32,9 +32,10 @@ const ( ) var qemuPaths = map[string]string{ - QemuPCLite: "/usr/bin/qemu-lite-system-x86_64", - QemuPC: defaultQemuPath, - QemuQ35: defaultQemuPath, + QemuPCLite: "/usr/bin/qemu-lite-system-x86_64", + QemuPC: defaultQemuPath, + QemuQ35: defaultQemuPath, + QemuMicrovm: defaultQemuPath, } var kernelParams = []Param{ @@ -71,6 +72,10 @@ var supportedQemuMachines = []govmmQemu.Machine{ Type: QemuVirt, Options: defaultQemuMachineOptions, }, + { + Type: QemuMicrovm, + Options: defaultQemuMachineOptions, + }, } // MaxQemuVCPUs returns the maximum number of vCPUs supported @@ -115,14 +120,14 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) { q := &qemuAmd64{ qemuArchBase: qemuArchBase{ - qemuMachine: *mp, - qemuExePath: qemuPaths[machineType], - memoryOffset: config.MemOffset, - kernelParamsNonDebug: kernelParamsNonDebug, - kernelParamsDebug: kernelParamsDebug, - kernelParams: kernelParams, - disableNvdimm: config.DisableImageNvdimm, - dax: true, + qemuMachine: *mp, + qemuExePath: qemuPaths[machineType], + memoryOffset: config.MemOffset, + kernelParamsNonDebug: kernelParamsNonDebug, + kernelParamsDebug: kernelParamsDebug, + kernelParams: kernelParams, + disableNvdimm: config.DisableImageNvdimm, + dax: true, }, vmFactory: factory, } @@ -171,6 +176,12 @@ func (q *qemuAmd64) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) g return genericMemoryTopology(memoryMb, hostMemoryMb, slots, q.memoryOffset) } +// Is Memory Hotplug supported by this architecture/machine type combination? +func (q *qemuAmd64) supportGuestMemoryHotplug() bool { + // true for all amd64 machine types except for microvm. + return q.qemuMachine.Type != govmmQemu.MachineTypeMicrovm +} + func (q *qemuAmd64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) { if !q.disableNvdimm { return q.appendNvdimmImage(devices, path) diff --git a/src/runtime/virtcontainers/qemu_amd64_test.go b/src/runtime/virtcontainers/qemu_amd64_test.go index b2d0b0cfc3..f5ab24e7f9 100644 --- a/src/runtime/virtcontainers/qemu_amd64_test.go +++ b/src/runtime/virtcontainers/qemu_amd64_test.go @@ -47,6 +47,10 @@ func TestQemuAmd64Capabilities(t *testing.T) { amd64 = newTestQemu(assert, QemuQ35) caps = amd64.capabilities() assert.True(caps.IsBlockDeviceHotplugSupported()) + + amd64 = newTestQemu(assert, QemuMicrovm) + caps = amd64.capabilities() + assert.False(caps.IsBlockDeviceHotplugSupported()) } func TestQemuAmd64Bridges(t *testing.T) { @@ -65,6 +69,11 @@ func TestQemuAmd64Bridges(t *testing.T) { assert.NotNil(b.Devices) } + amd64 = newTestQemu(assert, QemuMicrovm) + amd64.bridges(uint32(len)) + bridges = amd64.getBridges() + assert.Nil(bridges) + amd64 = newTestQemu(assert, QemuQ35) amd64.bridges(uint32(len)) bridges = amd64.getBridges() @@ -256,3 +265,18 @@ func TestQemuAmd64Iommu(t *testing.T) { m := qemu.machine() assert.Contains(m.Options, "kernel_irqchip=split") } + +func TestQemuAmd64Microvm(t *testing.T) { + assert := assert.New(t) + + cfg := qemuConfig(QemuMicrovm) + amd64, err := newQemuArch(cfg) + assert.NoError(err) + assert.False(cfg.DisableImageNvdimm) + + for _, m := range supportedQemuMachines { + assert.NotContains(m.Options, qemuNvdimmOption) + } + + assert.False(amd64.supportGuestMemoryHotplug()) +} diff --git a/src/runtime/virtcontainers/qemu_arch_base.go b/src/runtime/virtcontainers/qemu_arch_base.go index ba2ab10385..5ed1154ea5 100644 --- a/src/runtime/virtcontainers/qemu_arch_base.go +++ b/src/runtime/virtcontainers/qemu_arch_base.go @@ -177,6 +177,9 @@ const ( // QemuQ35 is the QEMU Q35 machine type for amd64 QemuQ35 = "q35" + // QemuMicrovm is the QEMU microvm machine type for amd64 + QemuMicrovm = "microvm" + // QemuVirt is the QEMU virt machine type for aarch64 or amd64 QemuVirt = "virt"