All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: qemu-arm@nongnu.org
Cc: "Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Jason Wang" <jasowang@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-devel@nongnu.org, yurovsky@gmail.com
Subject: [Qemu-devel] [PATCH v3 03/30] imx_fec: Change queue flushing heuristics
Date: Mon,  6 Nov 2017 07:47:46 -0800	[thread overview]
Message-ID: <20171106154813.19936-4-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20171106154813.19936-1-andrew.smirnov@gmail.com>

In current implementation, packet queue flushing logic seem to suffer
from a deadlock like scenario if a packet is received by the interface
before before Rx ring is initialized by Guest's driver. Consider the
following sequence of events:

	1. A QEMU instance is started against a TAP device on Linux
	   host, running Linux guest, e. g., something to the effect
	   of:

	   qemu-system-arm \
	      -net nic,model=imx.fec,netdev=lan0 \
	      netdev tap,id=lan0,ifname=tap0,script=no,downscript=no \
	      ... rest of the arguments ...

	2. Once QEMU starts, but before guest reaches the point where
	   FEC deriver is done initializing the HW, Guest, via TAP
	   interface, receives a number of multicast MDNS packets from
	   Host (not necessarily true for every OS, but it happens at
	   least on Fedora 25)

	3. Recieving a packet in such a state results in
	   imx_eth_can_receive() returning '0', which in turn causes
	   tap_send() to disable corresponding event (tap.c:203)

	4. Once Guest's driver reaches the point where it is ready to
	   recieve packets it prepares Rx ring descriptors and writes
	   ENET_RDAR_RDAR to ENET_RDAR register to indicate to HW that
	   more descriptors are ready. And at this points emulation
	   layer does this:

	   	 s->regs[index] = ENET_RDAR_RDAR;
                 imx_eth_enable_rx(s);

	   which, combined with:

	   	  if (!s->regs[ENET_RDAR]) {
		     qemu_flush_queued_packets(qemu_get_queue(s->nic));
		  }

	   results in Rx queue never being flushed and corresponding
	   I/O event beign disabled.

To prevent the problem, change the code to always flush packet queue
when ENET_RDAR transitions 0 -> ENET_RDAR_RDAR.

Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
Cc: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org
Cc: yurovsky@gmail.com
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 hw/net/imx_fec.c         | 12 ++++++------
 include/hw/net/imx_fec.h |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
index 8b2e4b8ffe..eb034ffd0c 100644
--- a/hw/net/imx_fec.c
+++ b/hw/net/imx_fec.c
@@ -533,7 +533,7 @@ static void imx_eth_do_tx(IMXFECState *s)
     }
 }
 
-static void imx_eth_enable_rx(IMXFECState *s)
+static void imx_eth_enable_rx(IMXFECState *s, bool flush)
 {
     IMXFECBufDesc bd;
     bool rx_ring_full;
@@ -544,7 +544,7 @@ static void imx_eth_enable_rx(IMXFECState *s)
 
     if (rx_ring_full) {
         FEC_PRINTF("RX buffer full\n");
-    } else if (!s->regs[ENET_RDAR]) {
+    } else if (flush) {
         qemu_flush_queued_packets(qemu_get_queue(s->nic));
     }
 
@@ -807,7 +807,7 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             if (!s->regs[index]) {
                 s->regs[index] = ENET_RDAR_RDAR;
-                imx_eth_enable_rx(s);
+                imx_eth_enable_rx(s, true);
             }
         } else {
             s->regs[index] = 0;
@@ -930,7 +930,7 @@ static int imx_eth_can_receive(NetClientState *nc)
 
     FEC_PRINTF("\n");
 
-    return s->regs[ENET_RDAR] ? 1 : 0;
+    return !!s->regs[ENET_RDAR];
 }
 
 static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,
@@ -1020,7 +1020,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,
         }
     }
     s->rx_descriptor = addr;
-    imx_eth_enable_rx(s);
+    imx_eth_enable_rx(s, false);
     imx_eth_update(s);
     return len;
 }
@@ -1116,7 +1116,7 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf,
         }
     }
     s->rx_descriptor = addr;
-    imx_eth_enable_rx(s);
+    imx_eth_enable_rx(s, false);
     imx_eth_update(s);
     return len;
 }
diff --git a/include/hw/net/imx_fec.h b/include/hw/net/imx_fec.h
index 62ad473b05..4bc8f03ec2 100644
--- a/include/hw/net/imx_fec.h
+++ b/include/hw/net/imx_fec.h
@@ -252,6 +252,7 @@ typedef struct IMXFECState {
     uint32_t phy_int_mask;
 
     bool is_fec;
+    bool needs_flush;
 } IMXFECState;
 
 #endif
