From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" Subject: Re: [PATCH 07/12] vhost-scsi: convert put_page() to put_user_page*() Date: Wed, 24 Jul 2019 04:07:55 -0400 Message-ID: <20190724040745-mutt-send-email-mst@kernel.org> References: <20190724042518.14363-1-jhubbard@nvidia.com> <20190724042518.14363-8-jhubbard@nvidia.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline In-Reply-To: <20190724042518.14363-8-jhubbard@nvidia.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: john.hubbard@gmail.com Cc: Boaz Harrosh , Jan Kara , kvm@vger.kernel.org, Dave Chinner , virtualization@lists.linux-foundation.org, linux-mm@kvack.org, Christoph Hellwig , linux-cifs@vger.kernel.org, Miklos Szeredi , linux-rdma@vger.kernel.org, Matthew Wilcox , Jason Gunthorpe , Johannes Thumshirn , v9fs-developer@lists.sourceforge.net, Eric Van Hensbergen , John Hubbard , Dan Williams , Ming Lei , linux-block@vger.kernel.org, =?iso-8859-1?B?Suly9G1l?= Glisse , Alexander Viro , Stefan Hajnoczi , ceph-devel@vger.kernel.org, Trond Myklebust , Jens Axboe linux List-Id: virtualization@lists.linuxfoundation.org On Tue, Jul 23, 2019 at 09:25:13PM -0700, john.hubbard@gmail.com wrote: > From: J=E9r=F4me Glisse > = > For pages that were retained via get_user_pages*(), release those pages > via the new put_user_page*() routines, instead of via put_page(). > = > This is part a tree-wide conversion, as described in commit fc1d8e7cca2d > ("mm: introduce put_user_page*(), placeholder versions"). > = > Changes from J=E9r=F4me's original patch: > = > * Changed a WARN_ON to a BUG_ON. > = > Signed-off-by: J=E9r=F4me Glisse > Signed-off-by: John Hubbard > Cc: virtualization@lists.linux-foundation.org > Cc: linux-fsdevel@vger.kernel.org > Cc: linux-block@vger.kernel.org > Cc: linux-mm@kvack.org > Cc: Jan Kara > Cc: Dan Williams > Cc: Alexander Viro > Cc: Johannes Thumshirn > Cc: Christoph Hellwig > Cc: Jens Axboe > Cc: Ming Lei > Cc: Dave Chinner > Cc: Jason Gunthorpe > Cc: Matthew Wilcox > Cc: Boaz Harrosh > Cc: Miklos Szeredi > Cc: "Michael S. Tsirkin" > Cc: Jason Wang > Cc: Paolo Bonzini > Cc: Stefan Hajnoczi Acked-by: Michael S. Tsirkin > --- > drivers/vhost/scsi.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > = > diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c > index a9caf1bc3c3e..282565ab5e3f 100644 > --- a/drivers/vhost/scsi.c > +++ b/drivers/vhost/scsi.c > @@ -329,11 +329,11 @@ static void vhost_scsi_release_cmd(struct se_cmd *s= e_cmd) > = > if (tv_cmd->tvc_sgl_count) { > for (i =3D 0; i < tv_cmd->tvc_sgl_count; i++) > - put_page(sg_page(&tv_cmd->tvc_sgl[i])); > + put_user_page(sg_page(&tv_cmd->tvc_sgl[i])); > } > if (tv_cmd->tvc_prot_sgl_count) { > for (i =3D 0; i < tv_cmd->tvc_prot_sgl_count; i++) > - put_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); > + put_user_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); > } > = > vhost_scsi_put_inflight(tv_cmd->inflight); > @@ -630,6 +630,13 @@ vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd, > size_t offset; > unsigned int npages =3D 0; > = > + /* > + * Here in all cases we should have an IOVEC which use GUP. If that is > + * not the case then we will wrongly call put_user_page() and the page > + * refcount will go wrong (this is in vhost_scsi_release_cmd()) > + */ > + WARN_ON(!iov_iter_get_pages_use_gup(iter)); > + > bytes =3D iov_iter_get_pages(iter, pages, LONG_MAX, > VHOST_SCSI_PREALLOC_UPAGES, &offset); > /* No pages were pinned */ > @@ -681,7 +688,7 @@ vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, boo= l write, > while (p < sg) { > struct page *page =3D sg_page(p++); > if (page) > - put_page(page); > + put_user_page(page); > } > return ret; > } > -- = > 2.22.0