From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFjIy-0001uS-5D for qemu-devel@nongnu.org; Wed, 22 Jun 2016 10:39:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFjIr-0000B8-AC for qemu-devel@nongnu.org; Wed, 22 Jun 2016 10:38:59 -0400 References: <1466471645-5396-1-git-send-email-aik@ozlabs.ru> <1466471645-5396-5-git-send-email-aik@ozlabs.ru> From: Laurent Vivier Message-ID: <3ce058e2-d20f-abc1-1102-4eb240d6dfa7@redhat.com> Date: Wed, 22 Jun 2016 16:38:47 +0200 MIME-Version: 1.0 In-Reply-To: <1466471645-5396-5-git-send-email-aik@ozlabs.ru> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH qemu v18 4/5] vfio/spapr: Create DMA window dynamically (SPAPR IOMMU v2) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy , qemu-devel@nongnu.org Cc: Alex Williamson , qemu-ppc@nongnu.org, David Gibson On 21/06/2016 03:14, Alexey Kardashevskiy wrote: > New VFIO_SPAPR_TCE_v2_IOMMU type supports dynamic DMA window management= . > This adds ability to VFIO common code to dynamically allocate/remove > DMA windows in the host kernel when new VFIO container is added/removed= . >=20 > This adds a helper to vfio_listener_region_add which makes > VFIO_IOMMU_SPAPR_TCE_CREATE ioctl and adds just created IOMMU into > the host IOMMU list; the opposite action is taken in > vfio_listener_region_del. >=20 > When creating a new window, this uses heuristic to decide on the TCE ta= ble > levels number. >=20 > This should cause no guest visible change in behavior. >=20 > Signed-off-by: Alexey Kardashevskiy > --- > Changes: > v18: > * moved trace definitions under hw/vfio/spapr.c section > * moved trace_vfio_spapr_remove_window to vfio_spapr_remove_window() > * vfio_host_win_del() now checks for exact window size > * one ctz() less in vfio_spapr_create_window() >=20 > v17: > * moved spapr window create/remove helpers to separate file > * added hw_error() if vfio_host_win_del() failed >=20 > v16: > * used memory_region_iommu_get_page_sizes() in vfio_listener_region_add= () > * enforced no intersections between windows >=20 > v14: > * new to the series > --- > hw/vfio/common.c | 79 +++++++++++++++++++++++++++++++++++= ++------ > hw/vfio/spapr.c | 71 +++++++++++++++++++++++++++++++++++= +++ > include/hw/vfio/vfio-common.h | 6 ++++ > trace-events | 2 ++ > 4 files changed, 148 insertions(+), 10 deletions(-) >=20 > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index b53a1db..8e3466c 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -265,6 +265,21 @@ static void vfio_host_win_add(VFIOContainer *conta= iner, > QLIST_INSERT_HEAD(&container->hostwin_list, hostwin, hostwin_next)= ; > } > =20 > +static int vfio_host_win_del(VFIOContainer *container, hwaddr min_iova= , > + hwaddr max_iova) > +{ > + VFIOHostDMAWindow *hostwin; > + > + QLIST_FOREACH(hostwin, &container->hostwin_list, hostwin_next) { > + if (hostwin->min_iova =3D=3D min_iova && hostwin->max_iova =3D= =3D max_iova) { > + QLIST_REMOVE(hostwin, hostwin_next); > + return 0; > + } > + } > + > + return -1; > +} > + > static bool vfio_listener_skipped_section(MemoryRegionSection *section= ) > { > return (!memory_region_is_ram(section->mr) && > @@ -380,6 +395,30 @@ static void vfio_listener_region_add(MemoryListene= r *listener, > } > end =3D int128_get64(int128_sub(llend, int128_one())); > =20 > + if (container->iommu_type =3D=3D VFIO_SPAPR_TCE_v2_IOMMU) { > + VFIOHostDMAWindow *hostwin; > + hwaddr pgsize =3D 0; > + > + /* For now intersections are not allowed, we may relax this la= ter */ > + QLIST_FOREACH(hostwin, &container->hostwin_list, hostwin_next)= { > + if (ranges_overlap(hostwin->min_iova, > + hostwin->max_iova - hostwin->min_iova += 1, > + section->offset_within_address_space, > + int128_get64(section->size))) { > + goto fail; ret is not initialized and it is used in "fail:". hw/vfio/common.c: In function =E2=80=98vfio_listener_region_add=E2=80=99: hw/vfio/common.c:493:30: error: =E2=80=98ret=E2=80=99 may be used uniniti= alized in this function [-Werror=3Dmaybe-uninitialized] container->error =3D ret; Laurent