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:
parent
1a9d3b75c6
commit
2055d112fb
1 changed files with 5 additions and 5 deletions
10
src/lib.rs
10
src/lib.rs
|
|
@ -169,7 +169,7 @@ impl<S: VhostUserBackend> VhostUserDaemon<S> {
|
|||
struct AddrMapping {
|
||||
vmm_addr: u64,
|
||||
size: u64,
|
||||
offset: u64,
|
||||
gpa_base: u64,
|
||||
}
|
||||
|
||||
struct Memory {
|
||||
|
|
@ -447,7 +447,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -525,15 +525,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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue