From patchwork Tue Jul 19 18:42:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 9238287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8564600CB for ; Tue, 19 Jul 2016 20:32:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D96E226C2F for ; Tue, 19 Jul 2016 20:32:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE48127569; Tue, 19 Jul 2016 20:32:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 643AB26C2F for ; Tue, 19 Jul 2016 20:32:14 +0000 (UTC) Received: from localhost ([::1]:58648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPbgb-0007Eq-F9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 16:32:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPZyx-00041Q-GZ for qemu-devel@nongnu.org; Tue, 19 Jul 2016 14:43:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPZyw-0004ON-8T for qemu-devel@nongnu.org; Tue, 19 Jul 2016 14:43:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPZyw-0004OJ-07 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 14:43:02 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 7DD877F7C3 for ; Tue, 19 Jul 2016 18:43:01 +0000 (UTC) Received: from work.redhat.com (vpn-202-72.tlv.redhat.com [10.35.202.72]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JIgxFG011336; Tue, 19 Jul 2016 14:42:59 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 21:42:58 +0300 Message-Id: <1468953778-15295-1-git-send-email-marcel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 19 Jul 2016 18:43:01 +0000 (UTC) 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 V2] hw/virtio-pci: fix virtio behaviour on modern (PCIe) machines 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: marcel@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Modern machines are expected to be used by newer setups with modern guests aiming the use of the latest features. Enable modern and disable legacy for virtio devices plugged into PCIe ports (Root ports or Downstream ports). Using the Virtio 1 mode will remove the limitation of the number of devices that can be attached to a machine by removing the need for the IO BAR. Convert 'disable-modern' and 'disable-legacy' properties to OnOffAuto with default Auto. Signed-off-by: Marcel Apfelbaum --- Hi, v1 -> v2: - Stick to existing defaults for old machine types (Michael S. Tsirkin) If everyone agrees, I am thinking about getting it into 2.7 to avoid the ~15 virtio devices limitation per machine. Notes: - The non PCIe machines behaviour should remain the same. - I hope is OK to make the disable-* properties OnOffAuto. Previous setups using them can be affected, but libvirt is not using them yet (as far as I know) - My tests were limited to checking all possible disable-* configurations (and make check for all archs) Thanks, Marcel hw/virtio/virtio-pci.c | 31 ++++++++++++++++++++++++------- hw/virtio/virtio-pci.h | 2 ++ include/hw/compat.h | 8 ++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 2b34b43..ec9e84f 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1716,6 +1716,8 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) { VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev); VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev); + bool pcie_port = (pci_bus_is_express(pci_dev->bus) && + !pci_bus_is_root(pci_dev->bus)); /* * virtio pci bar layout used by default. @@ -1766,8 +1768,23 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) address_space_init(&proxy->modern_as, &proxy->modern_cfg, "virtio-pci-cfg-as"); - if (pci_is_express(pci_dev) && pci_bus_is_express(pci_dev->bus) && - !pci_bus_is_root(pci_dev->bus)) { + if ((pcie_port && (proxy->disable_modern == ON_OFF_AUTO_AUTO)) + || (proxy->disable_modern == ON_OFF_AUTO_OFF)) { + proxy->flags &= ~VIRTIO_PCI_FLAG_DISABLE_MODERN; + pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; + } else { + proxy->flags |= VIRTIO_PCI_FLAG_DISABLE_MODERN; + pci_dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS; + } + + if ((pcie_port && (proxy->disable_legacy == ON_OFF_AUTO_AUTO)) + || (proxy->disable_legacy == ON_OFF_AUTO_ON)) { + proxy->flags |= VIRTIO_PCI_FLAG_DISABLE_LEGACY; + } else { + proxy->flags &= ~VIRTIO_PCI_FLAG_DISABLE_LEGACY; + } + + if (pcie_port && pci_is_express(pci_dev)) { int pos; pos = pcie_endpoint_cap_init(pci_dev, 0); @@ -1821,10 +1838,10 @@ static void virtio_pci_reset(DeviceState *qdev) static Property virtio_pci_properties[] = { DEFINE_PROP_BIT("virtio-pci-bus-master-bug-migration", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT, false), - DEFINE_PROP_BIT("disable-legacy", VirtIOPCIProxy, flags, - VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT, false), - DEFINE_PROP_BIT("disable-modern", VirtIOPCIProxy, flags, - VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT, true), + DEFINE_PROP_ON_OFF_AUTO("disable-legacy", VirtIOPCIProxy, disable_legacy, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("disable-modern", VirtIOPCIProxy, disable_modern, + ON_OFF_AUTO_AUTO), DEFINE_PROP_BIT("migrate-extra", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT, true), DEFINE_PROP_BIT("modern-pio-notify", VirtIOPCIProxy, flags, @@ -1841,7 +1858,7 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) PCIDevice *pci_dev = &proxy->pci_dev; if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) && - !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN)) { + !(proxy->disable_modern == ON_OFF_AUTO_ON)) { pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; } diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index e4548c2..4f219d4 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -144,6 +144,8 @@ struct VirtIOPCIProxy { uint32_t modern_mem_bar; int config_cap; uint32_t flags; + OnOffAuto disable_modern; + OnOffAuto disable_legacy; uint32_t class_code; uint32_t nvectors; uint32_t dfselect; diff --git a/include/hw/compat.h b/include/hw/compat.h index 9914e7a..1531399 100644 --- a/include/hw/compat.h +++ b/include/hw/compat.h @@ -6,6 +6,14 @@ .driver = "virtio-mmio",\ .property = "format_transport_address",\ .value = "off",\ + },{\ + .driver = "virtio-pci",\ + .property = "disable-modern",\ + .value = "on",\ + },{\ + .driver = "virtio-pci",\ + .property = "disable-legacy",\ + .value = "off",\ }, #define HW_COMPAT_2_5 \