From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Subject: Re: [PATCH kernel 1/3] vfio_pci: Allow mapping extra regions Date: Thu, 8 Nov 2018 17:04:22 +1100 Message-ID: <20181108060422.GP5575@umbus.fritz.box> References: <20181015094233.1324-1-aik@ozlabs.ru> <20181015094233.1324-2-aik@ozlabs.ru> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AwNVUpjOmSj7UnwZ" Cc: kvm@vger.kernel.org, Alistair Popple , linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org, Alex Williamson , Reza Arbab To: Alexey Kardashevskiy Return-path: Content-Disposition: inline In-Reply-To: <20181015094233.1324-2-aik@ozlabs.ru> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+glppe-linuxppc-embedded-2=m.gmane.org@lists.ozlabs.org Sender: "Linuxppc-dev" List-Id: kvm.vger.kernel.org --AwNVUpjOmSj7UnwZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 15, 2018 at 08:42:31PM +1100, Alexey Kardashevskiy wrote: 65;5402;1c> So far we only allowed mapping of MMIO BARs to the userspace. H= owever > there there are GPUs with on-board coherent RAM accessible via side > channels which we also want to map to the userspace. The first client > for this is NVIDIA V100 GPU with NVLink2 direct links to a POWER9 > NPU-enabled CPU; such GPUs have 16GB RAM which is coherently mapped > to the system address space, we are going to export these as an extra > PCI region. >=20 > We already support extra PCI regions and this adds support for mapping > them to the userspace. >=20 > Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson > --- > Changes: > v2: > * reverted one of mistakenly removed error checks > --- > drivers/vfio/pci/vfio_pci_private.h | 3 +++ > drivers/vfio/pci/vfio_pci.c | 8 ++++++++ > 2 files changed, 11 insertions(+) >=20 > diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_= pci_private.h > index cde3b5d..86aab05 100644 > --- a/drivers/vfio/pci/vfio_pci_private.h > +++ b/drivers/vfio/pci/vfio_pci_private.h > @@ -59,6 +59,9 @@ struct vfio_pci_regops { > size_t count, loff_t *ppos, bool iswrite); > void (*release)(struct vfio_pci_device *vdev, > struct vfio_pci_region *region); > + int (*mmap)(struct vfio_pci_device *vdev, > + struct vfio_pci_region *region, > + struct vm_area_struct *vma); > }; > =20 > struct vfio_pci_region { > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > index d9af440..7923314 100644 > --- a/drivers/vfio/pci/vfio_pci.c > +++ b/drivers/vfio/pci/vfio_pci.c > @@ -1126,6 +1126,14 @@ static int vfio_pci_mmap(void *device_data, struct= vm_area_struct *vma) > return -EINVAL; > if ((vma->vm_flags & VM_SHARED) =3D=3D 0) > return -EINVAL; > + if (index >=3D VFIO_PCI_NUM_REGIONS) { > + int regnum =3D index - VFIO_PCI_NUM_REGIONS; > + struct vfio_pci_region *region =3D vdev->region + regnum; > + > + if (region && region->ops && region->ops->mmap) > + return region->ops->mmap(vdev, region, vma); > + return -EINVAL; > + } > if (index >=3D VFIO_PCI_ROM_REGION_INDEX) > return -EINVAL; > if (!vdev->bar_mmap_supported[index]) --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --AwNVUpjOmSj7UnwZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlvj0eIACgkQbDjKyiDZ s5Kh/Q/9EDTEywNiv2jB25o+GG9jDesXxhv2omzhGl/zfTYBKecgx0yaL5adZqNi mVvnWIF+HaQvKzrSoJ2Lc/ebEHNwLF84hpepoHBY4V6jI3O5xmsuwdZNGYmKtrYt 1Ga7iMFmLHnDggm9NHJIENXCb3aSrGczMNDHrso2Pbf7XbAc4RVdI6AvENG8da4e 9ub0n/XeyqxAMEVLDKn8hjpSFa+eL2QtqVyIpz1pr/QeEDZ+/IF4c76a+d19Nk3n ilcQkVOHvvaGp9BL2JypZ2NiKDHhEQwNZSE6BKP7HtjoSkqDeUcsJgurEPJzgQ1C SH1ae9XLahVUwq/V3NIf2uu9hLVG/nfkuLPmM3QIDr6gg151LjA4+5FTHXzSSwDs s8xoqzFbA01tl8EFJ1CihfsiaoxC3glZlrHTYgVafBvhj0dH/xgZ228MY4diuiq1 8S0AzD0TeLraralYTdJL/IgO3orXOsmrroqZVStG6NxAX3YlIlAoA6geAJ3I5U+C 2h+Xeg3fy2DKHRkD7J/2/vN3yQL8iHRU4Sp1qyS2GQ4/xamALL4u+Z5SA0YVABPB oIf5vgRKzvUzQUvbwsCsbumXb7/ehLyFH5lAS3OITz4JtCRPK6J/HFfmDE3rgTjZ LZ5b8buJbPOIzKQzuG6tRmmwk4MV4DNO8KF85+Km7nTqB7YyaSA= =za5f -----END PGP SIGNATURE----- --AwNVUpjOmSj7UnwZ--