Skip to content

Commit 6c0534c

Browse files
committed
refactor(vmm): rename items related to serializable MSRs
Rename items (functions, variables and methods) related to serializable MSRs. Previously they were named `msr_list` or `supported_msrs` that were confusing or difficult to guess their usage from their names. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 5b8813f commit 6c0534c

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/vmm/src/arch/x86_64/msr.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ macro_rules! MSR_RANGE {
136136
}
137137

138138
// List of MSRs that can be serialized. List is sorted in ascending order of MSRs addresses.
139-
static ALLOWED_MSR_RANGES: &[MsrRange] = &[
139+
static SERIALIZABLE_MSR_RANGES: &[MsrRange] = &[
140140
MSR_RANGE!(MSR_IA32_P5_MC_ADDR),
141141
MSR_RANGE!(MSR_IA32_P5_MC_TYPE),
142142
MSR_RANGE!(MSR_IA32_TSC),
@@ -242,7 +242,9 @@ pub fn msr_should_serialize(index: u32) -> bool {
242242
if index == MSR_IA32_MCG_CTL {
243243
return false;
244244
};
245-
ALLOWED_MSR_RANGES.iter().any(|range| range.contains(index))
245+
SERIALIZABLE_MSR_RANGES
246+
.iter()
247+
.any(|range| range.contains(index))
246248
}
247249

248250
/// Creates and populates required MSR entries for booting Linux on X86_64.
@@ -315,12 +317,12 @@ pub fn set_msrs(
315317
})
316318
}
317319

