From 7b4a1afca1c91eda1349c6f56c5d34013db51b0a Mon Sep 17 00:00:00 2001
Message-Id: <7b4a1afca1c91eda1349c6f56c5d34013db51b0a.1361183855.git.minovotn@redhat.com>
In-Reply-To: <8a5181c3fa0b1efb69153485808afcb612d0aa60.1361183855.git.minovotn@redhat.com>
References: <8a5181c3fa0b1efb69153485808afcb612d0aa60.1361183855.git.minovotn@redhat.com>
From: Vlad Yasevich <vyasevic@redhat.com>
Date: Thu, 14 Feb 2013 22:48:25 +0100
Subject: [PATCH 4/5] e1000: Discard packets that are too long if !SBP and
 !LPE

RH-Author: Vlad Yasevich <vyasevic@redhat.com>
Message-id: <1360882106-11660-2-git-send-email-vyasevic@redhat.com>
Patchwork-id: 48531
O-Subject: [RHEL-6.5 kvm PATCH 1/2] e1000: Discard packets that are too long if !SBP and !LPE
Bugzilla: 910842
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Amos Kong <akong@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Petr Matousek <pmatouse@redhat.com>

From: Michael Contreras <michael@inetric.com>

The e1000_receive function for the e1000 needs to discard packets longer than
1522 bytes if the SBP and LPE flags are disabled. The linux driver assumes
this behavior and allocates memory based on this assumption.

Signed-off-by: Michael Contreras <michael@inetric.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

(cherry-picked from b0d9ffcd0251161c7c92f94804dcf599dfa3edeb)

Signed-off-by: Vlad Yasevich <vyasevic.redhat.com>
---
 hw/e1000.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/e1000.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/e1000.c b/hw/e1000.c
index 016aae1..e9ed1aa 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -55,6 +55,9 @@ static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);
 #define PNPMMIO_SIZE      0x20000
 #define MIN_BUF_SIZE      60 /* Min. octets in an ethernet frame sans FCS */
 
+/* this is the size past which hardware will drop packets when setting LPE=0 */
+#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
+
 /*
  * HW models:
  *  E1000_DEV_ID_82540EM works with Windows and Linux
@@ -774,6 +777,13 @@ e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
         size = sizeof(min_buf);
     }
 
+    /* Discard oversized packets if !LPE and !SBP. */
+    if (size > MAXIMUM_ETHERNET_VLAN_SIZE
+        && !(s->mac_reg[RCTL] & E1000_RCTL_LPE)
+        && !(s->mac_reg[RCTL] & E1000_RCTL_SBP)) {
+        return size;
+    }
+
     if (!receive_filter(s, buf, size))
         return size;
 
-- 
1.7.11.7

