Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
       [not found] <0d19ac08-88b0-675d-19bd-4cdc543fdb30@virtuozzo.com>
@ 2017-02-10  9:54 ` Andrey Ryabinin
  2017-02-10 10:24   ` Dmitry Vyukov
  0 siblings, 1 reply; 11+ messages in thread
From: Andrey Ryabinin @ 2017-02-10  9:54 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86
  Cc: Tobias Regnery, Paul E . McKenney, Dmitry Vyukov,
	Alexander Potapenko, kasan-dev, linux-kernel, Andrey Ryabinin,
	stable

CONFIG_KASAN=y needs a lot of virtual memory mapped for its shadow.
In that case ptdump_walk_pgd_level_core() takes a lot of time to
walk across all page tables and doing this without
a rescheduling causes soft lockups:

 NMI watchdog: BUG: soft lockup - CPU#3 stuck for 23s! [swapper/0:1]
 ...
 Call Trace:
  ptdump_walk_pgd_level_core+0x40c/0x550
  ptdump_walk_pgd_level_checkwx+0x17/0x20
  mark_rodata_ro+0x13b/0x150
  kernel_init+0x2f/0x120
  ret_from_fork+0x2c/0x40

I guess that this issue might arise even without KASAN on a huge
machines with several terabytes of RAM.

Stick cond_resched() in pgd loop to fix this.

Reported-by: Tobias Regnery <tobias.regnery@gmail.com>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: <stable@vger.kernel.org>
---
 arch/x86/mm/dump_pagetables.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index ea9c49a..8aa6bea 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -15,6 +15,7 @@
 #include <linux/debugfs.h>
 #include <linux/mm.h>
 #include <linux/init.h>
+#include <linux/sched.h>
 #include <linux/seq_file.h>
 
 #include <asm/pgtable.h>
@@ -406,6 +407,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
 		} else
 			note_page(m, &st, __pgprot(0), 1);
 
+		cond_resched();
 		start++;
 	}
 
-- 
2.10.2


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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10  9:54 ` [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker Andrey Ryabinin
@ 2017-02-10 10:24   ` Dmitry Vyukov
  2017-02-10 11:18     ` Thomas Gleixner
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Vyukov @ 2017-02-10 10:24 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86@kernel.org,
	Tobias Regnery, Paul E . McKenney, Alexander Potapenko, kasan-dev,
	LKML, stable

On Fri, Feb 10, 2017 at 10:54 AM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
> CONFIG_KASAN=y needs a lot of virtual memory mapped for its shadow.
> In that case ptdump_walk_pgd_level_core() takes a lot of time to
> walk across all page tables and doing this without
> a rescheduling causes soft lockups:
>
>  NMI watchdog: BUG: soft lockup - CPU#3 stuck for 23s! [swapper/0:1]
>  ...
>  Call Trace:
>   ptdump_walk_pgd_level_core+0x40c/0x550
>   ptdump_walk_pgd_level_checkwx+0x17/0x20
>   mark_rodata_ro+0x13b/0x150
>   kernel_init+0x2f/0x120
>   ret_from_fork+0x2c/0x40
>
> I guess that this issue might arise even without KASAN on a huge
> machines with several terabytes of RAM.
>
> Stick cond_resched() in pgd loop to fix this.
>
> Reported-by: Tobias Regnery <tobias.regnery@gmail.com>
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: <stable@vger.kernel.org>
> ---
>  arch/x86/mm/dump_pagetables.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> index ea9c49a..8aa6bea 100644
> --- a/arch/x86/mm/dump_pagetables.c
> +++ b/arch/x86/mm/dump_pagetables.c
> @@ -15,6 +15,7 @@
>  #include <linux/debugfs.h>
>  #include <linux/mm.h>
>  #include <linux/init.h>
> +#include <linux/sched.h>
>  #include <linux/seq_file.h>
>
>  #include <asm/pgtable.h>
> @@ -406,6 +407,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>                 } else
>                         note_page(m, &st, __pgprot(0), 1);
>
> +               cond_resched();


This is the right thing to do per se, but I am concerned that now
people will just suffers from slow boot (it can take literally
minutes) and will not realize the root cause nor that it's fixable
(e.g. with rodata=n) and will probably just blame KASAN for slowness.

Could we default this rodata check to n under KASAN? Or at least print
some explanatory warning message before doing marking rodata (it
should be printed right before "hang", so if you stare at it for a
minute during each boot you realize that it may be related)? Or
something along these lines. FWIW in my builds I just always disable
the check.

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 10:24   ` Dmitry Vyukov
@ 2017-02-10 11:18     ` Thomas Gleixner
  2017-02-10 12:15       ` Andrey Ryabinin
  0 siblings, 1 reply; 11+ messages in thread
