From patchwork Thu Sep 4 16:38:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 385901 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 A9C8214010C for ; Fri, 5 Sep 2014 02:39:27 +1000 (EST) Received: from localhost ([::1]:52605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPa4D-0004lU-Pe for incoming@patchwork.ozlabs.org; Thu, 04 Sep 2014 12:39:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPa3T-0003N3-95 for qemu-devel@nongnu.org; Thu, 04 Sep 2014 12:38:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPa3O-0005yc-Bi for qemu-devel@nongnu.org; Thu, 04 Sep 2014 12:38:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPa3O-0005yK-3d for qemu-devel@nongnu.org; Thu, 04 Sep 2014 12:38:34 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s84GcSMH028165 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 4 Sep 2014 12:38:28 -0400 Received: from localhost (ovpn-112-58.ams2.redhat.com [10.36.112.58]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s84GcRlM002863; Thu, 4 Sep 2014 12:38:27 -0400 From: Stefan Hajnoczi To: Date: Thu, 4 Sep 2014 17:38:14 +0100 Message-Id: <1409848699-28374-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1409848699-28374-1-git-send-email-stefanha@redhat.com> References: <1409848699-28374-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , zhanghailiang , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 1/6] 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 From: zhanghailiang 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 Signed-off-by: Stefan Hajnoczi --- net/net.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/net.c b/net/net.c index 6d930ea..962c05f 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; }