Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit 595a21c

Browse files
dianpopaalxiord
authored andcommitted
arm: add wrapper over kvm_reg_list
In order to be able to save/restore vcpu registers on arm, we need to support the KVM_REG_LIST ioctl. However, the structure holding the registers list has a flexible array member. This commit add a `FamStructWrapper` over the `kvm_reg_list` structure. Fixes: #20. Signed-off-by: Diana Popa <dpopa@amazon.com>
1 parent 6d77d6e commit 595a21c

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

src/arm/fam_wrappers.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use vmm_sys_util::fam::{FamStruct, FamStructWrapper};
5+
6+
use arm::bindings::*;
7+
8+
// There is no constant in the kernel as far as the maximum number
9+
// of registers on arm, but KVM_GET_REG_LIST usually returns around 450.
10+
const ARM_REGS_MAX: usize = 500;
11+
12+
// Implement the FamStruct trait for kvm_reg_list.
13+
generate_fam_struct_impl!(kvm_reg_list, u64, reg, u64, n, ARM_REGS_MAX);
14+
15+
/// Wrapper over the `kvm_reg_list` structure.
16+
///
17+
/// The `kvm_reg_list` structure contains a flexible array member. For details check the
18+
/// [KVM API](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt)
19+
/// documentation on `kvm_reg_list`. To provide safe access to
20+
/// the array elements, this type is implemented using
21+
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
22+
pub type RegList = FamStructWrapper<kvm_reg_list>;

src/arm/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#[cfg(feature = "fam-wrappers")]
5+
mod fam_wrappers;
6+
47
// Export 4.14 bindings when the feature kvm-v4_20_0 is not specified.
58
#[cfg(all(feature = "kvm-v4_14_0", not(feature = "kvm-v4_20_0")))]
69
#[allow(clippy::all)]
@@ -24,4 +27,7 @@ pub mod bindings {
2427
all(not(feature = "kvm-v4_14_0"), not(feature = "kvm-v4_20_0"))
2528
))]
2629
pub use super::bindings_v4_20_0::*;
30+
31+
#[cfg(feature = "fam-wrappers")]
32+
pub use super::fam_wrappers::*;
2733
}

src/arm64/fam_wrappers.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use vmm_sys_util::fam::{FamStruct, FamStructWrapper};
5+
6+
use arm64::bindings::*;
7+
8+
// There is no constant in the kernel as far as the maximum number
9+
// of registers on arm, but KVM_GET_REG_LIST usually returns around 450.
10+
const ARM64_REGS_MAX: usize = 500;
11+
12+
// Implement the FamStruct trait for kvm_reg_list.
13+
generate_fam_struct_impl!(kvm_reg_list, u64, reg, u64, n, ARM64_REGS_MAX);
14+
15+
/// Wrapper over the `kvm_reg_list` structure.
16+
///
17+
/// The `kvm_reg_list` structure contains a flexible array member. For details check the
18+
/// [KVM API](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt)
19+
/// documentation on `kvm_reg_list`. To provide safe access to
20+
/// the array elements, this type is implemented using
21+
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
22+
pub type RegList = FamStructWrapper<kvm_reg_list>;

src/arm64/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#[cfg(feature = "fam-wrappers")]
5+
mod fam_wrappers;
6+
47
// Export 4.14 bindings when the feature kvm-v4_20_0 is not specified.
58
#[cfg(all(feature = "kvm-v4_14_0", not(feature = "kvm-v4_20_0")))]
69
#[allow(clippy::all)]
@@ -24,4 +27,7 @@ pub mod bindings {
2427
all(not(feature = "kvm-v4_14_0"), not(feature = "kvm-v4_20_0"))
2528
))]
2629
pub use super::bindings_v4_20_0::*;
30+
31+
#[cfg(feature = "fam-wrappers")]
32+
pub use super::fam_wrappers::*;
2733
}

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
#![allow(non_snake_case)]
77

88
#[macro_use]
9-
#[cfg(all(
10-
feature = "fam-wrappers",
11-
any(target_arch = "x86", target_arch = "x86_64")
12-
))]
9+
#[cfg(feature = "fam-wrappers")]
1310
extern crate vmm_sys_util;
1411

1512
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

0 commit comments

Comments
 (0)