From nobody Sat Apr 4 04:48:19 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C9EFC3E0235 for ; Fri, 20 Mar 2026 18:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774030067; cv=none; b=FR6herZhd9quEfa9t5PB6PMeDYx1/iOrFvfvdNrYTgbCcM9ZRu9FRX8TWqAchkTGf7bCv3/QOJ0jWHtasrYgbW8DH0HvxY7NvQzpCOAxDoxnQ+48y6wcx6JlA/czQnl140ZonTZqejMfH4dob/5+oJZKhuGJ7bSRNTi1ob+mSis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774030067; c=relaxed/simple; bh=fI1DXKEqfJaz8wCKY4bKhT28MvXJUmPPDBUHofI9UvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NePlDe0X0Yw1SBwaQSncXaDAdmEBc2jgDf9q4mqsUDomzgDcR+3Aso2+EWprO8U7UBOJMWHj4NaudccOWs6lFWaSquzjpJRVVyiTz6xMOSZ5tQlsrnYPF/RZ5UC3jeYzD/2FvC/IOjyCUBWWcL5dQpi6vNwvBixcBYew76HCXc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=awXrgR7a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="awXrgR7a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E64E3C2BCAF; Fri, 20 Mar 2026 18:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774030067; bh=fI1DXKEqfJaz8wCKY4bKhT28MvXJUmPPDBUHofI9UvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=awXrgR7a4UDCSAsSaSsKba7axf1o1Sg7jj30LbzIxY72sjLdrgXkGIjnf847MV5Ng zx6ITshDDS5/YBfSTa50y/7DfdmMur1WeCxqDRBNOMvPBJQbUOQZ1qX0pbz9o0CoN0 DLiNudkoRFSeIlD0mZikAL64hN3qlZGPcwb/PF4+NcVYh0B88FGJ2QjSPWEljCm6iw e1+l7o4seDZ1x/vF/TSoTDdAop0lSZbyG1U1COgzVLC8hcHsIpnKOkzMid7cp/Hqtm VAAZcdsFcke/J5UKZ8HlgptNQ+Pzqeh1s+1XKiotfNPxFSTP7EM+DMu9i0Fa6c4zEk PxcDkaH/vloyQ== From: "Lorenzo Stoakes (Oracle)" To: Andrew Morton Cc: David Hildenbrand , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kiryl Shutsemau , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 05/13] mm/huge_memory: add a common exit path to zap_huge_pmd() Date: Fri, 20 Mar 2026 18:07:22 +0000 Message-ID: <6b281d8ed972dff0e89bdcbdd810c96c7ae8c9dc.1774029655.git.ljs@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Other than when we acquire the PTL, we always need to unlock the PTL, and optionally need to flush on exit. The code is currently very duplicated in this respect, so default flush_needed to false, set it true in the case in which it's required, then share the same logic for all exit paths. This also makes flush_needed make more sense as a function-scope value (we don't need to flush for the PFN map/mixed map, zero huge, error cases for instance). Reviewed-by: Baolin Wang Signed-off-by: Lorenzo Stoakes (Oracle) Reviewed-by: Suren Baghdasaryan --- mm/huge_memory.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0056ac27ec9a..b9d9acfef147 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2338,7 +2338,7 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_a= rea_struct *vma, pmd_t *pmd, unsigned long addr) { struct folio *folio =3D NULL; - bool flush_needed =3D true; + bool flush_needed =3D false; spinlock_t *ptl; pmd_t orig_pmd; =20 @@ -2360,19 +2360,18 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm= _area_struct *vma, if (vma_is_special_huge(vma)) { if (arch_needs_pgtable_deposit()) zap_deposited_table(tlb->mm, pmd); - spin_unlock(ptl); - return true; + goto out; } if (is_huge_zero_pmd(orig_pmd)) { if (!vma_is_dax(vma) || arch_needs_pgtable_deposit()) zap_deposited_table(tlb->mm, pmd); - spin_unlock(ptl); - return true; + goto out; } =20 if (pmd_present(orig_pmd)) { struct page *page =3D pmd_page(orig_pmd); =20 + flush_needed =3D true; folio =3D page_folio(page); folio_remove_rmap_pmd(folio, page, vma); WARN_ON_ONCE(folio_mapcount(folio) < 0); @@ -2381,14 +2380,12 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm= _area_struct *vma, const softleaf_t entry =3D softleaf_from_pmd(orig_pmd); =20 folio =3D softleaf_to_folio(entry); - flush_needed =3D false; =20 if (!thp_migration_supported()) WARN_ONCE(1, "Non present huge pmd without pmd migration enabled!"); } else { WARN_ON_ONCE(true); - spin_unlock(ptl); - return true; + goto out; } =20 if (folio_test_anon(folio)) { @@ -2415,10 +2412,10 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm= _area_struct *vma, folio_put(folio); } =20 +out: spin_unlock(ptl); if (flush_needed) tlb_remove_page_size(tlb, &folio->page, HPAGE_PMD_SIZE); - return true; } =20 --=20 2.53.0