From nobody Thu Apr 9 17:07:58 2026 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 54FBC34750D for ; Fri, 6 Mar 2026 10:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772793872; cv=none; b=r9tbB4TPZ8jL+Nl1YWcExz8cqfwg9ZC+gzesjA9pkYsNIl7bBIVl6PLZXGUcw+c1ZzwYPsjIh769Yn68COPuq2Lf6mQJQEPUmKt2Hhe0nEHBjfy5UbM9WkD4JDPTREAGSXXjCDnP9whisFpmB/4tPhUJPv7AUZvs6pA53RwCju0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772793872; c=relaxed/simple; bh=E2hZoxvh0SEy/viB8y4uD1UeEnc3Kphpy6T7N87kHxc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FNiU4qisFHzr8tkhh2p3BZZabGMn5uTOJ7sm4ZYkNAZGkj2BVtiBZK1cuO00tlzW7PxYnF1fPcceOWfxS9Ec0Qxe1OiIGNGRJcJ8HL3tWnyj2WMmnlDwZQN/9XpXPZ3uTbjr4e4JeyBJebXhg1fiuAGR/80ouTuwaOSfSn6s6gc= 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=c+UJ2XDd; arc=none smtp.client-ip=95.215.58.188 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="c+UJ2XDd" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772793867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OPkOlmZaIM4hn1GJiU7CIu0V9mRULm8+LVW3w/1ow4U=; b=c+UJ2XDdi4k+VS0R8giqACqN1oD/vn6D1u0lCqF7odDR/jh8q8v2m75CwemTGM4Uzqb7p9 n0kRFzf38ovvKPs3/XByos86icCRt1D5t4pumXN8u5r9A568CEEjXOYutLEDg//TsUH9dL ntHmSX5D5o9PuLDqwUMFm4zuPvaDm6I= From: Usama Arif To: Andrew Morton , npache@redhat.com, david@kernel.org, ziy@nvidia.com, linux-mm@kvack.org, mpenttil@redhat.com, balbirs@nvidia.com 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: document folio_get requirement before frozen PMD split Date: Fri, 6 Mar 2026 02:44:09 -0800 Message-ID: <20260306104409.3915811-1-usama.arif@linux.dev> 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" split_huge_pmd_address() with freeze=3Dtrue splits a PMD migration entry into PTE migration entries, consuming one folio reference in the process. The folio_get() before it provides this reference. Add a comment explaining this relationship and a VM_WARN_ON_ONCE to catch an unexpected refcount !=3D 1 entry state. Suggested-by: Zi Yan Signed-off-by: Usama Arif Reviewed-by: Nico Pache Reviewed-by: Zi Yan --- mm/migrate_device.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 78c7acf024615..6fa2878848a7e 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -908,6 +908,11 @@ static int migrate_vma_split_unmapped_folio(struct mig= rate_vma *migrate, unsigned long flags; int ret =3D 0; =20 + VM_WARN_ON_ONCE(folio_ref_count(folio) !=3D 1); + /* + * take a reference, since split_huge_pmd_address() with freeze =3D true + * drops a reference at the end. + */ folio_get(folio); split_huge_pmd_address(migrate->vma, addr, true); ret =3D folio_split_unmapped(folio, 0); --=20 2.47.3