From c44661b4d904f8be227faef8f84ddb22934a01e8 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 23 Aug 2022 19:58:51 +0000 Subject: deploy: c94950f9dca80387aab264c7aa4044feff76625c --- src/kvm_rs/cap.rs.html | 25 ++-- src/kvm_rs/fmt.rs.html | 209 ++++++++++++++------------- src/kvm_rs/kvm.rs.html | 25 ++-- src/kvm_rs/kvm_sys.rs.html | 351 ++++++++++++++++++++++++++++++++------------- src/kvm_rs/lib.rs.html | 205 +++++++++++++------------- src/kvm_rs/vcpu.rs.html | 337 ++++++++++++++++++++++++++++++------------- src/kvm_rs/vm.rs.html | 25 ++-- src/kvm_rs/x86_64.rs.html | 213 ++++++++++++++------------- 8 files changed, 842 insertions(+), 548 deletions(-) (limited to 'src/kvm_rs') diff --git a/src/kvm_rs/cap.rs.html b/src/kvm_rs/cap.rs.html index 6add2e1..34abcf0 100644 --- a/src/kvm_rs/cap.rs.html +++ b/src/kvm_rs/cap.rs.html @@ -1,17 +1,18 @@ -cap.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
@@ -72,5 +73,5 @@
     }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/fmt.rs.html b/src/kvm_rs/fmt.rs.html index 35514e7..dffb60f 100644 --- a/src/kvm_rs/fmt.rs.html +++ b/src/kvm_rs/fmt.rs.html @@ -1,107 +1,108 @@ -fmt.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
 100
 101
 102
@@ -132,6 +133,7 @@
 127
 128
 129
+130
 
use std::fmt;
 
 use crate::kvm_sys::{kvm_dtable, kvm_regs, kvm_segment, kvm_sregs};
