From: John Hubbard Subject: Re: [PATCH v2 05/18] mm/gup: introduce pin_user_pages*() and FOLL_PIN Date: Mon, 4 Nov 2019 13:34:04 -0800 Message-ID: References: <20191103211813.213227-6-jhubbard@nvidia.com> <20191104173325.GD5134@redhat.com> <20191104191811.GI5134@redhat.com> <20191104195248.GA7731@redhat.com> <25ec4bc0-caaa-2a01-2ae7-2d79663a40e1@nvidia.com> <20191104203153.GB7731@redhat.com> <20191104203702.GG30938@ziepe.ca> <20191104211525.GJ30938@ziepe.ca> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20191104211525.GJ30938@ziepe.ca> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Jason Gunthorpe Cc: Jerome Glisse , Andrew Morton , Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Christoph Hellwig , Dan Williams , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jan Kara , Jens Axboe , Jonathan Corbet , Magnus Karlsson , Mauro Carvalho Chehab , Michael Ellerman , Michal Hocko List-Id: dri-devel@lists.freedesktop.org On 11/4/19 1:15 PM, Jason Gunthorpe wrote: ... >> Right, and I thought about this when converting, and realized that the above >> code is working around the current gup.c limitations, which are "cannot support >> gup remote with FOLL_LONGTERM". > > But AFAICT it doesn't have a problem, the protection test is just too > strict, and I guess the control flow needs a bit of fixing.. > > The issue is this: > > static __always_inline long __get_user_pages_locked(): > { > if (locked) { > /* if VM_FAULT_RETRY can be returned, vmas become invalid */ > BUG_ON(vmas); > /* check caller initialized locked */ > BUG_ON(*locked != 1); > } > > > so remote could be written as: > > if (gup_flags & FOLL_LONGTERM) { > if (WARN_ON_ONCE(locked)) > return -EINVAL; > return __gup_longterm_locked(...) > } > > return __get_user_pages_locked(...) > > ?? Yes, that loosens it up just enough for the vfio case (which doesn't set "locked") to get through, great! OK, I'll put that (the above plus corresponding vfio fix) in a separate patch first. This should clear things up nicely. thanks, -- John Hubbard NVIDIA