From patchwork Thu Aug 30 07:36:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1386711 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 749CDDF215 for ; Thu, 30 Aug 2012 07:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751636Ab2H3Hgm (ORCPT ); Thu, 30 Aug 2012 03:36:42 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:49939 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751298Ab2H3Hgh (ORCPT ); Thu, 30 Aug 2012 03:36:37 -0400 Received: by wibhq12 with SMTP id hq12so8578213wib.1 for ; Thu, 30 Aug 2012 00:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=kF9yWI4IlioRKIKlKsRwfKEHJme15V170qXwq4hj6cI=; b=RT6npDZ+ujhLMsoKo/GrSZpNAWur1rllRYz92nh4mSWl7wa9OwY9oV/hxbMbkXNlaF zplf5ADP16tyPetnc1V77D8Uuj9jvE/6XurFvDBNlapGx4nbr5r3O6fGBEUXar8FDRF2 4ECdaD7Hy7wtHr/KUHd1B16OxXJHtIRm/y2940xlHMBZPwrn80A4KsT3VZIq4x3Esbbp m4oYzUt/kbsJSlQL8W6A3F1aTu3Be6JBVMfKyfuvz0Lr4gnEU5cGQth7nMFKce4YuKYO aFz9qsPdMr8qwTEQjFehFeeIYtPaf9fBzoD7kz6gtdWQqNiXEfHok2XaTUUZnbN260Dx TxUQ== Received: by 10.180.106.97 with SMTP id gt1mr46005722wib.5.1346312196168; Thu, 30 Aug 2012 00:36:36 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id fr4sm2847342wib.8.2012.08.30.00.36.33 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Aug 2012 00:36:35 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 3/7] kvm tools: Use the new KVM_SIGNAL_MSI ioctl to inject interrupts directly. Date: Thu, 30 Aug 2012 09:36:39 +0200 Message-Id: <1346312203-29456-3-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346312203-29456-1-git-send-email-levinsasha928@gmail.com> References: <1346312203-29456-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We still create GSIs and keep them for two reasons: - They're required by virtio-* devices. - There's not much overhead since we just create them when starting the guest, they don't use anything when the guest is running. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/virtio-pci.h | 3 +++ tools/kvm/virtio/pci.c | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/kvm/include/kvm/virtio-pci.h b/tools/kvm/include/kvm/virtio-pci.h index 9e036b2..44130e0c 100644 --- a/tools/kvm/include/kvm/virtio-pci.h +++ b/tools/kvm/include/kvm/virtio-pci.h @@ -15,6 +15,8 @@ struct virtio_pci_ioevent_param { u32 vq; }; +#define VIRTIO_PCI_F_SIGNAL_MSI (1 << 0) + struct virtio_pci { struct pci_device_header pci_hdr; void *dev; @@ -22,6 +24,7 @@ struct virtio_pci { u16 base_addr; u8 status; u8 isr; + u32 features; /* MSI-X */ u16 config_vector; diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c index f17cd8a..4dc7916 100644 --- a/tools/kvm/virtio/pci.c +++ b/tools/kvm/virtio/pci.c @@ -7,6 +7,7 @@ #include "kvm/virtio.h" #include "kvm/ioeventfd.h" +#include #include #include #include @@ -236,6 +237,17 @@ static void virtio_pci__mmio_callback(u64 addr, u8 *data, u32 len, u8 is_write, memcpy(data, table + addr - offset, len); } +static void virtio_pci__signal_msi(struct kvm *kvm, struct virtio_pci *vpci, int vec) +{ + struct kvm_msi msi = { + .address_lo = vpci->msix_table[vec].msg.address_lo, + .address_hi = vpci->msix_table[vec].msg.address_hi, + .data = vpci->msix_table[vec].msg.data, + }; + + ioctl(kvm->vm_fd, KVM_SIGNAL_MSI, &msi); +} + int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq) { struct virtio_pci *vpci = vdev->virtio; @@ -249,7 +261,10 @@ int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq) return 0; } - kvm__irq_trigger(kvm, vpci->gsis[vq]); + if (vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) + virtio_pci__signal_msi(kvm, vpci, vpci->vq_vector[vq]); + else + kvm__irq_trigger(kvm, vpci->gsis[vq]); } else { vpci->isr = VIRTIO_IRQ_HIGH; kvm__irq_trigger(kvm, vpci->pci_hdr.irq_line); @@ -270,7 +285,10 @@ int virtio_pci__signal_config(struct kvm *kvm, struct virtio_device *vdev) return 0; } - kvm__irq_trigger(kvm, vpci->config_gsi); + if (vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) + virtio_pci__signal_msi(kvm, vpci, vpci->vq_vector[vpci->config_vector]); + else + kvm__irq_trigger(kvm, vpci->config_gsi); } else { vpci->isr = VIRTIO_PCI_ISR_CONFIG; kvm__irq_trigger(kvm, vpci->pci_hdr.irq_line); @@ -347,6 +365,9 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev, if (r < 0) goto free_mmio; + if (kvm__supports_extension(kvm, KVM_CAP_SIGNAL_MSI)) + vpci->features |= VIRTIO_PCI_F_SIGNAL_MSI; + vpci->pci_hdr.irq_pin = pin; vpci->pci_hdr.irq_line = line; r = pci__register(&vpci->pci_hdr, ndev);