qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: William Tu <u9012063@gmail.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] Question about libvhost-user and vhost-user-bridge.c
Date: Thu, 15 Aug 2019 09:25:45 -0700	[thread overview]
Message-ID: <CALDO+SZXLvktEhJxL62b9vUuMw9RWj=wzvqpy==X1eDy_ZzSSw@mail.gmail.com> (raw)
In-Reply-To: <20190815140744.GE10996@stefanha-x1.localdomain>

Hi Stefan,

Thanks for your reply.

On Thu, Aug 15, 2019 at 7:07 AM Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Wed, Aug 14, 2019 at 10:54:34AM -0700, William Tu wrote:
> > Hi,
> >
> > I'm using libvhost-user.a to write a vhost backend, in order to receive and
> > send packets from/to VMs from OVS. I started by reading the vhost-user-bridge.c.
> > I can now pass the initialization stage, seeing .queue_set_started get invoked.
> >
> > However, I am stuck at receiving the packet from VM.
> > So is it correct to do:
> > 1) check vu_queue_empty, started, and aval_bytes, if OK, then
>
> This step can be skipped because vu_queue_pop() returns NULL if there
> are no virtqueue elements available.
>
> > 2) elem = vu_queue_pop(&dev->vudev, vq, sizeof(VuVirtqElement));
> > 3) the packet payload should be at elem->in_sg->iov_base + hdrlen? or
> > at elem->out_sg?
>
> The driver->device buffers are elem->out_sg and the device->driver
> buffers are elem->in_sg.

OK, thanks. Then for vswitch to receive from qemu, I should check
device->driver.
>
> Device implementations must not make assumptions about the layout of
> out_sg and in_sg (e.g. you cannot assume that in_sg[0]->iov_len ==
> sizeof(struct virtio_net_hdr) and you must handle the case where
> in_sg[0]->iov_len == 1).

OK so I might need to copy to a single continuous buffer.

>
> > I tried to hex dump the iov_base, but the content doesn't look like
> > having a ethernet header. I saw in vubr_backend_recv_cb at vhost-user-bridge.c,
> > we're creating another iovec and recvmsg(vubr->backend_udp_sock, &msg, 0);
> > I don't think I have to create backend UDP sock, am I correct?
>
> Please see the VIRTIO specification for details of the virtio-net rx/tx
> virtqueue formats:
> https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1-2050006
>
> I think you may need to handle the struct virtio_net_hdr that comes
> before the Ethernet header.

Thank, will look at it.
William
>
> Stefan


      reply	other threads:[~2019-08-15 16:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-14 17:54 [Qemu-devel] Question about libvhost-user and vhost-user-bridge.c William Tu
2019-08-15 14:07 ` Stefan Hajnoczi
2019-08-15 16:25   ` William Tu [this message]

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='CALDO+SZXLvktEhJxL62b9vUuMw9RWj=wzvqpy==X1eDy_ZzSSw@mail.gmail.com' \
    --to=u9012063@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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).