Skip to content

Commit fe315c9

Browse files
bchaliosShadowCurse
authored andcommitted
serde: add support for kvm_irq_routing
Add serde support for kvm_irq_routing and kvm_irq_routing_entry type. Signed-off-by: Babis Chalios <bchalios@amazon.es>
1 parent 1fb9925 commit fe315c9

File tree

6 files changed

+205
-11
lines changed

6 files changed

+205
-11
lines changed

kvm-bindings/src/arm64/bindings.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* automatically generated by rust-bindgen 0.70.1 */
22

3-
#[repr(C)]
3+
#[repr(transparent)]
44
#[derive(Default)]
5+
#[cfg_attr(
6+
feature = "serde",
7+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
8+
)]
59
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
610
impl<T> __IncompleteArrayField<T> {
711
#[inline]
@@ -3141,6 +3145,10 @@ impl Default for kvm_enable_cap {
31413145
}
31423146
#[repr(C)]
31433147
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3148+
#[cfg_attr(
3149+
feature = "serde",
3150+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3151+
)]
31443152
pub struct kvm_irq_routing_irqchip {
31453153
pub irqchip: __u32,
31463154
pub pin: __u32,
@@ -3157,6 +3165,10 @@ const _: () = {
31573165
};
31583166
#[repr(C)]
31593167
#[derive(Copy, Clone)]
3168+
#[cfg_attr(
3169+
feature = "serde",
3170+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3171+
)]
31603172
pub struct kvm_irq_routing_msi {
31613173
pub address_lo: __u32,
31623174
pub address_hi: __u32,
@@ -3165,6 +3177,7 @@ pub struct kvm_irq_routing_msi {
31653177
}
31663178
#[repr(C)]
31673179
#[derive(Copy, Clone)]
3180+
#[cfg_attr(feature = "serde", derive(zerocopy::Immutable, zerocopy::FromBytes))]
31683181
pub union kvm_irq_routing_msi__bindgen_ty_1 {
31693182
pub pad: __u32,
31703183
pub devid: __u32,
@@ -3221,6 +3234,10 @@ impl ::std::fmt::Debug for kvm_irq_routing_msi {
32213234
}
32223235
#[repr(C)]
32233236
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3237+
#[cfg_attr(
3238+
feature = "serde",
3239+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3240+
)]
32243241
pub struct kvm_irq_routing_s390_adapter {
32253242
pub ind_addr: __u64,
32263243
pub summary_addr: __u64,
@@ -3247,6 +3264,10 @@ const _: () = {
32473264
};
32483265
#[repr(C)]
32493266
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3267+
#[cfg_attr(
3268+
feature = "serde",
3269+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3270+
)]
32503271
pub struct kvm_irq_routing_hv_sint {
32513272
pub vcpu: __u32,
32523273
pub sint: __u32,
@@ -3263,6 +3284,10 @@ const _: () = {
32633284
};
32643285
#[repr(C)]
32653286
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3287+
#[cfg_attr(
3288+
feature = "serde",
3289+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3290+
)]
32663291
pub struct kvm_irq_routing_xen_evtchn {
32673292
pub port: __u32,
32683293
pub vcpu: __u32,
@@ -3283,6 +3308,10 @@ const _: () = {
32833308
};
32843309
#[repr(C)]
32853310
#[derive(Copy, Clone)]
3311+
#[cfg_attr(
3312+
feature = "serde",
3313+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3314+
)]
32863315
pub struct kvm_irq_routing_entry {
32873316
pub gsi: __u32,
32883317
pub type_: __u32,
@@ -3292,6 +3321,7 @@ pub struct kvm_irq_routing_entry {
32923321
}
32933322
#[repr(C)]
32943323
#[derive(Copy, Clone)]
3324+
#[cfg_attr(feature = "serde", derive(zerocopy::Immutable, zerocopy::FromBytes))]
32953325
pub union kvm_irq_routing_entry__bindgen_ty_1 {
32963326
pub irqchip: kvm_irq_routing_irqchip,
32973327
pub msi: kvm_irq_routing_msi,
@@ -3368,6 +3398,10 @@ impl ::std::fmt::Debug for kvm_irq_routing_entry {
33683398
}
33693399
}
33703400
#[repr(C)]
3401+
#[cfg_attr(
3402+
feature = "serde",
3403+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3404+
)]
33713405
pub struct kvm_irq_routing {
33723406
pub nr: __u32,
33733407
pub flags: __u32,

kvm-bindings/src/arm64/serialize.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use bindings::{
2-
kvm_mp_state, kvm_one_reg, kvm_regs, kvm_vcpu_init, user_fpsimd_state, user_pt_regs,
2+
kvm_irq_routing, kvm_irq_routing_entry, kvm_irq_routing_entry__bindgen_ty_1,
3+
kvm_irq_routing_msi__bindgen_ty_1, kvm_mp_state, kvm_one_reg, kvm_regs, kvm_vcpu_init,
4+
user_fpsimd_state, user_pt_regs,
35
};
46
use serde::{Deserialize, Deserializer, Serialize, Serializer};
57
use zerocopy::{transmute, IntoBytes};
@@ -10,7 +12,33 @@ serde_impls! {
1012
kvm_regs,
1113
kvm_vcpu_init,
1214
kvm_mp_state,
13-
kvm_one_reg
15+
kvm_one_reg,
16+
kvm_irq_routing,
17+
kvm_irq_routing_entry
18+
}
19+
20+
// SAFETY: zerocopy's derives explicitly disallow deriving for unions where
21+
// the fields have different sizes, due to the smaller fields having padding.
22+
// Miri however does not complain about these implementations (e.g. about
23+
// reading the "padding" for one union field as valid data for a bigger one)
24+
unsafe impl IntoBytes for kvm_irq_routing_msi__bindgen_ty_1 {
25+
fn only_derive_is_allowed_to_implement_this_trait()
26+
where
27+
Self: Sized,
28+
{
29+
}
30+
}
31+
32+
// SAFETY: zerocopy's derives explicitly disallow deriving for unions where
33+
// the fields have different sizes, due to the smaller fields having padding.
34+
// Miri however does not complain about these implementations (e.g. about
35+
// reading the "padding" for one union field as valid data for a bigger one)
36+
unsafe impl IntoBytes for kvm_irq_routing_entry__bindgen_ty_1 {
37+
fn only_derive_is_allowed_to_implement_this_trait()
38+
where
39+
Self: Sized,
40+
{
41+
}
1442
}
1543

1644
#[cfg(test)]
@@ -58,6 +86,8 @@ mod tests {
5886
is_serde::<kvm_vcpu_init>();
5987
is_serde::<kvm_mp_state>();
6088
is_serde::<kvm_one_reg>();
89+
is_serde::<kvm_irq_routing>();
90+
is_serde::<kvm_irq_routing_entry>();
6191
}
6292

6393
fn is_serde_json<T: Serialize + for<'de> Deserialize<'de> + Default>() {
@@ -77,5 +107,7 @@ mod tests {
77107
is_serde_json::<kvm_vcpu_init>();
78108
is_serde_json::<kvm_mp_state>();
79109
is_serde_json::<kvm_one_reg>();
110+
is_serde_json::<kvm_irq_routing>();
111+
is_serde_json::<kvm_irq_routing_entry>();
80112
}
81113
}

kvm-bindings/src/riscv64/bindings.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* automatically generated by rust-bindgen 0.70.1 */
22

3-
#[repr(C)]
3+
#[repr(transparent)]
44
#[derive(Default)]
5+
#[cfg_attr(
6+
feature = "serde",
7+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
8+
)]
59
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
610
impl<T> __IncompleteArrayField<T> {
711
#[inline]
@@ -3021,6 +3025,10 @@ impl Default for kvm_enable_cap {
30213025
}
30223026
#[repr(C)]
30233027
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3028+
#[cfg_attr(
3029+
feature = "serde",
3030+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3031+
)]
30243032
pub struct kvm_irq_routing_irqchip {
30253033
pub irqchip: __u32,
30263034
pub pin: __u32,
@@ -3037,6 +3045,10 @@ const _: () = {
30373045
};
30383046
#[repr(C)]
30393047
#[derive(Copy, Clone)]
3048+
#[cfg_attr(
3049+
feature = "serde",
3050+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3051+
)]
30403052
pub struct kvm_irq_routing_msi {
30413053
pub address_lo: __u32,
30423054
pub address_hi: __u32,
@@ -3045,6 +3057,7 @@ pub struct kvm_irq_routing_msi {
30453057
}
30463058
#[repr(C)]
30473059
#[derive(Copy, Clone)]
3060+
#[cfg_attr(feature = "serde", derive(zerocopy::Immutable, zerocopy::FromBytes))]
30483061
pub union kvm_irq_routing_msi__bindgen_ty_1 {
30493062
pub pad: __u32,
30503063
pub devid: __u32,
@@ -3101,6 +3114,10 @@ impl ::std::fmt::Debug for kvm_irq_routing_msi {
31013114
}
31023115
#[repr(C)]
31033116
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3117+
#[cfg_attr(
3118+
feature = "serde",
3119+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3120+
)]
31043121
pub struct kvm_irq_routing_s390_adapter {
31053122
pub ind_addr: __u64,
31063123
pub summary_addr: __u64,
@@ -3127,6 +3144,10 @@ const _: () = {
31273144
};
31283145
#[repr(C)]
31293146
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3147+
#[cfg_attr(
3148+
feature = "serde",
3149+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3150+
)]
31303151
pub struct kvm_irq_routing_hv_sint {
31313152
pub vcpu: __u32,
31323153
pub sint: __u32,
@@ -3143,6 +3164,10 @@ const _: () = {
31433164
};
31443165
#[repr(C)]
31453166
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3167+
#[cfg_attr(
3168+
feature = "serde",
3169+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3170+
)]
31463171
pub struct kvm_irq_routing_xen_evtchn {
31473172
pub port: __u32,
31483173
pub vcpu: __u32,
@@ -3163,6 +3188,10 @@ const _: () = {
31633188
};
31643189
#[repr(C)]
31653190
#[derive(Copy, Clone)]
3191+
#[cfg_attr(
3192+
feature = "serde",
3193+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3194+
)]
31663195
pub struct kvm_irq_routing_entry {
31673196
pub gsi: __u32,
31683197
pub type_: __u32,
@@ -3172,6 +3201,7 @@ pub struct kvm_irq_routing_entry {
31723201
}
31733202
#[repr(C)]
31743203
#[derive(Copy, Clone)]
3204+
#[cfg_attr(feature = "serde", derive(zerocopy::Immutable, zerocopy::FromBytes))]
31753205
pub union kvm_irq_routing_entry__bindgen_ty_1 {
31763206
pub irqchip: kvm_irq_routing_irqchip,
31773207
pub msi: kvm_irq_routing_msi,
@@ -3248,6 +3278,10 @@ impl ::std::fmt::Debug for kvm_irq_routing_entry {
32483278
}
32493279
}
32503280
#[repr(C)]
3281+
#[cfg_attr(
3282+
feature = "serde",
3283+
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3284+
)]
32513285
pub struct kvm_irq_routing {
32523286
pub nr: __u32,
32533287
pub flags: __u32,

kvm-bindings/src/riscv64/serialize.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
use bindings::{
6-
kvm_mp_state, kvm_one_reg, kvm_riscv_aia_csr, kvm_riscv_config, kvm_riscv_core, kvm_riscv_csr,
7-
kvm_riscv_sbi_sta, kvm_riscv_smstateen_csr, kvm_riscv_timer, user_regs_struct,
6+
kvm_irq_routing, kvm_irq_routing_entry, kvm_irq_routing_entry__bindgen_ty_1,
7+
kvm_irq_routing_msi__bindgen_ty_1, kvm_mp_state, kvm_one_reg, kvm_riscv_aia_csr,
8+
kvm_riscv_config, kvm_riscv_core, kvm_riscv_csr, kvm_riscv_sbi_sta, kvm_riscv_smstateen_csr,
9+
kvm_riscv_timer, user_regs_struct,
810
};
911
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1012
use zerocopy::{transmute, IntoBytes};
@@ -19,7 +21,33 @@ serde_impls! {
1921
kvm_riscv_aia_csr,
2022
kvm_riscv_smstateen_csr,
2123
kvm_riscv_timer,
22-
kvm_riscv_sbi_sta
24+
kvm_riscv_sbi_sta,
25+
kvm_irq_routing,
26+
kvm_irq_routing_entry
27+
}
28+
29+
// SAFETY: zerocopy's derives explicitly disallow deriving for unions where
30+
// the fields have different sizes, due to the smaller fields having padding.
31+
// Miri however does not complain about these implementations (e.g. about
32+
// reading the "padding" for one union field as valid data for a bigger one)
33+
unsafe impl IntoBytes for kvm_irq_routing_msi__bindgen_ty_1 {
34+
fn only_derive_is_allowed_to_implement_this_trait()
35+
where
36+
Self: Sized,
37+
{
38+
}
39+
}
40+
41+
// SAFETY: zerocopy's derives explicitly disallow deriving for unions where
42+
// the fields have different sizes, due to the smaller fields having padding.
43+
// Miri however does not complain about these implementations (e.g. about
44+
// reading the "padding" for one union field as valid data for a bigger one)
45+
unsafe impl IntoBytes for kvm_irq_routing_entry__bindgen_ty_1 {
46+
fn only_derive_is_allowed_to_implement_this_trait()
47+
where
48+
Self: Sized,
49+
{
50+
}
2351
}
2452

2553
#[cfg(test)]
@@ -71,6 +99,8 @@ mod tests {
7199
is_serde::<kvm_riscv_smstateen_csr>();
72100
is_serde::<kvm_riscv_timer>();
73101
is_serde::<kvm_riscv_sbi_sta>();
102+
is_serde::<kvm_irq_routing>();
103+
is_serde::<kvm_irq_routing_entry>();
74104
}
75105

76106
fn is_serde_json<T: Serialize + for<'de> Deserialize<'de> + Default>() {
@@ -96,5 +126,7 @@ mod tests {
96126
is_serde_json::<kvm_riscv_smstateen_csr>();
97127
is_serde_json::<kvm_riscv_timer>();
98128
is_serde_json::<kvm_riscv_sbi_sta>();
129+
is_serde_json::<kvm_irq_routing>();
130+
is_serde_json::<kvm_irq_routing_entry>();
99131
}
100132
}

0 commit comments

Comments
 (0)