Blame SOURCES/kvm-virtio-net-don-t-update-mac_table-in-error-state.patch

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