Skip to content

Commit

Permalink
Merge pull request #2831 from Jakob-Naucke/backport-!x86-static
Browse files Browse the repository at this point in the history
Backport runtime: Fix !x86 static checks
  • Loading branch information
GabyCT authored Oct 13, 2021
2 parents 4102a18 + 1f6b0f6 commit 3a035c1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 33 deletions.
24 changes: 12 additions & 12 deletions src/runtime/cli/kata-check_s390x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
10 changes: 10 additions & 0 deletions src/runtime/virtcontainers/hypervisor_arm64.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions src/runtime/virtcontainers/hypervisor_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
23 changes: 14 additions & 9 deletions src/runtime/virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 (
Expand Down
19 changes: 18 additions & 1 deletion src/runtime/virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -77,6 +78,7 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
kernelParams: kernelParams,
disableNvdimm: config.DisableImageNvdimm,
dax: true,
protection: noneProtection,
},
}

Expand Down Expand Up @@ -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
}
17 changes: 6 additions & 11 deletions src/runtime/virtcontainers/qemu_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions src/runtime/virtcontainers/utils/utils_linux_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//

//nolint:deadcode,unused
package utils

// from <linux/vhost.h>
Expand Down

0 comments on commit 3a035c1

Please sign in to comment.