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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use serde::{Deserialize, Serialize};
/// The CPU Template defines a set of flags to be disabled from the microvm so that
/// the features exposed to the guest are the same as in the selected instance type.
/// This parameter has been deprecated and it will be removed in future Firecracker
/// release.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CPUTemplate(
/// default: "None"
pub CPUTemplateString,
);
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum CPUTemplateString {
#[serde(rename = "C3")]
C3,
#[serde(rename = "T2")]
T2,
#[serde(rename = "T2S")]
T2S,
#[serde(rename = "T2CL")]
T2CL,
#[serde(rename = "T2A")]
T2A,
#[serde(rename = "V1N1")]
V1N1,
#[serde(rename = "None")]
None,
}
/// The CPU configuration template defines a set of bit maps as modifiers
/// of flags accessed by register to be disabled/enabled for the microvm.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CPUConfig {
// A collection of CPUIDs to be modified. (x86_64)
pub cpuid_modifiers: Vec<CpuIdModifier>,
// A collection of model specific registers to be modified. (x86_64)
pub msr_modifiers: Vec<MsrModifier>,
// A collection of registers to be modified. (aarch64)
pub reg_modifiers: Vec<RegModifier>,
}
/// CPUID modifiers. Only for x86_64.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CpuIdModifier {
/// CPUID leaf index (or function). Must be a string containing an integer.
/// Examples: ["0x1", "0x2"]
pub leaf: String,
/// CPUID subleaf index (or subfunction). Must be a string containing an integer.
/// Examples: ["0x1", "0x2"]
pub subleaf: String,
/// KVM CPUID flags, see https://docs.kernel.org/virt/kvm/api.html#kvm-get-supported-cpuid
pub flags: u32,
/// CPUID register modifiers.
pub modifiers: Vec<Modifiers>,
}
/// CPUID register modifier
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Modifiers {
/// CPUID register name
/// One of ["eax", "ebx", "ecx", "edx"]
pub register: ModifierRegisterName,
/// CPUID register value bitmap.
/// Must be in format `0b[01x]{32}`.
/// Corresponding bits will be cleared (`0`), set (`1`) or left intact (`x`). (`_`) can be used as a separator.
/// Examples: ["0bxxxx000000000011xx00011011110010", "0bxxxxxxxxxxxxx0xx00xx00x0_0000_00xx"]
pub bitmap: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ModifierRegisterName {
#[serde(rename = "eax")]
EAX,
#[serde(rename = "ebx")]
EBX,
#[serde(rename = "ecx")]
ECX,
#[serde(rename = "edx")]
EDX,
}
/// MSR modifiers. Only for x86_64.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MsrModifier {
/// MSR address/identifier. Must be a string containing an integer.
/// Example: ["0x10a"]
pub addr: String,
/// MSR value bitmap.
/// Must be in format `0b[01x]{64}`.
/// Corresponding bits will be cleared (`0`), set (`1`) or left intact (`x`). (`_`) can be used as a separator.
/// Example: ["0bxxxx0000000000000000000000000000000000000000000000000000_11101011"]
pub bitmap: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RegModifier {
/// ARM register address/identifier. Must be a string containing an integer. See https://docs.kernel.org/virt/kvm/api.html#kvm-set-one-reg
/// Example: ["0x603000000013c020"]
pub addr: String,
/// ARM register value bitmap. Must be in format `0b[01x]{1,128}`. The actual length of the bitmap should be less or equal to the size of the register in bits. Corresponding bits will be cleared (`0`), set (`1`) or left intact (`x`). (`_`) can be used as a separator.
/// Example: ["0bxxxxxxxxxxxx_0000_xxxx_xxxx_xxxx_0000_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx"]
pub bitmap: String,
}