[1/3] mm/memory: Change vmf_anon_prepare() to be non-static

Message ID 20240220231424.126600-2-vishal.moola@gmail.com
State New
Headers
Series Handle hugetlb faults under the VMA lock |

Commit Message

Vishal Moola Feb. 20, 2024, 11:14 p.m. UTC
  In order to handle hugetlb faults under the VMA lock, hugetlb can use
vmf_anon_prepare() to ensure we can safely prepare an anon_vma. Change
it to be a non-static function so it can be used within hugetlb as well.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
 include/linux/hugetlb.h | 1 +
 mm/memory.c             | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
  

Comments

Matthew Wilcox Feb. 21, 2024, 3:36 a.m. UTC | #1
On Tue, Feb 20, 2024 at 03:14:22PM -0800, Vishal Moola (Oracle) wrote:
> In order to handle hugetlb faults under the VMA lock, hugetlb can use
> vmf_anon_prepare() to ensure we can safely prepare an anon_vma. Change
> it to be a non-static function so it can be used within hugetlb as well.

I think the prototype for this should probably live in mm/internal.h?

> +++ b/include/linux/hugetlb.h
> @@ -272,6 +272,7 @@ void hugetlb_vma_unlock_write(struct vm_area_struct *vma);
>  int hugetlb_vma_trylock_write(struct vm_area_struct *vma);
>  void hugetlb_vma_assert_locked(struct vm_area_struct *vma);
>  void hugetlb_vma_lock_release(struct kref *kref);
> +vm_fault_t vmf_anon_prepare(struct vm_fault *vmf);
>  
>  int pmd_huge(pmd_t pmd);
>  int pud_huge(pud_t pud);
>
  
Vishal Moola Feb. 21, 2024, 4:49 p.m. UTC | #2
On Tue, Feb 20, 2024 at 7:36 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Feb 20, 2024 at 03:14:22PM -0800, Vishal Moola (Oracle) wrote:
> > In order to handle hugetlb faults under the VMA lock, hugetlb can use
> > vmf_anon_prepare() to ensure we can safely prepare an anon_vma. Change
> > it to be a non-static function so it can be used within hugetlb as well.
>
> I think the prototype for this should probably live in mm/internal.h?

That does make more sense, I'll move it for v2.

> > +++ b/include/linux/hugetlb.h
> > @@ -272,6 +272,7 @@ void hugetlb_vma_unlock_write(struct vm_area_struct *vma);
> >  int hugetlb_vma_trylock_write(struct vm_area_struct *vma);
> >  void hugetlb_vma_assert_locked(struct vm_area_struct *vma);
> >  void hugetlb_vma_lock_release(struct kref *kref);
> > +vm_fault_t vmf_anon_prepare(struct vm_fault *vmf);
> >
> >  int pmd_huge(pmd_t pmd);
> >  int pud_huge(pud_t pud);
> >
  
kernel test robot Feb. 21, 2024, 5:30 p.m. UTC | #3
Hi Vishal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.8-rc5 next-20240221]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vishal-Moola-Oracle/mm-memory-Change-vmf_anon_prepare-to-be-non-static/20240221-071907
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20240220231424.126600-2-vishal.moola%40gmail.com
patch subject: [PATCH 1/3] mm/memory: Change vmf_anon_prepare() to be non-static
config: arm-defconfig (https://download.01.org/0day-ci/archive/20240222/202402220109.SIlFdfQ5-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240222/202402220109.SIlFdfQ5-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202402220109.SIlFdfQ5-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/memory.c:3283:12: warning: no previous prototype for function 'vmf_anon_prepare' [-Wmissing-prototypes]
   vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
              ^
   mm/memory.c:3283:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
   ^
   static 
   1 warning generated.


vim +/vmf_anon_prepare +3283 mm/memory.c

  3282	
> 3283	vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
  3284	{
  3285		struct vm_area_struct *vma = vmf->vma;
  3286	
  3287		if (likely(vma->anon_vma))
  3288			return 0;
  3289		if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
  3290			vma_end_read(vma);
  3291			return VM_FAULT_RETRY;
  3292		}
  3293		if (__anon_vma_prepare(vma))
  3294			return VM_FAULT_OOM;
  3295		return 0;
  3296	}
  3297
  
kernel test robot Feb. 21, 2024, 7:37 p.m. UTC | #4
Hi Vishal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.8-rc5 next-20240221]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vishal-Moola-Oracle/mm-memory-Change-vmf_anon_prepare-to-be-non-static/20240221-071907
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20240220231424.126600-2-vishal.moola%40gmail.com
patch subject: [PATCH 1/3] mm/memory: Change vmf_anon_prepare() to be non-static
config: alpha-allnoconfig (https://download.01.org/0day-ci/archive/20240222/202402220352.930oDAQ6-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240222/202402220352.930oDAQ6-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202402220352.930oDAQ6-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/memory.c:3283:12: warning: no previous prototype for 'vmf_anon_prepare' [-Wmissing-prototypes]
    3283 | vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
         |            ^~~~~~~~~~~~~~~~


vim +/vmf_anon_prepare +3283 mm/memory.c

  3282	
> 3283	vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
  3284	{
  3285		struct vm_area_struct *vma = vmf->vma;
  3286	
  3287		if (likely(vma->anon_vma))
  3288			return 0;
  3289		if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
  3290			vma_end_read(vma);
  3291			return VM_FAULT_RETRY;
  3292		}
  3293		if (__anon_vma_prepare(vma))
  3294			return VM_FAULT_OOM;
  3295		return 0;
  3296	}
  3297
  

Patch

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index c1ee640d87b1..9b45edb6e303 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -272,6 +272,7 @@  void hugetlb_vma_unlock_write(struct vm_area_struct *vma);
 int hugetlb_vma_trylock_write(struct vm_area_struct *vma);
 void hugetlb_vma_assert_locked(struct vm_area_struct *vma);
 void hugetlb_vma_lock_release(struct kref *kref);
+vm_fault_t vmf_anon_prepare(struct vm_fault *vmf);
 
 int pmd_huge(pmd_t pmd);
 int pud_huge(pud_t pud);
diff --git a/mm/memory.c b/mm/memory.c
index 89bcae0b224d..c93b058adfb2 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3081,7 +3081,7 @@  static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf)
 	return VM_FAULT_RETRY;
 }
 
-static vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
+vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;