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

Commit

Permalink
arch/arm64: Fix ARM64 build
Browse files Browse the repository at this point in the history
Fix ARM64 build which silently broken (as we still don't have an ARM CI).

Fixes #349.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Jun 1, 2018
1 parent 2400978 commit 6e161a2
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 28 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 = "CPU variant"
)

// 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
10 changes: 7 additions & 3 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ VERSION_ID="%s"
`, expectedDistro.Name, expectedDistro.Version)

procCPUInfoContents := fmt.Sprintf(`
vendor_id : %s
model name : %s
`, expectedCPU.Vendor, expectedCPU.Model)
%s : %s
%s : %s
`,
archCPUVendorField,
expectedCPU.Vendor,
archCPUModelField,
expectedCPU.Model)

data := []filesToCreate{
{procVersion, procVersionContents},
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
6 changes: 3 additions & 3 deletions cli/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ func TestGetCPUDetails(t *testing.T) {
}

const validVendorName = "a vendor"
validVendor := fmt.Sprintf(`vendor_id : %s`, validVendorName)
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)

const validModelName = "some CPU model"
validModel := fmt.Sprintf(`model name : %s`, validModelName)
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)

validContents := fmt.Sprintf(`
a : b
Expand All @@ -240,7 +240,7 @@ foo : bar
data := []testData{
{"", "", "", true},
{"invalid", "", "", true},
{"vendor_id", "", "", true},
{archCPUVendorField, "", "", true},
{validVendor, "", "", true},
{validModel, "", "", true},
{validContents, validVendorName, validModelName, false},
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 6e161a2

Please sign in to comment.