From: Thomas Gleixner @ 2017-02-10 11:18 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Andrey Ryabinin, Ingo Molnar, H. Peter Anvin, x86@kernel.org,
	Tobias Regnery, Paul E . McKenney, Alexander Potapenko, kasan-dev,
	LKML, stable

On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
> This is the right thing to do per se, but I am concerned that now
> people will just suffers from slow boot (it can take literally
> minutes) and will not realize the root cause nor that it's fixable
> (e.g. with rodata=n) and will probably just blame KASAN for slowness.
> 
> Could we default this rodata check to n under KASAN? Or at least print
> some explanatory warning message before doing marking rodata (it
> should be printed right before "hang", so if you stare at it for a
> minute during each boot you realize that it may be related)? Or
> something along these lines. FWIW in my builds I just always disable
> the check.

That certainly makes sense and we emit such warnings in other places
already (lockdep, trace_printk ...)

Thanks,

	tglx

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 11:18     ` Thomas Gleixner
@ 2017-02-10 12:15       ` Andrey Ryabinin
  2017-02-10 13:02         ` Dmitry Vyukov
  0 siblings, 1 reply; 11+ messages in thread
From: Andrey Ryabinin @ 2017-02-10 12:15 UTC (permalink / raw)
  To: Thomas Gleixner, Dmitry Vyukov
  Cc: Ingo Molnar, H. Peter Anvin, x86@kernel.org, Tobias Regnery,
	Paul E . McKenney, Alexander Potapenko, kasan-dev, LKML, stable



On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
>> This is the right thing to do per se, but I am concerned that now
>> people will just suffers from slow boot (it can take literally
>> minutes) and will not realize the root cause nor that it's fixable
>> (e.g. with rodata=n) and will probably just blame KASAN for slowness.
>>
>> Could we default this rodata check to n under KASAN? Or at least print
>> some explanatory warning message before doing marking rodata (it
>> should be printed right before "hang", so if you stare at it for a
>> minute during each boot you realize that it may be related)? Or
>> something along these lines. FWIW in my builds I just always disable
>> the check.
> 
> That certainly makes sense and we emit such warnings in other places
> already (lockdep, trace_printk ...)
> 

Agreed, but perhaps it would be better to make this code faster for KASAN=y?
The main problem here is that we have many pgd entries containing kasan_zero_pud values
and ptdump walker checks kasan_zero_pud many times.
Instead, we could check it only once and skip further kasan_zero_pud's.

I can't say I like this hack very much, but it wins me almost 20 seconds of boot time.
Any objections?


diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index 8aa6bea..0fbae1d 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -13,6 +13,7 @@
  */
 
 #include <linux/debugfs.h>
+#include <linux/kasan.h>
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/sched.h>
@@ -121,6 +122,30 @@ static struct addr_marker address_markers[] = {
                        seq_printf(m, fmt, ##args);             \
 })
 
+
+#ifdef CONFIG_KASAN
+static bool kasan_pgd_checked(pgd_t pgd, bool checkwx)
+{
+       static bool kasan_zero_pgd_checked = false;
+       pgd_t kasan_zero_pgd = __pgd(__pa(kasan_zero_pud) | _PAGE_TABLE);
+
+       if (!checkwx)
+               return false;
+
+       if (pgd_val(pgd) == pgd_val(kasan_zero_pgd)) {
+               if (kasan_zero_pgd_checked)
+                       return true;
+               kasan_zero_pgd_checked = true;
+       }
+       return false;
+}
+#else
+static inline bool kasan_pgd_checked(pgd_t pgd, bool checkwx)
+{
+       return false;
+}
+#endif
+
 /*
  * Print a readable form of a pgprot_t to the seq_file
  */
@@ -396,7 +421,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
 
        for (i = 0; i < PTRS_PER_PGD; i++) {
                st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
-               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
+               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
+                               !kasan_pgd_checked(*start, checkwx)) {
                        if (pgd_large(*start) || !pgd_present(*start)) {
                                prot = pgd_flags(*start);
                                note_page(m, &st, __pgprot(prot), 1);


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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 12:15       ` Andrey Ryabinin
@ 2017-02-10 13:02         ` Dmitry Vyukov
  2017-02-10 13:56           ` Andrey Ryabinin
  2017-02-10 14:38           ` Mark Rutland
  0 siblings, 2 replies; 11+ messages in thread
From: Dmitry Vyukov @ 2017-02-10 13:02 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86@kernel.org,
	Tobias Regnery, Paul E . McKenney, Alexander Potapenko, kasan-dev,
	LKML, stable, Mark Rutland

On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
>
>
> On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
>> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
>>> This is the right thing to do per se, but I am concerned that now
>>> people will just suffers from slow boot (it can take literally
>>> minutes) and will not realize the root cause nor that it's fixable
>>> (e.g. with rodata=n) and will probably just blame KASAN for slowness.
>>>
>>> Could we default this rodata check to n under KASAN? Or at least print
>>> some explanatory warning message before doing marking rodata (it
>>> should be printed right before "hang", so if you stare at it for a
>>> minute during each boot you realize that it may be related)? Or
>>> something along these lines. FWIW in my builds I just always disable
>>> the check.
>>
>> That certainly makes sense and we emit such warnings in other places
>> already (lockdep, trace_printk ...)
>>
>
> Agreed, but perhaps it would be better to make this code faster for KASAN=y?
> The main problem here is that we have many pgd entries containing kasan_zero_pud values
> and ptdump walker checks kasan_zero_pud many times.
> Instead, we could check it only once and skip further kasan_zero_pud's.
>
> I can't say I like this hack very much, but it wins me almost 20 seconds of boot time.
> Any objections?


Now I remember that we already discussed it in this thread:
https://lkml.org/lkml/2016/11/8/775

Andrey, you proposed:

"I didn't look at any code, but we probably could can remember last
visited pgd and skip next pgd if it's the same as previous."

Do you still think it's a good idea?
Walking the same pgd multiple times does not make sense (right?). And
it could probably speedup non-kasan builds to some degree in some
contexts. And the code will be free of additional ifdefs.



> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> index 8aa6bea..0fbae1d 100644
> --- a/arch/x86/mm/dump_pagetables.c
> +++ b/arch/x86/mm/dump_pagetables.c
> @@ -13,6 +13,7 @@
>   */
>
>  #include <linux/debugfs.h>
> +#include <linux/kasan.h>
>  #include <linux/mm.h>
>  #include <linux/init.h>
>  #include <linux/sched.h>
> @@ -121,6 +122,30 @@ static struct addr_marker address_markers[] = {
>                         seq_printf(m, fmt, ##args);             \
>  })
>
> +
> +#ifdef CONFIG_KASAN
> +static bool kasan_pgd_checked(pgd_t pgd, bool checkwx)
> +{
> +       static bool kasan_zero_pgd_checked = false;
> +       pgd_t kasan_zero_pgd = __pgd(__pa(kasan_zero_pud) | _PAGE_TABLE);
> +
> +       if (!checkwx)
> +               return false;
> +
> +       if (pgd_val(pgd) == pgd_val(kasan_zero_pgd)) {
> +               if (kasan_zero_pgd_checked)
> +                       return true;
> +               kasan_zero_pgd_checked = true;
> +       }
> +       return false;
> +}
> +#else
> +static inline bool kasan_pgd_checked(pgd_t pgd, bool checkwx)
> +{
> +       return false;
> +}
> +#endif
> +
>  /*
>   * Print a readable form of a pgprot_t to the seq_file
>   */
> @@ -396,7 +421,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>
>         for (i = 0; i < PTRS_PER_PGD; i++) {
>                 st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
> -               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
> +               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
> +                               !kasan_pgd_checked(*start, checkwx)) {
>                         if (pgd_large(*start) || !pgd_present(*start)) {
>                                 prot = pgd_flags(*start);
>                                 note_page(m, &st, __pgprot(prot), 1);
>

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 13:02         ` Dmitry Vyukov
@ 2017-02-10 13:56           ` Andrey Ryabinin
  2017-02-10 14:17             ` Dmitry Vyukov
  2017-02-10 14:29             ` Mark Rutland
  2017-02-10 14:38           ` Mark Rutland
  1 sibling, 2 replies; 11+ messages in thread
