From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 12/26] imx_fec: Change queue flushing heuristics
Date: Thu, 11 Jan 2018 13:38:08 +0000 [thread overview]
Message-ID: <1515677902-23436-13-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1515677902-23436-1-git-send-email-peter.maydell@linaro.org>
From: Andrey Smirnov <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
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/net/imx_fec.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
index 8b2e4b8..eb034ff 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;
}
--
2.7.4
next prev parent reply other threads:[~2018-01-11 13:38 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-11 13:37 [Qemu-devel] [PULL 00/26] target-arm queue Peter Maydell
2018-01-11 13:37 ` [Qemu-devel] [PULL 01/26] linux-user: Add support for big-endian aarch64 Peter Maydell
2018-01-11 13:37 ` [Qemu-devel] [PULL 02/26] linux-user: Add separate aarch64_be uname Peter Maydell
2018-01-11 13:37 ` [Qemu-devel] [PULL 03/26] linux-user: Fix endianess of aarch64 signal trampoline Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 04/26] configure: Add aarch64_be-linux-user target Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 05/26] linux-user: Add aarch64_be magic numbers to qemu-binfmt-conf.sh Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 06/26] linux-user: Separate binfmt arm CPU families Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 07/26] linux-user: Activate armeb handler registration Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 08/26] target/arm: Fix stlxp for aarch64_be Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 09/26] Virt: ACPI: fix qemu assert due to re-assigned table data address Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 10/26] imx_fec: Do not link to netdev Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 11/26] imx_fec: Refactor imx_eth_enable_rx() Peter Maydell
2018-01-11 13:38 ` Peter Maydell [this message]
2018-01-11 13:38 ` [Qemu-devel] [PULL 13/26] imx_fec: Move Tx frame buffer away from the stack Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 14/26] imx_fec: Use ENET_FTRL to determine truncation length Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 15/26] imx_fec: Use MIN instead of explicit ternary operator Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 16/26] imx_fec: Emulate SHIFT16 in ENETx_RACC Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 17/26] imx_fec: Add support for multiple Tx DMA rings Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 18/26] imx_fec: Use correct length for packet size Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 19/26] imx_fec: Fix a typo in imx_enet_receive() Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 20/26] imx_fec: Reserve full FSL_IMX25_FEC_SIZE page for the register file Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 21/26] hw/timer/pxa2xx_timer: replace hw_error() -> qemu_log_mask() Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 22/26] hw/sd/pxa2xx_mmci: add read/write() trace events Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 23/26] linux-user/arm/nwfpe: Check coprocessor number for FPA emulation Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 24/26] target/arm: Make disas_thumb2_insn() generate its own UNDEF exceptions Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 25/26] hw/intc/arm_gicv3: Make reserved register addresses RAZ/WI Peter Maydell
2018-01-11 13:38 ` [Qemu-devel] [PULL 26/26] hw/intc/arm_gic: reserved register addresses are RAZ/WI Peter Maydell
2018-01-11 14:19 ` [Qemu-devel] [PULL 00/26] target-arm queue no-reply
2018-01-11 15:24 ` Peter Maydell
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=1515677902-23436-13-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).