From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C30747DD72 for ; Wed, 19 Aug 2026 15:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787152449; cv=none; b=ZbUogIHf0vUIAOvABrZvzU0gVy4K0vsiz7Wf8QWQHmY4ZEsk8ginALhGqSbPhsBxs9o3D8x99Emt24xNtqLzuLw2xJs3zDieQyVCUcnLehxTqHsdxWgB6UMEySi53twvAyEd+uvQ2ZLHSv55bHf1xMkpV577KqY19gW6qjXLfzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787152449; c=relaxed/simple; bh=0sttszakrMH7NTiNLnAlhNDJWnM8SzIAOWKav4bGCDg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ipNoT0txfjPWLdfIf9OcABNH8od9CdNLcvm3a0A5VL2YR4GYO/ComraPuPYoWebSUZ45JwXgsyDreFJfUkFwvF5C19iNTbXbda3911/9LHnvdxqh6DKPvBzknz3hOgvpQajvPWLnXD3+25QvvblKxBcpKBZNWSkfOMglsIQz8XM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YTfv8y3b; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YTfv8y3b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DD341F000E9; Wed, 19 Aug 2026 15:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787152446; bh=AtA5mvQQ7MuCXISnQbexM1kw6XBF0r5MhQXIqx1BTrs=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=YTfv8y3biilDCuhY6OYy8ANnKdiNdgKHBJpENZHNL7vbYFN01xDQNac9b1YHuO9U9 0Meqyla48o5PxUmvrCk6BmfeNsnQd66uitkuAXcPrHkkBINVUeBvUtkMgMA+AoCl1/ C3jolJQGfiieQBrqmoTlp/Ime2eLMXMJXRZlhkqwiH3jFm2OK0GNyR6ZeTEanWsxKk FWx7VKyGRFdn6rnKvwIwurt6xpkLP97Ejp3SjQphHTb+AMu6XeK2ko1Fluf7/U559j 2zBVGRRFDY30U4S4VYsK81IgcYpL3Dh8UaVTL7nYErX26hpz4sjkDarZFQIw0fLXNU WmyXkU6xKipTw== Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfauth.ams.internal (Postfix) with ESMTP id 58FEB198007C; Wed, 19 Aug 2026 11:13:59 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 19 Aug 2026 11:14:03 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFC874SqF5jgsGEVLBfbAFduP+mDXsDSwMWKiKTuMoavP1oB+KifqBRX/hDeHraKn C7cfsEd3id27APShl8ehKo2D/BrLfhYUjDUUJSYZnUAyHw5GR6ippKZ0dIcwwUwUUBJHfz tLscdKxQf9sMOh/ztP/IltP5J74r5Gk8cLjJqG8ArQ1asEjzFDgrqUKPLajNVdLLdS11CP wjMu8+NSt/1a+rRq3Y1/7hVBbm06JC+qs9eHXcOOmC/NdFBysy20LymarntUyvWTXty776 ciqsnw8bL1OmbbhooeEbBHnb/FJ3/96PTKBGsUb/yZ5BM81GiTeOkmXadYlHbmd0wp4Ycz 6h4eGTiM3n+KmSTR9SP8vg14497+uVjAkCKo4mr/vkRcVVB7VWoR4cyUF7fSjESRpzXqAU nIlwrXfkMuO5qFJUmYazFuG/a1G+DBMOlQHq0FMvaDl+Vl9MEE/sIf/7eyBSFvPEYMDqov BHrBgWFdhKuZ93N2kRYuKtkW9mXDEwmf1CfDwLKjsCVO4d6gui12hg275bxNEE2HSBRvi/ e6/tsu9TCQGecnn/t06T2OHuU84IlSjNfnzHk158PHdeyb3jcwEpOw/Z3kuMOsPLoN4K93 RhGohPwdLXodlGh5VZmkyITb3tPMBvQ1zGE9qe4yNl5pCS7lNXmFpVjUE7rg X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 Aug 2026 11:13:58 -0400 (EDT) Date: Wed, 19 Aug 2026 16:13:57 +0100 From: Kiryl Shutsemau To: Usama Arif Cc: Andrew Morton , david@kernel.org, chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com, linux-mm@kvack.org, ying.huang@linux.alibaba.com, Baoquan He , willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, Nico Pache , "Liam R. Howlett" , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, yosry@kernel.org, kernel-team@meta.com Subject: Re: [PATCH v6 03/12] mm: add PMD swap entry splitting support Message-ID: References: <20260818131202.494754-1-usama.arif@linux.dev> <20260818131202.494754-4-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260818131202.494754-4-usama.arif@linux.dev> On Tue, Aug 18, 2026 at 06:09:44AM -0700, Usama Arif wrote: > Add a swap branch in __split_huge_pmd_locked() that splits a PMD swap > entry into 512 PTE swap entries. No folio reference is needed because > swap entries point to swap slots rather than pages. Each PTE inherits > the correct sub-slot offset and preserves soft_dirty, uffd_wp, and > exclusive flags. > > The folio_remove_rmap_pmd() gate at the end must inspect old_pmd > rather than *pmd: for a present THP split, *pmd has already been > cleared by pmdp_invalidate(), and that invalidated bit pattern can > decode as a plausible swap entry. Hm. On x86, pmd_present() recognises !_PAGE_PRESENT | _PAGE_PSE PMDs as present. Other archs do similar thing. pmdp_invalidate() clears present bit, but keeps PSE around, so it is present from SW PoV. pmd_is_migration_entry() should work correctly on pmdp_invalidate()ed entries. > This branch is reached from the explicit __split_huge_pmd() callers > that hit a non-present PMD: partial-range mprotect / munmap, the > wp_huge_pmd() PMD-COW fallback, and the swap-in / swapoff fallbacks > added in later patches when the cached folio is no longer PMD-sized. > page_vma_mapped_walk() does not iterate PMD swap entries, so > try_to_unmap_one() and try_to_migrate_one() do not reach this branch > and freeze=true cannot occur in this branch today. page and folio > are therefore left uninitialized in the swap branch; a > VM_WARN_ON_ONCE(freeze) catches any future caller that breaks this > invariant before the freeze path dereferences page_to_pfn(page + i) > or put_page(page). > > Signed-off-by: Usama Arif > --- > mm/huge_memory.c | 29 ++++++++++++++++++++++++++++- > 1 file changed, 28 insertions(+), 1 deletion(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 1b6b0aa2baa3b..a473e85d30f51 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3252,6 +3252,14 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, > folio_add_anon_rmap_ptes(folio, page, HPAGE_PMD_NR, > vma, haddr, rmap_flags); > } > + } else if (pmd_is_swap_entry(*pmd)) { > + VM_WARN_ON_ONCE(freeze); > + /* Swap entries have no page for the migration freeze path. */ > + freeze = false; > + old_pmd = *pmd; PTL protects us from value drifting under us if compiler decides to load it multiple times, right? Same pattern as the migration/device-private branches above, so not a new concern, just checking. BTW, do we want VM_WARN_ON_ONCE(pmd_is_swap_entry(old_pmd)) in !vma_is_anonymous() branch to avoid surprises? -- Kiryl Shutsemau / Kirill A. Shutemov