From 3a4aec153e5824d437ca1cc2557f4f793dcb9d28 Mon Sep 17 00:00:00 2001 From: Qi Feng Huo Date: Fri, 7 Aug 2020 20:49:14 +0800 Subject: [PATCH] qemu: add annotations for iommu_platform for s390x virtio devices Add iommu_platform annotations for qemu for ccw, other supported devices can also make use of that. Fixes #2830 Signed-off-by: Qi Feng Huo --- .../configuration-qemu-virtiofs.toml.in | 4 ++++ cli/config/configuration-qemu.toml.in | 4 ++++ pkg/katautils/config-settings.go.in | 1 + pkg/katautils/config.go | 12 ++++++++++++ virtcontainers/hypervisor.go | 3 +++ virtcontainers/pkg/annotations/annotations.go | 3 +++ virtcontainers/pkg/oci/utils.go | 9 +++++++++ virtcontainers/pkg/oci/utils_test.go | 2 ++ virtcontainers/qemu.go | 19 ++++++++++--------- 9 files changed, 48 insertions(+), 9 deletions(-) diff --git a/cli/config/configuration-qemu-virtiofs.toml.in b/cli/config/configuration-qemu-virtiofs.toml.in index 579d264340..75002abd50 100644 --- a/cli/config/configuration-qemu-virtiofs.toml.in +++ b/cli/config/configuration-qemu-virtiofs.toml.in @@ -195,6 +195,10 @@ vhost_user_store_path = "@DEFVHOSTUSERSTOREPATH@" # command line: intel_iommu=on,iommu=pt #enable_iommu = true +# Enable IOMMU_PLATFORM, default false +# Enabling this will result in the VM device having iommu_platform=on set +#enable_iommu_platform = true + # Enable file based guest memory support. The default is an empty string which # will disable this feature. In the case of virtio-fs, this is enabled # automatically and '/dev/shm' is used as the backing folder. diff --git a/cli/config/configuration-qemu.toml.in b/cli/config/configuration-qemu.toml.in index 9c7af06fab..80d7c5fc28 100644 --- a/cli/config/configuration-qemu.toml.in +++ b/cli/config/configuration-qemu.toml.in @@ -202,6 +202,10 @@ vhost_user_store_path = "@DEFVHOSTUSERSTOREPATH@" # command line: intel_iommu=on,iommu=pt #enable_iommu = true +# Enable IOMMU_PLATFORM, default false +# Enabling this will result in the VM device having iommu_platform=on set +#enable_iommu_platform = true + # Enable file based guest memory support. The default is an empty string which # will disable this feature. In the case of virtio-fs, this is enabled # automatically and '/dev/shm' is used as the backing folder. diff --git a/pkg/katautils/config-settings.go.in b/pkg/katautils/config-settings.go.in index 3be124b9d0..99b97c248d 100644 --- a/pkg/katautils/config-settings.go.in +++ b/pkg/katautils/config-settings.go.in @@ -40,6 +40,7 @@ const defaultEnableIOThreads bool = false const defaultEnableMemPrealloc bool = false const defaultEnableHugePages bool = false const defaultEnableIOMMU bool = false +const defaultEnableIOMMUPlatform bool = false const defaultFileBackedMemRootDir string = "" const defaultEnableSwap bool = false const defaultEnableDebug bool = false diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index f909127f61..a982a3f499 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -121,6 +121,7 @@ type hypervisor struct { HugePages bool `toml:"enable_hugepages"` VirtioMem bool `toml:"enable_virtio_mem"` IOMMU bool `toml:"enable_iommu"` + IOMMUPlatform bool `toml:"enable_iommu_platform"` FileBackedMemRootDir string `toml:"file_mem_backend"` Swap bool `toml:"enable_swap"` Debug bool `toml:"enable_debug"` @@ -444,6 +445,15 @@ func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) return } +func (h hypervisor) getIOMMUPlatform() bool { + if h.IOMMUPlatform { + kataUtilsLogger.Info("IOMMUPlatform is enabled by default.") + } else { + kataUtilsLogger.Info("IOMMUPlatform is disabled by default.") + } + return h.IOMMUPlatform +} + func (p proxy) path() (string, error) { path := p.Path if path == "" { @@ -671,6 +681,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { MemPrealloc: h.MemPrealloc, HugePages: h.HugePages, IOMMU: h.IOMMU, + IOMMUPlatform: h.getIOMMUPlatform(), FileBackedMemRootDir: h.FileBackedMemRootDir, Mlock: !h.Swap, Debug: h.Debug, @@ -1115,6 +1126,7 @@ func GetDefaultHypervisorConfig() vc.HypervisorConfig { MemPrealloc: defaultEnableMemPrealloc, HugePages: defaultEnableHugePages, IOMMU: defaultEnableIOMMU, + IOMMUPlatform: defaultEnableIOMMUPlatform, FileBackedMemRootDir: defaultFileBackedMemRootDir, Mlock: !defaultEnableSwap, Debug: defaultEnableDebug, diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index 55a77f41bc..aa441b23a8 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -364,6 +364,9 @@ type HypervisorConfig struct { // IOMMU specifies if the VM should have a vIOMMU IOMMU bool + // IOMMUPlatform is used to indicate if IOMMU_PLATFORM is enabled for supported devices + IOMMUPlatform bool + // Realtime Used to enable/disable realtime Realtime bool diff --git a/virtcontainers/pkg/annotations/annotations.go b/virtcontainers/pkg/annotations/annotations.go index da41d4bf89..ff62bb2415 100644 --- a/virtcontainers/pkg/annotations/annotations.go +++ b/virtcontainers/pkg/annotations/annotations.go @@ -154,6 +154,9 @@ const ( // Iommu is a sandbox annotation to specify if the VM should have a vIOMMU device IOMMU = kataAnnotHypervisorPrefix + "enable_iommu" + // Enable Hypervisor Devices IOMMU_PLATFORM + IOMMUPlatform = kataAnnotHypervisorPrefix + "enable_iommu_platform" + // FileBackedMemRootDir is a sandbox annotation to soecify file based memory backend root directory FileBackedMemRootDir = kataAnnotHypervisorPrefix + "file_mem_backend" diff --git a/virtcontainers/pkg/oci/utils.go b/virtcontainers/pkg/oci/utils.go index 99e9a6f554..51077e935e 100644 --- a/virtcontainers/pkg/oci/utils.go +++ b/virtcontainers/pkg/oci/utils.go @@ -557,6 +557,15 @@ func addHypervisorMemoryOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig sbConfig.HypervisorConfig.IOMMU = iommu } + + if value, ok := ocispec.Annotations[vcAnnotations.IOMMUPlatform]; ok { + deviceIOMMU, err := strconv.ParseBool(value) + if err != nil { + return fmt.Errorf("Error parsing annotation for enable_iommu_platform: Please specify boolean value 'true|false'") + } + + sbConfig.HypervisorConfig.IOMMUPlatform = deviceIOMMU + } return nil } diff --git a/virtcontainers/pkg/oci/utils_test.go b/virtcontainers/pkg/oci/utils_test.go index 7b80567e68..dbc844b031 100644 --- a/virtcontainers/pkg/oci/utils_test.go +++ b/virtcontainers/pkg/oci/utils_test.go @@ -792,6 +792,7 @@ func TestAddHypervisorAnnotations(t *testing.T) { ocispec.Annotations[vcAnnotations.HotplugVFIOOnRootBus] = "true" ocispec.Annotations[vcAnnotations.PCIeRootPort] = "2" ocispec.Annotations[vcAnnotations.EntropySource] = "/dev/urandom" + ocispec.Annotations[vcAnnotations.IOMMUPlatform] = "true" addAnnotations(ocispec, &config) assert.Equal(config.HypervisorConfig.NumVCPUs, uint32(1)) @@ -825,6 +826,7 @@ func TestAddHypervisorAnnotations(t *testing.T) { assert.Equal(config.HypervisorConfig.HotplugVFIOOnRootBus, true) assert.Equal(config.HypervisorConfig.PCIeRootPort, uint32(2)) assert.Equal(config.HypervisorConfig.EntropySource, "/dev/urandom") + assert.Equal(config.HypervisorConfig.IOMMUPlatform, true) // In case an absurd large value is provided, the config value if not over-ridden ocispec.Annotations[vcAnnotations.DefaultVCPUs] = "655536" diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 65795f5998..c4dd91e906 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -486,15 +486,16 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa } knobs := govmmQemu.Knobs{ - NoUserConfig: true, - NoDefaults: true, - NoGraphic: true, - NoReboot: true, - Daemonize: true, - MemPrealloc: q.config.MemPrealloc, - HugePages: q.config.HugePages, - Realtime: q.config.Realtime, - Mlock: q.config.Mlock, + NoUserConfig: true, + NoDefaults: true, + NoGraphic: true, + NoReboot: true, + Daemonize: true, + MemPrealloc: q.config.MemPrealloc, + HugePages: q.config.HugePages, + Realtime: q.config.Realtime, + Mlock: q.config.Mlock, + IOMMUPlatform: q.config.IOMMUPlatform, } kernelPath, err := q.config.KernelAssetPath()