mm/mremap.c: cleanup move_page_tables() a little
Subsystems (4)
cover mm/mremap.c: cleanup move_page_tables() a little
move_page_tables() tries to move page table by PMD or PTE.
The root reason is if it tries to move PMD, both old and new range should be PMD aligned. But current code calculate old range and new range separately. This leads to some redundant check and calculation.
This cleanup tries to consolidate the range check in one place to reduce some extra range handling.
Wei Yang (5):
mm/mremap: format the check in move_normal_pmd() same as
move_huge_pmd()
mm/mremap: it is sure to have enough space when extent meets
requirement
mm/mremap: use pmd_addr_end to calculate next in move_page_tables() mm/mremap: calculate extent in one place
mm/mremap: start addresses are properly aligned
include/linux/huge_mm.h | 2 +- mm/huge_memory.c | 8 +------- mm/mremap.c | 24 +++++++----------------- 3 files changed, 9 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/5 mm/mremap: format the check in move_normal_pmd() same as move_huge_pmd()
No functional change, just improve the readability and prepare for following cleanup.
--- mm/mremap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/mremap.c +3 -2
@@ -200,8 +200,9 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,struct mm_struct *mm = vma->vm_mm;pmd_t pmd; -if ((old_addr & ~PMD_MASK ) || (new_addr & ~PMD_MASK ) - || old_end - old_addr <PMD_SIZE ) +if ((old_addr & ~PMD_MASK ) || + (new_addr & ~PMD_MASK ) || + old_end - old_addr <PMD_SIZE )return false;/*
Signature · 1 line
2.17.1
PATCH 2/5 mm/mremap: it is sure to have enough space when extent meets requirement
In reply to Wei Yangold_end is passed to these two function to check whether there is enough space to do the move, while this check is done before invoking these functions.
These two functions only would be invoked when extent meets the requirement and there is one check before invoking these functions:
if (extent > old_end - old_addr)
extent = old_end - old_addr;
This implies (old_end - old_addr) won't fail the check in these two functions.
--- include/linux/huge_mm.h | 2 +- mm/huge_memory.c | 7 ++----- mm/mremap.c | 11 ++++------- 3 files changed, 7 insertions(+), 13 deletions(-)
include/linux/huge_mm.h +1 -1
@@ -42,7 +42,7 @@ extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, unsigned long end, unsigned char *vec);extern bool move_huge_pmd (struct vm_area_struct *vma,unsigned long old_addr, -unsigned long new_addr,unsigned long old_end, +unsigned long new_addr,pmd_t *old_pmd,pmd_t *new_pmd); extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, pgprot_t newprot,
mm/huge_memory.c +2 -5
@@ -1871,17 +1871,14 @@ static pmd_t move_soft_dirty_pmd(pmd_t pmd) }bool move_huge_pmd (struct vm_area_struct *vma,unsigned long old_addr, -unsigned long new_addr,unsigned long old_end, -pmd_t *old_pmd,pmd_t *new_pmd) +unsigned long new_addr,pmd_t *old_pmd,pmd_t *new_pmd) {spinlock_t *old_ptl, *new_ptl;pmd_t pmd;struct mm_struct *mm = vma->vm_mm;bool force_flush = false; -if ((old_addr & ~HPAGE_PMD_MASK ) || - (new_addr & ~HPAGE_PMD_MASK ) || - old_end - old_addr <HPAGE_PMD_SIZE ) +if ((old_addr & ~HPAGE_PMD_MASK ) || (new_addr & ~HPAGE_PMD_MASK ))return false;/*
mm/mremap.c +4 -7
@@ -193,16 +193,13 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,#ifdef CONFIG_HAVE_MOVE_PMD static bool move_normal_pmd (struct vm_area_struct *vma,unsigned long old_addr, -unsigned long new_addr,unsigned long old_end, -pmd_t *old_pmd,pmd_t *new_pmd) +unsigned long new_addr,pmd_t *old_pmd,pmd_t *new_pmd) {spinlock_t *old_ptl, *new_ptl;struct mm_struct *mm = vma->vm_mm;pmd_t pmd; -if ((old_addr & ~PMD_MASK ) || - (new_addr & ~PMD_MASK ) || - old_end - old_addr <PMD_SIZE ) +if ((old_addr & ~PMD_MASK ) || (new_addr & ~PMD_MASK ))return false;/*
@@ -274,7 +271,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (need_rmap_locks)take_rmap_locks (vma); moved =move_huge_pmd (vma, old_addr, new_addr, - old_end, old_pmd, new_pmd); + old_pmd, new_pmd);if (need_rmap_locks)drop_rmap_locks (vma);if (moved)
@@ -294,7 +291,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (need_rmap_locks)take_rmap_locks (vma); moved =move_normal_pmd (vma, old_addr, new_addr, - old_end, old_pmd, new_pmd); + old_pmd, new_pmd);if (need_rmap_locks)drop_rmap_locks (vma);if (moved)
Signature · 1 line
2.17.1
PATCH 3/5 mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
In reply to Wei YangUse the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
mm/mremap.c +2 -5
@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;
@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,
Signature · 1 line
2.17.1
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;
mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,
Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190
and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
Andrew Morton
maintainerRe: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 41 lines · On Sun, 26 Jan 2020 17:47:57 +0300 Dmitry Osipenko…
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
Thanks. I had these tagged for 5.7-rc1 anyway, so I'll drop all five patches.
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
27.01.2020 05:59, Andrew Morton пишет:
Quoted 1 line · On Sun, 26 Jan 2020 17:47:57 +0300 Dmitry Osipenko <[email protected]> wrote:
...
Quoted 7 lines
Quoted 7 lines
Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190
Quoted 8 lines
Quoted 4 lines
and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
Thanks. I had these tagged for 5.7-rc1 anyway, so I'll drop all five patches.
Hello Andrew,
FYI, I'm still seeing the offending patches in the today's next-20200129.
Andrew Morton
maintainerRe: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 15 lines · On Wed, 29 Jan 2020 20:18:56 +0300 Dmitry Osipenko <[email protected]> wrote:
27.01.2020 05:59, Andrew Morton пишет:
Quoted 1 line · On Sun, 26 Jan 2020 17:47:57 +0300 Dmitry Osipenko <[email protected]> wrote:
...
Quoted 12 lines
Quoted 11 lines
Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
Quoted 7 lines
Quoted 3 lines
Thanks. I had these tagged for 5.7-rc1 anyway, so I'll drop all five patches.
Hello Andrew,
FYI, I'm still seeing the offending patches in the today's next-20200129.
hm, me too. Stephen, it's unexpected that 9ff4452912d63f ("mm/mremap:
use pmd_addr_end to calculate next in move_page_tables()") is still in the -next lineup? It was dropped from -mm on Jan 26?
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Hi Andrew,
Quoted 4 lines · On Wed, 29 Jan 2020 15:59:07 -0800 Andrew Morton…
hm, me too. Stephen, it's unexpected that
9ff4452912d63f("mm/mremap:
usepmd_addr_endto calculate next inmove_page_tables()") is still in the -next lineup? It was dropped from -mm on Jan 26?
The mmotm 2020-01-28-20-05 arrived just to late for yesterday's linux-next (it will be in today's linux-next). The mmotm before that was 2020-01-23-21-12. I attempt to fetch mmotm (along with all the remaining unmerged trees) about every 30 minutes (sometimes more often) during the day.
Signature · 2 lines
Cheers, Stephen Rothwell
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
In reply to Dmitry OsipenkoQuoted 38 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Quoted 5 lines
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190
Thanks.
Would you mind letting me know which case you are testing? Or the special thing is 32-bit platform?
Quoted 4 lines
and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
Signature · 7 lines
Wei Yang Help you, Help me _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
28.01.2020 03:43, Wei Yang пишет:
Quoted 42 lines · Dmitry Osipenko
Quoted 41 lines
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
Quoted 2 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190Thanks.
Would you mind letting me know which case you are testing?
Nothing special, systemd starts to fall apart during boot.
Quoted 1 line
Or the special thing is 32-bit platform?
I have a limited knowledge about mm/, so can't provide detailed explanation.
Please take a look at this:
[1]
https://elixir.bootlin.com/linux/v5.5/source/arch/arm/include/asm/pgtable-2level.h#L210
[2]
https://elixir.bootlin.com/linux/v5.5/source/include/asm-generic/pgtable.h#L549
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 57 lines · Dmitry Osipenko
28.01.2020 03:43, Wei Yang пишет:
Quoted 42 lines · Dmitry Osipenko
Quoted 41 lines
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
Quoted 2 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190Thanks.
Would you mind letting me know which case you are testing?
Nothing special, systemd starts to fall apart during boot.
Quoted 1 line
Or the special thing is 32-bit platform?
I have a limited knowledge about
mm/, so can't provide detailed explanation.Please take a look at this:
Quoted 8 lines
[1]
https://elixir.bootlin.com/linux/v5.5/source/arch/arm/include/asm/pgtable-2level.h#L210[2]
https://elixir.bootlin.com/linux/v5.5/source/include/asm-generic/pgtable.h#L549
Thanks, I see the difference here.
If this is the case, we can't use pmd_addr_end() to simplify the calculation. This changes the behavior.
I would prepare another patch set to fix this. Would you mind helping me verify on your platform?
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
29.01.2020 02:29, Wei Yang пишет:
Quoted 67 lines · Dmitry Osipenko
Quoted 57 lines
28.01.2020 03:43, Wei Yang пишет:
Quoted 42 lines · Dmitry Osipenko
Quoted 41 lines
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
Quoted 2 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190Thanks.
Would you mind letting me know which case you are testing?
Nothing special, systemd starts to fall apart during boot.
Quoted 1 line
Or the special thing is 32-bit platform?
I have a limited knowledge about
mm/, so can't provide detailed explanation.Please take a look at this:
Quoted 7 lines
Thanks, I see the difference here.
If this is the case, we can't use
pmd_addr_end()to simplify the calculation. This changes the behavior.I would prepare another patch set to fix this. Would you mind helping me verify on your platform?
Sure, please feel free to CC me on that patch.
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 70 lines · Dmitry Osipenko
29.01.2020 02:29, Wei Yang пишет:
Quoted 69 lines · Dmitry Osipenko
Quoted 57 lines
28.01.2020 03:43, Wei Yang пишет:
Quoted 42 lines · Dmitry Osipenko
Quoted 41 lines
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
Quoted 2 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190Thanks.
Would you mind letting me know which case you are testing?
Nothing special, systemd starts to fall apart during boot.
Quoted 1 line
Or the special thing is 32-bit platform?
I have a limited knowledge about
mm/, so can't provide detailed explanation.Please take a look at this:
Quoted 8 lines
[1]
https://elixir.bootlin.com/linux/v5.5/source/arch/arm/include/asm/pgtable-2level.h#L210[2]
https://elixir.bootlin.com/linux/v5.5/source/include/asm-generic/pgtable.h#L549Thanks, I see the difference here.
Quoted 7 lines
Quoted 5 lines
If this is the case, we can't use
pmd_addr_end()to simplify the calculation. This changes the behavior.I would prepare another patch set to fix this. Would you mind helping me verify on your platform?
Sure, please feel free to CC me on that patch.
Thanks, you are in the cc list of v2.
Hope this one works fine on ARM.
Signature · 7 lines
Wei Yang Help you, Help me _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
29.01.2020 03:28, Wei Yang пишет:
...
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I would prepare another patch set to fix this. Would you mind helping me verify on your platform?
Sure, please feel free to CC me on that patch.
Thanks, you are in the cc list of v2.
Hope this one works fine on ARM.
Okay, I'll reply to the v2 after some more extensive testing (tomorrow).
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
In reply to Dmitry OsipenkoQuoted 41 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong - pXX_addr_end() are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.
When page tables are "rolled up" when levels don't exist, it is common practice for these macros to just return their end address index. Hence, if they are used with arbitary end address indicies, then the iteration will fail.
The only way to do this is:
next = pmd_addr_end(old_addr, pud_addr_end(old_addr, p4d_addr_end(old_addr, pgd_addr_end(old_addr, old_end))));
which gives pmd_addr_end() (and each of the intermediate pXX_addr_end()) the correct end argument. However, that's a more complex and verbose, and likely less efficient than the current code.
I'd suggest that there's nothing to "fix" in the v5.5 code wrt this, and trying to "clean it up" will just result in less efficient or broken code.
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
29.01.2020 12:47, Russell King - ARM Linux admin пишет:
Quoted 66 lines · Dmitry Osipenko
Quoted 41 lines
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
Quoted 6 lines
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong -
pXX_addr_end()are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.When page tables are "rolled up" when levels don't exist, it is common practice for these macros to just return their end address index. Hence, if they are used with arbitary end address indicies, then the iteration will fail.
The only way to do this is:
next = pmd_addr_end(old_addr, pud_addr_end(old_addr, p4d_addr_end(old_addr, pgd_addr_end(old_addr, old_end))));
Quoted 8 lines
which gives
pmd_addr_end()(and each of the intermediatepXX_addr_end()) the correct end argument. However, that's a more complex and verbose, and likely less efficient than the current code.I'd suggest that there's nothing to "fix" in the v5.5 code wrt this, and trying to "clean it up" will just result in less efficient or broken code.
Hello Russell,
Thank you very much for the extra clarification!
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
In reply to Russell King - ARM Linux adminQuoted 46 lines · Russell King - ARM Linux admin
Quoted 45 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Quoted 8 lines
Quoted 2 lines
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong -
pXX_addr_end()are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.
#define pmd_addr_end(addr, end) \
({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \
(__boundary - 1 < (end) - 1)? __boundary: (end); \
})If my understanding is correct, the definition here align the addr to next PMD boundary or end.
I don't see the possibility to across another PMD. Do I miss something?
Quoted 24 lines
When page tables are "rolled up" when levels don't exist, it is common practice for these macros to just return their end address index. Hence, if they are used with arbitary end address indicies, then the iteration will fail.
The only way to do this is:
next = pmd_addr_end(old_addr, pud_addr_end(old_addr, p4d_addr_end(old_addr, pgd_addr_end(old_addr, old_end))));which gives
pmd_addr_end()(and each of the intermediatepXX_addr_end()) the correct end argument. However, that's a more complex and verbose, and likely less efficient than the current code.I'd suggest that there's nothing to "fix" in the v5.5 code wrt this, and trying to "clean it up" will just result in less efficient or broken code.
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 57 lines · Wei Yang
Quoted 46 lines · Russell King - ARM Linux admin
Quoted 45 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Quoted 8 lines
Quoted 2 lines
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong -
pXX_addr_end()are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.#define
pmd_addr_end(addr, end)\
Quoted 8 lines
({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ (__boundary - 1 < (end) - 1)? __boundary: (end); \ })If my understanding is correct, the definition here align the addr to next PMD boundary or end.
I don't see the possibility to across another PMD. Do I miss something?
Look at the definition of p*_addr_end() that are used when page tables are rolled up.
Quoted 29 lines
Quoted 24 lines
When page tables are "rolled up" when levels don't exist, it is common practice for these macros to just return their end address index. Hence, if they are used with arbitary end address indicies, then the iteration will fail.
The only way to do this is:
next = pmd_addr_end(old_addr, pud_addr_end(old_addr, p4d_addr_end(old_addr, pgd_addr_end(old_addr, old_end))));which gives
pmd_addr_end()(and each of the intermediatepXX_addr_end()) the correct end argument. However, that's a more complex and verbose, and likely less efficient than the current code.I'd suggest that there's nothing to "fix" in the v5.5 code wrt this, and trying to "clean it up" will just result in less efficient or broken code.
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps upSignature · 2 lines
Wei Yang Help you, Help me
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 62 lines · Russell King - ARM Linux admin
Quoted 61 lines · Wei Yang
Quoted 46 lines · Russell King - ARM Linux admin
Quoted 45 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Quoted 8 lines
Quoted 2 lines
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong -
pXX_addr_end()are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.#define
pmd_addr_end(addr, end)\({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ (__boundary - 1 < (end) - 1)? __boundary: (end); \ })
Quoted 8 lines
Quoted 4 lines
If my understanding is correct, the definition here align the addr to next PMD boundary or end.
I don't see the possibility to across another PMD. Do I miss something?
Look at the definition of p*_addr_end() that are used when page tables are rolled up.
Sorry, I don't get your point.
What's the meaning of "roll up" here?
Would you mind giving me an example? I see pmd_addr_end() is not used in many places in core kernel. By glancing those usages, all the places use it like pmd_addr_end(addr, end). Seems no specially handing on the end address.
Or you mean the case when pmd_addr_end() is defined to return "end" directly?
Quoted 34 lines
Quoted 29 lines
Quoted 24 lines
When page tables are "rolled up" when levels don't exist, it is common practice for these macros to just return their end address index. Hence, if they are used with arbitary end address indicies, then the iteration will fail.
The only way to do this is:
next = pmd_addr_end(old_addr, pud_addr_end(old_addr, p4d_addr_end(old_addr, pgd_addr_end(old_addr, old_end))));which gives
pmd_addr_end()(and each of the intermediatepXX_addr_end()) the correct end argument. However, that's a more complex and verbose, and likely less efficient than the current code.I'd suggest that there's nothing to "fix" in the v5.5 code wrt this, and trying to "clean it up" will just result in less efficient or broken code.
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps upSignature · 2 lines
Wei Yang Help you, Help meSignature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 74 lines · Wei Yang
Quoted 62 lines · Russell King - ARM Linux admin
Quoted 61 lines · Wei Yang
Quoted 46 lines · Russell King - ARM Linux admin
Quoted 45 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Quoted 8 lines
Quoted 2 lines
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong -
pXX_addr_end()are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.#define
pmd_addr_end(addr, end)\({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ (__boundary - 1 < (end) - 1)? __boundary: (end); \ })Quoted 8 lines
Quoted 4 lines
If my understanding is correct, the definition here align the addr to next PMD boundary or end.
I don't see the possibility to across another PMD. Do I miss something?
Look at the definition of p*_addr_end() that are used when page tables are rolled up.
Sorry, I don't get your point.
Quoted 7 lines
What's the meaning of "roll up" here?
Would you mind giving me an example? I see
pmd_addr_end()is not used in many places in core kernel. By glancing those usages, all the places use it likepmd_addr_end(addr, end). Seems no specially handing on the end address.Or you mean the case when
pmd_addr_end()is defined to return "end" directly?
Not all hardware has five levels of page tables. When hardware does not have five levels, it is common to "roll up" some of the page tables into others.
There are generic ways to implement this, which include using:
include/asm-generic/pgtable-nop4d.hinclude/asm-generic/pgtable-nopud.hinclude/asm-generic/pgtable-nopmd.h
and then there's architecture ways to implement this. 32-bit ARM takes its implementation for PMD not from the generic version, which post-dates 32-bit ARM, but from how page table roll-up was implemented back at the time when the current ARM scheme was devised. The generic scheme is unsuitable for 32-bit ARM since we do more than just roll-up page tables, but this is irrelevent for this discussion.
All three of the generic implementations, and 32-bit ARM, define the pXX_addr_end() macros thusly:
include/asm-generic/pgtable-nop4d.h:#define p4d_addr_end(addr, end) (end) include/asm-generic/pgtable-nopmd.h:#define pmd_addr_end(addr, end) (end) include/asm-generic/pgtable-nopud.h:#define pud_addr_end(addr, end) (end) arch/arm/include/asm/pgtable-2level.h:#define pmd_addr_end(addr,end) (end)
since, as I stated, pXX_addr_end() expects its "end" argument to be the address index of the next entry in the immediately upper page table level, or the address index of the last entry we wish to process, which ever is smaller.
If it's larger than the address index of the next entry in the immediately upper page table level, then the effect of all these macros will be to walk off the end of the current level of page table.
To see how they _should_ be used, see the loops in free_pgd_range() and the free_pXX_range() functions called from there and below.
In all cases when the pXX_addr_end() macro was introduced, what I state above holds true - and I believe still holds true today, until this patch that has reportedly caused issues.
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Re: [PATCH 3/5] mm/mremap: use pmd_addr_end to calculate next in move_page_tables()
Quoted 118 lines · Russell King - ARM Linux admin
Quoted 74 lines · Wei Yang
Quoted 62 lines · Russell King - ARM Linux admin
Quoted 61 lines · Wei Yang
Quoted 46 lines · Russell King - ARM Linux admin
Quoted 45 lines · Dmitry Osipenko
18.01.2020 02:22, Wei Yang пишет:
Quoted 26 lines
Use the general helper instead of do it by hand.
Signed-off-by Wei Yang <[email protected]>--- mm/mremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)mm/mremap.c +1
-4@@ -253,11 +253,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next = (old_addr +PMD_SIZE ) &PMD_MASK ; -/* even if next overflowed, extent below will be ok */ + next =pmd_addr_end (old_addr, old_end); extent = next - old_addr; -if (extent > old_end - old_addr) - extent = old_end - old_addr; old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;mm/mremap.c unsigned long move_page_tables(struct vm_area_struct *vma, · line 304
Quoted 8 lines
mm/mremap.c +1
-1@@ -301,7 +298,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next = (new_addr +PMD_SIZE ) &PMD_MASK ; + next =pmd_addr_end (new_addr, new_addr + len);if (extent > next - new_addr) extent = next - new_addr; move_ptes(vma, old_pmd, old_addr, old_addr + extent, new_vma,Hello Wei,
Starting with next-20200122, I'm seeing the following in KMSG on NVIDIA Tegra (ARM32):
BUG: Bad rss-counter state mm:(ptrval) type:MM_ANONPAGES val:190and eventually kernel hangs.
Quoted 8 lines
Quoted 2 lines
Git's bisection points to this patch and reverting it helps. Please fix, thanks in advance.
The above is definitely wrong -
pXX_addr_end()are designed to be used with an address index within the pXX table table and the address index of either the last entry in the same pXX table or the beginning of the _next_ pXX table. Arbitary end address indicies are not allowed.#define
pmd_addr_end(addr, end)\({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ (__boundary - 1 < (end) - 1)? __boundary: (end); \ })Quoted 8 lines
Quoted 4 lines
If my understanding is correct, the definition here align the addr to next PMD boundary or end.
I don't see the possibility to across another PMD. Do I miss something?
Look at the definition of p*_addr_end() that are used when page tables are rolled up.
Sorry, I don't get your point.
Quoted 7 lines
What's the meaning of "roll up" here?
Would you mind giving me an example? I see
pmd_addr_end()is not used in many places in core kernel. By glancing those usages, all the places use it likepmd_addr_end(addr, end). Seems no specially handing on the end address.Or you mean the case when
pmd_addr_end()is defined to return "end" directly?Not all hardware has five levels of page tables. When hardware does not have five levels, it is common to "roll up" some of the page tables into others.
There are generic ways to implement this, which include using:
include/asm-generic/pgtable-nop4d.hinclude/asm-generic/pgtable-nopud.hinclude/asm-generic/pgtable-nopmd.hand then there's architecture ways to implement this. 32-bit ARM takes its implementation for PMD not from the generic version, which post-dates 32-bit ARM, but from how page table roll-up was implemented back at the time when the current ARM scheme was devised. The generic scheme is unsuitable for 32-bit ARM since we do more than just roll-up page tables, but this is irrelevent for this discussion.
All three of the generic implementations, and 32-bit ARM, define the
pXX_addr_end()macros thusly:include/asm-generic/pgtable-nop4d.h:#define
p4d_addr_end(addr, end)(end) include/asm-generic/pgtable-nopmd.h:#definepmd_addr_end(addr, end)(end) include/asm-generic/pgtable-nopud.h:#definepud_addr_end(addr, end)(end) arch/arm/include/asm/pgtable-2level.h:#definepmd_addr_end(addr,end)(end)since, as I stated,
pXX_addr_end()expects its "end" argument to be the address index of the next entry in the immediately upper page table level, or the address index of the last entry we wish to process, which ever is smaller.If it's larger than the address index of the next entry in the immediately upper page table level, then the effect of all these macros will be to walk off the end of the current level of page table.
Quoted 7 lines
To see how they _should_ be used, see the loops in
free_pgd_range()and thefree_pXX_range()functions called from there and below.In all cases when the
pXX_addr_end()macro was introduced, what I state above holds true - and I believe still holds true today, until this patch that has reportedly caused issues.
Thanks for your patience in explaining this for me.
I got your point. This is my fault in understanding the code.
Quoted 4 lines
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
Signature · 2 lines
Wei Yang Help you, Help me
PATCH 4/5 mm/mremap: calculate extent in one place
In reply to Wei YangPage tables is moved on the base of PMD. This requires both source and destination range should meet the requirement.
Current code works well since move_huge_pmd() and move_normal_pmd() would check old_addr and new_addr again. And then return to move_ptes() if the either of them is not aligned.
In stead of calculating the extent separately, it is better to calculate in one place, so we know it is not necessary to try move pmd. By doing so, the logic seems a little clear.
--- mm/mremap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
mm/mremap.c +4 -6
@@ -240,7 +240,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long new_addr, unsigned long len, bool need_rmap_locks) { - unsigned long extent, next, old_end; + unsigned long extent, old_next, new_next, old_end;struct mmu_notifier_range range;pmd_t *old_pmd, *new_pmd;
@@ -253,8 +253,9 @@ unsigned long move_page_tables(struct vm_area_struct *vma,for (; old_addr < old_end; old_addr += extent, new_addr += extent) {cond_resched (); - next =pmd_addr_end (old_addr, old_end); - extent = next - old_addr; + old_next =pmd_addr_end (old_addr, old_end); + new_next =pmd_addr_end (new_addr, new_addr + len); + extent =min ((old_next - old_addr), (new_next - new_addr)); old_pmd =get_old_pmd (vma->vm_mm, old_addr);if (!old_pmd)continue ;
@@ -298,9 +299,6 @@ unsigned long move_page_tables(struct vm_area_struct *vma,if (pte_alloc (new_vma->vm_mm, new_pmd))break ; - next =pmd_addr_end (new_addr, new_addr + len); -if (extent > next - new_addr) - extent = next - new_addr;move_ptes (vma, old_pmd, old_addr, old_addr + extent, new_vma, new_pmd, new_addr, need_rmap_locks); }
Signature · 1 line
2.17.1
PATCH 5/5 mm/mremap: start addresses are properly aligned
In reply to Wei YangAfter previous cleanup, extent is the minimal step for both source and destination. This means when extent is HPAGE_PMD_SIZE or PMD_SIZE, old_addr and new_addr are properly aligned too.
Since these two functions are only invoked in move_page_tables, it is safe to remove the check now.
--- mm/huge_memory.c | 3 --- mm/mremap.c | 3 --- 2 files changed, 6 deletions(-)
mm/huge_memory.c +0 -3
@@ -1878,9 +1878,6 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,struct mm_struct *mm = vma->vm_mm;bool force_flush = false; -if ((old_addr & ~HPAGE_PMD_MASK ) || (new_addr & ~HPAGE_PMD_MASK )) -return false; -/* * The destination pmd shouldn't be established, free_pgtables() * should have release it.
mm/mremap.c +0 -3
@@ -199,9 +199,6 @@ static bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr,struct mm_struct *mm = vma->vm_mm;pmd_t pmd; -if ((old_addr & ~PMD_MASK ) || (new_addr & ~PMD_MASK )) -return false; -/* * The destination pmd shouldn't be established, free_pgtables() * should have release it.
Signature · 1 line
2.17.1
Andrew Morton
maintainerQuoted 8 lines · On Sat, 18 Jan 2020 07:22:49 +0800 Wei Yang <[email protected]>…
move_page_tables()tries to move page table by PMD or PTE.The root reason is if it tries to move PMD, both old and new range should be PMD aligned. But current code calculate old range and new range separately. This leads to some redundant check and calculation.
This cleanup tries to consolidate the range check in one place to reduce some extra range handling.
Thanks, I grabbed these, aimed at 5.7-rc1.
Quoted 4 lines · Andrew Morton
Quoted 2 lines · On Sat, 18 Jan 2020 07:22:49 +0800 Wei Yang <[email protected]>…
move_page_tables()tries to move page table by PMD or PTE.
Quoted 8 lines
Quoted 6 lines
The root reason is if it tries to move PMD, both old and new range should be PMD aligned. But current code calculate old range and new range separately. This leads to some redundant check and calculation.
This cleanup tries to consolidate the range check in one place to reduce some extra range handling.
Thanks, I grabbed these, aimed at 5.7-rc1.
Thanks :)
Signature · 2 lines
Wei Yang Help you, Help me