gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/qemu_amd64.go (about) 1 // Copyright (c) 2018 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers 7 8 import ( 9 "time" 10 11 "github.com/kata-containers/runtime/virtcontainers/types" 12 13 govmmQemu "github.com/intel/govmm/qemu" 14 ) 15 16 type qemuAmd64 struct { 17 // inherit from qemuArchBase, overwrite methods if needed 18 qemuArchBase 19 20 vmFactory bool 21 } 22 23 const ( 24 defaultQemuPath = "/usr/bin/qemu-system-x86_64" 25 26 defaultQemuMachineType = QemuPC 27 28 defaultQemuMachineOptions = "accel=kvm,kernel_irqchip" 29 30 qmpMigrationWaitTimeout = 5 * time.Second 31 ) 32 33 var qemuPaths = map[string]string{ 34 QemuPCLite: "/usr/bin/qemu-lite-system-x86_64", 35 QemuPC: defaultQemuPath, 36 QemuQ35: defaultQemuPath, 37 QemuMicrovm: defaultQemuPath, 38 } 39 40 var kernelParams = []Param{ 41 {"tsc", "reliable"}, 42 {"no_timer_check", ""}, 43 {"rcupdate.rcu_expedited", "1"}, 44 {"i8042.direct", "1"}, 45 {"i8042.dumbkbd", "1"}, 46 {"i8042.nopnp", "1"}, 47 {"i8042.noaux", "1"}, 48 {"noreplace-smp", ""}, 49 {"reboot", "k"}, 50 {"console", "hvc0"}, 51 {"console", "hvc1"}, 52 {"iommu", "off"}, 53 {"cryptomgr.notests", ""}, 54 {"net.ifnames", "0"}, 55 {"pci", "lastbus=0"}, 56 } 57 58 var supportedQemuMachines = []govmmQemu.Machine{ 59 { 60 Type: QemuPCLite, 61 Options: defaultQemuMachineOptions, 62 }, 63 { 64 Type: QemuPC, 65 Options: defaultQemuMachineOptions, 66 }, 67 { 68 Type: QemuQ35, 69 Options: defaultQemuMachineOptions, 70 }, 71 { 72 Type: QemuVirt, 73 Options: defaultQemuMachineOptions, 74 }, 75 { 76 Type: QemuMicrovm, 77 Options: defaultQemuMachineOptions, 78 }, 79 } 80 81 // MaxQemuVCPUs returns the maximum number of vCPUs supported 82 func MaxQemuVCPUs() uint32 { 83 return uint32(240) 84 } 85 86 func newQemuArch(config HypervisorConfig) qemuArch { 87 machineType := config.HypervisorMachineType 88 if machineType == "" { 89 machineType = defaultQemuMachineType 90 } 91 92 factory := false 93 if config.BootToBeTemplate || config.BootFromTemplate { 94 factory = true 95 } 96 97 q := &qemuAmd64{ 98 qemuArchBase: qemuArchBase{ 99 machineType: machineType, 100 memoryOffset: config.MemOffset, 101 qemuPaths: qemuPaths, 102 supportedQemuMachines: supportedQemuMachines, 103 kernelParamsNonDebug: kernelParamsNonDebug, 104 kernelParamsDebug: kernelParamsDebug, 105 kernelParams: kernelParams, 106 disableNvdimm: config.DisableImageNvdimm, 107 dax: true, 108 }, 109 vmFactory: factory, 110 } 111 112 q.handleImagePath(config) 113 114 return q 115 } 116 117 func (q *qemuAmd64) capabilities() types.Capabilities { 118 var caps types.Capabilities 119 120 if q.machineType == QemuPC || 121 q.machineType == QemuQ35 || 122 q.machineType == QemuVirt { 123 caps.SetBlockDeviceHotplugSupport() 124 } 125 126 caps.SetMultiQueueSupport() 127 caps.SetFsSharingSupport() 128 129 return caps 130 } 131 132 func (q *qemuAmd64) bridges(number uint32) { 133 q.Bridges = genericBridges(number, q.machineType) 134 } 135 136 func (q *qemuAmd64) cpuModel() string { 137 cpuModel := defaultCPUModel 138 139 // VMX is not migratable yet. 140 // issue: https://github.com/kata-containers/runtime/issues/1750 141 if q.vmFactory { 142 virtLog.WithField("subsystem", "qemuAmd64").Warn("VMX is not migratable yet: turning it off") 143 cpuModel += ",vmx=off" 144 } 145 146 return cpuModel 147 } 148 149 func (q *qemuAmd64) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory { 150 return genericMemoryTopology(memoryMb, hostMemoryMb, slots, q.memoryOffset) 151 } 152 153 // Is Memory Hotplug supported by this architecture/machine type combination? 154 func (q *qemuAmd64) supportGuestMemoryHotplug() bool { 155 // true for all amd64 machine types except for microvm. 156 return q.machineType != govmmQemu.MachineTypeMicrovm 157 } 158 159 func (q *qemuAmd64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) { 160 if !q.disableNvdimm { 161 return q.appendNvdimmImage(devices, path) 162 } 163 return q.appendBlockImage(devices, path) 164 } 165 166 // appendBridges appends to devices the given bridges 167 func (q *qemuAmd64) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device { 168 return genericAppendBridges(devices, q.Bridges, q.machineType) 169 }