@@ -146,7 +148,7 @@
              r8 : {:#018x} r9 : {:#018x} r10: {:#018x} r11: {:#018x}\n\
              r12: {:#018x} r13: {:#018x} r14: {:#018x} r15: {:#018x}\n\
              rsp: {:#018x} rbp: {:#018x}\n\
-             rip: {:#018x} rfl: {:#018x} O({}) D({}) I({}) S({}) Z({}) P({}) C({})",
+             rip: {:#018x} rfl: {:#018x} O({}) D({}) I({}) T({}) S({}) Z({}) P({}) C({})",
             self.rax,
             self.rbx,
             self.rcx,
@@ -168,6 +170,7 @@
             rflags_of(self.rflags),
             rflags_df(self.rflags),
             rflags_if(self.rflags),
+            rflags_tf(self.rflags),
             rflags_sf(self.rflags),
             rflags_zf(self.rflags),
             rflags_pf(self.rflags),
@@ -262,5 +265,5 @@
     }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/kvm.rs.html b/src/kvm_rs/kvm.rs.html index 5e4b2f5..91ed733 100644 --- a/src/kvm_rs/kvm.rs.html +++ b/src/kvm_rs/kvm.rs.html @@ -1,17 +1,18 @@ -kvm.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
@@ -150,5 +151,5 @@
     }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/kvm_sys.rs.html b/src/kvm_rs/kvm_sys.rs.html index ee527a3..0557e54 100644 --- a/src/kvm_rs/kvm_sys.rs.html +++ b/src/kvm_rs/kvm_sys.rs.html @@ -1,107 +1,108 @@ -kvm_sys.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
 100
 101
 102
@@ -200,6 +201,79 @@
 195
 196
 197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
 
//! Definitions of the system header [`<linux/kvm.h>`][kvm-h].
 //!
 //! [kvm-h]: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/kvm.h
@@ -293,6 +367,32 @@
     pub userspace_addr: u64,
 }
 
+#[cfg(target_arch = "x86_64")]
+#[repr(C)]
+#[derive(Default, Debug)]
+pub struct kvm_debugregs {
+    pub db: [u64; 4],
+    pub dr6: u64,
+    pub dr7: u64,
+    pub flags: u64,
+    pub reserved: [u64; 9],
+}
+
+#[repr(C)]
+#[derive(Default, Debug)]
+pub(crate) struct kvm_guest_debug {
+    pub control: u32,
+    pad: u32,
+    pub arch: kvm_guest_debug_arch,
+}
+
+#[cfg(target_arch = "x86_64")]
+#[repr(C)]
+#[derive(Default, Debug)]
+pub(crate) struct kvm_guest_debug_arch {
+    pub debugreg: [u64; 8],
+}
+
 #[repr(C)]
 pub(crate) struct kvm_run {
     request_interrupt_window: u8,
@@ -329,11 +429,23 @@
     pub is_write: u8,
 }
 
+#[cfg(target_arch = "x86_64")]
+#[repr(C)]
+#[derive(Copy, Clone, Debug)]
+pub(crate) struct kvm_run_debug {
+    pub exception: u32,
+    pad: u32,
+    pub pc: u64,
+    pub dr6: u64,
+    pub dr7: u64,
+}
+
 // Only add the union fields used here.
 #[repr(C)]
 pub(crate) union kvm_run_union {
     pub io: kvm_run_io,
     pub mmio: kvm_run_mmio,
+    pub debug: kvm_run_debug,
     padding: [u8; 256],
 }
 
@@ -396,7 +508,42 @@
         assert_eq!(mem::size_of::<kvm_run_mmio>(), TEST_KVM_RUN_MMIO_SIZE);
         assert_eq!(mem::size_of::<kvm_run_union_s>(), TEST_KVM_RUN_UNION_S_SIZE);
     }
+
+    #[cfg(target_arch = "x86_64")]
+    #[test]
+    fn check_kvm_run_x86() {
+        assert_eq!(mem::size_of::<kvm_run_debug>(), TEST_KVM_RUN_DEBUG_SIZE);
+    }
+
+    #[cfg(target_arch = "x86_64")]
+    #[test]
+    fn check_kvm_debugregs() {
+        assert_eq!(mem::size_of::<kvm_debugregs>(), TEST_KVM_DEBUGREGS_SIZE);
+        assert_eq!(mem::align_of::<kvm_debugregs>(), TEST_KVM_DEBUGREGS_ALIGN);
+    }
+
+    #[test]
+    fn check_kvm_guest_dbg() {
+        assert_eq!(mem::size_of::<kvm_guest_debug>(), TEST_KVM_GUEST_DEBUG_SIZE);
+        assert_eq!(
+            mem::align_of::<kvm_guest_debug>(),
+            TEST_KVM_GUEST_DEBUG_ALIGN
+        );
+    }
+
+    #[cfg(target_arch = "x86_64")]
+    #[test]
+    fn check_kvm_guest_dbg_arch() {
+        assert_eq!(
+            mem::size_of::<kvm_guest_debug_arch>(),
+            TEST_KVM_GUEST_DEBUG_ARCH_SIZE
+        );
+        assert_eq!(
+            mem::align_of::<kvm_guest_debug_arch>(),
+            TEST_KVM_GUEST_DEBUG_ARCH_ALIGN
+        );
+    }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/lib.rs.html b/src/kvm_rs/lib.rs.html index 7124c68..51825a9 100644 --- a/src/kvm_rs/lib.rs.html +++ b/src/kvm_rs/lib.rs.html @@ -1,107 +1,108 @@ -lib.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
 100
 101
 102
@@ -336,5 +337,5 @@
     }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/vcpu.rs.html b/src/kvm_rs/vcpu.rs.html index 9c0da9c..43ba988 100644 --- a/src/kvm_rs/vcpu.rs.html +++ b/src/kvm_rs/vcpu.rs.html @@ -1,107 +1,108 @@ -vcpu.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
 100
 101
 102
@@ -139,6 +140,72 @@
 134
 135
 136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
 
//! VCPU system ioctls.
 
 use std::fs;
