Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
qemu: add annotations for iommu_platform for s390x virtio devices
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Qi Feng Huo committed Aug 11, 2020
1 parent 9305ef7 commit 3a4aec1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cli/config/configuration-qemu-virtiofs.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions cli/config/configuration-qemu.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/katautils/config-settings.go.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1115,6 +1126,7 @@ func GetDefaultHypervisorConfig() vc.HypervisorConfig {
MemPrealloc: defaultEnableMemPrealloc,
HugePages: defaultEnableHugePages,
IOMMU: defaultEnableIOMMU,
IOMMUPlatform: defaultEnableIOMMUPlatform,
FileBackedMemRootDir: defaultFileBackedMemRootDir,
Mlock: !defaultEnableSwap,
Debug: defaultEnableDebug,
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3a4aec1

Please sign in to comment.