qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: pbonzini@redhat.com, clg@fr.ibm.com, qemu-devel@nongnu.org,
	qemu-stable@nongnu.org
Subject: Re: [Qemu-devel] [PATCH V2] virtio-net: unbreak any layout
Date: Thu, 16 Jul 2015 16:00:12 +0800	[thread overview]
Message-ID: <55A7648C.5000109@redhat.com> (raw)
In-Reply-To: <20150716102849-mutt-send-email-mst@redhat.com>



On 07/16/2015 03:29 PM, Michael S. Tsirkin wrote:
> On Thu, Jul 16, 2015 at 02:49:48PM +0800, Jason Wang wrote:
>> > 
>> > 
>> > On 07/16/2015 02:42 PM, Michael S. Tsirkin wrote:
>>> > > On Wed, Jul 15, 2015 at 03:56:07PM +0800, Jason Wang wrote:
>>>> > >> Commit 032a74a1c0fcdd5fd1c69e56126b4c857ee36611
>>>> > >> ("virtio-net: byteswap virtio-net header") breaks any layout by
>>>> > >> requiring out_sg[0].iov_len >= n->guest_hdr_len. Fixing this by
>>>> > >> copying header to temporary buffer if swap is needed, and then use
>>>> > >> this buffer as part of out_sg.
>>>> > >>
>>>> > >> Fixes 032a74a1c0fcdd5fd1c69e56126b4c857ee36611
>>>> > >> ("virtio-net: byteswap virtio-net header")
>>>> > >> Cc: qemu-stable@nongnu.org
>>>> > >> Cc: clg@fr.ibm.com
>>>> > >> Signed-off-by: Jason Wang <jasowang@redhat.com>
>>>> > >> ---
>>>> > >> Changes from V1:
>>>> > >> - avoid header copying if there's no need to do header swap
>>>> > >> - don't write the header back
>>>> > >> ---
>>>> > >>  hw/net/virtio-net.c               | 17 ++++++++++++++---
>>>> > >>  include/hw/virtio/virtio-access.h |  9 +++++++++
>>>> > >>  2 files changed, 23 insertions(+), 3 deletions(-)
>>>> > >>
>>>> > >> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>>>> > >> index e3c2db3..12322bd 100644
>>>> > >> --- a/hw/net/virtio-net.c
>>>> > >> +++ b/hw/net/virtio-net.c
>>>> > >> @@ -1142,7 +1142,8 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
>>>> > >>          ssize_t ret, len;
>>>> > >>          unsigned int out_num = elem.out_num;
>>>> > >>          struct iovec *out_sg = &elem.out_sg[0];
>>>> > >> -        struct iovec sg[VIRTQUEUE_MAX_SIZE];
>>>> > >> +        struct iovec sg[VIRTQUEUE_MAX_SIZE], sg2[VIRTQUEUE_MAX_SIZE];
>>>> > >> +        struct virtio_net_hdr hdr;
>>>> > >>  
>>>> > >>          if (out_num < 1) {
>>>> > >>              error_report("virtio-net header not in first element");
>>>> > >> @@ -1150,11 +1151,21 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
>>>> > >>          }
>>>> > >>  
>>>> > >>          if (n->has_vnet_hdr) {
>>>> > >> -            if (out_sg[0].iov_len < n->guest_hdr_len) {
>>>> > >> +            if (iov_size(out_sg, out_num) < n->guest_hdr_len) {
>>>> > >>                  error_report("virtio-net header incorrect");
>>>> > >>                  exit(1);
>>>> > >>              }
>>> > > this scans the iov unnecessarily. How about checking return
>>> > > code from iov_to_buf instead?
>> > 
>> > Looks ok since hdr is very short anyway.
> but iov_size scans the whole iov, not just the header.
>

Right.

      reply	other threads:[~2015-07-16  8:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-15  7:56 [Qemu-devel] [PATCH V2] virtio-net: unbreak any layout Jason Wang
2015-07-15  8:00 ` Paolo Bonzini
2015-07-15 11:23 ` Michael S. Tsirkin
2015-07-16  5:54   ` Jason Wang
2015-07-16  6:19     ` Michael S. Tsirkin
2015-07-16  6:42 ` Michael S. Tsirkin
2015-07-16  6:49   ` Jason Wang
2015-07-16  7:29     ` Michael S. Tsirkin
2015-07-16  8:00       ` Jason Wang [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=55A7648C.5000109@redhat.com \
    --to=jasowang@redhat.com \
    --cc=clg@fr.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /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).