From patchwork Wed Apr 28 20:16:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 95774 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3SKK5GN029115 for ; Wed, 28 Apr 2010 20:20:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932172Ab0D1UUA (ORCPT ); Wed, 28 Apr 2010 16:20:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43095 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757003Ab0D1UT6 (ORCPT ); Wed, 28 Apr 2010 16:19:58 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3SKJwFG027811 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 28 Apr 2010 16:19:58 -0400 Received: from redhat.com (vpn1-5-200.ams2.redhat.com [10.36.5.200]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o3SKJtx7024423; Wed, 28 Apr 2010 16:19:55 -0400 Date: Wed, 28 Apr 2010 23:16:15 +0300 From: "Michael S. Tsirkin" To: Juan Quintela , amit.shah@redhat.com, kraxel@redhat.com, mtosatti@redhat.com Cc: amit.shah@redhat.com, kraxel@redhat.com, kvm@vger.kernel.org Subject: [RHEL6.0 PATCH] qemu-kvm: fix crash on reboot with vhost-net Message-ID: <20100428201615.GA12865@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 28 Apr 2010 20:20:05 +0000 (UTC) diff --git a/hw/msix.c b/hw/msix.c index 3fcf3a1..94e3981 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -610,14 +610,44 @@ void msix_unuse_all_vectors(PCIDevice *dev) int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque) { + int r; + if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector]) + return 0; + + assert(dev->msix_mask_notifier); + assert(opaque); + assert(!dev->msix_mask_notifier_opaque[vector]); + + if (msix_is_masked(dev, vector)) { + return 0; + } + r = dev->msix_mask_notifier(dev, vector, opaque, + msix_is_masked(dev, vector)); + if (r < 0) { + return r; + } + dev->msix_mask_notifier_opaque[vector] = opaque; + return r; +} + +int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector) +{ int r = 0; if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector]) return 0; - if (dev->msix_mask_notifier) - r = dev->msix_mask_notifier(dev, vector, opaque, - msix_is_masked(dev, vector)); - if (r >= 0) - dev->msix_mask_notifier_opaque[vector] = opaque; + assert(dev->msix_mask_notifier); + assert(dev->msix_mask_notifier_opaque[vector]); + + if (msix_is_masked(dev, vector)) { + return 0; + } + r = dev->msix_mask_notifier(dev, vector, + dev->msix_mask_notifier_opaque[vector], + msix_is_masked(dev, vector)); + if (r < 0) { + return r; + } + dev->msix_mask_notifier_opaque[vector] = NULL; return r; } diff --git a/hw/msix.h b/hw/msix.h index f167231..6b21ffb 100644 --- a/hw/msix.h +++ b/hw/msix.h @@ -34,4 +34,5 @@ void msix_reset(PCIDevice *dev); extern int msix_supported; int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque); +int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector); #endif diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index cba188c..22f7fa0 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -437,10 +437,13 @@ static int virtio_pci_guest_notifier(void *opaque, int n, bool assign) msix_set_mask_notifier(&proxy->pci_dev, virtio_queue_vector(proxy->vdev, n), vq); } else { - msix_set_mask_notifier(&proxy->pci_dev, - virtio_queue_vector(proxy->vdev, n), NULL); + msix_unset_mask_notifier(&proxy->pci_dev, + virtio_queue_vector(proxy->vdev, n)); qemu_set_fd_handler(event_notifier_get_fd(notifier), NULL, NULL, NULL); + /* Test and clear notifier before closing it, + * in case poll callback didn't have time to run. */ + virtio_pci_guest_notifier_read(vq); event_notifier_cleanup(notifier); }