9ae3a8
From 4b542df026dfcc30802d300e56a99799f410ef50 Mon Sep 17 00:00:00 2001
9ae3a8
From: Amos Kong <akong@redhat.com>
9ae3a8
Date: Mon, 6 Jan 2014 05:29:20 +0100
9ae3a8
Subject: [PATCH 7/8] virtio-net: don't update mac_table in error state
9ae3a8
9ae3a8
RH-Author: Amos Kong <akong@redhat.com>
9ae3a8
Message-id: <1388986160-19461-1-git-send-email-akong@redhat.com>
9ae3a8
Patchwork-id: 56495
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH] virtio-net: don't update mac_table in error state
9ae3a8
Bugzilla: 1048671
9ae3a8
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
9ae3a8
RH-Acked-by: Vlad Yasevich <vyasevic@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1048671
9ae3a8
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=6805382
9ae3a8
9ae3a8
mac_table was always cleaned up first in handling
9ae3a8
VIRTIO_NET_CTRL_MAC_TABLE_SET command, and we din't recover
9ae3a8
mac_table content in error state, it's not correct.
9ae3a8
9ae3a8
This patch makes all the changes in temporal variables,
9ae3a8
only update the real mac_table if everything is ok.
9ae3a8
We won't change mac_table in error state, so rxfilter
9ae3a8
notification isn't needed.
9ae3a8
9ae3a8
This patch also fixed same problame in
9ae3a8
 http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg01188.html
9ae3a8
 (not merge)
9ae3a8
9ae3a8
I will send patch for virtio spec to clarifying this change.
9ae3a8
9ae3a8
Signed-off-by: Amos Kong <akong@redhat.com>
9ae3a8
Reviewed-by: Vlad Yasevich <vyasevic@redhat.com>
9ae3a8
Acked-by: Jason Wang <jasowang@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit cae2e5562cdaf3aafa1c4ec2d5f2b19af6c886dd)
9ae3a8
---
9ae3a8
 hw/net/virtio-net.c |   35 ++++++++++++++++++++---------------
9ae3a8
 1 files changed, 20 insertions(+), 15 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/net/virtio-net.c |   35 ++++++++++++++++++++---------------
9ae3a8
 1 files changed, 20 insertions(+), 15 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
9ae3a8
index 915aa70..21b126f 100644
9ae3a8
--- a/hw/net/virtio-net.c
9ae3a8
+++ b/hw/net/virtio-net.c
9ae3a8
@@ -548,11 +548,11 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
9ae3a8
         return VIRTIO_NET_ERR;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    n->mac_table.in_use = 0;
9ae3a8
-    n->mac_table.first_multi = 0;
9ae3a8
-    n->mac_table.uni_overflow = 0;
9ae3a8
-    n->mac_table.multi_overflow = 0;
9ae3a8
-    memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
9ae3a8
+    int in_use = 0;
9ae3a8
+    int first_multi = 0;
9ae3a8
+    uint8_t uni_overflow = 0;
9ae3a8
+    uint8_t multi_overflow = 0;
9ae3a8
+    uint8_t *macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN);
9ae3a8
 
9ae3a8
     s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
9ae3a8
                    sizeof(mac_data.entries));
9ae3a8
@@ -567,19 +567,19 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (mac_data.entries <= MAC_TABLE_ENTRIES) {
9ae3a8
-        s = iov_to_buf(iov, iov_cnt, 0, n->mac_table.macs,
9ae3a8
+        s = iov_to_buf(iov, iov_cnt, 0, macs,
9ae3a8
                        mac_data.entries * ETH_ALEN);
9ae3a8
         if (s != mac_data.entries * ETH_ALEN) {
9ae3a8
             goto error;
9ae3a8
         }
9ae3a8
-        n->mac_table.in_use += mac_data.entries;
9ae3a8
+        in_use += mac_data.entries;
9ae3a8
     } else {
9ae3a8
-        n->mac_table.uni_overflow = 1;
9ae3a8
+        uni_overflow = 1;
9ae3a8
     }
9ae3a8
 
9ae3a8
     iov_discard_front(&iov, &iov_cnt, mac_data.entries * ETH_ALEN);
9ae3a8
 
9ae3a8
-    n->mac_table.first_multi = n->mac_table.in_use;
9ae3a8
+    first_multi = in_use;
9ae3a8
 
9ae3a8
     s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
9ae3a8
                    sizeof(mac_data.entries));
9ae3a8
@@ -594,24 +594,29 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
9ae3a8
         goto error;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if (n->mac_table.in_use + mac_data.entries <= MAC_TABLE_ENTRIES) {
9ae3a8
-        s = iov_to_buf(iov, iov_cnt, 0,
9ae3a8
-                       &n->mac_table.macs[n->mac_table.in_use * ETH_ALEN],
9ae3a8
+    if (in_use + mac_data.entries <= MAC_TABLE_ENTRIES) {
9ae3a8
+        s = iov_to_buf(iov, iov_cnt, 0, &macs[in_use * ETH_ALEN],
9ae3a8
                        mac_data.entries * ETH_ALEN);
9ae3a8
         if (s != mac_data.entries * ETH_ALEN) {
9ae3a8
             goto error;
9ae3a8
         }
9ae3a8
-        n->mac_table.in_use += mac_data.entries;
9ae3a8
+        in_use += mac_data.entries;
9ae3a8
     } else {
9ae3a8
-        n->mac_table.multi_overflow = 1;
9ae3a8
+        multi_overflow = 1;
9ae3a8
     }
9ae3a8
 
9ae3a8
+    n->mac_table.in_use = in_use;
9ae3a8
+    n->mac_table.first_multi = first_multi;
9ae3a8
+    n->mac_table.uni_overflow = uni_overflow;
9ae3a8
+    n->mac_table.multi_overflow = multi_overflow;
9ae3a8
+    memcpy(n->mac_table.macs, macs, MAC_TABLE_ENTRIES * ETH_ALEN);
9ae3a8
+    g_free(macs);
9ae3a8
     rxfilter_notify(nc);
9ae3a8
 
9ae3a8
     return VIRTIO_NET_OK;
9ae3a8
 
9ae3a8
 error:
9ae3a8
-    rxfilter_notify(nc);
9ae3a8
+    g_free(macs);
9ae3a8
     return VIRTIO_NET_ERR;
9ae3a8
 }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8