From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 A5BE2175A79 for ; Thu, 2 Jul 2026 04:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782967520; cv=none; b=tYzRY+1wGRy6GjBWJ+8veGy71yqvHzj06TZxXLThgOeR3VbKPbX8c/8aje7W4JTpw5g+EJTHqGzZ0QEkUWV3ybUuZtthSyl85HhLqXXtFnz81q+zMh6MaHwrpLN4CzPtcwUQSJhOURccFD1tWiTYwjNmwK+JUbxxQa4CaXvVwfY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782967520; c=relaxed/simple; bh=xIBMiepbyHQfcLd9CfLtfNdW0pHGT6gAAhx21hh38HA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=S9CYZWERuSpSOFikizQAfqNLJ6cQx4RwM65tI6wES5lCKD3I3RiUHOnjYaZtyqr6bRGFTweRXq7koMmpKY53skQt7hVFguHl9UN903S//Rn+5Tr3hTuc8EE3N3t8WlH1BfzETFIb+XPIw/Z1SRhURySskDV2kXyCyokN43mz+gU= 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=weW0BPcn; arc=none smtp.client-ip=91.218.175.170 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="weW0BPcn" 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=1782967515; 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=xIBMiepbyHQfcLd9CfLtfNdW0pHGT6gAAhx21hh38HA=; b=weW0BPcnO1ev+IyK6zUUlig1b9Pj9X0H6ekkMNkZiNSRVEHF953xBiUorA2xyFneSf7Q8E Rw0iPPxnrvdyzX1wHZEhJRM1e23/g7V93QF1wOUklexl2becpCjPYYOSHdEa5dqmmjGwyK EgkjoM6sVa5sZ0i0NSk5wQumTPrNs3U= From: Lance Yang To: usama.arif@linux.dev Cc: akpm@linux-foundation.org, apopple@nvidia.com, byungchul@sk.com, david@kernel.org, gourry@gourry.net, joshua.hahnjy@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, matthew.brost@intel.com, rakie.kim@sk.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, shakeel.butt@linux.dev, hannes@cmpxchg.org, kernel-team@meta.com, sashiko-bot@kernel.org, Lance Yang Subject: Re: [PATCH] mm/migrate_device: pin large folios before splitting Date: Thu, 2 Jul 2026 12:45:05 +0800 Message-Id: <20260702044505.98105-1-lance.yang@linux.dev> In-Reply-To: <20260701140638.840773-1-usama.arif@linux.dev> References: <20260701140638.840773-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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Wed, Jul 01, 2026 at 07:06:38AM -0700, Usama Arif wrote: >migrate_vma_collect_pmd() can detect a large folio while holding the PTE >lock, then drop the PTE lock before calling migrate_vma_split_folio(). The >split helper took its own reference, but only after the lock had already >been dropped. > >One way to hit this is device migration over a range that contains a large >folio. The walker reads the PTE while holding the PTE lock and derives the >folio either from a present PTE via vm_normal_page(), or from a non-present >PTE that encodes a device-private softleaf entry. It then has to drop the >PTE lock because split_folio() can block. Before migrate_vma_split_folio() >gets a folio reference, concurrent reclaim, migration, or truncation can >replace or clear the entry and drop the last reference to the folio. The >split helper would then take a reference and lock on a stale folio pointer. > >Take a temporary reference before dropping the PTE lock and pass that >reference into migrate_vma_split_folio(). The helper consumes the >reference, so split_folio() still sees only the expected caller pin instead >of an extra pin that could make the split fail. Yeah, that's how it should have been: lookup under PTL -> get folio ref -> drop PTL. Getting a ref after dropping PTL feels a bit too optimistic ... >Reported-by: sashiko-bot >Link: https://sashiko.dev/#/patchset/20260630164143.1595669-1-usama.arif%40linux.dev >Fixes: 022a12deda53 ("mm/migrate_device: handle partially mapped folios during collection") >Signed-off-by: Usama Arif >--- Thanks for fixing it! Feel free to add: Reviewed-by: Lance Yang