From 3fd74b84076488ae44ba5f3cfed22ff056c5199c Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Thu, 26 Jun 2014 23:01:32 +0200 Subject: vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message Old code was affected by memory gaps which resulted in buffer pointers pointing to address outside of the mapped regions. Here we are introducing following changes: - new function qemu_get_ram_block_host_ptr() returns host pointer to the ram block, it is needed to calculate offset of specific region in the host memory - new field mmap_offset is added to the VhostUserMemoryRegion. It contains offset where specific region starts in the mapped memory. As there is stil no wider adoption of vhost-user agreement was made that we will not bump version number due to this change - other fileds in VhostUserMemoryRegion struct are not changed, as they are all needed for usermode app implementation - region data is not taken from ram_list.blocks anymore, instead we use region data which is alredy calculated for use in vhost-net - Now multiple regions can have same FD and user applicaton can call mmap() multiple times with the same FD but with different offset (user needs to take care for offset page alignment) Signed-off-by: Damjan Marion Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Signed-off-by: Damjan Marion --- exec.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'exec.c') diff --git a/exec.c b/exec.c index c8494051a6..a94c5832f4 100644 --- a/exec.c +++ b/exec.c @@ -1456,6 +1456,13 @@ int qemu_get_ram_fd(ram_addr_t addr) return block->fd; } +void *qemu_get_ram_block_host_ptr(ram_addr_t addr) +{ + RAMBlock *block = qemu_get_ram_block(addr); + + return block->host; +} + /* Return a host pointer to ram allocated with qemu_ram_alloc. With the exception of the softmmu code in this file, this should only be used for local memory (e.g. video ram) that the device owns, -- cgit v1.2.1