Skip to content

Commit 6d8b08b

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 c910e44 commit 6d8b08b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ pub fn config_to_template(cpu_config: &CpuConfiguration) -> CustomCpuTemplate {
1111
let mut reg_modifiers: Vec<RegisterModifier> = cpu_config
1212
.regs
1313
.iter()
14-
.map(|reg| match reg.size() {
15-
RegSize::U32 => {
16-
reg_modifier!(reg.id, u128::from(reg.value::<u32, 4>()))
14+
.filter_map(|reg| match reg.size() {
15+
RegSize::U32 => Some(reg_modifier!(reg.id, u128::from(reg.value::<u32, 4>()))),
16+
RegSize::U64 => Some(reg_modifier!(reg.id, u128::from(reg.value::<u64, 8>()))),
17+
RegSize::U128 => Some(reg_modifier!(reg.id, reg.value::<u128, 16>())),
18+
_ => {
19+
println!(
20+
"Only 32, 64 and 128 bit wide registers are supported in cpu templates. \
21+
Skipping: {:#x}",
22+
reg.id
23+
);
24+
None
1725
}
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"),
2526
})
2627
.collect();
2728
reg_modifiers.sort_by_key(|modifier| modifier.addr);
@@ -43,6 +44,10 @@ mod tests {
4344
const KVM_REG_SIZE_U32: u64 = 0x0020000000000000;
4445
const KVM_REG_SIZE_U64: u64 = 0x0030000000000000;
4546
const KVM_REG_SIZE_U128: u64 = 0x0040000000000000;
47+
const KVM_REG_SIZE_U256: u64 = 0x0050000000000000;
48+
const KVM_REG_SIZE_U512: u64 = 0x0060000000000000;
49+
const KVM_REG_SIZE_U1024: u64 = 0x0070000000000000;
50+
const KVM_REG_SIZE_U2048: u64 = 0x0080000000000000;
4651

4752
fn build_sample_regs() -> Aarch64RegisterVec {
4853
let mut v = Aarch64RegisterVec::default();
@@ -58,6 +63,10 @@ mod tests {
5863
KVM_REG_SIZE_U64,
5964
&0x0000_ffff_0000_ffff_u64.to_le_bytes(),
6065
));
66+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U256, &[0x69; 32]));
67+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U512, &[0x69; 64]));
68+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U1024, &[0x69; 128]));
69+
v.push(Aarch64RegisterRef::new(KVM_REG_SIZE_U2048, &[0x69; 256]));
6170
v
6271
}
6372

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)