Skip to content

Commit 4c8d541

Browse files
krkzulinx86
authored andcommitted
fix: handle E2BIG error from get_reg_list
Resize the kvm_reg_list buffer and make the get_reg_list call again, if the reported buffer size is larger than 500. get_reg_list returns E2BIG when the passed buffer is not large enough. Signed-off-by: krk <keremkat@gmail.com>
1 parent 34af8d6 commit 4c8d541

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/vmm/src/arch/aarch64/vcpu.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,30 @@ pub fn get_registers(
153153
/// Returns all registers ids, including core and system
154154
pub fn get_all_registers_ids(vcpufd: &VcpuFd) -> Result<Vec<u64>, VcpuError> {
155155
// Call KVM_GET_REG_LIST to get all registers available to the guest. For ArmV8 there are
156-
// less than 500 registers.
156+
// less than 500 registers expected, resize to the reported size when necessary.
157157
let mut reg_list = RegList::new(500).map_err(VcpuError::Fam)?;
158-
vcpufd
159-
.get_reg_list(&mut reg_list)
160-
.map_err(VcpuError::GetRegList)?;
161-
Ok(reg_list.as_slice().to_vec())
158+
159+
match vcpufd.get_reg_list(&mut reg_list) {
160+
Ok(_) => Ok(reg_list.as_slice().to_vec()),
161+
Err(e) => match e.errno() {
162+
libc::E2BIG => {
163+
// resize and retry.
164+
let size: usize = reg_list
165+
.as_fam_struct_ref()
166+
.n
167+
.try_into()
168+
// Safe to unwrap as Firecracker only targets 64-bit machines.
169+
.unwrap();
170+
reg_list = RegList::new(size).map_err(VcpuError::Fam)?;
171+
vcpufd
172+
.get_reg_list(&mut reg_list)
173+
.map_err(VcpuError::GetRegList)?;
174+
175+
Ok(reg_list.as_slice().to_vec())
176+
}
177+
_ => Err(VcpuError::GetRegList(e)),
178+
},
179+
}
162180
}
163181

164182
/// Set the state of the system registers.

0 commit comments

Comments
 (0)