Skip to content

Commit 55b9481

Browse files
MrXinWangalxiord
authored andcommitted
Add support to get Host_IPA_Limit for AArch64
Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and is dependent on the CPU capability and the kernel configuration. The limit can be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION ioctl. This commit adds support for getting Host_IPA_Limit for AArch64. Signed-off-by: Henry Wang <[email protected]>
1 parent 26e62f9 commit 55b9481

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

coverage_config_aarch64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 76.2,
2+
"coverage_score": 76.9,
33
"exclude_path": "",
44
"crate_features": ""
55
}

src/cap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ pub enum Cap {
140140
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
141141
SplitIrqchip = KVM_CAP_SPLIT_IRQCHIP,
142142
ImmediateExit = KVM_CAP_IMMEDIATE_EXIT,
143+
ArmVmIPASize = KVM_CAP_ARM_VM_IPA_SIZE,
143144
}

src/ioctls/system.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ impl Kvm {
108108
unsafe { ioctl(self, KVM_GET_API_VERSION()) }
109109
}
110110

111+
/// AArch64 specific call to get the host Intermediate Physical Address space limit.
112+
///
113+
/// Returns 0 if the capability is not available and an integer larger than 32 otherwise.
114+
#[cfg(any(target_arch = "aarch64"))]
115+
pub fn get_host_ipa_limit(&self) -> i32 {
116+
self.check_extension_int(Cap::ArmVmIPASize)
117+
}
118+
111119
/// Wrapper over `KVM_CHECK_EXTENSION`.
112120
///
113121
/// Returns 0 if the capability is not available and a positive integer otherwise.
@@ -412,6 +420,20 @@ mod tests {
412420
assert!(kvm.check_extension(Cap::UserMemory));
413421
}
414422

423+
#[test]
424+
#[cfg(any(target_arch = "aarch64"))]
425+
fn test_get_host_ipa_limit() {
426+
let kvm = Kvm::new().unwrap();
427+
let host_ipa_limit = kvm.get_host_ipa_limit();
428+
429+
if host_ipa_limit > 0 {
430+
assert!(host_ipa_limit >= 32);
431+
} else {
432+
// if unsupported, the return value should be 0.
433+
assert_eq!(host_ipa_limit, 0);
434+
}
435+
}
436+
415437
#[test]
416438
fn test_kvm_getters() {
417439
let kvm = Kvm::new().unwrap();

0 commit comments

Comments
 (0)