Skip to contentSkip to conversation

x86, mm: disable 1GB direct mapping when disabling 2MB mapping

PATCH In review Vlastimil Babka 3 participants 4 messages Jun 9, 2017 – Jun 13, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, mm: disable 1GB direct mapping when disabling 2MB mapping

The kmemleak and debug_pagealloc features both disable using huge pages for direct mapping so they can do cpa() on page level granularity in any context. However they only do that for 2MB pages, which means 1GB pages can still be used if the CPU supports it, unless disabled by a boot param, which is non-obvious. Disable also 1GB pages when disabling 2MB pages.

---
 arch/x86/mm/init.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/init.c +4 -0
index cbc87ea98751..20282dfce0fa 100644
@@ -170,6 +170,10 @@ static void __init probe_page_size_mask(void)
 	 */
 	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled())
 		page_size_mask |= 1 << PG_LEVEL_2M;
+	else
+		direct_gbpages = 0;
+#else
+	direct_gbpages = 0;
 #endif
 
 	/* Enable PSE if available */
Signature · 7 lines
2.13.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 16 lines · Vlastimil Babka

The kmemleak and debug_pagealloc features both disable using huge pages for direct mapping so they can do cpa() on page level granularity in any context. However they only do that for 2MB pages, which means 1GB pages can still be used if the CPU supports it, unless disabled by a boot param, which is non-obvious. Disable also 1GB pages when disabling 2MB pages.

---
 arch/x86/mm/init.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/mm/init.c +0 -0
index cbc87ea98751..20282dfce0fa 100644

arch/x86/mm/init.c static void __init probe_page_size_mask(void) · line 179

Quoted 10 lines
arch/x86/mm/init.c +4 -0
@@ -170,6 +170,10 @@ static void __init probe_page_size_mask(void)
 	 */
 	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled())
 		page_size_mask |= 1 << PG_LEVEL_2M;
+	else
+		direct_gbpages = 0;
+#else
+	direct_gbpages = 0;
 #endif
 
 	/* Enable PSE if available */

So I agree with the fix, but I think it would be much cleaner to eliminate the outer #ifdef:

	#if !defined(CONFIG_KMEMCHECK)

and put it into the condition, like this:

	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled() && !IS_ENABLED(CONFIG_KMEMCHECK))
		page_size_mask |= 1 << PG_LEVEL_2M;
	else
		direct_gbpages = 0;

without any #ifdeffery. This makes it much more readable all around, and also makes it obvious that when the 2MB size bit is not set then gbpages are disabled as well.

Thanks,

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 8 lines · Ingo Molnar

So I agree with the fix, but I think it would be much cleaner to eliminate the outer #ifdef:

	#if !defined(CONFIG_KMEMCHECK)

and put it into the condition, like this:

	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled() && !IS_ENABLED(CONFIG_KMEMCHECK))

Right, that's better, thanks.

----8<----
From: Vlastimil Babka <[email protected]>
Date: Fri, 9 Jun 2017 15:41:22 +0200
Subject: [PATCH v2] x86, mm: disable 1GB direct mapping when disabling 2MB
mapping

The kmemleak and debug_pagealloc features both disable using huge pages for direct mapping so they can do cpa() on page level granularity in any context. However they only do that for 2MB pages, which means 1GB pages can still be used if the CPU supports it, unless disabled by a boot param, which is non-obvious. Disable also 1GB pages when disabling 2MB pages.

---
 arch/x86/mm/init.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/mm/init.c +4 -3
index cbc87ea98751..b11afaf04c9d 100644
@@ -161,16 +161,17 @@ static int page_size_mask;
 
 static void __init probe_page_size_mask(void)
 {
-#if !defined(CONFIG_KMEMCHECK)
 	/*
 	 * For CONFIG_KMEMCHECK or pagealloc debugging, identity mapping will
 	 * use small pages.
 	 * This will simplify cpa(), which otherwise needs to support splitting
 	 * large pages into small in interrupt context, etc.
 	 */
-	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled())
+	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled() &&
+						!IS_ENABLED(CONFIG_KMEMCHECK))
 		page_size_mask |= 1 << PG_LEVEL_2M;
-#endif
+	else
+		direct_gbpages = 0;
 
 	/* Enable PSE if available */
 	if (boot_cpu_has(X86_FEATURE_PSE))
Signature · 7 lines
2.13.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

[tip:x86/urgent] x86/mm: Disable 1GB direct mappings when disabling 2MB mappings

x86/mm: Disable 1GB direct mappings when disabling 2MB mappings
Commit-ID:  d9ee35acfabbc909c3be4360cd5655a006628b2e
Gitweb:     http://git.kernel.org/tip/d9ee35acfabbc909c3be4360cd5655a006628b2e
Author:     Vlastimil Babka <[email protected]>
AuthorDate: Mon, 12 Jun 2017 09:21:30 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Jun 2017 08:33:00 +0200

x86/mm: Disable 1GB direct mappings when disabling 2MB mappings

The kmemleak and debug_pagealloc features both disable using huge pages for direct mappings so they can do cpa() on page level granularity in any context.

However they only do that for 2MB pages, which means 1GB pages can still be used if the CPU supports it, unless disabled by a boot param, which is non-obvious. Disable also 1GB pages when disabling 2MB pages.

---
 arch/x86/mm/init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/mm/init.c +3 -3
index cbc87ea..9b3f9fa 100644
@@ -161,16 +161,16 @@ static int page_size_mask;
 
 static void __init probe_page_size_mask(void)
 {
-#if !defined(CONFIG_KMEMCHECK)
 	/*
 	 * For CONFIG_KMEMCHECK or pagealloc debugging, identity mapping will
 	 * use small pages.
 	 * This will simplify cpa(), which otherwise needs to support splitting
 	 * large pages into small in interrupt context, etc.
 	 */
-	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled())
+	if (boot_cpu_has(X86_FEATURE_PSE) && !debug_pagealloc_enabled() && !IS_ENABLED(CONFIG_KMEMCHECK))
 		page_size_mask |= 1 << PG_LEVEL_2M;
-#endif
+	else
+		direct_gbpages = 0;
 
 	/* Enable PSE if available */
 	if (boot_cpu_has(X86_FEATURE_PSE))