From patchwork Thu Mar 5 05:48:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 446624 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 2E6B314015A for ; Thu, 5 Mar 2015 16:56:49 +1100 (AEDT) Received: from localhost ([::1]:48504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTOm7-0004Sw-Fx for incoming@patchwork.ozlabs.org; Thu, 05 Mar 2015 00:56:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTOfa-0006oB-PL for qemu-devel@nongnu.org; Thu, 05 Mar 2015 00:50:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTOfY-00026p-Uv for qemu-devel@nongnu.org; Thu, 05 Mar 2015 00:50:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTOfY-00026j-Nb; Thu, 05 Mar 2015 00:50:00 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t255nxs1003328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 5 Mar 2015 00:49:59 -0500 Received: from jason-ThinkPad-T430s.nay.redhat.com ([10.66.70.106]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t255mx4J006801; Thu, 5 Mar 2015 00:49:55 -0500 From: Jason Wang To: qemu-devel@nongnu.org Date: Thu, 5 Mar 2015 13:48:51 +0800 Message-Id: <1425534531-6305-15-git-send-email-jasowang@redhat.com> In-Reply-To: <1425534531-6305-1-git-send-email-jasowang@redhat.com> References: <1425534531-6305-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: "Michael S. Tsirkin" , Jason Wang , Alexander Graf , qemu-ppc@nongnu.org, Anthony Liguori , Paolo Bonzini , Richard Henderson Subject: [Qemu-devel] [PATCH V3 14/14] virtio-pci: introduce auto_msix_bar_size property 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 Currently we don't support more than 128 MSI-X vectors for a pci devices, trying to use vector=129 for a virtio-net-pci device may get: qemu-system-x86_64: -device virtio-net-pci,netdev=hn0,vectors=129: unable to init msix vectors to 129 This this because the MSI-X bar size were hard-coded as 4096. So this patch introduces boolean auto_msix_bar_size property for virito-pcidevices. Enable this will let the device calculate the msix bar sizebased on the number of MSI-X entries instead of previous 4096 hard-coded limit. This is a must to let virtio-net can up to 256 queues and each queue were associated with a specific MSI-X entry. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Anthony Liguori Cc: Michael S. Tsirkin Cc: Alexander Graf Cc: qemu-ppc@nongnu.org Signed-off-by: Jason Wang --- hw/i386/pc_piix.c | 4 ++++ hw/i386/pc_q35.c | 4 ++++ hw/ppc/spapr.c | 5 +++++ hw/virtio/virtio-pci.c | 17 +++++++++++++++-- hw/virtio/virtio-pci.h | 3 +++ include/hw/compat.h | 8 ++++++++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 821d44c..07bf0b4 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -537,6 +537,10 @@ static QEMUMachine pc_i440fx_machine_v2_2 = { PC_I440FX_2_2_MACHINE_OPTIONS, .name = "pc-i440fx-2.2", .init = pc_init_pci_2_2, + .compat_props = (GlobalProperty[]) { + HW_COMPAT_2_2, + { /* end of list */ } + }, }; #define PC_I440FX_2_1_MACHINE_OPTIONS \ diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index dc5ada4..42799ab 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -433,6 +433,10 @@ static QEMUMachine pc_q35_machine_v2_2 = { PC_Q35_2_2_MACHINE_OPTIONS, .name = "pc-q35-2.2", .init = pc_q35_init_2_2, + .compat_props = (GlobalProperty[]) { + HW_COMPAT_2_2, + { /* end of list */ } + }, }; #define PC_Q35_2_1_MACHINE_OPTIONS \ diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b560459..b50d600 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1777,11 +1777,16 @@ static const TypeInfo spapr_machine_2_1_info = { static void spapr_machine_2_2_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); + static GlobalProperty compat_props[] = { + HW_COMPAT_2_2, + { /* end of list */ } + }; mc->name = "pseries-2.2"; mc->desc = "pSeries Logical Partition (PAPR compliant) v2.2"; mc->alias = "pseries"; mc->is_default = 1; + mc->compat_props = compat_props; } static const TypeInfo spapr_machine_2_2_info = { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 0d26cb4..26d4773 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -972,7 +972,7 @@ static void virtio_pci_device_plugged(DeviceState *d) VirtIOPCIProxy *proxy = VIRTIO_PCI(d); VirtioBusState *bus = &proxy->bus; uint8_t *config; - uint32_t size; + uint32_t size, bar_size; config = proxy->pci_dev.config; if (proxy->class_code) { @@ -983,8 +983,19 @@ static void virtio_pci_device_plugged(DeviceState *d) pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus)); config[PCI_INTERRUPT_PIN] = 1; + if (proxy->flags & VIRTIO_PCI_FLAG_AUTO_MSIX_SIZE) { + bar_size = proxy->nvectors * PCI_MSIX_ENTRY_SIZE * 2; + if (bar_size & (bar_size - 1)) { + bar_size = 1 << qemu_fls(bar_size); + } + } else { + /* For migration compatibility */ + bar_size = 4096; + } + if (proxy->nvectors && - msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1, 4096)) { + msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1, + bar_size)) { error_report("unable to init msix vectors to %" PRIu32, proxy->nvectors); proxy->nvectors = 0; @@ -1429,6 +1440,8 @@ static const TypeInfo virtio_serial_pci_info = { static Property virtio_net_properties[] = { DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), + DEFINE_PROP_BIT("auto_msix_bar_size", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_AUTO_MSIX_SIZE_BIT, true), DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features), DEFINE_PROP_END_OF_LIST(), diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 8873b6d..96dea82 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -62,6 +62,9 @@ typedef struct VirtioBusClass VirtioPCIBusClass; * vcpu thread using ioeventfd for some devices. */ #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT) +#define VIRTIO_PCI_FLAG_AUTO_MSIX_SIZE_BIT 2 +#define VIRTIO_PCI_FLAG_AUTO_MSIX_SIZE \ + (1 << VIRTIO_PCI_FLAG_AUTO_MSIX_SIZE_BIT) typedef struct { MSIMessage msg; diff --git a/include/hw/compat.h b/include/hw/compat.h index 313682a..3e5c5ae 100644 --- a/include/hw/compat.h +++ b/include/hw/compat.h @@ -1,7 +1,15 @@ #ifndef HW_COMPAT_H #define HW_COMPAT_H +#define HW_COMPAT_2_2 \ + {\ + .driver = "virtio-net-pci",\ + .property = "auto_msix_bar_size",\ + .value = "off",\ + } + #define HW_COMPAT_2_1 \ + HW_COMPAT_2_2, \ {\ .driver = "intel-hda",\ .property = "old_msi_addr",\