mm/migrate_device: fix cache flush when replacing huge zero PMD
Subsystems (2)
PATCH 1/1 mm/migrate_device: fix cache flush when replacing huge zero PMD
migrate_vma_insert_huge_pmd_page() calls flush_cache_page() before replacing an existing huge zero PMD. However, the third argument to flush_cache_page() is a PFN, while addr + HPAGE_PMD_SIZE is an end virtual address.
More importantly, the mapping being invalidated is PMD-sized rather than PAGE_SIZE-sized. Flush the whole PMD range with flush_cache_range(), matching other huge PMD invalidation paths.
--- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate_device.c +1 -1
@@ -872,7 +872,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,if (flush) {pte_free (vma->vm_mm, pgtable); -flush_cache_page (vma, addr, addr +HPAGE_PMD_SIZE ); +flush_cache_range (vma, addr, addr +HPAGE_PMD_SIZE );pmdp_invalidate (vma, addr, pmdp); }else {pgtable_trans_huge_deposit (vma->vm_mm, pmdp, pgtable);
Signature · 1 line
2.54.0
Quoted 20 lines · Hui Su
migrate_vma_insert_huge_pmd_page()callsflush_cache_page()before replacing an existing huge zero PMD. However, the third argument toflush_cache_page()is a PFN, while addr +HPAGE_PMD_SIZEis an end virtual address.More importantly, the mapping being invalidated is PMD-sized rather than PAGE_SIZE-sized. Flush the whole PMD range with
flush_cache_range(), matching other huge PMD invalidation paths.Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Hui Su <[email protected]>--- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/migrate_device.c +0
-0
mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 878
Quoted 8 lines
mm/migrate_device.c +1
-1@@ -872,7 +872,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,if (flush) {pte_free (vma->vm_mm, pgtable); -flush_cache_page (vma, addr, addr +HPAGE_PMD_SIZE ); +flush_cache_range (vma, addr, addr +HPAGE_PMD_SIZE );pmdp_invalidate (vma, addr, pmdp); }else {pgtable_trans_huge_deposit (vma->vm_mm, pmdp, pgtable);
Andrew Morton
maintainerQuoted 22 lines · On Mon, 17 Aug 2026 17:35:53 +1000 Balbir Singh <[email protected]> wrote:
Quoted 21 lines · Hui Su
migrate_vma_insert_huge_pmd_page()callsflush_cache_page()before replacing an existing huge zero PMD. However, the third argument toflush_cache_page()is a PFN, while addr +HPAGE_PMD_SIZEis an end virtual address.More importantly, the mapping being invalidated is PMD-sized rather than PAGE_SIZE-sized. Flush the whole PMD range with
flush_cache_range(), matching other huge PMD invalidation paths.Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Hui Su <[email protected]>--- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/migrate_device.c +0
-0@@ -872,7 +872,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
Quoted 9 lines
mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 878
Quoted 7 lines
mm/migrate_device.c +1
-1if (flush) {pte_free (vma->vm_mm, pgtable); -flush_cache_page (vma, addr, addr +HPAGE_PMD_SIZE ); +flush_cache_range (vma, addr, addr +HPAGE_PMD_SIZE );pmdp_invalidate (vma, addr, pmdp); }else {pgtable_trans_huge_deposit (vma->vm_mm, pmdp, pgtable);Reviewed-by Balbir Singh <[email protected]>
doh. It's a shame this actually compiled...
Can we add some speculation about the userspace-visible effects of the bug?
I'm assuming we should backport the fix?
Quoted 34 lines · On Mon, 17 Aug 2026 17:35:53 +1000 Balbir Singh <[email protected]> wrote:
Quoted 23 lines · Hui Su
Quoted 21 lines
migrate_vma_insert_huge_pmd_page()callsflush_cache_page()before replacing an existing huge zero PMD. However, the third argument toflush_cache_page()is a PFN, while addr +HPAGE_PMD_SIZEis an end virtual address.More importantly, the mapping being invalidated is PMD-sized rather than PAGE_SIZE-sized. Flush the whole PMD range with
flush_cache_range(), matching other huge PMD invalidation paths.Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Hui Su <[email protected]>--- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/migrate_device.c +0
-0@@ -872,7 +872,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,Quoted 9 lines
mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 878
Quoted 7 lines
mm/migrate_device.c +1
-1if (flush) {pte_free (vma->vm_mm, pgtable); -flush_cache_page (vma, addr, addr +HPAGE_PMD_SIZE ); +flush_cache_range (vma, addr, addr +HPAGE_PMD_SIZE );pmdp_invalidate (vma, addr, pmdp); }else {pgtable_trans_huge_deposit (vma->vm_mm, pmdp, pgtable);Reviewed-by Balbir Singh <[email protected]>
Quoted 6 lines
doh. It's a shame this actually compiled...
Can we add some speculation about the userspace-visible effects of the bug?
I'm assuming we should backport the fix?
Hi,
I took a closer look at this, there is no userspace-visible effect today.
The architectures that currently enable ARCH_ENABLE_THP_MIGRATION use no-op implementations of flush_cache_page()/flush_cache_range(). 32-bit ARM has non-trivial implementations, but does not enable ARCH_ENABLE_THP_MIGRATION.
So this appears to be a latent API misuse rather than a currently observable bug, and I don't think a stable backport is necessary.
Should I resend a v2 clarifying the userspace-visible effect in the changelog?
Thanks,
Hui
Andrew Morton
maintainerQuoted 25 lines · On Tue, 18 Aug 2026 00:36:46 +0800 Hui Su <[email protected]> wrote:
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
mm/migrate_device.c +0
-0@@ -872,7 +872,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,Quoted 9 lines
mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 878
Quoted 7 lines
mm/migrate_device.c +1
-1if (flush) {pte_free (vma->vm_mm, pgtable); -flush_cache_page (vma, addr, addr +HPAGE_PMD_SIZE ); +flush_cache_range (vma, addr, addr +HPAGE_PMD_SIZE );pmdp_invalidate (vma, addr, pmdp); }else {pgtable_trans_huge_deposit (vma->vm_mm, pmdp, pgtable);Reviewed-by Balbir Singh <[email protected]>Quoted 6 lines
doh. It's a shame this actually compiled...
Can we add some speculation about the userspace-visible effects of the bug?
I'm assuming we should backport the fix?
Hi,
I took a closer look at this, there is no userspace-visible effect today.
Quoted 7 lines
The architectures that currently enable
ARCH_ENABLE_THP_MIGRATIONuse no-op implementations of flush_cache_page()/flush_cache_range(). 32-bit ARM has non-trivial implementations, but does not enableARCH_ENABLE_THP_MIGRATION.So this appears to be a latent API misuse rather than a currently observable bug, and I don't think a stable backport is necessary.
OK, thanks for checking.
Quoted 2 lines
Should I resend a v2 clarifying the userspace-visible effect in the changelog?
Yes please, after 7.3-rc1.
Quoted 35 lines · Andrew Morton
Quoted 25 lines · On Tue, 18 Aug 2026 00:36:46 +0800 Hui Su <[email protected]> wrote:
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
mm/migrate_device.c +0
-0@@ -872,7 +872,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,Quoted 9 lines
mm/migrate_device.c static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, · line 878
Quoted 7 lines
mm/migrate_device.c +1
-1if (flush) {pte_free (vma->vm_mm, pgtable); -flush_cache_page (vma, addr, addr +HPAGE_PMD_SIZE ); +flush_cache_range (vma, addr, addr +HPAGE_PMD_SIZE );pmdp_invalidate (vma, addr, pmdp); }else {pgtable_trans_huge_deposit (vma->vm_mm, pmdp, pgtable);Reviewed-by Balbir Singh <[email protected]>Quoted 6 lines
doh. It's a shame this actually compiled...
Can we add some speculation about the userspace-visible effects of the bug?
I'm assuming we should backport the fix?
Hi,
I took a closer look at this, there is no userspace-visible effect today.
Quoted 7 lines
The architectures that currently enable
ARCH_ENABLE_THP_MIGRATIONuse no-op implementations of flush_cache_page()/flush_cache_range(). 32-bit ARM has non-trivial implementations, but does not enableARCH_ENABLE_THP_MIGRATION.So this appears to be a latent API misuse rather than a currently observable bug, and I don't think a stable backport is necessary.
Quoted 6 lines
OK, thanks for checking.
Quoted 2 lines
Should I resend a v2 clarifying the userspace-visible effect in the changelog?
Yes please, after 7.3-rc1.
I have been running some tests at my end, I have some new ones, nothing so far exposes this. Thanks for checking Hui!
Balbir
Andrew Morton
maintainerQuoted 12 lines · On Mon, 17 Aug 2026 14:34:15 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines
Hi,
I took a closer look at this, there is no userspace-visible effect today.
The architectures that currently enable
ARCH_ENABLE_THP_MIGRATIONuse no-op implementations of flush_cache_page()/flush_cache_range(). 32-bit ARM has non-trivial implementations, but does not enableARCH_ENABLE_THP_MIGRATION.So this appears to be a latent API misuse rather than a currently observable bug, and I don't think a stable backport is necessary.
Quoted 6 lines
OK, thanks for checking.
Quoted 2 lines
Should I resend a v2 clarifying the userspace-visible effect in the changelog?
Yes please, after 7.3-rc1.
Actually, I updated the changelog and added it to next week's queue-for-Linus.
Quoted 9 lines · Hui Su
migrate_vma_insert_huge_pmd_page()callsflush_cache_page()before replacing an existing huge zero PMD. However, the third argument toflush_cache_page()is a PFN, while addr +HPAGE_PMD_SIZEis an end virtual address.More importantly, the mapping being invalidated is PMD-sized rather than PAGE_SIZE-sized. Flush the whole PMD range with
flush_cache_range(), matching other huge PMD invalidation paths.
Quoted 6 lines
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Hui Su <[email protected]>--- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thank you for fixing it.
Signature · 2 lines
Best Regards, Yan, Zi
Quoted 17 lines · Zi Yan
Quoted 9 lines · Hui Su
migrate_vma_insert_huge_pmd_page()callsflush_cache_page()before replacing an existing huge zero PMD. However, the third argument toflush_cache_page()is a PFN, while addr +HPAGE_PMD_SIZEis an end virtual address.More importantly, the mapping being invalidated is PMD-sized rather than PAGE_SIZE-sized. Flush the whole PMD range with
flush_cache_range(), matching other huge PMD invalidation paths.Quoted 6 lines
Fixes a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")Signed-off-by Hui Su <[email protected]>--- mm/migrate_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines
Thank you for fixing it.
Reviewed-by Zi Yan <[email protected]>
I do wonder whether there should be a PMD helper.
Signature · 3 lines
Cheers, David