From: Jason Wang <jasowang@redhat.com>
To: stefanha@linux.vnet.ibm.com, mst@redhat.com,
qemu-devel@nongnu.org, blauwirbel@gmail.com,
benjamin.poirier@gmail.com, liguori@us.ibm.com,
aurelien@aurel32.net
Subject: [Qemu-devel] [1/6 V2 PATCH] rtl8139: limit transmission buffer size in c+ mode
Date: Wed, 07 Mar 2012 11:17:48 +0800 [thread overview]
Message-ID: <20120307031748.6355.500.stgit@jason-ThinkPad-T400> (raw)
In-Reply-To: <20120305030824.8515.53602.stgit@jason-ThinkPad-T400>
The tx buffer would be re-allocated for tx descriptor with big size
and without LS bit set, this would make guest driver could easily let
qemu to allocate unlimited.
In linux host, a glib failure were easy to be triggered:
GLib-ERROR **: gmem.c:176: failed to allocate 18446744071562067968 bytes
This patch fix this by adding a limit. As the spec didn't tell the maximum size
of buffer allowed, stick it to current CP_TX_BUFFER_SIZE (65536).
Changes from V1:
Drop the while statement and s->cplus_txbuffer check.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
hw/rtl8139.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 05b8e1e..be4bc6a 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -2061,13 +2061,12 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
s->cplus_txbuffer_len);
}
- while (s->cplus_txbuffer && s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len)
+ if (s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len)
{
- s->cplus_txbuffer_len += CP_TX_BUFFER_SIZE;
- s->cplus_txbuffer = g_realloc(s->cplus_txbuffer, s->cplus_txbuffer_len);
-
- DPRINTF("+++ C+ mode transmission buffer space changed to %d\n",
- s->cplus_txbuffer_len);
+ /* The spec didn't tell the maximum size, stick to CP_TX_BUFFER_SIZE */
+ txsize = s->cplus_txbuffer_len - s->cplus_txbuffer_offset;
+ DPRINTF("+++ C+ mode transmission buffer overrun, truncated descriptor"
+ "length to %d\n", txsize);
}
if (!s->cplus_txbuffer)
next prev parent reply other threads:[~2012-03-07 3:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-05 3:08 [Qemu-devel] [PATCH 1/6] rtl8139: limit transmission buffer size in c+ mode Jason Wang
2012-03-05 3:08 ` [Qemu-devel] [PATCH 2/6] rtl8139: remove unused marco Jason Wang
2012-03-05 3:08 ` [Qemu-devel] [PATCH 3/6] rtl8139: support byte read to TxStatus registers Jason Wang
2012-03-05 3:08 ` [Qemu-devel] [PATCH 4/6] net: move compute_mcast_idx() to net.h Jason Wang
2012-03-05 3:08 ` [Qemu-devel] [PATCH 5/6] rtl8139: correctly check the opmode Jason Wang
2012-03-05 3:09 ` [Qemu-devel] [PATCH 6/6] rtl8139: do the network/host communication only in normal operating mode Jason Wang
2012-03-05 8:31 ` [Qemu-devel] [PATCH 1/6] rtl8139: limit transmission buffer size in c+ mode Stefan Hajnoczi
2012-03-07 3:17 ` Jason Wang [this message]
2012-03-07 8:13 ` [Qemu-devel] [1/6 V2 PATCH] " Stefan Hajnoczi
2012-03-15 23:01 ` Michael S. Tsirkin
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=20120307031748.6355.500.stgit@jason-ThinkPad-T400 \
--to=jasowang@redhat.com \
--cc=aurelien@aurel32.net \
--cc=benjamin.poirier@gmail.com \
--cc=blauwirbel@gmail.com \
--cc=liguori@us.ibm.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
/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).