Skip to content

Commit a526086

Browse files
committed
fix(cpu-template-helper): ignore wide registers
When SVE extension is enabled on aarch64 cpus, KVM will return wide registers when queried. Because cpu templates do not support registers wider than 128 bits we need to ignore wide registers when converting cpu configuration into a cpu template. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 49db07b commit a526086

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/cpu-template-helper/src/template/dump/aarch64.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44
use vmm::arch::aarch64::regs::RegSize;
55
use vmm::cpu_config::aarch64::custom_cpu_template::RegisterModifier;
66
use vmm::cpu_config::templates::{CpuConfiguration, CustomCpuTemplate, RegisterValueFilter};
7+
use vmm::logger::warn;
78

89
use crate::utils::aarch64::reg_modifier;
910

1011
pub fn config_to_template(cpu_config: &CpuConfiguration) -> CustomCpuTemplate {
1112
let mut reg_modifiers: Vec<RegisterModifier> = cpu_config
1213
.regs
1314
.iter()
14-
.map(|reg| match reg.size() {
15-
RegSize::U32 => {
16-
reg_modifier!(reg.id, u128::from(reg.value::<u32, 4>()))
15+
.filter_map(|reg| match reg.size() {
16+
RegSize::U32 => Some(reg_modifier!(reg.id, u128::from(reg.value::<u32, 4>()))),
17+
RegSize::U64 => Some(reg_modifier!(reg.id, u128::from(reg.value::<u64, 8>()))),
18+
RegSize::U128 => Some(reg_modifier!(reg.id, reg.value::<u128, 16>())),
19+
_ => {
20+
warn!(
21+
"Only 32, 64 and 128 bit wide registers are supported in cpu templates. \
22+
Skipping: {:#x}",
23+
reg.id
24+
);
25+
None
1726
}
18-
RegSize::U64 => {
19-
reg_modifier!(reg.id, u128::from(reg.value::<u64, 8>()))
20-
}
21-
RegSize::U128 => {
22-
reg_modifier!(reg.id, reg.value::<u128, 16>())
23-
}
24-
_ => unreachable!("Only 32, 64 and 128 bit wide registers are supported"),
2527
})
2628
.collect();
2729
reg_modifiers.sort_by_key(|modifier| modifier.addr);
@@ -43,6 +45,10 @@ mod tests {
4345
const KVM_REG_SIZE_U32: u64 = 0x0020000000000000;
4446
const KVM_REG_SIZE_U64: u64 = 0x0030000000000000;
4547
const KVM_REG_SIZE_U128: u64 = 0x0040000000000000;
48+
const KVM_REG_SIZE_U256: u64 = 0x0050000000000000;
49+
const KVM_REG_SIZE_U512: u64 = 0x0060000000000000;
50+
const KVM_REG_SIZE_U1024: u64 = 0x0070000000000000;
51+
const KVM_REG_SIZE_U2048: u64 = 0x0080000000000000;
4652

4753
fn build_sample_regs() -> Aarch64RegisterVec {
4854
let mut v = Aarch64RegisterVec::default();
@@ -58,6 +64,10 @@ mod tests {
5864
KVM_REG_SIZE_U64,
5965
&0x0000_ffff_0000_ffff_u64.to_le_bytes(),
6066
));
67+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U256, &[0x69; 32]));
68+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U512, &[0x69; 64]));
69+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U1024, &[0x69; 128]));
70+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U2048, &[0x69; 256]));
6171
v
6272
}
6373

tests/integration_tests/functional/test_cpu_template_helper.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ def test_json_static_templates(
410410
"""
411411
Verify that JSON static CPU templates are applied as intended.
412412
"""
413-
if custom_cpu_template["name"] == "aarch64_with_sve_and_pac":
414-
pytest.skip("does not work yet")
415413
# Generate VM config with JSON static CPU template
416414
microvm = test_microvm_with_api
417415
microvm.spawn()

0 commit comments

Comments
 (0)