Received: from eggs.gnu.org ([2001:4830:134:3::10]:37861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAWgu-0005xv-5q for qemu-devel@nongnu.org; Wed, 08 Jun 2016 02:10:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAWgl-0004tL-7y for qemu-devel@nongnu.org; Wed, 08 Jun 2016 02:10:11 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAWgk-0004tB-U2 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 02:10:03 -0400 Received: by mail-pf0-x242.google.com with SMTP id t190so2693046pfb.2 for ; Tue, 07 Jun 2016 23:10:02 -0700 (PDT) References: <1464771463-37214-1-git-send-email-aik@ozlabs.ru> <201606010901.u518x1wF023568@mx0a-001b2d01.pphosted.com> <20160606055759.GL9226@voom.fritz.box> <20160608055743.GX9226@voom.fritz.box> From: Alexey Kardashevskiy Message-ID: <20d3189c-ac47-3cdb-137b-079a93eaaff2@ozlabs.ru> Date: Wed, 8 Jun 2016 16:09:57 +1000 MIME-Version: 1.0 In-Reply-To: <20160608055743.GX9226@voom.fritz.box> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mGHJHpBsUbGXCjpSE0AaXFa133LwD5pSF" Subject: Re: [Qemu-devel] [PATCH qemu v17 11/12] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Alexander Graf , Alex Williamson This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --mGHJHpBsUbGXCjpSE0AaXFa133LwD5pSF From: Alexey Kardashevskiy To: David Gibson Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Alexander Graf , Alex Williamson Message-ID: <20d3189c-ac47-3cdb-137b-079a93eaaff2@ozlabs.ru> Subject: Re: [PATCH qemu v17 11/12] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) References: <1464771463-37214-1-git-send-email-aik@ozlabs.ru> <201606010901.u518x1wF023568@mx0a-001b2d01.pphosted.com> <20160606055759.GL9226@voom.fritz.box> <20160608055743.GX9226@voom.fritz.box> In-Reply-To: <20160608055743.GX9226@voom.fritz.box> Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable On 08/06/16 15:57, David Gibson wrote: > On Mon, Jun 06, 2016 at 06:12:58PM +1000, Alexey Kardashevskiy wrote: >> On 06/06/16 15:57, David Gibson wrote: >>> On Wed, Jun 01, 2016 at 06:57:42PM +1000, Alexey Kardashevskiy wrote:= >>>> This adds support for Dynamic DMA Windows (DDW) option defined by >>>> the SPAPR specification which allows to have additional DMA window(s= ) >>>> >>>> The "ddw" property is enabled by default on a PHB but for compatibil= ity >>>> the pseries-2.5 machine (TODO: update version) and older disable it.= >>> >>> Looks like your todo is now todone, but you need to update the commit= >>> message. >>> >>>> This also creates a single DMA window for the older machines to >>>> maintain backward migration. >>>> >>>> This implements DDW for PHB with emulated and VFIO devices. The host= >>>> kernel support is required. The advertised IOMMU page sizes are 4K a= nd >>>> 64K; 16M pages are supported but not advertised by default, in order= to >>>> enable them, the user has to specify "pgsz" property for PHB and >>>> enable huge pages for RAM. >>>> >>>> The existing linux guests try creating one additional huge DMA windo= w >>>> with 64K or 16MB pages and map the entire guest RAM to. If succeeded= , >>>> the guest switches to dma_direct_ops and never calls TCE hypercalls >>>> (H_PUT_TCE,...) again. This enables VFIO devices to use the entire R= AM >>>> and not waste time on map/unmap later. This adds a "dma64_win_addr" >>>> property which is a bus address for the 64bit window and by default >>>> set to 0x800.0000.0000.0000 as this is what the modern POWER8 hardwa= re >>>> uses and this allows having emulated and VFIO devices on the same bu= s. >>>> >>>> This adds 4 RTAS handlers: >>>> * ibm,query-pe-dma-window >>>> * ibm,create-pe-dma-window >>>> * ibm,remove-pe-dma-window >>>> * ibm,reset-pe-dma-window >>>> These are registered from type_init() callback. >>>> >>>> These RTAS handlers are implemented in a separate file to avoid poll= uting >>>> spapr_iommu.c with PCI. >>>> >>>> This changes sPAPRPHBState::dma_liobn to an array to allow 2 LIOBNs.= >>>> >>>> Signed-off-by: Alexey Kardashevskiy >>> >>> Looks pretty close to ready. >>> >>> There are a handful of nits and one real error noted below. >>> >>>> --- >>>> Changes: >>>> v17: >>>> * fixed: "query" did return non-page-shifted value when memory hotpl= ug is enabled >>>> >>>> v16: >>>> * s/dma_liobn/dma_liobn[SPAPR_PCI_DMA_MAX_WINDOWS]/ >>>> * s/SPAPR_PCI_LIOBN()/dma_liobn[]/ >>>> >>>> v15: >>>> * moved page mask filtering to PHB realize(), use "-mempath" to know= >>>> if there are huge pages >>>> * fixed error reporting in RTAS handlers >>>> * max window size accounts now hotpluggable memory boundaries >>>> --- >>>> hw/ppc/Makefile.objs | 1 + >>>> hw/ppc/spapr.c | 5 + >>>> hw/ppc/spapr_pci.c | 77 +++++++++--- >>>> hw/ppc/spapr_rtas_ddw.c | 293 +++++++++++++++++++++++++++++++++= +++++++++++ >>>> include/hw/pci-host/spapr.h | 8 +- >>>> include/hw/ppc/spapr.h | 16 ++- >>>> trace-events | 4 + >>>> 7 files changed, 383 insertions(+), 21 deletions(-) >>>> create mode 100644 hw/ppc/spapr_rtas_ddw.c >>>> >>>> diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs >>>> index c1ffc77..986b36f 100644 >>>> --- a/hw/ppc/Makefile.objs >>>> +++ b/hw/ppc/Makefile.objs >>>> @@ -7,6 +7,7 @@ obj-$(CONFIG_PSERIES) +=3D spapr_pci.o spapr_rtc.o s= papr_drc.o spapr_rng.o >>>> ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) >>>> obj-y +=3D spapr_pci_vfio.o >>>> endif >>>> +obj-$(CONFIG_PSERIES) +=3D spapr_rtas_ddw.o >>>> # PowerPC 4xx boards >>>> obj-y +=3D ppc405_boards.o ppc4xx_devs.o ppc405_uc.o ppc440_bamboo.= o >>>> obj-y +=3D ppc4xx_pci.o >>>> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c >>>> index 44e401a..6ddcda9 100644 >>>> --- a/hw/ppc/spapr.c >>>> +++ b/hw/ppc/spapr.c >>>> @@ -2366,6 +2366,11 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true); >>>> .driver =3D "spapr-vlan", \ >>>> .property =3D "use-rx-buffer-pools", \ >>>> .value =3D "off", \ >>>> + }, \ >>>> + {\ >>>> + .driver =3D TYPE_SPAPR_PCI_HOST_BRIDGE,\ >>>> + .property =3D "ddw",\ >>>> + .value =3D stringify(off),\ >>>> }, >>>> =20 >>>> static void spapr_machine_2_5_instance_options(MachineState *machin= e) >>>> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c >>>> index 68de523..bcf0360 100644 >>>> --- a/hw/ppc/spapr_pci.c >>>> +++ b/hw/ppc/spapr_pci.c >>>> @@ -35,6 +35,7 @@ >>>> #include "hw/ppc/spapr.h" >>>> #include "hw/pci-host/spapr.h" >>>> #include "exec/address-spaces.h" >>>> +#include "exec/ram_addr.h" >>>> #include >>>> #include "trace.h" >>>> #include "qemu/error-report.h" >>>> @@ -45,6 +46,7 @@ >>>> #include "hw/ppc/spapr_drc.h" >>>> #include "sysemu/device_tree.h" >>>> #include "sysemu/kvm.h" >>>> +#include "sysemu/hostmem.h" >>>> =20 >>>> #include "hw/vfio/vfio.h" >>>> =20 >>>> @@ -1088,7 +1090,7 @@ static void spapr_phb_add_pci_device(sPAPRDRCo= nnector *drc, >>>> int fdt_start_offset =3D 0, fdt_size; >>>> =20 >>>> if (object_dynamic_cast(OBJECT(pdev), "vfio-pci")) { >>>> - sPAPRTCETable *tcet =3D spapr_tce_find_by_liobn(phb->dma_li= obn); >>>> + sPAPRTCETable *tcet =3D spapr_tce_find_by_liobn(phb->dma_li= obn[0]); >>>> =20 >>>> spapr_tce_set_need_vfio(tcet, true); >>>> } >>> >>> Hang on.. I thought you'd got rid of the need for this explicit >>> set_need_vfio() stuff. >> >> >> It is in 12/12 (which I'll split in 2 halves when I respin this), I mo= ved >> it to the end as it is not essential for DDW itself. >=20 > Yes, sorry, I saw that shortly after writing this. >=20 >>>> @@ -1310,11 +1312,14 @@ static void spapr_phb_realize(DeviceState *d= ev, Error **errp) >>>> PCIBus *bus; >>>> uint64_t msi_window_size =3D 4096; >>>> sPAPRTCETable *tcet; >>>> + const unsigned windows_supported =3D >>>> + sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1; >>>> =20 >>>> if (sphb->index !=3D (uint32_t)-1) { >>>> hwaddr windows_base; >>>> =20 >>>> - if ((sphb->buid !=3D (uint64_t)-1) || (sphb->dma_liobn !=3D= (uint32_t)-1) >>>> + if ((sphb->buid !=3D (uint64_t)-1) || (sphb->dma_liobn[0] != =3D (uint32_t)-1) >>>> + || ((sphb->dma_liobn[1] !=3D (uint32_t)-1) && (windows_= supported > 1)) >>>> || (sphb->mem_win_addr !=3D (hwaddr)-1) >>>> || (sphb->io_win_addr !=3D (hwaddr)-1)) { >>>> error_setg(errp, "Either \"index\" or other parameters = must" >>>> @@ -1329,7 +1334,9 @@ static void spapr_phb_realize(DeviceState *dev= , Error **errp) >>>> } >>>> =20 >>>> sphb->buid =3D SPAPR_PCI_BASE_BUID + sphb->index; >>>> - sphb->dma_liobn =3D SPAPR_PCI_LIOBN(sphb->index, 0); >>>> + for (i =3D 0; i < windows_supported; ++i) { >>>> + sphb->dma_liobn[i] =3D SPAPR_PCI_LIOBN(sphb->index, i);= >>>> + } >>>> =20 >>>> windows_base =3D SPAPR_PCI_WINDOW_BASE >>>> + sphb->index * SPAPR_PCI_WINDOW_SPACING; >>>> @@ -1342,8 +1349,9 @@ static void spapr_phb_realize(DeviceState *dev= , Error **errp) >>>> return; >>>> } >>>> =20 >>>> - if (sphb->dma_liobn =3D=3D (uint32_t)-1) { >>>> - error_setg(errp, "LIOBN not specified for PHB"); >>>> + if ((sphb->dma_liobn[0] =3D=3D (uint32_t)-1) || >>>> + ((sphb->dma_liobn[1] =3D=3D (uint32_t)-1) && (windows_suppo= rted > 1))) { >>>> + error_setg(errp, "LIOBN(s) not specified for PHB"); >>>> return; >>>> } >>> >>> Hrm.. there's a bit of false generality here, since this would break >>> if windows_supported > 2, and dma_liobn[2] was not specified. Not >>> urgent for the initial commit though. >> >> >> Is s/windows_supported > 1/windows_supported =3D=3D 2/ any better here= ? >=20 > Not really. Unless you also have a windows_supported > 2 case (which > could just error / abort / whatever). It cannot be >2 as SPAPR_PCI_DMA_MAX_WINDOWS is defined as "2" now and it= is quite unlikely to change in the future. What do I do right now? :) --=20 Alexey --mGHJHpBsUbGXCjpSE0AaXFa133LwD5pSF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXV7a1AAoJEIYTPdgrwSC5iWgQALsRZqm6Rv1vphVaVv47Yb2t FojrcT3yPkcfkk67DgG49Xb1+Wr1irD//bPRdl3MRa1OPX+Hx8as41h7Fqv1ymyo HszSiRFM5gxxfI3832l596nMTAq1s6YvA/91fN/zvyt5K4uUZbba4oJwp/Z4BoWy zyiMeaDllLg0dTjBByY6Gt5Zefav67H6a3i2i4C3SUYo3pewwk3AviAwC8dBfcdV pfA2EGXn1NJsGkpjS5KFkK+I+mYAhO+hC1h+Etfwyatyj1ptfDnl/FmR1+dDUeXs Js+AwZm526gpqcDD4FbaWSrIWXWPug77TzetWWtzcySad7mIXrnjyqqvBugRi/Kk d34qxE+SU5LxZauRGVb1+zya6L0J6wbp2l/HEfBu2g2sRGq+63F9iifTYNm6Jv6W h4qR1M7Wyiv/b5hsqQ7GesnDLEEvn+25MUm0t4ytvQAE0a01V0asHlsKVoJUm+uO 4qicnZQDI3ymeOcH4WBzHhsHMR7Ign6ELY6FD+h2jwrP26SJwqM5XVu8FE1DDFsh 5PUidEpfAHEzAVOmhsJD6oVS1HLk1wbkT1dFH6wjUBYtntSVMuW4p+Ss6By5YL27 ftaQ0rhsYtqZn2/eD4eGrk/A1/WVArbzTi8CX/0JAY0ds0p/7u5WEtlQc/6jx6Pb gXc1CT8JrEdr/dw2GVcB =5SSM -----END PGP SIGNATURE----- --mGHJHpBsUbGXCjpSE0AaXFa133LwD5pSF--