forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypervisor_linux_arm64.go
More file actions
71 lines (62 loc) · 1.66 KB
/
hypervisor_linux_arm64.go
File metadata and controls
71 lines (62 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2021 Arm Ltd.
//
// SPDX-License-Identifier: Apache-2.0
package virtcontainers
/*
#include <linux/kvm.h>
*/
import "C"
import (
"github.com/sirupsen/logrus"
"syscall"
)
// variables rather than consts to allow tests to modify them
var (
kvmDevice = "/dev/kvm"
syscallSyscall = syscall.Syscall
syscallOpen = syscall.Open
syscallClose = syscall.Close
)
// This KVM_CAP_ARM_RME ABI is aligned with CCA/v8 patch sets.
// It will be changed to other number after the whole KVM CCA/RME
// support patches is merged to the upstream.
const KVM_ARM_CAP_RME_ID = 240
func availableGuestProtection() (guestProtection, error) {
ret, err := checkKVMExtensionsRME()
if err != nil {
return noneProtection, err
}
if ret == true {
return ccaProtection, nil
} else {
return noneProtection, nil
}
}
// checkKVMExtensionsRME allows to query about the specific kvm extensions
func checkKVMExtensionsRME() (bool, error) {
flags := syscall.O_RDWR | syscall.O_CLOEXEC
kvm, err := syscallOpen(kvmDevice, flags, 0)
if err != nil {
return false, err
}
defer syscallClose(kvm)
logger := hvLogger.WithFields(logrus.Fields{
"type": "kvm extension",
"description": "Realm Management Extension",
"id": KVM_ARM_CAP_RME_ID,
})
ret, _, errno := syscallSyscall(syscall.SYS_IOCTL,
uintptr(kvm),
uintptr(C.KVM_CHECK_EXTENSION),
uintptr(KVM_ARM_CAP_RME_ID))
// Generally return value(ret) 0 means no and 1 means yes,
// but some extensions may report additional information in the integer return value.
if errno != 0 {
logger.Error("is not supported")
return false, errno
}
if int(ret) == 1 {
return true, nil
}
return false, nil
}