From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.202 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795451593; b=fVWN3bkLn2Fuqn+ui6nrGi1sQUN7yhU+4UoSgrrbODouRpRq+VJ6mFUbw1/hxj7VH15w TVIz+pMxE07gInk86elbRsGA2L67d69zCJau1hcS14tPgKLkYXz86YJyTWmNHOOouG+PZ YCC++BbfssGmFx4QKRgkUDzh5q5QbPy1pio7ExGtT78vD2s0jyniA80TB/ZfBCqAtRfRo m5FefGlbJgMOOUhzKup1z2+79tWW8+kBCr1kpMYBTFHwK08cFknBB3u3BE1rLwTjNO395 whFqy6p+PMY4yW6KICNDRzTQGPM2e6jK0z6zcU5owpjsOoXEocn+8GfD5lGoMEnGjpQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795451593; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=fwWiH4TsPLewrmvX2AV6vJSDmcGS5DTBi3bpUFUWZos=; b=I/Gflds6/nE6HMbXbMo0HAVYwUT7klWx1j8t2pxGLR8tTDHTq44aQgWFvjBPSPpalUXe Q5Fg/C9NM1aP6L1dAoCYBtszKfq9+rANBiDhZaDKuqolfcDF7uI/OLlSQdXNt+jFOeaBP gspzaLRdf8hDxEWqjATGxFPp+GpULVF88gWSec/1IqEDJwNXv+NWy8QylHNf4brRms8dH grYUBKpuZsuLafGLt9iXjPTBtrgxL+r1FFGg2jN2TRArzOQhS4hIt42bnidn/W2gEnvW1 /ws9yq21Kfd0a4SUlfv2B2M0BL+uBDPyk6hzs5tsHQzjCYFOISx6/T/5vFqc/aXmz8A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="Py/+/lA1"; arc=none smtp.remote-ip=91.218.175.202 Received: from mta0.migadu.com (out-202.mta0.migadu.com [91.218.175.202]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A5D8606A334 for ; Mon, 23 Nov 2026 16:33:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2A5D8606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Py/+/lA1 X-Envelope-To: stable@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=jZKaGu0pxutsSN80ekzFiD3bJEXetF6Gf5LZ+jjPkrg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795451591; v=1; x=1796056391; b=Py/+/lA1zyJVVJiczuM15viS6Njs8KdAidXAs6is5IgCTM0N59Sk5fBfv/s3yoFz5DrzhkRc WgQuNx3/CvFfOSvWO5i65B2sauxgZeqYgPjKeahIJwUtWei4Vf7eKgTwTIz+RiQkNSlq3U7zNhs 6cvrsp+Zcy0ZbMvaeW7FUuZw= X-Envelope-To: stable@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id 9be87c2e82eba38f; Mon, 23 Nov 2026 16:33:10 +0000 X-Mizu-Trace-ID: 9be87c2e82eba38f X-Migadu-Flow: FLOW_OUT From: Usama Arif To: Andrew Morton , apopple@nvidia.com, byungchul@sk.com, david@kernel.org, gourry@gourry.net, jannh@google.com, joshua.hahnjy@gmail.com, liam@infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, matthew.brost@intel.com, mhocko@suse.com, pfalcato@suse.de, rppt@kernel.org, surenb@google.com, vbabka@kernel.org, ying.huang@linux.alibaba.com, ziy@nvidia.com, kas@kernel.org, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, kernel-team@meta.com, baolin.wang@linux.alibaba.com, Nico Pache , ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev Cc: Usama Arif , stable@vger.kernel.org Subject: [PATCH v3 1/5] mm/migrate_device: avoid leaking folio references during THP splitting Date: Mon, 23 Nov 2026 08:32:07 -0800 Message-ID: <20261123163301.1568240-2-usama.arif@linux.dev> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261123163301.1568240-1-usama.arif@linux.dev> References: <20261123163301.1568240-1-usama.arif@linux.dev> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit migrate_vma_split_unmapped_folio() takes an extra folio reference because split_huge_pmd_address(..., true) drops one when it splits a PMD. However, migrate_vma only holds mmap_lock for reading. A concurrent MADV_DONTNEED can clear the migration PMD, or split it into PTE migration entries, before the split helper takes the PMD lock. The helper then does nothing and leaves the extra reference behind. folio_split_unmapped() fails with -EAGAIN due to the unexpected reference, and the reference is never dropped, so the source THP is leaked. If a THP is faulted in at the same address inside that window it is worse: freeze = true replaces the new folio's mappings with migration entries that nothing will ever remove, and drops a reference the caller never took. An existing migration PMD is expanded into PTE migration entries even with freeze = false. Use that mode and remove the extra folio_get(). The reference already held by migration keeps the source folio alive whether or not its PMD migration entry still exists. Reported-by: Zi Yan Closes: https://lore.kernel.org/all/DLZ48KMS7YG8.3BTM0UUU8CTU2@nvidia.com/ Fixes: 4265d67e405a ("mm/migrate_device: add THP splitting during migration") Cc: stable@vger.kernel.org Signed-off-by: Usama Arif Reviewed-by: David Hildenbrand (Arm) Reviewed-by: Zi Yan Reviewed-by: Kiryl Shutsemau (Meta) --- mm/migrate_device.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 9e19fadfa65c67..3286bb8a4b73ee 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -920,12 +920,7 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate, unsigned long flags; int ret = 0; - /* - * take a reference, since split_huge_pmd_address() with freeze = true - * drops a reference at the end. - */ - folio_get(folio); - split_huge_pmd_address(migrate->vma, addr, true); + split_huge_pmd_address(migrate->vma, addr, false); ret = folio_split_unmapped(folio, 0); if (ret) return ret; -- 2.53.1-Meta