Skip to content

Commit f9269aa

Browse files
committed
refactor: move KVM_SET_TSS_ADDR call into Vm::arch_create
Since we issue this ioctl with a constant address, it doesn't really matter _when_ we do it. Internally, it causes a hidden memslot of size 3 pages to be created. If we create it _after_ all other memslots, then this ioctl can fail with EEXIST if it would overlap some pre-existing memslot. Now, instead the creation of the overlapping memslot would fail with EEXIST. But this is a moot point, because if Firecracker ever tried to create a memslot that overlaps this one, something is fundamentally broken. Signed-off-by: Patrick Roy <[email protected]>
1 parent 56b4979 commit f9269aa

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/vmm/src/vstate/vm/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use kvm_bindings::{kvm_userspace_memory_region, KVM_MEM_LOG_DIRTY_PAGES};
99
use kvm_ioctls::VmFd;
1010
use vmm_sys_util::eventfd::EventFd;
1111

12-
#[cfg(target_arch = "x86_64")]
13-
use crate::utils::u64_to_usize;
1412
use crate::vstate::memory::{Address, GuestMemory, GuestMemoryMmap, GuestMemoryRegion};
1513

1614
#[cfg(target_arch = "x86_64")]
@@ -68,13 +66,7 @@ impl Vm {
6866

6967
/// Initializes the guest memory.
7068
pub fn memory_init(&self, guest_mem: &GuestMemoryMmap) -> Result<(), VmError> {
71-
self.set_kvm_memory_regions(guest_mem)?;
72-
#[cfg(target_arch = "x86_64")]
73-
self.fd
74-
.set_tss_address(u64_to_usize(crate::arch::x86_64::layout::KVM_TSS_ADDRESS))
75-
.map_err(VmError::VmSetup)?;
76-
77-
Ok(())
69+
self.set_kvm_memory_regions(guest_mem)
7870
}
7971

8072
pub(crate) fn set_kvm_memory_regions(

src/vmm/src/vstate/vm/x86_64.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kvm_ioctls::VmFd;
1111
use serde::{Deserialize, Serialize};
1212

1313
use crate::arch::x86_64::msr::MsrError;
14+
use crate::utils::u64_to_usize;
1415
use crate::vstate::vm::VmError;
1516

1617
/// Error type for [`Vm::restore_state`]
@@ -42,6 +43,8 @@ pub enum ArchVmError {
4243
VmSetIrqChip(kvm_ioctls::Error),
4344
/// Failed to get MSR index list to save into snapshots: {0}
4445
GetMsrsToSave(MsrError),
46+
/// Failed during KVM_SET_TSS_ADDRESS: {0}
47+
SetTssAddress(kvm_ioctls::Error),
4548
}
4649

4750
/// Structure representing the current architecture's understand of what a "virtual machine" is.
@@ -56,6 +59,10 @@ impl ArchVm {
5659
pub fn new(kvm: &crate::vstate::kvm::Kvm) -> Result<ArchVm, VmError> {
5760
let fd = kvm.fd.create_vm().map_err(VmError::VmFd)?;
5861
let msrs_to_save = kvm.msrs_to_save().map_err(ArchVmError::GetMsrsToSave)?;
62+
63+
fd.set_tss_address(u64_to_usize(crate::arch::x86_64::layout::KVM_TSS_ADDRESS))
64+
.map_err(ArchVmError::SetTssAddress)?;
65+
5966
Ok(ArchVm { fd, msrs_to_save })
6067
}
6168

0 commit comments

Comments
 (0)