Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752278AbcKGIm0 (ORCPT ); Mon, 7 Nov 2016 03:42:26 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33593 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751266AbcKGImW (ORCPT ); Mon, 7 Nov 2016 03:42:22 -0500 Subject: Re: [PATCH v11 07/22] vfio iommu type1: Update argument of vaddr_get_pfn() To: Kirti Wankhede , alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com References: <1478293856-8191-1-git-send-email-kwankhede@nvidia.com> <1478293856-8191-8-git-send-email-kwankhede@nvidia.com> Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com, jike.song@intel.com, bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org From: Alexey Kardashevskiy Message-ID: Date: Mon, 7 Nov 2016 19:42:15 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1478293856-8191-8-git-send-email-kwankhede@nvidia.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7Ro4DJf1h98FxHvIQKra5CpVliA8dICPU" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5149 Lines: 161 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7Ro4DJf1h98FxHvIQKra5CpVliA8dICPU Content-Type: multipart/mixed; boundary="BuItU7dks1nUSjrD1hU1ItGcmntRJacU0"; protected-headers="v1" From: Alexey Kardashevskiy To: Kirti Wankhede , alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com, jike.song@intel.com, bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Message-ID: Subject: Re: [PATCH v11 07/22] vfio iommu type1: Update argument of vaddr_get_pfn() References: <1478293856-8191-1-git-send-email-kwankhede@nvidia.com> <1478293856-8191-8-git-send-email-kwankhede@nvidia.com> In-Reply-To: <1478293856-8191-8-git-send-email-kwankhede@nvidia.com> --BuItU7dks1nUSjrD1hU1ItGcmntRJacU0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable On 05/11/16 08:10, Kirti Wankhede wrote: > Update arguments of vaddr_get_pfn() to take struct mm_struct *mm as inp= ut > argument. >=20 > Signed-off-by: Kirti Wankhede > Signed-off-by: Neo Jia > Change-Id: I885fd4cd4a9f66f4ee2c1caf58267464ec239f52 > --- > drivers/vfio/vfio_iommu_type1.c | 30 +++++++++++++++++++++++------- > 1 file changed, 23 insertions(+), 7 deletions(-) >=20 > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_= type1.c > index 02b302d0b7de..653386e80e85 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -226,20 +226,36 @@ static int put_pfn(unsigned long pfn, int prot) > return 0; > } > =20 > -static int vaddr_get_pfn(unsigned long vaddr, int prot, unsigned long = *pfn) > +static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, > + int prot, unsigned long *pfn) > { > struct page *page[1]; > struct vm_area_struct *vma; > int ret =3D -EFAULT; > =20 > - if (get_user_pages_fast(vaddr, 1, !!(prot & IOMMU_WRITE), page) =3D=3D= 1) { > + if (mm =3D=3D current->mm) afaik the rule is if one branch of "if" uses curly braces, the other shou= ld do so too. > + ret =3D get_user_pages_fast(vaddr, 1, !!(prot & IOMMU_WRITE), > + page); > + else { > + unsigned int flags =3D 0; > + > + if (prot & IOMMU_WRITE) > + flags |=3D FOLL_WRITE; > + > + down_read(&mm->mmap_sem); > + ret =3D get_user_pages_remote(NULL, mm, vaddr, 1, flags, page, > + NULL); > + up_read(&mm->mmap_sem); This chunk is not just about passing mm everywhere, it would be nice to s= ee in the commit log why this change is in this patch (may be it was comment= ed already, and I just missed it?). > + } > + > + if (ret =3D=3D 1) { > *pfn =3D page_to_pfn(page[0]); > return 0; > } > =20 > - down_read(¤t->mm->mmap_sem); > + down_read(&mm->mmap_sem); > =20 > - vma =3D find_vma_intersection(current->mm, vaddr, vaddr + 1); > + vma =3D find_vma_intersection(mm, vaddr, vaddr + 1); > =20 > if (vma && vma->vm_flags & VM_PFNMAP) { > *pfn =3D ((vaddr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; > @@ -247,7 +263,7 @@ static int vaddr_get_pfn(unsigned long vaddr, int p= rot, unsigned long *pfn) > ret =3D 0; > } > =20 > - up_read(¤t->mm->mmap_sem); > + up_read(&mm->mmap_sem); > =20 > return ret; > } > @@ -268,7 +284,7 @@ static long __vfio_pin_pages_remote(unsigned long v= addr, long npage, > if (!current->mm) > return -ENODEV; > =20 > - ret =3D vaddr_get_pfn(vaddr, prot, pfn_base); > + ret =3D vaddr_get_pfn(current->mm, vaddr, prot, pfn_base); > if (ret) > return ret; > =20 > @@ -291,7 +307,7 @@ static long __vfio_pin_pages_remote(unsigned long v= addr, long npage, > for (i =3D 1, vaddr +=3D PAGE_SIZE; i < npage; i++, vaddr +=3D PAGE_S= IZE) { > unsigned long pfn =3D 0; > =20 > - ret =3D vaddr_get_pfn(vaddr, prot, &pfn); > + ret =3D vaddr_get_pfn(current->mm, vaddr, prot, &pfn); > if (ret) > break; > =20 >=20 --=20 Alexey --BuItU7dks1nUSjrD1hU1ItGcmntRJacU0-- --7Ro4DJf1h98FxHvIQKra5CpVliA8dICPU 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 iQIrBAEBCAAVBQJYID5nDhxhaWtAb3psYWJzLnJ1AAoJEIYTPdgrwSC5D7MP/iDQ FRdLXQC3bcIj6rvjpQSdIJfZRK+MtQYc+by/IJrHdMSuIVBDgWalaSt9O4U4vdGW wKQajgkl61dVpOExv7mA3E9+gQOqIasY5wfomzCb6Z86tjEGv3C5gqZk7lq51eBP ffvOjR0H3WnByZCJ3s7TQjNwLUac/NWoagVzrK2WGkJHIGORlDx0jD3YTlWhLFQz k0yiZkLt8o5R3ZnMGcprsO1gIjAh7c/xJMb/bVzoDJwrGeD1uO6S8bZDJGogyNjO p/cjuHhy70qvLm2kZd80VbdW19TmqWrXxilV6kRXlJ3ClCB7VhcIUvY/rWvIktmM 5mJ0aWbbTVUOXOfqxcobnl7DyYlCALJ/7JDveHSAON7C6MlbP/6GsLM+TCbgjLDp gcutSdTSMrS4669Z/tYpVVWZMHF21SzBXRqx+oWVPw2E8wC99dtn+f9XDhVII1zl 7GXiYMHvg0wWE5KJ1XiSRKQcLZeeS035/zAVeo7ugwDqc00ycMElKolig+H6VJm3 7gU+mE+cYt45HAiNAm/ZIKzoDPyyl+Lh8GpWe6H3DPO6iQY9Ul8jsqkH1ScM27EO TyYZj/bN6OH2kRgE6Xn1BKBr8yx/HgWmU0yj78K4p42agA2vpdDm/FeVo1Vahp/E /ndbxHxYtWzS2gw1NpDfVBdNUL48jClcbiKN18KB =gOer -----END PGP SIGNATURE----- --7Ro4DJf1h98FxHvIQKra5CpVliA8dICPU--