Skip to content

Commit

Permalink
fix(mmio): handle unaligned and partial read/write
Browse files Browse the repository at this point in the history
Signed-off-by: Changyuan Lyu <[email protected]>
  • Loading branch information
Lencerf committed Nov 18, 2024
1 parent b32061f commit 8df69f1
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 16 deletions.
247 changes: 239 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ assert_matches = "1"
proc-macro2 = "1"
syn = { version = "2", features = ["full"] }
quote = { version = "1" }
rstest = "0.23"

[profile.release]
lto = true
Expand Down
1 change: 1 addition & 0 deletions alioth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ io-uring = "0.7"

[dev-dependencies]
assert_matches.workspace = true
rstest.workspace = true
3 changes: 1 addition & 2 deletions alioth/src/hv/kvm/vmexit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ impl KvmVcpu {
#[cfg(target_endian = "little")]
pub(super) fn handle_mmio(&mut self) -> Result<VmExit, Error> {
let kvm_mmio = unsafe { &self.kvm_run.exit.mmio };
let data = u64::from_ne_bytes(kvm_mmio.data) & u64::MAX >> (64 - (kvm_mmio.len << 3));
let exit = VmExit::Mmio {
addr: kvm_mmio.phys_addr,
write: if kvm_mmio.is_write > 0 {
Some(data)
Some(u64::from_ne_bytes(kvm_mmio.data))
} else {
None
},
Expand Down
Loading

0 comments on commit 8df69f1

Please sign in to comment.