Skip to content

Commit

Permalink
Update kvm-bindings and kvm-ioctls deps
Browse files Browse the repository at this point in the history
Update kvm-bindings to 0.8 and kvm-ioctls to 0.17, and apply some minor
changes to vmm to overcome the API-breaking changes in the latter.

Signed-off-by: Sergio Lopez <slp@redhat.com>
  • Loading branch information
slp committed Jun 4, 2024
1 parent aff2644 commit 76f4cb5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
37 changes: 29 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/arch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ smbios = { path = "../smbios" }
utils = { path = "../utils" }

[target.'cfg(target_os = "linux")'.dependencies]
kvm-bindings = { version = ">=0.6", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.15"
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.17"

[target.'cfg(target_arch = "aarch64")'.dependencies]
vm-fdt = ">= 0.2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/cpuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
vmm-sys-util = ">=0.11"

[target.'cfg(target_os = "linux")'.dependencies]
kvm-bindings = { version = ">=0.6", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.15"
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.17"
4 changes: 2 additions & 2 deletions src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ nix = "0.24.1"
cpuid = { path = "../cpuid" }

[target.'cfg(target_os = "linux")'.dependencies]
kvm-bindings = { version = ">=0.6", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.15"
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.17"

[target.'cfg(target_os = "macos")'.dependencies]
hvf = { path = "../hvf" }
Expand Down
27 changes: 8 additions & 19 deletions src/vmm/src/linux/vstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ pub struct VcpuConfig {
}

// Using this for easier explicit type-casting to help IDEs interpret the code.
type VcpuCell = Cell<Option<*const Vcpu>>;
type VcpuCell = Cell<Option<*mut Vcpu>>;

/// A wrapper around creating and using a kvm-based VCPU.
pub struct Vcpu {
Expand Down Expand Up @@ -803,7 +803,7 @@ impl Vcpu {
if cell.get().is_some() {
return Err(Error::VcpuTlsInit);
}
cell.set(Some(self as *const Vcpu));
cell.set(Some(self as *mut Vcpu));
Ok(())
})
}
Expand All @@ -819,7 +819,7 @@ impl Vcpu {
// _before_ running this, then there is nothing we can do.
Self::TLS_VCPU_PTR.with(|cell: &VcpuCell| {
if let Some(vcpu_ptr) = cell.get() {
if vcpu_ptr == self as *const Vcpu {
if vcpu_ptr == self as *mut Vcpu {
Self::TLS_VCPU_PTR.with(|cell: &VcpuCell| cell.take());
return Ok(());
}
Expand All @@ -840,13 +840,13 @@ impl Vcpu {
/// dereferencing from pointer an already borrowed `Vcpu`.
unsafe fn run_on_thread_local<F>(func: F) -> Result<()>
where
F: FnOnce(&Vcpu),
F: FnOnce(&mut Vcpu),
{
Self::TLS_VCPU_PTR.with(|cell: &VcpuCell| {
if let Some(vcpu_ptr) = cell.get() {
// Dereferencing here is safe since `TLS_VCPU_PTR` is populated/non-empty,
// and it is being cleared on `Vcpu::drop` so there is no dangling pointer.
let vcpu_ref: &Vcpu = &*vcpu_ptr;
let vcpu_ref: &mut Vcpu = &mut *vcpu_ptr;
func(vcpu_ref);
Ok(())
} else {
Expand All @@ -862,7 +862,7 @@ impl Vcpu {
// This is safe because it's temporarily aliasing the `Vcpu` object, but we are
// only reading `vcpu.fd` which does not change for the lifetime of the `Vcpu`.
unsafe {
let _ = Vcpu::run_on_thread_local(|vcpu| {
let _ = Vcpu::run_on_thread_local(|vcpu: &mut Vcpu| {
vcpu.fd.set_kvm_immediate_exit(1);
fence(Ordering::Release);
});
Expand Down Expand Up @@ -1520,19 +1520,12 @@ mod tests {
vm.supported_msrs().clone(),
devices::Bus::new(),
exit_evt,
super::super::super::TimestampUs::default(),
)
.unwrap();
}
#[cfg(target_arch = "aarch64")]
{
vcpu = Vcpu::new_aarch64(
1,
vm.fd(),
exit_evt,
super::super::super::TimestampUs::default(),
)
.unwrap();
vcpu = Vcpu::new_aarch64(1, vm.fd(), exit_evt).unwrap();
vm.setup_irqchip(1).expect("Cannot setup irqchip");
}

Expand Down Expand Up @@ -1599,7 +1592,6 @@ mod tests {
vm.supported_msrs().clone(),
devices::Bus::new(),
EventFd::new(utils::eventfd::EFD_NONBLOCK).unwrap(),
super::super::super::TimestampUs::default(),
)
.unwrap();
// Trying to setup irqchip after KVM_VCPU_CREATE was called will result in error.
Expand All @@ -1617,7 +1609,6 @@ mod tests {
1,
vm.fd(),
EventFd::new(utils::eventfd::EFD_NONBLOCK).unwrap(),
super::super::TimestampUs::default(),
)
.unwrap();

Expand Down Expand Up @@ -1667,7 +1658,6 @@ mod tests {
0,
vm.fd(),
EventFd::new(utils::eventfd::EFD_NONBLOCK).unwrap(),
super::super::TimestampUs::default(),
)
.unwrap();

Expand All @@ -1680,7 +1670,6 @@ mod tests {
1,
vm.fd(),
EventFd::new(utils::eventfd::EFD_NONBLOCK).unwrap(),
super::super::TimestampUs::default(),
)
.unwrap();

Expand Down Expand Up @@ -1752,7 +1741,7 @@ mod tests {
Vcpu::register_kick_signal_handler();
let (vm, mut vcpu, _mem) = setup_vcpu(0x1000);

let kvm_run =
let mut kvm_run =
KvmRunWrapper::mmap_from_fd(&vcpu.fd, vm.fd.run_size()).expect("cannot mmap kvm-run");
let success = Arc::new(std::sync::atomic::AtomicBool::new(false));
let vcpu_success = success.clone();
Expand Down

0 comments on commit 76f4cb5

Please sign in to comment.