From patchwork Tue Apr 19 08:38:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 612038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qpzFC07z2z9syq for ; Tue, 19 Apr 2016 18:48:30 +1000 (AEST) Received: from localhost ([::1]:54092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asRKf-0007bZ-0A for incoming@patchwork.ozlabs.org; Tue, 19 Apr 2016 04:48:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asRCA-0007G2-O8 for qemu-devel@nongnu.org; Tue, 19 Apr 2016 04:39:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asRC9-0006MB-LM for qemu-devel@nongnu.org; Tue, 19 Apr 2016 04:39:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asRC9-0006M5-EQ for qemu-devel@nongnu.org; Tue, 19 Apr 2016 04:39:41 -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 1658BC049E1E; Tue, 19 Apr 2016 08:39:41 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-238.nay.redhat.com [10.66.14.238]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3J8clBT031338; Tue, 19 Apr 2016 04:39:37 -0400 From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Apr 2016 16:38:39 +0800 Message-Id: <1461055122-32378-14-git-send-email-peterx@redhat.com> In-Reply-To: <1461055122-32378-1-git-send-email-peterx@redhat.com> References: <1461055122-32378-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 v4 13/16] intel_iommu: add support for split irqchip 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, rth@twiddle.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In split irqchip mode, IOAPIC is working in user space, only update kernel irq routes when entry changed. When IR is enabled, we directly update the kernel with translated messages. It works just like a kernel cache for the remapping entries. Since KVM irqfd is using kernel gsi routes to deliver interrupts, as long as we can support split irqchip, we will support irqfd as well. Also, since kernel gsi routes will cache translated interrupts, irqfd delivery will not suffer from any performance impact due to IR. And, since we supported irqfd, vhost devices will be able to work seamlessly with IR now. Logically this should contain both vhost-net and vhost-user case. Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 5 +++++ include/hw/i386/intel_iommu.h | 2 ++ target-i386/kvm.c | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 58f6064..ca7e069 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2138,6 +2138,11 @@ do_not_translate: return 0; } +int vtd_int_remap(void *iommu, MSIMessage *src, MSIMessage *dst) +{ + return vtd_interrupt_remap_msi(iommu, src, dst); +} + static uint64_t vtd_mem_ir_read(void *opaque, hwaddr addr, unsigned size) { uint64_t data = 0; diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 5945670..5910e6f 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -25,6 +25,7 @@ #include "sysemu/dma.h" #include "hw/i386/ioapic.h" #include "hw/pci/msi.h" +#include "hw/sysbus.h" #define TYPE_INTEL_IOMMU_DEVICE "intel-iommu" #define INTEL_IOMMU_DEVICE(obj) \ @@ -250,5 +251,6 @@ struct IntelIOMMUState { VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn); /* Get default IOMMU object */ IntelIOMMUState *vtd_iommu_get(void); +int vtd_int_remap(void *iommu, MSIMessage *src, MSIMessage *dst); #endif diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 799fdfa..7a996a2 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -36,6 +36,7 @@ #include "hw/i386/apic.h" #include "hw/i386/apic_internal.h" #include "hw/i386/apic-msidef.h" +#include "hw/i386/intel_iommu.h" #include "exec/ioport.h" #include "standard-headers/asm-x86/hyperv.h" @@ -3327,6 +3328,29 @@ int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id) int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, uint64_t address, uint32_t data, PCIDevice *dev) { + IntelIOMMUState *iommu = vtd_iommu_get(); + + if (iommu) { + int ret; + MSIMessage src, dst; + + src.address = route->u.msi.address_hi; + src.address <<= VTD_MSI_ADDR_HI_SHIFT; + src.address |= route->u.msi.address_lo; + src.data = route->u.msi.data; + + ret = vtd_int_remap(iommu, &src, &dst); + if (ret) { + error_report("VT-d Failed to remap interrupt for gsi %d.", + route->gsi); + return 1; + } + + route->u.msi.address_hi = dst.address >> VTD_MSI_ADDR_HI_SHIFT; + route->u.msi.address_lo = dst.address & VTD_MSI_ADDR_LO_MASK; + route->u.msi.data = dst.data; + } + return 0; }