2022-02-01 20:50:57

by Pasha Tatashin

[permalink] [raw]
Subject: [PATCH v5 1/4] mm/debug_vm_pgtable: remove pte entry from the page table

The pte entry that is used in pte_advanced_tests() is never removed from
the page table at the end of the test.

The issue is detected by page_table_check, to repro compile kernel with
the following configs:

CONFIG_DEBUG_VM_PGTABLE=y
CONFIG_PAGE_TABLE_CHECK=y
CONFIG_PAGE_TABLE_CHECK_ENFORCED=y

During the boot the following BUG is printed:

[ 2.262821] debug_vm_pgtable: [debug_vm_pgtable ]: Validating
architecture page table helpers
[ 2.276826] ------------[ cut here ]------------
[ 2.280426] kernel BUG at mm/page_table_check.c:162!
[ 2.284118] invalid opcode: 0000 [#1] PREEMPT SMP PTI
[ 2.287787] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
5.16.0-11413-g2c271fe77d52 #3
[ 2.293226] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org
04/01/2014
...

The entry should be properly removed from the page table before the page
is released to the free list.

Fixes: a5c3b9ffb0f4 ("mm/debug_vm_pgtable: add tests validating advanced arch page table helpers")
Cc: [email protected] # 5.9+

Signed-off-by: Pasha Tatashin <[email protected]>
Reviewed-by: Zi Yan <[email protected]>
Tested-by: Zi Yan <[email protected]>
Acked-by: David Rientjes <[email protected]>
---
mm/debug_vm_pgtable.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
index a7ac97c76762..db2abd9e415b 100644
--- a/mm/debug_vm_pgtable.c
+++ b/mm/debug_vm_pgtable.c
@@ -171,6 +171,8 @@ static void __init pte_advanced_tests(struct pgtable_debug_args *args)
ptep_test_and_clear_young(args->vma, args->vaddr, args->ptep);
pte = ptep_get(args->ptep);
WARN_ON(pte_young(pte));
+
+ ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1);
}

static void __init pte_savedwrite_tests(struct pgtable_debug_args *args)
--
2.35.0.rc2.247.g8bbb082509-goog


2022-02-02 09:54:20

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH v5 1/4] mm/debug_vm_pgtable: remove pte entry from the page table



On 2/1/22 2:02 AM, Pasha Tatashin wrote:
> The pte entry that is used in pte_advanced_tests() is never removed from
> the page table at the end of the test.
>
> The issue is detected by page_table_check, to repro compile kernel with
> the following configs:
>
> CONFIG_DEBUG_VM_PGTABLE=y
> CONFIG_PAGE_TABLE_CHECK=y
> CONFIG_PAGE_TABLE_CHECK_ENFORCED=y
>
> During the boot the following BUG is printed:
>
> [ 2.262821] debug_vm_pgtable: [debug_vm_pgtable ]: Validating
> architecture page table helpers
> [ 2.276826] ------------[ cut here ]------------
> [ 2.280426] kernel BUG at mm/page_table_check.c:162!
> [ 2.284118] invalid opcode: 0000 [#1] PREEMPT SMP PTI
> [ 2.287787] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
> 5.16.0-11413-g2c271fe77d52 #3
> [ 2.293226] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
> BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org
> 04/01/2014
> ...
>
> The entry should be properly removed from the page table before the page
> is released to the free list.
>
> Fixes: a5c3b9ffb0f4 ("mm/debug_vm_pgtable: add tests validating advanced arch page table helpers")
> Cc: [email protected] # 5.9+

Not sure marking stable is necessary here.

>
> Signed-off-by: Pasha Tatashin <[email protected]>
> Reviewed-by: Zi Yan <[email protected]>
> Tested-by: Zi Yan <[email protected]>
> Acked-by: David Rientjes <[email protected]>

Dont see any problems on arm64. Although it would be great to run this
on all enabled platforms.

Reviewed-by: Anshuman Khandual <[email protected]>

> ---
> mm/debug_vm_pgtable.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
> index a7ac97c76762..db2abd9e415b 100644
> --- a/mm/debug_vm_pgtable.c
> +++ b/mm/debug_vm_pgtable.c
> @@ -171,6 +171,8 @@ static void __init pte_advanced_tests(struct pgtable_debug_args *args)
> ptep_test_and_clear_young(args->vma, args->vaddr, args->ptep);
> pte = ptep_get(args->ptep);
> WARN_ON(pte_young(pte));
> +
> + ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1);
> }
>
> static void __init pte_savedwrite_tests(struct pgtable_debug_args *args)
>