tree: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable head: ff9d7221f1fc9bddb4f71f7501154c68b6942b9b commit: 24a134b0c0a857bbf193eb7b3d8fcbbf77517c5f [102/232] mm: refactor of vma_merge() config: x86_64-defconfig compiler: gcc-11 (Debian 11.3.0-3) 11.3.0 reproduce (this is a W=1 build): # https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?id=24a134b0c0a857bbf193eb7b3d8fcbbf77517c5f git remote add akpm-mm https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git git fetch --no-tags akpm-mm mm-unstable git checkout 24a134b0c0a857bbf193eb7b3d8fcbbf77517c5f # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot All warnings (new ones prefixed by >>): mm/mmap.c: In function 'vma_merge': mm/mmap.c:1094:9: error: 'area' undeclared (first use in this function) 1094 | area = next; | ^~~~ mm/mmap.c:1094:9: note: each undeclared identifier is reported only once for each function it appears in >> mm/mmap.c:1084:14: warning: unused variable 'merge_next' [-Wunused-variable] 1084 | bool merge_next = false; | ^~~~~~~~~~ >> mm/mmap.c:1083:14: warning: unused variable 'merge_prev' [-Wunused-variable] 1083 | bool merge_prev = false; | ^~~~~~~~~~ >> mm/mmap.c:1081:45: warning: unused variable 'res' [-Wunused-variable] 1081 | struct vm_area_struct *mid, *next, *res; | ^~~ >> mm/mmap.c:1081:32: warning: unused variable 'mid' [-Wunused-variable] 1081 | struct vm_area_struct *mid, *next, *res; | ^~~ vim +/merge_next +1084 mm/mmap.c 1028 1029 /* 1030 * Given a mapping request (addr,end,vm_flags,file,pgoff,anon_name), 1031 * figure out whether that can be merged with its predecessor or its 1032 * successor. Or both (it neatly fills a hole). 1033 * 1034 * In most cases - when called for mmap, brk or mremap - [addr,end) is 1035 * certain not to be mapped by the time vma_merge is called; but when 1036 * called for mprotect, it is certain to be already mapped (either at 1037 * an offset within prev, or at the start of next), and the flags of 1038 * this area are about to be changed to vm_flags - and the no-change 1039 * case has already been eliminated. 1040 * 1041 * The following mprotect cases have to be considered, where AAAA is 1042 * the area passed down from mprotect_fixup, never extending beyond one 1043 * vma, PPPPPP is the prev vma specified, and NNNNNN the next vma after: 1044 * 1045 * AAAA AAAA AAAA 1046 * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPNNNNNN 1047 * cannot merge might become might become 1048 * PPNNNNNNNNNN PPPPPPPPPPNN 1049 * mmap, brk or case 4 below case 5 below 1050 * mremap move: 1051 * AAAA AAAA 1052 * PPPP NNNN PPPPNNNNXXXX 1053 * might become might become 1054 * PPPPPPPPPPPP 1 or PPPPPPPPPPPP 6 or 1055 * PPPPPPPPNNNN 2 or PPPPPPPPXXXX 7 or 1056 * PPPPNNNNNNNN 3 PPPPXXXXXXXX 8 1057 * 1058 * It is important for case 8 that the vma NNNN overlapping the 1059 * region AAAA is never going to extended over XXXX. Instead XXXX must 1060 * be extended in region AAAA and NNNN must be removed. This way in 1061 * all cases where vma_merge succeeds, the moment vma_adjust drops the 1062 * rmap_locks, the properties of the merged vma will be already 1063 * correct for the whole merged range. Some of those properties like 1064 * vm_page_prot/vm_flags may be accessed by rmap_walks and they must 1065 * be correct for the whole merged range immediately after the 1066 * rmap_locks are released. Otherwise if XXXX would be removed and 1067 * NNNN would be extended over the XXXX range, remove_migration_ptes 1068 * or other rmap walkers (if working on addresses beyond the "end" 1069 * parameter) may establish ptes with the wrong permissions of NNNN 1070 * instead of the right permissions of XXXX. 1071 */ 1072 struct vm_area_struct *vma_merge(struct mm_struct *mm, 1073 struct vm_area_struct *prev, unsigned long addr, 1074 unsigned long end, unsigned long vm_flags, 1075 struct anon_vma *anon_vma, struct file *file, 1076 pgoff_t pgoff, struct mempolicy *policy, 1077 struct vm_userfaultfd_ctx vm_userfaultfd_ctx, 1078 struct anon_vma_name *anon_name) 1079 { 1080 pgoff_t pglen = (end - addr) >> PAGE_SHIFT; > 1081 struct vm_area_struct *mid, *next, *res; 1082 int err = -1; > 1083 bool merge_prev = false; > 1084 bool merge_next = false; 1085 1086 /* 1087 * We later require that vma->vm_flags == vm_flags, 1088 * so this tests vma->vm_flags & VM_SPECIAL, too. 1089 */ 1090 if (vm_flags & VM_SPECIAL) 1091 return NULL; 1092 1093 next = find_vma(mm, prev ? prev->vm_end : 0); 1094 area = next; 1095 if (area && area->vm_end == end) /* cases 6, 7, 8 */ 1096 next = find_vma(mm, next->vm_end); 1097 1098 /* verify some invariant that must be enforced by the caller */ 1099 VM_WARN_ON(prev && addr <= prev->vm_start); 1100 VM_WARN_ON(area && end > area->vm_end); 1101 VM_WARN_ON(addr >= end); 1102 1103 /* 1104 * Can it merge with the predecessor? 1105 */ 1106 if (prev && prev->vm_end == addr && 1107 mpol_equal(vma_policy(prev), policy) && 1108 can_vma_merge_after(prev, vm_flags, 1109 anon_vma, file, pgoff, 1110 vm_userfaultfd_ctx, anon_name)) { 1111 /* 1112 * OK, it can. Can we now merge in the successor as well? 1113 */ 1114 if (next && end == next->vm_start && 1115 mpol_equal(policy, vma_policy(next)) && 1116 can_vma_merge_before(next, vm_flags, 1117 anon_vma, file, 1118 pgoff+pglen, 1119 vm_userfaultfd_ctx, anon_name) && 1120 is_mergeable_anon_vma(prev->anon_vma, 1121 next->anon_vma, NULL)) { 1122 /* cases 1, 6 */ 1123 err = __vma_adjust(prev, prev->vm_start, 1124 next->vm_end, prev->vm_pgoff, NULL, 1125 prev); 1126 } else /* cases 2, 5, 7 */ 1127 err = __vma_adjust(prev, prev->vm_start, 1128 end, prev->vm_pgoff, NULL, prev); 1129 if (err) 1130 return NULL; 1131 khugepaged_enter_vma(prev, vm_flags); 1132 return prev; 1133 } 1134 1135 /* 1136 * Can this new request be merged in front of next? 1137 */ 1138 if (next && end == next->vm_start && 1139 mpol_equal(policy, vma_policy(next)) && 1140 can_vma_merge_before(next, vm_flags, 1141 anon_vma, file, pgoff+pglen, 1142 vm_userfaultfd_ctx, anon_name)) { 1143 if (prev && addr < prev->vm_end) /* case 4 */ 1144 err = __vma_adjust(prev, prev->vm_start, 1145 addr, prev->vm_pgoff, NULL, next); 1146 else { /* cases 3, 8 */ 1147 err = __vma_adjust(area, addr, next->vm_end, 1148 next->vm_pgoff - pglen, NULL, next); 1149 /* 1150 * In case 3 area is already equal to next and 1151 * this is a noop, but in case 8 "area" has 1152 * been removed and next was expanded over it. 1153 */ 1154 area = next; 1155 } 1156 if (err) 1157 return NULL; 1158 khugepaged_enter_vma(area, vm_flags); 1159 return area; 1160 } 1161 1162 return NULL; 1163 } 1164 -- 0-DAY CI Kernel Test Service https://01.org/lkp