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 5687A3CE0BB for ; Thu, 23 Jul 2026 07:09:57 +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=1784790598; cv=none; b=rvVMlTbY3CKc4QhUNZzxDDoxMC9OswALkdv/rQQFxkzBKWbfH3+pLHEoDgAD1p5deQrsoRcIxGIfhbxr/wSDqrHDEve8mt6OAjXSG2vQIEcHw0Zv/wj6CqMUyGva6EjbruHm5DW7kaBDqzBWtYe2jde6J1yabiHEuMyH+cHv8n4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784790598; c=relaxed/simple; bh=yBeFG6ZrZTecABCeoXEb9SJ6EL++3Ahm1QCSPbW+WP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FeJBcgscckU8pW1OYc9LNtuJgTtqcywlJENFrRzdUBoDJ7Xe8xagfFOiSohCprbyHjS7rH3Y4JvzKny37hVoYRPzjwl2qSWSX1nynr8fAdYRW0EJLzq/T+Um28gr6wB0JUZUwodBGLkYGolC17KTaTqIt7rLP8pJeP7z14M7KqY= 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=IEQzhbRr; 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="IEQzhbRr" 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 8174D176A; Thu, 23 Jul 2026 00:09:52 -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 C92EB3F66F; Thu, 23 Jul 2026 00:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784790596; bh=yBeFG6ZrZTecABCeoXEb9SJ6EL++3Ahm1QCSPbW+WP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IEQzhbRr4BfxqMjqiFb2W7EeZ3ul3RzHqDjJWUZ+BBOBoJB38lL5h/lHv1lT0CiQ0 V5Di1hM1Pv/Pskgb9mgj6Cb9QLAOsoEOcn49UkQ+yczy4jfIMtevNRvJLFpOXmbibp BBgx3V9bbhmWjY0O+ZTB10LAP0phn8zAHm2jYAyk= 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 5/8] mm/internal: add set_softleaf_ptes Date: Thu, 23 Jul 2026 07:09:01 +0000 Message-ID: <20260723070905.3422276-6-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 Currently we have a helper called set_ptes() which is used to set consecutive present ptes in the pgtables. To do the same operation but to set "consecutive" nonpresent (softleaf) ptes, add set_softleaf_ptes(). The softleaves which have a notion of consecutivity is swap softleaf, and those grouped by softeaf_has_pfn(). The latter is trivial; future code can convert present ptes pointing to the same large folio to swap softleaves with consecutive offsets using this helper. The other case is softleaf markers. They do not have a notion of a swap offset or PFN, so future code can use set_softleaf_ptes() to store multiple (same) markers on the ptes. Signed-off-by: Dev Jain --- mm/internal.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mm/internal.h b/mm/internal.h index ce52188a8a65d..3fc1c1c776ca3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -514,6 +514,39 @@ static inline pte_t pte_next_softleaf_offset(pte_t pte) return pte_move_softleaf_offset(pte, 1); } +/** + * set_softleaf_ptes - Set consecutive softleaf PTEs. + * @mm: Address space the PTEs belong to. + * @addr: Address of the first PTE. + * @ptep: Page table pointer for the first PTE. + * @pte: PTE to set for the first entry. + * @nr: Number of PTEs to set. + * + * Install @nr softleaf PTEs, advancing @pte when its softleaf entry + * represents consecutive offsets. Swap entries advance through swap offsets, + * PFN softleaf entries advance through PFNs (encoded by swap offset), and + * marker entries are repeated unchanged. + */ +static inline void set_softleaf_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned long nr) +{ + softleaf_t entry; + bool advance; + + entry = softleaf_from_pte(pte); + advance = softleaf_is_swap(entry) || softleaf_has_pfn(entry); + + for (;;) { + set_pte_at(mm, addr, ptep, pte); + if (--nr == 0) + break; + if (advance) + pte = pte_next_softleaf_offset(pte); + ptep++; + addr += PAGE_SIZE; + } +} + /** * swap_pte_batch - detect a PTE batch for a set of contiguous swap entries * @start_ptep: Page table pointer for the first entry. -- 2.43.0