Merge pull request #2831 from Jakob-Naucke/backport-!x86-static

Backport runtime: Fix !x86 static checks
This commit is contained in:
GabyCT
2021-10-13 13:35:48 -05:00
committed by GitHub
7 changed files with 68 additions and 33 deletions

View File

@@ -57,51 +57,51 @@ func TestArchKernelParamHandler(t *testing.T) {
assert := assert.New(t)
type testData struct {
onVMM bool
expectIgnore bool
fields logrus.Fields
msg string
onVMM bool
expectIgnore bool
}
data := []testData{
{true, false, logrus.Fields{}, ""},
{false, false, logrus.Fields{}, ""},
{logrus.Fields{}, "", true, false},
{logrus.Fields{}, "", false, false},
{
false,
false,
logrus.Fields{
// wrong type
"parameter": 123,
},
"foo",
false,
false,
},
{
false,
false,
logrus.Fields{
"parameter": "unrestricted_guest",
},
"",
false,
false,
},
{
true,
true,
logrus.Fields{
"parameter": "unrestricted_guest",
},
"",
true,
true,
},
{
false,
true,
logrus.Fields{
"parameter": "nested",
},
"",
false,
true,
},
}

View File

@@ -0,0 +1,10 @@
// Copyright (c) 2021 Arm Ltd.
//
// SPDX-License-Identifier: Apache-2.0
package virtcontainers
//Returns pefProtection if the firmware directory exists
func availableGuestProtection() (guestProtection, error) {
return noneProtection, nil
}

View File

@@ -26,3 +26,10 @@ func TestRunningOnVMM(t *testing.T) {
assert.NoError(err)
assert.Equal(expectedOutput, running)
}
func TestAvailableGuestProtection(t *testing.T) {
assert := assert.New(t)
out, _ := availableGuestProtection()
assert.Equal(out, noneProtection)
}

View File

@@ -159,19 +159,23 @@ const (
//Intel Trust Domain Extensions
//https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html
tdxProtection
// Exclude from lint checking for it won't be used on arm64 code
tdxProtection //nolint
// AMD Secure Encrypted Virtualization
// https://developer.amd.com/sev/
sevProtection
// Exclude from lint checking for it won't be used on arm64 code
sevProtection //nolint
// IBM POWER 9 Protected Execution Facility
// https://www.kernel.org/doc/html/latest/powerpc/ultravisor.html
pefProtection
// Exclude from lint checking for it won't be used on arm64 code
pefProtection //nolint
// IBM Secure Execution (IBM Z & LinuxONE)
// https://www.kernel.org/doc/html/latest/virt/kvm/s390-pv.html
seProtection
// Exclude from lint checking for it won't be used on arm64 code
seProtection //nolint
)
type qemuArchBase struct {
@@ -184,11 +188,12 @@ type qemuArchBase struct {
Bridges []types.Bridge
memoryOffset uint64
networkIndex int
protection guestProtection
nestedRun bool
vhost bool
disableNvdimm bool
dax bool
// Exclude from lint checking for it is ultimately only used in architecture-specific code
protection guestProtection //nolint:structcheck
nestedRun bool
vhost bool
disableNvdimm bool
dax bool
}
const (

View File

@@ -8,8 +8,9 @@ package virtcontainers
import (
"context"
"fmt"
"time"
"os"
"runtime"
"time"
govmmQemu "github.com/kata-containers/govmm/qemu"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
@@ -77,6 +78,7 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
kernelParams: kernelParams,
disableNvdimm: config.DisableImageNvdimm,
dax: true,
protection: noneProtection,
},
}
@@ -162,3 +164,18 @@ func (q *qemuArm64) getPFlash() ([]string, error) {
return nil, fmt.Errorf("too many pflash images for arm64")
}
}
func (q *qemuArm64) enableProtection() error {
q.protection, _ = availableGuestProtection()
if q.protection != noneProtection {
return fmt.Errorf("Protection %v is not supported on arm64", q.protection)
}
return nil
}
func (q *qemuArm64) appendProtectionDevice(devices []govmmQemu.Device, firmware string) ([]govmmQemu.Device, string, error) {
err := q.enableProtection()
virtLog.WithField("arch", runtime.GOARCH).Warnf("%v", err)
return devices, firmware, err
}

View File

@@ -102,14 +102,11 @@ func TestQemuArm64AppendImage(t *testing.T) {
imageStat, err := f.Stat()
assert.NoError(err)
// save default supportedQemuMachines options
machinesCopy := make([]govmmQemu.Machine, len(supportedQemuMachines))
assert.Equal(len(supportedQemuMachines), copy(machinesCopy, supportedQemuMachines))
cfg := qemuConfig(QemuVirt)
cfg.ImagePath = f.Name()
arm64 := newQemuArch(cfg)
assert.Contains(m.machine().Options, qemuNvdimmOption)
arm64, err := newQemuArch(cfg)
assert.NoError(err)
assert.Contains(arm64.machine().Options, qemuNvdimmOption)
expectedOut := []govmmQemu.Device{
govmmQemu.Object{
@@ -125,9 +122,6 @@ func TestQemuArm64AppendImage(t *testing.T) {
devices, err = arm64.appendImage(context.Background(), devices, f.Name())
assert.NoError(err)
assert.Equal(expectedOut, devices)
//restore default supportedQemuMachines options
assert.Equal(len(supportedQemuMachines), copy(supportedQemuMachines, machinesCopy))
}
func TestQemuArm64AppendNvdimmImage(t *testing.T) {
@@ -168,7 +162,8 @@ func TestQemuArm64WithInitrd(t *testing.T) {
cfg := qemuConfig(QemuVirt)
cfg.InitrdPath = "dummy-initrd"
arm64 := newQemuArch(cfg)
arm64, err := newQemuArch(cfg)
assert.NoError(err)
assert.NotContains(m.machine().Options, qemuNvdimmOption)
assert.NotContains(arm64.machine().Options, qemuNvdimmOption)
}

View File

@@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//
//nolint:deadcode,unused
package utils
// from <linux/vhost.h>