Skip to content

feat: Add KVM Nested State support and upgrade to Rust edition 2024 #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kvm-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "kvm-bindings"
version = "0.12.0"
edition = "2024"
authors = ["Amazon firecracker team <firecracker-devel@amazon.com>"]
description = "Rust FFI bindings to KVM generated using bindgen."
repository = "https://github.com/rust-vmm/kvm"
Expand Down
72 changes: 61 additions & 11 deletions kvm-bindings/src/arm64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl<T> __IncompleteArrayField<T> {
}
#[inline]
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
::std::slice::from_raw_parts(self.as_ptr(), len)
unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) }
}
#[inline]
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) }
}
}
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
Expand Down Expand Up @@ -2067,7 +2067,11 @@ impl Default for kvm_run__bindgen_ty_1__bindgen_ty_8 {
}
impl ::std::fmt::Debug for kvm_run__bindgen_ty_1__bindgen_ty_8 {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run__bindgen_ty_1__bindgen_ty_8 {{ nr: {:?}, args: {:?}, ret: {:?}, __bindgen_anon_1: {:?} }}" , self . nr , self . args , self . ret , self . __bindgen_anon_1)
write!(
f,
"kvm_run__bindgen_ty_1__bindgen_ty_8 {{ nr: {:?}, args: {:?}, ret: {:?}, __bindgen_anon_1: {:?} }}",
self.nr, self.args, self.ret, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2194,8 +2198,18 @@ const _: () = {
["Alignment of kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1"]
[::std::mem::align_of::<kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1>(
) - 1usize];
["Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_size"] [:: std :: mem :: offset_of ! (kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1 , insn_size) - 0usize] ;
["Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_bytes"] [:: std :: mem :: offset_of ! (kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1 , insn_bytes) - 1usize] ;
[
"Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_size",
][::std::mem::offset_of!(
kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1,
insn_size
) - 0usize];
[
"Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_bytes",
][::std::mem::offset_of!(
kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1,
insn_bytes
) - 1usize];
};
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
Expand Down Expand Up @@ -2245,7 +2259,11 @@ impl Default for kvm_run__bindgen_ty_1__bindgen_ty_14 {
}
impl ::std::fmt::Debug for kvm_run__bindgen_ty_1__bindgen_ty_14 {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run__bindgen_ty_1__bindgen_ty_14 {{ suberror: {:?}, ndata: {:?}, flags: {:?}, __bindgen_anon_1: {:?} }}" , self . suberror , self . ndata , self . flags , self . __bindgen_anon_1)
write!(
f,
"kvm_run__bindgen_ty_1__bindgen_ty_14 {{ suberror: {:?}, ndata: {:?}, flags: {:?}, __bindgen_anon_1: {:?} }}",
self.suberror, self.ndata, self.flags, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2390,7 +2408,11 @@ impl Default for kvm_run__bindgen_ty_1__bindgen_ty_19 {
}
impl ::std::fmt::Debug for kvm_run__bindgen_ty_1__bindgen_ty_19 {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run__bindgen_ty_1__bindgen_ty_19 {{ type: {:?}, ndata: {:?}, __bindgen_anon_1: {:?} }}" , self . type_ , self . ndata , self . __bindgen_anon_1)
write!(
f,
"kvm_run__bindgen_ty_1__bindgen_ty_19 {{ type: {:?}, ndata: {:?}, __bindgen_anon_1: {:?} }}",
self.type_, self.ndata, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2705,7 +2727,23 @@ impl Default for kvm_run {
}
impl ::std::fmt::Debug for kvm_run {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run {{ request_interrupt_window: {:?}, immediate_exit: {:?}, padding1: {:?}, exit_reason: {:?}, ready_for_interrupt_injection: {:?}, if_flag: {:?}, flags: {:?}, cr8: {:?}, apic_base: {:?}, __bindgen_anon_1: {:?}, kvm_valid_regs: {:?}, kvm_dirty_regs: {:?}, s: {:?} }}" , self . request_interrupt_window , self . immediate_exit , self . padding1 , self . exit_reason , self . ready_for_interrupt_injection , self . if_flag , self . flags , self . cr8 , self . apic_base , self . __bindgen_anon_1 , self . kvm_valid_regs , self . kvm_dirty_regs , self . s)
write!(
f,
"kvm_run {{ request_interrupt_window: {:?}, immediate_exit: {:?}, padding1: {:?}, exit_reason: {:?}, ready_for_interrupt_injection: {:?}, if_flag: {:?}, flags: {:?}, cr8: {:?}, apic_base: {:?}, __bindgen_anon_1: {:?}, kvm_valid_regs: {:?}, kvm_dirty_regs: {:?}, s: {:?} }}",
self.request_interrupt_window,
self.immediate_exit,
self.padding1,
self.exit_reason,
self.ready_for_interrupt_injection,
self.if_flag,
self.flags,
self.cr8,
self.apic_base,
self.__bindgen_anon_1,
self.kvm_valid_regs,
self.kvm_dirty_regs,
self.s
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2835,7 +2873,11 @@ impl Default for kvm_coalesced_mmio {
}
impl ::std::fmt::Debug for kvm_coalesced_mmio {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_coalesced_mmio {{ phys_addr: {:?}, len: {:?}, __bindgen_anon_1: {:?}, data: {:?} }}" , self . phys_addr , self . len , self . __bindgen_anon_1 , self . data)
write!(
f,
"kvm_coalesced_mmio {{ phys_addr: {:?}, len: {:?}, __bindgen_anon_1: {:?}, data: {:?} }}",
self.phys_addr, self.len, self.__bindgen_anon_1, self.data
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -3037,7 +3079,11 @@ impl Default for kvm_clear_dirty_log {
}
impl ::std::fmt::Debug for kvm_clear_dirty_log {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_clear_dirty_log {{ slot: {:?}, num_pages: {:?}, first_page: {:?}, __bindgen_anon_1: {:?} }}" , self . slot , self . num_pages , self . first_page , self . __bindgen_anon_1)
write!(
f,
"kvm_clear_dirty_log {{ slot: {:?}, num_pages: {:?}, first_page: {:?}, __bindgen_anon_1: {:?} }}",
self.slot, self.num_pages, self.first_page, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -3272,7 +3318,11 @@ impl Default for kvm_irq_routing_msi {
}
impl ::std::fmt::Debug for kvm_irq_routing_msi {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_irq_routing_msi {{ address_lo: {:?}, address_hi: {:?}, data: {:?}, __bindgen_anon_1: {:?} }}" , self . address_lo , self . address_hi , self . data , self . __bindgen_anon_1)
write!(
f,
"kvm_irq_routing_msi {{ address_lo: {:?}, address_hi: {:?}, data: {:?}, __bindgen_anon_1: {:?} }}",
self.address_lo, self.address_hi, self.data, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion kvm-bindings/src/arm64/fam_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use vmm_sys_util::fam::{FamStruct, FamStructWrapper};

use arm64::bindings::*;
use crate::arm64::bindings::*;

// There is no constant in the kernel as far as the maximum number
// of registers on arm, but KVM_GET_REG_LIST usually returns around 450.
Expand Down
8 changes: 4 additions & 4 deletions kvm-bindings/src/arm64/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bindings::{
use crate::bindings::{
kvm_irq_routing, kvm_irq_routing_entry, kvm_irq_routing_entry__bindgen_ty_1,
kvm_irq_routing_msi__bindgen_ty_1, kvm_mp_state, kvm_one_reg, kvm_regs, kvm_vcpu_init,
user_fpsimd_state, user_pt_regs,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use zerocopy::{transmute, IntoBytes};
use zerocopy::{IntoBytes, transmute};

serde_impls! {
user_pt_regs,
Expand Down Expand Up @@ -43,8 +43,8 @@ unsafe impl IntoBytes for kvm_irq_routing_entry__bindgen_ty_1 {

#[cfg(test)]
mod tests {
use bindings::*;
use serde::{Deserialize, Serialize};
use crate::bindings::*;
use crate::serde::{Deserialize, Serialize};

fn is_serde<T: Serialize + for<'de> Deserialize<'de> + Default>() {
let config = bincode::config::standard();
Expand Down
72 changes: 61 additions & 11 deletions kvm-bindings/src/riscv64/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl<T> __IncompleteArrayField<T> {
}
#[inline]
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
::std::slice::from_raw_parts(self.as_ptr(), len)
unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) }
}
#[inline]
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) }
}
}
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
Expand Down Expand Up @@ -1925,7 +1925,11 @@ impl Default for kvm_run__bindgen_ty_1__bindgen_ty_8 {
}
impl ::std::fmt::Debug for kvm_run__bindgen_ty_1__bindgen_ty_8 {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run__bindgen_ty_1__bindgen_ty_8 {{ nr: {:?}, args: {:?}, ret: {:?}, __bindgen_anon_1: {:?} }}" , self . nr , self . args , self . ret , self . __bindgen_anon_1)
write!(
f,
"kvm_run__bindgen_ty_1__bindgen_ty_8 {{ nr: {:?}, args: {:?}, ret: {:?}, __bindgen_anon_1: {:?} }}",
self.nr, self.args, self.ret, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2052,8 +2056,18 @@ const _: () = {
["Alignment of kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1"]
[::std::mem::align_of::<kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1>(
) - 1usize];
["Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_size"] [:: std :: mem :: offset_of ! (kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1 , insn_size) - 0usize] ;
["Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_bytes"] [:: std :: mem :: offset_of ! (kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1 , insn_bytes) - 1usize] ;
[
"Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_size",
][::std::mem::offset_of!(
kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1,
insn_size
) - 0usize];
[
"Offset of field: kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1::insn_bytes",
][::std::mem::offset_of!(
kvm_run__bindgen_ty_1__bindgen_ty_14__bindgen_ty_1__bindgen_ty_1,
insn_bytes
) - 1usize];
};
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
Expand Down Expand Up @@ -2103,7 +2117,11 @@ impl Default for kvm_run__bindgen_ty_1__bindgen_ty_14 {
}
impl ::std::fmt::Debug for kvm_run__bindgen_ty_1__bindgen_ty_14 {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run__bindgen_ty_1__bindgen_ty_14 {{ suberror: {:?}, ndata: {:?}, flags: {:?}, __bindgen_anon_1: {:?} }}" , self . suberror , self . ndata , self . flags , self . __bindgen_anon_1)
write!(
f,
"kvm_run__bindgen_ty_1__bindgen_ty_14 {{ suberror: {:?}, ndata: {:?}, flags: {:?}, __bindgen_anon_1: {:?} }}",
self.suberror, self.ndata, self.flags, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2248,7 +2266,11 @@ impl Default for kvm_run__bindgen_ty_1__bindgen_ty_19 {
}
impl ::std::fmt::Debug for kvm_run__bindgen_ty_1__bindgen_ty_19 {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run__bindgen_ty_1__bindgen_ty_19 {{ type: {:?}, ndata: {:?}, __bindgen_anon_1: {:?} }}" , self . type_ , self . ndata , self . __bindgen_anon_1)
write!(
f,
"kvm_run__bindgen_ty_1__bindgen_ty_19 {{ type: {:?}, ndata: {:?}, __bindgen_anon_1: {:?} }}",
self.type_, self.ndata, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2563,7 +2585,23 @@ impl Default for kvm_run {
}
impl ::std::fmt::Debug for kvm_run {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_run {{ request_interrupt_window: {:?}, immediate_exit: {:?}, padding1: {:?}, exit_reason: {:?}, ready_for_interrupt_injection: {:?}, if_flag: {:?}, flags: {:?}, cr8: {:?}, apic_base: {:?}, __bindgen_anon_1: {:?}, kvm_valid_regs: {:?}, kvm_dirty_regs: {:?}, s: {:?} }}" , self . request_interrupt_window , self . immediate_exit , self . padding1 , self . exit_reason , self . ready_for_interrupt_injection , self . if_flag , self . flags , self . cr8 , self . apic_base , self . __bindgen_anon_1 , self . kvm_valid_regs , self . kvm_dirty_regs , self . s)
write!(
f,
"kvm_run {{ request_interrupt_window: {:?}, immediate_exit: {:?}, padding1: {:?}, exit_reason: {:?}, ready_for_interrupt_injection: {:?}, if_flag: {:?}, flags: {:?}, cr8: {:?}, apic_base: {:?}, __bindgen_anon_1: {:?}, kvm_valid_regs: {:?}, kvm_dirty_regs: {:?}, s: {:?} }}",
self.request_interrupt_window,
self.immediate_exit,
self.padding1,
self.exit_reason,
self.ready_for_interrupt_injection,
self.if_flag,
self.flags,
self.cr8,
self.apic_base,
self.__bindgen_anon_1,
self.kvm_valid_regs,
self.kvm_dirty_regs,
self.s
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2693,7 +2731,11 @@ impl Default for kvm_coalesced_mmio {
}
impl ::std::fmt::Debug for kvm_coalesced_mmio {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_coalesced_mmio {{ phys_addr: {:?}, len: {:?}, __bindgen_anon_1: {:?}, data: {:?} }}" , self . phys_addr , self . len , self . __bindgen_anon_1 , self . data)
write!(
f,
"kvm_coalesced_mmio {{ phys_addr: {:?}, len: {:?}, __bindgen_anon_1: {:?}, data: {:?} }}",
self.phys_addr, self.len, self.__bindgen_anon_1, self.data
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -2895,7 +2937,11 @@ impl Default for kvm_clear_dirty_log {
}
impl ::std::fmt::Debug for kvm_clear_dirty_log {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_clear_dirty_log {{ slot: {:?}, num_pages: {:?}, first_page: {:?}, __bindgen_anon_1: {:?} }}" , self . slot , self . num_pages , self . first_page , self . __bindgen_anon_1)
write!(
f,
"kvm_clear_dirty_log {{ slot: {:?}, num_pages: {:?}, first_page: {:?}, __bindgen_anon_1: {:?} }}",
self.slot, self.num_pages, self.first_page, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down Expand Up @@ -3130,7 +3176,11 @@ impl Default for kvm_irq_routing_msi {
}
impl ::std::fmt::Debug for kvm_irq_routing_msi {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write ! (f , "kvm_irq_routing_msi {{ address_lo: {:?}, address_hi: {:?}, data: {:?}, __bindgen_anon_1: {:?} }}" , self . address_lo , self . address_hi , self . data , self . __bindgen_anon_1)
write!(
f,
"kvm_irq_routing_msi {{ address_lo: {:?}, address_hi: {:?}, data: {:?}, __bindgen_anon_1: {:?} }}",
self.address_lo, self.address_hi, self.data, self.__bindgen_anon_1
)
}
}
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion kvm-bindings/src/riscv64/fam_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use vmm_sys_util::fam::{FamStruct, FamStructWrapper};

use riscv64::bindings::*;
use crate::riscv64::bindings::*;

// There is no constant in the kernel as far as the maximum number
// of registers on RISC-V, but KVM_GET_REG_LIST usually returns around 160.
Expand Down
8 changes: 4 additions & 4 deletions kvm-bindings/src/riscv64/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use bindings::{
use crate::bindings::{
kvm_irq_routing, kvm_irq_routing_entry, kvm_irq_routing_entry__bindgen_ty_1,
kvm_irq_routing_msi__bindgen_ty_1, kvm_mp_state, kvm_one_reg, kvm_riscv_aia_csr,
kvm_riscv_config, kvm_riscv_core, kvm_riscv_csr, kvm_riscv_sbi_sta, kvm_riscv_smstateen_csr,
kvm_riscv_timer, user_regs_struct,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use zerocopy::{transmute, IntoBytes};
use zerocopy::{IntoBytes, transmute};

serde_impls! {
kvm_mp_state,
Expand Down Expand Up @@ -52,8 +52,8 @@ unsafe impl IntoBytes for kvm_irq_routing_entry__bindgen_ty_1 {

#[cfg(test)]
mod tests {
use bindings::*;
use serde::{Deserialize, Serialize};
use crate::bindings::*;
use crate::serde::{Deserialize, Serialize};

fn is_serde<T: Serialize + for<'de> Deserialize<'de> + Default>() {
let config = bincode::config::standard();
Expand Down
Loading