mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 09:26:52 +00:00 
			
		
		
		
	virtcontainers: x86: Support microvm machine type
[ port from runtime commit 6aff077901021d9a0075c446dfe281b2487e1487 ] With the addition of support to govmm for multiple transports (intel/govmm#111) and microvm (intel/govmm#121) we can now enable support for the 'microvm' machine type in kata-runtime. Signed-off-by: Liam Merwick <liam.merwick@oracle.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
		| @@ -14,6 +14,7 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"github.com/BurntSushi/toml" | 	"github.com/BurntSushi/toml" | ||||||
|  | 	govmmQemu "github.com/intel/govmm/qemu" | ||||||
| 	vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" | 	vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" | ||||||
| 	"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" | 	"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" | ||||||
| 	exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental" | 	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() | 	kernelParams := h.kernelParams() | ||||||
| 	machineType := h.machineType() | 	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() | 	blockDriver, err := h.blockDeviceDriver() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return vc.HypervisorConfig{}, err | 		return vc.HypervisorConfig{}, err | ||||||
|   | |||||||
| @@ -35,6 +35,7 @@ var qemuPaths = map[string]string{ | |||||||
| 	QemuPCLite:  "/usr/bin/qemu-lite-system-x86_64", | 	QemuPCLite:  "/usr/bin/qemu-lite-system-x86_64", | ||||||
| 	QemuPC:      defaultQemuPath, | 	QemuPC:      defaultQemuPath, | ||||||
| 	QemuQ35:     defaultQemuPath, | 	QemuQ35:     defaultQemuPath, | ||||||
|  | 	QemuMicrovm: defaultQemuPath, | ||||||
| } | } | ||||||
|  |  | ||||||
| var kernelParams = []Param{ | var kernelParams = []Param{ | ||||||
| @@ -71,6 +72,10 @@ var supportedQemuMachines = []govmmQemu.Machine{ | |||||||
| 		Type:    QemuVirt, | 		Type:    QemuVirt, | ||||||
| 		Options: defaultQemuMachineOptions, | 		Options: defaultQemuMachineOptions, | ||||||
| 	}, | 	}, | ||||||
|  | 	{ | ||||||
|  | 		Type:    QemuMicrovm, | ||||||
|  | 		Options: defaultQemuMachineOptions, | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
| // MaxQemuVCPUs returns the maximum number of vCPUs supported | // MaxQemuVCPUs returns the maximum number of vCPUs supported | ||||||
| @@ -171,6 +176,12 @@ func (q *qemuAmd64) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) g | |||||||
| 	return genericMemoryTopology(memoryMb, hostMemoryMb, slots, q.memoryOffset) | 	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) { | func (q *qemuAmd64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) { | ||||||
| 	if !q.disableNvdimm { | 	if !q.disableNvdimm { | ||||||
| 		return q.appendNvdimmImage(devices, path) | 		return q.appendNvdimmImage(devices, path) | ||||||
|   | |||||||
| @@ -47,6 +47,10 @@ func TestQemuAmd64Capabilities(t *testing.T) { | |||||||
| 	amd64 = newTestQemu(assert, QemuQ35) | 	amd64 = newTestQemu(assert, QemuQ35) | ||||||
| 	caps = amd64.capabilities() | 	caps = amd64.capabilities() | ||||||
| 	assert.True(caps.IsBlockDeviceHotplugSupported()) | 	assert.True(caps.IsBlockDeviceHotplugSupported()) | ||||||
|  |  | ||||||
|  | 	amd64 = newTestQemu(assert, QemuMicrovm) | ||||||
|  | 	caps = amd64.capabilities() | ||||||
|  | 	assert.False(caps.IsBlockDeviceHotplugSupported()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestQemuAmd64Bridges(t *testing.T) { | func TestQemuAmd64Bridges(t *testing.T) { | ||||||
| @@ -65,6 +69,11 @@ func TestQemuAmd64Bridges(t *testing.T) { | |||||||
| 		assert.NotNil(b.Devices) | 		assert.NotNil(b.Devices) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	amd64 = newTestQemu(assert, QemuMicrovm) | ||||||
|  | 	amd64.bridges(uint32(len)) | ||||||
|  | 	bridges = amd64.getBridges() | ||||||
|  | 	assert.Nil(bridges) | ||||||
|  |  | ||||||
| 	amd64 = newTestQemu(assert, QemuQ35) | 	amd64 = newTestQemu(assert, QemuQ35) | ||||||
| 	amd64.bridges(uint32(len)) | 	amd64.bridges(uint32(len)) | ||||||
| 	bridges = amd64.getBridges() | 	bridges = amd64.getBridges() | ||||||
| @@ -256,3 +265,18 @@ func TestQemuAmd64Iommu(t *testing.T) { | |||||||
| 	m := qemu.machine() | 	m := qemu.machine() | ||||||
| 	assert.Contains(m.Options, "kernel_irqchip=split") | 	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()) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -177,6 +177,9 @@ const ( | |||||||
| 	// QemuQ35 is the QEMU Q35 machine type for amd64 | 	// QemuQ35 is the QEMU Q35 machine type for amd64 | ||||||
| 	QemuQ35 = "q35" | 	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 is the QEMU virt machine type for aarch64 or amd64 | ||||||
| 	QemuVirt = "virt" | 	QemuVirt = "virt" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user