linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86, mm: disable 1GB direct mapping when disabling 2MB mapping
@ 2017-06-09 13:57 Vlastimil Babka
  2017-06-11  7:57 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Vlastimil Babka @ 2017-06-09 13:57 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin
  Cc: x86, linux-mm, linux-kernel, Vegard Nossum, Pekka Enberg,
	Christian Borntraeger, 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.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 arch/x86/mm/init.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index cbc87ea98751..20282dfce0fa 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -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 */
-- 
2.13.1

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86, mm: disable 1GB direct mapping when disabling 2MB mapping
  2017-06-09 13:57 [PATCH] x86, mm: disable 1GB direct mapping when disabling 2MB mapping Vlastimil Babka
@ 2017-06-11  7:57 ` Ingo Molnar
  2017-06-12  7:21   ` Vlastimil Babka
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2017-06-11  7:57 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, x86, linux-mm,
	linux-kernel, Vegard Nossum, Pekka Enberg, Christian Borntraeger


* Vlastimil Babka <vbabka@suse.cz> wrote:

> 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.
> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>  arch/x86/mm/init.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index cbc87ea98751..20282dfce0fa 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86, mm: disable 1GB direct mapping when disabling 2MB mapping
  2017-06-11  7:57 ` Ingo Molnar
@ 2017-06-12  7:21   ` Vlastimil Babka
  0 siblings, 0 replies; 3+ messages in thread
From: Vlastimil Babka @ 2017-06-12  7:21 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, x86, linux-mm,
	linux-kernel, Vegard Nossum, Pekka Enberg, Christian Borntraeger

On 06/11/2017 09:57 AM, Ingo Molnar wrote:
> 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 <vbabka@suse.cz>
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.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 arch/x86/mm/init.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index cbc87ea98751..b11afaf04c9d 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -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))
-- 
2.13.1

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-12  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-09 13:57 [PATCH] x86, mm: disable 1GB direct mapping when disabling 2MB mapping Vlastimil Babka
2017-06-11  7:57 ` Ingo Molnar
2017-06-12  7:21   ` Vlastimil Babka

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).