From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E18233B19B0 for ; Thu, 23 Jul 2026 07:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784790591; cv=none; b=eRLBltB16eWMAefBgL1Vu6vqxQGWFG+n1arCvsVTm3oz4Q5pgJtY49QaDNqneuOK34VBR3W4gDkWjiO5lhDstoDLLBMDidq9B5BC1YiC6JJmZT7M/mO0FP+0bsrM9oviOlPGfWNWC8eBgOmbJUuCZmyji6GtLFs8ujqRQRFm6w4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784790591; c=relaxed/simple; bh=8z/IjN6A8ouMBXAvCBuKGoi4RW1OBOi0aq0dGUH3uLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FRccVJxTcsOGhWWFJW3Dpen+sqbDJPeZVtb0Hd1FzPN2BPn1Jy1SRDPryhtiZj7hsY958fSJ/dDarVguK7MldqdVyKhbvtkZhMHjaZKTUhyjC9nIEzh7lPHFnpfLjBm/qC8R6XAOs4m+Wttho+JbIJiywqQi1XAROXqueiGs3Ec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=sAhah4yA; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="sAhah4yA" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1FE6C176B; Thu, 23 Jul 2026 00:09:45 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-01.blr.arm.com (cesw-amp-gbt-1s-m12830-01.blr.arm.com [10.164.195.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6055D3F66F; Thu, 23 Jul 2026 00:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784790589; bh=8z/IjN6A8ouMBXAvCBuKGoi4RW1OBOi0aq0dGUH3uLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sAhah4yAeGvs882Pyx2OtXKfBtyWfijIeC2XeoNNnu2KzC28X7QCnrMdJZSI1TXN+ 5/UhHIcdkSFdIzqJJMaDPv28kAVLfgcR7DrFYOe75E4kGwlMMXT7pDfMMOqYh065Bp L7DshNrVQm+EfglmkE28btTHS5aWw6jcgkpsbv18= From: Dev Jain To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hughd@google.com, chrisl@kernel.org, kasong@tencent.com Cc: Dev Jain , riel@surriel.com, liam@infradead.org, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, baolin.wang@linux.alibaba.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, baoquan.he@linux.dev, baohua@kernel.org, youngjun.park@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, pfalcato@suse.de, ryan.roberts@arm.com, anshuman.khandual@arm.com Subject: [PATCH 4/8] mm/internal: rename swap offset helpers to softleaf offset Date: Thu, 23 Jul 2026 07:09:00 +0000 Message-ID: <20260723070905.3422276-5-dev.jain@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260723070905.3422276-1-dev.jain@arm.com> References: <20260723070905.3422276-1-dev.jain@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In preparation for adding a helper to set softleaf ptes in one go, generalize the swap entry helpers shifting the swap offset by delta, for softleaves. Note that the soft-dirty bit, exclusive bit and uffd bit preservation will still work for non-swap softleaves, since a softleaf entry is constructed out of a type and offset, and those bits are ahead of the soft-dirty, exclusive and uffd bits. For example, for a migration entry, pte_swp_exclusive() will return false, as the exclusivity is encoded in the type itself (SOFTLEAF_MIGRATION_READ_EXCLUSIVE). Signed-off-by: Dev Jain --- mm/internal.h | 29 +++++++++++++++-------------- mm/memory.c | 4 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 51ee4c1310908..ce52188a8a65d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -475,16 +475,16 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte, unsigned int max_nr); /** - * pte_move_swp_offset - Move the swap entry offset field of a swap pte - * forward or backward by delta - * @pte: The initial pte state; must be a swap entry + * pte_move_softleaf_offset - Move the softleaf entry offset field of a + * softleaf pte forward or backward by delta + * @pte: The initial pte state; must be a softleaf entry * @delta: The direction and the offset we are moving; forward if delta * is positive; backward if delta is negative * - * Moves the swap offset, while maintaining all other fields, including - * swap type, and any swp pte bits. The resulting pte is returned. + * Moves the softleaf offset, while maintaining all other fields, including + * softleaf type, and any softleaf pte bits. The resulting pte is returned. */ -static inline pte_t pte_move_swp_offset(pte_t pte, long delta) +static inline pte_t pte_move_softleaf_offset(pte_t pte, long delta) { const softleaf_t entry = softleaf_from_pte(pte); pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry), @@ -502,15 +502,16 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta) /** - * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. - * @pte: The initial pte state; must be a swap entry. + * pte_next_softleaf_offset - Increment the softleaf entry offset field of a + * non-present pte. + * @pte: The initial pte state; must be a softleaf entry. * - * Increments the swap offset, while maintaining all other fields, including - * swap type, and any swp pte bits. The resulting pte is returned. + * Increments the softleaf offset, while maintaining all other fields, including + * softleaf type, and any softleaf pte bits. The resulting pte is returned. */ -static inline pte_t pte_next_swp_offset(pte_t pte) +static inline pte_t pte_next_softleaf_offset(pte_t pte) { - return pte_move_swp_offset(pte, 1); + return pte_move_softleaf_offset(pte, 1); } /** @@ -530,7 +531,7 @@ static inline pte_t pte_next_swp_offset(pte_t pte) */ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte) { - pte_t expected_pte = pte_next_swp_offset(pte); + pte_t expected_pte = pte_next_softleaf_offset(pte); const pte_t *end_ptep = start_ptep + max_nr; pte_t *ptep = start_ptep + 1; @@ -542,7 +543,7 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte) if (!pte_same(pte, expected_pte)) break; - expected_pte = pte_next_swp_offset(expected_pte); + expected_pte = pte_next_softleaf_offset(expected_pte); ptep++; } diff --git a/mm/memory.c b/mm/memory.c index d88df15018268..7a8442fda0b51 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4753,7 +4753,7 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages) idx = (vmf->address - addr) / PAGE_SIZE; pte = ptep_get(ptep); - if (!pte_same(pte, pte_move_swp_offset(vmf->orig_pte, -idx))) + if (!pte_same(pte, pte_move_softleaf_offset(vmf->orig_pte, -idx))) return false; /* * swap_read_folio() can't handle the case a large folio is hybridly @@ -5062,7 +5062,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) folio_ptep = vmf->pte - idx; folio_pte = ptep_get(folio_ptep); - if (!pte_same(folio_pte, pte_move_swp_offset(vmf->orig_pte, -idx)) || + if (!pte_same(folio_pte, pte_move_softleaf_offset(vmf->orig_pte, -idx)) || swap_pte_batch(folio_ptep, nr, folio_pte) != nr) goto check_folio; -- 2.43.0