From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Zijlstra Subject: Re: [PATCH v7 18/27] mm: Introduce do_mmap_locked() Date: Fri, 7 Jun 2019 09:47:07 +0200 Message-ID: <20190607074707.GD3463@hirez.programming.kicks-ass.net> References: <20190606200646.3951-1-yu-cheng.yu@intel.com> <20190606200646.3951-19-yu-cheng.yu@intel.com> <20190607074322.GP3419@hirez.programming.kicks-ass.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20190607074322.GP3419@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org To: Yu-cheng Yu Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit List-Id: linux-api@vger.kernel.org On Fri, Jun 07, 2019 at 09:43:22AM +0200, Peter Zijlstra wrote: > On Thu, Jun 06, 2019 at 01:06:37PM -0700, Yu-cheng Yu wrote: > > There are a few places that need do_mmap() with mm->mmap_sem held. > > Create an in-line function for that. > > > > Signed-off-by: Yu-cheng Yu > > --- > > include/linux/mm.h | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 398f1e1c35e5..7cf014604848 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2411,6 +2411,24 @@ static inline void mm_populate(unsigned long addr, unsigned long len) > > static inline void mm_populate(unsigned long addr, unsigned long len) {} > > #endif > > > > +static inline unsigned long do_mmap_locked(unsigned long addr, > > + unsigned long len, unsigned long prot, unsigned long flags, > > + vm_flags_t vm_flags) > > +{ > > + struct mm_struct *mm = current->mm; > > + unsigned long populate; > > + > > + down_write(&mm->mmap_sem); > > + addr = do_mmap(NULL, addr, len, prot, flags, vm_flags, 0, > > + &populate, NULL); > > Funny thing how do_mmap() takes a file pointer as first argument and > this thing explicitly NULLs that. That more or less invalidates the name > do_mmap_locked(). > > > + up_write(&mm->mmap_sem); > > + > > + if (populate) > > + mm_populate(addr, populate); > > + > > + return addr; > > +} You also don't retain that last @uf argument. I'm thikning you're better off adding a helper to the cet.c file; call it cet_mmap() or whatever. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bombadil.infradead.org ([198.137.202.133]:54470 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725497AbfFGHr0 (ORCPT ); Fri, 7 Jun 2019 03:47:26 -0400 Date: Fri, 7 Jun 2019 09:47:07 +0200 From: Peter Zijlstra Subject: Re: [PATCH v7 18/27] mm: Introduce do_mmap_locked() Message-ID: <20190607074707.GD3463@hirez.programming.kicks-ass.net> References: <20190606200646.3951-1-yu-cheng.yu@intel.com> <20190606200646.3951-19-yu-cheng.yu@intel.com> <20190607074322.GP3419@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190607074322.GP3419@hirez.programming.kicks-ass.net> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Yu-cheng Yu Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Message-ID: <20190607074707.M3ET4C0Px-6oK4uelWU6KILlu1vXLCcdCZAEn1RgzqY@z> On Fri, Jun 07, 2019 at 09:43:22AM +0200, Peter Zijlstra wrote: > On Thu, Jun 06, 2019 at 01:06:37PM -0700, Yu-cheng Yu wrote: > > There are a few places that need do_mmap() with mm->mmap_sem held. > > Create an in-line function for that. > > > > Signed-off-by: Yu-cheng Yu > > --- > > include/linux/mm.h | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 398f1e1c35e5..7cf014604848 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2411,6 +2411,24 @@ static inline void mm_populate(unsigned long addr, unsigned long len) > > static inline void mm_populate(unsigned long addr, unsigned long len) {} > > #endif > > > > +static inline unsigned long do_mmap_locked(unsigned long addr, > > + unsigned long len, unsigned long prot, unsigned long flags, > > + vm_flags_t vm_flags) > > +{ > > + struct mm_struct *mm = current->mm; > > + unsigned long populate; > > + > > + down_write(&mm->mmap_sem); > > + addr = do_mmap(NULL, addr, len, prot, flags, vm_flags, 0, > > + &populate, NULL); > > Funny thing how do_mmap() takes a file pointer as first argument and > this thing explicitly NULLs that. That more or less invalidates the name > do_mmap_locked(). > > > + up_write(&mm->mmap_sem); > > + > > + if (populate) > > + mm_populate(addr, populate); > > + > > + return addr; > > +} You also don't retain that last @uf argument. I'm thikning you're better off adding a helper to the cet.c file; call it cet_mmap() or whatever.