Skip to content

Commit a27d964

Browse files
bchaliosJonathanWoollett-Light
authored andcommitted
Add capabilities for pointer authentication
Add the capabilities for pointer authentication in Aarch64, KVM_CAP_ARM_PTRAUTH_GENERIC and KVM_CAP_ARM_PTRAUTH_ADDRESS. Also, add a unit test for checking the existence of capabilities and try to enable the feature in the vcpu initialization if present. Signed-off-by: Babis Chalios <[email protected]>
1 parent 4bb7199 commit a27d964

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
of `Cap` enum.
77
- [[#228](https://github.com/rust-vmm/kvm-ioctls/pull/228)] arm64: add
88
support for vCPU SVE feature.
9+
- [[#219](https://github.com/rust-vmm/kvm-ioctls/pull/226)] Add `Cap::ArmPtrAuthAddress`
10+
and `Cap::ArmPtrAuthGeneric` capabilities.
911

1012
# v0.14.0
1113

src/cap.rs

+4
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,8 @@ pub enum Cap {
150150
GetMsrFeatures = KVM_CAP_GET_MSR_FEATURES,
151151
#[cfg(target_arch = "aarch64")]
152152
ArmSve = KVM_CAP_ARM_SVE,
153+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
154+
ArmPtrAuthAddress = KVM_CAP_ARM_PTRAUTH_ADDRESS,
155+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
156+
ArmPtrAuthGeneric = KVM_CAP_ARM_PTRAUTH_GENERIC,
153157
}

src/ioctls/vcpu.rs

+19
Original file line numberDiff line numberDiff line change
@@ -2785,4 +2785,23 @@ mod tests {
27852785
assert!(vcpu.has_device_attr(&dist_attr).is_ok());
27862786
assert!(vcpu.set_device_attr(&dist_attr).is_ok());
27872787
}
2788+
2789+
#[test]
2790+
#[cfg(target_arch = "aarch64")]
2791+
fn test_pointer_authentication() {
2792+
let kvm = Kvm::new().unwrap();
2793+
let vm = kvm.create_vm().unwrap();
2794+
let vcpu = vm.create_vcpu(0).unwrap();
2795+
2796+
let mut kvi: kvm_bindings::kvm_vcpu_init = kvm_bindings::kvm_vcpu_init::default();
2797+
vm.get_preferred_target(&mut kvi)
2798+
.expect("Cannot get preferred target");
2799+
if kvm.check_extension(Cap::ArmPtrAuthAddress) {
2800+
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PTRAUTH_ADDRESS;
2801+
}
2802+
if kvm.check_extension(Cap::ArmPtrAuthGeneric) {
2803+
kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PTRAUTH_GENERIC;
2804+
}
2805+
assert!(vcpu.vcpu_init(&kvi).is_ok());
2806+
}
27882807
}

0 commit comments

Comments
 (0)