diff mbox series

[mm-unstable,11/17] mm: sh: Introduce arch_mmap_hint()

Message ID 20241210024119.2488608-12-kaleshsingh@google.com (mailing list archive)
State Superseded
Headers show
Series mm: Introduce arch_mmap_hint() | expand

Commit Message

Kalesh Singh Dec. 10, 2024, 2:41 a.m. UTC
Introduce sh arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.

Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
 arch/sh/include/asm/pgtable.h |  1 +
 arch/sh/mm/mmap.c             | 48 +++++++++++++++++++----------------
 2 files changed, 27 insertions(+), 22 deletions(-)

Comments

kernel test robot Dec. 10, 2024, 12:41 p.m. UTC | #1
Hi Kalesh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Kalesh-Singh/mm-Introduce-generic_mmap_hint/20241210-104424
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241210024119.2488608-12-kaleshsingh%40google.com
patch subject: [PATCH mm-unstable 11/17] mm: sh: Introduce arch_mmap_hint()
config: sh-randconfig-001-20241210 (https://download.01.org/0day-ci/archive/20241210/202412102044.uIAN0clk-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241210/202412102044.uIAN0clk-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/202412102044.uIAN0clk-lkp@intel.com/

All warnings (new ones prefixed by >>):

   arch/sh/mm/mmap.c: In function 'arch_get_unmapped_area':
>> arch/sh/mm/mmap.c:79:32: warning: unused variable 'vma' [-Wunused-variable]
      79 |         struct vm_area_struct *vma;
         |                                ^~~
>> arch/sh/mm/mmap.c:78:27: warning: unused variable 'mm' [-Wunused-variable]
      78 |         struct mm_struct *mm = current->mm;
         |                           ^~
   arch/sh/mm/mmap.c: In function 'arch_get_unmapped_area_topdown':
   arch/sh/mm/mmap.c:117:32: warning: unused variable 'vma' [-Wunused-variable]
     117 |         struct vm_area_struct *vma;
         |                                ^~~


vim +/vma +79 arch/sh/mm/mmap.c

2261b9c7c2357a0 Kalesh Singh      2024-12-09   73  
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   74  unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
25d4054cc97484f Mark Brown        2024-09-04   75  	unsigned long len, unsigned long pgoff, unsigned long flags,
25d4054cc97484f Mark Brown        2024-09-04   76  	vm_flags_t vm_flags)
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   77  {
4a4a9be3ebdbf17 Paul Mundt        2008-11-12  @78  	struct mm_struct *mm = current->mm;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12  @79  	struct vm_area_struct *vma;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   80  	int do_colour_align;
b80fa3cbb78c0fb Rick Edgecombe    2024-03-25   81  	struct vm_unmapped_area_info info = {};
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   82  
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   83  	if (flags & MAP_FIXED) {
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   84  		/* We do not accept a shared mapping if it would violate
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   85  		 * cache aliasing constraints.
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   86  		 */
e77414e0aad6a1b Al Viro           2009-12-05   87  		if ((flags & MAP_SHARED) &&
e77414e0aad6a1b Al Viro           2009-12-05   88  		    ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   89  			return -EINVAL;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   90  		return addr;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   91  	}
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   92  
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   93  	if (unlikely(len > TASK_SIZE))
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   94  		return -ENOMEM;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   95  
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   96  	do_colour_align = 0;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   97  	if (filp || (flags & MAP_SHARED))
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   98  		do_colour_align = 1;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12   99  
2261b9c7c2357a0 Kalesh Singh      2024-12-09  100  	addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
2261b9c7c2357a0 Kalesh Singh      2024-12-09  101  	if (addr)
4a4a9be3ebdbf17 Paul Mundt        2008-11-12  102  		return addr;
4a4a9be3ebdbf17 Paul Mundt        2008-11-12  103  
b4265f12340f809 Michel Lespinasse 2012-12-11  104  	info.length = len;
b4265f12340f809 Michel Lespinasse 2012-12-11  105  	info.low_limit = TASK_UNMAPPED_BASE;
b4265f12340f809 Michel Lespinasse 2012-12-11  106  	info.high_limit = TASK_SIZE;
b4265f12340f809 Michel Lespinasse 2012-12-11  107  	info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
b4265f12340f809 Michel Lespinasse 2012-12-11  108  	info.align_offset = pgoff << PAGE_SHIFT;
b4265f12340f809 Michel Lespinasse 2012-12-11  109  	return vm_unmapped_area(&info);
4a4a9be3ebdbf17 Paul Mundt        2008-11-12  110  }
ee1acbfabd5270b Paul Mundt        2009-05-07  111
diff mbox series

Patch

diff --git a/arch/sh/include/asm/pgtable.h b/arch/sh/include/asm/pgtable.h
index 729f5c6225fb..072dbe038808 100644
--- a/arch/sh/include/asm/pgtable.h
+++ b/arch/sh/include/asm/pgtable.h
@@ -149,5 +149,6 @@  static inline bool pte_access_permitted(pte_t pte, bool write)
 /* arch/sh/mm/mmap.c */
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
 
 #endif /* __ASM_SH_PGTABLE_H */
diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
index c442734d9b0c..5c96055dd5f5 100644
--- a/arch/sh/mm/mmap.c
+++ b/arch/sh/mm/mmap.c
@@ -51,6 +51,26 @@  static inline unsigned long COLOUR_ALIGN(unsigned long addr,
 	return base + off;
 }
 
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+			     unsigned long len, unsigned long pgoff,
+			     unsigned long flags)
+{
+	int do_color_align = 0;
+
+	if (!addr)
+		return 0;
+
+	if (filp || (flags & MAP_SHARED))
+		do_color_align = 1;
+
+	if (do_color_align)
+		addr = COLOUR_ALIGN(addr, pgoff);
+	else
+		addr = PAGE_ALIGN(addr);
+
+	return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
 	unsigned long len, unsigned long pgoff, unsigned long flags,
 	vm_flags_t vm_flags)
@@ -77,17 +97,9 @@  unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
 	if (filp || (flags & MAP_SHARED))
 		do_colour_align = 1;
 
-	if (addr) {
-		if (do_colour_align)
-			addr = COLOUR_ALIGN(addr, pgoff);
-		else
-			addr = PAGE_ALIGN(addr);
-
-		vma = find_vma(mm, addr);
-		if (TASK_SIZE - len >= addr &&
-		    (!vma || addr + len <= vm_start_gap(vma)))
-			return addr;
-	}
+	addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+	if (addr)
+		return addr;
 
 	info.length = len;
 	info.low_limit = TASK_UNMAPPED_BASE;
@@ -126,17 +138,9 @@  arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
 		do_colour_align = 1;
 
 	/* requesting a specific address */
-	if (addr) {
-		if (do_colour_align)
-			addr = COLOUR_ALIGN(addr, pgoff);
-		else
-			addr = PAGE_ALIGN(addr);
-
-		vma = find_vma(mm, addr);
-		if (TASK_SIZE - len >= addr &&
-		    (!vma || addr + len <= vm_start_gap(vma)))
-			return addr;
-	}
+	addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+	if (addr)
+		return addr;
 
 	info.flags = VM_UNMAPPED_AREA_TOPDOWN;
 	info.length = len;