From d9738cfd6500ced30efde9e747eb73e5076e73ed Mon Sep 17 00:00:00 2001 From: jiangpengfei Date: Tue, 18 Aug 2020 22:47:13 +0800 Subject: [PATCH 43/50] kata-runtime: support add hypervisor global parameters in config file reason: support add hypervisor global parameters in config file with defaultHypervisorParams config option. Signed-off-by: jiangpengfei --- Makefile | 2 ++ cli/config/configuration-qemu.toml.in | 7 +++++++ pkg/katautils/config-settings.go.in | 1 + pkg/katautils/config.go | 13 ++++++++++++- vendor/github.com/intel/govmm/qemu/qemu.go | 6 +++--- virtcontainers/qemu.go | 2 +- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d5e4bbe1..b62e64b0 100644 --- a/Makefile +++ b/Makefile @@ -400,6 +400,7 @@ USER_VARS += FIRMWAREPATH USER_VARS += MACHINEACCELERATORS USER_VARS += DEFMACHINETYPE_CLH USER_VARS += KERNELPARAMS +USER_VARS += HYPERVISORPARAMS USER_VARS += LIBEXECDIR USER_VARS += LOCALSTATEDIR USER_VARS += PKGDATADIR @@ -607,6 +608,7 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit -e "s|@FIRMWAREPATH_CLH@|$(FIRMWAREPATH_CLH)|g" \ -e "s|@DEFMACHINETYPE_CLH@|$(DEFMACHINETYPE_CLH)|g" \ -e "s|@KERNELPARAMS@|$(KERNELPARAMS)|g" \ + -e "s|@HYPERVISORPARAMS@|$(HYPERVISORPARAMS)|g" \ -e "s|@LOCALSTATEDIR@|$(LOCALSTATEDIR)|g" \ -e "s|@PKGLIBEXECDIR@|$(PKGLIBEXECDIR)|g" \ -e "s|@PKGRUNDIR@|$(PKGRUNDIR)|g" \ diff --git a/cli/config/configuration-qemu.toml.in b/cli/config/configuration-qemu.toml.in index aa11b38f..e57a954c 100644 --- a/cli/config/configuration-qemu.toml.in +++ b/cli/config/configuration-qemu.toml.in @@ -29,6 +29,13 @@ machine_type = "@MACHINETYPE@" # container and look for 'default-kernel-parameters' log entries. kernel_params = "@KERNELPARAMS@" +# Optional space-separated list of options to pass to the hypervisor. +# For example, use `hypervisor_params = "kvm-pit.lost_tick_policy=discard"` +# +# WARNING: - any parameter specified here will take priority over the default +# parameter value of the same name used to start the hypervisor. +hypervisor_params = "@HYPERVISORPARAMS@" + # Path to the firmware. # If you want that qemu uses the default firmware leave this option empty firmware = "@FIRMWAREPATH@" diff --git a/pkg/katautils/config-settings.go.in b/pkg/katautils/config-settings.go.in index aaf78cc3..b2dfdfa1 100644 --- a/pkg/katautils/config-settings.go.in +++ b/pkg/katautils/config-settings.go.in @@ -20,6 +20,7 @@ var defaultShimPath = "/usr/libexec/kata-containers/kata-shim" var systemdUnitName = "kata-containers.target" const defaultKernelParams = "" +const defaultHypervisorParams = "kvm-pit.lost_tick_policy=discard" const defaultMachineType = "pc" const defaultVCPUCount uint32 = 1 diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index 51120311..3365b3f5 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -130,6 +130,7 @@ type hypervisor struct { HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"` DisableVhostNet bool `toml:"disable_vhost_net"` GuestHookPath string `toml:"guest_hook_path"` + HypervisorParams string `toml:"hypervisor_params"` } type proxy struct { @@ -270,6 +271,14 @@ func (h hypervisor) kernelParams() string { return h.KernelParams } +func (h hypervisor) hypervisorParams() string { + if h.HypervisorParams == "" { + return defaultHypervisorParams + } + + return h.HypervisorParams +} + func (h hypervisor) machineType() string { if h.MachineType == "" { return defaultMachineType @@ -632,6 +641,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { machineAccelerators := h.machineAccelerators() kernelParams := h.kernelParams() + hypervisorParams := h.hypervisorParams() machineType := h.machineType() blockDriver, err := h.blockDeviceDriver() @@ -675,6 +685,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { FirmwarePath: firmware, MachineAccelerators: machineAccelerators, KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)), + HypervisorParams: vc.DeserializeParams(strings.Fields(hypervisorParams)), HypervisorMachineType: machineType, NumVCPUs: h.defaultVCPUs(), DefaultMaxVCPUs: h.defaultMaxVCPUs(), @@ -983,7 +994,7 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc TraceMode: agent.traceMode(), TraceType: agent.traceType(), KernelModules: agent.kernelModules(), - MountBlkInVM: agent.mountBlkDevInVM(), + MountBlkInVM: agent.mountBlkDevInVM(), } default: return fmt.Errorf("%s agent type is not supported", k) diff --git a/vendor/github.com/intel/govmm/qemu/qemu.go b/vendor/github.com/intel/govmm/qemu/qemu.go index 3e7720b4..68f8d2b0 100644 --- a/vendor/github.com/intel/govmm/qemu/qemu.go +++ b/vendor/github.com/intel/govmm/qemu/qemu.go @@ -2096,7 +2096,7 @@ type Config struct { SMP SMP // GlobalParam is the -global parameter. - GlobalParam string + GlobalParam []string // Knobs is a set of qemu boolean settings. Knobs Knobs @@ -2285,9 +2285,9 @@ func (config *Config) appendRTC() { } func (config *Config) appendGlobalParam() { - if config.GlobalParam != "" { + for _, param := range config.GlobalParam { config.qemuParams = append(config.qemuParams, "-global") - config.qemuParams = append(config.qemuParams, config.GlobalParam) + config.qemuParams = append(config.qemuParams, param) } } diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index a10c66fb..657b6be7 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -600,7 +600,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa Knobs: knobs, Incoming: incoming, VGA: "none", - GlobalParam: "kvm-pit.lost_tick_policy=discard", + GlobalParam: SerializeParams(hypervisorConfig.HypervisorParams, "="), Bios: firmwarePath, PidFile: filepath.Join(q.store.RunVMStoragePath(), q.id, "pid"), } -- 2.14.3 (Apple Git-98)