mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-23 01:04:25 +01:00
qemu: add cpu_features option
[ port from runtime commit 0100af18a2afdd6dfcc95129ec6237ba4915b3e5 ] To control whether guest can enable/disable some CPU features. E.g. pmu=off, vmx=off. As discussed in the thread [1], the best approach is to let users specify them. How about adding a new option in the configuration file. Currently this patch only supports this option in qemu,no other vmm. [1] https://github.com/kata-containers/runtime/pull/2559#issuecomment-603998256 Signed-off-by: Jia He <justin.he@arm.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
@@ -93,6 +93,7 @@ type hypervisor struct {
|
||||
Image string `toml:"image"`
|
||||
Firmware string `toml:"firmware"`
|
||||
MachineAccelerators string `toml:"machine_accelerators"`
|
||||
CPUFeatures string `toml:"cpu_features"`
|
||||
KernelParams string `toml:"kernel_params"`
|
||||
MachineType string `toml:"machine_type"`
|
||||
BlockDeviceDriver string `toml:"block_device_driver"`
|
||||
@@ -244,11 +245,9 @@ func (h hypervisor) firmware() (string, error) {
|
||||
|
||||
func (h hypervisor) machineAccelerators() string {
|
||||
var machineAccelerators string
|
||||
accelerators := strings.Split(h.MachineAccelerators, ",")
|
||||
acceleratorsLen := len(accelerators)
|
||||
for i := 0; i < acceleratorsLen; i++ {
|
||||
if accelerators[i] != "" {
|
||||
machineAccelerators += strings.Trim(accelerators[i], "\r\t\n ") + ","
|
||||
for _, accelerator := range strings.Split(h.MachineAccelerators, ",") {
|
||||
if accelerator != "" {
|
||||
machineAccelerators += strings.TrimSpace(accelerator) + ","
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,6 +256,19 @@ func (h hypervisor) machineAccelerators() string {
|
||||
return machineAccelerators
|
||||
}
|
||||
|
||||
func (h hypervisor) cpuFeatures() string {
|
||||
var cpuFeatures string
|
||||
for _, feature := range strings.Split(h.CPUFeatures, ",") {
|
||||
if feature != "" {
|
||||
cpuFeatures += strings.TrimSpace(feature) + ","
|
||||
}
|
||||
}
|
||||
|
||||
cpuFeatures = strings.Trim(cpuFeatures, ",")
|
||||
|
||||
return cpuFeatures
|
||||
}
|
||||
|
||||
func (h hypervisor) kernelParams() string {
|
||||
if h.KernelParams == "" {
|
||||
return defaultKernelParams
|
||||
@@ -624,6 +636,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
||||
}
|
||||
|
||||
machineAccelerators := h.machineAccelerators()
|
||||
cpuFeatures := h.cpuFeatures()
|
||||
kernelParams := h.kernelParams()
|
||||
machineType := h.machineType()
|
||||
|
||||
@@ -677,6 +690,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
||||
ImagePath: image,
|
||||
FirmwarePath: firmware,
|
||||
MachineAccelerators: machineAccelerators,
|
||||
CPUFeatures: cpuFeatures,
|
||||
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
||||
HypervisorMachineType: machineType,
|
||||
NumVCPUs: h.defaultVCPUs(),
|
||||
@@ -1129,6 +1143,7 @@ func GetDefaultHypervisorConfig() vc.HypervisorConfig {
|
||||
InitrdPath: defaultInitrdPath,
|
||||
FirmwarePath: defaultFirmwarePath,
|
||||
MachineAccelerators: defaultMachineAccelerators,
|
||||
CPUFeatures: defaultCPUFeatures,
|
||||
HypervisorMachineType: defaultMachineType,
|
||||
NumVCPUs: defaultVCPUCount,
|
||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||
|
||||
Reference in New Issue
Block a user