aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2021-12-10 23:47:04 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2021-12-10 23:47:04 +0100
commit1be06acc235878253977ae75467db591763f31bf (patch)
tree25b80c85f69ab515939cc059c7bec3eb04771a38
parent25b430f13a828f6e83c309e6bff9b5d2f0d85b0d (diff)
downloadmini-kvm-rs-1be06acc235878253977ae75467db591763f31bf.tar.gz
mini-kvm-rs-1be06acc235878253977ae75467db591763f31bf.zip
example:long_mode: Assert phys memory against bytes written from guest to virt address.
-rw-r--r--examples/long_mode.rs10
-rw-r--r--guest/guest64.S6
2 files changed, 16 insertions, 0 deletions
diff --git a/examples/long_mode.rs b/examples/long_mode.rs
index 6d52abe..06af791 100644
--- a/examples/long_mode.rs
+++ b/examples/long_mode.rs
@@ -6,6 +6,7 @@ use kvm_rs::{PhysAddr, UserMem};
fn setup_long_mode_segments(sregs: &mut kvm_sys::kvm_sregs) {
let code_seg = |seg: &mut kvm_sys::kvm_segment| {
+ // Segment base address (unused in 64bit).
seg.base = 0x0;
// Limit (unused in 64bit).
seg.limit = 0x0;
@@ -28,6 +29,7 @@ fn setup_long_mode_segments(sregs: &mut kvm_sys::kvm_sregs) {
};
let data_seg = |seg: &mut kvm_sys::kvm_segment| {
+ // Segment base address (unused in 64bit).
seg.base = 0x0;
// Limit (unused in 64bit).
seg.limit = 0x0;
@@ -182,5 +184,13 @@ fn main() -> std::io::Result<()> {
};
}
+ // The guest writes at virtual address [0x2000 - 0x2003] which will be visible in physical
+ // memory at [0x6000 - 0x6003] due to the paging structure we setup.
+ // See `setup_long_mode_4level_paging` above for details.
+ assert_eq!(
+ &mem.as_ref()[0x4000 + 0x2000..][..4],
+ &[0xaa, 0xbb, 0xcc, 0xdd]
+ );
+
Ok(())
}
diff --git a/guest/guest64.S b/guest/guest64.S
index 6629273..a07df0c 100644
--- a/guest/guest64.S
+++ b/guest/guest64.S
@@ -12,6 +12,12 @@
lea di, [in_dest] // Destination address.
insb // Read byte from input port dx to ds:di.
+ // Write to allocated virtual addresses.
+ mov byte ptr ds:[0x2000], 0xaa
+ mov byte ptr ds:[0x2001], 0xbb
+ mov byte ptr ds:[0x2002], 0xcc
+ mov byte ptr ds:[0x2003], 0xdd
+
// Trigger `KVM_EXIT_HLT`.
hlt