From patchwork Tue Aug 26 08:06:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 383004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DB40214009B for ; Tue, 26 Aug 2014 18:07:29 +1000 (EST) Received: from localhost ([::1]:52417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMBmp-0007Z0-WB for incoming@patchwork.ozlabs.org; Tue, 26 Aug 2014 04:07:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMBmX-0007Gn-23 for qemu-devel@nongnu.org; Tue, 26 Aug 2014 04:07:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMBmS-000444-8C for qemu-devel@nongnu.org; Tue, 26 Aug 2014 04:07:09 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:20506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMBmR-00043u-HC for qemu-devel@nongnu.org; Tue, 26 Aug 2014 04:07:04 -0400 Received: from 172.24.2.119 (EHLO szxeml423-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BYQ27389; Tue, 26 Aug 2014 16:06:46 +0800 (CST) Received: from localhost (10.177.22.69) by szxeml423-hub.china.huawei.com (10.82.67.162) with Microsoft SMTP Server id 14.3.158.1; Tue, 26 Aug 2014 16:06:34 +0800 From: zhanghailiang To: Date: Tue, 26 Aug 2014 16:06:17 +0800 Message-ID: <1409040377-12088-1-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.2.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.22.69] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: stefanha@redhat.com, mst@redhat.com, jasowang@redhat.com, luonengjun@huawei.com, peter.huangpeng@huawei.com, aliguori@amazon.com, zhanghailiang Subject: [Qemu-devel] [PATCH V4] net: Forbid dealing with packets when VM is not running X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For all NICs(except virtio-net) emulated by qemu, Such as e1000, rtl8139, pcnet and ne2k_pci, Qemu can still receive packets when VM is not running. If this happened in *migration's* last PAUSE VM stage, but before the end of the migration, the new receiving packets will possibly dirty parts of RAM which has been cached in *iovec*(will be sent asynchronously) and dirty parts of new RAM which will be missed. This will lead serious network fault in VM. To avoid this, we forbid receiving packets in generic net code when VM is not running. Bug reproduction steps: (1) Start a VM which configured at least one NIC (2) In VM, open several Terminal and do *Ping IP -i 0.1* (3) Migrate the VM repeatedly between two Hosts And the *PING* command in VM will very likely fail with message: 'Destination HOST Unreachable', the NIC in VM will stay unavailable unless you run 'service network restart' Signed-off-by: zhanghailiang Reviewed-by: Jason Wang Reviewed-by: Juan Quintela Reviewed-by: Michael S. Tsirkin --- v4: - The action of flush queued packets is unnecessary, remove this. (Thanks for the help of Jason Wang and Stefan). v3: - change the 'vmstate' to 'vm_running' v2: - remove the superfluous check of nc->received_disabled --- net/net.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/net.c b/net/net.c index 6d930ea..4cb92c0 100644 --- a/net/net.c +++ b/net/net.c @@ -41,6 +41,7 @@ #include "qapi-visit.h" #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h" +#include "sysemu/sysemu.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -452,6 +453,12 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) int qemu_can_send_packet(NetClientState *sender) { + int vm_running = runstate_is_running(); + + if (!vm_running) { + return 0; + } + if (!sender->peer) { return 1; }