From: Dmitry Fleytman <dmitry@daynix.com>
To: qemu-devel@nongnu.org
Cc: Yan Vugenfirer <yan@daynix.com>,
Dmitry Fleytman <dmitry@daynix.com>,
Chris Webb <chris.webb@elastichosts.com>,
Richard Davies <richard.davies@elastichosts.com>
Subject: [Qemu-devel] [PATCH 1/2] Ignore RX tail kicks when RX disabled.
Date: Wed, 17 Oct 2012 20:31:46 +0200 [thread overview]
Message-ID: <1350498707-6749-2-git-send-email-dmitry@daynix.com> (raw)
In-Reply-To: <1350498707-6749-1-git-send-email-dmitry@daynix.com>
Device RX initization from driver's side consists of following steps:
1. Initialize head and tail of RX ring to 0
2. Enable Rx (set bit in RCTL register)
3. Allocate buffers, fill descriptors
4. Write ring tail
Forth operation signals hardware that RX buffers available
and it may start packets indication.
Current implementation treats first operation (write 0 to ring tail)
as signal of buffers availability and starts data transfers as soon
as RX enable indicaton arrives.
This is not correct because there is a chance that ring is still
empty (third action not performed yet) and then memory corruption
occures.
Device has to ignore RX tail kicks unless RX enabled.
Reported-by: Chris Webb <chris.webb@elastichosts.com>
Reported-by: Richard Davies <richard.davies@elastichosts.com>
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
---
hw/e1000.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/hw/e1000.c b/hw/e1000.c
index 63fee10..606bf3a 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -267,6 +267,7 @@ static void e1000_reset(void *opaque)
{
E1000State *d = opaque;
+ d->check_rxov = 1;
qemu_del_timer(d->autoneg_timer);
memset(d->phy_reg, 0, sizeof d->phy_reg);
memmove(d->phy_reg, phy_reg_init, sizeof phy_reg_init);
@@ -285,6 +286,10 @@ set_ctrl(E1000State *s, int index, uint32_t val)
{
/* RST is self clearing */
s->mac_reg[CTRL] = val & ~E1000_CTRL_RST;
+
+ if (val & E1000_CTRL_RST) {
+ s->check_rxov = 1;
+ }
}
static void
@@ -754,12 +759,18 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size)
return total_size <= bufs * s->rxbuf_size;
}
+static inline bool
+is_receive_enabled(E1000State *s)
+{
+ return s->mac_reg[RCTL] & E1000_RCTL_EN;
+}
+
static int
e1000_can_receive(NetClientState *nc)
{
E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
- return (s->mac_reg[RCTL] & E1000_RCTL_EN) && e1000_has_rxbufs(s, 1);
+ return is_receive_enabled(s) && e1000_has_rxbufs(s, 1);
}
static uint64_t rx_desc_base(E1000State *s)
@@ -785,8 +796,9 @@ e1000_receive(NetClientState *nc, const uint8_t *buf, size_t size)
size_t desc_size;
size_t total_size;
- if (!(s->mac_reg[RCTL] & E1000_RCTL_EN))
+ if (!is_receive_enabled(s)) {
return -1;
+ }
/* Pad to minimum Ethernet frame length */
if (size < sizeof(min_buf)) {
@@ -925,8 +937,12 @@ mac_writereg(E1000State *s, int index, uint32_t val)
static void
set_rdt(E1000State *s, int index, uint32_t val)
{
- s->check_rxov = 0;
s->mac_reg[index] = val & 0xffff;
+
+ if (is_receive_enabled(s)) {
+ s->check_rxov = 0;
+ }
+
if (e1000_has_rxbufs(s, 1)) {
qemu_flush_queued_packets(&s->nic->nc);
}
@@ -1065,7 +1081,12 @@ static void e1000_io_write(void *opaque, target_phys_addr_t addr,
{
E1000State *s = opaque;
- (void)s;
+ switch (addr) {
+ case E1000_CTRL_DUP:
+ if (val & E1000_CTRL_RST) {
+ s->check_rxov = 1;
+ }
+ }
}
static const MemoryRegionOps e1000_io_ops = {
--
1.7.11.4
next prev parent reply other threads:[~2012-10-17 18:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-17 18:31 [Qemu-devel] [PATCH 0/2] E1000 RX/Live migration bugs fixed Dmitry Fleytman
2012-10-17 18:31 ` Dmitry Fleytman [this message]
2012-10-18 7:31 ` [Qemu-devel] [PATCH 1/2] Ignore RX tail kicks when RX disabled Stefan Hajnoczi
2012-10-18 8:08 ` Dmitry Fleytman
2012-10-18 8:09 ` Stefan Hajnoczi
2012-10-18 8:34 ` Dmitry Fleytman
2012-10-18 14:31 ` Stefan Hajnoczi
2012-10-18 16:06 ` Alexander Duyck
2012-10-18 16:12 ` Dmitry Fleytman
2012-10-17 18:31 ` [Qemu-devel] [PATCH 2/2] Add check_rxov into VMState Dmitry Fleytman
2012-10-18 7:24 ` Stefan Hajnoczi
2012-10-18 8:06 ` Dmitry Fleytman
2012-10-18 14:56 ` Avi Kivity
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=1350498707-6749-2-git-send-email-dmitry@daynix.com \
--to=dmitry@daynix.com \
--cc=chris.webb@elastichosts.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.davies@elastichosts.com \
--cc=yan@daynix.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).