From nobody Mon Feb 9 16:45:00 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513263695337538.9663380575482; Thu, 14 Dec 2017 07:01:35 -0800 (PST) Received: from localhost ([::1]:41414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePV0j-0007fj-CL for importer@patchew.org; Thu, 14 Dec 2017 10:01:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePUt6-0001OW-0T for qemu-devel@nongnu.org; Thu, 14 Dec 2017 09:53:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePUt4-0000Nk-VT for qemu-devel@nongnu.org; Thu, 14 Dec 2017 09:53:28 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePUt2-0000H0-7F; Thu, 14 Dec 2017 09:53:24 -0500 Received: by mail-pf0-x243.google.com with SMTP id p84so3774381pfd.3; Thu, 14 Dec 2017 06:53:24 -0800 (PST) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id e7sm8757439pfj.44.2017.12.14.06.53.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Dec 2017 06:53:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=okFMpTBn3CPHVnnf0sYzsV4tcjnm7uVfAD8Wu4GZgfo=; b=eEIw2cvoDIF0i9IZJRNSkYsErfyvjD9nSSnU96Nm3Zrjp1mlFNDsSvJpxPj4WX7sWQ VHXoXz8o/zYrClw/kDxjqZGI65XpiNC77XsHvl8UMJ9L2lS5eFZvO3ZxgGy3gfrw2W9J MDbREOdnl/LBtUmoRtgf0cEVxdxW9ajtj3tw1qdX++I5+xLUNy+++TWFHhBS7daCLjml ywhMFx6R34ocNRZpg1Qql/Lo6XODIT+4J+wj2tYB/O+JCNgNP0aAp1gcR90CmG5kpw/U RLErOyyjj6NU89PBODRSjwIJR+Ao2m3fW8T4AqH+pjVsvrWGrDPxpPQQqJIDsddIAoPU 5P9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=okFMpTBn3CPHVnnf0sYzsV4tcjnm7uVfAD8Wu4GZgfo=; b=idfae42+0vZ6w2H5UVc7SPth0kt8t4ehdqDfV2YSe1NmRtmE4fYkOkRFxzaBOF+NqU Dx8hIwRa33vxyF/3fyskmiLHUQY3bx8Z0+QxmM+jMbVP7JZs/8rgt7DoAv4MYRXI4xLj OHFh4v9N0jeLGT1Ta73Ml1V8srWBegDLbm3tr+UwXU4+W0izkkCfr1ZoQEIFsRH1YYYr 1t1ScbRQESffu2OuCDYkTxNK/GSu5nC8KIWlLQa+Iamrlk2d47A+UJfLxh49zPGyP//2 dlp9qvaarFVpXR9xwgPgKnrhOF+yky006zC5A56Jr2NMZFh4Cec6fgfqeKmajT+DxXWo qzfA== X-Gm-Message-State: AKGB3mKVnD52ii2hLHSrGkwSKcAwKVIJ6rW8+03V8p2UmwyNxHLSdOZ8 yHUXk5RowYJpIMGEXnwZaNNB2wA2 X-Google-Smtp-Source: ACJfBovTCw2lChInRF799Nem1gck/TTFrvOYqgT8Z+n6DCXEXvJRotpeGG5VBAsbsxxkqtECOa7GxQ== X-Received: by 10.98.17.196 with SMTP id 65mr9971369pfr.35.1513263202653; Thu, 14 Dec 2017 06:53:22 -0800 (PST) From: Andrey Smirnov To: qemu-arm@nongnu.org Date: Thu, 14 Dec 2017 06:52:43 -0800 Message-Id: <20171214145255.31545-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171214145255.31545-1-andrew.smirnov@gmail.com> References: <20171214145255.31545-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v2 03/15] imx_fec: Change queue flushing heuristics X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrey Smirnov , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, yurovsky@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 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=3Dimx.fec,netdev=3Dlan0 \ netdev tap,id=3Dlan0,ifname=3Dtap0,script=3Dno,downscript=3Dno \ ... 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] =3D 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 Cc: Jason Wang Cc: Philippe Mathieu-Daud=C3=A9 Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Cc: yurovsky@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Andrey Smirnov --- 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 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) } } =20 -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) =20 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)); } =20 @@ -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] =3D ENET_RDAR_RDAR; - imx_eth_enable_rx(s); + imx_eth_enable_rx(s, true); } } else { s->regs[index] =3D 0; @@ -930,7 +930,7 @@ static int imx_eth_can_receive(NetClientState *nc) =20 FEC_PRINTF("\n"); =20 - return s->regs[ENET_RDAR] ? 1 : 0; + return !!s->regs[ENET_RDAR]; } =20 static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, @@ -1020,7 +1020,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, co= nst uint8_t *buf, } } s->rx_descriptor =3D 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, c= onst uint8_t *buf, } } s->rx_descriptor =3D addr; - imx_eth_enable_rx(s); + imx_eth_enable_rx(s, false); imx_eth_update(s); return len; } --=20 2.14.3