From nobody Thu May 2 00:36:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151305616310979.20044202633653; Mon, 11 Dec 2017 21:22:43 -0800 (PST) Received: from localhost ([::1]:56732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOd1Y-0007xY-Cr for importer@patchew.org; Tue, 12 Dec 2017 00:22:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOd0c-0006uv-PX for qemu-devel@nongnu.org; Tue, 12 Dec 2017 00:21:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOd0Z-000181-Fm for qemu-devel@nongnu.org; Tue, 12 Dec 2017 00:21:38 -0500 Received: from ozlabs.ru ([107.173.13.209]:60940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOd0Z-00017V-6a; Tue, 12 Dec 2017 00:21:35 -0500 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 3761B3A60098; Tue, 12 Dec 2017 00:20:56 -0500 (EST) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Tue, 12 Dec 2017 16:21:31 +1100 Message-Id: <20171212052131.24649-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 107.173.13.209 Subject: [Qemu-devel] [PATCH qemu] RFC: vfio-pci: Allow mmap of MSIX BAR 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: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This makes use of a new VFIO_REGION_INFO_CAP_MSIX_MAPPABLE capability which tells that a region with MSIX data can be mapped entirely, i.e. the VFIO PCI driver won't prevent MSIX vectors area from being mapped. This adds a "msix-no-mmap" property to the vfio-pci device, it is "true" by default and "false" for pseries-2.12+ machines. This requites kernel's "vfio-pci: Allow mapping MSIX BAR" https://www.spinics.net/lists/kvm/msg160282.html Signed-off-by: Alexey Kardashevskiy --- This is an RFC as it requires kernel headers update which is not there yet. I'd like to make it "msix-mmap" (without "no") but could not find a way of enabling a device property for machine versions newer than some value. I changed 2.11 machine just for the demonstration purpose. --- hw/vfio/pci.h | 1 + include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 5 +++++ hw/ppc/spapr.c | 10 +++++++++- hw/vfio/common.c | 15 +++++++++++++++ hw/vfio/pci.c | 11 +++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index a8fb3b3..53912ef 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -142,6 +142,7 @@ typedef struct VFIOPCIDevice { bool no_kvm_intx; bool no_kvm_msi; bool no_kvm_msix; + bool msix_no_mmap; } VFIOPCIDevice; =20 uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f3a2ac9..927d600 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -171,6 +171,7 @@ int vfio_get_region_info(VFIODevice *vbasedev, int inde= x, struct vfio_region_info **info); int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo); +bool vfio_is_cap_present(VFIODevice *vbasedev, uint16_t cap_type, int regi= on); #endif extern const MemoryListener vfio_prereg_listener; =20 diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 4e7ab4c..bce9baf 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -300,6 +300,11 @@ struct vfio_region_info_cap_type { #define VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG (2) #define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG (3) =20 +/* + * The MSIX mappable capability informs that MSIX data of a BAR can be mma= pped. + */ +#define VFIO_REGION_INFO_CAP_MSIX_MAPPABLE 3 + /** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 9de63f0..1dfc386 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3742,13 +3742,21 @@ static const TypeInfo spapr_machine_info =3D { /* * pseries-2.11 */ +#define SPAPR_COMPAT_2_11 \ + HW_COMPAT_2_10 \ + { \ + .driver =3D "vfio-pci", \ + .property =3D "msix-no-mmap", \ + .value =3D "on", \ + }, \ + static void spapr_machine_2_11_instance_options(MachineState *machine) { } =20 static void spapr_machine_2_11_class_options(MachineClass *mc) { - /* Defaults for the latest behaviour inherited from the base class */ + SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_11); } =20 DEFINE_SPAPR_MACHINE(2_11, "2.11", true); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ed7717d..593514c 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1408,6 +1408,21 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, u= int32_t type, return -ENODEV; } =20 +bool vfio_is_cap_present(VFIODevice *vbasedev, uint16_t cap_type, int regi= on) +{ + struct vfio_region_info *info =3D NULL; + bool ret =3D false; + + if (!vfio_get_region_info(vbasedev, region, &info)) { + if (vfio_get_region_info_cap(info, cap_type)) { + ret =3D true; + } + g_free(info); + } + + return ret; +} + /* * Interfaces for IBM EEH (Enhanced Error Handling) */ diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c977ee3..d9aeae8 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1289,6 +1289,12 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevice= *vdev) off_t start, end; VFIORegion *region =3D &vdev->bars[vdev->msix->table_bar].region; =20 + if (!vdev->msix_no_mmap && + vfio_is_cap_present(&vdev->vbasedev, VFIO_REGION_INFO_CAP_MSIX_MAP= PABLE, + vdev->msix->table_bar)) { + return; + } + /* * We expect to find a single mmap covering the whole BAR, anything el= se * means it's either unsupported or already setup. @@ -1473,6 +1479,10 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) */ memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false); =20 + if (!vdev->msix_no_mmap) { + memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false); + } + return 0; } =20 @@ -2986,6 +2996,7 @@ static Property vfio_pci_dev_properties[] =3D { DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features, VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), DEFINE_PROP_BOOL("x-no-mmap", VFIOPCIDevice, vbasedev.no_mmap, false), + DEFINE_PROP_BOOL("msix-no-mmap", VFIOPCIDevice, msix_no_mmap, true), DEFINE_PROP_BOOL("x-no-kvm-intx", VFIOPCIDevice, no_kvm_intx, false), DEFINE_PROP_BOOL("x-no-kvm-msi", VFIOPCIDevice, no_kvm_msi, false), DEFINE_PROP_BOOL("x-no-kvm-msix", VFIOPCIDevice, no_kvm_msix, false), --=20 2.11.0