From c47e3b8689c092acc8774616a6d56ca2ac78dc76 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 4 May 2022 15:22:27 +0100 Subject: [PATCH] gdb: Do not use VmmOps for memory manipulation We don't use the VmmOps trait directly for manipulating memory in the core of the VMM as it's really designed for the MSHV crate to handle instruction decoding. As I plan to make this trait MSHV specific to allow reduced locking for MMIO and PIO handling when running on KVM this use should be removed. Signed-off-by: Rob Bradford --- vmm/src/cpu.rs | 19 +++++++++++-------- vmm/src/gdb.rs | 9 ++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 0acdf48df..e82ab2e69 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -46,8 +46,9 @@ use std::sync::{Arc, Barrier, Mutex}; use std::{cmp, io, result, thread}; use thiserror::Error; use vm_device::BusDevice; -use vm_memory::GuestAddress; -use vm_memory::GuestMemoryAtomic; +#[cfg(feature = "gdb")] +use vm_memory::{Bytes, GuestAddressSpace}; +use vm_memory::{GuestAddress, GuestMemoryAtomic}; use vm_migration::{ Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable, Transportable, @@ -2046,10 +2047,11 @@ impl Debuggable for CpuManager { }; let psize = arch::PAGE_SIZE as u64; let read_len = std::cmp::min(len as u64 - total_read, psize - (paddr & (psize - 1))); - self.vmmops - .guest_mem_read( - paddr, + self.vm_memory + .memory() + .read( &mut buf[total_read as usize..total_read as usize + read_len as usize], + GuestAddress(paddr), ) .map_err(DebuggableError::ReadMem)?; total_read += read_len; @@ -2078,10 +2080,11 @@ impl Debuggable for CpuManager { data.len() as u64 - total_written, psize - (paddr & (psize - 1)), ); - self.vmmops - .guest_mem_write( - paddr, + self.vm_memory + .memory() + .write( &data[total_written as usize..total_written as usize + write_len as usize], + GuestAddress(paddr), ) .map_err(DebuggableError::WriteMem)?; total_written += write_len; diff --git a/vmm/src/gdb.rs b/vmm/src/gdb.rs index 0c5a7ad8c..cf1c01f0c 100644 --- a/vmm/src/gdb.rs +++ b/vmm/src/gdb.rs @@ -5,8 +5,6 @@ // // SPDX-License-Identifier: BSD-3-Clause -use std::{os::unix::net::UnixListener, sync::mpsc}; - use gdbstub::{ arch::Arch, common::{Signal, Tid}, @@ -30,7 +28,8 @@ use gdbstub::{ use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs; #[cfg(target_arch = "x86_64")] use gdbstub_arch::x86::X86_64_SSE as GdbArch; -use vm_memory::GuestAddress; +use std::{os::unix::net::UnixListener, sync::mpsc}; +use vm_memory::{GuestAddress, GuestMemoryError}; #[cfg(target_arch = "x86_64")] type ArchUsize = u64; @@ -42,8 +41,8 @@ pub enum DebuggableError { Resume(vm_migration::MigratableError), ReadRegs(crate::cpu::Error), WriteRegs(crate::cpu::Error), - ReadMem(hypervisor::HypervisorVmError), - WriteMem(hypervisor::HypervisorVmError), + ReadMem(GuestMemoryError), + WriteMem(GuestMemoryError), TranslateGva(crate::cpu::Error), PoisonedState, }