Skip to content

Commit

Permalink
vmm: Remove PC from vCPU config dump
Browse files Browse the repository at this point in the history
The dumped vCPU config is used to:
- create a new custom CPU template based on it
- keep track of its changes over time.

The value of program counter (PC) is determined by the given kernel
image, so it should not be overwritten by a custom CPU template and
does not need to be tracked as part of a fingerprint file.

Signed-off-by: Takahiro Itazuri <[email protected]>
  • Loading branch information
zulinx86 committed Sep 20, 2023
1 parent 3156667 commit a8deede
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
if no limit is set). This avoids the kernel reallocating the fdtable during
Firecracker operations, resulting in a 30ms to 70ms reduction of snapshot
restore times for medium to large microVMs with many devices attached.
- Changed the dump feature of `cpu-template-helper` tool not to enumerate program
counter (PC) on ARM because it is determined by the given kernel image and
it is useless in the custom CPU template context.

### Fixed

Expand Down
15 changes: 13 additions & 2 deletions src/vmm/src/vstate/vcpu/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.

use kvm_bindings::*;
use kvm_ioctls::*;
use logger::{error, IncMetric, METRICS};
use utils::vm_memory::{Address, GuestAddress, GuestMemoryMmap};
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;

use crate::arch::aarch64::regs::{
Aarch64RegisterOld, Aarch64RegisterRef, Aarch64RegisterVec, KVM_REG_ARM_TIMER_CNT,
arm64_core_reg_id, offset__of, Aarch64RegisterOld, Aarch64RegisterRef, Aarch64RegisterVec,
KVM_REG_ARM_TIMER_CNT,
};
use crate::arch::aarch64::vcpu::{
get_all_registers, get_all_registers_ids, get_mpidr, get_mpstate, get_registers, set_mpstate,
Expand Down Expand Up @@ -208,11 +210,20 @@ impl KvmVcpu {
pub fn dump_cpu_config(&self) -> Result<CpuConfiguration, KvmVcpuError> {
let mut reg_list = get_all_registers_ids(&self.fd).map_err(KvmVcpuError::DumpCpuConfig)?;

let kvm_reg_pc = {
let kreg_off = offset__of!(kvm_regs, regs);
let pc_off = offset__of!(user_pt_regs, pc) + kreg_off;
arm64_core_reg_id!(KVM_REG_SIZE_U64, pc_off)
};

// KVM_REG_ARM_TIMER_CNT should be removed, because it depends on the elapsed time and
// the dumped CPU config is used to create custom CPU templates to modify CPU features
// exposed to guests or ot detect CPU configuration changes caused by firecracker/KVM/
// BIOS.
reg_list.retain(|&reg_id| reg_id != KVM_REG_ARM_TIMER_CNT);
// The value of program counter (PC) is determined by the given kernel image. It should not
// be overwritten by a custom CPU template and does not need to be tracked in a fingerprint
// file.
reg_list.retain(|&reg_id| reg_id != KVM_REG_ARM_TIMER_CNT && reg_id != kvm_reg_pc);

let mut regs = Aarch64RegisterVec::default();
get_registers(&self.fd, &reg_list, &mut regs).map_err(KvmVcpuError::DumpCpuConfig)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@
"addr": "0x603000000010003e",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"addr": "0x6030000000100040",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000"
},
{
"addr": "0x6030000000100042",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000101"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@
"addr": "0x603000000010003e",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"addr": "0x6030000000100040",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000"
},
{
"addr": "0x6030000000100042",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000101"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@
"addr": "0x603000000010003e",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"addr": "0x6030000000100040",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000"
},
{
"addr": "0x6030000000100042",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000101"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
"addr": "0x6030000000100000",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001111111000000000000000000000"
},
{
"addr": "0x6030000000100002",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"addr": "0x6030000000100004",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@
"addr": "0x603000000010003e",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"addr": "0x6030000000100040",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000"
},
{
"addr": "0x6030000000100042",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000101"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@
"addr": "0x603000000010003e",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"addr": "0x6030000000100040",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000"
},
{
"addr": "0x6030000000100042",
"bitmap": "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000101"
Expand Down

0 comments on commit a8deede

Please sign in to comment.