* [Qemu-devel] vhost-user question @ 2018-01-31 11:42 jack.chen 2018-01-31 17:31 ` Dr. David Alan Gilbert 0 siblings, 1 reply; 7+ messages in thread From: jack.chen @ 2018-01-31 11:42 UTC (permalink / raw) To: qemu 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! ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] vhost-user question 2018-01-31 11:42 [Qemu-devel] vhost-user question jack.chen @ 2018-01-31 17:31 ` Dr. David Alan Gilbert 2018-02-01 2:03 ` jack.chen 0 siblings, 1 reply; 7+ messages in thread From: Dr. David Alan Gilbert @ 2018-01-31 17:31 UTC (permalink / raw) To: jack.chen; +Cc: qemu, maxime.coquelin * jack.chen (zhunxun@gmail.com) 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 / dgilbert@redhat.com / Manchester, UK ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] vhost-user question 2018-01-31 17:31 ` Dr. David Alan Gilbert @ 2018-02-01 2:03 ` jack.chen 2018-02-01 9:51 ` Dr. David Alan Gilbert 0 siblings, 1 reply; 7+ messages in thread From: jack.chen @ 2018-02-01 2:03 UTC (permalink / raw) To: Dr. David Alan Gilbert; +Cc: qemu, maxime.coquelin thanks,but I really can not understand how the fd works,can someone explain it or give me some reference material?? 2018-02-01 1:31 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat.com>: > * jack.chen (zhunxun@gmail.com) 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 / dgilbert@redhat.com / Manchester, UK ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] vhost-user question 2018-02-01 2:03 ` jack.chen @ 2018-02-01 9:51 ` Dr. David Alan Gilbert 2018-02-01 10:17 ` jack.chen 0 siblings, 1 reply; 7+ messages in thread From: Dr. David Alan Gilbert @ 2018-02-01 9:51 UTC (permalink / raw) To: jack.chen; +Cc: qemu, maxime.coquelin * jack.chen (zhunxun@gmail.com) wrote: > thanks,but I really can not understand how the fd works,can someone > explain it or give me some reference material?? Probably the man page for the mmap system call, or an introduction to linux/unix syscalls. Just remember that any shared memory will be 'backed' by a file (or something that works like a file), and if it's a file, when you open it you get a file descriptor. Once you have that fd you can map it somewhere else. Dave > > 2018-02-01 1:31 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat.com>: > > * jack.chen (zhunxun@gmail.com) 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 / dgilbert@redhat.com / Manchester, UK -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] vhost-user question 2018-02-01 9:51 ` Dr. David Alan Gilbert @ 2018-02-01 10:17 ` jack.chen 2018-02-01 10:30 ` Dr. David Alan Gilbert 0 siblings, 1 reply; 7+ messages in thread From: jack.chen @ 2018-02-01 10:17 UTC (permalink / raw) To: Dr. David Alan Gilbert; +Cc: qemu, maxime.coquelin Thanks,But my question is how the fd belonging to qemu can be used in another process such as DPDK?is fd just effective within one process? for example ,if process A open file a.txt,and it gets one fd。the fd can only be used in process A ,can it be used in process B? 2018-02-01 17:51 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat.com>: > * jack.chen (zhunxun@gmail.com) wrote: >> thanks,but I really can not understand how the fd works,can someone >> explain it or give me some reference material?? > > Probably the man page for the mmap system call, or an introduction to > linux/unix syscalls. Just remember that any shared memory will be > 'backed' by a file (or something that works like a file), and if it's a > file, when you open it you get a file descriptor. Once you have that fd > you can map it somewhere else. > > Dave > >> >> 2018-02-01 1:31 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat.com>: >> > * jack.chen (zhunxun@gmail.com) 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 / dgilbert@redhat.com / Manchester, UK > -- > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] vhost-user question 2018-02-01 10:17 ` jack.chen @ 2018-02-01 10:30 ` Dr. David Alan Gilbert 2018-02-01 10:50 ` jack 0 siblings, 1 reply; 7+ messages in thread From: Dr. David Alan Gilbert @ 2018-02-01 10:30 UTC (permalink / raw) To: jack.chen; +Cc: qemu, maxime.coquelin * jack.chen (zhunxun@gmail.com) wrote: > Thanks,But my question is how the fd belonging to qemu can be used in > another process such as DPDK?is fd just effective within one process? > for example ,if process A open file a.txt,and it gets one fd。the fd > can only be used in process A ,can it be used in process B? Both processes can use the fd - but it needs a trick. Unix sockets can pass fd's between processes - so you pass the fd down the socket and it's received on the destination - the number the fd gets is different on the two processes, but ti still represents the same underlying fd on the same file. Follow the call to vhost_user_write in vhost_user_set_mem_table you see it takes the 'fds' array, that eventually gets passed over the unix socket. Dave > 2018-02-01 17:51 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat.com>: > > * jack.chen (zhunxun@gmail.com) wrote: > >> thanks,but I really can not understand how the fd works,can someone > >> explain it or give me some reference material?? > > > > Probably the man page for the mmap system call, or an introduction to > > linux/unix syscalls. Just remember that any shared memory will be > > 'backed' by a file (or something that works like a file), and if it's a > > file, when you open it you get a file descriptor. Once you have that fd > > you can map it somewhere else. > > > > Dave > > > >> > >> 2018-02-01 1:31 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat.com>: > >> > * jack.chen (zhunxun@gmail.com) 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 / dgilbert@redhat.com / Manchester, UK > > -- > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] vhost-user question 2018-02-01 10:30 ` Dr. David Alan Gilbert @ 2018-02-01 10:50 ` jack 0 siblings, 0 replies; 7+ messages in thread From: jack @ 2018-02-01 10:50 UTC (permalink / raw) To: Dr. David Alan Gilbert Cc: qemu开发者邮件列表, maxime.coquelin that is what i really want to know,thanks very very much!!! from jack chen On 2/1/2018 18:30,[1]Dr. David Alan Gilbert<dgilbert@redhat.com> wrote: * jack.chen (zhunxun@gmail.com) wrote: > Thanks,But my question is how the fd belonging to qemu can be used in > another process such as DPDK?is fd just effective within one proce ss? > for example ,if process A open file a.txt,and it gets one fd。the f d > can only be used in process A ,can it be used in process B? Both processes can use the fd - but it needs a trick. Unix sockets can pass fd's between processes - so you pass the fd do wn the socket and it's received on the destination - the number the fd gets is different on the two processes, but ti still represents the same underlying fd on the same file. Follow the call to vhost_user_write in vhost_user_set_mem_table you see it takes the 'fds' array, that eventually gets passed over the unix socket. Dave > 2018-02-01 17:51 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redhat .com>: > > * jack.chen (zhunxun@gmail.com) wrote: > >> thanks,but I really can not understand how the fd works,can som eone > >> explain it or give me some reference material?? > > > > Probably the man page for the mmap system call, or an introducti on to > > linux/unix syscalls. Just remember that any shared memory will be > > 'backed' by a file (or something that works like a file), and if it's a > > file, when you open it you get a file descriptor. Once you have that fd > > you can map it somewhere else. > > > > Dave > > > >> > >> 2018-02-01 1:31 GMT+08:00 Dr. David Alan Gilbert <dgilbert@redh at.com>: > >> > * jack.chen (zhunxun@gmail.com) wrote: > >> >> hello,I am confused when I read vhost-user source code in qe mu.I know > >> >> vhost-user app shared memory with qemu by mmap,but why it ca n 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_add r = > >> >> reg->userspace_addr; > >> >> msg.payload.memory.regions[fd_num].memory_size = > >> >> reg->memory_size; > >> >> msg.payload.memory.regions[fd_num].guest_phys_ad dr = > >> >> 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 m map; > >> > each fd corresponds to the backing file of the memory area th at's being > >> > shared. This way the dpdk/vhost doesn't need to open those f iles 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 an d offsets. > >> > > >> > Dave > >> > > >> > -- > >> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK > > -- > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK References 1. mailto:dgilbert@redhat.com ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-02-01 10:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-01-31 11:42 [Qemu-devel] vhost-user question jack.chen 2018-01-31 17:31 ` Dr. David Alan Gilbert 2018-02-01 2:03 ` jack.chen 2018-02-01 9:51 ` Dr. David Alan Gilbert 2018-02-01 10:17 ` jack.chen 2018-02-01 10:30 ` Dr. David Alan Gilbert 2018-02-01 10:50 ` jack
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.