From 7757dceab38103f41d030108ce0ce3f1a3cb7021 Mon Sep 17 00:00:00 2001 From: Penny Zheng Date: Mon, 4 Jun 2018 06:43:44 +0000 Subject: [PATCH] cpuinfo/arm64: Refine CPUInfo in Arm64 The CPUinfo need to be refined in Arm architecture, because the vendor and model of CPU may refer to different meaning in Arm architecture. Besides, relevant contents extracted from /proc/cpuinfo may need to be normalized for human-readability. Fixes: #368 Signed-off-by: Penny Zheng Signed-off-by: Wei Chen --- cli/kata-check_amd64.go | 4 +++ cli/kata-check_arm64.go | 71 +++++++++++++++++++++++++++++++++++++-- cli/kata-check_ppc64le.go | 4 +++ cli/utils.go | 4 +-- 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/cli/kata-check_amd64.go b/cli/kata-check_amd64.go index db46e246cb..a642602059 100644 --- a/cli/kata-check_amd64.go +++ b/cli/kata-check_amd64.go @@ -74,3 +74,7 @@ func hostIsVMContainerCapable(details vmContainerCapableDetails) error { func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool { return genericArchKernelParamHandler(onVMM, fields, msg) } + +func getCPUDetails() (vendor, model string, err error) { + return genericGetCPUDetails() +} diff --git a/cli/kata-check_arm64.go b/cli/kata-check_arm64.go index ab73393df1..35a4d807f9 100644 --- a/cli/kata-check_arm64.go +++ b/cli/kata-check_arm64.go @@ -5,12 +5,16 @@ package main -import "github.com/sirupsen/logrus" +import ( + "fmt" + + "github.com/sirupsen/logrus" +) const ( cpuFlagsTag = "Features" archCPUVendorField = "CPU implementer" - archCPUModelField = "CPU variant" + archCPUModelField = "CPU architecture" ) // archRequiredCPUFlags maps a CPU flag value to search for and a @@ -49,9 +53,70 @@ func archHostCanCreateVMContainer() error { // hostIsVMContainerCapable checks to see if the host is theoretically capable // of creating a VM container. func hostIsVMContainerCapable(details vmContainerCapableDetails) error { - return genericHostIsVMContainerCapable(details) + count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler) + if err != nil { + return err + } + + if count == 0 { + return nil + } + + return fmt.Errorf("ERROR: %s", failMessage) + } func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool { return genericArchKernelParamHandler(onVMM, fields, msg) } + +// The CPU Vendor here for Arm means the CPU core +// IP Implementer. +// normalizeArmVendor maps 'CPU implementer' in /proc/cpuinfo +// to human-readable description of that value. +func normalizeArmVendor(vendor string) string { + + switch vendor { + case "0x41": + vendor = "ARM Limited" + default: + vendor = "3rd Party Limited" + } + + return vendor +} + +// The CPU Model here for Arm means the Instruction set, that is +// the variant number of Arm processor. +// normalizeArmModel maps 'CPU architecture' in /proc/cpuinfo +// to human-readable description of that value. +func normalizeArmModel(model string) string { + switch model { + case "8": + model = "v8" + case "7", "7M", "?(12)", "?(13)", "?(14)", "?(15)", "?(16)", "?(17)": + model = "v7" + case "6", "6TEJ": + model = "v6" + case "5", "5T", "5TE", "5TEJ": + model = "v5" + case "4", "4T": + model = "v4" + case "3": + model = "v3" + default: + model = "unknown" + } + + return model +} + +func getCPUDetails() (vendor, model string, err error) { + if vendor, model, err := genericGetCPUDetails(); err == nil { + vendor = normalizeArmVendor(vendor) + model = normalizeArmModel(model) + return vendor, model, err + } else { + return vendor, model, err + } +} diff --git a/cli/kata-check_ppc64le.go b/cli/kata-check_ppc64le.go index 750338fdb7..152303876c 100644 --- a/cli/kata-check_ppc64le.go +++ b/cli/kata-check_ppc64le.go @@ -65,3 +65,7 @@ func kvmIsUsable() error { func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool { return genericArchKernelParamHandler(onVMM, fields, msg) } + +func getCPUDetails() (vendor, model string, err error) { + return genericGetCPUDetails() +} diff --git a/cli/utils.go b/cli/utils.go index df83a1aa85..61a8ee1edf 100644 --- a/cli/utils.go +++ b/cli/utils.go @@ -96,10 +96,10 @@ func getDistroDetails() (name, version string, err error) { return "", "", fmt.Errorf("failed to find expected fields in one of %v", files) } -// getCPUDetails returns the vendor and model of the CPU. +// genericGetCPUDetails returns the vendor and model of the CPU. // If it is not possible to determine both values an error is // returned. -func getCPUDetails() (vendor, model string, err error) { +func genericGetCPUDetails() (vendor, model string, err error) { cpuinfo, err := getCPUInfo(procCPUInfo) if err != nil { return "", "", err