From: Andrey Ryabinin @ 2017-02-10 13:56 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86@kernel.org,
	Tobias Regnery, Paul E . McKenney, Alexander Potapenko, kasan-dev,
	LKML, stable, Mark Rutland

On 02/10/2017 04:02 PM, Dmitry Vyukov wrote:
> On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
> <aryabinin@virtuozzo.com> wrote:
>>
>>
>> On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
>>> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
>>>> This is the right thing to do per se, but I am concerned that now
>>>> people will just suffers from slow boot (it can take literally
>>>> minutes) and will not realize the root cause nor that it's fixable
>>>> (e.g. with rodata=n) and will probably just blame KASAN for slowness.
>>>>
>>>> Could we default this rodata check to n under KASAN? Or at least print
>>>> some explanatory warning message before doing marking rodata (it
>>>> should be printed right before "hang", so if you stare at it for a
>>>> minute during each boot you realize that it may be related)? Or
>>>> something along these lines. FWIW in my builds I just always disable
>>>> the check.
>>>
>>> That certainly makes sense and we emit such warnings in other places
>>> already (lockdep, trace_printk ...)
>>>
>>
>> Agreed, but perhaps it would be better to make this code faster for KASAN=y?
>> The main problem here is that we have many pgd entries containing kasan_zero_pud values
>> and ptdump walker checks kasan_zero_pud many times.
>> Instead, we could check it only once and skip further kasan_zero_pud's.
>>
>> I can't say I like this hack very much, but it wins me almost 20 seconds of boot time.
>> Any objections?
> 
> 
> Now I remember that we already discussed it in this thread:
> https://lkml.org/lkml/2016/11/8/775
> 
> Andrey, you proposed:
> 
> "I didn't look at any code, but we probably could can remember last
> visited pgd and skip next pgd if it's the same as previous."
> 
> Do you still think it's a good idea?

