Skip to content

Commit 202c2d4

Browse files
michael2012zlauralt
authored andcommitted
Add KVM_CAP_GUEST_DEBUG_HW_BPS/WPS
The API `KVM_CAP_GUEST_DEBUG_HW_BPS` and `KVM_CAP_GUEST_DEBUG_HW_WPS` are required to determine the number of supported guest debug registers. Signed-off-by: Michael Zhao <[email protected]>
1 parent 63f2f12 commit 202c2d4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/cap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ pub enum Cap {
144144
MsiDevid = KVM_CAP_MSI_DEVID,
145145
HypervSynic = KVM_CAP_HYPERV_SYNIC,
146146
HypervSynic2 = KVM_CAP_HYPERV_SYNIC2,
147+
DebugHwBps = KVM_CAP_GUEST_DEBUG_HW_BPS,
148+
DebugHwWps = KVM_CAP_GUEST_DEBUG_HW_WPS,
147149
}

src/ioctls/system.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,27 @@ impl Kvm {
9797
/// AArch64 specific call to get the host Intermediate Physical Address space limit.
9898
///
9999
/// Returns 0 if the capability is not available and an integer >= 32 otherwise.
100-
#[cfg(any(target_arch = "aarch64"))]
100+
#[cfg(target_arch = "aarch64")]
101101
pub fn get_host_ipa_limit(&self) -> i32 {
102102
self.check_extension_int(Cap::ArmVmIPASize)
103103
}
104104

105+
/// AArch64 specific call to get the number of supported hardware breakpoints.
106+
///
107+
/// Returns 0 if the capability is not available and a positive integer otherwise.
108+
#[cfg(target_arch = "aarch64")]
109+
pub fn get_guest_debug_hw_bps(&self) -> i32 {
110+
self.check_extension_int(Cap::DebugHwBps)
111+
}
112+
113+
/// AArch64 specific call to get the number of supported hardware watchpoints.
114+
///
115+
/// Returns 0 if the capability is not available and a positive integer otherwise.
116+
#[cfg(target_arch = "aarch64")]
117+
pub fn get_guest_debug_hw_wps(&self) -> i32 {
118+
self.check_extension_int(Cap::DebugHwWps)
119+
}
120+
105121
/// Wrapper over `KVM_CHECK_EXTENSION`.
106122
///
107123
/// Returns 0 if the capability is not available and a positive integer otherwise.
@@ -571,7 +587,7 @@ mod tests {
571587
}
572588

573589
#[test]
574-
#[cfg(any(target_arch = "aarch64"))]
590+
#[cfg(target_arch = "aarch64")]
575591
fn test_get_host_ipa_limit() {
576592
let kvm = Kvm::new().unwrap();
577593
let host_ipa_limit = kvm.get_host_ipa_limit();
@@ -584,6 +600,17 @@ mod tests {
584600
}
585601
}
586602

603+
#[test]
604+
#[cfg(target_arch = "aarch64")]
605+
fn test_guest_debug_hw_capacity() {
606+
let kvm = Kvm::new().unwrap();
607+
// The number of supported breakpoints and watchpoints may vary on
608+
// different platforms.
609+
// It could be 0 if no supported, or any positive integer otherwise.
610+
assert!(kvm.get_guest_debug_hw_bps() >= 0);
611+
assert!(kvm.get_guest_debug_hw_wps() >= 0);
612+
}
613+
587614
#[test]
588615
fn test_kvm_getters() {
589616
let kvm = Kvm::new().unwrap();

0 commit comments

Comments
 (0)