Skip to content
Merged
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[workspace]
resolver = "2"
package.edition = "2024"
package.rust-version = "1.85"
resolver = "3"
members = [
"kvm-bindings",
"kvm-ioctls",
Expand Down
3 changes: 3 additions & 0 deletions kvm-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Upcoming Release

### Changed
- Rust edition 2024

## v0.13.0

### Added
Expand Down
10 changes: 5 additions & 5 deletions kvm-bindings/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

### Bindgen
The bindings are currently generated using
[bindgen](https://crates.io/crates/bindgen) version 0.70.1:
[bindgen](https://crates.io/crates/bindgen) version 0.72.0:
```bash
cargo install bindgen-cli --vers 0.70.1
cargo install bindgen-cli --vers 0.72.0
```

### Linux Kernel
Generating bindings depends on the Linux kernel, so you need to have the
repository on your machine. Replace `v6.9` with the kernel release for
repository on your machine. Replace `v6.16` with the kernel release for
which you wish to generate bindings:

```bash
Expand All @@ -23,7 +23,7 @@ git clone https://github.com/torvalds/linux.git --branch v6.9 --depth 1
When adding a new architecture, the bindings must be generated for all existing
versions for consistency reasons.

### Example for arm64 and kernel version 6.9
### Example for arm64 and kernel version 6.16

For this example we assume that you have both linux and kvm-bindings
repositories in your root.
Expand All @@ -44,7 +44,7 @@ export ARCH=arm64
make headers_install ARCH=$ARCH INSTALL_HDR_PATH="$ARCH"_headers
pushd "$ARCH"_headers
bindgen include/linux/kvm.h -o bindings.rs \
--impl-debug --with-derive-default \
--impl-debug --with-derive-default --rust-edition 2024 \
--with-derive-partialeq --impl-partialeq \
-- -Iinclude
popd
Expand Down
2 changes: 2 additions & 0 deletions kvm-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ repository = "https://github.com/rust-vmm/kvm"
readme = "README.md"
keywords = ["kvm"]
license = "Apache-2.0"
edition.workspace = true
rust-version.workspace = true

[package.metadata.docs.rs]
all-features = true
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 super::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
6 changes: 3 additions & 3 deletions kvm-bindings/src/arm64/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bindings::{
use super::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,7 +43,7 @@ unsafe impl IntoBytes for kvm_irq_routing_entry__bindgen_ty_1 {

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

fn is_serde<T: Serialize + for<'de> Deserialize<'de> + Default>() {
Expand Down
1 change: 1 addition & 0 deletions kvm-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![deny(clippy::undocumented_unsafe_blocks)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

#[cfg(feature = "fam-wrappers")]
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 super::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
Loading