Fix some bugs related to ramp and dax
Subsystems (7)
v5 cover Fix some bugs related to ramp and dax
This series is based on next-20220225.
Patch 1-2 fix a cache flush bug, because subsequent patches depend on those on those changes, there are placed in this series. Patch 3-4 are preparation for fixing a dax bug in patch 5. Patch 6 is code cleanup since the previous patch remove the usage of follow_invalidate_pte().
v5:
- Collect Reviewed-by from Dan Williams.
- Fix panic reported by kernel test robot <[email protected]>.
- Remove pmdpp parameter from follow_invalidate_pte() and fold it into follow_pte().
v4:
- Fix compilation error on riscv.
v3:
- Based on next-20220225.
v2:
- Avoid the overly long line in lots of places suggested by Christoph.
- Fix a compiler warning reported by kernel test robot since pmd_pfn() is not defined when !CONFIG_TRANSPARENT_HUGEPAGE on powerpc architecture.
- Split a new patch 4 for preparation of fixing the dax bug.
Muchun Song (6):
mm: rmap: fix cache flush on THP pages
dax: fix cache flush on PMD-mapped pages
mm: rmap: introduce pfn_mkclean_range() to cleans PTEs
mm: pvmw: add support for walking devmap pages
dax: fix missing writeprotect the pte entry
mm: simplify follow_invalidate_pte()
fs/dax.c | 82 +++++----------------------------------------------- include/linux/mm.h | 3 -- include/linux/rmap.h | 3 ++ mm/internal.h | 26 +++++++++++------ mm/memory.c | 81 +++++++++++++++------------------------------------ mm/page_vma_mapped.c | 16 +++++----- mm/rmap.c | 68 +++++++++++++++++++++++++++++++++++-------- 7 files changed, 114 insertions(+), 165 deletions(-)
Signature · 1 line
2.11.0
PATCH v5 1/6 mm: rmap: fix cache flush on THP pages
The flush_cache_page() only remove a PAGE_SIZE sized range from the cache. However, it does not cover the full pages in a THP except a head page. Replace it with flush_cache_range() to fix this issue. At least, no problems were found due to this. Maybe because the architectures that have virtual indexed caches is less.
--- mm/rmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/rmap.c +2 -1
@@ -970,7 +970,8 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,if (!pmd_dirty (*pmd) && !pmd_write (*pmd))continue ; -flush_cache_page (vma, address,folio_pfn (folio)); +flush_cache_range (vma, address, + address +HPAGE_PMD_SIZE ); entry =pmdp_invalidate (vma, address, pmd); entry =pmd_wrprotect (entry); entry =pmd_mkclean (entry);
Signature · 1 line
2.11.0
Re: [PATCH v5 1/6] mm: rmap: fix cache flush on THP pages
Quoted 10 lines · Muchun Song
The
flush_cache_page()only remove aPAGE_SIZEsized range from the cache. However, it does not cover the full pages in a THP except a head page. Replace it withflush_cache_range()to fix this issue. At least, no problems were found due to this. Maybe because the architectures that have virtual indexed caches is less.Fixes f27176cfc363 ("mm: convert page_mkclean_one() to use page_vma_mapped_walk()")Signed-off-by Muchun Song <[email protected]>Reviewed-by Yang Shi <[email protected]>Reviewed-by Dan Williams <[email protected]>
Looks good:
PATCH v5 2/6 dax: fix cache flush on PMD-mapped pages
In reply to Muchun SongThe flush_cache_page() only remove a PAGE_SIZE sized range from the cache. However, it does not cover the full pages in a THP except a head page. Replace it with flush_cache_range() to fix this issue. This is just a documentation issue with the respect to properly documenting the expected usage of cache flushing before modifying the pmd. However, in practice this is not a problem due to the fact that DAX is not available on architectures with virtually indexed caches per:
commit d92576f1167c ("dax: does not work correctly with virtual aliasing caches")
--- fs/dax.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dax.c +2 -1
@@ -845,7 +845,8 @@ static void dax_entry_mkclean(struct address_space *mapping, pgoff_t index,if (!pmd_dirty (*pmdp) && !pmd_write (*pmdp)) goto unlock_pmd; -flush_cache_page (vma, address, pfn); +flush_cache_range (vma, address, + address +HPAGE_PMD_SIZE ); pmd =pmdp_invalidate (vma, address, pmdp); pmd =pmd_wrprotect (pmd); pmd =pmd_mkclean (pmd);
Signature · 1 line
2.11.0
Re: [PATCH v5 2/6] dax: fix cache flush on PMD-mapped pages
Quoted 8 lines · Muchun Song
The
flush_cache_page()only remove aPAGE_SIZEsized range from the cache. However, it does not cover the full pages in a THP except a head page. Replace it withflush_cache_range()to fix this issue. This is just a documentation issue with the respect to properly documenting the expected usage of cache flushing before modifying the pmd. However, in practice this is not a problem due to the fact that DAX is not available on architectures with virtually indexed caches per:
Quoted 5 lines
commit
d92576f1167c("dax: does not work correctly with virtual aliasing caches")Fixes f729c8c9b24f ("dax: wrprotect pmd_t in dax_mapping_entry_mkclean")Signed-off-by Muchun Song <[email protected]>Reviewed-by Dan Williams <[email protected]>
Looks good:
PATCH v5 3/6 mm: rmap: introduce pfn_mkclean_range() to cleans PTEs
In reply to Muchun SongThe page_mkclean_one() is supposed to be used with the pfn that has a associated struct page, but not all the pfns (e.g. DAX) have a struct page. Introduce a new function pfn_mkclean_range() to cleans the PTEs (including PMDs) mapped with range of pfns which has no struct page associated with them. This helper will be used by DAX device in the next patch to make pfns clean.
--- include/linux/rmap.h | 3 +++ mm/internal.h | 26 +++++++++++++-------- mm/rmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 74 insertions(+), 20 deletions(-)
include/linux/rmap.h +3 -0
@@ -263,6 +263,9 @@ unsigned long page_address_in_vma(struct page *, struct vm_area_struct *);*/ int folio_mkclean (struct folio *); +int pfn_mkclean_range (unsigned long pfn,unsigned long nr_pages,pgoff_t pgoff, +struct vm_area_struct *vma); +void remove_migration_ptes (struct folio *src,struct folio *dst,bool locked);/*
mm/internal.h +17 -9
@@ -516,26 +516,22 @@ void mlock_page_drain(int cpu);extern pmd_t maybe_pmd_mkwrite (pmd_t pmd,struct vm_area_struct *vma);/* -* At what user virtual address is page expected in vma? -* Returns -EFAULT if all of the page is outside the range of vma. -* If page is a compound head, the entire compound page is considered. +* * Return the start of user virtual address at the specific offset within +* a vma. */ static inline unsigned long -vma_address (struct page *page,struct vm_area_struct *vma) +vma_pgoff_address (pgoff_t pgoff,unsigned long nr_pages, +struct vm_area_struct *vma) { -pgoff_t pgoff;unsigned long address; -VM_BUG_ON_PAGE (PageKsm (page), page);/* KSM page->index unusable */ - pgoff =page_to_pgoff (page);if (pgoff >= vma->vm_pgoff) { address = vma->vm_start + ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT );/* Check for address beyond vma (or wrapped through 0?) */ if (address < vma->vm_start || address >= vma->vm_end) address = -EFAULT ; - }else if (PageHead (page) && - pgoff +compound_nr (page) -1 >= vma->vm_pgoff) { + }else if (pgoff + nr_pages -1 >= vma->vm_pgoff) {/* Test above avoids possibility of wrap to 0 on 32-bit */ address = vma->vm_start; }else {
@@ -545,6 +541,18 @@ vma_address(struct page *page, struct vm_area_struct *vma) }/* +* Return the start of user virtual address of a page within a vma. +* Returns -EFAULT if all of the page is outside the range of vma. +* If page is a compound head, the entire compound page is considered. +*/ +static inline unsigned long +vma_address (struct page *page,struct vm_area_struct *vma) +{ +VM_BUG_ON_PAGE (PageKsm (page), page);/* KSM page->index unusable */ +return vma_pgoff_address (page_to_pgoff (page),compound_nr (page), vma); +} + +/* * Then at what user virtual address will none of the range be found in vma? * Assumes that vma_address() already returned a good starting address. */
mm/rmap.c +54 -11
106 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v5 4/6 mm: pvmw: add support for walking devmap pages
In reply to Muchun SongThe devmap pages can not use page_vma_mapped_walk() to check if a huge devmap page is mapped into a vma. Add support for walking huge devmap pages so that DAX can use it in the next patch.
--- mm/page_vma_mapped.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
mm/page_vma_mapped.c +8 -8
@@ -210,16 +210,9 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)*/ pmde =READ_ONCE (*pvmw->pmd); -if (pmd_trans_huge (pmde) ||is_pmd_migration_entry (pmde)) { +if (pmd_leaf (pmde) ||is_pmd_migration_entry (pmde)) { pvmw->ptl =pmd_lock (mm, pvmw->pmd); pmde = *pvmw->pmd; -if (likely (pmd_trans_huge (pmde))) { -if (pvmw->flags &PVMW_MIGRATION ) -return not_found (pvmw); -if (!check_pmd (pmd_pfn (pmde), pvmw)) -return not_found (pvmw); -return true; - }if (!pmd_present (pmde)) {swp_entry_t entry;
@@ -232,6 +225,13 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)return not_found (pvmw);return true; } +if (likely (pmd_trans_huge (pmde) ||pmd_devmap (pmde))) { +if (pvmw->flags &PVMW_MIGRATION ) +return not_found (pvmw); +if (!check_pmd (pmd_pfn (pmde), pvmw)) +return not_found (pvmw); +return true; + }/* THP pmd was split under us: handle on pte level */ spin_unlock (pvmw->ptl); pvmw->ptl =NULL ;
Signature · 1 line
2.11.0
PATCH v5 5/6 dax: fix missing writeprotect the pte entry
In reply to Muchun SongCurrently dax_mapping_entry_mkclean() fails to clean and write protect the pte entry within a DAX PMD entry during an *sync operation. This can result in data loss in the following sequence:
1) process A mmap write to DAX PMD, dirtying PMD radix tree entry and making the pmd entry dirty and writeable.
2) process B mmap with the @offset (e.g. 4K) and @length (e.g. 4K) write to the same file, dirtying PMD radix tree entry (already done in 1)) and making the pte entry dirty and writeable.
3) fsync, flushing out PMD data and cleaning the radix tree entry. We currently fail to mark the pte entry as clean and write protected since the vma of process B is not covered in dax_entry_mkclean().
4) process B writes to the pte. These don't cause any page faults since the pte entry is dirty and writeable. The radix tree entry remains clean.
5) fsync, which fails to flush the dirty PMD data because the radix tree entry was clean.
6) crash - dirty data that should have been fsync'd as part of 5) could still have been in the processor cache, and is lost.
Just to use pfn_mkclean_range() to clean the pfns to fix this issue.
--- fs/dax.c | 83 ++++++---------------------------------------------------------- 1 file changed, 7 insertions(+), 76 deletions(-)
fs/dax.c +7 -76
@@ -24,6 +24,7 @@#include <linux/sizes.h> #include <linux/mmu_notifier.h> #include <linux/iomap.h> +#include <linux/rmap.h> #include <asm/pgalloc.h> #define CREATE_TRACE_POINTS
@@ -789,87 +790,17 @@ static void *dax_insert_entry(struct xa_state *xas,return entry; } -static inline -unsigned long pgoff_address (pgoff_t pgoff,struct vm_area_struct *vma) -{ -unsigned long address; - - address = vma->vm_start + ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT ); -VM_BUG_ON_VMA (address < vma->vm_start || address >= vma->vm_end, vma); -return address; -} -/* Walk all mappings of a given index of a file and writeprotect them */ -static void dax_entry_mkclean (struct address_space *mapping,pgoff_t index, -unsigned long pfn) +static void dax_entry_mkclean (struct address_space *mapping,unsigned long pfn, +unsigned long npfn,pgoff_t start) {struct vm_area_struct *vma; -pte_t pte, *ptep =NULL ; -pmd_t *pmdp =NULL ; -spinlock_t *ptl; +pgoff_t end = start + npfn -1 ;i_mmap_lock_read (mapping); - vma_interval_tree_foreach(vma, &mapping->i_mmap, index, index) { -struct mmu_notifier_range range; -unsigned long address; - + vma_interval_tree_foreach(vma, &mapping->i_mmap, start, end) { +pfn_mkclean_range (pfn, npfn, start, vma);cond_resched (); - -if (!(vma->vm_flags &VM_SHARED )) -continue ; - - address =pgoff_address (index, vma); - -/* -* follow_invalidate_pte() will use the range to call -* mmu_notifier_invalidate_range_start() on our behalf before -* taking any lock. -*/ -if (follow_invalidate_pte (vma->vm_mm, address, &range, &ptep, - &pmdp, &ptl)) -continue ; - -/* -* No need to call mmu_notifier_invalidate_range() as we are -* downgrading page table protection not changing it to point -* to a new page. -* -* See Documentation/vm/mmu_notifier.rst -*/ -if (pmdp) { -#ifdef CONFIG_FS_DAX_PMD -pmd_t pmd; - -if (pfn !=pmd_pfn (*pmdp)) - goto unlock_pmd; -if (!pmd_dirty (*pmdp) && !pmd_write (*pmdp)) - goto unlock_pmd; - -flush_cache_range (vma, address, - address +HPAGE_PMD_SIZE ); - pmd =pmdp_invalidate (vma, address, pmdp); - pmd =pmd_wrprotect (pmd); - pmd =pmd_mkclean (pmd); -set_pmd_at (vma->vm_mm, address, pmdp, pmd); -unlock_pmd: -#endif -spin_unlock (ptl); - }else { -if (pfn !=pte_pfn (*ptep)) - goto unlock_pte; -if (!pte_dirty (*ptep) && !pte_write (*ptep)) - goto unlock_pte; - -flush_cache_page (vma, address, pfn); - pte =ptep_clear_flush (vma, address, ptep); - pte =pte_wrprotect (pte); - pte =pte_mkclean (pte); -set_pte_at (vma->vm_mm, address, ptep, pte); -unlock_pte: -pte_unmap_unlock (ptep, ptl); - } - -mmu_notifier_invalidate_range_end (&range); }i_mmap_unlock_read (mapping); }
@@ -937,7 +868,7 @@ static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev, count =1UL <<dax_entry_order (entry); index = xas->xa_index & ~(count -1 ); -dax_entry_mkclean (mapping, index, pfn); +dax_entry_mkclean (mapping, pfn, count, index);dax_flush (dax_dev,page_address (pfn_to_page (pfn)), count *PAGE_SIZE );/* * After we have flushed the cache, we can clear the dirty tag. There
Signature · 1 line
2.11.0
Re: [PATCH v5 5/6] dax: fix missing writeprotect the pte entry
fs/dax.c static void *dax_insert_entry(struct xa_state *xas, · line 805
Quoted 12 lines
fs/dax.c +5
-0+static void dax_entry_mkclean (struct address_space *mapping,unsigned long pfn, +unsigned long npfn,pgoff_t start) {struct vm_area_struct *vma; +pgoff_t end = start + npfn -1 ;i_mmap_lock_read (mapping); + vma_interval_tree_foreach(vma, &mapping->i_mmap, start, end) { +pfn_mkclean_range (pfn, npfn, start, vma);cond_resched (); }i_mmap_unlock_read (mapping);
Is there any point in even keeping this helper vs just open coding it in the only caller below?
Otherwise looks good:
Re: [PATCH v5 5/6] dax: fix missing writeprotect the pte entry
Quoted 15 lines · Christoph Hellwig
fs/dax.c static void *dax_insert_entry(struct xa_state *xas, · line 805
Quoted 13 lines
fs/dax.c +5
-0+static void dax_entry_mkclean (struct address_space *mapping,unsigned long pfn, +unsigned long npfn,pgoff_t start) {struct vm_area_struct *vma; +pgoff_t end = start + npfn -1 ;i_mmap_lock_read (mapping); + vma_interval_tree_foreach(vma, &mapping->i_mmap, start, end) { +pfn_mkclean_range (pfn, npfn, start, vma);cond_resched (); }i_mmap_unlock_read (mapping);
Quoted 2 lines
Is there any point in even keeping this helper vs just open coding it in the only caller below?
Good point. I'll fold dax_entry_mkclean() into the caller.
Quoted 4 lines
Otherwise looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Thanks.
PATCH v5 6/6 mm: simplify follow_invalidate_pte()
In reply to Muchun SongThe only user (DAX) of range and pmdpp parameters of follow_invalidate_pte() is gone, it is safe to remove them and make it static to simlify the code. This is revertant of the following commits:
097963959594 ("mm: add follow_pte_pmd()") a4d1a8852513 ("dax: update to new mmu_notifier semantic")
There is only one caller of the follow_invalidate_pte(). So just fold it into follow_pte() and remove it.
--- include/linux/mm.h | 3 -- mm/memory.c | 81 ++++++++++++++++-------------------------------------- 2 files changed, 23 insertions(+), 61 deletions(-)
include/linux/mm.h +0 -3
@@ -1871,9 +1871,6 @@ void free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, unsigned long floor, unsigned long ceiling);int copy_page_range (struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma); -int follow_invalidate_pte (struct mm_struct *mm,unsigned long address, -struct mmu_notifier_range *range,pte_t **ptepp, -pmd_t **pmdpp,spinlock_t **ptlp);int follow_pte (struct mm_struct *mm,unsigned long address,pte_t **ptepp,spinlock_t **ptlp); int follow_pfn(struct vm_area_struct *vma, unsigned long address,
mm/memory.c +23 -58
105 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH v5 6/6] mm: simplify follow_invalidate_pte()
Looks good:
Quoted 6 lines · Muchun Song
This series is based on next-20220225.
Patch 1-2 fix a cache flush bug, because subsequent patches depend on those on those changes, there are placed in this series. Patch 3-4 are preparation for fixing a dax bug in patch 5. Patch 6 is code cleanup since the previous patch remove the usage of
follow_invalidate_pte().
Reverting this series fixed boot crashes.
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f] Mem abort info: ESR = 0x96000004 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x04: level 0 translation fault Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 [dfff800000000003] address between user and kernel address ranges Internal error: Oops: 96000004 [#1] PREEMPT SMP Modules linked in: cdc_ether usbnet ipmi_devintf ipmi_msghandler cppc_cpufreq fuse ip_tables x_tables ipv6 btrfs blake2b_generic libcrc32c xor xor_neon raid6_pq zstd_compress dm_mod nouveau crct10dif_ce drm_ttm_helper mlx5_core ttm drm_dp_helper drm_kms_helper nvme mpt3sas nvme_core xhci_pci raid_class drm xhci_pci_renesas CPU: 3 PID: 1707 Comm: systemd-udevd Not tainted 5.17.0-next-20220331-00004-g2d550916a6b9 #51 pstate: 104000c9 (nzcV daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __lock_acquire lr : lock_acquire.part.0 sp : ffff800030a16fd0 x29: ffff800030a16fd0 x28: ffffdd876c4e9f90 x27: 0000000000000018 x26: 0000000000000000 x25: 0000000000000018 x24: 0000000000000000 x23: ffff08022beacf00 x22: ffffdd8772507660 x21: 0000000000000000 x20: 0000000000000000 x19: 0000000000000000 x18: ffffdd8772417d2c x17: ffffdd876c5bc2e0 x16: 1fffe100457d5b06 x15: 0000000000000094 x14: 000000000000f1f1 x13: 00000000f3f3f3f3 x12: ffff08022beacf08 x11: 1ffffbb0ee482fa5 x10: ffffdd8772417d28 x9 : 0000000000000000 x8 : 0000000000000003 x7 : ffffdd876c4e9f90 x6 : 0000000000000000 x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000000000000003 x0 : dfff800000000000 Call trace: __lock_acquire lock_acquire.part.0 lock_acquire _raw_spin_lock page_vma_mapped_walk try_to_migrate_one rmap_walk_anon try_to_migrate __unmap_and_move unmap_and_move migrate_pages migrate_misplaced_page do_huge_pmd_numa_page __handle_mm_fault handle_mm_fault do_translation_fault do_mem_abort el0_da el0t_64_sync_handler el0t_64_sync Code: d65f03c0 d343ff61 d2d00000 f2fbffe0 (38e06820) ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Oops: Fatal exception SMP: stopping secondary CPUs Kernel Offset: 0x5d8763da0000 from 0xffff800008000000 PHYS_OFFSET: 0x80000000 CPU features: 0x000,00085c0d,19801c82 Memory Limit: none ---[ end Kernel panic - not syncing: Oops: Fatal exception ]---
Quoted 38 lines
v5:
- Collect Reviewed-by from Dan Williams.
- Fix panic reported by kernel test robot <[email protected]>.
- Remove pmdpp parameter fromfollow_invalidate_pte()and fold it intofollow_pte().v4:
- Fix compilation error on riscv.v3:
- Based on next-20220225.v2:
- Avoid the overly long line in lots of places suggested by Christoph.
- Fix a compiler warning reported by kernel test robot sincepmd_pfn()is not defined when !CONFIG_TRANSPARENT_HUGEPAGE on powerpc architecture.
- Split a new patch 4 for preparation of fixing the dax bug.Muchun Song (6):
mm: rmap: fix cache flush on THP pages
dax: fix cache flush on PMD-mapped pages
mm: rmap: introducepfn_mkclean_range()to cleans PTEs
mm: pvmw: add support for walking devmap pages
dax: fix missing writeprotect the pte entry
mm: simplifyfollow_invalidate_pte()fs/dax.c | 82 +++++----------------------------------------------- include/linux/mm.h | 3 -- include/linux/rmap.h | 3 ++ mm/internal.h | 26 +++++++++++------ mm/memory.c | 81 +++++++++++++++------------------------------------ mm/page_vma_mapped.c | 16 +++++----- mm/rmap.c | 68 +++++++++++++++++++++++++++++++++++-------- 7 files changed, 114 insertions(+), 165 deletions(-)Signature · 1 line
2.11.0
Andrew Morton
maintainerQuoted 10 lines · On Thu, 31 Mar 2022 11:55:47 -0400 Qian Cai <[email protected]> wrote:
Quoted 6 lines · Muchun Song
This series is based on next-20220225.
Patch 1-2 fix a cache flush bug, because subsequent patches depend on those on those changes, there are placed in this series. Patch 3-4 are preparation for fixing a dax bug in patch 5. Patch 6 is code cleanup since the previous patch remove the usage of
follow_invalidate_pte().Reverting this series fixed boot crashes.
Thanks. I'll drop
mm-rmap-fix-cache-flush-on-thp-pages.patch dax-fix-cache-flush-on-pmd-mapped-pages.patch mm-rmap-introduce-pfn_mkclean_range-to-cleans-ptes.patch mm-rmap-introduce-pfn_mkclean_range-to-cleans-ptes-fix.patch mm-pvmw-add-support-for-walking-devmap-pages.patch dax-fix-missing-writeprotect-the-pte-entry.patch dax-fix-missing-writeprotect-the-pte-entry-v6.patch mm-simplify-follow_invalidate_pte.patch
Hi Andrew,
Quoted 11 lines · On Thu, 31 Mar 2022 15:36:04 -0700 Andrew Morton <[email protected]>…
Thanks. I'll drop
mm-rmap-fix-cache-flush-on-thp-pages.patch dax-fix-cache-flush-on-pmd-mapped-pages.patch mm-rmap-introduce-pfn_mkclean_range-to-cleans-ptes.patch mm-rmap-introduce-pfn_mkclean_range-to-cleans-ptes-fix.patch mm-pvmw-add-support-for-walking-devmap-pages.patch dax-fix-missing-writeprotect-the-pte-entry.patch dax-fix-missing-writeprotect-the-pte-entry-v6.patch mm-simplify-follow_invalidate_pte.patch
I have removed those and the 4 patches that I had to revert yesterday.
Signature · 2 lines
Cheers, Stephen Rothwell
Quoted 61 lines · Qian Cai
Quoted 6 lines · Muchun Song
This series is based on next-20220225.
Patch 1-2 fix a cache flush bug, because subsequent patches depend on those on those changes, there are placed in this series. Patch 3-4 are preparation for fixing a dax bug in patch 5. Patch 6 is code cleanup since the previous patch remove the usage of
follow_invalidate_pte().Reverting this series fixed boot crashes.
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f] Mem abort info: ESR = 0x96000004 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x04: level 0 translation fault Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 [dfff800000000003] address between user and kernel address ranges Internal error: Oops: 96000004 [#1] PREEMPT SMP Modules linked in: cdc_ether usbnet ipmi_devintf ipmi_msghandler cppc_cpufreq fuse ip_tables x_tables ipv6 btrfs blake2b_generic libcrc32c xor xor_neon raid6_pq zstd_compress dm_mod nouveau crct10dif_ce drm_ttm_helper mlx5_core ttm drm_dp_helper drm_kms_helper nvme mpt3sas nvme_core xhci_pci raid_class drm xhci_pci_renesas CPU: 3 PID: 1707 Comm: systemd-udevd Not tainted 5.17.0-next-20220331-00004-g2d550916a6b9 #51 pstate: 104000c9 (nzcV daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __lock_acquire lr : lock_acquire.part.0 sp : ffff800030a16fd0 x29: ffff800030a16fd0 x28: ffffdd876c4e9f90 x27: 0000000000000018 x26: 0000000000000000 x25: 0000000000000018 x24: 0000000000000000 x23: ffff08022beacf00 x22: ffffdd8772507660 x21: 0000000000000000 x20: 0000000000000000 x19: 0000000000000000 x18: ffffdd8772417d2c x17: ffffdd876c5bc2e0 x16: 1fffe100457d5b06 x15: 0000000000000094 x14: 000000000000f1f1 x13: 00000000f3f3f3f3 x12: ffff08022beacf08 x11: 1ffffbb0ee482fa5 x10: ffffdd8772417d28 x9 : 0000000000000000 x8 : 0000000000000003 x7 : ffffdd876c4e9f90 x6 : 0000000000000000 x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000000000000003 x0 : dfff800000000000 Call trace: __lock_acquire lock_acquire.part.0 lock_acquire _raw_spin_lock page_vma_mapped_walk try_to_migrate_one rmap_walk_anon try_to_migrate __unmap_and_move unmap_and_move migrate_pages migrate_misplaced_page do_huge_pmd_numa_page __handle_mm_fault handle_mm_fault do_translation_fault do_mem_abort el0_da el0t_64_sync_handler el0t_64_sync Code: d65f03c0 d343ff61 d2d00000 f2fbffe0 (38e06820)
Quoted 8 lines
---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Oops: Fatal exception SMP: stopping secondary CPUs Kernel Offset: 0x5d8763da0000 from 0xffff800008000000 PHYS_OFFSET: 0x80000000 CPU features: 0x000,00085c0d,19801c82 Memory Limit: none ---[ end Kernel panic - not syncing: Oops: Fatal exception ]---
Thanks for your report. Would you mind providing the .config?
Quoted 72 lines · Muchun Song
Quoted 61 lines · Qian Cai
Quoted 6 lines · Muchun Song
This series is based on next-20220225.
Patch 1-2 fix a cache flush bug, because subsequent patches depend on those on those changes, there are placed in this series. Patch 3-4 are preparation for fixing a dax bug in patch 5. Patch 6 is code cleanup since the previous patch remove the usage of
follow_invalidate_pte().Reverting this series fixed boot crashes.
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f] Mem abort info: ESR = 0x96000004 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x04: level 0 translation fault Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 [dfff800000000003] address between user and kernel address ranges Internal error: Oops: 96000004 [#1] PREEMPT SMP Modules linked in: cdc_ether usbnet ipmi_devintf ipmi_msghandler cppc_cpufreq fuse ip_tables x_tables ipv6 btrfs blake2b_generic libcrc32c xor xor_neon raid6_pq zstd_compress dm_mod nouveau crct10dif_ce drm_ttm_helper mlx5_core ttm drm_dp_helper drm_kms_helper nvme mpt3sas nvme_core xhci_pci raid_class drm xhci_pci_renesas CPU: 3 PID: 1707 Comm: systemd-udevd Not tainted 5.17.0-next-20220331-00004-g2d550916a6b9 #51 pstate: 104000c9 (nzcV daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __lock_acquire lr : lock_acquire.part.0 sp : ffff800030a16fd0 x29: ffff800030a16fd0 x28: ffffdd876c4e9f90 x27: 0000000000000018 x26: 0000000000000000 x25: 0000000000000018 x24: 0000000000000000 x23: ffff08022beacf00 x22: ffffdd8772507660 x21: 0000000000000000 x20: 0000000000000000 x19: 0000000000000000 x18: ffffdd8772417d2c x17: ffffdd876c5bc2e0 x16: 1fffe100457d5b06 x15: 0000000000000094 x14: 000000000000f1f1 x13: 00000000f3f3f3f3 x12: ffff08022beacf08 x11: 1ffffbb0ee482fa5 x10: ffffdd8772417d28 x9 : 0000000000000000 x8 : 0000000000000003 x7 : ffffdd876c4e9f90 x6 : 0000000000000000 x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000000000000003 x0 : dfff800000000000 Call trace: __lock_acquire lock_acquire.part.0 lock_acquire _raw_spin_lock page_vma_mapped_walk try_to_migrate_one rmap_walk_anon try_to_migrate __unmap_and_move unmap_and_move migrate_pages migrate_misplaced_page do_huge_pmd_numa_page __handle_mm_fault handle_mm_fault do_translation_fault do_mem_abort el0_da el0t_64_sync_handler el0t_64_sync Code: d65f03c0 d343ff61 d2d00000 f2fbffe0 (38e06820)Quoted 8 lines
---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Oops: Fatal exception SMP: stopping secondary CPUs Kernel Offset: 0x5d8763da0000 from 0xffff800008000000 PHYS_OFFSET: 0x80000000 CPU features: 0x000,00085c0d,19801c82 Memory Limit: none ---[ end Kernel panic - not syncing: Oops: Fatal exception ]---
Quoted 1 line
Thanks for your report. Would you mind providing the .config?
Hi Qian Cai,
Would you mind helping me test if the following patch works properly? Thanks.
mm/page_vma_mapped.c +2 -1
@@ -210,7 +210,8 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)*/ pmde =READ_ONCE (*pvmw->pmd); -if (pmd_leaf (pmde) ||is_pmd_migration_entry (pmde)) { +if (pmd_trans_huge (pmde) ||is_pmd_migration_entry (pmde) || + (pmd_present (pmde) &&pmd_devmap (pmde))) { pvmw->ptl =pmd_lock (mm, pvmw->pmd); pmde = *pvmw->pmd;if (!pmd_present (pmde)) {
Quoted 1 line · Muchun Song
Thanks for your report. Would you mind providing the .config?
$ make ARCH=arm64 defconfig debug.config
Quoted 53 lines · Qian Cai
Quoted 6 lines · Muchun Song
This series is based on next-20220225.
Patch 1-2 fix a cache flush bug, because subsequent patches depend on those on those changes, there are placed in this series. Patch 3-4 are preparation for fixing a dax bug in patch 5. Patch 6 is code cleanup since the previous patch remove the usage of
follow_invalidate_pte().Reverting this series fixed boot crashes.
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f] Mem abort info: ESR = 0x96000004 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x04: level 0 translation fault Data abort info: ISV = 0, ISS = 0x00000004 CM = 0, WnR = 0 [dfff800000000003] address between user and kernel address ranges Internal error: Oops: 96000004 [#1] PREEMPT SMP Modules linked in: cdc_ether usbnet ipmi_devintf ipmi_msghandler cppc_cpufreq fuse ip_tables x_tables ipv6 btrfs blake2b_generic libcrc32c xor xor_neon raid6_pq zstd_compress dm_mod nouveau crct10dif_ce drm_ttm_helper mlx5_core ttm drm_dp_helper drm_kms_helper nvme mpt3sas nvme_core xhci_pci raid_class drm xhci_pci_renesas CPU: 3 PID: 1707 Comm: systemd-udevd Not tainted 5.17.0-next-20220331-00004-g2d550916a6b9 #51 pstate: 104000c9 (nzcV daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __lock_acquire lr : lock_acquire.part.0 sp : ffff800030a16fd0 x29: ffff800030a16fd0 x28: ffffdd876c4e9f90 x27: 0000000000000018 x26: 0000000000000000 x25: 0000000000000018 x24: 0000000000000000 x23: ffff08022beacf00 x22: ffffdd8772507660 x21: 0000000000000000 x20: 0000000000000000 x19: 0000000000000000 x18: ffffdd8772417d2c x17: ffffdd876c5bc2e0 x16: 1fffe100457d5b06 x15: 0000000000000094 x14: 000000000000f1f1 x13: 00000000f3f3f3f3 x12: ffff08022beacf08 x11: 1ffffbb0ee482fa5 x10: ffffdd8772417d28 x9 : 0000000000000000 x8 : 0000000000000003 x7 : ffffdd876c4e9f90 x6 : 0000000000000000 x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000000000000003 x0 : dfff800000000000 Call trace: __lock_acquire lock_acquire.part.0 lock_acquire _raw_spin_lock page_vma_mapped_walk try_to_migrate_one rmap_walk_anon try_to_migrate __unmap_and_move unmap_and_move migrate_pages migrate_misplaced_page do_huge_pmd_numa_page
Quoted 8 lines
__handle_mm_fault handle_mm_fault do_translation_fault do_mem_abort el0_da el0t_64_sync_handler el0t_64_sync Code: d65f03c0 d343ff61 d2d00000 f2fbffe0 (38e06820)
Hi,
I have found the root cause. It is because the implementation of pmd_leaf() on arm64 is wrong. It didn't consider the PROT_NONE mapped PMD, which does not match the expectation of pmd_leaf(). I'll send a fixed patch for arm64 like the following.
arch/arm64/include/asm/pgtable.h +0 -0
@@ -535,7 +535,7 @@ extern pgprot_t phys_mem_access_prot(struct file
*file, unsigned long pfn,
PMD_TYPE_TABLE)
#define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \
PMD_TYPE_SECT)
-#define pmd_leaf(pmd) pmd_sect(pmd)
+#define pmd_leaf(pmd) (pmd_present(pmd) && !(pmd_val(pmd) &PMD_TABLE_BIT))
#define pmd_bad(pmd) (!pmd_table(pmd))
#define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE)
Thanks.