From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796063646; b=upEHXCmCLb1fYnaOsm02OmIDbh5jahZrVnUaWamob3n4jIhGR6A6osoO+F+qio8znmGl D4OaFqOF2P08RrSd8ptvLHiNQnGG05e0/Xvl8FjE7twh5z7bmfKUVYhEzSJvcOdfsMrqu oKxHX/BS4S1AHs2GV57BM8ft5aiM7GBOu0SNjCFIikKmWL4aFEwfXp4VLQg6UZU+S4hQ0 4uPgLAIfWtQ3xhgsPSlNjhgueTShMT8xhyxTj1nQavAO/b2MXePO0POR71qPO+lUFtjFX EpA2Z8CqjoH3p6vNqYyzIMOTCHea0/HwYP9dpS/6MX0QpFmevNAUfQ5trBXxCZBIEkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796063646; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=VciXt1OBz+Uy0wa5NJsKNDCP6XJEO0jS9ARHRms0SmE=; b=obs/t8VTzyff/KK4s58UTE+vQvAkF3cyyVb7Hut2zbo1hZpeFx+g9F1t/QqMIDmDYMvM gAnUcN8y4LDr5TnQTAF+FU8hpdcc4cqv734eb3BGrjLj3NGMZhuhMEsnuZWsbJrv+TiZD tZqGQEAvu6h56sqmF5KKG2E6DcIozEhrCF39zC8o58/g8YxX/NgN9o6bCIqvwDSFPGeMC iZ3gf9xqEE9gJbXMHVuP0ijy2FAsLA3a34Q152HMwTsXsuDSZdTIxaiw5l9qGkbWY2kxc Gl/5+m171iGOQh6RUdgsKnb1UD1Gn8yVygzOxKiwGwRmyVzOz15sJftI8PtgEbD4JXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HFpAXU8o; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71883606A31C; Mon, 30 Nov 2026 18:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HFpAXU8o Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB1921F000C1; Mon, 30 Nov 2026 18:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796063646; bh=VciXt1OBz+Uy0wa5NJsKNDCP6XJEO0jS9ARHRms0SmE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=HFpAXU8o0wL1JIkGNko2Fv+Jw6R3ocXUaMbf+ILKMu+W6w3ANw0ehoVo5pKufUcbc 3Kcngz9jZSi61VA65WBMxXKWK63UR2PmY00eoD1fMBZbD2xZYWKFqhl+z0HXP/JR90 wA/0f5Fpl8o/fPDb+3Nn+avauPbhU97ZiPLJsd/c19QbQEEFwAatbi1alqKpBMsVTj fbriPWmuKanfi59KEYJh/HG53ZwZ7Ibf+rzrSiR8yROho0sgL6210G2xB9nEEkD1oe f0TSG2VLgsRZR8Eu+1SwZqT3Oeq9E+rWh+i/G/2rLhcSbWtKoyr71HMjyp0TlfOTSY rGBhkFzCyLDmQ== Date: Mon, 30 Nov 2026 18:33:56 +0000 From: "Lorenzo Stoakes (ARM)" To: "Jose A. Perez de Azpillaga" Cc: David Hildenbrand , Zi Yan , Andrew Morton , Zach O'Keefe , Hugh Dickins , Kiryl Shutsemau , Baolin Wang , Dev Jain , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Barry Song , Lance Yang , Usama Arif , Vlastimil Babka , Mike Rapoport , Michal Hocko , linux-mm@kvack.org, Matthew Wilcox , Jan Kara , Johannes Weiner , Rik van Riel , Song Liu , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 1/3] mm/memory: allocate the deposit page table with NOFS in do_set_pmd() Message-ID: References: <20261127091344.113688-1-azpijr@gmail.com> <20261127091344.113688-2-azpijr@gmail.com> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127091344.113688-2-azpijr@gmail.com> On Fri, Nov 27, 2026 at 10:12:14AM +0100, Jose A. Perez de Azpillaga wrote: > On ppc64 with the hash MMU, do_set_pmd() allocates the page table to > deposit when the caller did not preallocate one. Both callers that let > it allocate hold the folio lock: set_huge_pmd() in khugepaged never > preallocates, and finish_fault() has no preallocated table when the > page table was removed after __do_fault() checked the PMD. Coudl we de-schloppen this a bit? E.g.: ppc64 allocates a page table in do_set_pmd() when it's not preallocated while callers of it hold the folio lock, e.g. set_huge_pmd() and finish_fault() (under certain circumstances). > > Allocating with __GFP_FS while holding a folio lock can deadlock in > reclaim, for example the memcg reclaim deadlock on cgroup v1 described > in commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with > writeback"). > > pte_alloc_one() takes no gfp flags, so allocate the table in a NOFS > scope. > > Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE") > Fixes: 1d65b771bc08 ("mm/khugepaged: retract_page_tables() without mmap or vma lock") > Cc: stable@vger.kernel.org > Signed-off-by: Jose A. Perez de Azpillaga Looks reasonable so with changes requested and to commit msg: Reviewed-by: Lorenzo Stoakes (ARM) > --- > Changes in v2: > - new, replaces v1 3/4 "mm/memory: never allocate a page table in > do_set_pmd()" (David) > > v1: https://lore.kernel.org/20261125100058.15200-4-azpijr@gmail.com > > mm/memory.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/mm/memory.c b/mm/memory.c > index dfa307a9228c..05d03b32ce52 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5806,9 +5806,17 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct folio *folio, struct page *pa > * related to pte entry. Use the preallocated table for that. > */ > if (arch_needs_pgtable_deposit() && !vmf->prealloc_pte) { > + unsigned int nofs_flags; 'flags' please. It's a small block-scope var we don't really need to spell it out! > + > if (!may_alloc) > return VM_FAULT_FALLBACK; > + /* > + * The folio is locked, and reclaim or compaction with __GFP_FS It IS locked? Under all circumstances? Presumably so. > + * could deadlock on it. pte_alloc_one() takes no gfp flags. > + */ This is schloppy and silly. 'pte_alloc_one() takes no flags'. Which one can observe from literally looking 2 lines below... It's also asking for bitrot. Just make it something like: /* Folio is locked, so avoid deadlock against concurrent reclaim */ Please. > + nofs_flags = memalloc_nofs_save(); > vmf->prealloc_pte = pte_alloc_one(vma->vm_mm); > + memalloc_nofs_restore(nofs_flags); > if (!vmf->prealloc_pte) > return VM_FAULT_OOM; > pgtable_allocated = true; > -- > 2.56.1 > -- Cheers, Lorenzo