From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793085645; b=XefV1EycbVO/zspbTmsbRnmUc1b5eWfuy6S7MmPKaVJE6U5MgeBTQWeSpC1st5e+vzjv N3eN6kJCGaaOqDTUwm3IzA0HFfqnQza0m2SHGFPmjKXkkKP9jfdH+2WAg6ATVicLOW2ai FPmu213GIqedvmAe3AQlVrTZn/zbGYCU4P5TvFEHXEMrPNcDfkyQCvF4C5Ax+4IKbjZf3 +NkD77KeMhkoTk8sCQlxpoJWWPLUTDqGqI1Bd/iEgn6HPKA3Waf8wEcLWEcamg497Oa8S N3BwcdjcJx4kHA3DgxRXGvJ6Uu5Wu7xsRSuFCQrBANftbcV2QcdnU1grOr+MAvziQIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793085645; h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=JxvqEmSKUPHSp/dylabMtz9NDYhSF/aiHTeMfx5p0gg=; b=wGlMEmfImBXXTyHB5gD3Vki2cA2SO5lAn0OsQGSNEg63lAf+FVkwnlbbl9fxhT9Kz1aw bNYwCYpfejKpKV/GcqP+h0E1Z8cvfAmpKbUsGH/X8trXj7YHqfCvWgkMXGiy1Qb4cOmTw mnxyc2dpQ1GNfUgFect5LxKQDtBJ2m7y/vugJ8zdf0obwAOqHH6cmlqv9JJdUtZtohZP4 yovxL0Hp3WD/kbhjIjtyo0+7AphlYA5fJikqrboBsJ0zFm21QFuoU8aUtZtxoHDHQtnxt C6zSYQEldpBw6W+0XHKadZ6tCdiUqVT8NXNzbQ01A2/Feh5ZnjzR7C3IpGgcalQaCOg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=vQcZ+K7u; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA75B606A31A; Tue, 27 Oct 2026 07:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA75B606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=vQcZ+K7u Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DD3D21655; Tue, 27 Oct 2026 00:20:39 -0700 (PDT) Received: from [10.163.152.160] (unknown [10.163.152.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EA8A93F673; Tue, 27 Oct 2026 00:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1793085643; bh=9hjydCMJHH07W+S/5zQJiskTD8rJHnoHE7cyvgQKAu4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=vQcZ+K7utjnoFyY/avj8WNV9xYKitfP2P//3Id71b4DAsIKJDegS4COAwYGEiNKT2 PrXdAjX60UJjVEs2tZHA6I59AtFq0w29SQQ4rAvE+M4N2PjAlsPToayaOUnEVUpCVa /LBIke5i9dpMnl6JO3d6gq7y1YASHSTdsmqI17a4= Message-ID: <12633ce2-dc65-4908-930f-b128f525cc8a@arm.com> Date: Tue, 27 Oct 2026 12:50:19 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 01/46] mm/mglru: don't use stack pointers when walking PUD and PMD tables To: "David Hildenbrand (Arm)" , Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kees Cook , Peter Zijlstra , Jann Horn , Pedro Falcato , Hugh Dickins , Pasha Tatashin , Pratyush Yadav , "Matthew Wilcox (Oracle)" , Jan Kara , Zi Yan , Lance Yang , Rik van Riel , Harry Yoo , Alistair Popple , Nico Pache , Ryan Roberts , Usama Arif , Kiryl Shutsemau , Matthew Brost , John Hubbard , Peter Xu , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Oscar Salvador , Minchan Kim , Muchun Song , Xu Xin , Chengming Zhou , Chris Li , Kemeng Shi , Nhat Pham , Youngjun Park , Gregory Price , Joshua Hahn , Rakie Kim , Ying Huang , Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, Josef Bacik , stable@vger.kernel.org References: <20261027-fixes_core-v1-0-6f74bec9a5bb@kernel.org> <20261027-fixes_core-v1-1-6f74bec9a5bb@kernel.org> Content-Language: en-US From: Dev Jain In-Reply-To: <20261027-fixes_core-v1-1-6f74bec9a5bb@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 27/10/26 4:47 am, David Hildenbrand (Arm) wrote: > From: Josef Bacik > > MGLRU passes stack copies of page-table entries in walk_pud_range() and > walk_pmd_range() when walking to the next level. These copies can become > stale when khugepaged or MADV_DONTNEED (CONFIG_PT_RECLAIM) removes a PTE > table concurrently. > > This pattern dates back to commit bd74fdaea146 ("mm: multi-gen LRU: > support page table walks"). Likely, earlier locking masked the latent > bug. Later changes exposed it: commit 1d65b771bc08 ("mm/khugepaged: > retract_page_tables() without mmap or vma lock") allowed concurrent > retraction, and commit cf4a65539c13 ("memcg-v1: no need for memcg locking > for MGLRU") dropped the walker's outer RCU protection. > > The fix is simple, so just fix the original commit so we don't have to > speculate. To fix it, pass the actual PMD/PUD pointers. This restores the > RCU-protected lookup and validation against the live PMD. Note that the PUD > handling is required as well to handle folded page tables correctly in all > cases. > > Fix generated by an LLM and sent by Josef Bacik in private. > > Fixes: bd74fdaea146 ("mm: multi-gen LRU: support page table walks") > Cc: stable@vger.kernel.org > Signed-off-by: Josef Bacik > [ david: handle walk_pud_range() as well, clarify+simplify description, > adjust Fixes: ] > Signed-off-by: David Hildenbrand (Arm) > --- Reviewed-by: Dev Jain > mm/vmscan.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 9959ca158ce83..6a1af9b92349f 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -3911,7 +3911,7 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end, > > walk->mm_stats[MM_NONLEAF_FOUND]++; > > - if (!walk_pte_range(&val, addr, next, args)) > + if (!walk_pte_range(pmd + i, addr, next, args)) > continue; > > walk->mm_stats[MM_NONLEAF_ADDED]++; > @@ -3947,7 +3947,7 @@ static int walk_pud_range(p4d_t *p4d, unsigned long start, unsigned long end, > if (!pud_present(val) || WARN_ON_ONCE(pud_leaf(val))) > continue; > > - walk_pmd_range(&val, addr, next, args); > + walk_pmd_range(pud + i, addr, next, args); > > if (need_resched() || walk->batched >= MAX_LRU_BATCH) { > end = (addr | ~PUD_MASK) + 1; >