lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <50fc95b4c806eb4bfcdb578f2ce8d634faf93d57.1762464515.git.luizcap@redhat.com>
Date: Thu,  6 Nov 2025 16:28:49 -0500
From: Luiz Capitulino <luizcap@...hat.com>
To: david@...nel.org,
	linux-kernel@...r.kernel.org,
	linux-mm@...ck.org
Cc: ryan.roberts@....com,
	akpm@...ux-foundation.org,
	lorenzo.stoakes@...cle.com
Subject: [RFC 02/10] mm: introduce pgtable_has_pmd_leaves()

This is a new helper which can be used to check if the architecture
supports PMD-sized pages. It's intended to replace two existing helpers:

- has_transparent_hugepages(): it's used to check for PMD-sized pages
  (not exactly THP support), but it may perform a hardware check so it's
  not intended to be used in fast paths

- thp_disabled_by_hw(): also checks for PMD-sized pages support, but
  uses a cached value

pgtable_has_pmd_leaves() implementation is split in two parts:

1. init_arch_has_pmd_leaves(): runs at boottime as early_initcall as a
   wrapper to has_transparent_hugepages(). The result is cached

2. pgtable_has_pmd_leaves(): just returns the cached value

The next commits will convert users of both has_transparent_hugepages()
and thp_disabled_by_hw() to pgtable_has_pmd_leaves().

Signed-off-by: Luiz Capitulino <luizcap@...hat.com>
---
 include/linux/pgtable.h | 10 ++++++++++
 mm/memory.c             | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 32e8457ad535..e4c5f70b0a01 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -2001,6 +2001,16 @@ static inline const char *pgtable_level_to_str(enum pgtable_level level)
 	}
 }
 
+/*
+ * IMPORTANT: pgtable_has_pmd_leaves() can only be called after
+ * early_initcall, since that's when __arch_has_pmd_leaves is set
+ */
+extern bool __arch_has_pmd_leaves;
+static inline bool pgtable_has_pmd_leaves(void)
+{
+	return __arch_has_pmd_leaves;
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #if !defined(MAX_POSSIBLE_PHYSMEM_BITS) && !defined(CONFIG_64BIT)
diff --git a/mm/memory.c b/mm/memory.c
index 74b45e258323..7b50f3ec9b37 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -176,6 +176,16 @@ static int __init init_zero_pfn(void)
 }
 early_initcall(init_zero_pfn);
 
+bool __arch_has_pmd_leaves __read_mostly;
+EXPORT_SYMBOL(__arch_has_pmd_leaves);
+
+static int __init init_arch_has_pmd_leaves(void)
+{
+	__arch_has_pmd_leaves = has_transparent_hugepage();
+	return 0;
+}
+early_initcall(init_arch_has_pmd_leaves);
+
 void mm_trace_rss_stat(struct mm_struct *mm, int member)
 {
 	trace_rss_stat(mm, member);
-- 
2.51.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