Content-Type: multipart/mixed; boundary="===============4138943068097393040==" MIME-Version: 1.0 From: kernel test robot To: kbuild-all@lists.01.org Subject: Re: [PATCH 3/5] mm: page_vma_mapped: support checking if a pfn is mapped into a vma Date: Tue, 25 Jan 2022 01:05:12 +0800 Message-ID: <202201250022.zqRQezMj-lkp@intel.com> In-Reply-To: <20220121075515.79311-3-songmuchun@bytedance.com> List-Id: --===============4138943068097393040== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi Muchun, Thank you for the patch! Yet something to improve: [auto build test ERROR on hnaz-mm/master] url: https://github.com/0day-ci/linux/commits/Muchun-Song/mm-rmap-fix-ca= che-flush-on-THP-pages/20220121-160020 base: https://github.com/hnaz/linux-mm master config: powerpc-allnoconfig (https://download.01.org/0day-ci/archive/202201= 25/202201250022.zqRQezMj-lkp(a)intel.com/config) compiler: powerpc-linux-gcc (GCC) 11.2.0 reproduce (this is a W=3D1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/= make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/0c83393977dfe53edadec9793= 328b7281e8af7aa git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Muchun-Song/mm-rmap-fix-cache-flus= h-on-THP-pages/20220121-160020 git checkout 0c83393977dfe53edadec9793328b7281e8af7aa # save the config file to linux build tree mkdir build_dir COMPILER_INSTALL_PATH=3D$HOME/0day COMPILER=3Dgcc-11.2.0 make.cross= O=3Dbuild_dir ARCH=3Dpowerpc SHELL=3D/bin/bash If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot All errors (new ones prefixed by >>): mm/page_vma_mapped.c: In function 'page_vma_mapped_walk': >> mm/page_vma_mapped.c:246:37: error: implicit declaration of function 'pm= d_pfn'; did you mean 'pmd_off'? [-Werror=3Dimplicit-function-declaration] 246 | if (pmd_pfn(pmde) !=3D pfn) | ^~~~~~~ | pmd_off cc1: some warnings being treated as errors vim +246 mm/page_vma_mapped.c 134 = 135 /** 136 * page_vma_mapped_walk - check if @pvmw->page or @pvmw->pfn is mapp= ed in 137 * @pvmw->vma at @pvmw->address 138 * @pvmw: pointer to struct page_vma_mapped_walk. page (or pfn and n= r and 139 * index), vma, address and flags must be set. pmd, pte and ptl must= be NULL. 140 * 141 * Returns true if the page or pfn is mapped in the vma. @pvmw->pmd = and 142 * @pvmw->pte point to relevant page table entries. @pvmw->ptl is lo= cked. 143 * @pvmw->address is adjusted if needed (for PTE-mapped THPs). 144 * 145 * If @pvmw->pmd is set but @pvmw->pte is not, you have found PMD-ma= pped page 146 * (usually THP or Huge DEVMAP). For PMD-mapped page, you should run 147 * page_vma_mapped_walk() in a loop to find all PTEs that map the hu= ge page. 148 * 149 * For HugeTLB pages, @pvmw->pte is set to the relevant page table e= ntry 150 * regardless of which page table level the page is mapped at. @pvmw= ->pmd is 151 * NULL. 152 * 153 * Returns false if there are no more page table entries for the pag= e or pfn in 154 * the vma. @pvmw->ptl is unlocked and @pvmw->pte is unmapped. 155 * 156 * If you need to stop the walk before page_vma_mapped_walk() return= ed false, 157 * use page_vma_mapped_walk_done(). It will do the housekeeping. 158 */ 159 bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) 160 { 161 struct mm_struct *mm =3D pvmw->vma->vm_mm; 162 struct page *page; 163 unsigned long end; 164 unsigned long pfn; 165 pgd_t *pgd; 166 p4d_t *p4d; 167 pud_t *pud; 168 pmd_t pmde; 169 = 170 if (pvmw->flags & PVMW_PFN_WALK) { 171 page =3D NULL; 172 pfn =3D pvmw->pfn; 173 } else { 174 page =3D pvmw->page; 175 pfn =3D page_to_pfn(page); 176 } 177 = 178 /* The only possible pmd mapping has been handled on last iteration= */ 179 if (pvmw->pmd && !pvmw->pte) 180 return not_found(pvmw); 181 = 182 if (unlikely(page && PageHuge(page))) { 183 /* The only possible mapping was handled on last iteration */ 184 if (pvmw->pte) 185 return not_found(pvmw); 186 = 187 /* when pud is not present, pte will be NULL */ 188 pvmw->pte =3D huge_pte_offset(mm, pvmw->address, page_size(page)); 189 if (!pvmw->pte) 190 return false; 191 = 192 pvmw->ptl =3D huge_pte_lockptr(page_hstate(page), mm, pvmw->pte); 193 spin_lock(pvmw->ptl); 194 if (!check_pte(pvmw)) 195 return not_found(pvmw); 196 return true; 197 } 198 = 199 /* 200 * Seek to next pte only makes sense for THP. 201 * But more important than that optimization, is to filter out 202 * any PageKsm page: whose page->index misleads vma_address() 203 * and vma_address_end() to disaster. 204 */ 205 if (page) 206 end =3D PageTransCompound(page) ? 207 vma_address_end(page, pvmw->vma) : 208 pvmw->address + PAGE_SIZE; 209 else 210 end =3D vma_pgoff_address_end(pvmw->index, pvmw->nr, pvmw->vma); 211 = 212 if (pvmw->pte) 213 goto next_pte; 214 restart: 215 do { 216 pgd =3D pgd_offset(mm, pvmw->address); 217 if (!pgd_present(*pgd)) { 218 step_forward(pvmw, PGDIR_SIZE); 219 continue; 220 } 221 p4d =3D p4d_offset(pgd, pvmw->address); 222 if (!p4d_present(*p4d)) { 223 step_forward(pvmw, P4D_SIZE); 224 continue; 225 } 226 pud =3D pud_offset(p4d, pvmw->address); 227 if (!pud_present(*pud)) { 228 step_forward(pvmw, PUD_SIZE); 229 continue; 230 } 231 = 232 pvmw->pmd =3D pmd_offset(pud, pvmw->address); 233 /* 234 * Make sure the pmd value isn't cached in a register by the 235 * compiler and used as a stale value after we've observed a 236 * subsequent update. 237 */ 238 pmde =3D READ_ONCE(*pvmw->pmd); 239 = 240 if (pmd_leaf(pmde) || is_pmd_migration_entry(pmde)) { 241 pvmw->ptl =3D pmd_lock(mm, pvmw->pmd); 242 pmde =3D *pvmw->pmd; 243 if (likely(pmd_leaf(pmde))) { 244 if (pvmw->flags & PVMW_MIGRATION) 245 return not_found(pvmw); > 246 if (pmd_pfn(pmde) !=3D pfn) 247 return not_found(pvmw); 248 return true; 249 } 250 if (!pmd_present(pmde)) { 251 swp_entry_t entry; 252 = 253 if (!thp_migration_supported() || 254 !(pvmw->flags & PVMW_MIGRATION)) 255 return not_found(pvmw); 256 entry =3D pmd_to_swp_entry(pmde); 257 if (!is_migration_entry(entry) || 258 page_to_pfn(pfn_swap_entry_to_page(entry)) !=3D pfn) 259 return not_found(pvmw); 260 return true; 261 } 262 /* THP pmd was split under us: handle on pte level */ 263 spin_unlock(pvmw->ptl); 264 pvmw->ptl =3D NULL; 265 } else if (!pmd_present(pmde)) { 266 /* 267 * If PVMW_SYNC, take and drop THP pmd lock so that we 268 * cannot return prematurely, while zap_huge_pmd() has 269 * cleared *pmd but not decremented compound_mapcount(). 270 */ 271 if ((pvmw->flags & PVMW_SYNC) && page && 272 PageTransCompound(page)) { 273 spinlock_t *ptl =3D pmd_lock(mm, pvmw->pmd); 274 = 275 spin_unlock(ptl); 276 } 277 step_forward(pvmw, PMD_SIZE); 278 continue; 279 } 280 if (!map_pte(pvmw)) 281 goto next_pte; 282 this_pte: 283 if (check_pte(pvmw)) 284 return true; 285 next_pte: 286 do { 287 pvmw->address +=3D PAGE_SIZE; 288 if (pvmw->address >=3D end) 289 return not_found(pvmw); 290 /* Did we cross page table boundary? */ 291 if ((pvmw->address & (PMD_SIZE - PAGE_SIZE)) =3D=3D 0) { 292 if (pvmw->ptl) { 293 spin_unlock(pvmw->ptl); 294 pvmw->ptl =3D NULL; 295 } 296 pte_unmap(pvmw->pte); 297 pvmw->pte =3D NULL; 298 goto restart; 299 } 300 pvmw->pte++; 301 if ((pvmw->flags & PVMW_SYNC) && !pvmw->ptl) { 302 pvmw->ptl =3D pte_lockptr(mm, pvmw->pmd); 303 spin_lock(pvmw->ptl); 304 } 305 } while (pte_none(*pvmw->pte)); 306 = 307 if (!pvmw->ptl) { 308 pvmw->ptl =3D pte_lockptr(mm, pvmw->pmd); 309 spin_lock(pvmw->ptl); 310 } 311 goto this_pte; 312 } while (pvmw->address < end); 313 = 314 return false; 315 } 316 = --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org --===============4138943068097393040==--