From patchwork Wed Sep 22 19:52:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 65449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7C856B70D5 for ; Thu, 23 Sep 2010 05:53:45 +1000 (EST) Received: from localhost ([127.0.0.1]:37807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OyVNr-0005P8-Gi for incoming@patchwork.ozlabs.org; Wed, 22 Sep 2010 15:53:39 -0400 Received: from [140.186.70.92] (port=36516 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OyVN2-0005Nq-0a for qemu-devel@nongnu.org; Wed, 22 Sep 2010 15:52:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OyVN0-0006FQ-V5 for qemu-devel@nongnu.org; Wed, 22 Sep 2010 15:52:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34497) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OyVN0-0006F8-OP for qemu-devel@nongnu.org; Wed, 22 Sep 2010 15:52:46 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8MJqjCV017197 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Sep 2010 15:52:45 -0400 Received: from s20.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8MJqiIT032158; Wed, 22 Sep 2010 15:52:44 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Wed, 22 Sep 2010 13:52:44 -0600 Message-ID: <20100922195244.30890.93113.stgit@s20.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: alex.williamson@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH] virtio-net: Don't pass NULL peer to tap routines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org During a hotplug, the netdev might be removed before the connected virtio device. When this happens, the guest might be running cleanup operations that can trigger a segfault in qemu. Avoid one set of these by checking whether the peer device is present before trying to do tap operations. Signed-off-by: Alex Williamson --- hw/virtio-net.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 0a9cae2..2c758ad 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -216,6 +216,10 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) n->mergeable_rx_bufs = !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF)); + if (!n->nic->nc.peer || + n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP) { + return; + } if (n->has_vnet_hdr) { tap_set_offload(n->nic->nc.peer, (features >> VIRTIO_NET_F_GUEST_CSUM) & 1, @@ -224,10 +228,6 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) (features >> VIRTIO_NET_F_GUEST_ECN) & 1, (features >> VIRTIO_NET_F_GUEST_UFO) & 1); } - if (!n->nic->nc.peer || - n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP) { - return; - } if (!tap_get_vhost_net(n->nic->nc.peer)) { return; } @@ -859,7 +859,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) return -1; } - if (n->has_vnet_hdr) { + if (n->nic->nc.peer && n->has_vnet_hdr) { tap_using_vnet_hdr(n->nic->nc.peer, 1); tap_set_offload(n->nic->nc.peer, (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_CSUM) & 1,