318-
/// Returns the list of supported, serializable MSRs.
320+
/// Returns the list of supported and serializable MSR indices.
319321
///
320322
/// # Arguments
321323
///
322324
/// * `kvm_fd` - Structure that holds the KVM's fd.
323-
pub fn supported_guest_msrs(kvm_fd: &Kvm) -> Result<MsrList> {
325+
pub fn get_msrs_to_save(kvm_fd: &Kvm) -> Result<MsrList> {
324326
let mut msr_list = kvm_fd
325327
.get_msr_index_list()
326328
.map_err(Error::GetSupportedModelSpecificRegisters)?;
@@ -338,7 +340,7 @@ mod tests {
338340

339341
#[test]
340342
fn test_msr_allowlist() {
341-
for range in ALLOWED_MSR_RANGES.iter() {
343+
for range in SERIALIZABLE_MSR_RANGES.iter() {
342344
for msr in range.base..(range.base + range.nmsrs) {
343345
let should = !matches!(msr, MSR_IA32_MCG_CTL);
344346
assert_eq!(msr_should_serialize(msr), should);

src/vmm/src/guest_config/x86_64/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct CpuConfiguration {
4545
pub msrs: HashMap<u32, u64>,
4646

4747
/// Set of supported MSRs
48-
pub supported_msrs: HashSet<u32>,
48+
pub msrs_to_save: HashSet<u32>,
4949

5050
/// Architectural MSPs required for boot
5151
pub msr_boot_entries: Vec<kvm_msr_entry>,
@@ -69,7 +69,7 @@ impl CpuConfiguration {
6969
Ok(Self {
7070
cpuid: supported_cpuid,
7171
msrs: Default::default(),
72-
supported_msrs: Default::default(),
72+
msrs_to_save: Default::default(),
7373
msr_boot_entries: create_boot_msr_entries(),
7474
})
7575
}
@@ -106,13 +106,13 @@ impl CpuConfiguration {
106106
// C3, T2 and T2A currently don't have extra MSRs to save/set.
107107
match template {
108108
StaticCpuTemplate::T2S => {
109-
config.supported_msrs.extend(msr_entries_to_save());
109+
config.msrs_to_save.extend(msr_entries_to_save());
110110
static_cpu_templates::t2s::update_t2s_msr_entries(
111111
&mut config.msr_boot_entries,
112112
);
113113
}
114114
StaticCpuTemplate::T2CL => {
115-
config.supported_msrs.extend(msr_entries_to_save());
115+
config.msrs_to_save.extend(msr_entries_to_save());
116116
static_cpu_templates::t2cl::update_t2cl_msr_entries(
117117
&mut config.msr_boot_entries,
118118
);
@@ -130,7 +130,7 @@ impl CpuConfiguration {
130130
let Self {
131131
mut cpuid,
132132
mut msrs,
133-
supported_msrs,
133+
msrs_to_save,
134134
msr_boot_entries,
135135
} = self;
136136

@@ -188,7 +188,7 @@ impl CpuConfiguration {
188188
Ok(Self {
189189
cpuid,
190190
msrs,
191-
supported_msrs,
191+
msrs_to_save,
192192
msr_boot_entries,
193193
})
194194
}
@@ -266,7 +266,7 @@ mod tests {
266266
CpuConfiguration {
267267
cpuid: Cpuid::Intel(IntelCpuid(BTreeMap::new())),
268268
msrs: Default::default(),
269-
supported_msrs: Default::default(),
269+
msrs_to_save: Default::default(),
270270
msr_boot_entries: Default::default(),
271271
}
272272
}
@@ -275,7 +275,7 @@ mod tests {
275275
CpuConfiguration {
276276
cpuid: static_cpu_templates::t2::t2(),
277277
msrs: HashMap::from([(0x8000, 0b1000), (0x9999, 0b1010)]),
278-
supported_msrs: Default::default(),
278+
msrs_to_save: Default::default(),
279279
msr_boot_entries: Default::default(),
280280
}
281281
}
@@ -284,7 +284,7 @@ mod tests {
284284
CpuConfiguration {
285285
cpuid: static_cpu_templates::t2::t2(),
286286
msrs: HashMap::from([(0x8000, 0b1000), (0x8001, 0b1010)]),
287-
supported_msrs: Default::default(),
287+
msrs_to_save: Default::default(),
288288
msr_boot_entries: Default::default(),
289289
}
290290
}

src/vmm/src/vstate/vcpu/x86_64.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct KvmVcpu {
191191
pub pio_bus: Option<devices::Bus>,
192192
pub mmio_bus: Option<devices::Bus>,
193193

194-
msr_list: HashSet<u32>,
194+
msrs_to_save: HashSet<u32>,
195195
}
196196

197197
impl KvmVcpu {
@@ -209,7 +209,7 @@ impl KvmVcpu {
209209
fd: kvm_vcpu,
210210
pio_bus: None,
211211
mmio_bus: None,
212-
msr_list: vm.supported_msrs().as_slice().iter().copied().collect(),
212+
msrs_to_save: vm.msrs_to_save().as_slice().iter().copied().collect(),
213213
})
214214
}
215215

@@ -228,8 +228,8 @@ impl KvmVcpu {
228228
vcpu_config: &VcpuConfig,
229229
) -> std::result::Result<(), KvmVcpuConfigureError> {
230230
let mut cpuid = vcpu_config.cpu_config.cpuid.clone();
231-
self.msr_list
232-
.extend(vcpu_config.cpu_config.supported_msrs.iter());
231+
self.msrs_to_save
232+
.extend(vcpu_config.cpu_config.msrs_to_save.iter());
233233
let msr_boot_entries = vcpu_config.cpu_config.msr_boot_entries.clone();
234234

235235
// Apply machine specific changes to CPUID.
@@ -264,7 +264,7 @@ impl KvmVcpu {
264264
// the extra MSRs that we need to save based on a dependency map.
265265
let extra_msrs = crate::guest_config::cpuid::common::msrs_to_save_by_cpuid(&kvm_cpuid)
266266
.map_err(KvmVcpuConfigureError::MsrsToSaveByCpuid)?;
267-
self.msr_list.extend(extra_msrs);
267+
self.msrs_to_save.extend(extra_msrs);
268268

269269
// By this point we know that at snapshot, the list of MSRs we need to
270270
// save is `architectural MSRs` + `MSRs inferred through CPUID` + `other
@@ -321,11 +321,11 @@ impl KvmVcpu {
321321
// more than KVM_MAX_MSR_ENTRIES in the snapshot, so we use a Vec<Msrs>
322322
// to allow an unlimited number.
323323
let mut all_msrs: Vec<Msrs> = Vec::new();
324-
let msr_list: Vec<&u32> = self.msr_list.iter().collect();
324+
let msrs_to_save: Vec<&u32> = self.msrs_to_save.iter().collect();
325325

326326
// KVM only supports getting KVM_MAX_MSR_ENTRIES at a time so chunk
327327
// them up into `Msrs` so it's easy to pass to the ioctl.
328-
for chunk in msr_list.chunks(KVM_MAX_MSR_ENTRIES) {
328+
for chunk in msrs_to_save.chunks(KVM_MAX_MSR_ENTRIES) {
329329
let mut msrs = Msrs::new(chunk.len()).map_err(Error::Fam)?;
330330
let msr_entries = msrs.as_mut_slice();
331331
assert_eq!(chunk.len(), msr_entries.len());

src/vmm/src/vstate/vm.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub struct Vm {
116116
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
117117
supported_cpuid: CpuId,
118118
#[cfg(target_arch = "x86_64")]
119-
supported_msrs: MsrList,
119+
msrs_to_save: MsrList,
120120

121121
// Arm specific fields.
122122
// On aarch64 we need to keep around the fd obtained by creating the VGIC device.
@@ -246,13 +246,13 @@ impl Vm {
246246
let supported_cpuid = kvm
247247
.get_supported_cpuid(KVM_MAX_CPUID_ENTRIES)
248248
.map_err(Error::VmFd)?;
249-
let supported_msrs =
250-
crate::arch::x86_64::msr::supported_guest_msrs(kvm).map_err(Error::GuestMsrs)?;
249+
let msrs_to_save =
250+
crate::arch::x86_64::msr::get_msrs_to_save(kvm).map_err(Error::GuestMsrs)?;
251251

252252
Ok(Vm {
253253
fd: vm_fd,
254254
supported_cpuid,
255-
supported_msrs,
255+
msrs_to_save,
256256
})
257257
}
258258

@@ -261,9 +261,9 @@ impl Vm {
261261
&self.supported_cpuid
262262
}
263263

264-
/// Returns a ref to the supported `MsrList` for this Vm.
265-
pub fn supported_msrs(&self) -> &MsrList {
266-
&self.supported_msrs
264+
/// Returns a ref to the list of serializable MSR indices.
265+
pub fn msrs_to_save(&self) -> &MsrList {
266+
&self.msrs_to_save
267267
}
268268

269269
/// Restores the KVM VM state.

0 commit comments

Comments
 (0)