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 9149C481FCE; Thu, 24 Sep 2026 13:12:15 +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=1790255538; cv=none; b=HM8LcFJJEu+4AVYxYQYVZhq5rwCQXT6JdRnSse/IOO9VypKOGDDSaSNMi4iv0HEg37QuUxELKma/X14CBAIgllf53HAHM4OhiAR7XKE6Pv6DXGT9hH0o2TTKKaw+3pY21hZgYs3AZVIEPIFr9id6uHqB8xj22UUZxkfLtZ6Totk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790255538; c=relaxed/simple; bh=SdgJCddjPp7/Mvalka61vw2zQLeW42ALZN0qZGzm4do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JmHh4oQ010SZkJtUtBJsRfX8KNjP8Fa36VKy4c6+dFDryvdAFoK48km36MTLuedVSDn0uLv2ODncCMgra9P+YXOriC/DIgcYUqiRl3fFnIS8JOYYCaJEHlZemGvYElNmgOhkTIc48lu4hDBSAKLBWilb93zvEHLEmiYJG0qQIT8= 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=XGt0CeCZ; 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="XGt0CeCZ" 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 30BFB1BCB; Thu, 24 Sep 2026 06:12:10 -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 906783F86F; Thu, 24 Sep 2026 06:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1790255533; bh=SdgJCddjPp7/Mvalka61vw2zQLeW42ALZN0qZGzm4do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGt0CeCZXa84341ORqXF1Qk53S9zQuTR0fAfx2PSczJ/Sfzz5uIjthi3J94axjDk6 GMjtt4emAlgBb0XiCPUbJwHR3xR6FaetJXSRzB8mtYD19DrZkM312UGHrqy+hykZYb +2EeSHa7InZYwv+F6wTirMo5P72UNRg18QhSkUu4= From: Dev Jain To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hughd@google.com, chrisl@kernel.org, kasong@tencent.com, davem@davemloft.net, andreas@gaisler.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, jgg@ziepe.ca, thuth@redhat.com, sparclinux@vger.kernel.org, ryan.roberts@arm.com, anshuman.khandual@arm.com Subject: [PATCH v3 6/9] mm/internal: add set_softleaf_ptes Date: Thu, 24 Sep 2026 13:09:34 +0000 Message-ID: <20260924131106.1730494-7-dev.jain@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924131106.1730494-1-dev.jain@arm.com> References: <20260924131106.1730494-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. Reviewed-by: Barry Song 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 b8ec379b90bb0..0ffc9565c3273 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -508,6 +508,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