[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 05/14] virtio-net: use safe iov operations for r
From: |
Anthony Liguori |
Subject: |
Re: [Qemu-devel] [PATCH 05/14] virtio-net: use safe iov operations for rx |
Date: |
Mon, 24 Sep 2012 19:38:24 -0500 |
User-agent: |
Notmuch/0.13.2+93~ged93d79 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) |
"Michael S. Tsirkin" <address@hidden> writes:
> Avoid magling iov manually: use safe iov operations
> for processing packets incoming to guest.
> This also removes the requirement for virtio header to
> fit the first s/g entry exactly.
>
> Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Anthony Liguori <address@hidden>
Regards,
Anthony Liguori
> ---
> hw/virtio-net.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/hw/virtio-net.c b/hw/virtio-net.c
> index 6e53858..9611d95 100644
> --- a/hw/virtio-net.c
> +++ b/hw/virtio-net.c
> @@ -593,8 +593,9 @@ static int receive_filter(VirtIONet *n, const uint8_t
> *buf, int size)
> static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf,
> size_t size)
> {
> VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
> - struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
> - const struct iovec *sg = elem.in_sg;
> + struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE];
> + struct virtio_net_hdr_mrg_rxbuf mhdr;
> + unsigned mhdr_cnt = 0;
> size_t offset, i, guest_offset;
>
> if (!virtio_net_can_receive(&n->nic->nc))
> @@ -632,14 +633,13 @@ static ssize_t virtio_net_receive(NetClientState *nc,
> const uint8_t *buf, size_t
> exit(1);
> }
>
> - if (!n->mergeable_rx_bufs && elem.in_sg[0].iov_len !=
> n->guest_hdr_len) {
> - error_report("virtio-net header not in first element");
> - exit(1);
> - }
> -
> if (i == 0) {
> - if (n->mergeable_rx_bufs)
> - mhdr = (struct virtio_net_hdr_mrg_rxbuf *)sg[0].iov_base;
> + if (n->mergeable_rx_bufs) {
> + mhdr_cnt = iov_cpy(mhdr_sg, ARRAY_SIZE(mhdr_sg),
> + sg, elem.in_num,
> + offsetof(typeof(mhdr), num_buffers),
> + sizeof(mhdr.num_buffers));
> + }
>
> offset += receive_header(n, sg, elem.in_num,
> buf + offset, size - offset);
> @@ -672,8 +672,11 @@ static ssize_t virtio_net_receive(NetClientState *nc,
> const uint8_t *buf, size_t
> virtqueue_fill(n->rx_vq, &elem, total, i++);
> }
>
> - if (mhdr) {
> - stw_p(&mhdr->num_buffers, i);
> + if (mhdr_cnt) {
> + stw_p(&mhdr.num_buffers, i);
> + iov_from_buf(mhdr_sg, mhdr_cnt,
> + 0,
> + &mhdr.num_buffers, sizeof mhdr.num_buffers);
> }
>
> virtqueue_flush(n->rx_vq, i);
> --
> MST
- [Qemu-devel] [PATCH 00/14] virtio-net: iovec handling cleanup, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 01/14] virtio-net: track host/guest header length, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 03/14] iov: add iov_cpy, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 04/14] virtio-net: avoid sg copy, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 05/14] virtio-net: use safe iov operations for rx, Michael S. Tsirkin, 2012/09/24
- Re: [Qemu-devel] [PATCH 05/14] virtio-net: use safe iov operations for rx,
Anthony Liguori <=
- [Qemu-devel] [PATCH 07/14] virtio-net: first s/g is always at start of buf, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 02/14] iov: add const annotation, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 08/14] virtio-net: switch tx to safe iov functions, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 09/14] virtio-net: simplify rx code, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 06/14] virtio-net: refactor receive_hdr, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 10/14] virtio: don't mark unaccessed memory as dirty, Michael S. Tsirkin, 2012/09/24
- [Qemu-devel] [PATCH 11/14] virtio-net: fix used len for tx, Michael S. Tsirkin, 2012/09/24