From patchwork Mon Oct 17 09:27:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 120155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D107B6FA5 for ; Mon, 17 Oct 2011 21:50:52 +1100 (EST) Received: from localhost ([::1]:54881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFjX0-0001Cs-1q for incoming@patchwork.ozlabs.org; Mon, 17 Oct 2011 05:30:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]:32952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFjUm-0005FJ-SY for qemu-devel@nongnu.org; Mon, 17 Oct 2011 05:28:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RFjUi-0004If-Dg for qemu-devel@nongnu.org; Mon, 17 Oct 2011 05:28:32 -0400 Received: from david.siemens.de ([192.35.17.14]:19068) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFjUh-0004GW-Mk for qemu-devel@nongnu.org; Mon, 17 Oct 2011 05:28:28 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by david.siemens.de (8.13.6/8.13.6) with ESMTP id p9H9SQO6023442; Mon, 17 Oct 2011 11:28:26 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p9H9SKVZ023511; Mon, 17 Oct 2011 11:28:26 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Date: Mon, 17 Oct 2011 11:27:53 +0200 Message-Id: <869b269736f714cb82498954df06f6759d97c60f.1318843693.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.14 Cc: Alex Williamson , qemu-devel@nongnu.org, kvm@vger.kernel.org, "Michael S. Tsirkin" Subject: [Qemu-devel] [RFC][PATCH 19/45] qemu-kvm: Factor out kvm_msi_irqfd_set 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 This makes the KVM core layer aware of the irqfd associated with some MSI cache. kvm_msi_irqfd_set is defined for this purpose, which avoids that virtio needs to peek into the cache for extracting the GSI. Signed-off-by: Jan Kiszka --- hw/virtio-pci.c | 6 +++--- kvm.h | 2 ++ qemu-kvm.c | 14 +++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 23880e0..ad6a002 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -524,9 +524,9 @@ static int virtio_pci_mask_vq(PCIDevice *dev, unsigned vector, VirtQueue *vq, int masked) { EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); - int r = kvm_set_irqfd(dev->msix_cache[vector].kvm_gsi, - event_notifier_get_fd(notifier), - !masked); + int r = kvm_msi_irqfd_set(&dev->msix_cache[vector], + event_notifier_get_fd(notifier), + !masked); if (r < 0) { return (r == -ENOSYS) ? 0 : r; } diff --git a/kvm.h b/kvm.h index 3706fc6..fe2eec5 100644 --- a/kvm.h +++ b/kvm.h @@ -208,6 +208,8 @@ int kvm_msi_message_add(MSIMessage *msg, MSIRoutingCache *cache); int kvm_msi_message_del(MSIRoutingCache *cache); int kvm_msi_message_update(MSIMessage *msg, MSIRoutingCache *cache); +int kvm_msi_irqfd_set(MSIRoutingCache *cache, int fd, bool assigned); + int kvm_commit_irq_routes(void); int kvm_irqchip_in_kernel(void); diff --git a/qemu-kvm.c b/qemu-kvm.c index 13d4f90..ab7703b 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -352,8 +352,11 @@ int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry) *e = *p; cache = s->msi_cache[i]; - if (cache) { + if (cache && cache->type != MSI_ROUTE_NONE) { cache->type = MSI_ROUTE_NONE; + if (cache->kvm_irqfd >= 0) { + kvm_set_irqfd(cache->kvm_gsi, cache->kvm_irqfd, false); + } } s->msi_cache[i] = s->msi_cache[s->irq_routes->nr]; @@ -521,6 +524,15 @@ int kvm_msi_message_update(MSIMessage *msg, MSIRoutingCache *cache) } +int kvm_msi_irqfd_set(MSIRoutingCache *cache, int fd, bool assigned) +{ + if (cache->type == MSI_ROUTE_NONE) { + return assigned ? -EINVAL : 0; + } + cache->kvm_irqfd = assigned ? fd : -1; + return kvm_set_irqfd(cache->kvm_gsi, fd, assigned); +} + #ifdef KVM_CAP_DEVICE_MSIX int kvm_assign_set_msix_nr(KVMState *s, struct kvm_assigned_msix_nr *msix_nr) {