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=1796298257; b=Q2Dbv3l3zbLJ4fS8WozlnBDimt8IeZ78fGcXqALbBG3BAoTaopnQMWCy1hIl5kBC/LP5 xr7YI96kO0w0KXBT5vRnUItyfN7DyT2qCBUf4I4rHb0X9XaJiP2vr6swKwMql7f0O4exG kW75NkH3076uTpu+DDQYi0KZXhG3Q4RvgH4cpS2HQO3DMzXgZMwuWNqsCSKkq4jsaM9/d +V0V+mVo8w4NI3jbKsJn0GxyYz1Mi9dtmtJXW8NM6wUbLpEiaUFZAf4fdWEu9QJgnokdv Raki0PRMrTuFB1Erf6TiS7McjSJZL28co32WnxDIIGvNsH0G0IEmgZaZ0tc7IkdzvTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298257; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=KpYYMGqWhu5m+KzZjD0k5grcGksSIdfBaxK2fkkc+Jk=; b=ChvK8RIt71vf56IWt4MUtmxBqSY04l9r6YPNokxJpDXllTCT1mZwpf5B3yzJyz/zcAR3 7FGziPOfsyvUBd39KpIgajXgQ93ys0ncisaFYOVfGfrHnl426Ah74Ze/QRMKOPBoiATxL FzCZgxhhbWwJ5SgNodT9Kh/XGWIBWYPA2uVb77MIm+vZm7Zlx9RlfIKtsdybUbnfZ3Zeh VHiQmTShuyyYzEuvnN4EUFe82SKlJkcXO3fD2YUMtqT1mOiCm2B/cqYhr8Jjn8U5TfIp6 F4MvAErOmB7OaFcj46yUuZBfucZUw2bHDebSwXNwggCsA4Wyxr0trKkMBjdshxLPYuQ== 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=mXMkVfan; 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 BBF05606A322; Thu, 3 Dec 2026 11:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mXMkVfan Received: by smtp.kernel.org (Postfix) with ESMTPSA id C86901F00899; Thu, 3 Dec 2026 11:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298257; bh=KpYYMGqWhu5m+KzZjD0k5grcGksSIdfBaxK2fkkc+Jk=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=mXMkVfanluetOM/ROHbTFnOvgN/Mu8b+UwIP1zKWo28lPFAk56mrC7Ac0wmbtB4fQ vm5tk9YUVvEv3hpoc1sLDfvWfLNDN7DdLvdMixCDH74P+8QLHIfO+hd2sOspX+Tsej 2eHslkORft5CTbSEJ5ipBgVF6mIXjFk0Vnao5YMrqhzHj6fT8PG345o0KUkySackNc 6DjbOiR3bjm3bvS84qwW6BknPwn+Rzy2T5nFssZzExpgsQliyGxbdJsA1HkingLGdw KdFdsxM3IRtcteTIfdrGQ2QXkX7d3P8dMHNONMrx40fp27kLgWdehBEoDh+asrowld RXP7fYiLk9t8A== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:49 +0100 Subject: [PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs X-Mailing-List: linux-doc@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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-26-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> To: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , stable@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2313; i=david@kernel.org; h=from:subject:message-id; bh=YYMmr/IFx5H73tD97eq8uuIPhtb+qUjJqmr53PoMfOk=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ2r+daZUbueL+SQXsDJFVOfVNluGPI/9lbuEHxqEb OxZPOtJRykLgxgHg6yYIktQ8H2Dly/X1Va78THDzGFlAhnCwMUpABO5/57hn1pGts+nqdzuVg/f W4f51jwU5Wlo3NIUNEVEKrwpzG6bPiPDZLPwv+K8QiLrMpnmcvxXrbY4aTpnMu/kgoccxXxV+Sd 4AQ== X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Before unmapping a hugetlb page cache folio, try_to_migrate_one() and try_to_unmap_poisoned_hugetlb_one() try to unshare the PMD table, which requires the hugetlb VMA lock in write mode. As we already hold the i_mmap_rwsem, we can only trylock it, and give up if that fails. Since private hugetlb VMAs have a VMA lock as well, the trylock can also fail on private VMAs, for example while another thread is faulting in that VMA. PMD table sharing does not apply in private VMAs, so there is nothing to unshare and we fail for no reason: migration fails more often, and memory failure might leave a poisoned folio mapped. Let's fix it by only taking the VMA lock and trying to unshare if PMD tables can be shared. Fortunately, we can drop the anon folio checks now. This has low urgency, as it requires racing with, for example, a page fault in the private VMA, and migration is usually retried. Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs") Cc: stable@vger.kernel.org Signed-off-by: David Hildenbrand (Arm) --- mm/rmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 4193793158bc1..b85ab855a438a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2049,7 +2049,7 @@ static bool try_to_unmap_poisoned_hugetlb_one(struct folio *folio, * acquiring vma_lock BEFORE i_mmap_rwsem. We can only try lock here and * fail if unsuccessful. */ - if (!folio_test_anon(folio)) { + if (__vma_shareable_lock(vma)) { struct mmu_gather tlb; VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED)); @@ -2580,8 +2580,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, PageAnonExclusive(subpage); if (folio_test_hugetlb(folio)) { - bool anon = folio_test_anon(folio); - /* * huge_pmd_unshare may unmap an entire PMD page. * There is no way of knowing exactly which PMDs may @@ -2601,7 +2599,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, * i_mmap_rwsem. We can only try lock here and * fail if unsuccessful. */ - if (!anon) { + if (__vma_shareable_lock(vma)) { struct mmu_gather tlb; VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); -- 2.56.1