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

Enable Kata container on ppc64le arch #286

Merged
merged 4 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ ifeq (,$(installing))
EXTRA_DEPS = clean
endif

ifeq (uncompressed,$(KERNELTYPE))
KERNEL_NAME = vmlinux.container
else
KERNEL_NAME = vmlinuz.container
endif

LIBEXECDIR := $(PREFIX)/libexec
SHAREDIR := $(PREFIX)/share
DEFAULTSDIR := $(SHAREDIR)/defaults
Expand All @@ -77,7 +83,7 @@ PKGLIBDIR := $(LOCALSTATEDIR)/lib/$(PROJECT_DIR)
PKGRUNDIR := $(LOCALSTATEDIR)/run/$(PROJECT_DIR)
PKGLIBEXECDIR := $(LIBEXECDIR)/$(PROJECT_DIR)

KERNELPATH := $(PKGDATADIR)/vmlinuz.container
KERNELPATH := $(PKGDATADIR)/$(KERNEL_NAME)
INITRDPATH := $(PKGDATADIR)/$(INITRDNAME)
IMAGEPATH := $(PKGDATADIR)/$(IMAGENAME)
FIRMWAREPATH :=
Expand Down Expand Up @@ -150,6 +156,7 @@ USER_VARS += INITRDNAME
USER_VARS += INITRDPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
USER_VARS += KERNELTYPE
USER_VARS += FIRMWAREPATH
USER_VARS += MACHINEACCELERATORS
USER_VARS += KERNELPARAMS
Expand Down
12 changes: 12 additions & 0 deletions arch/ppc64le-options.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2018 IBM
#
# SPDX-License-Identifier: Apache-2.0
#

# Power ppc64le settings

MACHINETYPE := pseries
KERNELPARAMS :=
MACHINEACCELERATORS :=
KERNELTYPE := uncompressed #This architecture must use an uncompressed kernel.
QEMUCMD := qemu-system-ppc64le
72 changes: 70 additions & 2 deletions cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@

package main

/*
#include <linux/kvm.h>

const int ioctl_KVM_CREATE_VM = KVM_CREATE_VM;
*/
import "C"

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"syscall"

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -51,6 +59,11 @@ var (
modInfoCmd = "modinfo"
)

// variables rather than consts to allow tests to modify them
var (
kvmDevice = "/dev/kvm"
)

// getCPUInfo returns details of the first CPU read from the specified cpuinfo file
func getCPUInfo(cpuInfoFile string) (string, error) {
text, err := getFileContents(cpuInfoFile)
Expand Down Expand Up @@ -222,9 +235,9 @@ func checkKernelModules(modules map[string]kernelModule, handler kernelParamHand
return count, nil
}

// hostIsVMContainerCapable checks to see if the host is theoretically capable
// genericHostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container.
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
func genericHostIsVMContainerCapable(details vmContainerCapableDetails) error {
cpuinfo, err := getCPUInfo(details.cpuInfoFile)
if err != nil {
return err
Expand Down Expand Up @@ -293,3 +306,58 @@ var kataCheckCLICommand = cli.Command{
return nil
},
}

func genericArchKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
param, ok := fields["parameter"].(string)
if !ok {
return false
}

// This option is not required when
// already running under a hypervisor.
if param == "unrestricted_guest" && onVMM {
kataLog.WithFields(fields).Warn(kernelPropertyCorrect)
return true
}

if param == "nested" {
kataLog.WithFields(fields).Warn(msg)
return true
}

// don't ignore the error
return false
}

// genericKvmIsUsable determines if it will be possible to create a full virtual machine
// by creating a minimal VM and then deleting it.
func genericKvmIsUsable() error {
flags := syscall.O_RDWR | syscall.O_CLOEXEC

f, err := syscall.Open(kvmDevice, flags, 0)
if err != nil {
return err
}
defer syscall.Close(f)

fieldLogger := kataLog.WithField("check-type", "full")

fieldLogger.WithField("device", kvmDevice).Info("device available")

vm, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(f),
uintptr(C.ioctl_KVM_CREATE_VM),
0)
if errno != 0 {
if errno == syscall.EBUSY {
fieldLogger.WithField("reason", "another hypervisor running").Error("cannot create VM")
}

return errno
}
defer syscall.Close(int(vm))

fieldLogger.WithField("feature", "create-vm").Info("feature available")

return nil
}
69 changes: 8 additions & 61 deletions cli/kata-check_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@

