qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] vhost-user question


From: Dr. David Alan Gilbert
Subject: Re: [Qemu-devel] vhost-user question
Date: Wed, 31 Jan 2018 17:31:55 +0000
User-agent: Mutt/1.9.1 (2017-09-22)

* jack.chen (address@hidden) wrote:
> hello,I am confused when I read vhost-user source code in qemu.I know
> vhost-user app shared memory with qemu by mmap,but why it can use fd which
> is belong to qemu?
> relative code:
>  qemu code in function vhost_user_set_mem_table
> fd = memory_region_get_fd(mr);
>         if (fd > 0) {
>             msg.payload.memory.regions[fd_num].userspace_addr =
> reg->userspace_addr;
>             msg.payload.memory.regions[fd_num].memory_size  =
> reg->memory_size;
>             msg.payload.memory.regions[fd_num].guest_phys_addr =
> reg->guest_phys_addr;
>             msg.payload.memory.regions[fd_num].mmap_offset = offset;
>             assert(fd_num < VHOST_MEMORY_MAX_NREGIONS);
>             fds[fd_num++] = fd;
>         }
> 
> ……
> DPDK code in vhost_user_set_mem_table
> 
> mmap_addr = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
> MAP_SHARED | MAP_POPULATE, fd, 0);
> ……
> 
> thanks a lot!

Because that's how the dpdk/vhost-user binary knows what to mmap;
each fd corresponds to the backing file of the memory area that's being
shared.  This way the dpdk/vhost doesn't need to open those files itself
or try and match the exact memory configuration of qemu; QEMU just gives
it the exact thing it needs to mmap - which is just the fd and offsets.

Dave

--
Dr. David Alan Gilbert / address@hidden / Manchester, UK



reply via email to

[Prev in Thread] Current Thread [Next in Thread]