From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Return-Path: Date: Sat, 25 May 2019 14:51:18 -0700 From: Andrew Morton Subject: Re: [PATCH v2] mm: add account_locked_vm utility function Message-Id: <20190525145118.bfda2d75a14db05a001e49ad@linux-foundation.org> In-Reply-To: <20190524175045.26897-1-daniel.m.jordan@oracle.com> References: <20190524175045.26897-1-daniel.m.jordan@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit To: Daniel Jordan Cc: Alexey Kardashevskiy , Alan Tull , Alex Williamson , Benjamin Herrenschmidt , Christoph Lameter , Christophe Leroy , Davidlohr Bueso , Jason Gunthorpe , Mark Rutland , Michael Ellerman , Moritz Fischer , Paul Mackerras , Steve Sistare , Wu Hao , linux-mm@kvack.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org List-ID: On Fri, 24 May 2019 13:50:45 -0400 Daniel Jordan wrote: > locked_vm accounting is done roughly the same way in five places, so > unify them in a helper. Standardize the debug prints, which vary > slightly, but include the helper's caller to disambiguate between > callsites. > > Error codes stay the same, so user-visible behavior does too. The one > exception is that the -EPERM case in tce_account_locked_vm is removed > because Alexey has never seen it triggered. > > ... > > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1564,6 +1564,25 @@ long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, > int get_user_pages_fast(unsigned long start, int nr_pages, > unsigned int gup_flags, struct page **pages); > > +int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, > + struct task_struct *task, bool bypass_rlim); > + > +static inline int account_locked_vm(struct mm_struct *mm, unsigned long pages, > + bool inc) > +{ > + int ret; > + > + if (pages == 0 || !mm) > + return 0; > + > + down_write(&mm->mmap_sem); > + ret = __account_locked_vm(mm, pages, inc, current, > + capable(CAP_IPC_LOCK)); > + up_write(&mm->mmap_sem); > + > + return ret; > +} That's quite a mouthful for an inlined function. How about uninlining the whole thing and fiddling drivers/vfio/vfio_iommu_type1.c to suit. I wonder why it does down_write_killable and whether it really needs to...