package main

/*
#include <linux/kvm.h>

const int ioctl_KVM_CREATE_VM = KVM_CREATE_VM;
*/
import "C"

import (
"syscall"

"github.com/sirupsen/logrus"
)

// variables rather than consts to allow tests to modify them
var (
kvmDevice = "/dev/kvm"
)

// archRequiredCPUFlags maps a CPU flag value to search for and a
// human-readable description of that value.
var archRequiredCPUFlags = map[string]string{
Expand Down Expand Up @@ -66,58 +52,19 @@ var archRequiredKernelModules = map[string]kernelModule{
// kvmIsUsable determines if it will be possible to create a full virtual machine
// by creating a minimal VM and then deleting it.
func kvmIsUsable() error {
flags := syscall.O_RDWR | syscall.O_CLOEXEC

f, err := syscall.Open(kvmDevice, flags, 0)
if err != nil {
return err
}
defer syscall.Close(f)

fieldLogger := kataLog.WithField("check-type", "full")

fieldLogger.WithField("device", kvmDevice).Info("device available")

vm, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(f),
uintptr(C.ioctl_KVM_CREATE_VM),
0)
if errno != 0 {
if errno == syscall.EBUSY {
fieldLogger.WithField("reason", "another hypervisor running").Error("cannot create VM")
}

return errno
}
defer syscall.Close(int(vm))

fieldLogger.WithField("feature", "create-vm").Info("feature available")

return nil
return genericKvmIsUsable()
}

func archHostCanCreateVMContainer() error {
return kvmIsUsable()
}

func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
param, ok := fields["parameter"].(string)
if !ok {
return false
}

// This option is not required when
// already running under a hypervisor.
if param == "unrestricted_guest" && onVMM {
kataLog.WithFields(fields).Warn(kernelPropertyCorrect)
return true
}

if param == "nested" {
kataLog.WithFields(fields).Warn(msg)
return true
}
// hostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container.
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
return genericHostIsVMContainerCapable(details)
}

// don't ignore the error
return false
func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}
22 changes: 22 additions & 0 deletions cli/kata-check_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//

package main

// kvmIsUsable determines if it will be possible to create a full virtual machine
// by creating a minimal VM and then deleting it.
func kvmIsUsable() error {
return genericKvmIsUsable()
}

func archHostCanCreateVMContainer() error {
return kvmIsUsable()
}

// hostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container.
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
return genericHostIsVMContainerCapable(details)
}
114 changes: 114 additions & 0 deletions cli/kata-check_data_ppc64le_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) 2018 IBM
//
// SPDX-License-Identifier: Apache-2.0
//

package main

const testCPUInfoTemplate = `
processor : 0
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 8
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 16
cpu : POWER8E (raw), altivec supported
clock : 2360.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 24
cpu : POWER8E (raw), altivec supported
clock : 2061.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 32
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 40
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 48
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 56
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 64
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 72
cpu : POWER8E (raw), altivec supported
clock : 3059.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 80
cpu : POWER8E (raw), altivec supported
clock : 2693.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 88
cpu : POWER8E (raw), altivec supported
clock : 2061.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 96
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 104
cpu : POWER8E (raw), altivec supported
clock : 2061.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 112
cpu : POWER8E (raw), altivec supported
clock : 2061.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 120
cpu : POWER8E (raw), altivec supported
clock : 2061.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 128
cpu : POWER8E (raw), altivec supported
clock : 3690.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 136
cpu : POWER8E (raw), altivec supported
clock : 2061.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 144
cpu : POWER8E (raw), altivec supported
clock : 2294.000000MHz
revision : 2.1 (pvr 004b 0201)

processor : 152
cpu : POWER8E (raw), altivec supported
clock : 2560.000000MHz
revision : 2.1 (pvr 004b 0201)

timebase : 512000000
platform : PowerNV
model : 8247-22L
machine : PowerNV 8247-22L
firmware : OPAL v3
`
Loading