From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-71.mta0.migadu.com [91.218.175.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D859E246762 for ; Tue, 18 Aug 2026 02:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787019227; cv=none; b=CsA5zTfU5QyUh+YKVDgVZziyegAJF/xBZXPB5u46Eui4FzGuStEUVb7UzbL26ZobnK+TXZtN0jkehw79oDUAzYuUZ4bZultybtV+VEjS1L5/h/twAnD8NKd/RWMLYKF2qIa7ExhuA4t+cWPucP8AdLfSPnIT9ms/sYZcLiHVuxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787019227; c=relaxed/simple; bh=0PU5qADEL7pdf7bNZgRQ74sxC6pNxIIp3raq58ojt4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IJRC5PkRkZb4NrlEANQlqLRlfxloYeopGhtQALqTmaYpvbRP3fVV8xLKQ9G6SKJWJFmgk/KodALskfmJe5THEvfiLoWIXTDwPsy6VGmnSluDU77SKwDbTPFuhPjst+H2cHFxlZpEVnaFpQjzfiQOTaZI6VlhjhbRBruDrflEkMs= 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=D1nkQdHr; arc=none smtp.client-ip=91.218.175.71 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="D1nkQdHr" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=0PU5qADEL7pdf7bNZgRQ74sxC6pNxIIp3raq58ojt4E=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787019220; v=1; x=1787624020; b=D1nkQdHrAsatLKEjVrljJKf5nRjM9kaKsf9/P4sK6XADWBro4xo81BVuU1n7FlYmyhxOK6uv hHMzmMtosEOFoyZHjCvosrgpfdTXH7Ws0j0vPSPniLGea4jkVOVQHW6CTVN1EAvNpwRukvZZfT6 UkcUdKYqW1ZF7EjJKjRBS0O4= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (223.70.159.239) by smtp.migadu.com with ESMTPS id 142a8766c7c2699b; Tue, 18 Aug 2026 02:13:40 +0000 X-Migadu-Flow: FLOW_OUT From: Hongfu Li To: david@kernel.org Cc: akpm@linux-foundation.org, hongfu.li@linux.dev, liam@infradead.org, lihongfu@kylinos.cn, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, mhocko@suse.com, rppt@kernel.org, surenb@google.com, vbabka@kernel.org Subject: Re: [PATCH v4] mm: Use a folio in the softleaf_is_device_private path Date: Tue, 18 Aug 2026 10:13:26 +0800 Message-ID: <20260818021326.5910-1-hongfu.li@linux.dev> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit > > So after migrate_to_ram() the folio might have been split or otherwise somehow > > the page doesn't belong to the same locked, refcount-incremented folio it did > > before? > > I suspect a split. > > > > > That's kinda a footgun... but this documents it at least. > > > > I think a comment explaining how this can happen would be helpful though as this > > doesn't seem intuitive. > > I think, conceptually, calling into something that consumes a page (vmf->page) > always needs care when operating on folios. > > Passing the vmf to some callback might be the odd thing here, because the > vmf->page contract is not really clear. I'm very sorry for introducing this regression. Thank you for identifying and testing this issue. I will double-check this code path and apply your fix to run further tests locally. Would it make sense to add a comment here like the below, to make this subtle behavior clearer for future readers? diff --git a/mm/memory.c b/mm/memory.c index 4134ac607ee0..2b6d6c863ecb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4937,6 +4937,12 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); pgmap = page_pgmap(vmf->page); ret = pgmap->ops->migrate_to_ram(vmf); + /* + * migrate_to_ram() can split a large folio, updating + * vmf->page to a different folio. Re-fetch folio for + * correct unlock/put. + */ + folio = page_folio(vmf->page); folio_unlock(folio); folio_put(folio); } else {