From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 38D7B349CD7; Fri, 17 Jul 2026 18:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784312608; cv=none; b=IMuLlF2t4ND0Mmf9F22GHu5rwUYRf9Md6lHJdVNDUD7MolOmmb57PDVR2cfNR8m6SVqe8O7Yii06q6lzjjUaZNije/e96ivhxn7nWBaELysKHkjRfzqfulsXz9tw2fOB8VePXMsd0Qcs+T/kFT5oRoP75D6jrF2n1ZpxBteE8W4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784312608; c=relaxed/simple; bh=6pAegtlPfBQ3G3CGe2dDWkuXSlF6+Udh4ZexgB7rXRw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tQe+EDSzWWt/y4UnWKamD9l9h7geQHIpeKKdSyDvtXPugOoHKLAXwq0vn+R5G9U+fvfDvhMAbXOv1AZN240tD5S0x0vvrdwKl+AkKkTb5qHUjejnM4eESHOhYI2uK+k8ywvfnCX0XUgfbUxO3qpuHu56NToE6vVX6J7R4ppEfiQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iZ50G7B9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iZ50G7B9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42F6B1F00A3D; Fri, 17 Jul 2026 18:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784312605; bh=LAYYiM2rpTmaPPo2VlPYNoqH0gFENrcwglvYiZo/Bls=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=iZ50G7B9X1eEJ+gjLEVKfTpi5LG2qZTmjqad3Qg4Kly7DE9FC9veVfrNbHX7mY8UC 3koAjIihABNFqIt/r2bxQ1SLL4TO1GVk1j9dn39GBDtf+quhPEqqWZ77guX1Ls2nsT YozctpZgHRXUVZZHfCLBJi9p/6ZGu26Nmto8hBvm4AZhcRnNIwd5TAUU34CjzDuqn/ 7W0HPy5aPvO7h6PCL3F8CK27lvT4Jgq6JB7PkiVHEF+jaK9xFpygzAsLbdo3xIV1Bf dEbDUlcZxYXUdY5GdfQJhuqaYzEKWmrR2d2ZOwg+kcLFljrJ91dXHOC0flCwocph5j 3pY8V+ezEsFnQ== From: "Lorenzo Stoakes (ARM)" Date: Fri, 17 Jul 2026 19:19:46 +0100 Subject: [PATCH 08/15] mm: introduce and use linear_folio_page_index() 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: 7bit Message-Id: <20260717-b4-scalable-cow-virt-pgoff-v1-8-cf24910ef094@kernel.org> References: <20260717-b4-scalable-cow-virt-pgoff-v1-0-cf24910ef094@kernel.org> In-Reply-To: <20260717-b4-scalable-cow-virt-pgoff-v1-0-cf24910ef094@kernel.org> To: Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , "Matthew Wilcox (Oracle)" , Jan Kara , Miaohe Lin , Naoya Horiguchi , Rik van Riel , Harry Yoo , Lance Yang , Kees Cook , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Usama Arif , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Peter Xu , Xu Xin , Chengming Zhou , Arnd Bergmann , Greg Kroah-Hartman Cc: "Lorenzo Stoakes (ARM)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4022; i=ljs@kernel.org; h=from:subject:message-id; bh=6pAegtlPfBQ3G3CGe2dDWkuXSlF6+Udh4ZexgB7rXRw=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLKiivbNurLzn7vj8qY5HOe75/ZoLd3/KXmjaJgIx53Zt 5XS/hxN6ShlYRDjYpAVU2R5/kV8f5BI2LzOC/5uMHNYmUCGMHBxCsBE3ucx/LN8F3ziz3yR9Zu/ Cv2pSqxmUuMPWvw8SOXG2ja2kMJNzPsY/sfZJlVsiDxTHHpo4e85L9z2u+wVlD3ztN6p95/s/gt XSpgB X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 This function is, for now, a placeholder; it will be used in future to determine whether to use the virtual page index or not, based on whether the folio is anonymous or not. Currently it simply wraps linear_page_index(), so this does not change behaviour. We update callers that will, once the change is introduced to track anonymous folios by virtual page offset if MAP_PRIVATE file-backed, need to determine which index to use based on folio type. No functional change intended. Signed-off-by: Lorenzo Stoakes (ARM) --- include/linux/pagemap.h | 18 ++++++++++++++++++ mm/huge_memory.c | 3 ++- mm/migrate.c | 6 ++++-- mm/userfaultfd.c | 6 ++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 81da91e103b3..dab355eda0ef 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1142,6 +1142,24 @@ static inline pgoff_t linear_virt_page_index(const struct vm_area_struct *vma, return pgoff; } +/** + * linear_folio_page_index() - Determine the absolute page offset of + * @address within @vma from @folio. + * @folio: The folio whose linear page index is sought. + * @vma: The VMA in which @address resides. + * @address: The address whose absolute page offset is required. + * + * For compatibility, currently identical to linear_page_index(). + * + * Returns: The absolute page offset of @address within @vma. + */ +static inline pgoff_t linear_folio_page_index(const struct folio *folio, + const struct vm_area_struct *vma, + const unsigned long address) +{ + return linear_page_index(vma, address); +} + struct wait_page_key { struct folio *folio; int bit_nr; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9b1f3b24f7e0..abc65d608c23 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2887,7 +2887,8 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm } folio_move_anon_rmap(src_folio, dst_vma); - src_folio->index = linear_page_index(dst_vma, dst_addr); + src_folio->index = linear_folio_page_index(src_folio, dst_vma, + dst_addr); _dst_pmd = folio_mk_pmd(src_folio, dst_vma->vm_page_prot); /* Follow mremap() behavior and treat the entry dirty after the move */ diff --git a/mm/migrate.c b/mm/migrate.c index 222c8c15f782..37fe7a9b3fac 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -363,8 +363,10 @@ static bool remove_migration_pte(struct folio *folio, unsigned long idx = 0; /* pgoff is invalid for ksm pages, but they are never large */ - if (folio_test_large(folio) && !folio_test_hugetlb(folio)) - idx = linear_page_index(vma, pvmw.address) - pvmw.pgoff; + if (folio_test_large(folio) && !folio_test_hugetlb(folio)) { + idx += linear_folio_page_index(folio, vma, pvmw.address); + idx -= pvmw.pgoff; + } new = folio_page(folio, idx); #ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 8fd24c8b428e..258b03182a78 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1352,7 +1352,8 @@ static long move_present_ptes(struct mm_struct *mm, } folio_move_anon_rmap(src_folio, dst_vma); - src_folio->index = linear_page_index(dst_vma, dst_addr); + src_folio->index = linear_folio_page_index(src_folio, dst_vma, + dst_addr); orig_dst_pte = folio_mk_pte(src_folio, dst_vma->vm_page_prot); /* Set soft dirty bit so userspace can notice the pte was moved */ @@ -1428,7 +1429,8 @@ static int move_swap_pte(struct mm_struct *mm, struct vm_area_struct *dst_vma, */ if (src_folio) { folio_move_anon_rmap(src_folio, dst_vma); - src_folio->index = linear_page_index(dst_vma, dst_addr); + src_folio->index = linear_folio_page_index(src_folio, dst_vma, + dst_addr); } else { /* * Check if the swap entry is cached after acquiring the src_pte -- 2.55.0