From: Lance Yang <lance.yang@linux.dev>
To: akpm@linux-foundation.org
Cc: rppt@kernel.org, david@kernel.org, tglx@kernel.org,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, luto@kernel.org,
peterz@infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, xueyuan.chen21@gmail.com,
ioworker0@gmail.com, Lance Yang <lance.yang@linux.dev>
Subject: [RFC PATCH 1/2] mm/secretmem: try to restore large page mappings in direct map
Date: Wed, 3 Jun 2026 18:46:23 +0800 [thread overview]
Message-ID: <20260603104624.36390-2-lance.yang@linux.dev> (raw)
In-Reply-To: <20260603104624.36390-1-lance.yang@linux.dev>
From: Lance Yang <lance.yang@linux.dev>
secretmem removes the pages backing secretmem mappings from the direct map.
Removing one base page from the direct map can split the covering large
mapping down to PTE mappings. Repeated splits can leave more of the direct
map mapped with PTEs, meaning more TLB entries for the same range and
potentially more TLB pressure.
So let's try to restore large page mappings whenever secretmem restores a
folio to the direct map.
Tested-by: Xueyuan Chen <xueyuan.chen21@gmail.com>
Signed-off-by: Lance Yang <lance.yang@linux.dev>
---
include/linux/set_memory.h | 6 ++++++
mm/secretmem.c | 12 ++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h
index 3030d9245f5a..ad2fa414a22d 100644
--- a/include/linux/set_memory.h
+++ b/include/linux/set_memory.h
@@ -58,6 +58,12 @@ static inline bool can_set_direct_map(void)
#endif
#endif /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */
+#ifndef arch_try_collapse_direct_map
+static inline void arch_try_collapse_direct_map(struct page *page)
+{
+}
+#endif
+
#ifdef CONFIG_X86_64
int set_mce_nospec(unsigned long pfn);
int clear_mce_nospec(unsigned long pfn);
diff --git a/mm/secretmem.c b/mm/secretmem.c
index 5f57ac4720d3..82634b99aa2c 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -47,6 +47,14 @@ bool secretmem_active(void)
return !!atomic_read(&secretmem_users);
}
+static void secretmem_restore_direct_map(struct folio *folio)
+{
+ struct page *page = folio_page(folio, 0);
+
+ if (!set_direct_map_default_noflush(page))
+ arch_try_collapse_direct_map(page);
+}
+
static vm_fault_t secretmem_fault(struct vm_fault *vmf)
{
struct address_space *mapping = vmf->vma->vm_file->f_mapping;
@@ -87,7 +95,7 @@ static vm_fault_t secretmem_fault(struct vm_fault *vmf)
* already happened when we marked the page invalid
* which guarantees that this call won't fail
*/
- set_direct_map_default_noflush(folio_page(folio, 0));
+ secretmem_restore_direct_map(folio);
folio_put(folio);
if (err == -EEXIST)
goto retry;
@@ -151,7 +159,7 @@ static int secretmem_migrate_folio(struct address_space *mapping,
static void secretmem_free_folio(struct folio *folio)
{
- set_direct_map_default_noflush(folio_page(folio, 0));
+ secretmem_restore_direct_map(folio);
folio_zero_segment(folio, 0, folio_size(folio));
}
--
2.49.0
next prev parent reply other threads:[~2026-06-03 10:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 10:46 [RFC PATCH 0/2] restore large page mappings in direct map for secretmem Lance Yang
2026-06-03 10:46 ` Lance Yang [this message]
2026-06-03 10:59 ` [RFC PATCH 1/2] mm/secretmem: try to restore large page mappings in direct map Mike Rapoport
2026-06-03 11:41 ` Lance Yang
2026-06-03 12:35 ` Mike Rapoport
2026-06-03 13:09 ` Lance Yang
2026-06-03 15:48 ` David Hildenbrand (Arm)
2026-06-03 10:46 ` [RFC PATCH 2/2] x86/mm: restore large page mappings for secretmem Lance Yang
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=20260603104624.36390-2-lance.yang@linux.dev \
--to=lance.yang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=xueyuan.chen21@gmail.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