From nobody Mon Apr 6 18:22:53 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 66E6B343216 for ; Wed, 18 Mar 2026 20:40:13 +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=1773866413; cv=none; b=lSR9vZBIn9WSj+yjRQxI6805aYyyZOR2ckVbUU5f570x2MiZ+EqkNy7WM+SgT7NgDrpCyVTygT+cMuzI8cBE9osVqb7KG3PiZAhpIcg0+F5BCoEu79aYIZWr59VCLMBpyyemFeiEI5swt8lBJzFP6HYybejkJk8rafPYdqbl7Eo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773866413; c=relaxed/simple; bh=PITG7FjF940ShIQWg3bTh2lmckgtj7Y/LuersIz6UxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDjXm73kC4oXgW7Ijg0EXqpV5hrg+YyiRxBpYMMH764W+IhvCDpmdP3UcsiPmQfHqxdV/oCmKsGoQUPem0DPVIS+umBiWXFkDz95f6sZqvM+LAIKr5iAABgKdE9aHCATMoQk+0HBBGDvwV3E56AZcmw/2w10yImsdr28Tw2m3u4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OdvEiXHC; 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="OdvEiXHC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87D6DC19424; Wed, 18 Mar 2026 20:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773866413; bh=PITG7FjF940ShIQWg3bTh2lmckgtj7Y/LuersIz6UxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OdvEiXHCpeAbqal9LePZD/KHjW3xBrUm7WV0dIIJQr2KHDb3x/ltFr/AuEnIk2paw wWs3EG2ql2D4SXuru/wxiChjn9zjb15QQsXtyZd5RhebbR0QnuIwxdd+ay4ZeggAOZ Z5Lr15mPo/gj7zSTKc4lfSuIdCLYGFuYJUxAlLGtBxBuO/MVGE1+n7cQDQy2VuqQIL xrUOv5aQRhpvjNwjhLxW2+IagPnKUJAmB70c8wSjPy18bHhvdTWX1N+912BbMXCTie EqXMRYupVviG4B2gFzp8wzi47A1F1WH9UudPsq8jHspuEgLAIfgc6BY5906b+UR5sE aNu/8gElozfFw== 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 , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] mm/huge_memory: add a common exit path to zap_huge_pmd() Date: Wed, 18 Mar 2026 20:39:27 +0000 Message-ID: <3d8ec0634fc3465b200ca678fe097097cf6ad1bc.1773865827.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). Signed-off-by: Lorenzo Stoakes (Oracle) --- mm/huge_memory.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8e6b7ba11448..724e1de74367 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2431,7 +2431,8 @@ 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; + bool ret =3D true; spinlock_t *ptl; pmd_t orig_pmd; =20 @@ -2453,19 +2454,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); @@ -2474,14 +2474,13 @@ 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 false; + ret =3D false; + goto out; } =20 if (folio_test_anon(folio)) { @@ -2508,11 +2507,11 @@ 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; + return ret; } =20 #ifndef pmd_move_must_withdraw --=20 2.53.0