vhost_user_backend: fix memory region offsetting

The way in which offsets are currently use in memory regions is
derived from QEMU's contrib/libvhost-user, but while this one works
mainly by translating vmm va's to local va's, vm-memory expects us to
use proper guest addresses and thus, define memory regions that
actually match the guest's memory disposition.

With this change, we create the memory regions with the proper length
and offsets, extend AddrMapping to store the guest physical address,
and use the latter instead of offset in vmm_va_to_gpa().

Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
Sergio Lopez 2019-11-28 12:56:35 +01:00 committed by Sebastien Boeuf
parent d378da64ee
commit 669d9a8ae8

View File

@ -169,7 +169,7 @@ impl<S: VhostUserBackend> VhostUserDaemon<S> {
struct AddrMapping {
vmm_addr: u64,
size: u64,
offset: u64,
gpa_base: u64,
}
struct Memory {
@ -446,7 +446,7 @@ impl<S: VhostUserBackend> VhostUserHandler<S> {
if let Some(memory) = &self.memory {
for mapping in memory.mappings.iter() {
if vmm_va >= mapping.vmm_addr && vmm_va < mapping.vmm_addr + mapping.size {
return Ok(vmm_va - mapping.vmm_addr + mapping.offset);
return Ok(vmm_va - mapping.vmm_addr + mapping.gpa_base);
}
}
}
@ -524,15 +524,15 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandler for VhostUserHandler<S> {
for (idx, region) in ctx.iter().enumerate() {
let g_addr = GuestAddress(region.guest_phys_addr);
let len = (region.memory_size + region.mmap_offset) as usize;
let len = region.memory_size as usize;
let file = unsafe { File::from_raw_fd(fds[idx]) };
let f_off = FileOffset::new(file, 0);
let f_off = FileOffset::new(file, region.mmap_offset);
regions.push((g_addr, len, Some(f_off)));
mappings.push(AddrMapping {
vmm_addr: region.user_addr,
size: region.memory_size,
offset: region.mmap_offset,
gpa_base: region.guest_phys_addr,
});
}