qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "jack.chen" <zhunxun@gmail.com>
Cc: qemu <qemu-devel@nongnu.org>, maxime.coquelin@redhat.com
Subject: Re: [Qemu-devel] vhost-user question
Date: Thu, 1 Feb 2018 09:51:18 +0000	[thread overview]
Message-ID: <20180201095118.GA2457@work-vm> (raw)
In-Reply-To: <CADUDsArE1tfNyiHB13a_GoizMn7pEoT2_s8JX7OeDuK_=xcB=A@mail.gmail.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

  reply	other threads:[~2018-02-01  9:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2018-02-01 10:17       ` jack.chen
2018-02-01 10:30         ` Dr. David Alan Gilbert
2018-02-01 10:50           ` jack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180201095118.GA2457@work-vm \
    --to=dgilbert@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhunxun@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).