QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [Qemu-devel] Question about libvhost-user and vhost-user-bridge.c
@ 2019-08-14 17:54 William Tu
  2019-08-15 14:07 ` Stefan Hajnoczi
  0 siblings, 1 reply; 3+ messages in thread
From: William Tu @ 2019-08-14 17:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst

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
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?

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?

Thanks
William


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] Question about libvhost-user and vhost-user-bridge.c
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2019-08-15 14:07 UTC (permalink / raw)
  To: William Tu; +Cc: Marc-André Lureau, qemu-devel, mst

[-- Attachment #1: Type: text/plain, Size: 1663 bytes --]

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.

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).

> 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.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] Question about libvhost-user and vhost-user-bridge.c
  2019-08-15 14:07 ` Stefan Hajnoczi
@ 2019-08-15 16:25   ` William Tu
  0 siblings, 0 replies; 3+ messages in thread
From: William Tu @ 2019-08-15 16:25 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Marc-André Lureau, qemu-devel, mst

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org qemu-devel@archiver.kernel.org
	public-inbox-index qemu-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox