From patchwork Thu May 9 16:36:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 242791 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 41CCE2C00E4 for ; Fri, 10 May 2013 02:37:25 +1000 (EST) Received: from localhost ([::1]:60459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaTqN-0008SG-Gr for incoming@patchwork.ozlabs.org; Thu, 09 May 2013 12:37:23 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaTpA-0006vg-AW for qemu-devel@nongnu.org; Thu, 09 May 2013 12:36:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UaTp9-0004Ih-3y for qemu-devel@nongnu.org; Thu, 09 May 2013 12:36:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaTp8-0004Ic-RW for qemu-devel@nongnu.org; Thu, 09 May 2013 12:36:07 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r49Ga6B4020489 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 May 2013 12:36:06 -0400 Received: from bling.home (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r49Ga5Fp032252; Thu, 9 May 2013 12:36:05 -0400 To: jan.kiszka@siemens.com, mst@redhat.com From: Alex Williamson Date: Thu, 09 May 2013 10:36:05 -0600 Message-ID: <20130509163605.22536.77178.stgit@bling.home> In-Reply-To: <20130509163157.22536.68566.stgit@bling.home> References: <20130509163157.22536.68566.stgit@bling.home> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/2] pci-assign: Add MSI affinity support 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 Track the last MSIMessage programmed so we can determine when it has changed and update the routing to the guest. Signed-off-by: Alex Williamson --- hw/i386/kvm/pci-assign.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c index 0f83a4c..e09265b 100644 --- a/hw/i386/kvm/pci-assign.c +++ b/hw/i386/kvm/pci-assign.c @@ -134,6 +134,7 @@ typedef struct AssignedDevice { int msi_nr; struct { int virq; + MSIMessage msg; } *msi; MSIXTableEntry *msix_table; hwaddr msix_table_addr; @@ -1015,6 +1016,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev) assigned_dev->msi = g_malloc(sizeof(*assigned_dev->msi)); assigned_dev->msi_nr = 1; assigned_dev->msi[0].virq = virq; + assigned_dev->msi[0].msg = msg; if (kvm_device_msi_assign(kvm_state, assigned_dev->dev_id, virq) < 0) { perror("assigned_dev_update_msi: kvm_device_msi_assign"); } @@ -1027,6 +1029,27 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev) } } +static void assigned_dev_update_msi_msg(PCIDevice *pci_dev) +{ + AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev); + uint8_t ctrl_byte = pci_get_byte(pci_dev->config + pci_dev->msi_cap + + PCI_MSI_FLAGS); + MSIMessage msg; + + if (assigned_dev->assigned_irq_type != ASSIGNED_IRQ_MSI || + !(ctrl_byte & PCI_MSI_FLAGS_ENABLE)) { + return; + } + + msg = msi_get_message(pci_dev, 0); + + if (msg.address != assigned_dev->msi[0].msg.address || + msg.data != assigned_dev->msi[0].msg.data) { + kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi[0].virq, msg); + assigned_dev->msi[0].msg = msg; + } +} + static bool assigned_dev_msix_masked(MSIXTableEntry *entry) { return (entry->ctrl & cpu_to_le32(0x1)) != 0; @@ -1202,6 +1225,10 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address, if (range_covers_byte(address, len, pci_dev->msi_cap + PCI_MSI_FLAGS)) { assigned_dev_update_msi(pci_dev); + } else if (ranges_overlap(address, len, + pci_dev->msi_cap + PCI_MSI_ADDRESS_LO, + 10 - PCI_MSI_ADDRESS_LO)) { + assigned_dev_update_msi_msg(pci_dev); } } if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {