From nobody Mon Apr 13 21:01:10 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 2F10A372667 for ; Wed, 4 Mar 2026 12:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772625724; cv=none; b=D21mYKrEdLsWByYFzbzvEWpUKyx2ee8vZQJ1lpvHm3gso3gsnU1qQePX1vpQMw/6h583f2xLf2kHn/AHhgTg91+y/hY5PY9Iqzxw7VdBuf98wyFJcJL2K4bcLkua8ROssoIvWXqkPP+AVrQ9soZYS2uDDNqQpd17w6ttGa8MVbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772625724; c=relaxed/simple; bh=1MwtitaERsbRHnrWKmPPALwYmraE5wkeLPXhpD9ozyE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MI7B4yUCijjLH9baeViBjU5/RGEZQHQgCmT1lA1xZLJpIZqnHPFoqP2nEhCerip2VrcdyCz/hfHHQAXnQCdTm7ydNTBo34Y+dku57+RkXGZEIBhcsV9sJVCLK/vlnfS7ZOzAY2x0zw0FjSmICAFQ1ytV2isTxM08s+y9EEZLTqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif To: Andrew Morton , npache@redhat.com, david@kernel.org, ziy@nvidia.com, linux-mm@kvack.org Cc: matthew.brost@intel.com, joshua.hahnjy@gmail.com, hannes@cmpxchg.org, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, riel@surriel.com, shakeel.butt@linux.dev, kas@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH] mm/migrate_device: fix folio refcount leak on folio_split_unmapped failure Date: Wed, 4 Mar 2026 04:01:32 -0800 Message-ID: <20260304120132.3973445-1-usamaarif642@gmail.com> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Usama Arif migrate_vma_split_unmapped_folio() takes an extra reference via folio_get() before calling folio_split_unmapped(). On success, the split consumes this reference: __folio_freeze_and_split_unmapped() expects the +1 in its folio_ref_freeze() check, and distributes it across the resulting sub-folios via folio_ref_unfreeze(...+1), which are later balanced by folio_put() calls in __migrate_device_finalize(). If folio_split_unmapped() fails (e.g., unexpected pinning returns -EAGAIN), the function returns without calling folio_put(). The extra reference is never released. Add the missing folio_put() on the error path. Fixes: 4265d67e405a4 ("mm/migrate_device: add THP splitting during migratio= n") Closes: https://lore.kernel.org/all/CAA1CXcDyqPPwf_-W7B+PFQtL8HdoJGCEqVsVxq= 7DhOUB=3DL4PQA@mail.gmail.com/ Reported-by: Nico Pache Signed-off-by: Usama Arif Acked-by: Balbir Singh Reviewed-by: Joshua Hahn --- mm/migrate_device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 0a8b31939640f..351ecd9065d13 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -917,8 +917,10 @@ static int migrate_vma_split_unmapped_folio(struct mig= rate_vma *migrate, folio_get(folio); split_huge_pmd_address(migrate->vma, addr, true); ret =3D folio_split_unmapped(folio, 0); - if (ret) + if (ret) { + folio_put(folio); return ret; + } migrate->src[idx] &=3D ~MIGRATE_PFN_COMPOUND; flags =3D migrate->src[idx] & ((1UL << MIGRATE_PFN_SHIFT) - 1); pfn =3D migrate->src[idx] >> MIGRATE_PFN_SHIFT; --=20 2.47.3