[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout
From: |
Jason Wang |
Subject: |
Re: [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout |
Date: |
Mon, 13 Jul 2015 16:30:55 +0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
On 07/13/2015 03:24 PM, Michael S. Tsirkin wrote:
> On Mon, Jul 13, 2015 at 01:46:51PM +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 and copying it back after byteswap.
>>
>> Fixes 032a74a1c0fcdd5fd1c69e56126b4c857ee36611
>> ("virtio-net: byteswap virtio-net header")
>> Cc: address@hidden
>> Cc: address@hidden
>> Signed-off-by: Jason Wang <address@hidden>
>> ---
>> hw/net/virtio-net.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index e3c2db3..b42af8f 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -1139,10 +1139,11 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
>> }
>>
>> while (virtqueue_pop(q->tx_vq, &elem)) {
>> - ssize_t ret, len;
>> + ssize_t ret, len, s;
>> unsigned int out_num = elem.out_num;
>> struct iovec *out_sg = &elem.out_sg[0];
>> struct iovec sg[VIRTQUEUE_MAX_SIZE];
>> + struct virtio_net_hdr hdr;
>>
>> if (out_num < 1) {
>> error_report("virtio-net header not in first element");
>> @@ -1150,11 +1151,14 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
>> }
>>
>> if (n->has_vnet_hdr) {
>> - if (out_sg[0].iov_len < n->guest_hdr_len) {
>> + s = iov_to_buf(out_sg, out_num, 0, &hdr, sizeof(hdr));
>> + if (s != sizeof(hdr)) {
>> error_report("virtio-net header incorrect");
>> exit(1);
>> }
>> - virtio_net_hdr_swap(vdev, (void *) out_sg[0].iov_base);
>> + virtio_net_hdr_swap(vdev, (void *) &hdr);
>> + s = iov_from_buf(out_sg, out_num, 0, &hdr, sizeof(hdr));
>> + assert(s == sizeof(hdr));
>> }
>>
>> /*
> Looks like this will write into out_sg - that's violating the virtio spec.
Right, will fix this in V2.
Thanks
>
>> --
>> 2.1.4
[Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout, Jason Wang, 2015/07/13
Re: [Qemu-devel] [PATCH 5/5] virtio-net: unbreak any layout,
Jason Wang <=
Re: [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write(), Michael S. Tsirkin, 2015/07/13
Re: [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write(), Jason Wang, 2015/07/13