@@ -159,6 +226,7 @@
     IoOut(u16, &'cpu [u8]),
     MmioRead(u64, &'cpu mut [u8]),
     MmioWrite(u64, &'cpu [u8]),
+    Debug(u64),
 }
 
 /// Wrapper for VCPU ioctls.
@@ -227,6 +295,65 @@
         .map(|_| ())
     }
 
+    /// Get the debug registers with the [`KVM_GET_DEBUGREGS`][kvm-get-debugregs] ioctl in form of
+    /// [`kvm_debugregs`](crate::kvm_sys::kvm_debugregs).
+    ///
+    /// [kvm-get-debugregs]:
+    /// https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-get-debugregs
+    #[cfg(target_arch = "x86_64")]
+    pub fn get_debugregs(&self) -> io::Result<kvm_sys::kvm_debugregs> {
+        let mut dregs = kvm_sys::kvm_debugregs::default();
+        ioctl(
+            &self.vcpu,
+            kvm_sys::KVM_GET_DEBUGREGS,
+            &mut dregs as *mut _ as u64,
+        )?;
+        Ok(dregs)
+    }
+
+    /// Set the debug registers with the [`KVM_SET_DEBUGREGS`][kvm-set-debugregs] ioctl in form of
+    /// [`kvm_debugregs`](crate::kvm_sys::kvm_debugregs).
+    ///
+    /// [kvm-set-debugregs]:
+    /// https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-set-debugregs
+    #[cfg(target_arch = "x86_64")]
+    pub fn set_debugregs(&self, dregs: kvm_sys::kvm_debugregs) -> io::Result<()> {
+        ioctl(
+            &self.vcpu,
+            kvm_sys::KVM_SET_DEBUGREGS,
+            &dregs as *const _ as u64,
+        )
+        .map(|_| ())
+    }
+
+    /// Enable or disable guest single steppig (debug) with the
+    /// [`KVM_GUESTDBG_ENABLE`][kvm-guest-debug] ioctl.
+    ///
+    /// [kvm-guest-debug]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-set-guest-debug
+    #[cfg(target_arch = "x86_64")]
+    pub fn set_single_step(&self, enable: bool) -> io::Result<()> {
+        let mut dbg = kvm_sys::kvm_guest_debug::default();
+
+        if enable {
+            // Enable guest debugging and single stepping.
+            dbg.control = kvm_sys::KVM_GUESTDBG_ENABLE | kvm_sys::KVM_GUESTDBG_SINGLESTEP;
+        }
+
+        // Initialize debug registers based on current VCPUs debug register values.
+        let dregs = self.get_debugregs()?;
+        dbg.arch.debugreg[0..4].copy_from_slice(&dregs.db);
+        // DR4-DR5 are reserved.
+        dbg.arch.debugreg[6] = dregs.dr6;
+        dbg.arch.debugreg[7] = dregs.dr7;
+
+        ioctl(
+            &self.vcpu,
+            kvm_sys::KVM_SET_GUEST_DEBUG,
+            &dbg as *const _ as u64,
+        )
+        .map(|_| ())
+    }
+
     /// Run the guest VCPU with the [`KVM_RUN`][kvm-run] ioctl until it exits with one of the exit
     /// reasons described in [`KvmExit`](crate::vcpu::KvmExit).
     ///
@@ -269,6 +396,12 @@
                     _ => unreachable!(),
                 }
             }
+            kvm_sys::KVM_EXIT_DEBUG => {
+                // Safe to use union `debug` field, as Kernel instructed us to.
+                let debug = unsafe { kvm_run.inner.debug };
+
+                Ok(KvmExit::Debug(debug.pc))
+            }
             r @ _ => {
                 todo!("KVM_EXIT_... (exit_reason={}) not implemented!", r)
             }
@@ -276,5 +409,5 @@
     }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/vm.rs.html b/src/kvm_rs/vm.rs.html index 4218bfc..7e99ae1 100644 --- a/src/kvm_rs/vm.rs.html +++ b/src/kvm_rs/vm.rs.html @@ -1,17 +1,18 @@ -vm.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
 10
 11
 12
@@ -142,5 +143,5 @@
     }
 }
 
-
+
\ No newline at end of file diff --git a/src/kvm_rs/x86_64.rs.html b/src/kvm_rs/x86_64.rs.html index d218b2e..abfd34f 100644 --- a/src/kvm_rs/x86_64.rs.html +++ b/src/kvm_rs/x86_64.rs.html @@ -1,107 +1,108 @@ -x86_64.rs - source -
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
 100
 101
 102
@@ -162,6 +163,9 @@
 157
 158
 159
+160
+161
+162
 
//! `x86_64` flags and bitfields.
 
 pub use x86_64::*;
@@ -180,6 +184,8 @@
     pub const RFLAGS_ZF: u64 = 1 << 6;
     /// Sign flag.
     pub const RFLAGS_SF: u64 = 1 << 7;
+    /// Trap flag.
+    pub const RFLAGS_TF: u64 = 1 << 8;
     /// Sign flag.
     pub const RFLAGS_IF: u64 = 1 << 9;
     /// Direction flag.
@@ -196,6 +202,7 @@
     pub const fn rflags_af(r: u64) -> u64   { (r & RFLAGS_AF)   >> 4 }
     pub const fn rflags_zf(r: u64) -> u64   { (r & RFLAGS_ZF)   >> 6 }
     pub const fn rflags_sf(r: u64) -> u64   { (r & RFLAGS_SF)   >> 7 }
+    pub const fn rflags_tf(r: u64) -> u64   { (r & RFLAGS_TF)   >> 8 }
     pub const fn rflags_if(r: u64) -> u64   { (r & RFLAGS_IF)   >> 9 }
     pub const fn rflags_df(r: u64) -> u64   { (r & RFLAGS_DF)   >> 10 }
     pub const fn rflags_of(r: u64) -> u64   { (r & RFLAGS_OF)   >> 11 }
@@ -319,8 +326,8 @@
     /// Page region read/write.
     ///
     /// If set, region reference by paging entry is writeable.
-    pub const PAGE_RENTRY_RW: u64 = 1 << 1;
+    pub const PAGE_ENTRY_RW: u64 = 1 << 1;
 }
 
-
+
\ No newline at end of file -- cgit v1.2.3