-- 
2.13.6

  parent reply	other threads:[~2017-11-06 15:48 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-06 15:47 [Qemu-devel] [PATCH v3 00/30] Initial i.MX7 support Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 01/30] imx_fec: Do not link to netdev Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 02/30] imx_fec: Refactor imx_eth_enable_rx() Andrey Smirnov
2017-11-06 15:47 ` Andrey Smirnov [this message]
2017-11-21 17:27   ` [Qemu-devel] [PATCH v3 03/30] imx_fec: Change queue flushing heuristics Peter Maydell
2017-11-22 20:22     ` Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 04/30] imx_fec: Use ENET_FTRL to determine truncation length Andrey Smirnov
2017-11-21 17:31   ` Peter Maydell
2017-11-22 20:22     ` Andrey Smirnov
2017-11-23  9:50       ` Peter Maydell
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 05/30] imx_fec: Use MIN instead of explicit ternary operator Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 06/30] imx_fec: Emulate SHIFT16 in ENETx_RACC Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 07/30] imx_fec: Add support for multiple Tx DMA rings Andrey Smirnov
2017-11-21 17:44   ` Peter Maydell
2017-11-22 20:25     ` Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 08/30] imx_fec: Use correct length for packet size Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 09/30] imx_fec: Fix a typo in imx_enet_receive() Andrey Smirnov
2017-11-21 17:44   ` Peter Maydell
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 10/30] imx_fec: Reserve full 4K page for the register file Andrey Smirnov
2017-11-21 17:48   ` Peter Maydell
2017-11-22 20:34     ` Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 11/30] sdhci: Add i.MX specific subtype of SDHCI Andrey Smirnov
2017-11-21 18:02   ` Peter Maydell
2017-11-22 20:43     ` Andrey Smirnov
2017-11-23  9:52       ` Peter Maydell
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 12/30] sdhci: Implement write method of ACMD12ERRSTS register Andrey Smirnov
2017-11-21 18:04   ` Peter Maydell
2017-11-22 20:50     ` Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 13/30] i.MX: Add code to emulate i.MX7 CCM, PMU and ANALOG IP blocks Andrey Smirnov
2017-11-21 18:08   ` Peter Maydell
2017-11-22 21:06     ` Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 14/30] i.MX: Add code to emulate i.MX2 watchdog IP block Andrey Smirnov
2017-11-21 18:10   ` Peter Maydell
2017-11-22 21:07     ` Andrey Smirnov
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 15/30] i.MX: Add code to emulate i.MX7 SNVS IP-block Andrey Smirnov
2017-11-21 18:15   ` Peter Maydell
2017-11-06 15:47 ` [Qemu-devel] [PATCH v3 16/30] i.MX: Add code to emulate GPCv2 IP block Andrey Smirnov
2017-11-21 18:18   ` Peter Maydell
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 17/30] i.MX: Add code to emulate i.MX7 IOMUXC " Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 19/30] i.MX: Add code to emulate SDMA " Andrey Smirnov
2017-11-21 18:20   ` Peter Maydell
2017-11-22 21:08     ` Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 20/30] i.MX: Add code to emulate FlexCAN " Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 21/30] i.MX: Add implementation of i.MX7 GPR " Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 22/30] pci: Add support for Designware " Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 23/30] i.MX: Add code to emulate i.MX7 USBMISC " Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 24/30] i.MX: Add code to emulate i.MX7 ADC " Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 25/30] i.MX: Add code to emulate i.MX7 SRC IP-block Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 26/30] usb: Add basic code to emulate Chipidea USB IP Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 27/30] ARM: Add basic code to emulate A7MPCore DAP block Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 28/30] i.MX: Add code to emulate i.MX LCD block Andrey Smirnov
2017-11-06 15:48 ` [Qemu-devel] [PATCH v3 29/30] i.MX: Add i.MX7 SOC implementation Andrey Smirnov
2017-11-22 15:34   ` Igor Mammedov
2017-11-22 21:08     ` Andrey Smirnov
     [not found] ` <20171106154813.19936-31-andrew.smirnov@gmail.com>
2017-11-21 18:22   ` [Qemu-devel] [PATCH v3 30/30] Implement support for i.MX7 Sabre board Peter Maydell
2017-11-22 19:24     ` Andrey Smirnov
2017-11-21 18:34 ` [Qemu-devel] [PATCH v3 00/30] Initial i.MX7 support Peter Maydell
2017-11-22 20:19   ` Andrey Smirnov

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=20171106154813.19936-4-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=jasowang@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=yurovsky@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.