From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (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 A52EE344D86 for ; Fri, 6 Mar 2026 10:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772794069; cv=none; b=brm/RFpeLh+X9e1wCDhxRns9ZGZSokGlpYQRAR2aDFhg95VS3N0YNl6ow+9GtAwAED6HyeJOWycXZICJiB0fMqMNbX87HjeXWSc9NdugBN1g3BEaZSv7V8dFcspxHTaU0QmORmIopKTk9DHxMTIhwH0hlLSPha9rtm4WrW8HFR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772794069; c=relaxed/simple; bh=QffQ7rKwaehB+yYn4NjqlFFVOX/0N9S2Lsw3S1Ji5hM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hcug7SqbyewjnpfgXls0kM7760CP6n0KZ3xF8JjGrL9hCy+D5APAG4QySj/HRHLDjtZqi+8u2n18h/XmwmcuE795pR2XPSnR/YUIHZA5uet7khZx7dQQHU9FTq00JGXmabbnENcEnerqvl1nPQeB1bG0D4E4Rx3jHZay7ccj4Ok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NOfHMeXp; arc=none smtp.client-ip=95.215.58.183 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) header.d=linux.dev header.i=@linux.dev header.b="NOfHMeXp" Message-ID: <3dd4399f-a138-4ec0-b3a8-0ce200423ebe@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772794065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tjPP1MkY7cVIKE6dM0lngCXvsWMfl9x5zuCWaBUpV24=; b=NOfHMeXpi6Cr3mGYireNzPc4UXDrWxm689oejv2P7DpZe+niwQ5cKFZE8SCUo/wX3HR8w5 tZ/95TAThil5pEgo2sRPydEcoEMBDApYOgLMl1L44qQnR4nMQ3QDhEcdqIoKnQRa2iskft E9KTe9lhlr6eUH37SMjT6k5fL1LIIFk= Date: Fri, 6 Mar 2026 13:47:35 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/migrate_device: fix folio refcount leak on folio_split_unmapped failure Content-Language: en-GB To: Zi Yan Cc: =?UTF-8?Q?Mika_Penttil=C3=A4?= , Balbir Singh , Kiryl Shutsemau , matthew.brost@intel.com, npache@redhat.com, david@kernel.org, Usama Arif , Andrew Morton , linux-mm@kvack.org, 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, linux-kernel@vger.kernel.org, kernel-team@meta.com References: <20260304120132.3973445-1-usamaarif642@gmail.com> <5e59c077-9f06-4e45-86e1-ca696e6105b4@nvidia.com> <622eb392-8c04-473d-b42a-ecdc489799c4@linux.dev> <942f2df4-6fb5-415f-b7d4-87a83315890b@redhat.com> <80683d6d-ea38-4326-af5e-e4c173bb1930@redhat.com> <332c9e16-46c3-4e1c-898e-2cb0a87ba1fc@linux.dev> <7996d5c5-24db-4ef2-b88a-1b9d33f9e976@linux.dev> <1EAE2E58-7A71-4B59-B1EF-3A3C753DDC1E@nvidia.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: <1EAE2E58-7A71-4B59-B1EF-3A3C753DDC1E@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT > > I do not think there is a need to explain why there is no folio_put() > below. How about below? > > 1. it makes sure the folio has the right ref count, > 2. it explains folio_get() is for split_huge_pmd_address() instead of > folio_split_unmapped(). > > diff --git a/mm/migrate_device.c b/mm/migrate_device.c > index 0a8b31939640f..0b31b878210ba 100644 > --- a/mm/migrate_device.c > +++ b/mm/migrate_device.c > @@ -914,8 +914,14 @@ static int migrate_vma_split_unmapped_folio(struct migrate_vma *migrate, > unsigned long flags; > int ret = 0; > > + VM_WARN_ON_ONCE(folio_ref_count(folio) == 1); Thanks! I have sent it in [1]. One thing is, I think you mean over here folio_ref_count(folio) != 1, right? Thats what the patch has. [1] https://lore.kernel.org/all/20260306104409.3915811-1-usama.arif@linux.dev/ > + /* > + * 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); > + > ret = folio_split_unmapped(folio, 0); > if (ret) > return ret; > > >> >>>> >>>> >>>> [1] https://gist.github.com/uarif1/65e1e816af7aa0ae38dd6ec64d62a993 >>>> [2] https://gist.github.com/uarif1/79ea9500667daa4e2ef09cb5d308f041 >>>> [3] https://gist.github.com/uarif1/8a35a6c65ba8b3a1c1dfe72dc30e821d >>> >>> >>> Best Regards, >>> Yan, Zi > > > Best Regards, > Yan, Zi