Skip to content

Commit

Permalink
arch: Fix ARM64 build
Browse files Browse the repository at this point in the history
As we still don't have an ARM CI, the ARM64 build broke.

Fixes kata-containers#349.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Jun 1, 2018
1 parent 2400978 commit 3f2d07e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 22 deletions.
6 changes: 5 additions & 1 deletion cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ type vmContainerCapableDetails struct {

const (
moduleParamDir = "parameters"
cpuFlagsTag = "flags"
successMessageCapable = "System is capable of running " + project
successMessageCreate = "System can currently create " + project
failMessage = "System is not capable of running " + project
kernelPropertyCorrect = "Kernel property value correct"

// these refer to fields in the procCPUINFO file
genericCPUFlagsTag = "flags"
genericCPUVendorField = "vendor_id"
genericCPUModelField = "model name"
)

// variables rather than consts to allow tests to modify them
Expand Down
6 changes: 6 additions & 0 deletions cli/kata-check_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/sirupsen/logrus"
)

const (
cpuFlagsTag = genericCPUFlagsTag
archCPUVendorField = genericCPUVendorField
archCPUModelField = genericCPUModelField
)

// archRequiredCPUFlags maps a CPU flag value to search for and a
// human-readable description of that value.
var archRequiredCPUFlags = map[string]string{
Expand Down
35 changes: 35 additions & 0 deletions cli/kata-check_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@

package main

import "github.com/sirupsen/logrus"

const (
cpuFlagsTag = "Features"
archCPUVendorField = "CPU implementer"
archCPUModelField = ""
)

// archRequiredCPUFlags maps a CPU flag value to search for and a
// human-readable description of that value.
var archRequiredCPUFlags = map[string]string{}

// archRequiredCPUAttribs maps a CPU (non-CPU flag) attribute value to search for
// and a human-readable description of that value.
var archRequiredCPUAttribs = map[string]string{}

// archRequiredKernelModules maps a required module name to a human-readable
// description of the modules functionality and an optional list of
// required module parameters.
var archRequiredKernelModules = map[string]kernelModule{
"kvm": {
desc: "Kernel-based Virtual Machine",
},
"vhost": {
desc: "Host kernel accelerator for virtio",
},
"vhost_net": {
desc: "Host kernel accelerator for virtio network",
},
}

// 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 {
Expand All @@ -20,3 +51,7 @@ func archHostCanCreateVMContainer() error {
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
return genericHostIsVMContainerCapable(details)
}

func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}
12 changes: 7 additions & 5 deletions cli/kata-check_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ package main

import (
"fmt"

"github.com/sirupsen/logrus"
)

const (
cpuFlagsTag = genericCPUFlagsTag
archCPUVendorField = genericCPUVendorField
archCPUModelField = genericCPUModelField
)

// 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 @@ -37,11 +44,6 @@ func archHostCanCreateVMContainer() error {
// hostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container.
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
_, err := getCPUInfo(details.cpuInfoFile)
if err != nil {
return err
}

count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler)
if err != nil {
return err
Expand Down
21 changes: 17 additions & 4 deletions cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,23 @@ func TestCheckGetCPUFlags(t *testing.T) {
{"foo", ""},
{"foo bar", ""},
{":", ""},
{"flags", ""},
{"flags:", ""},
{"flags: a b c", "a b c"},
{"flags: a b c foo bar d", "a b c foo bar d"},

{
cpuFlagsTag,
"",
},
{
cpuFlagsTag + ":",
"",
},
{
fmt.Sprintf("%s: a b c", cpuFlagsTag),
"a b c",
},
{
fmt.Sprintf("%s: a b c foo bar d", cpuFlagsTag),
"a b c foo bar d",
},
}

for _, d := range data {
Expand Down
33 changes: 22 additions & 11 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,35 @@ func getCPUDetails() (vendor, model string, err error) {
lines := strings.Split(cpuinfo, "\n")

for _, line := range lines {
if strings.HasPrefix(line, "vendor_id") {
fields := strings.Split(line, ":")
if len(fields) > 1 {
vendor = strings.TrimSpace(fields[1])
if archCPUVendorField != "" {
if strings.HasPrefix(line, archCPUVendorField) {
fields := strings.Split(line, ":")
if len(fields) > 1 {
vendor = strings.TrimSpace(fields[1])
}
}
} else if strings.HasPrefix(line, "model name") {
fields := strings.Split(line, ":")
if len(fields) > 1 {
model = strings.TrimSpace(fields[1])
}

if archCPUModelField != "" {
if strings.HasPrefix(line, archCPUModelField) {
fields := strings.Split(line, ":")
if len(fields) > 1 {
model = strings.TrimSpace(fields[1])
}
}
}
}

if vendor != "" && model != "" {
return vendor, model, nil
if vendor == "" {
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
}

// model name is optional
if archCPUModelField != "" && model == "" {
return "", "", fmt.Errorf("cannot find model field in file %v", procCPUInfo)
}

return "", "", fmt.Errorf("failed to find expected fields in file %v", procCPUInfo)
return vendor, model, nil
}

// resolvePath returns the fully resolved and expanded value of the
Expand Down
5 changes: 4 additions & 1 deletion virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const defaultQemuMachineType = QemuVirt

const defaultQemuMachineOptions = "gic-version=host,usb=off,accel=kvm"

// Not used
const defaultPCBridgeBus = ""

var qemuPaths = map[string]string{
QemuVirt: defaultQemuPath,
}
Expand All @@ -47,7 +50,7 @@ func MaxQemuVCPUs() uint32 {
return uint32(runtime.NumCPU())
}

func newQemuArch(config HypervisrConfig) qemuArch {
func newQemuArch(config HypervisorConfig) qemuArch {
machineType := config.HypervisorMachineType
if machineType == "" {
machineType = defaultQemuMachineType
Expand Down

0 comments on commit 3f2d07e

Please sign in to comment.