linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Yin Fengwei <fengwei.yin@intel.com>, linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	david@redhat.com, dave.hansen@intel.com, tim.c.chen@intel.com,
	ying.huang@intel.com
Subject: [PATCH v5 2/5] mm: Add generic set_ptes()
Date: Tue,  7 Feb 2023 19:49:32 +0000	[thread overview]
Message-ID: <20230207194937.122543-3-willy@infradead.org> (raw)
In-Reply-To: <20230207194937.122543-1-willy@infradead.org>

This set_ptes should work for most architectures.  Those that need to
set a special bit in their PTEs or have their PFNs located at a different
offset from PAGE_SHIFT will need to override it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/pgtable.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index c63cd44777ec..e1804d23e7c4 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1439,6 +1439,33 @@ static inline int pmd_protnone(pmd_t pmd)
 
 #endif /* CONFIG_MMU */
 
+#ifndef set_ptes
+/**
+ * set_ptes - Map consecutive pages to a contiguous range of addresses.
+ * @mm: Address space to map the pages into.
+ * @addr: Address to map the first page at.
+ * @ptep: Page table pointer for the first entry.
+ * @pte: Page table entry for the first page.
+ * @nr: Number of pages to map.
+ *
+ * Context: The caller holds the page table lock.  The PTEs all lie
+ * within a single PMD (and VMA, and folio).
+ */
+static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
+		pte_t *ptep, pte_t pte, unsigned int nr)
+{
+	for (;;) {
+		set_pte_at(mm, addr, ptep, pte);
+		if (--nr == 0)
+			break;
+		ptep++;
+		addr += PAGE_SIZE;
+		/* This works for x86.  Check how PTEs are encoded */
+		pte = __pte(pte_val(pte) + PAGE_SIZE);
+	}
+}
+#endif
+
 #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
 
 #ifndef __PAGETABLE_P4D_FOLDED
-- 
2.35.1



  parent reply	other threads:[~2023-02-07 19:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07 19:49 [PATCH v5 0/5] Batched page table updates for file-backed large folios Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 1/5] filemap: Add filemap_map_folio_range() Matthew Wilcox (Oracle)
2023-02-07 19:49 ` Matthew Wilcox (Oracle) [this message]
2023-02-08  0:48   ` [PATCH v5 2/5] mm: Add generic set_ptes() kernel test robot
2023-02-08  2:20   ` kernel test robot
2023-02-08  4:57   ` Yin Fengwei
2023-02-08  8:38   ` Kirill A. Shutemov
2023-02-08 18:14     ` Matthew Wilcox
2023-02-09  8:11       ` Kirill A. Shutemov
2023-02-07 19:49 ` [PATCH v5 3/5] rmap: add folio_add_file_rmap_range() Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 4/5] mm: Convert do_set_pte() to set_pte_range() Matthew Wilcox (Oracle)
2023-02-07 19:49 ` [PATCH v5 5/5] filemap: Batch PTE mappings Matthew Wilcox (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230207194937.122543-3-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=fengwei.yin@intel.com \
    --cc=linux-mm@kvack.org \
    --cc=tim.c.chen@intel.com \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).