Message ID | 20190722223415.13269-4-jhubbard@nvidia.com |
---|---|
State | Not Applicable |
Delegated to: | David Miller |
Headers | show |
Series | introduce __put_user_pages(), convert a few call sites | expand |
On Mon, Jul 22, 2019 at 03:34:15PM -0700, john.hubbard@gmail.com wrote: > From: John Hubbard <jhubbard@nvidia.com> > > For pages that were retained via get_user_pages*(), release those pages > via the new put_user_page*() routines, instead of via put_page() or > release_pages(). > > This is part a tree-wide conversion, as described in commit fc1d8e7cca2d > ("mm: introduce put_user_page*(), placeholder versions"). > > Cc: Björn Töpel <bjorn.topel@intel.com> > Cc: Magnus Karlsson <magnus.karlsson@intel.com> > Cc: David S. Miller <davem@davemloft.net> > Cc: netdev@vger.kernel.org > Signed-off-by: John Hubbard <jhubbard@nvidia.com> > --- > net/xdp/xdp_umem.c | 9 +-------- > 1 file changed, 1 insertion(+), 8 deletions(-) > > diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c > index 83de74ca729a..0325a17915de 100644 > --- a/net/xdp/xdp_umem.c > +++ b/net/xdp/xdp_umem.c > @@ -166,14 +166,7 @@ void xdp_umem_clear_dev(struct xdp_umem *umem) > > static void xdp_umem_unpin_pages(struct xdp_umem *umem) > { > - unsigned int i; > - > - for (i = 0; i < umem->npgs; i++) { > - struct page *page = umem->pgs[i]; > - > - set_page_dirty_lock(page); > - put_page(page); > - } > + put_user_pages_dirty_lock(umem->pgs, umem->npgs); What is the difference between this and __put_user_pages(umem->pgs, umem->npgs, PUP_FLAGS_DIRTY_LOCK); ? I'm a bit concerned with adding another form of the same interface. We should either have 1 call with flags (enum in this case) or multiple calls. Given the previous discussion lets move in the direction of having the enum but don't introduce another caller of the "old" interface. So I think on this patch NAK from me. I also don't like having a __* call in the exported interface but there is a __get_user_pages_fast() call so I guess there is precedent. :-/ Ira > > kfree(umem->pgs); > umem->pgs = NULL; > -- > 2.22.0 >
On 7/22/19 5:25 PM, Ira Weiny wrote: > On Mon, Jul 22, 2019 at 03:34:15PM -0700, john.hubbard@gmail.com wrote: >> From: John Hubbard <jhubbard@nvidia.com> >> >> For pages that were retained via get_user_pages*(), release those pages >> via the new put_user_page*() routines, instead of via put_page() or >> release_pages(). >> >> This is part a tree-wide conversion, as described in commit fc1d8e7cca2d >> ("mm: introduce put_user_page*(), placeholder versions"). >> >> Cc: Björn Töpel <bjorn.topel@intel.com> >> Cc: Magnus Karlsson <magnus.karlsson@intel.com> >> Cc: David S. Miller <davem@davemloft.net> >> Cc: netdev@vger.kernel.org >> Signed-off-by: John Hubbard <jhubbard@nvidia.com> >> --- >> net/xdp/xdp_umem.c | 9 +-------- >> 1 file changed, 1 insertion(+), 8 deletions(-) >> >> diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c >> index 83de74ca729a..0325a17915de 100644 >> --- a/net/xdp/xdp_umem.c >> +++ b/net/xdp/xdp_umem.c >> @@ -166,14 +166,7 @@ void xdp_umem_clear_dev(struct xdp_umem *umem) >> >> static void xdp_umem_unpin_pages(struct xdp_umem *umem) >> { >> - unsigned int i; >> - >> - for (i = 0; i < umem->npgs; i++) { >> - struct page *page = umem->pgs[i]; >> - >> - set_page_dirty_lock(page); >> - put_page(page); >> - } >> + put_user_pages_dirty_lock(umem->pgs, umem->npgs); > > What is the difference between this and > > __put_user_pages(umem->pgs, umem->npgs, PUP_FLAGS_DIRTY_LOCK); > > ? No difference. > > I'm a bit concerned with adding another form of the same interface. We should > either have 1 call with flags (enum in this case) or multiple calls. Given the > previous discussion lets move in the direction of having the enum but don't > introduce another caller of the "old" interface. I disagree that this is a "problem". There is no maintenance pitfall here; there are merely two ways to call the put_user_page*() API. Both are correct, and neither one will get you into trouble. Not only that, but there is ample precedent for this approach in other kernel APIs. > > So I think on this patch NAK from me. > > I also don't like having a __* call in the exported interface but there is a > __get_user_pages_fast() call so I guess there is precedent. :-/ > I thought about this carefully, and looked at other APIs. And I noticed that things like __get_user_pages*() are how it's often done: * The leading underscores are often used for the more elaborate form of the call (as oppposed to decorating the core function name with "_flags", for example). * There are often calls in which you can either call the simpler form, or the form with flags and additional options, and yes, you'll get the same result. Obviously, this stuff is all subject to a certain amount of opinion, but I think I'm on really solid ground as far as precedent goes. So I'm pushing back on the NAK... :) thanks,
On Mon, Jul 22, 2019 at 09:41:34PM -0700, John Hubbard wrote: > * The leading underscores are often used for the more elaborate form of the > call (as oppposed to decorating the core function name with "_flags", for > example). IMHO usually the __ version of a public symbol means something like 'why are you using this? you probably should not' Often because the __ version has no locking or some other dangerous configuration like that. Jason
On Mon, Jul 22, 2019 at 09:41:34PM -0700, John Hubbard wrote: > On 7/22/19 5:25 PM, Ira Weiny wrote: > > On Mon, Jul 22, 2019 at 03:34:15PM -0700, john.hubbard@gmail.com wrote: > > > From: John Hubbard <jhubbard@nvidia.com> > > > > > > For pages that were retained via get_user_pages*(), release those pages > > > via the new put_user_page*() routines, instead of via put_page() or > > > release_pages(). > > > > > > This is part a tree-wide conversion, as described in commit fc1d8e7cca2d > > > ("mm: introduce put_user_page*(), placeholder versions"). > > > > > > Cc: Björn Töpel <bjorn.topel@intel.com> > > > Cc: Magnus Karlsson <magnus.karlsson@intel.com> > > > Cc: David S. Miller <davem@davemloft.net> > > > Cc: netdev@vger.kernel.org > > > Signed-off-by: John Hubbard <jhubbard@nvidia.com> > > > --- > > > net/xdp/xdp_umem.c | 9 +-------- > > > 1 file changed, 1 insertion(+), 8 deletions(-) > > > > > > diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c > > > index 83de74ca729a..0325a17915de 100644 > > > --- a/net/xdp/xdp_umem.c > > > +++ b/net/xdp/xdp_umem.c > > > @@ -166,14 +166,7 @@ void xdp_umem_clear_dev(struct xdp_umem *umem) > > > static void xdp_umem_unpin_pages(struct xdp_umem *umem) > > > { > > > - unsigned int i; > > > - > > > - for (i = 0; i < umem->npgs; i++) { > > > - struct page *page = umem->pgs[i]; > > > - > > > - set_page_dirty_lock(page); > > > - put_page(page); > > > - } > > > + put_user_pages_dirty_lock(umem->pgs, umem->npgs); > > > > What is the difference between this and > > > > __put_user_pages(umem->pgs, umem->npgs, PUP_FLAGS_DIRTY_LOCK); > > > > ? > > No difference. > > > > > I'm a bit concerned with adding another form of the same interface. We should > > either have 1 call with flags (enum in this case) or multiple calls. Given the > > previous discussion lets move in the direction of having the enum but don't > > introduce another caller of the "old" interface. > > I disagree that this is a "problem". There is no maintenance pitfall here; there > are merely two ways to call the put_user_page*() API. Both are correct, and > neither one will get you into trouble. > > Not only that, but there is ample precedent for this approach in other > kernel APIs. > > > > > So I think on this patch NAK from me. > > > > I also don't like having a __* call in the exported interface but there is a > > __get_user_pages_fast() call so I guess there is precedent. :-/ > > > > I thought about this carefully, and looked at other APIs. And I noticed that > things like __get_user_pages*() are how it's often done: > > * The leading underscores are often used for the more elaborate form of the > call (as oppposed to decorating the core function name with "_flags", for > example). > > * There are often calls in which you can either call the simpler form, or the > form with flags and additional options, and yes, you'll get the same result. > > Obviously, this stuff is all subject to a certain amount of opinion, but I > think I'm on really solid ground as far as precedent goes. So I'm pushing > back on the NAK... :) Fair enough... However, we have discussed in the past how GUP can be a confusing interface to use. So I'd like to see it be more directed. Only using the __put_user_pages() version allows us to ID callers easier through a grep of PUP_FLAGS_DIRTY_LOCK in addition to directing users to use that interface rather than having to read the GUP code to figure out that the 2 calls above are equal. It is not a huge deal but... Ira > > thanks, > -- > John Hubbard > NVIDIA >
On 7/23/19 11:06 AM, Ira Weiny wrote: > On Mon, Jul 22, 2019 at 09:41:34PM -0700, John Hubbard wrote: >> On 7/22/19 5:25 PM, Ira Weiny wrote: >>> On Mon, Jul 22, 2019 at 03:34:15PM -0700, john.hubbard@gmail.com wrote: ... >> Obviously, this stuff is all subject to a certain amount of opinion, but I >> think I'm on really solid ground as far as precedent goes. So I'm pushing >> back on the NAK... :) > > Fair enough... However, we have discussed in the past how GUP can be a > confusing interface to use. > > So I'd like to see it be more directed. Only using the __put_user_pages() > version allows us to ID callers easier through a grep of PUP_FLAGS_DIRTY_LOCK > in addition to directing users to use that interface rather than having to read > the GUP code to figure out that the 2 calls above are equal. It is not a huge > deal but... > OK, combining all the feedback to date, which is: * the leading double underscore is unloved, * set_page_dirty() is under investigation, but likely guilty of incitement to cause bugs, ...we end up with this: void put_user_pages_dirty_lock(struct page **pages, unsigned long npages, bool make_dirty) ...which I have a v2 patchset for, ready to send out. It makes IB all pretty too. :) thanks,
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index 83de74ca729a..0325a17915de 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -166,14 +166,7 @@ void xdp_umem_clear_dev(struct xdp_umem *umem) static void xdp_umem_unpin_pages(struct xdp_umem *umem) { - unsigned int i; - - for (i = 0; i < umem->npgs; i++) { - struct page *page = umem->pgs[i]; - - set_page_dirty_lock(page); - put_page(page); - } + put_user_pages_dirty_lock(umem->pgs, umem->npgs); kfree(umem->pgs); umem->pgs = NULL;