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 D0E273EC2D1 for ; Tue, 19 May 2026 22:00:11 +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=1779228013; cv=none; b=UM6uVhr/3Q6lGW0gObZ49kieRwQWYXtYTcR4xtTicXxrbd0gAciCuPcm9hYxO7eu1tPd/Ueyaat01bk0KkHvGyM79ewHcIXztP2YIZHcKjz0nRbn3CzRcTcdjmbX5FWLmitk/w5Sl/yewwshZkHrKMGy4n5InnXB1pkZm/BH70I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779228013; c=relaxed/simple; bh=T7+2olcVTpv1PEWchFLnOI50G4ghyNIaoum5GYmLUf4=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=pmF44TxEvyQb5pkAxPHWOzsu5oHXaYPdwFxzlN4OLT4fcVtMxhDJ28wy3PeLdPmw5/wnB7vHRxZFsidiZUM+jvGi3LPdyDzlpUp56RorlXK2IQS/nrdlEycIHKlpeIuUXANxNRwn0aBvX0RaoU3ZB46qvsqm8fg4Csy5eJw+Gkg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=IfMl/NWN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="IfMl/NWN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCDFB1F00893; Tue, 19 May 2026 22:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1779228011; bh=GnGwuiYlVJlBXNtcIqK4KbKEb2r6ker+wowDhgc6gnA=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=IfMl/NWNFt1b1HQUzivum+2BhsMi/hbKSotMR6HUnqUIgTpccTixvjpyqhu9Aa8Mg UU23C4UYmod2eGcw49FL/HN0QKDQuA18YhjA00j5AAVCA0kbzk6bSYZwa+dFIerwya 0HYc7kI/lgvIYw6kvLuUHiOp1Q/FX/8UBpHRR8Yo= Date: Tue, 19 May 2026 15:00:10 -0700 From: Andrew Morton To: Balbir Singh Cc: Sunny Patel , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm/migrate_device: fix pgtable leak in migrate_vma_insert_huge_pmd_page Message-Id: <20260519150010.a1cb46f2c8478414117d6932@linux-foundation.org> In-Reply-To: <4c3eb1b4-1ea6-46ea-b04d-b218ef266c7f@nvidia.com> References: <20260501115122.23288-1-nueralspacetech@gmail.com> <20260501054416.af0ed62d635c3eb01d425e61@linux-foundation.org> <5b25ef69-ffd1-49f3-a340-db70dcc96b29@nvidia.com> <4c3eb1b4-1ea6-46ea-b04d-b218ef266c7f@nvidia.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Sat, 2 May 2026 10:59:33 +1000 Balbir Singh wrote: > > > > The issue can be reached if we try to migrate a non private/coherent folio (I assume DAX/P2PDMA) > > pages. Even migrate_vma_insert_page() has a similar pattern. Creating the pud/pmd/pte structure > > there is unnecessary (but not allocations occur, depends on pmd_none() for example), do we want > > to clean up all of it (need to think through)? > > > > I'll re-review and send fixes as needed. Looks like David sent some fixes out, will review > > those as well. > > > > I checked migrate_vma_insert_page() is no affected. > Thanks. What to do here. We have a cc:stable hotfix which is adequately tested and seems to have passed review. And a cleanup patch from David. I'm inclined to upstream this patch as-is and leave the cleanup on David's TODO list (one more can't make any difference ;)) ? From: Sunny Patel Subject: mm/migrate_device: fix pgtable leak in migrate_vma_insert_huge_pmd_page Date: Fri, 1 May 2026 17:21:16 +0530 When migrate_vma_insert_huge_pmd_page() jumps to unlock_abort due to a PMD check failure, the pgtable allocated earlier via pte_alloc_one() is never freed, causing a memory leak. Added free_abort label to release the pgtable in error path. Link: https://lore.kernel.org/20260501115122.23288-1-nueralspacetech@gmail.com Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages") Signed-off-by: Sunny Patel Acked-by: David Hildenbrand (Arm) Reviewed-by: Huang Ying Cc: Alistair Popple Cc: Balbir Singh Cc: Byungchul Park Cc: Gregory Price Cc: Joshua Hahn Cc: Matthew Brost Cc: Rakie Kim Cc: Zi Yan Cc: Signed-off-by: Andrew Morton --- mm/migrate_device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/mm/migrate_device.c~mm-migrate_device-fix-pgtable-leak-in-migrate_vma_insert_huge_pmd_page +++ a/mm/migrate_device.c @@ -840,7 +840,7 @@ static int migrate_vma_insert_huge_pmd_p } else { if (folio_is_zone_device(folio) && !folio_is_device_coherent(folio)) { - goto abort; + goto free_abort; } entry = folio_mk_pmd(folio, vma->vm_page_prot); if (vma->vm_flags & VM_WRITE) @@ -893,6 +893,8 @@ static int migrate_vma_insert_huge_pmd_p unlock_abort: spin_unlock(ptl); +free_abort: + pte_free(vma->vm_mm, pgtable); abort: for (i = 0; i < HPAGE_PMD_NR; i++) src[i] &= ~MIGRATE_PFN_MIGRATE; _