Ah, indeed. It will do roughly the same but with less of code churn, see bellow.

> Walking the same pgd multiple times does not make sense (right?). And
> it could probably speedup non-kasan builds to some degree in some
> contexts. And the code will be free of additional ifdefs.
> 

We could make it without ifdefs but this would be useless for KASAN=n
as page table entries normally unique. So I'm thinking to add #ifdef
at least for documentation purposes.



diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index 8aa6bea..1599a5c 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -373,6 +373,11 @@ static inline bool is_hypervisor_range(int idx)
 #endif
 }
 
+static bool pgd_already_checked(pgd_t *prev_pgd, pgd_t *pgd, bool checkwx)
+{
+       return checkwx && prev_pgd && (pgd_val(*prev_pgd) == pgd_val(*pgd));
+}
+
 static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
                                       bool checkwx)
 {
@@ -381,6 +386,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
 #else
        pgd_t *start = swapper_pg_dir;
 #endif
+       pgd_t *prev_pgd = NULL;
        pgprotval_t prot;
        int i;
        struct pg_state st = {};
@@ -396,7 +402,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
 
        for (i = 0; i < PTRS_PER_PGD; i++) {
                st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
-               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
+               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
+                               !pgd_already_checked(prev_pgd, start, checkwx)) {
                        if (pgd_large(*start) || !pgd_present(*start)) {
                                prot = pgd_flags(*start);
                                note_page(m, &st, __pgprot(prot), 1);
@@ -408,6 +415,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
                        note_page(m, &st, __pgprot(0), 1);
 
                cond_resched();
+               prev_pgd = start;
                start++;
        }

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 13:56           ` Andrey Ryabinin
@ 2017-02-10 14:17             ` Dmitry Vyukov
  2017-02-10 14:29             ` Mark Rutland
  1 sibling, 0 replies; 11+ messages in thread
From: Dmitry Vyukov @ 2017-02-10 14:17 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86@kernel.org,
	Tobias Regnery, Paul E . McKenney, Alexander Potapenko, kasan-dev,
	LKML, stable, Mark Rutland

On Fri, Feb 10, 2017 at 2:56 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
> On 02/10/2017 04:02 PM, Dmitry Vyukov wrote:
>> On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
>> <aryabinin@virtuozzo.com> wrote:
>>>
>>>
>>> On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
>>>> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
>>>>> This is the right thing to do per se, but I am concerned that now
>>>>> people will just suffers from slow boot (it can take literally
>>>>> minutes) and will not realize the root cause nor that it's fixable
>>>>> (e.g. with rodata=n) and will probably just blame KASAN for slowness.
>>>>>
>>>>> Could we default this rodata check to n under KASAN? Or at least print
>>>>> some explanatory warning message before doing marking rodata (it
>>>>> should be printed right before "hang", so if you stare at it for a
>>>>> minute during each boot you realize that it may be related)? Or
>>>>> something along these lines. FWIW in my builds I just always disable
>>>>> the check.
>>>>
>>>> That certainly makes sense and we emit such warnings in other places
>>>> already (lockdep, trace_printk ...)
>>>>
>>>
>>> Agreed, but perhaps it would be better to make this code faster for KASAN=y?
>>> The main problem here is that we have many pgd entries containing kasan_zero_pud values
>>> and ptdump walker checks kasan_zero_pud many times.
>>> Instead, we could check it only once and skip further kasan_zero_pud's.
>>>
>>> I can't say I like this hack very much, but it wins me almost 20 seconds of boot time.
>>> Any objections?


Looks good to me.


>> Now I remember that we already discussed it in this thread:
>> https://lkml.org/lkml/2016/11/8/775
>>
>> Andrey, you proposed:
>>
>> "I didn't look at any code, but we probably could can remember last
>> visited pgd and skip next pgd if it's the same as previous."
>>
>> Do you still think it's a good idea?
>
> Ah, indeed. It will do roughly the same but with less of code churn, see bellow.
>
>> Walking the same pgd multiple times does not make sense (right?). And
>> it could probably speedup non-kasan builds to some degree in some
>> contexts. And the code will be free of additional ifdefs.
>>
>
> We could make it without ifdefs but this would be useless for KASAN=n
> as page table entries normally unique. So I'm thinking to add #ifdef
> at least for documentation purposes.
>
>
>
> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> index 8aa6bea..1599a5c 100644
> --- a/arch/x86/mm/dump_pagetables.c
> +++ b/arch/x86/mm/dump_pagetables.c
> @@ -373,6 +373,11 @@ static inline bool is_hypervisor_range(int idx)
>  #endif
>  }
>
> +static bool pgd_already_checked(pgd_t *prev_pgd, pgd_t *pgd, bool checkwx)
> +{
> +       return checkwx && prev_pgd && (pgd_val(*prev_pgd) == pgd_val(*pgd));
> +}
> +
>  static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>                                        bool checkwx)
>  {
> @@ -381,6 +386,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>  #else
>         pgd_t *start = swapper_pg_dir;
>  #endif
> +       pgd_t *prev_pgd = NULL;
>         pgprotval_t prot;
>         int i;
>         struct pg_state st = {};
> @@ -396,7 +402,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>
>         for (i = 0; i < PTRS_PER_PGD; i++) {
>                 st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
> -               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
> +               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
> +                               !pgd_already_checked(prev_pgd, start, checkwx)) {
>                         if (pgd_large(*start) || !pgd_present(*start)) {
>                                 prot = pgd_flags(*start);
>                                 note_page(m, &st, __pgprot(prot), 1);
> @@ -408,6 +415,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>                         note_page(m, &st, __pgprot(0), 1);
>
>                 cond_resched();
> +               prev_pgd = start;
>                 start++;
>         }
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To post to this group, send email to kasan-dev@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/730837a1-ee6f-9891-0421-93616dd1c4eb%40virtuozzo.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 13:56           ` Andrey Ryabinin
  2017-02-10 14:17             ` Dmitry Vyukov
@ 2017-02-10 14:29             ` Mark Rutland
  2017-02-10 14:38               ` Andrey Ryabinin
  1 sibling, 1 reply; 11+ messages in thread
From: Mark Rutland @ 2017-02-10 14:29 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Dmitry Vyukov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86@kernel.org, Tobias Regnery, Paul E . McKenney,
	Alexander Potapenko, kasan-dev, LKML, stable

Hi,

On Fri, Feb 10, 2017 at 04:56:19PM +0300, Andrey Ryabinin wrote:
> On 02/10/2017 04:02 PM, Dmitry Vyukov wrote:
> > On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
> > <aryabinin@virtuozzo.com> wrote:
> >> On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
> >>> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:

> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> index 8aa6bea..1599a5c 100644
> --- a/arch/x86/mm/dump_pagetables.c
> +++ b/arch/x86/mm/dump_pagetables.c
> @@ -373,6 +373,11 @@ static inline bool is_hypervisor_range(int idx)
>  #endif
>  }
>  
> +static bool pgd_already_checked(pgd_t *prev_pgd, pgd_t *pgd, bool checkwx)
> +{
> +       return checkwx && prev_pgd && (pgd_val(*prev_pgd) == pgd_val(*pgd));
> +}
> +
>  static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>                                        bool checkwx)
>  {
> @@ -381,6 +386,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>  #else
>         pgd_t *start = swapper_pg_dir;
>  #endif
> +       pgd_t *prev_pgd = NULL;
>         pgprotval_t prot;
>         int i;
>         struct pg_state st = {};
> @@ -396,7 +402,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>  
>         for (i = 0; i < PTRS_PER_PGD; i++) {
>                 st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
> -               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
> +               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
> +                               !pgd_already_checked(prev_pgd, start, checkwx)) {

This means we'll fall into the else case...

>                         if (pgd_large(*start) || !pgd_present(*start)) {
>                                 prot = pgd_flags(*start);
>                                 note_page(m, &st, __pgprot(prot), 1);
> @@ -408,6 +415,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>                         note_page(m, &st, __pgprot(0), 1);

... i.e. the note_page() here, where we'll claim that the's nothing
present due to the empty prot.

That'll give erroneous output for the userspace pagetable dumps, so I do
not think this is quite right, even though it gives a boot-time speedup.

Thanks,
Mark.

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 14:29             ` Mark Rutland
@ 2017-02-10 14:38               ` Andrey Ryabinin
  2017-02-10 14:41                 ` Mark Rutland
  0 siblings, 1 reply; 11+ messages in thread
From: Andrey Ryabinin @ 2017-02-10 14:38 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Dmitry Vyukov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86@kernel.org, Tobias Regnery, Paul E . McKenney,
	Alexander Potapenko, kasan-dev, LKML, stable



On 02/10/2017 05:29 PM, Mark Rutland wrote:
> Hi,
> 
> On Fri, Feb 10, 2017 at 04:56:19PM +0300, Andrey Ryabinin wrote:
>> On 02/10/2017 04:02 PM, Dmitry Vyukov wrote:
>>> On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
>>> <aryabinin@virtuozzo.com> wrote:
>>>> On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
>>>>> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
> 
>> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
>> index 8aa6bea..1599a5c 100644
>> --- a/arch/x86/mm/dump_pagetables.c
>> +++ b/arch/x86/mm/dump_pagetables.c
>> @@ -373,6 +373,11 @@ static inline bool is_hypervisor_range(int idx)
>>  #endif
>>  }
>>  
>> +static bool pgd_already_checked(pgd_t *prev_pgd, pgd_t *pgd, bool checkwx)
>> +{
>> +       return checkwx && prev_pgd && (pgd_val(*prev_pgd) == pgd_val(*pgd));
>> +}
>> +
>>  static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>>                                        bool checkwx)
>>  {
>> @@ -381,6 +386,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>>  #else
>>         pgd_t *start = swapper_pg_dir;
>>  #endif
>> +       pgd_t *prev_pgd = NULL;
>>         pgprotval_t prot;
>>         int i;
>>         struct pg_state st = {};
>> @@ -396,7 +402,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>>  
>>         for (i = 0; i < PTRS_PER_PGD; i++) {
>>                 st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
>> -               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
>> +               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
>> +                               !pgd_already_checked(prev_pgd, start, checkwx)) {
> 
> This means we'll fall into the else case...
> 
>>                         if (pgd_large(*start) || !pgd_present(*start)) {
>>                                 prot = pgd_flags(*start);
>>                                 note_page(m, &st, __pgprot(prot), 1);
>> @@ -408,6 +415,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
>>                         note_page(m, &st, __pgprot(0), 1);
> 
> ... i.e. the note_page() here, where we'll claim that the's nothing
> present due to the empty prot.
> 
> That'll give erroneous output for the userspace pagetable dumps, so I do
> not think this is quite right, even though it gives a boot-time speedup.
> 

For userspace pagetable dumps checkwx is false, so page_already_checked() will return false and will not
go into else. userspace pagetable dumps works as before.


> Thanks,
> Mark.
> 

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 13:02         ` Dmitry Vyukov
  2017-02-10 13:56           ` Andrey Ryabinin
@ 2017-02-10 14:38           ` Mark Rutland
  1 sibling, 0 replies; 11+ messages in thread
From: Mark Rutland @ 2017-02-10 14:38 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Andrey Ryabinin, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86@kernel.org, Tobias Regnery, Paul E . McKenney,
	Alexander Potapenko, kasan-dev, LKML, stable

On Fri, Feb 10, 2017 at 02:02:19PM +0100, Dmitry Vyukov wrote:
> On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
> <aryabinin@virtuozzo.com> wrote:
> >
> >
> > On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
> >> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:

> >>> Could we default this rodata check to n under KASAN? Or at least print
> >>> some explanatory warning message before doing marking rodata (it
> >>> should be printed right before "hang", so if you stare at it for a
> >>> minute during each boot you realize that it may be related)?

Regardless of any optimisation work, I think it would make sense to both
log something in the debug_check_wx() and to default it off if KASAN is
selected.

That could be generic, so we don't have to alter each and every arch
port...

The WX check is a one-time boot check, and missing it for a KASAN kernel
isn't the end of the world, though I'd still like to be able to use the
userspace page table dumps.

Thanks,
Mark.

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

* Re: [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker.
  2017-02-10 14:38               ` Andrey Ryabinin
@ 2017-02-10 14:41                 ` Mark Rutland
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Rutland @ 2017-02-10 14:41 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Dmitry Vyukov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86@kernel.org, Tobias Regnery, Paul E . McKenney,
	Alexander Potapenko, kasan-dev, LKML, stable

On Fri, Feb 10, 2017 at 05:38:20PM +0300, Andrey Ryabinin wrote:
> On 02/10/2017 05:29 PM, Mark Rutland wrote:
> > On Fri, Feb 10, 2017 at 04:56:19PM +0300, Andrey Ryabinin wrote:
> >> On 02/10/2017 04:02 PM, Dmitry Vyukov wrote:
> >>> On Fri, Feb 10, 2017 at 1:15 PM, Andrey Ryabinin
> >>> <aryabinin@virtuozzo.com> wrote:
> >>>> On 02/10/2017 02:18 PM, Thomas Gleixner wrote:
> >>>>> On Fri, 10 Feb 2017, Dmitry Vyukov wrote:
> > 
> >> diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
> >> index 8aa6bea..1599a5c 100644
> >> --- a/arch/x86/mm/dump_pagetables.c
> >> +++ b/arch/x86/mm/dump_pagetables.c
> >> @@ -373,6 +373,11 @@ static inline bool is_hypervisor_range(int idx)
> >>  #endif
> >>  }
> >>  
> >> +static bool pgd_already_checked(pgd_t *prev_pgd, pgd_t *pgd, bool checkwx)
> >> +{
> >> +       return checkwx && prev_pgd && (pgd_val(*prev_pgd) == pgd_val(*pgd));
> >> +}
> >> +
> >>  static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
> >>                                        bool checkwx)
> >>  {
> >> @@ -381,6 +386,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
> >>  #else
> >>         pgd_t *start = swapper_pg_dir;
> >>  #endif
> >> +       pgd_t *prev_pgd = NULL;
> >>         pgprotval_t prot;
> >>         int i;
> >>         struct pg_state st = {};
> >> @@ -396,7 +402,8 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
> >>  
> >>         for (i = 0; i < PTRS_PER_PGD; i++) {
> >>                 st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
> >> -               if (!pgd_none(*start) && !is_hypervisor_range(i)) {
> >> +               if (!pgd_none(*start) && !is_hypervisor_range(i) &&
> >> +                               !pgd_already_checked(prev_pgd, start, checkwx)) {
> > 
> > This means we'll fall into the else case...
> > 
> >>                         if (pgd_large(*start) || !pgd_present(*start)) {
> >>                                 prot = pgd_flags(*start);
> >>                                 note_page(m, &st, __pgprot(prot), 1);
> >> @@ -408,6 +415,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
> >>                         note_page(m, &st, __pgprot(0), 1);
> > 
> > ... i.e. the note_page() here, where we'll claim that the's nothing
> > present due to the empty prot.
> > 
> > That'll give erroneous output for the userspace pagetable dumps, so I do
> > not think this is quite right, even though it gives a boot-time speedup.
> > 
> 
> For userspace pagetable dumps checkwx is false, so
> page_already_checked() will return false and will not go into else.
> userspace pagetable dumps works as before.

Ah. I missed that; sorry for the noise.

That sounds ok then, though it's probably worth a comment as to what
we're doing this for.

Thanks,
Mark.

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

end of thread, other threads:[~2017-02-10 14:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <0d19ac08-88b0-675d-19bd-4cdc543fdb30@virtuozzo.com>
2017-02-10  9:54 ` [PATCH] x86/mm/ptdump: Fix soft lockup in page table walker Andrey Ryabinin
2017-02-10 10:24   ` Dmitry Vyukov
2017-02-10 11:18     ` Thomas Gleixner
2017-02-10 12:15       ` Andrey Ryabinin
2017-02-10 13:02         ` Dmitry Vyukov
2017-02-10 13:56           ` Andrey Ryabinin
2017-02-10 14:17             ` Dmitry Vyukov
2017-02-10 14:29             ` Mark Rutland
2017-02-10 14:38               ` Andrey Ryabinin
2017-02-10 14:41                 ` Mark Rutland
2017-02-10 14:38           ` Mark Rutland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox