Message ID | 20240903232241.43995-10-anthony.yznaga@oracle.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Add support for shared PTEs across processes | expand |
On Tue, Sep 03, 2024 at 04:22:40PM -0700, Anthony Yznaga wrote: > In preparation for mapping objects into an mshare region, create > __do_mmap() to allow mapping into a specified mm. There are no > functional changes otherwise. > > Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> > --- > include/linux/mm.h | 18 +++++++++++++++++- > mm/mmap.c | 12 +++++------- > 2 files changed, 22 insertions(+), 8 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 3aa0b3322284..a9afbda73cb0 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -3409,11 +3409,27 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, > > extern unsigned long mmap_region(struct file *file, unsigned long addr, > unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, > - struct list_head *uf); > + struct list_head *uf, struct mm_struct *mm); > +#ifdef CONFIG_MMU > +extern unsigned long __do_mmap(struct file *file, unsigned long addr, > + unsigned long len, unsigned long prot, unsigned long flags, > + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, > + struct list_head *uf, struct mm_struct *mm); > +static inline unsigned long do_mmap(struct file *file, unsigned long addr, > + unsigned long len, unsigned long prot, unsigned long flags, > + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, > + struct list_head *uf) > +{ > + return __do_mmap(file, addr, len, prot, flags, vm_flags, pgoff, > + populate, uf, current->mm); > +} > +#else > extern unsigned long do_mmap(struct file *file, unsigned long addr, > unsigned long len, unsigned long prot, unsigned long flags, > vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, > struct list_head *uf); > +#endif > + > extern int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, > unsigned long start, size_t len, struct list_head *uf, > bool unlock); > diff --git a/mm/mmap.c b/mm/mmap.c > index d0dfc85b209b..4112f18e7302 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1250,15 +1250,14 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, > } > > /* > - * The caller must write-lock current->mm->mmap_lock. > + * The caller must write-lock mm->mmap_lock. > */ > -unsigned long do_mmap(struct file *file, unsigned long addr, > +unsigned long __do_mmap(struct file *file, unsigned long addr, > unsigned long len, unsigned long prot, > unsigned long flags, vm_flags_t vm_flags, > unsigned long pgoff, unsigned long *populate, > - struct list_head *uf) > + struct list_head *uf, struct mm_struct *mm) Argument list getting too long. At some point we need to have a struct to pass them around. > { > - struct mm_struct *mm = current->mm; > int pkey = 0; > > *populate = 0; > @@ -1465,7 +1464,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, > vm_flags |= VM_NORESERVE; > } > > - addr = mmap_region(file, addr, len, vm_flags, pgoff, uf); > + addr = mmap_region(file, addr, len, vm_flags, pgoff, uf, mm); > if (!IS_ERR_VALUE(addr) && > ((vm_flags & VM_LOCKED) || > (flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE)) > @@ -2848,9 +2847,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, > > unsigned long mmap_region(struct file *file, unsigned long addr, > unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, > - struct list_head *uf) > + struct list_head *uf, struct mm_struct *mm) > { > - struct mm_struct *mm = current->mm; > struct vm_area_struct *vma = NULL; > struct vm_area_struct *next, *prev, *merge; > pgoff_t pglen = len >> PAGE_SHIFT; > -- > 2.43.5 >
On 10/7/24 1:44 AM, Kirill A. Shutemov wrote: > On Tue, Sep 03, 2024 at 04:22:40PM -0700, Anthony Yznaga wrote: >> In preparation for mapping objects into an mshare region, create >> __do_mmap() to allow mapping into a specified mm. There are no >> functional changes otherwise. >> >> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> >> --- >> include/linux/mm.h | 18 +++++++++++++++++- >> mm/mmap.c | 12 +++++------- >> 2 files changed, 22 insertions(+), 8 deletions(-) >> >> diff --git a/include/linux/mm.h b/include/linux/mm.h >> index 3aa0b3322284..a9afbda73cb0 100644 >> --- a/include/linux/mm.h >> +++ b/include/linux/mm.h >> @@ -3409,11 +3409,27 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, >> >> extern unsigned long mmap_region(struct file *file, unsigned long addr, >> unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, >> - struct list_head *uf); >> + struct list_head *uf, struct mm_struct *mm); >> +#ifdef CONFIG_MMU >> +extern unsigned long __do_mmap(struct file *file, unsigned long addr, >> + unsigned long len, unsigned long prot, unsigned long flags, >> + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, >> + struct list_head *uf, struct mm_struct *mm); >> +static inline unsigned long do_mmap(struct file *file, unsigned long addr, >> + unsigned long len, unsigned long prot, unsigned long flags, >> + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, >> + struct list_head *uf) >> +{ >> + return __do_mmap(file, addr, len, prot, flags, vm_flags, pgoff, >> + populate, uf, current->mm); >> +} >> +#else >> extern unsigned long do_mmap(struct file *file, unsigned long addr, >> unsigned long len, unsigned long prot, unsigned long flags, >> vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, >> struct list_head *uf); >> +#endif >> + >> extern int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, >> unsigned long start, size_t len, struct list_head *uf, >> bool unlock); >> diff --git a/mm/mmap.c b/mm/mmap.c >> index d0dfc85b209b..4112f18e7302 100644 >> --- a/mm/mmap.c >> +++ b/mm/mmap.c >> @@ -1250,15 +1250,14 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, >> } >> >> /* >> - * The caller must write-lock current->mm->mmap_lock. >> + * The caller must write-lock mm->mmap_lock. >> */ >> -unsigned long do_mmap(struct file *file, unsigned long addr, >> +unsigned long __do_mmap(struct file *file, unsigned long addr, >> unsigned long len, unsigned long prot, >> unsigned long flags, vm_flags_t vm_flags, >> unsigned long pgoff, unsigned long *populate, >> - struct list_head *uf) >> + struct list_head *uf, struct mm_struct *mm) > Argument list getting too long. At some point we need to have a struct to > pass them around. I'll look into doing that. Anthony > >> { >> - struct mm_struct *mm = current->mm; >> int pkey = 0; >> >> *populate = 0; >> @@ -1465,7 +1464,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, >> vm_flags |= VM_NORESERVE; >> } >> >> - addr = mmap_region(file, addr, len, vm_flags, pgoff, uf); >> + addr = mmap_region(file, addr, len, vm_flags, pgoff, uf, mm); >> if (!IS_ERR_VALUE(addr) && >> ((vm_flags & VM_LOCKED) || >> (flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE)) >> @@ -2848,9 +2847,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, >> >> unsigned long mmap_region(struct file *file, unsigned long addr, >> unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, >> - struct list_head *uf) >> + struct list_head *uf, struct mm_struct *mm) >> { >> - struct mm_struct *mm = current->mm; >> struct vm_area_struct *vma = NULL; >> struct vm_area_struct *next, *prev, *merge; >> pgoff_t pglen = len >> PAGE_SHIFT; >> -- >> 2.43.5 >>
diff --git a/include/linux/mm.h b/include/linux/mm.h index 3aa0b3322284..a9afbda73cb0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3409,11 +3409,27 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, extern unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf); + struct list_head *uf, struct mm_struct *mm); +#ifdef CONFIG_MMU +extern unsigned long __do_mmap(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, unsigned long flags, + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, + struct list_head *uf, struct mm_struct *mm); +static inline unsigned long do_mmap(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, unsigned long flags, + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, + struct list_head *uf) +{ + return __do_mmap(file, addr, len, prot, flags, vm_flags, pgoff, + populate, uf, current->mm); +} +#else extern unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, struct list_head *uf); +#endif + extern int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); diff --git a/mm/mmap.c b/mm/mmap.c index d0dfc85b209b..4112f18e7302 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1250,15 +1250,14 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, } /* - * The caller must write-lock current->mm->mmap_lock. + * The caller must write-lock mm->mmap_lock. */ -unsigned long do_mmap(struct file *file, unsigned long addr, +unsigned long __do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, - struct list_head *uf) + struct list_head *uf, struct mm_struct *mm) { - struct mm_struct *mm = current->mm; int pkey = 0; *populate = 0; @@ -1465,7 +1464,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, vm_flags |= VM_NORESERVE; } - addr = mmap_region(file, addr, len, vm_flags, pgoff, uf); + addr = mmap_region(file, addr, len, vm_flags, pgoff, uf, mm); if (!IS_ERR_VALUE(addr) && ((vm_flags & VM_LOCKED) || (flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE)) @@ -2848,9 +2847,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf) + struct list_head *uf, struct mm_struct *mm) { - struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; struct vm_area_struct *next, *prev, *merge; pgoff_t pglen = len >> PAGE_SHIFT;
In preparation for mapping objects into an mshare region, create __do_mmap() to allow mapping into a specified mm. There are no functional changes otherwise. Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> --- include/linux/mm.h | 18 +++++++++++++++++- mm/mmap.c | 12 +++++------- 2 files changed, 22 insertions(+), 8 deletions(-)