From patchwork Thu May 5 03:25:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 618835 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 3r0ghs1RHnz9s5Q for ; Thu, 5 May 2016 13:42:37 +1000 (AEST) Received: from localhost ([::1]:51539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayABL-0008Ts-S7 for incoming@patchwork.ozlabs.org; Wed, 04 May 2016 23:42:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ay9xY-0005kr-OU for qemu-devel@nongnu.org; Wed, 04 May 2016 23:28:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ay9xM-0008L5-Hv for qemu-devel@nongnu.org; Wed, 04 May 2016 23:28:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ay9xM-0008Hp-Ak for qemu-devel@nongnu.org; Wed, 04 May 2016 23:28:04 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 393597F093; Thu, 5 May 2016 03:27:53 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-147.nay.redhat.com [10.66.14.147]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u453Q5Q1016941; Wed, 4 May 2016 23:27:49 -0400 From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 5 May 2016 11:25:59 +0800 Message-Id: <1462418761-12714-25-git-send-email-peterx@redhat.com> In-Reply-To: <1462418761-12714-1-git-send-email-peterx@redhat.com> References: <1462418761-12714-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 24/26] kvm-irqchip: i386: add hook for add/remove virq X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, mst@redhat.com, jasowang@redhat.com, rkrcmar@redhat.com, peterx@redhat.com, alex.williamson@redhat.com, jan.kiszka@web.de, wexu@redhat.com, pbonzini@redhat.com, marcel@redhat.com, imammedo@redhat.com, davidkiarie4@gmail.com, rth@twiddle.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Adding two hooks to be notified when adding/removing msi routes. On x86 platform, one list is maintained for all existing msi routes. Signed-off-by: Peter Xu --- include/sysemu/kvm.h | 6 ++++++ kvm-all.c | 2 ++ target-arm/kvm.c | 11 +++++++++++ target-i386/kvm.c | 38 ++++++++++++++++++++++++++++++++++++++ target-mips/kvm.c | 11 +++++++++++ target-ppc/kvm.c | 11 +++++++++++ target-s390x/kvm.c | 11 +++++++++++ trace-events | 2 ++ 8 files changed, 92 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 20b52f0..94a7f63 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -355,6 +355,12 @@ void kvm_arch_init_irq_routing(KVMState *s); int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, uint64_t address, uint32_t data, PCIDevice *dev); +/* Notify arch about newly added MSI routes */ +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev); +/* Notify arch about released MSI routes */ +int kvm_arch_release_virq_post(int virq); + int kvm_arch_msi_data_to_gsi(uint32_t data); int kvm_set_irq(KVMState *s, int irq, int level); diff --git a/kvm-all.c b/kvm-all.c index f0dc769..a984564 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1073,6 +1073,7 @@ void kvm_irqchip_release_virq(KVMState *s, int virq) } } clear_gsi(s, virq); + kvm_arch_release_virq_post(virq); } static unsigned int kvm_hash_msi(uint32_t data) @@ -1221,6 +1222,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) } kvm_add_routing_entry(s, &kroute); + kvm_arch_add_msi_route_post(&kroute, vector, dev); kvm_irqchip_commit_routes(s); return virq; diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 3671032..90c293e 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -622,6 +622,17 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, return 0; } +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev) +{ + return 0; +} + +int kvm_arch_release_virq_post(int virq) +{ + return 0; +} + int kvm_arch_msi_data_to_gsi(uint32_t data) { return (data - 32) & 0xffff; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index d1a4d77..f043e45 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -3355,6 +3355,44 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, return 0; } +typedef struct MSIRouteEntry MSIRouteEntry; + +struct MSIRouteEntry { + PCIDevice *dev; /* Device pointer */ + int vector; /* MSI/MSIX vector index */ + int virq; /* Virtual IRQ index */ + QLIST_ENTRY(MSIRouteEntry) list; +}; + +/* List of used GSI routes */ +static QLIST_HEAD(, MSIRouteEntry) msi_route_list = \ + QLIST_HEAD_INITIALIZER(msi_route_list); + +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev) +{ + MSIRouteEntry *entry = g_new0(MSIRouteEntry, 1); + entry->dev = dev; + entry->vector = vector; + entry->virq = route->gsi; + QLIST_INSERT_HEAD(&msi_route_list, entry, list); + trace_kvm_x86_add_msi_route(route->gsi); + return 0; +} + +int kvm_arch_release_virq_post(int virq) +{ + MSIRouteEntry *entry, *next; + QLIST_FOREACH_SAFE(entry, &msi_route_list, list, next) { + if (entry->virq == virq) { + trace_kvm_x86_remove_msi_route(virq); + QLIST_REMOVE(entry, list); + break; + } + } + return 0; +} + int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); diff --git a/target-mips/kvm.c b/target-mips/kvm.c index 950bc05..1dd7904 100644 --- a/target-mips/kvm.c +++ b/target-mips/kvm.c @@ -1044,6 +1044,17 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, return 0; } +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev) +{ + return 0; +} + +int kvm_arch_release_virq_post(int virq) +{ + return 0; +} + int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index c4c8146..143a2bf 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -2566,6 +2566,17 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, return 0; } +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev) +{ + return 0; +} + +int kvm_arch_release_virq_post(int virq) +{ + return 0; +} + int kvm_arch_msi_data_to_gsi(uint32_t data) { return data & 0xffff; diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index e1859ca..22d2ed4 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -2246,6 +2246,17 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, return 0; } +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev) +{ + return 0; +} + +int kvm_arch_release_virq_post(int virq) +{ + return 0; +} + int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); diff --git a/trace-events b/trace-events index b03d310..2eea7f7 100644 --- a/trace-events +++ b/trace-events @@ -1912,3 +1912,5 @@ aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 # target-i386/kvm.c kvm_x86_fixup_msi_error(uint32_t gsi) "VT-d failed to remap interrupt for GSI %" PRIu32 +kvm_x86_add_msi_route(int virq) "Adding route entry for virq %d" +kvm_x86_remove_msi_route(int virq) "Removing route entry for virq %d"