New page table range API
Subsystems (30)
Matthew Wilcox (Oracle)
maintainerv3 cover New page table range API
This patchset changes the API used by the MM to set up page table entries. The four APIs are:
set_ptes(mm, addr, ptep, pte, nr) update_mmu_cache_range(vma, addr, ptep, nr) flush_dcache_folio(folio)
flush_icache_pages(vma, page, nr)
flush_dcache_folio() isn't technically new, but no architecture implemented it, so I've done that for you. The old APIs remain around but are mostly implemented by calling the new interfaces.
The new APIs are based around setting up N page table entries at once. The N entries belong to the same PMD, the same folio and the same VMA, so ptep++ is a legitimate operation, and locking is taken care of for you. Some architectures can do a better job of it than just a loop, but I have hesitated to make too deep a change to architectures I don't understand well.
One thing I have changed in every architecture is that PG_arch_1 is now a per-folio bit instead of a per-page bit. This was something that would have to happen eventually, and it makes sense to do it now rather than iterate over every page involved in a cache flush and figure out if it needs to happen.
The point of all this is better performance, and Fengwei Yin has measured improvement on x86. I suspect you'll see improvement on your architecture too. Try the new will-it-scale test mentioned here:
https://lore.kernel.org/linux-mm/[email protected]/
You'll need to run it on an XFS filesystem and have CONFIG_TRANSPARENT_HUGEPAGE set.
For testing, I've only run the code on x86. If an x86->foo compiler exists in Debian, I've built defconfig. I'm relying on the buildbots to tell me what I missed, and people who actually have the hardware to tell me if it actually works.
I'd like to get this into the MM tree soon after the current merge window closes, so quick feedback would be appreciated.
v3:
- Reinstate flush_dcache_icache_phys() on PowerPC
- Fix folio_flush_mapping(). The documentation was correct and the implementation was completely wrong
- Change the flush_dcache_page() documentation to describe flush_dcache_folio() instead
- Split ARM from ARC. I messed up my git commands
- Remove page_mapping_file()
- Rationalise how flush_icache_pages() and flush_icache_page() are defined
- Use flush_icache_pages() in do_set_pmd()
- Pick up Guo Ren's Ack for csky
Matthew Wilcox (Oracle) (30):
mm: Convert page_table_check_pte_set() to page_table_check_ptes_set()
mm: Add generic flush_icache_pages() and documentation
mm: Add folio_flush_mapping()
mm: Remove ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO
alpha: Implement the new page table range API
arc: Implement the new page table range API
arm: Implement the new page table range API
arm64: Implement the new page table range API
csky: Implement the new page table range API
hexagon: Implement the new page table range API
ia64: Implement the new page table range API
loongarch: Implement the new page table range API
m68k: Implement the new page table range API
microblaze: Implement the new page table range API
mips: Implement the new page table range API
nios2: Implement the new page table range API
openrisc: Implement the new page table range API
parisc: Implement the new page table range API
powerpc: Implement the new page table range API
riscv: Implement the new page table range API
s390: Implement the new page table range API
superh: Implement the new page table range API
sparc32: Implement the new page table range API
sparc64: Implement the new page table range API
um: Implement the new page table range API
x86: Implement the new page table range API
xtensa: Implement the new page table range API
mm: Remove page_mapping_file()
mm: Rationalise flush_icache_pages() and flush_icache_page()
mm: Use flush_icache_pages() in do_set_pmd()
Yin Fengwei (4):
filemap: Add filemap_map_folio_range()
rmap: add folio_add_file_rmap_range()
mm: Convert do_set_pte() to set_pte_range()
filemap: Batch PTE mappings
Documentation/core-api/cachetlb.rst | 51 +++++----- Documentation/filesystems/locking.rst | 2 +- arch/alpha/include/asm/cacheflush.h | 13 ++- arch/alpha/include/asm/pgtable.h | 18 +++- arch/arc/include/asm/cacheflush.h | 14 +-- arch/arc/include/asm/pgtable-bits-arcv2.h | 20 +++- arch/arc/mm/cache.c | 61 +++++++----- arch/arc/mm/tlb.c | 18 ++-- arch/arm/include/asm/cacheflush.h | 29 +++--- arch/arm/include/asm/pgtable.h | 5 +- arch/arm/include/asm/tlbflush.h | 13 ++- arch/arm/mm/copypage-v4mc.c | 5 +- arch/arm/mm/copypage-v6.c | 5 +- arch/arm/mm/copypage-xscale.c | 5 +- arch/arm/mm/dma-mapping.c | 24 ++--- arch/arm/mm/fault-armv.c | 14 +-- arch/arm/mm/flush.c | 99 +++++++++++-------- arch/arm/mm/mm.h | 2 +- arch/arm/mm/mmu.c | 14 ++- arch/arm64/include/asm/cacheflush.h | 4 +- arch/arm64/include/asm/pgtable.h | 25 +++-- arch/arm64/mm/flush.c | 36 +++---- arch/csky/abiv1/cacheflush.c | 32 ++++--- arch/csky/abiv1/inc/abi/cacheflush.h | 3 +- arch/csky/abiv2/cacheflush.c | 30 +++--- arch/csky/abiv2/inc/abi/cacheflush.h | 11 ++- arch/csky/include/asm/pgtable.h | 21 +++- arch/hexagon/include/asm/cacheflush.h | 9 +- arch/hexagon/include/asm/pgtable.h | 16 +++- arch/ia64/hp/common/sba_iommu.c | 26 ++--- arch/ia64/include/asm/cacheflush.h | 14 ++- arch/ia64/include/asm/pgtable.h | 14 ++- arch/ia64/mm/init.c | 29 ++++-- arch/loongarch/include/asm/cacheflush.h | 2 +- arch/loongarch/include/asm/pgtable.h | 30 ++++-- arch/m68k/include/asm/cacheflush_mm.h | 25 +++-- arch/m68k/include/asm/pgtable_mm.h | 21 +++- arch/m68k/mm/motorola.c | 2 +- arch/microblaze/include/asm/cacheflush.h | 8 ++ arch/microblaze/include/asm/pgtable.h | 17 +++- arch/microblaze/include/asm/tlbflush.h | 4 +- arch/mips/include/asm/cacheflush.h | 32 ++++--- arch/mips/include/asm/pgtable.h | 36 ++++--- arch/mips/mm/c-r4k.c | 5 +- arch/mips/mm/cache.c | 56 +++++------ arch/mips/mm/init.c | 17 ++-- arch/nios2/include/asm/cacheflush.h | 6 +- arch/nios2/include/asm/pgtable.h | 27 ++++-- arch/nios2/mm/cacheflush.c | 62 ++++++------ arch/openrisc/include/asm/cacheflush.h | 8 +- arch/openrisc/include/asm/pgtable.h | 27 +++++- arch/openrisc/mm/cache.c | 12 ++- arch/parisc/include/asm/cacheflush.h | 14 ++- arch/parisc/include/asm/pgtable.h | 28 ++++-- arch/parisc/kernel/cache.c | 101 ++++++++++++++------ arch/powerpc/include/asm/book3s/pgtable.h | 10 +- arch/powerpc/include/asm/cacheflush.h | 14 ++- arch/powerpc/include/asm/kvm_ppc.h | 10 +- arch/powerpc/include/asm/nohash/pgtable.h | 13 +-- arch/powerpc/include/asm/pgtable.h | 6 ++ arch/powerpc/mm/book3s64/hash_utils.c | 11 ++- arch/powerpc/mm/cacheflush.c | 40 +++----- arch/powerpc/mm/nohash/e500_hugetlbpage.c | 3 +- arch/powerpc/mm/pgtable.c | 51 +++++----- arch/riscv/include/asm/cacheflush.h | 19 ++-- arch/riscv/include/asm/pgtable.h | 26 +++-- arch/riscv/mm/cacheflush.c | 11 +-- arch/s390/include/asm/pgtable.h | 34 +++++-- arch/sh/include/asm/cacheflush.h | 21 ++-- arch/sh/include/asm/pgtable.h | 6 +- arch/sh/include/asm/pgtable_32.h | 16 +++- arch/sh/mm/cache-j2.c | 4 +- arch/sh/mm/cache-sh4.c | 26 +++-- arch/sh/mm/cache-sh7705.c | 26 +++-- arch/sh/mm/cache.c | 54 ++++++----- arch/sh/mm/kmap.c | 3 +- arch/sparc/include/asm/cacheflush_32.h | 9 +- arch/sparc/include/asm/cacheflush_64.h | 19 ++-- arch/sparc/include/asm/pgtable_32.h | 15 ++- arch/sparc/include/asm/pgtable_64.h | 25 ++++- arch/sparc/kernel/smp_64.c | 56 +++++++---- arch/sparc/mm/init_32.c | 13 ++- arch/sparc/mm/init_64.c | 78 ++++++++------- arch/sparc/mm/tlb.c | 5 +- arch/um/include/asm/pgtable.h | 15 ++- arch/x86/include/asm/pgtable.h | 21 +++- arch/xtensa/include/asm/cacheflush.h | 11 ++- arch/xtensa/include/asm/pgtable.h | 24 +++-- arch/xtensa/mm/cache.c | 83 +++++++++------- include/asm-generic/cacheflush.h | 7 -- include/linux/cacheflush.h | 13 ++- include/linux/mm.h | 3 +- include/linux/page_table_check.h | 14 +-- include/linux/pagemap.h | 28 ++++-- include/linux/rmap.h | 2 + mm/filemap.c | 111 +++++++++++++--------- mm/memory.c | 30 +++--- mm/page_table_check.c | 14 +-- mm/rmap.c | 60 +++++++++--- mm/util.c | 2 +- 100 files changed, 1436 insertions(+), 848 deletions(-)
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 1/34 mm: Convert page_table_check_pte_set() to page_table_check_ptes_set()
Tell the page table check how many PTEs & PFNs we want it to check.
--- arch/arm64/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable.h | 2 +- include/linux/page_table_check.h | 14 +++++++------- mm/page_table_check.c | 14 ++++++++------ 5 files changed, 18 insertions(+), 16 deletions(-)
arch/arm64/include/asm/pgtable.h +1 -1
@@ -358,7 +358,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,static inline void set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte) { -page_table_check_pte_set (mm, addr, ptep, pte); +page_table_check_ptes_set (mm, addr, ptep, pte,1 );return __set_pte_at (mm, addr, ptep, pte); }
arch/riscv/include/asm/pgtable.h +1 -1
@@ -459,7 +459,7 @@ static inline void __set_pte_at(struct mm_struct *mm,static inline void set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) { -page_table_check_pte_set (mm, addr, ptep, pteval); +page_table_check_ptes_set (mm, addr, ptep, pteval,1 );__set_pte_at (mm, addr, ptep, pteval); }
arch/x86/include/asm/pgtable.h +1 -1
@@ -1022,7 +1022,7 @@ static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp)static inline void set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte) { -page_table_check_pte_set (mm, addr, ptep, pte); +page_table_check_ptes_set (mm, addr, ptep, pte,1 );set_pte (ptep, pte); }
include/linux/page_table_check.h +7 -7
@@ -20,8 +20,8 @@ void __page_table_check_pmd_clear(struct mm_struct *mm, unsigned long addr, pmd_t pmd);void __page_table_check_pud_clear (struct mm_struct *mm,unsigned long addr,pud_t pud); -void __page_table_check_pte_set (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte); +void __page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr);void __page_table_check_pmd_set (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd); void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr,
@@ -73,14 +73,14 @@ static inline void page_table_check_pud_clear(struct mm_struct *mm,__page_table_check_pud_clear (mm, addr, pud); } -static inline void page_table_check_pte_set (struct mm_struct *mm, +static inline void page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr,pte_t *ptep, -pte_t pte) +pte_t pte,unsigned int nr) {if (static_branch_likely (&page_table_check_disabled))return ; -__page_table_check_pte_set (mm, addr, ptep, pte); +__page_table_check_ptes_set (mm, addr, ptep, pte, nr); } static inline void page_table_check_pmd_set(struct mm_struct *mm,
@@ -138,9 +138,9 @@ static inline void page_table_check_pud_clear(struct mm_struct *mm, { } -static inline void page_table_check_pte_set (struct mm_struct *mm, +static inline void page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr,pte_t *ptep, -pte_t pte) +pte_t pte,unsigned int nr) { }
mm/page_table_check.c +8 -6
@@ -184,20 +184,22 @@ void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr, }EXPORT_SYMBOL (__page_table_check_pud_clear); -void __page_table_check_pte_set (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) +void __page_table_check_ptes_set (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { +unsigned int i; +if (&init_mm == mm)return ; -__page_table_check_pte_clear (mm, addr, *ptep); +for (i =0 ; i < nr; i++) +__page_table_check_pte_clear (mm, addr, ptep[i]);if (pte_user_accessible_page (pte)) { -page_table_check_set (mm, addr,pte_pfn (pte), -PAGE_SIZE >>PAGE_SHIFT , +page_table_check_set (mm, addr,pte_pfn (pte), nr,pte_write (pte)); } } -EXPORT_SYMBOL (__page_table_check_pte_set); +EXPORT_SYMBOL (__page_table_check_ptes_set);void __page_table_check_pmd_set (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd)
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 2/34 mm: Add generic flush_icache_pages() and documentation
In reply to Matthew Wilcox (Oracle)flush_icache_page() is deprecated but not yet removed, so add a range version of it. Change the documentation to refer to update_mmu_cache_range() instead of update_mmu_cache().
--- Documentation/core-api/cachetlb.rst | 35 +++++++++++++++-------------- include/asm-generic/cacheflush.h | 5 +++++ 2 files changed, 23 insertions(+), 17 deletions(-)
Documentation/core-api/cachetlb.rst +18 -17
@@ -88,13 +88,13 @@ changes occur: This is used primarily during fault processing. -5) ``void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep)`` +5) ``void update_mmu_cache_range(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr)`` - At the end of every page fault, this routine is invoked to - tell the architecture specific code that a translation - now exists at virtual address "address" for address space - "vma->vm_mm", in the software page tables. + At the end of every page fault, this routine is invoked to tell + the architecture specific code that translations now exists + in the software page tables for address space "vma->vm_mm" + at virtual address "address" for "nr" consecutive pages. A port may use this information in any way it so chooses. For example, it could use this event to pre-load TLB
@@ -306,17 +306,18 @@ maps this page at its virtual address. private". The kernel guarantees that, for pagecache pages, it will clear this bit when such a page first enters the pagecache. - This allows these interfaces to be implemented much more efficiently. - It allows one to "defer" (perhaps indefinitely) the actual flush if - there are currently no user processes mapping this page. See sparc64's - flush_dcache_page and update_mmu_cache implementations for an example - of how to go about doing this. + This allows these interfaces to be implemented much more + efficiently. It allows one to "defer" (perhaps indefinitely) the + actual flush if there are currently no user processes mapping this + page. See sparc64's flush_dcache_page and update_mmu_cache_range + implementations for an example of how to go about doing this. - The idea is, first at flush_dcache_page() time, if page_file_mapping() - returns a mapping, and mapping_mapped on that mapping returns %false, - just mark the architecture private page flag bit. Later, in - update_mmu_cache(), a check is made of this flag bit, and if set the - flush is done and the flag bit is cleared. + The idea is, first at flush_dcache_page() time, if + page_file_mapping() returns a mapping, and mapping_mapped on that + mapping returns %false, just mark the architecture private page + flag bit. Later, in update_mmu_cache_range(), a check is made + of this flag bit, and if set the flush is done and the flag bit + is cleared. .. important::
@@ -369,7 +370,7 @@ maps this page at its virtual address. ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` All the functionality of flush_icache_page can be implemented in - flush_dcache_page and update_mmu_cache. In the future, the hope + flush_dcache_page and update_mmu_cache_range. In the future, the hope is to remove this interface completely. The final category of APIs is for I/O to deliberately aliased address
include/asm-generic/cacheflush.h +5 -0
@@ -78,6 +78,11 @@ static inline void flush_icache_range(unsigned long start, unsigned long end)#endif #ifndef flush_icache_page +static inline void flush_icache_pages (struct vm_area_struct *vma, +struct page *page,unsigned int nr) +{ +} +static inline void flush_icache_page (struct vm_area_struct *vma,struct page *page) {
Signature · 1 line
2.39.1
Re: [PATCH v3 02/34] mm: Add generic flush_icache_pages() and documentation
Quoted 5 lines · Matthew Wilcox (Oracle)
flush_icache_page()is deprecated but not yet removed, so add a range version of it. Change the documentation to refer toupdate_mmu_cache_range()instead ofupdate_mmu_cache().Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
Quoted 87 lines
--- Documentation/core-api/cachetlb.rst | 35 +++++++++++++++-------------- include/asm-generic/cacheflush.h | 5 +++++ 2 files changed, 23 insertions(+), 17 deletions(-)Documentation/core-api/cachetlb.rst +18
-17@@ -88,13 +88,13 @@ changes occur: This is used primarily during fault processing. -5) ``void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep)`` +5) ``void update_mmu_cache_range(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr)`` - At the end of every page fault, this routine is invoked to - tell the architecture specific code that a translation - now exists at virtual address "address" for address space - "vma->vm_mm", in the software page tables. + At the end of every page fault, this routine is invoked to tell + the architecture specific code that translations now exists + in the software page tables for address space "vma->vm_mm" + at virtual address "address" for "nr" consecutive pages. A port may use this information in any way it so chooses. For example, it could use this event to pre-load TLB@@ -306,17 +306,18 @@ maps this page at its virtual address. private". The kernel guarantees that, for pagecache pages, it will clear this bit when such a page first enters the pagecache. - This allows these interfaces to be implemented much more efficiently. - It allows one to "defer" (perhaps indefinitely) the actual flush if - there are currently no user processes mapping this page. See sparc64's - flush_dcache_page and update_mmu_cache implementations for an example - of how to go about doing this. + This allows these interfaces to be implemented much more + efficiently. It allows one to "defer" (perhaps indefinitely) the + actual flush if there are currently no user processes mapping this + page. See sparc64's flush_dcache_page and update_mmu_cache_range + implementations for an example of how to go about doing this. - The idea is, first at flush_dcache_page() time, if page_file_mapping() - returns a mapping, and mapping_mapped on that mapping returns %false, - just mark the architecture private page flag bit. Later, in - update_mmu_cache(), a check is made of this flag bit, and if set the - flush is done and the flag bit is cleared. + The idea is, first at flush_dcache_page() time, if + page_file_mapping() returns a mapping, and mapping_mapped on that + mapping returns %false, just mark the architecture private page + flag bit. Later, in update_mmu_cache_range(), a check is made + of this flag bit, and if set the flush is done and the flag bit + is cleared. .. important::@@ -369,7 +370,7 @@ maps this page at its virtual address. ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` All the functionality of flush_icache_page can be implemented in - flush_dcache_page and update_mmu_cache. In the future, the hope + flush_dcache_page and update_mmu_cache_range. In the future, the hope is to remove this interface completely. The final category of APIs is for I/O to deliberately aliased addressinclude/asm-generic/cacheflush.h +5
-0@@ -78,6 +78,11 @@ static inline void flush_icache_range(unsigned long start, unsigned long end)#endif #ifndef flush_icache_page +static inline void flush_icache_pages (struct vm_area_struct *vma, +struct page *page,unsigned int nr) +{ +} +static inline void flush_icache_page (struct vm_area_struct *vma,struct page *page) {Signature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox (Oracle)
maintainerPATCH v3 3/34 mm: Add folio_flush_mapping()
In reply to Matthew Wilcox (Oracle)This is the folio equivalent of page_mapping_file(), but rename it to make it clear that it's very different from page_file_mapping(). Theoretically, there's nothing flush-only about it, but there are no other users today, and I doubt there will be; it's almost always more useful to know the swapfile's mapping or the swapcache's mapping.
--- include/linux/pagemap.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
include/linux/pagemap.h +21 -5
@@ -369,6 +369,26 @@ static inline struct address_space *folio_file_mapping(struct folio *folio)return folio->mapping; } +/** +* folio_flush_mapping - Find the file mapping this folio belongs to. +* @folio: The folio. +* +* For folios which are in the page cache, return the mapping that this +* page belongs to. Anonymous folios return NULL, even if they're in +* the swap cache. Other kinds of folio also return NULL. +* +* This is ONLY used by architecture cache flushing code. If you aren't +* writing cache flushing code, you want either folio_mapping() or +* folio_file_mapping(). +*/ +static inline struct address_space *folio_flush_mapping (struct folio *folio) +{ +if (unlikely (folio_test_swapcache (folio))) +return NULL ; + +return folio_mapping (folio); +} +static inline struct address_space *page_file_mapping (struct page *page) {return folio_file_mapping (page_folio (page));
@@ -379,11 +399,7 @@ static inline struct address_space *page_file_mapping(struct page *page)*/ static inline struct address_space *page_mapping_file (struct page *page) { -struct folio *folio =page_folio (page); - -if (unlikely (folio_test_swapcache (folio))) -return NULL ; -return folio_mapping (folio); +return folio_flush_mapping (page_folio (page)); }/**
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 03/34] mm: Add folio_flush_mapping()
Quoted 16 lines · Matthew Wilcox (Oracle)
This is the folio equivalent of
page_mapping_file(), but rename it to make it clear that it's very different frompage_file_mapping(). Theoretically, there's nothing flush-only about it, but there are no other users today, and I doubt there will be; it's almost always more useful to know the swapfile's mapping or the swapcache's mapping.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- include/linux/pagemap.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)include/linux/pagemap.h +0
-0
include/linux/pagemap.h static inline struct address_space *folio_file_mapping(struct folio *folio) · line 377
Quoted 9 lines
include/linux/pagemap.h +6
-0@@ -369,6 +369,26 @@ static inline struct address_space *folio_file_mapping(struct folio *folio)return folio->mapping; } +/** +* folio_flush_mapping - Find the file mapping this folio belongs to. +* @folio: The folio. +* +* For folios which are in the page cache, return the mapping that this +* page belongs to. Anonymous folios return NULL, even if they're in
^ folio ?
Quoted 33 lines
include/linux/pagemap.h +15
-5+* the swap cache. Other kinds of folio also return NULL. +* +* This is ONLY used by architecture cache flushing code. If you aren't +* writing cache flushing code, you want either folio_mapping() or +* folio_file_mapping(). +*/ +static inline struct address_space *folio_flush_mapping (struct folio *folio) +{ +if (unlikely (folio_test_swapcache (folio))) +return NULL ; + +return folio_mapping (folio); +} +static inline struct address_space *page_file_mapping (struct page *page) {return folio_file_mapping (page_folio (page));@@ -379,11 +399,7 @@ static inline struct address_space *page_file_mapping(struct page *page)*/ static inline struct address_space *page_mapping_file (struct page *page) { -struct folio *folio =page_folio (page); - -if (unlikely (folio_test_swapcache (folio))) -return NULL ; -return folio_mapping (folio); +return folio_flush_mapping (page_folio (page)); }/** Signature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox (Oracle)
maintainerPATCH v3 4/34 mm: Remove ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO
In reply to Matthew Wilcox (Oracle)Current best practice is to reuse the name of the function as a define to indicate that the function is implemented by the architecture.
--- Documentation/core-api/cachetlb.rst | 24 +++++++++--------------- include/linux/cacheflush.h | 4 ++-- mm/util.c | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-)
Documentation/core-api/cachetlb.rst +9 -15
@@ -269,7 +269,7 @@ maps this page at its virtual address. If D-cache aliasing is not an issue, these two routines may simply call memcpy/memset directly and do nothing more. - ``void flush_dcache_page(struct page *page)`` + ``void flush_dcache_folio(struct folio *folio)`` This routines must be called when:
@@ -277,7 +277,7 @@ maps this page at its virtual address. and / or in high memory b) the kernel is about to read from a page cache page and user space shared/writable mappings of this page potentially exist. Note - that {get,pin}_user_pages{_fast} already call flush_dcache_page + that {get,pin}_user_pages{_fast} already call flush_dcache_folio on any page found in the user address space and thus driver code rarely needs to take this into account.
@@ -291,7 +291,7 @@ maps this page at its virtual address. The phrase "kernel writes to a page cache page" means, specifically, that the kernel executes store instructions that dirty data in that - page at the page->virtual mapping of that page. It is important to + page at the kernel virtual mapping of that page. It is important to flush here to handle D-cache aliasing, to make sure these kernel stores are visible to user space mappings of that page.
@@ -302,18 +302,18 @@ maps this page at its virtual address. If D-cache aliasing is not an issue, this routine may simply be defined as a nop on that architecture. - There is a bit set aside in page->flags (PG_arch_1) as "architecture + There is a bit set aside in folio->flags (PG_arch_1) as "architecture private". The kernel guarantees that, for pagecache pages, it will clear this bit when such a page first enters the pagecache. This allows these interfaces to be implemented much more efficiently. It allows one to "defer" (perhaps indefinitely) the actual flush if there are currently no user processes mapping this - page. See sparc64's flush_dcache_page and update_mmu_cache_range + page. See sparc64's flush_dcache_folio and update_mmu_cache_range implementations for an example of how to go about doing this. - The idea is, first at flush_dcache_page() time, if - page_file_mapping() returns a mapping, and mapping_mapped on that + The idea is, first at flush_dcache_folio() time, if + folio_flush_mapping() returns a mapping, and mapping_mapped() on that mapping returns %false, just mark the architecture private page flag bit. Later, in update_mmu_cache_range(), a check is made of this flag bit, and if set the flush is done and the flag bit
@@ -327,12 +327,6 @@ maps this page at its virtual address. dirty. Again, see sparc64 for examples of how to deal with this. - ``void flush_dcache_folio(struct folio *folio)`` - This function is called under the same circumstances as - flush_dcache_page(). It allows the architecture to - optimise for flushing the entire folio of pages instead - of flushing one page at a time. - ``void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long user_vaddr, void *dst, void *src, int len)`` ``void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
@@ -353,7 +347,7 @@ maps this page at its virtual address. When the kernel needs to access the contents of an anonymous page, it calls this function (currently only - get_user_pages()). Note: flush_dcache_page() deliberately + get_user_pages()). Note: flush_dcache_folio() deliberately doesn't work for an anonymous page. The default implementation is a nop (and should remain so for all coherent architectures). For incoherent architectures, it should flush
@@ -370,7 +364,7 @@ maps this page at its virtual address. ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` All the functionality of flush_icache_page can be implemented in - flush_dcache_page and update_mmu_cache_range. In the future, the hope + flush_dcache_folio and update_mmu_cache_range. In the future, the hope is to remove this interface completely. The final category of APIs is for I/O to deliberately aliased address
include/linux/cacheflush.h +2 -2
@@ -7,14 +7,14 @@struct folio ;#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE -#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO +#ifndef flush_dcache_foliovoid flush_dcache_folio (struct folio *folio);#endif #else static inline void flush_dcache_folio (struct folio *folio) { } -#define ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO 0 +#define flush_dcache_folio flush_dcache_folio#endif /* ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE */ #endif /* _LINUX_CACHEFLUSH_H */
mm/util.c +1 -1
@@ -1124,7 +1124,7 @@ void page_offline_end(void) }EXPORT_SYMBOL (page_offline_end); -#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO +#ifndef flush_dcache_foliovoid flush_dcache_folio (struct folio *folio) {long i, nr =folio_nr_pages (folio);
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 5/34 alpha: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_icache_pages().
--- arch/alpha/include/asm/cacheflush.h | 10 ++++++++++ arch/alpha/include/asm/pgtable.h | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
arch/alpha/include/asm/cacheflush.h +10 -0
@@ -57,6 +57,16 @@ extern void flush_icache_user_page(struct vm_area_struct *vma,#define flush_icache_page (vma, page) \ flush_icache_user_page((vma), (page), 0, 0) +/* +* Both implementations of flush_icache_user_page flush the entire +* address space, so one call, no matter how many pages. +*/ +static inline void flush_icache_pages (struct vm_area_struct *vma, +struct page *page,unsigned int nr) +{ +flush_icache_user_page (vma, page,0 ,0 ); +} +#include <asm-generic/cacheflush.h> #endif /* _ALPHA_CACHEFLUSH_H */
arch/alpha/include/asm/pgtable.h +17 -1
@@ -26,7 +26,18 @@ struct vm_area_struct;* hook is made available. */ #define set_pte (pteptr, pteval) ((*(pteptr)) = (pteval)) -#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1UL <<32 ; + } +} +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* PMD_SHIFT determines the size of the area a second-level page table can map */ #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
@@ -303,6 +314,11 @@ extern inline void update_mmu_cache(struct vm_area_struct * vma, { } +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) +{ +} +/* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that * are !pte_none() && !pte_present().
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 6/34 arc: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages().
Change the PG_dc_clean flag from being per-page to per-folio (which means it cannot always be set as we don't know that all pages in this folio were cleaned). Enhance the internal flush routines to take the number of pages to flush.
--- arch/arc/include/asm/cacheflush.h | 7 ++- arch/arc/include/asm/pgtable-bits-arcv2.h | 20 ++++++-- arch/arc/mm/cache.c | 61 ++++++++++++++--------- arch/arc/mm/tlb.c | 18 ++++--- 4 files changed, 68 insertions(+), 38 deletions(-)
arch/arc/include/asm/cacheflush.h +5 -2
@@ -25,17 +25,20 @@* in update_mmu_cache() */ #define flush_icache_page (vma, page) +#define flush_icache_pages (vma, page, nr)void flush_cache_all (void );void flush_icache_range (unsigned long kstart,unsigned long kend);void __sync_icache_dcache (phys_addr_t paddr,unsigned long vaddr,int len); -void __inv_icache_page (phys_addr_t paddr,unsigned long vaddr); -void __flush_dcache_page (phys_addr_t paddr,unsigned long vaddr); +void __inv_icache_pages (phys_addr_t paddr,unsigned long vaddr,unsigned nr); +void __flush_dcache_pages (phys_addr_t paddr,unsigned long vaddr,unsigned nr);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1void flush_dcache_page (struct page *page); +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_foliovoid dma_cache_wback_inv (phys_addr_t start,unsigned long sz);void dma_cache_inv (phys_addr_t start,unsigned long sz);
arch/arc/include/asm/pgtable-bits-arcv2.h +15 -5
@@ -100,14 +100,24 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)return __pte ((pte_val (pte) & _PAGE_CHG_MASK) |pgprot_val (newprot)); } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { -set_pte (ptep, pteval); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address, -pte_t *ptep); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,unsigned int nr); + +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)/* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
arch/arc/mm/cache.c +37 -24
146 lines not on this page · raw message
arch/arc/mm/tlb.c +11 -7
@@ -467,8 +467,8 @@ void create_tlb(struct vm_area_struct *vma, unsigned long vaddr, pte_t *ptep)* Note that flush (when done) involves both WBACK - so physical page is * in sync as well as INV - so any non-congruent aliases don't remain */ -void update_mmu_cache (struct vm_area_struct *vma,unsigned long vaddr_unaligned, -pte_t *ptep) +void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long vaddr_unaligned,pte_t *ptep,unsigned int nr) {unsigned long vaddr = vaddr_unaligned &PAGE_MASK ;phys_addr_t paddr =pte_val (*ptep) &PAGE_MASK_PHYS ;
@@ -491,15 +491,19 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long vaddr_unaligned,*/ if ((vma->vm_flags &VM_EXEC ) ||addr_not_cache_congruent (paddr, vaddr)) { - -int dirty = !test_and_set_bit (PG_dc_clean, &page->flags); +struct folio *folio =page_folio (page); +int dirty = !test_and_set_bit (PG_dc_clean, &folio->flags);if (dirty) { +unsigned long offset =offset_in_folio (folio, paddr); + nr =folio_nr_pages (folio); + paddr -= offset; + vaddr -= offset;/* wback + inv dcache lines (K-mapping) */ -__flush_dcache_page (paddr, paddr); +__flush_dcache_pages (paddr, paddr, nr);/* invalidate any existing icache lines (U-mapping) */ if (vma->vm_flags &VM_EXEC ) -__inv_icache_page (paddr, vaddr); +__inv_icache_pages (paddr, vaddr, nr); } } }
@@ -531,7 +535,7 @@ void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd) {pte_t pte =__pte (pmd_val (*pmd)); -update_mmu_cache (vma, addr, &pte); +update_mmu_cache_range (vma, addr, &pte,HPAGE_PMD_NR ); } void local_flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,
Signature · 7 lines
2.39.1 _______________________________________________ linux-snps-arc mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Matthew Wilcox (Oracle)
maintainerPATCH v3 7/34 arm: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_dcache_clear flag from being per-page to per-folio which makes __dma_page_dev_to_cpu() a bit more exciting. Also add flush_cache_pages(), even though this isn't used by generic code (yet?)
--- arch/arm/include/asm/cacheflush.h | 24 +++++--- arch/arm/include/asm/pgtable.h | 5 +- arch/arm/include/asm/tlbflush.h | 13 ++-- arch/arm/mm/copypage-v4mc.c | 5 +- arch/arm/mm/copypage-v6.c | 5 +- arch/arm/mm/copypage-xscale.c | 5 +- arch/arm/mm/dma-mapping.c | 24 ++++---- arch/arm/mm/fault-armv.c | 14 ++--- arch/arm/mm/flush.c | 99 +++++++++++++++++++------------ arch/arm/mm/mm.h | 2 +- arch/arm/mm/mmu.c | 14 +++-- 11 files changed, 125 insertions(+), 85 deletions(-)
arch/arm/include/asm/cacheflush.h +15 -9
@@ -231,14 +231,15 @@ vivt_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned vma->vm_flags); } -static inline void -vivt_flush_cache_page (struct vm_area_struct *vma,unsigned long user_addr,unsigned long pfn) +static inline void vivt_flush_cache_pages (struct vm_area_struct *vma, +unsigned long user_addr,unsigned long pfn,unsigned int nr) {struct mm_struct *mm = vma->vm_mm;if (!mm ||cpumask_test_cpu (smp_processor_id (),mm_cpumask (mm))) {unsigned long addr = user_addr &PAGE_MASK ; -__cpuc_flush_user_range (addr, addr +PAGE_SIZE , vma->vm_flags); +__cpuc_flush_user_range (addr, addr + nr *PAGE_SIZE , + vma->vm_flags); } }
@@ -247,15 +248,17 @@ vivt_flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsig vivt_flush_cache_mm(mm)#define flush_cache_range (vma,start,end) \ vivt_flush_cache_range(vma,start,end) -#define flush_cache_page (vma,addr,pfn) \ - vivt_flush_cache_page(vma,addr,pfn) +#define flush_cache_pages (vma, addr, pfn, nr) \ + vivt_flush_cache_pages(vma, addr, pfn, nr)#else -extern void flush_cache_mm (struct mm_struct *mm); -extern void flush_cache_range (struct vm_area_struct *vma,unsigned long start,unsigned long end); -extern void flush_cache_page (struct vm_area_struct *vma,unsigned long user_addr,unsigned long pfn); +void flush_cache_mm (struct mm_struct *mm); +void flush_cache_range (struct vm_area_struct *vma,unsigned long start,unsigned long end); +void flush_cache_pages (struct vm_area_struct *vma,unsigned long user_addr, +unsigned long pfn,unsigned int nr);#endif #define flush_cache_dup_mm (mm) flush_cache_mm(mm) +#define flush_cache_page (vma, addr, pfn) flush_cache_pages(vma, addr, pfn, 1)/* * flush_icache_user_range is used when we want to ensure that the
@@ -289,7 +292,9 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr* See update_mmu_cache for the user space part. */ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -extern void flush_dcache_page (struct page *); +void flush_dcache_page (struct page *); +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folio#define ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE 1static inline void flush_kernel_vmap_range (void *addr,int size)
@@ -321,6 +326,7 @@ static inline void flush_anon_page(struct vm_area_struct *vma,* duplicate cache flushing elsewhere performed by flush_dcache_page(). */ #define flush_icache_page (vma,page) do { } while (0) +#define flush_icache_pages (vma, page, nr) do { } while (0)/* * flush_cache_vmap() is used when creating mappings (eg, via vmap,
arch/arm/include/asm/pgtable.h +3 -2
@@ -207,8 +207,9 @@ static inline void __sync_icache_dcache(pte_t pteval)extern void __sync_icache_dcache (pte_t pteval);#endif -void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval); +void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval,unsigned int nr); +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline pte_t clear_pte_bit (pte_t pte,pgprot_t prot) {
arch/arm/include/asm/tlbflush.h +8 -5
@@ -619,18 +619,21 @@ extern void flush_bp_all(void);* If PG_dcache_clean is not set for the page, we need to ensure that any * cache entries for the kernels virtual memory range are written * back to the page. On ARMv6 and later, the cache coherency is handled via -* the set_pte_at() function. +* the set_ptes() function. */ #if __LINUX_ARM_ARCH__ <6 -extern void update_mmu_cache (struct vm_area_struct *vma,unsigned long addr, -pte_t *ptep); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long addr, +pte_t *ptep,unsigned int nr);#else -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long addr,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long addr,pte_t *ptep,unsigned int nr) { }#endif +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1) +#define update_mmu_cache_pmd (vma, address, pmd) do { } while (0)#endif
arch/arm/mm/copypage-v4mc.c +3 -2
@@ -64,10 +64,11 @@ static void mc_copy_user_page(void *from, void *to)void v4_mc_copy_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +struct folio *src =page_folio (from);void *kto =kmap_atomic (to); -if (!test_and_set_bit (PG_dcache_clean, &from->flags)) -__flush_dcache_page (page_mapping_file (from), from); +if (!test_and_set_bit (PG_dcache_clean, &src->flags)) +__flush_dcache_folio (folio_flush_mapping (src), src);raw_spin_lock (&minicache_lock);
arch/arm/mm/copypage-v6.c +3 -2
@@ -69,11 +69,12 @@ static void discard_old_kernel_data(void *kto)static void v6_copy_user_highpage_aliasing (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +struct folio *src =page_folio (from);unsigned int offset =CACHE_COLOUR (vaddr);unsigned long kfrom, kto; -if (!test_and_set_bit (PG_dcache_clean, &from->flags)) -__flush_dcache_page (page_mapping_file (from), from); +if (!test_and_set_bit (PG_dcache_clean, &src->flags)) +__flush_dcache_folio (folio_flush_mapping (src), src);/* FIXME: not highmem safe */ discard_old_kernel_data (page_address (to));
arch/arm/mm/copypage-xscale.c +3 -2
@@ -84,10 +84,11 @@ static void mc_copy_user_page(void *from, void *to)void xscale_mc_copy_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +struct folio *src =page_folio (from);void *kto =kmap_atomic (to); -if (!test_and_set_bit (PG_dcache_clean, &from->flags)) -__flush_dcache_page (page_mapping_file (from), from); +if (!test_and_set_bit (PG_dcache_clean, &src->flags)) +__flush_dcache_folio (folio_flush_mapping (src), src);raw_spin_lock (&minicache_lock);
arch/arm/mm/dma-mapping.c +12 -12
@@ -693,6 +693,7 @@ static void __dma_page_cpu_to_dev(struct page *page, unsigned long off,static void __dma_page_dev_to_cpu (struct page *page,unsigned long off,size_t size,enum dma_data_direction dir) { +struct folio *folio =page_folio (page);phys_addr_t paddr =page_to_phys (page) + off;/* FIXME: non-speculating: not required */
@@ -707,19 +708,18 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off,* Mark the D-cache clean for these pages to avoid extra flushing. */ if (dir !=DMA_TO_DEVICE && size >=PAGE_SIZE ) { -unsigned long pfn; -size_t left = size; - - pfn =page_to_pfn (page) + off /PAGE_SIZE ; - off %=PAGE_SIZE ; -if (off) { - pfn++; - left -=PAGE_SIZE - off; +ssize_t left = size; +size_t offset =offset_in_folio (folio, paddr); + +if (offset) { + left -=folio_size (folio) - offset; + folio =folio_next (folio); } -while (left >=PAGE_SIZE ) { - page =pfn_to_page (pfn++); -set_bit (PG_dcache_clean, &page->flags); - left -=PAGE_SIZE ; + +while (left >= (ssize_t )folio_size (folio)) { +set_bit (PG_dcache_clean, &folio->flags); + left -=folio_size (folio); + folio =folio_next (folio); } } }
arch/arm/mm/fault-armv.c +7 -7
@@ -178,8 +178,8 @@ make_coherent(struct address_space *mapping, struct vm_area_struct *vma,* * Note that the pte lock will be held. */ -void update_mmu_cache (struct vm_area_struct *vma,unsigned long addr, -pte_t *ptep) +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long addr, +pte_t *ptep,unsigned int nr) {unsigned long pfn =pte_pfn (*ptep);struct address_space *mapping;
@@ -192,13 +192,13 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,* The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - page =pfn_to_page (pfn); -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (pfn))return ; - mapping =page_mapping_file (page); -if (!test_and_set_bit (PG_dcache_clean, &page->flags)) -__flush_dcache_page (mapping, page); + folio =page_folio (pfn_to_page (pfn)); + mapping =folio_flush_mapping (page); +if (!test_and_set_bit (PG_dcache_clean, &folio->flags)) +__flush_dcache_folio (mapping, folio);if (mapping) {if (cache_is_vivt ())make_coherent (mapping, vma, addr, ptep, pfn);
arch/arm/mm/flush.c +60 -39
194 lines not on this page · raw message
arch/arm/mm/mm.h +1 -1
@@ -45,7 +45,7 @@ struct mem_type {const struct mem_type *get_mem_type (unsigned int type); -extern void __flush_dcache_page (struct address_space *mapping,struct page *page); +void __flush_dcache_folio (struct address_space *mapping,struct folio *folio);/* * ARM specific vm_struct->flags bits.
arch/arm/mm/mmu.c +10 -4
@@ -1788,7 +1788,7 @@ void __init paging_init(const struct machine_desc *mdesc)bootmem_init (); empty_zero_page =virt_to_page (zero_page); -__flush_dcache_page (NULL , empty_zero_page); +__flush_dcache_folio (NULL ,page_folio (empty_zero_page)); }void __init early_mm_init (const struct machine_desc *mdesc)
@@ -1797,8 +1797,8 @@ void __init early_mm_init(const struct machine_desc *mdesc)early_paging_init (mdesc); } -void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) +void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval,unsigned int nr) {unsigned long ext =0 ;
@@ -1808,5 +1808,11 @@ void set_pte_at(struct mm_struct *mm, unsigned long addr, ext |=PTE_EXT_NG ; } -set_pte_ext (ptep, pteval, ext); +for (;;) { +set_pte_ext (ptep, pteval, ext); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pteval) +=PAGE_SIZE ; + } }
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 8/34 arm64: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio.
--- arch/arm64/include/asm/cacheflush.h | 4 +++- arch/arm64/include/asm/pgtable.h | 25 ++++++++++++++------ arch/arm64/mm/flush.c | 36 +++++++++++------------------ 3 files changed, 35 insertions(+), 30 deletions(-)
arch/arm64/include/asm/cacheflush.h +3 -1
@@ -114,7 +114,7 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *,#define copy_to_user_page copy_to_user_page/* -* flush_dcache_page is used when the kernel has written to the page +* flush_dcache_folio is used when the kernel has written to the page * cache page at virtual address page->virtual. * * If this page isn't mapped (ie, page_mapping == NULL), or it might
@@ -127,6 +127,8 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *,*/ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1extern void flush_dcache_page (struct page *); +void flush_dcache_folio (struct folio *); +#define flush_dcache_folio flush_dcache_folio static __always_inline void icache_inval_all_pou(void) {
arch/arm64/include/asm/pgtable.h +18 -7
@@ -355,12 +355,21 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,set_pte (ptep, pte); } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) -{ -page_table_check_ptes_set (mm, addr, ptep, pte,1 ); -return __set_pte_at (mm, addr, ptep, pte); +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +page_table_check_ptes_set (mm, addr, ptep, pte, nr); + +for (;;) { +__set_pte_at (mm, addr, ptep, pte); +if (--nr ==0 ) +break ; + ptep++; + addr +=PAGE_SIZE ; +pte_val (pte) +=PAGE_SIZE ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* * Huge pte definitions.
@@ -1059,8 +1068,8 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio)/* * On AArch64, the cache coherency is handled via the set_pte_at() function. */ -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long addr,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long addr,pte_t *ptep,unsigned int nr) {/* * We don't do anything here, so there's a very small chance of
@@ -1069,6 +1078,8 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,*/ } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define update_mmu_cache_pmd (vma, address, pmd) do { } while (0)#ifdef CONFIG_ARM64_PA_BITS_52
arch/arm64/mm/flush.c +14 -22
@@ -50,20 +50,13 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page,void __sync_icache_dcache (pte_t pte) { -struct page *page =pte_page (pte); +struct folio *folio =page_folio (pte_page (pte)); -/* -* HugeTLB pages are always fully mapped, so only setting head page's -* PG_dcache_clean flag is enough. -*/ -if (PageHuge (page)) - page =compound_head (page); - -if (!test_bit (PG_dcache_clean, &page->flags)) { -sync_icache_aliases ((unsigned long )page_address (page), - (unsigned long )page_address (page) + -page_size (page)); -set_bit (PG_dcache_clean, &page->flags); +if (!test_bit (PG_dcache_clean, &folio->flags)) { +sync_icache_aliases ((unsigned long )folio_address (folio), + (unsigned long )folio_address (folio) + +folio_size (folio)); +set_bit (PG_dcache_clean, &folio->flags); } }EXPORT_SYMBOL_GPL (__sync_icache_dcache);
@@ -73,17 +66,16 @@ EXPORT_SYMBOL_GPL(__sync_icache_dcache);* it as dirty for later flushing when mapped in user space (if executable, * see __sync_icache_dcache). */ -void flush_dcache_page (struct page *page) +void flush_dcache_folio (struct folio *folio) { -/* -* HugeTLB pages are always fully mapped and only head page will be -* set PG_dcache_clean (see comments in __sync_icache_dcache()). -*/ -if (PageHuge (page)) - page =compound_head (page); +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); +} +EXPORT_SYMBOL (flush_dcache_folio); -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); }EXPORT_SYMBOL (flush_dcache_page);
Signature · 1 line
2.39.1
Re: [PATCH v3 08/34] arm64: Implement the new page table range API
Quoted 49 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range()andflush_dcache_folio(). Change thePG_dcache_cleanflag from being per-page to per-folio.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Reviewed-by Catalin Marinas <[email protected]>--- arch/arm64/include/asm/cacheflush.h | 4 +++- arch/arm64/include/asm/pgtable.h | 25 ++++++++++++++------ arch/arm64/mm/flush.c | 36 +++++++++++------------------ 3 files changed, 35 insertions(+), 30 deletions(-)arch/arm64/include/asm/cacheflush.h +3
-1@@ -114,7 +114,7 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *,#define copy_to_user_page copy_to_user_page/* -* flush_dcache_page is used when the kernel has written to the page +* flush_dcache_folio is used when the kernel has written to the page * cache page at virtual address page->virtual. * * If this page isn't mapped (ie, page_mapping == NULL), or it might @@ -127,6 +127,8 @@ extern void copy_to_user_page(struct vm_area_struct *, struct page *,*/ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1extern void flush_dcache_page (struct page *); +void flush_dcache_folio (struct folio *); +#define flush_dcache_folio flush_dcache_folio static __always_inline void icache_inval_all_pou(void) {arch/arm64/include/asm/pgtable.h +2
-5@@ -355,12 +355,21 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,set_pte (ptep, pte); } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) -{ -page_table_check_ptes_set (mm, addr, ptep, pte,1 ); -return __set_pte_at (mm, addr, ptep, pte); +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr)
arch/arm64/include/asm/pgtable.h static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, · line 369
Quoted 10 lines
arch/arm64/include/asm/pgtable.h +10
-0+{ +page_table_check_ptes_set (mm, addr, ptep, pte, nr); + +for (;;) { +__set_pte_at (mm, addr, ptep, pte); +if (--nr ==0 ) +break ; + ptep++; + addr +=PAGE_SIZE ; +pte_val (pte) +=PAGE_SIZE ;
For systems that support > 48-bit PA, arm64 places high bits [51:48] of the PA at a low position in the PTE. I think I've convinced myself that this is ok though, because set_ptes() promises that the range is always within a single PMD and therefore its guaranteed that we will not have ptes straddling both sides of the 48 bit boundary for a single call?
Also, its not clear to me if set_ptes() could be called for a range of not-present ptes? (i.e. clearing the pte-range or swap entries, etc). If so, then I guess you would only want to increment the address if pte_present(pte)? I'm guessing that batch-clearing ptes might appear in the near future so might be sensible to support that now?
Regardless, a comment to make these assumptions clear would be useful.
Thanks,
Ryan
Quoted 83 lines
arch/arm64/include/asm/pgtable.h +6
-2+ } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* * Huge pte definitions. @@ -1059,8 +1068,8 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio)/* * On AArch64, the cache coherency is handled via the set_pte_at() function. */ -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long addr,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long addr,pte_t *ptep,unsigned int nr) {/* * We don't do anything here, so there's a very small chance of @@ -1069,6 +1078,8 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,*/ } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define update_mmu_cache_pmd (vma, address, pmd) do { } while (0)#ifdef CONFIG_ARM64_PA_BITS_52 arch/arm64/mm/flush.c +14
-22@@ -50,20 +50,13 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page,void __sync_icache_dcache (pte_t pte) { -struct page *page =pte_page (pte); +struct folio *folio =page_folio (pte_page (pte)); -/* -* HugeTLB pages are always fully mapped, so only setting head page's -* PG_dcache_clean flag is enough. -*/ -if (PageHuge (page)) - page =compound_head (page); - -if (!test_bit (PG_dcache_clean, &page->flags)) { -sync_icache_aliases ((unsigned long )page_address (page), - (unsigned long )page_address (page) + -page_size (page)); -set_bit (PG_dcache_clean, &page->flags); +if (!test_bit (PG_dcache_clean, &folio->flags)) { +sync_icache_aliases ((unsigned long )folio_address (folio), + (unsigned long )folio_address (folio) + +folio_size (folio)); +set_bit (PG_dcache_clean, &folio->flags); } }EXPORT_SYMBOL_GPL (__sync_icache_dcache);@@ -73,17 +66,16 @@ EXPORT_SYMBOL_GPL(__sync_icache_dcache);* it as dirty for later flushing when mapped in user space (if executable, * see __sync_icache_dcache). */ -void flush_dcache_page (struct page *page) +void flush_dcache_folio (struct folio *folio) { -/* -* HugeTLB pages are always fully mapped and only head page will be -* set PG_dcache_clean (see comments in __sync_icache_dcache()). -*/ -if (PageHuge (page)) - page =compound_head (page); +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); +} +EXPORT_SYMBOL (flush_dcache_folio); -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); }EXPORT_SYMBOL (flush_dcache_page);
Matthew Wilcox (Oracle)
maintainerPATCH v3 9/34 csky: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio.
--- arch/csky/abiv1/cacheflush.c | 32 +++++++++++++++++----------- arch/csky/abiv1/inc/abi/cacheflush.h | 2 ++ arch/csky/abiv2/cacheflush.c | 30 +++++++++++++------------- arch/csky/abiv2/inc/abi/cacheflush.h | 10 +++++++-- arch/csky/include/asm/pgtable.h | 21 +++++++++++++++--- 5 files changed, 62 insertions(+), 33 deletions(-)
arch/csky/abiv1/cacheflush.c +19 -13
@@ -14,43 +14,49 @@#define PG_dcache_clean PG_arch_1 -void flush_dcache_page (struct page *page) +void flush_dcache_folio (struct folio *folio) {struct address_space *mapping; -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (folio_pfn (folio)))return ; - mapping =page_mapping_file (page); + mapping =folio_flush_mapping (folio); -if (mapping && !page_mapcount (page)) -clear_bit (PG_dcache_clean, &page->flags); +if (mapping && !folio_mapped (folio)) +clear_bit (PG_dcache_clean, &folio->flags);else {dcache_wbinv_all ();if (mapping)icache_inv_all (); -set_bit (PG_dcache_clean, &page->flags); +set_bit (PG_dcache_clean, &folio->flags); } } +EXPORT_SYMBOL (flush_dcache_folio); + +void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}EXPORT_SYMBOL (flush_dcache_page); -void update_mmu_cache (struct vm_area_struct *vma,unsigned long addr, -pte_t *ptep) +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long addr, +pte_t *ptep,unsigned int nr) {unsigned long pfn =pte_pfn (*ptep); -struct page *page; +struct folio *folio;if (!pfn_valid (pfn))return ; - page =pfn_to_page (pfn); -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (pfn))return ; -if (!test_and_set_bit (PG_dcache_clean, &page->flags)) + folio =page_folio (pfn_to_page (pfn)); +if (!test_and_set_bit (PG_dcache_clean, &folio->flags))dcache_wbinv_all (); -if (page_mapping_file (page)) { +if (folio_flush_mapping (folio)) {if (vma->vm_flags &VM_EXEC )icache_inv_all (); }
arch/csky/abiv1/inc/abi/cacheflush.h +2 -0
@@ -9,6 +9,8 @@#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1extern void flush_dcache_page (struct page *); +void flush_dcache_folio (struct folio *); +#define flush_dcache_folio flush_dcache_folio#define flush_cache_mm (mm) dcache_wbinv_all()#define flush_cache_page (vma, page, pfn) cache_wbinv_all()
arch/csky/abiv2/cacheflush.c +15 -15
@@ -6,30 +6,30 @@#include <linux/mm.h> #include <asm/cache.h> -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address, -pte_t *pte) +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *pte,unsigned int nr) { -unsigned long addr; +unsigned long pfn =pte_pfn (*pte);struct page *page; +unsigned int i; -if (!pfn_valid (pte_pfn (*pte))) +if (!pfn_valid (pfn) ||is_zero_pfn (pfn))return ; - page =pfn_to_page (pte_pfn (*pte)); -if (page ==ZERO_PAGE (0 )) -return ; + folio =page_folio (pfn_to_page (pfn)); -if (test_and_set_bit (PG_dcache_clean, &page->flags)) +if (test_and_set_bit (PG_dcache_clean, &folio->flags))return ; - addr = (unsigned long )kmap_atomic (page); - -dcache_wb_range (addr, addr +PAGE_SIZE ); +for (i =0 ; i <folio_nr_pages (folio); i++) { +unsigned long addr = (unsigned long )kmap_local_folio (folio, + i *PAGE_SIZE ); -if (vma->vm_flags &VM_EXEC ) -icache_inv_range (addr, addr +PAGE_SIZE ); - -kunmap_atomic ((void *) addr); +dcache_wb_range (addr, addr +PAGE_SIZE ); +if (vma->vm_flags &VM_EXEC ) +icache_inv_range (addr, addr +PAGE_SIZE ); +kunmap_local ((void *) addr); + } }void flush_icache_deferred (struct mm_struct *mm)
arch/csky/abiv2/inc/abi/cacheflush.h +8 -2
@@ -18,11 +18,17 @@#define PG_dcache_clean PG_arch_1 +static inline void flush_dcache_folio (struct folio *folio) +{ +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1static inline void flush_dcache_page (struct page *page) { -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +flush_dcache_folio (page_folio (page)); }#define flush_dcache_mmap_lock (mapping) do { } while (0)
arch/csky/include/asm/pgtable.h +18 -3
@@ -90,7 +90,20 @@ static inline void set_pte(pte_t *p, pte_t pte)/* prevent out of order excution */ smp_mb (); } -#define set_pte_at (mm, addr, ptep, pteval) set_pte(ptep, pteval) + +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline pte_t *pmd_page_vaddr (pmd_t pmd) {
@@ -263,8 +276,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];extern void paging_init (void ); -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address, -pte_t *pte); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *pte,unsigned int nr); +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define io_remap_pfn_range (vma, vaddr, pfn, size, prot) \ remap_pfn_range(vma, vaddr, pfn, size, prot)
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 09/34] csky: Implement the new page table range API
Quoted 100 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range()andflush_dcache_folio(). Change thePG_dcache_cleanflag from being per-page to per-folio.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Acked-by Guo Ren <[email protected]>--- arch/csky/abiv1/cacheflush.c | 32 +++++++++++++++++----------- arch/csky/abiv1/inc/abi/cacheflush.h | 2 ++ arch/csky/abiv2/cacheflush.c | 30 +++++++++++++------------- arch/csky/abiv2/inc/abi/cacheflush.h | 10 +++++++-- arch/csky/include/asm/pgtable.h | 21 +++++++++++++++--- 5 files changed, 62 insertions(+), 33 deletions(-)arch/csky/abiv1/cacheflush.c +19
-13@@ -14,43 +14,49 @@#define PG_dcache_clean PG_arch_1 -void flush_dcache_page (struct page *page) +void flush_dcache_folio (struct folio *folio) {struct address_space *mapping; -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (folio_pfn (folio)))return ; - mapping =page_mapping_file (page); + mapping =folio_flush_mapping (folio); -if (mapping && !page_mapcount (page)) -clear_bit (PG_dcache_clean, &page->flags); +if (mapping && !folio_mapped (folio)) +clear_bit (PG_dcache_clean, &folio->flags);else {dcache_wbinv_all ();if (mapping)icache_inv_all (); -set_bit (PG_dcache_clean, &page->flags); +set_bit (PG_dcache_clean, &folio->flags); } } +EXPORT_SYMBOL (flush_dcache_folio); + +void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}EXPORT_SYMBOL (flush_dcache_page); -void update_mmu_cache (struct vm_area_struct *vma,unsigned long addr, -pte_t *ptep) +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long addr, +pte_t *ptep,unsigned int nr) {unsigned long pfn =pte_pfn (*ptep); -struct page *page; +struct folio *folio;if (!pfn_valid (pfn))return ; - page =pfn_to_page (pfn); -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (pfn))return ; -if (!test_and_set_bit (PG_dcache_clean, &page->flags)) + folio =page_folio (pfn_to_page (pfn)); +if (!test_and_set_bit (PG_dcache_clean, &folio->flags))dcache_wbinv_all (); -if (page_mapping_file (page)) { +if (folio_flush_mapping (folio)) {if (vma->vm_flags &VM_EXEC )icache_inv_all (); }arch/csky/abiv1/inc/abi/cacheflush.h +2
-0@@ -9,6 +9,8 @@#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1extern void flush_dcache_page (struct page *); +void flush_dcache_folio (struct folio *); +#define flush_dcache_folio flush_dcache_folio#define flush_cache_mm (mm) dcache_wbinv_all()#define flush_cache_page (vma, page, pfn) cache_wbinv_all()arch/csky/abiv2/cacheflush.c +0
-0@@ -6,30 +6,30 @@#include <linux/mm.h>
arch/csky/abiv2/cacheflush.c line 13
Quoted 10 lines
arch/csky/abiv2/cacheflush.c +3
-3#include <asm/cache.h> -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address, -pte_t *pte) +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *pte,unsigned int nr) { -unsigned long addr; +unsigned long pfn =pte_pfn (*pte);struct page *page;
Should be struct folio *folio instead:
CC arch/csky/abiv2/cacheflush.oarch/csky/abiv2/cacheflush.c: In function 'update_mmu_cache_range':arch/csky/abiv2/cacheflush.c:19:9: error: 'folio' undeclared (first use in this function)
19 | folio = page_folio(pfn_to_page(pfn));
| ^~~~~arch/csky/abiv2/cacheflush.c:19:9: note: each undeclared identifier is reported only once for each function it appears in arch/csky/abiv2/cacheflush.c:13:22: warning: unused variable 'page' [-Wunused-variable]
13 | struct page *page;
| ^~~~
Quoted 100 lines
arch/csky/abiv2/cacheflush.c +12
-12+unsigned int i; -if (!pfn_valid (pte_pfn (*pte))) +if (!pfn_valid (pfn) ||is_zero_pfn (pfn))return ; - page =pfn_to_page (pte_pfn (*pte)); -if (page ==ZERO_PAGE (0 )) -return ; + folio =page_folio (pfn_to_page (pfn)); -if (test_and_set_bit (PG_dcache_clean, &page->flags)) +if (test_and_set_bit (PG_dcache_clean, &folio->flags))return ; - addr = (unsigned long )kmap_atomic (page); - -dcache_wb_range (addr, addr +PAGE_SIZE ); +for (i =0 ; i <folio_nr_pages (folio); i++) { +unsigned long addr = (unsigned long )kmap_local_folio (folio, + i *PAGE_SIZE ); -if (vma->vm_flags &VM_EXEC ) -icache_inv_range (addr, addr +PAGE_SIZE ); - -kunmap_atomic ((void *) addr); +dcache_wb_range (addr, addr +PAGE_SIZE ); +if (vma->vm_flags &VM_EXEC ) +icache_inv_range (addr, addr +PAGE_SIZE ); +kunmap_local ((void *) addr); + } }void flush_icache_deferred (struct mm_struct *mm)arch/csky/abiv2/inc/abi/cacheflush.h +8
-2@@ -18,11 +18,17 @@#define PG_dcache_clean PG_arch_1 +static inline void flush_dcache_folio (struct folio *folio) +{ +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1static inline void flush_dcache_page (struct page *page) { -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +flush_dcache_folio (page_folio (page)); }#define flush_dcache_mmap_lock (mapping) do { } while (0)arch/csky/include/asm/pgtable.h +18
-3@@ -90,7 +90,20 @@ static inline void set_pte(pte_t *p, pte_t pte)/* prevent out of order excution */ smp_mb (); } -#define set_pte_at (mm, addr, ptep, pteval) set_pte(ptep, pteval) + +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline pte_t *pmd_page_vaddr (pmd_t pmd) {@@ -263,8 +276,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];extern void paging_init (void ); -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address, -pte_t *pte); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *pte,unsigned int nr); +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define io_remap_pfn_range (vma, vaddr, pfn, size, prot) \ remap_pfn_range(vma, vaddr, pfn, size, prot)Signature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox (Oracle)
maintainerPATCH v3 10/34 hexagon: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes() and update_mmu_cache_range().
--- arch/hexagon/include/asm/cacheflush.h | 7 +++++-- arch/hexagon/include/asm/pgtable.h | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-)
arch/hexagon/include/asm/cacheflush.h +5 -2
@@ -58,12 +58,15 @@ extern void flush_cache_all_hexagon(void);* clean the cache when the PTE is set. * */ -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) {/* generic_ptrace_pokedata doesn't wind up here, does it? */ } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1) +void copy_to_user_page (struct vm_area_struct *vma,struct page *page,unsigned long vaddr,void *dst,void *src,int len);#define copy_to_user_page copy_to_user_page
arch/hexagon/include/asm/pgtable.h +14 -2
@@ -346,12 +346,24 @@ static inline int pte_exec(pte_t pte)#define set_pmd (pmdptr, pmdval) (*(pmdptr) = (pmdval))/* -* set_pte_at - update page table and do whatever magic may be +* set_ptes - update page table and do whatever magic may be * necessary to make the underlying hardware/firmware take note. * * VM may require a virtual instruction to alert the MMU. */ -#define set_pte_at (mm, addr, ptep, pte) set_pte(ptep, pte) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline unsigned long pmd_page_vaddr (pmd_t pmd) {
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 11/34 ia64: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_clean) flag from being per-page to per-folio, which makes arch_dma_mark_clean() and mark_clean() a little more exciting.
--- arch/ia64/hp/common/sba_iommu.c | 26 +++++++++++++++----------- arch/ia64/include/asm/cacheflush.h | 14 ++++++++++---- arch/ia64/include/asm/pgtable.h | 14 +++++++++++++- arch/ia64/mm/init.c | 29 +++++++++++++++++++---------- 4 files changed, 57 insertions(+), 26 deletions(-)
arch/ia64/hp/common/sba_iommu.c +15 -11
@@ -798,22 +798,26 @@ sba_io_pdir_entry(u64 *pdir_ptr, unsigned long vba)#endif #ifdef ENABLE_MARK_CLEAN -/** +/* * Since DMA is i-cache coherent, any (complete) pages that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ -static void -mark_clean (void *addr,size_t size) +static void mark_clean (void *addr,size_t size) { -unsigned long pg_addr, end; - - pg_addr =PAGE_ALIGN ((unsigned long ) addr); - end = (unsigned long ) addr + size; -while (pg_addr +PAGE_SIZE <= end) { -struct page *page =virt_to_page ((void *)pg_addr); -set_bit (PG_arch_1, &page->flags); - pg_addr +=PAGE_SIZE ; +struct folio *folio =virt_to_folio (addr); +ssize_t left = size; +size_t offset =offset_in_folio (folio, addr); + +if (offset) { + left -=folio_size (folio) - offset; + folio =folio_next (folio); + } + +while (left >=folio_size (folio)) { +set_bit (PG_arch_1, &folio->flags); + left -=folio_size (folio); + folio =folio_next (folio); } }#endif
arch/ia64/include/asm/cacheflush.h +10 -4
@@ -13,10 +13,16 @@#include <asm/page.h> #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page (page) \ -do { \ - clear_bit(PG_arch_1, &(page)->flags); \ -} while (0) +static inline void flush_dcache_folio (struct folio *folio) +{ +clear_bit (PG_arch_1, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}extern void flush_icache_range (unsigned long start,unsigned long end);#define flush_icache_range flush_icache_range
arch/ia64/include/asm/pgtable.h +13 -1
@@ -303,7 +303,18 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr =0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, add, ptep, pte, 1)/* * Make page protection values cacheable, uncacheable, or write-
@@ -396,6 +407,7 @@ pte_same (pte_t a, pte_t b)return pte_val (a) =pte_val (b); } +#define update_mmu_cache_range (vma, address, ptep, nr) do { } while (0)#define update_mmu_cache (vma, address, ptep) do { } while (0)extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];
arch/ia64/mm/init.c +19 -10
@@ -50,30 +50,39 @@ void __ia64_sync_icache_dcache (pte_t pte) {unsigned long addr; -struct page *page; +struct folio *folio; - page =pte_page (pte); - addr = (unsigned long )page_address (page); + folio =page_folio (pte_page (pte)); + addr = (unsigned long )folio_address (folio); -if (test_bit (PG_arch_1, &page->flags)) +if (test_bit (PG_arch_1, &folio->flags))return ;/* i-cache is already coherent with d-cache */ -flush_icache_range (addr, addr +page_size (page)); -set_bit (PG_arch_1, &page->flags);/* mark page as clean */ +flush_icache_range (addr, addr +folio_size (folio)); +set_bit (PG_arch_1, &folio->flags);/* mark page as clean */ }/* -* Since DMA is i-cache coherent, any (complete) pages that were written via +* Since DMA is i-cache coherent, any (complete) folios that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ void arch_dma_mark_clean (phys_addr_t paddr,size_t size) { -unsigned long pfn =PHYS_PFN (paddr); +struct folio *folio =page_folio (phys_to_page (paddr)); +ssize_t left = size; +size_t offset =offset_in_folio (folio, paddr); -do { +if (offset) { + left -=folio_size (folio) - offset; + folio =folio_next (folio); + } + +while (left >= (ssize_t )folio_size (folio)) {set_bit (PG_arch_1, &pfn_to_page (pfn)->flags); - }while (++pfn <=PHYS_PFN (paddr + size -1 )); + left -=folio_size (folio); + folio =folio_next (folio); + } } inline void
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 11/34] ia64: Implement the new page table range API
Quoted 141 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range()andflush_dcache_folio(). Change thePG_arch_1(akaPG_dcache_clean) flag from being per-page to per-folio, which makesarch_dma_mark_clean()andmark_clean()a little more exciting.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- arch/ia64/hp/common/sba_iommu.c | 26 +++++++++++++++----------- arch/ia64/include/asm/cacheflush.h | 14 ++++++++++---- arch/ia64/include/asm/pgtable.h | 14 +++++++++++++- arch/ia64/mm/init.c | 29 +++++++++++++++++++---------- 4 files changed, 57 insertions(+), 26 deletions(-)arch/ia64/hp/common/sba_iommu.c +15
-11@@ -798,22 +798,26 @@ sba_io_pdir_entry(u64 *pdir_ptr, unsigned long vba)#endif #ifdef ENABLE_MARK_CLEAN -/** +/* * Since DMA is i-cache coherent, any (complete) pages that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ -static void -mark_clean (void *addr,size_t size) +static void mark_clean (void *addr,size_t size) { -unsigned long pg_addr, end; - - pg_addr =PAGE_ALIGN ((unsigned long ) addr); - end = (unsigned long ) addr + size; -while (pg_addr +PAGE_SIZE <= end) { -struct page *page =virt_to_page ((void *)pg_addr); -set_bit (PG_arch_1, &page->flags); - pg_addr +=PAGE_SIZE ; +struct folio *folio =virt_to_folio (addr); +ssize_t left = size; +size_t offset =offset_in_folio (folio, addr); + +if (offset) { + left -=folio_size (folio) - offset; + folio =folio_next (folio); + } + +while (left >=folio_size (folio)) { +set_bit (PG_arch_1, &folio->flags); + left -=folio_size (folio); + folio =folio_next (folio); } }#endif arch/ia64/include/asm/cacheflush.h +10
-4@@ -13,10 +13,16 @@#include <asm/page.h> #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page (page) \ -do { \ - clear_bit(PG_arch_1, &(page)->flags); \ -} while (0) +static inline void flush_dcache_folio (struct folio *folio) +{ +clear_bit (PG_arch_1, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}extern void flush_icache_range (unsigned long start,unsigned long end);#define flush_icache_range flush_icache_rangearch/ia64/include/asm/pgtable.h +13
-1@@ -303,7 +303,18 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr =0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, add, ptep, pte, 1)/* * Make page protection values cacheable, uncacheable, or write- @@ -396,6 +407,7 @@ pte_same (pte_t a, pte_t b)return pte_val (a) =pte_val (b); } +#define update_mmu_cache_range (vma, address, ptep, nr) do { } while (0)#define update_mmu_cache (vma, address, ptep) do { } while (0)extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];arch/ia64/mm/init.c +6
-7@@ -50,30 +50,39 @@ void __ia64_sync_icache_dcache (pte_t pte) {unsigned long addr; -struct page *page; +struct folio *folio; - page =pte_page (pte); - addr = (unsigned long )page_address (page); + folio =page_folio (pte_page (pte)); + addr = (unsigned long )folio_address (folio); -if (test_bit (PG_arch_1, &page->flags)) +if (test_bit (PG_arch_1, &folio->flags))return ;/* i-cache is already coherent with d-cache */ -flush_icache_range (addr, addr +page_size (page)); -set_bit (PG_arch_1, &page->flags);/* mark page as clean */ +flush_icache_range (addr, addr +folio_size (folio)); +set_bit (PG_arch_1, &folio->flags);/* mark page as clean */ }/* -* Since DMA is i-cache coherent, any (complete) pages that were written via
arch/ia64/mm/init.c void · line 74
Quoted 10 lines
arch/ia64/mm/init.c +4
-1+* Since DMA is i-cache coherent, any (complete) folios that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ void arch_dma_mark_clean (phys_addr_t paddr,size_t size) { -unsigned long pfn =PHYS_PFN (paddr); +struct folio *folio =page_folio (phys_to_page (paddr)); +ssize_t left = size; +size_t offset =offset_in_folio (folio, paddr);
Build of defconfig failed miserably for me without this:
arch/ia64/mm/init.c +2 -1
@@ -69,7 +69,8 @@ __ia64_sync_icache_dcache (pte_t pte)*/ void arch_dma_mark_clean (phys_addr_t paddr,size_t size) { -struct folio *folio =page_folio (phys_to_page (paddr)); +unsigned long pfn =__phys_to_pfn (paddr); +struct folio *folio =page_folio (pfn_to_page (pfn));ssize_t left = size;size_t offset =offset_in_folio (folio, paddr);
Quoted 19 lines
arch/ia64/mm/init.c +9
-2-do { +if (offset) { + left -=folio_size (folio) - offset; + folio =folio_next (folio); + } + +while (left >= (ssize_t )folio_size (folio)) {set_bit (PG_arch_1, &pfn_to_page (pfn)->flags); - }while (++pfn <=PHYS_PFN (paddr + size -1 )); + left -=folio_size (folio); + folio =folio_next (folio); + } } inline voidSignature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox
maintainerRe: [PATCH v3 11/34] ia64: Implement the new page table range API
Quoted 15 lines · Mike Rapoport
Review
Quoted 6 lines · Matthew Wilcox (Oracle)
void
arch_dma_mark_clean(phys_addr_t paddr, size_t size){(quoted diff) +3
-1- unsigned long pfn = PHYS_PFN(paddr); + struct folio *folio = page_folio(phys_to_page(paddr)); + ssize_t left = size; + size_t offset = offset_in_folio(folio, paddr);Build of defconfig failed miserably for me without this:
arch/ia64/mm/init.c +0
-0
arch/ia64/mm/init.c __ia64_sync_icache_dcache (pte_t pte) · line 73
Quoted 6 lines
arch/ia64/mm/init.c +2
-1@@ -69,7 +69,8 @@ __ia64_sync_icache_dcache (pte_t pte)*/ void arch_dma_mark_clean (phys_addr_t paddr,size_t size) { -struct folio *folio =page_folio (phys_to_page (paddr)); +unsigned long pfn =__phys_to_pfn (paddr); +struct folio *folio =page_folio (pfn_to_page (pfn));
Huh, TIL that only some architectures have phys_to_page(). Thanks. I'm going to use PHYS_PFN instead of __phys_to_pfn just to reduce the diff.
Matthew Wilcox (Oracle)
maintainerPATCH v3 12/34 loongarch: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes() and update_mmu_cache_range(). It would probably be more efficient to implement __update_tlb() by flushing the entire folio instead of calling it __update_tlb() N times, but I'll leave that for someone who understands the architecture better.
--- arch/loongarch/include/asm/cacheflush.h | 2 ++ arch/loongarch/include/asm/pgtable.h | 30 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-)
arch/loongarch/include/asm/cacheflush.h +2 -0
@@ -47,8 +47,10 @@ void local_flush_icache_range(unsigned long start, unsigned long end);#define flush_cache_vmap (start, end) do { } while (0)#define flush_cache_vunmap (start, end) do { } while (0)#define flush_icache_page (vma, page) do { } while (0) +#define flush_icache_pages (vma, page) do { } while (0)#define flush_icache_user_page (vma, page, addr, len) do { } while (0)#define flush_dcache_page (page) do { } while (0) +#define flush_dcache_folio (folio) do { } while (0)#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0)
arch/loongarch/include/asm/pgtable.h +23 -7
@@ -334,12 +334,20 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) } } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) -{ -set_pte (ptep, pteval); +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 << _PFN_SHIFT; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +static inline void pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) {/* Preserve global status for the pair */
@@ -445,11 +453,19 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)extern void __update_tlb (struct vm_area_struct *vma,unsigned long address,pte_t *ptep); -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) { -__update_tlb (vma, address, ptep); +for (;;) { +__update_tlb (vma, address, ptep); +if (--nr ==0 ) +break ; + address +=PAGE_SIZE ; + ptep++; + } } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define __HAVE_ARCH_UPDATE_MMU_TLB#define update_mmu_tlb update_mmu_cache
Signature · 1 line
2.39.1
WANG Xuerui
reviewerRe: [PATCH v3 12/34] loongarch: Implement the new page table range API
Hi,
Quoted 4 lines · Matthew Wilcox (Oracle)
Add
set_ptes()andupdate_mmu_cache_range(). It would probably be more efficient to implement__update_tlb()by flushing the entire folio instead of calling it__update_tlb()N times, but I'll leave that for someone who understands the architecture better.
Thanks for the patch! Unfortunately it doesn't seem possible architecture-wise to batch-flush pages right now on loongarch, but AFAIK the vendor *could* be listening so a future model could have the feature supported... who knows!
Quoted 15 lines
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Cc Huacai Chen <[email protected]>Cc WANG Xuerui <[email protected]>--- arch/loongarch/include/asm/cacheflush.h | 2 ++ arch/loongarch/include/asm/pgtable.h | 30 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-)arch/loongarch/include/asm/cacheflush.h +0
-0
arch/loongarch/include/asm/cacheflush.h void local_flush_icache_range(unsigned long start, unsigned long end); · line 53
Quoted 7 lines
arch/loongarch/include/asm/cacheflush.h +2
-0@@ -47,8 +47,10 @@ void local_flush_icache_range(unsigned long start, unsigned long end);#define flush_cache_vmap (start, end) do { } while (0)#define flush_cache_vunmap (start, end) do { } while (0)#define flush_icache_page (vma, page) do { } while (0) +#define flush_icache_pages (vma, page) do { } while (0)#define flush_icache_user_page (vma, page, addr, len) do { } while (0)#define flush_dcache_page (page) do { } while (0) +#define flush_dcache_folio (folio) do { } while (0)
This will break the build because the surrounding code is unnecessarily redefining the stubs that the asm-generic include at the end of the file will properly take care of. With the build fixed (patch attached below), I can successfully boot-test and stress mm for a while on a Loongson 3A5000. I haven't done the benchmarks though.
arch/loongarch/include/asm/cacheflush.h void local_flush_icache_range(unsigned long start, unsigned long end); · line 56
Quoted 4 lines
arch/loongarch/include/asm/cacheflush.h +0
-0#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0)
Cleanup patch:
-- >8 --
From 0de3f49e6ba23c1b45e7b5da355f87398c4a7feb Mon Sep 17 00:00:00 2001
From: WANG Xuerui <[email protected]>
Date: Wed, 1 Mar 2023 09:32:18 +0800
Subject: [PATCH] LoongArch: Remove stub definitions in cacheflush.h
Per the current best practice in mm, it's unnecessary to define no-op stubs explicitly in arch code, because the asm-generic inclusion at the end of the file will properly take care of these. And the definition of ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE to 0 is going to confuse the asm-generic code, so remove the stubs for clarity and avoiding misuse.
--- arch/loongarch/include/asm/cacheflush.h | 15 --------------- 1 file changed, 15 deletions(-)
arch/loongarch/include/asm/cacheflush.h +0 -15
@@ -37,21 +37,6 @@ void local_flush_icache_range(unsigned long start, unsigned long end);#define flush_icache_range local_flush_icache_range#define flush_icache_user_range local_flush_icache_range -#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0 - -#define flush_cache_all () do { } while (0) -#define flush_cache_mm (mm) do { } while (0) -#define flush_cache_dup_mm (mm) do { } while (0) -#define flush_cache_range (vma, start, end) do { } while (0) -#define flush_cache_page (vma, vmaddr, pfn) do { } while (0) -#define flush_cache_vmap (start, end) do { } while (0) -#define flush_cache_vunmap (start, end) do { } while (0) -#define flush_icache_user_page (vma, page, addr, len) do { } while (0) -#define flush_dcache_page (page) do { } while (0) -#define flush_dcache_folio (folio) do { } while (0) -#define flush_dcache_mmap_lock (mapping) do { } while (0) -#define flush_dcache_mmap_unlock (mapping) do { } while (0) -#define cache_op (op, addr) \ __asm__ __volatile__( \ " cacop %0, %1 \n" \
Signature · 3 lines
WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
Matthew Wilcox (Oracle)
maintainerPATCH v3 13/34 m68k: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio().
--- arch/m68k/include/asm/cacheflush_mm.h | 26 +++++++++++++++++--------- arch/m68k/include/asm/pgtable_mm.h | 21 ++++++++++++++++++--- arch/m68k/mm/motorola.c | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-)
arch/m68k/include/asm/cacheflush_mm.h +17 -9
@@ -220,24 +220,28 @@ static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm/* Push the page at kernel virtual address and clear the icache */ /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */ -static inline void __flush_page_to_ram (void *vaddr) +static inline void __flush_pages_to_ram (void *vaddr,unsigned int nr) {if (CPU_IS_COLDFIRE ) {unsigned long addr, start, end; addr = ((unsigned long ) vaddr) & ~(PAGE_SIZE -1 ); start = addr &ICACHE_SET_MASK ; - end = (addr +PAGE_SIZE -1 ) &ICACHE_SET_MASK ; + end = (addr + nr *PAGE_SIZE -1 ) &ICACHE_SET_MASK ;if (start > end) {flush_cf_bcache (0 , end); end =ICACHE_MAX_ADDR ; }flush_cf_bcache (start, end); }else if (CPU_IS_040_OR_060 ) { - __asm__ __volatile__("nop\n\t" -".chip 68040\n\t" -"cpushp %%bc,(%0)\n\t" -".chip 68k" - : :"a" (__pa (vaddr))); +unsigned long paddr =__pa (vaddr); + +while (nr--) { + __asm__ __volatile__("nop\n\t" +".chip 68040\n\t" +"cpushp %%bc,(%0)\n\t" +".chip 68k" + : :"a" (paddr + nr *PAGE_SIZE )); + } }else {unsigned long _tmp; __asm__ __volatile__("movec %%cacr,%0\n\t"
@@ -249,10 +253,14 @@ static inline void __flush_page_to_ram(void *vaddr) }#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page (page) __flush_page_to_ram(page_address(page)) +#define flush_dcache_page (page) __flush_pages_to_ram(page_address(page), 1) +#define flush_dcache_folio (folio) \ + __flush_pages_to_ram(folio_address(folio), folio_nr_pages(folio))#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0) -#define flush_icache_page (vma, page) __flush_page_to_ram(page_address(page)) +#define flush_icache_pages (vma, page, nr) \ + __flush_pages_to_ram(page_address(page), nr) +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1)extern void flush_icache_user_page (struct vm_area_struct *vma,struct page *page,unsigned long addr,int len);
arch/m68k/include/asm/pgtable_mm.h +18 -3
@@ -31,8 +31,20 @@do { \ *(pteptr) = (pteval); \ } while(0) -#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* PMD_SHIFT determines the size of the area a second-level page table can map */ #if CONFIG_PGTABLE_LEVELS ==3
@@ -138,11 +150,14 @@ extern void kernel_set_cachemode(void *addr, unsigned long size, int cmode);* tables contain all the necessary information. The Sun3 does, but * they are updated on demand. */ -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) { } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1) +#endif /* !__ASSEMBLY__ */ /* MMU-specific headers */
arch/m68k/mm/motorola.c +1 -1
@@ -81,7 +81,7 @@ static inline void cache_page(void *vaddr)void mmu_page_ctor (void *page) { -__flush_page_to_ram (page); +__flush_pages_to_ram (page,1 );flush_tlb_kernel_page (page);nocache_page (page); }
Signature · 1 line
2.39.1
Geert Uytterhoeven
maintainerRe: [PATCH v3 13/34] m68k: Implement the new page table range API
Hi Willy,
Quoted 4 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range(),flush_icache_pages()andflush_dcache_folio().Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
Thanks for your patch!
Quoted 24 lines
arch/m68k/include/asm/cacheflush_mm.h +2
-5@@ -220,24 +220,28 @@ static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm/* Push the page at kernel virtual address and clear the icache */ /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */ -static inline void __flush_page_to_ram (void *vaddr) +static inline void __flush_pages_to_ram (void *vaddr,unsigned int nr) {if (CPU_IS_COLDFIRE ) {unsigned long addr, start, end; addr = ((unsigned long ) vaddr) & ~(PAGE_SIZE -1 ); start = addr &ICACHE_SET_MASK ; - end = (addr +PAGE_SIZE -1 ) &ICACHE_SET_MASK ; + end = (addr + nr *PAGE_SIZE -1 ) &ICACHE_SET_MASK ;if (start > end) {flush_cf_bcache (0 , end); end =ICACHE_MAX_ADDR ; }flush_cf_bcache (start, end); }else if (CPU_IS_040_OR_060 ) { - __asm__ __volatile__("nop\n\t" -".chip 68040\n\t" - "cpushp %%bc,(%0)\n\t"
arch/m68k/include/asm/cacheflush_mm.h static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm · line 243
Quoted 10 lines
arch/m68k/include/asm/cacheflush_mm.h +8
-2- ".chip 68k" - : : "a" (__pa(vaddr))); +unsigned long paddr =__pa (vaddr); + +while (nr--) { + __asm__ __volatile__("nop\n\t" +".chip 68040\n\t" +"cpushp %%bc,(%0)\n\t" +".chip 68k" + : :"a" (paddr + nr *PAGE_SIZE ));
As gcc (9.5.0) keeps on calculating "paddr + nr * PAGE_SIZE" inside the loop (albeit using a shift instead of a multiplication), please use "paddr" here, followed by "paddr += PAGE_SIZE;".
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Matthew Wilcox
maintainerRe: [PATCH v3 13/34] m68k: Implement the new page table range API
Quoted 10 lines · Geert Uytterhoeven
arch/m68k/include/asm/cacheflush_mm.h static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm · line 243
Quoted 6 lines
arch/m68k/include/asm/cacheflush_mm.h +6
-0+while (nr--) { + __asm__ __volatile__("nop\n\t" +".chip 68040\n\t" +"cpushp %%bc,(%0)\n\t" +".chip 68k" + : :"a" (paddr + nr *PAGE_SIZE ));As gcc (9.5.0) keeps on calculating "paddr + nr *
PAGE_SIZE" inside the loop (albeit using a shift instead of a multiplication), please use "paddr" here, followed by "paddr +=PAGE_SIZE;".
Thanks. So this?
+++ b/arch/m68k/include/asm/cacheflush_mm.h
@@ -235,13 +235,14 @@ static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr)
} else if (CPU_IS_040_OR_060) {
unsigned long paddr = __pa(vaddr);- while (nr--) {
+ do {
__asm__ __volatile__("nop\n\t"
".chip 68040\n\t"
"cpushp %%bc,(%0)\n\t"
".chip 68k"- : : "a" (paddr + nr * PAGE_SIZE));
- }
+ : : "a" (paddr));
+ paddr += PAGE_SIZE;
+ } while (--nr);
} else {
unsigned long _tmp;
__asm__ __volatile__("movec %%cacr,%0\n\t"Also, I noticed that I broke sun3. It puts the PFN in bits 0-n instead of 12-n. New patch coming soon.
Geert Uytterhoeven
maintainerRe: [PATCH v3 13/34] m68k: Implement the new page table range API
Hi Willy,
Quoted 23 lines · Matthew Wilcox
Quoted 10 lines · Geert Uytterhoeven
arch/m68k/include/asm/cacheflush_mm.h static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm · line 243
Quoted 6 lines
arch/m68k/include/asm/cacheflush_mm.h +6
-0+while (nr--) { + __asm__ __volatile__("nop\n\t" +".chip 68040\n\t" +"cpushp %%bc,(%0)\n\t" +".chip 68k" + : :"a" (paddr + nr *PAGE_SIZE ));As gcc (9.5.0) keeps on calculating "paddr + nr *
PAGE_SIZE" inside the loop (albeit using a shift instead of a multiplication), please use "paddr" here, followed by "paddr +=PAGE_SIZE;".Thanks. So this?
+++
b/arch/m68k/include/asm/cacheflush_mm.h(quoted diff) +1
-1@@ -235,13 +235,14 @@ static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr) } else if (CPU_IS_040_OR_060) { unsigned long paddr = __pa(vaddr); - while (nr--) { + do { __asm__ __volatile__("nop\n\t" ".chip 68040\n\t"
Review static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr) · line 248
Quoted 10 lines
(quoted diff) +3
-2"cpushp %%bc,(%0)\n\t" ".chip 68k" - : : "a" (paddr + nr * PAGE_SIZE)); - } + : : "a" (paddr)); + paddr += PAGE_SIZE; + } while (--nr); } else { unsigned long _tmp; __asm__ __volatile__("movec %%cacr,%0\n\t"
LGTM. Might be safer to keep the "while (nr--) {", just in case someone ever passes zero.
Quoted 2 lines
Also, I noticed that I broke sun3. It puts the PFN in bits 0-n instead of 12-n. New patch coming soon.
Thanks, hadn't noticed (there are no sun3-specific code changes in this series?)
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v3 13/34] m68k: Implement the new page table range API
In reply to Matthew WilcoxHi Matthew, Geert,
sorry, I missed that one when it got posted ...
Quoted 10 lines · Matthew Wilcox
Quoted 9 lines · Geert Uytterhoeven
arch/m68k/include/asm/cacheflush_mm.h static inline void flush_cache_page(struct vm_area_struct *vma, unsigned long vm · line 243
Quoted 6 lines
arch/m68k/include/asm/cacheflush_mm.h +6
-0+while (nr--) { + __asm__ __volatile__("nop\n\t" +".chip 68040\n\t" +"cpushp %%bc,(%0)\n\t" +".chip 68k" + : :"a" (paddr + nr *PAGE_SIZE ));As gcc (9.5.0) keeps on calculating "paddr + nr *
PAGE_SIZE" inside the loop (albeit using a shift instead of a multiplication), please use "paddr" here, followed by "paddr +=PAGE_SIZE;".
Are we certain that contiguous vaddr always maps to contiguous paddr?
If not, I'd suggest we increment vaddr inside the loop, and use __pa() each time:
Quoted 9 lines
+++
b/arch/m68k/include/asm/cacheflush_mm.h(quoted diff) +1
-1@@ -235,13 +235,14 @@ static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr) } else if (CPU_IS_040_OR_060) { - while (nr--) { + do { __asm__ __volatile__("nop\n\t" ".chip 68040\n\t" "cpushp %%bc,(%0)\n\t"
Review static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr) · line 248
Quoted 10 lines
(quoted diff) +3
-2".chip 68k" - : : "a" (paddr + nr * PAGE_SIZE)); - } + : : "a" __pa(vaddr)); + vaddr += PAGE_SIZE; + } while (--nr); } else { unsigned long _tmp; __asm__ __volatile__("movec %%cacr,%0\n\t"
(just edited Matthew's patch in the mail editor, untested, may not apply cleanly ...)
Cheers,
Michael
Geert Uytterhoeven
maintainerRe: [PATCH v3 13/34] m68k: Implement the new page table range API
Hi Michael,
Quoted 8 lines · Michael Schmitz
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Geert Uytterhoeven
Quoted 6 lines
arch/m68k/include/asm/cacheflush_mm.h +6
-0+while (nr--) { + __asm__ __volatile__("nop\n\t" +".chip 68040\n\t" +"cpushp %%bc,(%0)\n\t" +".chip 68k" + : :"a" (paddr + nr *PAGE_SIZE ));
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
As gcc (9.5.0) keeps on calculating "paddr + nr *
PAGE_SIZE" inside the loop (albeit using a shift instead of a multiplication), please use "paddr" here, followed by "paddr +=PAGE_SIZE;".Are we certain that contiguous vaddr always maps to contiguous paddr?
For a general __flush_pages_to_ram() function, that would not be guaranteed. But as this is meant for folios, it must be true:
https://elixir.bootlin.com/linux/latest/source/include/linux/mm_types.h#L320
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v3 13/34] m68k: Implement the new page table range API
Hi Geert,
Quoted 4 lines · Geert Uytterhoeven
Quoted 1 line
Are we certain that contiguous vaddr always maps to contiguous paddr?
For a general
__flush_pages_to_ram()function, that would not be guaranteed. But as this is meant for folios, it must be true:
https://elixir.bootlin.com/linux/latest/source/include/linux/mm_types.h#L320
Thanks for explaining - that just leaves the problem of cowboys like myself abusing __flush_pages_to_ram(addr, nr) with nr > 1 for something that isn't a folio. Maybe a comment 'nr > 1 only valid on folios' would help ...
Cheers,
Michael
Quoted 5 lines
Gr{oetje,eeting}s,
Geert
Matthew Wilcox (Oracle)
maintainerPATCH v3 14/34 microblaze: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Also change the calling convention for set_pte() to be the same as other architectures.
--- arch/microblaze/include/asm/cacheflush.h | 8 ++++++++ arch/microblaze/include/asm/pgtable.h | 17 ++++++++++++----- arch/microblaze/include/asm/tlbflush.h | 4 +++- 3 files changed, 23 insertions(+), 6 deletions(-)
arch/microblaze/include/asm/cacheflush.h +8 -0
@@ -74,6 +74,14 @@ do { \flush_dcache_range ((unsigned ) (addr), (unsigned ) (addr) +PAGE_SIZE ); \ }while (0 ); +static void flush_dcache_folio (struct folio *folio) +{ +unsigned long addr =folio_pfn (folio) <<PAGE_SHIFT ; + +flush_dcache_range (addr, addr +folio_size (folio)); +} +#define flush_dcache_folio flush_dcache_folio +#define flush_cache_page (vma, vmaddr, pfn) \ flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE);
arch/microblaze/include/asm/pgtable.h +12 -5
@@ -330,18 +330,25 @@ static inline unsigned long pte_update(pte_t *p, unsigned long clr,/* * set_pte stores a linux PTE into the linux page table. */ -static inline void set_pte (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) +static inline void set_pte (pte_t *ptep,pte_t pte) { *ptep = pte; } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { - *ptep = pte; +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 <<PFN_SHIFT_OFFSET ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNGstatic inline int ptep_test_and_clear_young (struct vm_area_struct *vma,unsigned long address,pte_t *ptep)
arch/microblaze/include/asm/tlbflush.h +3 -1
@@ -33,7 +33,9 @@ static inline void local_flush_tlb_range(struct vm_area_struct *vma,#define flush_tlb_kernel_range (start, end) do { } while (0) -#define update_mmu_cache (vma, addr, ptep) do { } while (0) +#define update_mmu_cache_range (vma, addr, ptep, nr) do { } while (0) +#define update_mmu_cache (vma, addr, pte) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define flush_tlb_all local_flush_tlb_all#define flush_tlb_mm local_flush_tlb_mm
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 14/34] microblaze: Implement the new page table range API
Quoted 48 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range(),flush_icache_pages()andflush_dcache_folio(). Also change the calling convention forset_pte()to be the same as other architectures.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Cc Michal Simek <[email protected]>--- arch/microblaze/include/asm/cacheflush.h | 8 ++++++++ arch/microblaze/include/asm/pgtable.h | 17 ++++++++++++----- arch/microblaze/include/asm/tlbflush.h | 4 +++- 3 files changed, 23 insertions(+), 6 deletions(-)arch/microblaze/include/asm/cacheflush.h +8
-0@@ -74,6 +74,14 @@ do { \flush_dcache_range ((unsigned ) (addr), (unsigned ) (addr) +PAGE_SIZE ); \ }while (0 ); +static void flush_dcache_folio (struct folio *folio) +{ +unsigned long addr =folio_pfn (folio) <<PAGE_SHIFT ; + +flush_dcache_range (addr, addr +folio_size (folio)); +} +#define flush_dcache_folio flush_dcache_folio +#define flush_cache_page (vma, vmaddr, pfn) \ flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE);arch/microblaze/include/asm/pgtable.h +1
-4@@ -330,18 +330,25 @@ static inline unsigned long pte_update(pte_t *p, unsigned long clr,/* * set_pte stores a linux PTE into the linux page table. */ -static inline void set_pte (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) +static inline void set_pte (pte_t *ptep,pte_t pte) { *ptep = pte; } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte)
arch/microblaze/include/asm/pgtable.h static inline unsigned long pte_update(pte_t *p, unsigned long clr, · line 346
Quoted 10 lines
arch/microblaze/include/asm/pgtable.h +8
-1+static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { - *ptep = pte; +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 <<PFN_SHIFT_OFFSET ;
This is the same as
pte_val(pte) += PAGE_SIZE;
isn't it?
Quoted 27 lines
arch/microblaze/include/asm/pgtable.h +3
-0+ } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNGstatic inline int ptep_test_and_clear_young (struct vm_area_struct *vma,unsigned long address,pte_t *ptep)arch/microblaze/include/asm/tlbflush.h +3
-1@@ -33,7 +33,9 @@ static inline void local_flush_tlb_range(struct vm_area_struct *vma,#define flush_tlb_kernel_range (start, end) do { } while (0) -#define update_mmu_cache (vma, addr, ptep) do { } while (0) +#define update_mmu_cache_range (vma, addr, ptep, nr) do { } while (0) +#define update_mmu_cache (vma, addr, pte) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define flush_tlb_all local_flush_tlb_all#define flush_tlb_mm local_flush_tlb_mmSignature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox
maintainerRe: [PATCH v3 14/34] microblaze: Implement the new page table range API
Quoted 14 lines · Mike Rapoport
arch/microblaze/include/asm/pgtable.h static inline unsigned long pte_update(pte_t *p, unsigned long clr, · line 346
Quoted 10 lines · Matthew Wilcox (Oracle)
arch/microblaze/include/asm/pgtable.h +8
-1+static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { - *ptep = pte; +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 <<PFN_SHIFT_OFFSET ;This is the same as
Quoted 3 lines
pte_val(pte) += PAGE_SIZE;isn't it?
Looks like it. Based on this:
$ git grep PFN_SHIFT_OFFSET arch/microblaze/ arch/microblaze/include/asm/pgtable.h:#define PFN_SHIFT_OFFSET (PAGE_SHIFT) arch/microblaze/include/asm/pgtable.h:#define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET)
I only looked at the definition of pte_pfn(); I didn't look to see how PFN_SHIFT_OFFSET was defined. I don't see the need to change it from what I have though?
Matthew Wilcox (Oracle)
maintainerPATCH v3 15/34 mips: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
--- arch/mips/include/asm/cacheflush.h | 32 +++++++++++------ arch/mips/include/asm/pgtable.h | 36 +++++++++++++------ arch/mips/mm/c-r4k.c | 5 +-- arch/mips/mm/cache.c | 56 +++++++++++++++--------------- arch/mips/mm/init.c | 17 +++++---- 5 files changed, 88 insertions(+), 58 deletions(-)
arch/mips/include/asm/cacheflush.h +21 -11
@@ -36,12 +36,12 @@*/ #define PG_dcache_dirty PG_arch_1 -#define Page_dcache_dirty (page) \ - test_bit(PG_dcache_dirty, &(page)->flags) -#define SetPageDcacheDirty (page) \ - set_bit(PG_dcache_dirty, &(page)->flags) -#define ClearPageDcacheDirty (page) \ - clear_bit(PG_dcache_dirty, &(page)->flags) +#define folio_test_dcache_dirty (folio) \ + test_bit(PG_dcache_dirty, &(folio)->flags) +#define folio_set_dcache_dirty (folio) \ + set_bit(PG_dcache_dirty, &(folio)->flags) +#define folio_clear_dcache_dirty (folio) \ + clear_bit(PG_dcache_dirty, &(folio)->flags)extern void (*flush_cache_all)(void );extern void (*__flush_cache_all)(void );
@@ -50,15 +50,24 @@ extern void (*flush_cache_mm)(struct mm_struct *mm);extern void (*flush_cache_range)(struct vm_area_struct *vma,unsigned long start,unsigned long end);extern void (*flush_cache_page)(struct vm_area_struct *vma,unsigned long page,unsigned long pfn); -extern void __flush_dcache_page (struct page *page); +extern void __flush_dcache_pages (struct page *page,unsigned int nr);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +static inline void flush_dcache_folio (struct folio *folio) +{ +if (cpu_has_dc_aliases) +__flush_dcache_pages (&folio->page,folio_nr_pages (folio)); +else if (!cpu_has_ic_fills_f_dc) +folio_set_dcache_dirty (folio); +} +#define flush_dcache_folio flush_dcache_folio +static inline void flush_dcache_page (struct page *page) {if (cpu_has_dc_aliases) -__flush_dcache_page (page); +__flush_dcache_pages (page,1 );else if (!cpu_has_ic_fills_f_dc) -SetPageDcacheDirty (page); +folio_set_dcache_dirty (page_folio (page)); }#define flush_dcache_mmap_lock (mapping) do { } while (0)
@@ -73,10 +82,11 @@ static inline void flush_anon_page(struct vm_area_struct *vma,__flush_anon_page (page, vmaddr); } -static inline void flush_icache_page (struct vm_area_struct *vma, -struct page *page) +static inline void flush_icache_pages (struct vm_area_struct *vma, +struct page *page,unsigned int nr) { } +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1)extern void (*flush_icache_range)(unsigned long start,unsigned long end);extern void (*local_flush_icache_range)(unsigned long start,unsigned long end);
arch/mips/include/asm/pgtable.h +25 -11
@@ -105,8 +105,10 @@ do { \ } \ }while (0 ) -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, -pte_t *ptep,pte_t pteval); +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr); + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && defined(CONFIG_CPU_MIPS32 )
@@ -204,19 +206,31 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *pt }#endif -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { +unsigned int i; +bool do_sync = false; -if (!pte_present (pteval)) - goto cache_sync_done; +for (i =0 ; i < nr; i++) { +if (!pte_present (pte)) +continue ; +if (pte_present (ptep[i]) && + (pte_pfn (ptep[i]) ==pte_pfn (pte))) +continue ; + do_sync = true; + } -if (pte_present (*ptep) && (pte_pfn (*ptep) ==pte_pfn (pteval))) - goto cache_sync_done; +if (do_sync) +__update_cache (addr, pte); -__update_cache (addr, pteval); -cache_sync_done: -set_pte (ptep, pteval); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 << _PFN_SHIFT; + } }/*
arch/mips/mm/c-r4k.c +3 -2
@@ -679,13 +679,14 @@ static inline void local_r4k_flush_cache_page(void *args)if ((mm == current->active_mm) && (pte_val (*ptep) & _PAGE_VALID)) vaddr =NULL ;else { +struct folio *folio =page_folio (page);/* * Use kmap_coherent or kmap_atomic to do flushes for * another ASID than the current one. */ map_coherent = (cpu_has_dc_aliases && -page_mapcount (page) && - !Page_dcache_dirty (page)); +folio_mapped (folio) && + !folio_test_dcache_dirty (folio));if (map_coherent) vaddr =kmap_coherent (page, addr);else
arch/mips/mm/cache.c +28 -28
93 lines not on this page · raw message
arch/mips/mm/init.c +11 -6
@@ -88,7 +88,7 @@ static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot)pte_t pte;int tlbidx; -BUG_ON (Page_dcache_dirty (page)); +BUG_ON (folio_test_dcache_dirty (page_folio (page)));preempt_disable ();pagefault_disable ();
@@ -169,11 +169,12 @@ void kunmap_coherent(void)void copy_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +struct folio *src =page_folio (from);void *vfrom, *vto; vto =kmap_atomic (to);if (cpu_has_dc_aliases && -page_mapcount (from) && !Page_dcache_dirty (from)) { +folio_mapped (src) && !folio_test_dcache_dirty (src)) { vfrom =kmap_coherent (from, vaddr);copy_page (vto, vfrom);kunmap_coherent ();
@@ -194,15 +195,17 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); +if (cpu_has_dc_aliases && - page_mapcount(page) && !Page_dcache_dirty(page)) { +folio_mapped (folio) && !folio_test_dcache_dirty (folio)) {void *vto =kmap_coherent (page, vaddr) + (vaddr & ~PAGE_MASK );memcpy (vto, src, len);kunmap_coherent (); }else {memcpy (dst, src, len);if (cpu_has_dc_aliases) -SetPageDcacheDirty (page); +folio_set_dcache_dirty (folio); }if (vma->vm_flags &VM_EXEC )flush_cache_page (vma, vaddr,page_to_pfn (page));
@@ -212,15 +215,17 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); +if (cpu_has_dc_aliases && - page_mapcount(page) && !Page_dcache_dirty(page)) { +folio_mapped (folio) && !folio_test_dcache_dirty (folio)) {void *vfrom =kmap_coherent (page, vaddr) + (vaddr & ~PAGE_MASK );memcpy (dst, vfrom, len);kunmap_coherent (); }else {memcpy (dst, src, len);if (cpu_has_dc_aliases) -SetPageDcacheDirty (page); +folio_set_dcache_dirty (folio); } }EXPORT_SYMBOL_GPL (copy_from_user_page);
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 15/34] mips: Implement the new page table range API
Quoted 3 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range(),flush_icache_pages()andflush_dcache_folio(). Change thePG_arch_1(akaPG_dcache_dirty) flag from being per-page to per-folio.
Looks like update_mmu_cache_range() is missing:
CC mm/memory.omm/memory.c: In function 'set_pte_range':mm/memory.c:4291:9: error: implicit declaration of function 'update_mmu_cache_range'; did you mean 'update_mmu_cache_pmd'? [-Werror=implicit-function-declaration]
4291 | update_mmu_cache_range(vma, addr, vmf->pte, nr);
| ^~~~~~~~~~~~~~~~~~~~~~
| update_mmu_cache_pmdcc1: some warnings being treated as errors
Quoted 326 lines
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Cc Thomas Bogendoerfer <[email protected]>--- arch/mips/include/asm/cacheflush.h | 32 +++++++++++------ arch/mips/include/asm/pgtable.h | 36 +++++++++++++------ arch/mips/mm/c-r4k.c | 5 +-- arch/mips/mm/cache.c | 56 +++++++++++++++--------------- arch/mips/mm/init.c | 17 +++++---- 5 files changed, 88 insertions(+), 58 deletions(-)arch/mips/include/asm/cacheflush.h +21
-11@@ -36,12 +36,12 @@*/ #define PG_dcache_dirty PG_arch_1 -#define Page_dcache_dirty (page) \ - test_bit(PG_dcache_dirty, &(page)->flags) -#define SetPageDcacheDirty (page) \ - set_bit(PG_dcache_dirty, &(page)->flags) -#define ClearPageDcacheDirty (page) \ - clear_bit(PG_dcache_dirty, &(page)->flags) +#define folio_test_dcache_dirty (folio) \ + test_bit(PG_dcache_dirty, &(folio)->flags) +#define folio_set_dcache_dirty (folio) \ + set_bit(PG_dcache_dirty, &(folio)->flags) +#define folio_clear_dcache_dirty (folio) \ + clear_bit(PG_dcache_dirty, &(folio)->flags)extern void (*flush_cache_all)(void );extern void (*__flush_cache_all)(void );@@ -50,15 +50,24 @@ extern void (*flush_cache_mm)(struct mm_struct *mm);extern void (*flush_cache_range)(struct vm_area_struct *vma,unsigned long start,unsigned long end);extern void (*flush_cache_page)(struct vm_area_struct *vma,unsigned long page,unsigned long pfn); -extern void __flush_dcache_page (struct page *page); +extern void __flush_dcache_pages (struct page *page,unsigned int nr);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +static inline void flush_dcache_folio (struct folio *folio) +{ +if (cpu_has_dc_aliases) +__flush_dcache_pages (&folio->page,folio_nr_pages (folio)); +else if (!cpu_has_ic_fills_f_dc) +folio_set_dcache_dirty (folio); +} +#define flush_dcache_folio flush_dcache_folio +static inline void flush_dcache_page (struct page *page) {if (cpu_has_dc_aliases) -__flush_dcache_page (page); +__flush_dcache_pages (page,1 );else if (!cpu_has_ic_fills_f_dc) -SetPageDcacheDirty (page); +folio_set_dcache_dirty (page_folio (page)); }#define flush_dcache_mmap_lock (mapping) do { } while (0)@@ -73,10 +82,11 @@ static inline void flush_anon_page(struct vm_area_struct *vma,__flush_anon_page (page, vmaddr); } -static inline void flush_icache_page (struct vm_area_struct *vma, -struct page *page) +static inline void flush_icache_pages (struct vm_area_struct *vma, +struct page *page,unsigned int nr) { } +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1)extern void (*flush_icache_range)(unsigned long start,unsigned long end);extern void (*local_flush_icache_range)(unsigned long start,unsigned long end);arch/mips/include/asm/pgtable.h +25
-11@@ -105,8 +105,10 @@ do { \ } \ }while (0 ) -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, -pte_t *ptep,pte_t pteval); +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr); + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && defined(CONFIG_CPU_MIPS32 )@@ -204,19 +206,31 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *pt }#endif -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { +unsigned int i; +bool do_sync = false; -if (!pte_present (pteval)) - goto cache_sync_done; +for (i =0 ; i < nr; i++) { +if (!pte_present (pte)) +continue ; +if (pte_present (ptep[i]) && + (pte_pfn (ptep[i]) ==pte_pfn (pte))) +continue ; + do_sync = true; + } -if (pte_present (*ptep) && (pte_pfn (*ptep) ==pte_pfn (pteval))) - goto cache_sync_done; +if (do_sync) +__update_cache (addr, pte); -__update_cache (addr, pteval); -cache_sync_done: -set_pte (ptep, pteval); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 << _PFN_SHIFT; + } }/* arch/mips/mm/c-r4k.c +3
-2@@ -679,13 +679,14 @@ static inline void local_r4k_flush_cache_page(void *args)if ((mm == current->active_mm) && (pte_val (*ptep) & _PAGE_VALID)) vaddr =NULL ;else { +struct folio *folio =page_folio (page);/* * Use kmap_coherent or kmap_atomic to do flushes for * another ASID than the current one. */ map_coherent = (cpu_has_dc_aliases && -page_mapcount (page) && - !Page_dcache_dirty (page)); +folio_mapped (folio) && + !folio_test_dcache_dirty (folio));if (map_coherent) vaddr =kmap_coherent (page, addr);else arch/mips/mm/cache.c +28
-28@@ -82,13 +82,15 @@ SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, bytes,return 0 ; } -void __flush_dcache_page (struct page *page) +void __flush_dcache_pages (struct page *page,unsigned int nr) { -struct address_space *mapping =page_mapping_file (page); +struct folio *folio =page_folio (page); +struct address_space *mapping =folio_flush_mapping (folio);unsigned long addr; +unsigned int i;if (mapping && !mapping_mapped (mapping)) { -SetPageDcacheDirty (page); +folio_set_dcache_dirty (folio);return ; }@@ -97,25 +99,21 @@ void __flush_dcache_page(struct page *page)* case is for exec env/arg pages and those are %99 certainly going to * get faulted into the tlb (and thus flushed) anyways. */ -if (PageHighMem (page)) - addr = (unsigned long )kmap_atomic (page); -else - addr = (unsigned long )page_address (page); - -flush_data_cache_page (addr); - -if (PageHighMem (page)) -kunmap_atomic ((void *)addr); +for (i =0 ; i < nr; i++) { + addr = (unsigned long )kmap_local_page (page + i); +flush_data_cache_page (addr); +kunmap_local ((void *)addr); + } } - -EXPORT_SYMBOL (__flush_dcache_page); +EXPORT_SYMBOL (__flush_dcache_pages);void __flush_anon_page (struct page *page,unsigned long vmaddr) {unsigned long addr = (unsigned long )page_address (page); +struct folio *folio =page_folio (page);if (pages_do_alias (addr, vmaddr)) { -if (page_mapcount (page) && !Page_dcache_dirty (page)) { +if (folio_mapped (folio) && !folio_test_dcache_dirty (folio)) {void *kaddr; kaddr =kmap_coherent (page, vmaddr);@@ -130,27 +128,29 @@ EXPORT_SYMBOL(__flush_anon_page);void __update_cache (unsigned long address,pte_t pte) { -struct page *page; +struct folio *folio;unsigned long pfn, addr;int exec = !pte_no_exec (pte) && !cpu_has_ic_fills_f_dc; +unsigned int i; pfn =pte_pfn (pte);if (unlikely (!pfn_valid (pfn)))return ; - page =pfn_to_page (pfn); -if (Page_dcache_dirty (page)) { -if (PageHighMem (page)) - addr = (unsigned long )kmap_atomic (page); -else - addr = (unsigned long )page_address (page); - -if (exec ||pages_do_alias (addr, address &PAGE_MASK )) -flush_data_cache_page (addr); -if (PageHighMem (page)) -kunmap_atomic ((void *)addr); + folio =page_folio (pfn_to_page (pfn)); + address &=PAGE_MASK ; + address -=offset_in_folio (folio, pfn <<PAGE_SHIFT ); + +if (folio_test_dcache_dirty (folio)) { +for (i =0 ; i <folio_nr_pages (folio); i++) { + addr = (unsigned long )kmap_local_folio (folio, i); -ClearPageDcacheDirty (page); +if (exec ||pages_do_alias (addr, address)) +flush_data_cache_page (addr); +kunmap_local ((void *)addr); + address +=PAGE_SIZE ; + } +folio_clear_dcache_dirty (folio); } }arch/mips/mm/init.c +11
-6@@ -88,7 +88,7 @@ static void *__kmap_pgprot(struct page *page, unsigned long addr, pgprot_t prot)pte_t pte;int tlbidx; -BUG_ON (Page_dcache_dirty (page)); +BUG_ON (folio_test_dcache_dirty (page_folio (page)));preempt_disable ();pagefault_disable ();@@ -169,11 +169,12 @@ void kunmap_coherent(void)void copy_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma) { +struct folio *src =page_folio (from);void *vfrom, *vto; vto =kmap_atomic (to);if (cpu_has_dc_aliases && -page_mapcount (from) && !Page_dcache_dirty (from)) { +folio_mapped (src) && !folio_test_dcache_dirty (src)) { vfrom =kmap_coherent (from, vaddr);copy_page (vto, vfrom);kunmap_coherent ();@@ -194,15 +195,17 @@ void copy_to_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); +if (cpu_has_dc_aliases && - page_mapcount(page) && !Page_dcache_dirty(page)) { +folio_mapped (folio) && !folio_test_dcache_dirty (folio)) {void *vto =kmap_coherent (page, vaddr) + (vaddr & ~PAGE_MASK );memcpy (vto, src, len);kunmap_coherent (); }else {memcpy (dst, src, len);if (cpu_has_dc_aliases) -SetPageDcacheDirty (page); +folio_set_dcache_dirty (folio); }if (vma->vm_flags &VM_EXEC )flush_cache_page (vma, vaddr,page_to_pfn (page));@@ -212,15 +215,17 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page, unsigned long vaddr, void *dst, const void *src, unsigned long len) { + struct folio *folio = page_folio(page); +if (cpu_has_dc_aliases && - page_mapcount(page) && !Page_dcache_dirty(page)) { +folio_mapped (folio) && !folio_test_dcache_dirty (folio)) {void *vfrom =kmap_coherent (page, vaddr) + (vaddr & ~PAGE_MASK );memcpy (dst, vfrom, len);kunmap_coherent (); }else {memcpy (dst, src, len);if (cpu_has_dc_aliases) -SetPageDcacheDirty (page); +folio_set_dcache_dirty (folio); } }EXPORT_SYMBOL_GPL (copy_from_user_page);Signature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox (Oracle)
maintainerPATCH v3 16/34 nios2: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
--- arch/nios2/include/asm/cacheflush.h | 6 ++- arch/nios2/include/asm/pgtable.h | 27 +++++++++---- arch/nios2/mm/cacheflush.c | 61 ++++++++++++++++------------- 3 files changed, 58 insertions(+), 36 deletions(-)
arch/nios2/include/asm/cacheflush.h +5 -1
@@ -29,9 +29,13 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1void flush_dcache_page (struct page *page); +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folioextern void flush_icache_range (unsigned long start,unsigned long end); -extern void flush_icache_page (struct vm_area_struct *vma,struct page *page); +void flush_icache_pages (struct vm_area_struct *vma,struct page *page, +unsigned int nr); +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1);#define flush_cache_vmap (start, end) flush_dcache_range(start, end)#define flush_cache_vunmap (start, end) flush_dcache_range(start, end)
arch/nios2/include/asm/pgtable.h +19 -8
@@ -178,15 +178,23 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { -unsigned long paddr = (unsigned long )page_to_virt (pte_page (pteval)); - -flush_dcache_range (paddr, paddr +PAGE_SIZE ); -set_pte (ptep, pteval); +unsigned long paddr = (unsigned long )page_to_virt (pte_page (pte)); + +flush_dcache_range (paddr, paddr + nr *PAGE_SIZE ); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +static inline int pmd_none (pmd_t pmd) { return (pmd_val(pmd) ==
@@ -273,7 +281,10 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)extern void __init paging_init (void );extern void __init mmu_init (void ); -extern void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *pte); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,unsigned int nr); + +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#endif /* _ASM_NIOS2_PGTABLE_H */
arch/nios2/mm/cacheflush.c +34 -27
114 lines not on this page · raw message
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 16/34] nios2: Implement the new page table range API
Quoted 3 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range(),flush_icache_pages()andflush_dcache_folio(). Change thePG_arch_1(akaPG_dcache_dirty) flag from being per-page to per-folio.
This failed for me with
CC arch/nios2/mm/cacheflush.oarch/nios2/mm/cacheflush.c: In function 'flush_dcache_folio':arch/nios2/mm/cacheflush.c:195:48: error: passing argument 2 of 'flush_aliases' from incompatible pointer type [-Werror=incompatible-pointer-types]
195 | flush_aliases(mapping, folio);
| ^~~~~
| |
| struct folio *arch/nios2/mm/cacheflush.c:74:71: note: expected 'struct page *' but argument is of type 'struct folio *'
74 | static void flush_aliases(struct address_space *mapping, struct page *page)
| ~~~~~~~~~~~~~^~~~
In file included from arch/nios2/mm/cacheflush.c:10:arch/nios2/mm/cacheflush.c: At top level:include/linux/export.h:57:43: error: redefinition of '__ksymtab_flush_dcache_folio'
57 | static const struct kernel_symbol __ksymtab_##sym \
| ^~~~~~~~~~include/linux/export.h:96:9: note: in expansion of macro '__KSYMTAB_ENTRY'
96 | __KSYMTAB_ENTRY(sym, sec)
| ^~~~~~~~~~~~~~~
include/linux/export.h:140:41: note: in expansion of macro '___EXPORT_SYMBOL'
140 | #define __EXPORT_SYMBOL(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
| ^~~~~~~~~~~~~~~~
include/linux/export.h:147:41: note: in expansion of macro '__EXPORT_SYMBOL'
147 | #define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
| ^~~~~~~~~~~~~~~
include/linux/export.h:150:41: note: in expansion of macro '_EXPORT_SYMBOL'
150 | #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
| ^~~~~~~~~~~~~~
arch/nios2/mm/cacheflush.c:207:1: note: in expansion of macro 'EXPORT_SYMBOL'
207 | EXPORT_SYMBOL(flush_dcache_folio);
| ^~~~~~~~~~~~~include/linux/export.h:57:43: note: previous definition of '__ksymtab_flush_dcache_folio' with type 'const struct kernel_symbol'
57 | static const struct kernel_symbol __ksymtab_##sym \
| ^~~~~~~~~~include/linux/export.h:96:9: note: in expansion of macro '__KSYMTAB_ENTRY'
96 | __KSYMTAB_ENTRY(sym, sec)
| ^~~~~~~~~~~~~~~
include/linux/export.h:140:41: note: in expansion of macro '___EXPORT_SYMBOL'
140 | #define __EXPORT_SYMBOL(sym, sec, ns) ___EXPORT_SYMBOL(sym, sec, ns)
| ^~~~~~~~~~~~~~~~
include/linux/export.h:147:41: note: in expansion of macro '__EXPORT_SYMBOL'
147 | #define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
| ^~~~~~~~~~~~~~~
include/linux/export.h:150:41: note: in expansion of macro '_EXPORT_SYMBOL'
150 | #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
| ^~~~~~~~~~~~~~
arch/nios2/mm/cacheflush.c:201:1: note: in expansion of macro 'EXPORT_SYMBOL'
201 | EXPORT_SYMBOL(flush_dcache_folio);
| ^~~~~~~~~~~~~
arch/nios2/mm/cacheflush.c: In function 'update_mmu_cache_range':
arch/nios2/mm/cacheflush.c:235:40: error: passing argument 2 of 'flush_aliases' from incompatible pointer type [-Werror=incompatible-pointer-types]
235 | flush_aliases(mapping, folio);
| ^~~~~
| |
| struct folio *arch/nios2/mm/cacheflush.c:74:71: note: expected 'struct page *' but argument is of type 'struct folio *'
74 | static void flush_aliases(struct address_space *mapping, struct page *page)
| ~~~~~~~~~~~~~^~~~
cc1: some warnings being treated as errors
make[4]: *** [scripts/Makefile.build:252: arch/nios2/mm/cacheflush.o] Error 1
make[3]: *** [scripts/Makefile.build:494: arch/nios2/mm] Error 2
make[2]: *** [scripts/Makefile.build:494: arch/nios2] Error 2
make[1]: *** [Makefile:2028: .] Error 2
make[1]: Leaving directory '/home/mike/build/cross/nios2/defconfig'
make: *** [Makefile:226: __sub-make] Error 2
Quoted 200 lines
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Cc Dinh Nguyen <[email protected]>--- arch/nios2/include/asm/cacheflush.h | 6 ++- arch/nios2/include/asm/pgtable.h | 27 +++++++++---- arch/nios2/mm/cacheflush.c | 61 ++++++++++++++++------------- 3 files changed, 58 insertions(+), 36 deletions(-)arch/nios2/include/asm/cacheflush.h +5
-1@@ -29,9 +29,13 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1void flush_dcache_page (struct page *page); +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folioextern void flush_icache_range (unsigned long start,unsigned long end); -extern void flush_icache_page (struct vm_area_struct *vma,struct page *page); +void flush_icache_pages (struct vm_area_struct *vma,struct page *page, +unsigned int nr); +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1);#define flush_cache_vmap (start, end) flush_dcache_range(start, end)#define flush_cache_vunmap (start, end) flush_dcache_range(start, end)arch/nios2/include/asm/pgtable.h +19
-8@@ -178,15 +178,23 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { -unsigned long paddr = (unsigned long )page_to_virt (pte_page (pteval)); - -flush_dcache_range (paddr, paddr +PAGE_SIZE ); -set_pte (ptep, pteval); +unsigned long paddr = (unsigned long )page_to_virt (pte_page (pte)); + +flush_dcache_range (paddr, paddr + nr *PAGE_SIZE ); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +static inline int pmd_none (pmd_t pmd) { return (pmd_val(pmd) ==@@ -273,7 +281,10 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)extern void __init paging_init (void );extern void __init mmu_init (void ); -extern void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *pte); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,unsigned int nr); + +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#endif /* _ASM_NIOS2_PGTABLE_H */ arch/nios2/mm/cacheflush.c +34
-27@@ -138,10 +138,11 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start,__flush_icache (start, end); } -void flush_icache_page (struct vm_area_struct *vma,struct page *page) +void flush_icache_pages (struct vm_area_struct *vma,struct page *page, +unsigned int nr) {unsigned long start = (unsigned long )page_address (page); -unsigned long end = start +PAGE_SIZE ; +unsigned long end = start + nr *PAGE_SIZE ;__flush_dcache (start, end);__flush_icache (start, end);@@ -158,19 +159,19 @@ void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,__flush_icache (start, end); } -void __flush_dcache_page (struct address_space *mapping,struct page *page) +void __flush_dcache_folio (struct address_space *mapping,struct folio *folio) {/* * Writeback any data associated with the kernel mapping of this * page. This ensures that data in the physical page is mutually * coherent with the kernels mapping. */ -unsigned long start = (unsigned long )page_address (page); +unsigned long start = (unsigned long )folio_address (folio); -__flush_dcache (start, start +PAGE_SIZE ); +__flush_dcache (start, start +folio_size (folio)); } -void flush_dcache_page (struct page *page) +void flush_dcache_folio (struct folio *folio) {struct address_space *mapping;@@ -178,32 +179,38 @@ void flush_dcache_page(struct page *page)* The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (folio_pfn (folio)))return ; - mapping =page_mapping_file (page); + mapping =folio_flush_mapping (folio);/* Flush this page if there are aliases. */ if (mapping && !mapping_mapped (mapping)) { -clear_bit (PG_dcache_clean, &page->flags); +clear_bit (PG_dcache_clean, &folio->flags); }else { -__flush_dcache_page (mapping, page); +__flush_dcache_folio (mapping, folio);if (mapping) { -unsigned long start = (unsigned long )page_address (page); -flush_aliases (mapping, page); -flush_icache_range (start, start +PAGE_SIZE ); +unsigned long start = (unsigned long )folio_address (folio); +flush_aliases (mapping, folio); +flush_icache_range (start, start +folio_size (folio)); } -set_bit (PG_dcache_clean, &page->flags); +set_bit (PG_dcache_clean, &folio->flags); } } -EXPORT_SYMBOL (flush_dcache_page); +EXPORT_SYMBOL (flush_dcache_folio); + +void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +} +EXPORT_SYMBOL (flush_dcache_folio); -void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *ptep) +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,unsigned int nr) {pte_t pte = *ptep;unsigned long pfn =pte_pfn (pte); -struct page *page; +struct folio *folio;struct address_space *mapping;reload_tlb_page (vma, address, pte);@@ -215,19 +222,19 @@ void update_mmu_cache(struct vm_area_struct *vma,* The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - page =pfn_to_page (pfn); -if (page ==ZERO_PAGE (0 )) +if (is_zero_pfn (pfn))return ; - mapping =page_mapping_file (page); -if (!test_and_set_bit (PG_dcache_clean, &page->flags)) -__flush_dcache_page (mapping, page); + folio =page_folio (pfn_to_page (pfn)); + mapping =folio_flush_mapping (folio); +if (!test_and_set_bit (PG_dcache_clean, &folio->flags)) +__flush_dcache_folio (mapping, folio); -if (mapping) - { -flush_aliases (mapping, page); +if (mapping) { +flush_aliases (mapping, folio);if (vma->vm_flags &VM_EXEC ) -flush_icache_page (vma, page); +flush_icache_pages (vma, &folio->page, +folio_nr_pages (folio)); } }Signature · 1 line
2.39.1
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox (Oracle)
maintainerPATCH v3 17/34 openrisc: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
--- arch/openrisc/include/asm/cacheflush.h | 8 +++++++- arch/openrisc/include/asm/pgtable.h | 27 +++++++++++++++++++++----- arch/openrisc/mm/cache.c | 12 ++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-)
arch/openrisc/include/asm/cacheflush.h +7 -1
@@ -56,10 +56,16 @@ static inline void sync_icache_dcache(struct page *page)*/ #define PG_dc_clean PG_arch_1 +static inline void flush_dcache_folio (struct folio *folio) +{ +clear_bit (PG_dc_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1static inline void flush_dcache_page (struct page *page) { -clear_bit (PG_dc_clean, &page->flags); +flush_dcache_folio (page_folio (page)); }#define flush_icache_user_page (vma, page, addr, len) \
arch/openrisc/include/asm/pgtable.h +22 -5
@@ -46,7 +46,21 @@ extern void paging_init(void);* hook is made available. */ #define set_pte (pteptr, pteval) ((*(pteptr)) = (pteval)) -#define set_pte_at (mm, addr, ptep, pteval) set_pte(ptep, pteval) + +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +/* * (pmds are folded into pgds so this doesn't get actually called, * but the define is needed for a generic inline function.)
@@ -379,13 +393,16 @@ static inline void update_tlb(struct vm_area_struct *vma,extern void update_cache (struct vm_area_struct *vma,unsigned long address,pte_t *pte); -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *pte) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) { -update_tlb (vma, address, pte); -update_cache (vma, address, pte); +update_tlb (vma, address, ptep); +update_cache (vma, address, ptep); } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1) +/* __PHX__ FIXME, SWAP, this probably doesn't work */ /*
arch/openrisc/mm/cache.c +8 -4
@@ -43,15 +43,19 @@ void update_cache(struct vm_area_struct *vma, unsigned long address, pte_t *pte) {unsigned long pfn =pte_val (*pte) >>PAGE_SHIFT ; -struct page *page =pfn_to_page (pfn); -int dirty = !test_and_set_bit (PG_dc_clean, &page->flags); +struct folio *folio =page_folio (pfn_to_page (pfn)); +int dirty = !test_and_set_bit (PG_dc_clean, &folio->flags);/* * Since icaches do not snoop for updated data on OpenRISC, we * must write back and invalidate any dirty pages manually. We * can skip data pages, since they will not end up in icaches. */ -if ((vma->vm_flags &VM_EXEC ) && dirty) -sync_icache_dcache (page); +if ((vma->vm_flags &VM_EXEC ) && dirty) { +unsigned int nr =folio_nr_pages (folio); + +while (nr--) +sync_icache_dcache (folio_page (folio, nr)); + } }
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 18/34 parisc: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
--- arch/parisc/include/asm/cacheflush.h | 14 ++-- arch/parisc/include/asm/pgtable.h | 28 +++++--- arch/parisc/kernel/cache.c | 101 +++++++++++++++++++-------- 3 files changed, 99 insertions(+), 44 deletions(-)
arch/parisc/include/asm/cacheflush.h +9 -5
@@ -46,16 +46,20 @@ void invalidate_kernel_vmap_range(void *vaddr, int size);#define flush_cache_vmap (start, end) flush_cache_all()#define flush_cache_vunmap (start, end) flush_cache_all() +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folio#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page (struct page *page); +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}#define flush_dcache_mmap_lock (mapping) xa_lock_irq(&mapping->i_pages)#define flush_dcache_mmap_unlock (mapping) xa_unlock_irq(&mapping->i_pages) -#define flush_icache_page (vma,page) do { \ - flush_kernel_dcache_page_addr(page_address(page)); \ - flush_kernel_icache_page(page_address(page)); \ -} while (0) +void flush_icache_pages (struct vm_area_struct *vma,struct page *page, +unsigned int nr); +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1)#define flush_icache_range (s,e) do { \ flush_kernel_dcache_range_asm(s,e); \
arch/parisc/include/asm/pgtable.h +19 -9
@@ -73,14 +73,7 @@ extern void __update_cache(pte_t pte);mb (); \ } while(0) -#define set_pte_at (mm, addr, pteptr, pteval) \ - do { \ - if (pte_present(pteval) && \ - pte_user(pteval)) \ - __update_cache(pteval); \ - *(pteptr) = (pteval); \ - purge_tlb_entries(mm, addr); \ - } while (0) +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#endif /* !__ASSEMBLY__ */
@@ -391,11 +384,28 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)extern void paging_init (void ); +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +if (pte_present (pte) &&pte_user (pte)) +__update_cache (pte); +for (;;) { + *ptep = pte; +purge_tlb_entries (mm, addr); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=1 <<PFN_PTE_SHIFT ; + addr +=PAGE_SIZE ; + } +} +/* Used for deferring calls to flush_dcache_page() */ #define PG_dcache_dirty PG_arch_1 -#define update_mmu_cache (vms,addr,ptep) __update_cache(*ptep) +#define update_mmu_cache_range (vma, addr, ptep, nr) __update_cache(*ptep) +#define update_mmu_cache (vma, addr, ptep) __update_cache(*ptep)/* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
arch/parisc/kernel/cache.c +71 -30
169 lines not on this page · raw message
Signature · 1 line
2.39.1
Re: [PATCH v3 18/34] parisc: Implement the new page table range API
Quoted 3 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range(),flush_dcache_folio()andflush_icache_pages(). Change thePG_arch_1(akaPG_dcache_dirty) flag from being per-page to per-folio.
I have tested this change on rp3440 at mainline commit e492250d5252635b6c97d52eddf2792ec26f1ec1 and c8000 at mainline commit ee3f96b164688dae21e2466a57f2e806b64e8a37.
So far, I haven't seen an issues on c8000. On rp3440, I saw the following:
_swap_info_get: Unused swap offset entry 00000320
BUG: Bad page map in process buildd pte:00032100 pmd:003606c3 addr:0000000000482000 vm_flags:00100077 anon_vma:0000000066f61340 mapping:0000000000000000 index:482 file:(null) fault:0x0 mmap:0x0 read_folio:0x0 CPU: 0 PID: 6813 Comm: buildd Not tainted 6.2.0+ #1 Hardware name: 9000/800/rp3440 Backtrace: [<000000004020af50>] show_stack+0x70/0x90 [<0000000040b7d408>] dump_stack_lvl+0xd8/0x128 [<0000000040b7d48c>] dump_stack+0x34/0x48 [<00000000404513a4>] print_bad_pte+0x24c/0x318 [<00000000404560dc>] zap_pte_range+0x8d4/0x958 [<0000000040456398>] unmap_page_range+0x1d8/0x490 [<000000004045681c>] unmap_vmas+0x10c/0x1a8 [<0000000040466330>] exit_mmap+0x198/0x4a0 [<0000000040235cbc>] mmput+0x114/0x2a8 [<0000000040244e90>] do_exit+0x4e0/0xc68 [<0000000040245938>] do_group_exit+0x68/0x128 [<000000004025967c>] get_signal+0xae4/0xb60 [<000000004021a570>] do_signal+0x50/0x228 [<000000004021ab38>] do_notify_resume+0x68/0x150 [<00000000402030b4>] intr_check_sig+0x38/0x3c
Disabling lock debugging due to kernel taint_swap_info_get: Unused swap offset entry 000003a9
BUG: Bad page map in process buildd pte:0003a940 pmd:003606c3 addr:0000000000523000 vm_flags:00100077 anon_vma:0000000066f61340 mapping:0000000000000000 index:523 file:(null) fault:0x0 mmap:0x0 read_folio:0x0 CPU: 2 PID: 6813 Comm: buildd Tainted: G B 6.2.0+ #1 Hardware name: 9000/800/rp3440 Backtrace: [<000000004020af50>] show_stack+0x70/0x90 [<0000000040b7d408>] dump_stack_lvl+0xd8/0x128 [<0000000040b7d48c>] dump_stack+0x34/0x48 [<00000000404513a4>] print_bad_pte+0x24c/0x318 [<00000000404560dc>] zap_pte_range+0x8d4/0x958 [<0000000040456398>] unmap_page_range+0x1d8/0x490 [<000000004045681c>] unmap_vmas+0x10c/0x1a8 [<0000000040466330>] exit_mmap+0x198/0x4a0 [<0000000040235cbc>] mmput+0x114/0x2a8 [<0000000040244e90>] do_exit+0x4e0/0xc68 [<0000000040245938>] do_group_exit+0x68/0x128 [<000000004025967c>] get_signal+0xae4/0xb60 [<000000004021a570>] do_signal+0x50/0x228 [<000000004021ab38>] do_notify_resume+0x68/0x150 [<00000000402030b4>] intr_check_sig+0x38/0x3c
[...]pagefault_out_of_memory: 1158973 callbacks suppressed Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF
Rebooted rp3440. Since then, I haven't seen any more problems.
Dave
Signature · 1 line
John David Anglin [email protected]
Re: [PATCH v3 18/34] parisc: Implement the new page table range API
Quoted 6 lines · John David Anglin
Quoted 3 lines · Matthew Wilcox (Oracle)
Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
I have tested this change on rp3440 at mainline commit e492250d5252635b6c97d52eddf2792ec26f1ec1 and c8000 at mainline commit ee3f96b164688dae21e2466a57f2e806b64e8a37.
Here's another one:
------------[ cut here ]------------ kernel BUG at mm/memory.c:3865! CPU: 1 PID: 6972 Comm: sbuild Not tainted 6.2.0+ #1 Hardware name: 9000/800/rp3440
YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI
PSW: 00001000000001101111111100001111 Not tainted
r00-03 000000000806ff0f 000000004fab8d40 00000000404584b0 000000004fab8d40 r04-07 0000000040c2f4c0 0000000047fe60c0 000000004fab8b98 0000000000000953 r08-11 000000004de3de00 0000000000000000 0000000047fe60c0 0000004093ff4660 r12-15 0000000000000001 0000000047fe60c0 0000000040000540 000000022f8e9540 r16-19 0000000000000000 000000004c694c40 000000004fab8860 00000000000003d0 r20-23 0000000007be3a40 0000000000000fff 0000000000000000 000000004109f1a0 r24-27 0000000000000000 0000000000000cc0 0000000046de3a68 0000000040c2f4c0 r28-31 80e00000000a0435 000000004fab8df0 000000004fab8e20 0000000000000001 sr00-03 0000000000207c00 0000000000000000 0000000000000000 0000000002f11c00 sr04-07 0000000000000000 0000000000000000 0000000000000000 0000000000000000
IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004045908c 0000000040459090
IIR: 03ffe01f ISR: 0000000000000000 IOR: 0000000000000000 CPU: 1 CR30: 0000004095d64c20 CR31: ffffffffffffffff
ORIG_R28: 000000001c569ad0
IAOQ[0]: do_swap_page+0x108c/0x1168
IAOQ[1]: do_swap_page+0x1090/0x1168
RP(r2): do_swap_page+0x4b0/0x1168
Backtrace: [<000000004045a554>] handle_pte_fault+0x244/0x358 [<000000004045c58c>] __handle_mm_fault+0x104/0x1b8 [<000000004045c81c>] handle_mm_fault+0x1dc/0x318 [<000000004044cb38>] faultin_page+0xa8/0x178 [<000000004044e848>] __get_user_pages+0x328/0x560 [<0000000040450ac4>] get_dump_page+0x9c/0x128 [<0000000040596cb8>] dump_user_range+0xc0/0x2d8 [<000000004058e790>] elf_core_dump+0x5f8/0x708 [<0000000040596384>] do_coredump+0xc2c/0x14a0 [<0000000040259040>] get_signal+0x4a8/0xb60 [<000000004021a570>] do_signal+0x50/0x228 [<000000004021ab38>] do_notify_resume+0x68/0x150 [<0000000040203ee0>] syscall_do_signal+0x54/0xa0 CPU: 1 PID: 6972 Comm: sbuild Not tainted 6.2.0+ #1 Hardware name: 9000/800/rp3440 Backtrace: [<000000004020af50>] show_stack+0x70/0x90 [<0000000040b7d408>] dump_stack_lvl+0xd8/0x128 [<0000000040b7d48c>] dump_stack+0x34/0x48 [<000000004020b160>] die_if_kernel+0x1d0/0x388 [<000000004020c1c4>] handle_interruption+0xc34/0xc88 [<000000004020307c>] intr_check_sig+0x0/0x3c ---[ end trace 0000000000000000 ]---
note: sbuild[6972] exited with preempt_count 1
Dave
Signature · 1 line
John David Anglin [email protected]
Re: [PATCH v3 18/34] parisc: Implement the new page table range API
Quoted 34 lines · John David Anglin
Quoted 6 lines · John David Anglin
Quoted 3 lines · Matthew Wilcox (Oracle)
Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
I have tested this change on rp3440 at mainline commit e492250d5252635b6c97d52eddf2792ec26f1ec1 and c8000 at mainline commit ee3f96b164688dae21e2466a57f2e806b64e8a37.
Here's another one:
------------[ cut here ]------------
kernel BUG at mm/memory.c:3865!
CPU: 1 PID: 6972 Comm: sbuild Not tainted 6.2.0+ #1 Hardware name: 9000/800/rp3440YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI
PSW: 00001000000001101111111100001111 Not tainted
r00-03 000000000806ff0f 000000004fab8d40 00000000404584b0 000000004fab8d40 r04-07 0000000040c2f4c0 0000000047fe60c0 000000004fab8b98 0000000000000953 r08-11 000000004de3de00 0000000000000000 0000000047fe60c0 0000004093ff4660 r12-15 0000000000000001 0000000047fe60c0 0000000040000540 000000022f8e9540 r16-19 0000000000000000 000000004c694c40 000000004fab8860 00000000000003d0 r20-23 0000000007be3a40 0000000000000fff 0000000000000000 000000004109f1a0 r24-27 0000000000000000 0000000000000cc0 0000000046de3a68 0000000040c2f4c0 r28-31 80e00000000a0435 000000004fab8df0 000000004fab8e20 0000000000000001 sr00-03 0000000000207c00 0000000000000000 0000000000000000 0000000002f11c00 sr04-07 0000000000000000 0000000000000000 0000000000000000 0000000000000000IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004045908c 0000000040459090 IIR: 03ffe01f ISR: 0000000000000000 IOR: 0000000000000000 CPU: 1 CR30: 0000004095d64c20 CR31: ffffffffffffffff ORIG_R28: 000000001c569ad0
IAOQ[0]: do_swap_page+0x108c/0x1168
IAOQ[1]: do_swap_page+0x1090/0x1168
RP(r2): do_swap_page+0x4b0/0x1168
Quoted 14 lines
Backtrace: [<000000004045a554>] handle_pte_fault+0x244/0x358 [<000000004045c58c>] __handle_mm_fault+0x104/0x1b8 [<000000004045c81c>] handle_mm_fault+0x1dc/0x318 [<000000004044cb38>] faultin_page+0xa8/0x178 [<000000004044e848>] __get_user_pages+0x328/0x560 [<0000000040450ac4>] get_dump_page+0x9c/0x128 [<0000000040596cb8>] dump_user_range+0xc0/0x2d8 [<000000004058e790>] elf_core_dump+0x5f8/0x708 [<0000000040596384>] do_coredump+0xc2c/0x14a0 [<0000000040259040>] get_signal+0x4a8/0xb60 [<000000004021a570>] do_signal+0x50/0x228 [<000000004021ab38>] do_notify_resume+0x68/0x150 [<0000000040203ee0>] syscall_do_signal+0x54/0xa0
Removed new page table API change and still see a swap issue on rp3440. So, these bugs are probably unrelated to the API change.
get_swap_device: Bad swap file entry 600000000014ee20get_swap_device: Bad swap file entry 600000000014ee20 [...]get_swap_device: Bad swap file entry 600000000014ee20 _swap_info_get: Bad swap file entry 600000000014ee20
BUG: Bad page map in process sh pte:14ee2418 pmd:01372913 addr:00000000f8406000 vm_flags:00000075 anon_vma:0000000000000000 mapping:000000007f67e1a8 index:25 file:libc.so.6 fault:xfs_filemap_fault [xfs] mmap:xfs_file_mmap [xfs] read_folio:xfs_vm_read_folio [xfs] CPU: 3 PID: 12702 Comm: sh Not tainted 6.2.0+ #1 Hardware name: 9000/800/rp3440 Backtrace: [<000000004020ac50>] show_stack+0x70/0x90 [<0000000040b7c148>] dump_stack_lvl+0xd8/0x128 [<0000000040b7c1cc>] dump_stack+0x34/0x48 [<000000004045020c>] print_bad_pte+0x24c/0x318 [<0000000040454f78>] zap_pte_range+0x908/0x990 [<0000000040455238>] unmap_page_range+0x1d8/0x490 [<00000000404556bc>] unmap_vmas+0x10c/0x1a8 [<0000000040465278>] exit_mmap+0x198/0x4a0 [<0000000040234a3c>] mmput+0x114/0x2a8 [<0000000040243c10>] do_exit+0x4e0/0xc68 [<00000000402446b8>] do_group_exit+0x68/0x128 [<00000000402583fc>] get_signal+0xae4/0xb60 [<0000000040219310>] do_signal+0x50/0x228 [<00000000402198d8>] do_notify_resume+0x68/0x150 [<00000000402030b4>] intr_check_sig+0x38/0x3c
Dave
Signature · 1 line
John David Anglin [email protected]
Matthew Wilcox (Oracle)
maintainerPATCH v3 19/34 powerpc: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio.
--- arch/powerpc/include/asm/book3s/pgtable.h | 10 +---- arch/powerpc/include/asm/cacheflush.h | 14 +++++-- arch/powerpc/include/asm/kvm_ppc.h | 10 ++--- arch/powerpc/include/asm/nohash/pgtable.h | 13 ++---- arch/powerpc/include/asm/pgtable.h | 6 +++ arch/powerpc/mm/book3s64/hash_utils.c | 11 ++--- arch/powerpc/mm/cacheflush.c | 40 ++++++------------ arch/powerpc/mm/nohash/e500_hugetlbpage.c | 3 +- arch/powerpc/mm/pgtable.c | 51 +++++++++++++---------- 9 files changed, 77 insertions(+), 81 deletions(-)
arch/powerpc/include/asm/book3s/pgtable.h +2 -8
@@ -9,13 +9,6 @@#endif #ifndef __ASSEMBLY__ -/* Insert a PTE, top-level function is out of line. It uses an inline -* low level function in the respective pgtable-* files -*/ -extern void set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep, -pte_t pte); - -#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGSextern int ptep_set_access_flags (struct vm_area_struct *vma,unsigned long address,pte_t *ptep,pte_t entry,int dirty);
@@ -36,7 +29,8 @@ void __update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t* corresponding HPTE into the hash table ahead of time, instead of * waiting for the inevitable extra hash-table miss exception. */ -static inline void update_mmu_cache (struct vm_area_struct *vma,unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) {if (IS_ENABLED (CONFIG_PPC32 ) && !mmu_has_feature (MMU_FTR_HPTE_TABLE ))return ;
arch/powerpc/include/asm/cacheflush.h +10 -4
@@ -35,13 +35,19 @@ static inline void flush_cache_vmap(unsigned long start, unsigned long end)* It just marks the page as not i-cache clean. We do the i-cache * flush later when the page is given to a user process, if necessary. */ -static inline void flush_dcache_page (struct page *page) +static inline void flush_dcache_folio (struct folio *folio) {if (cpu_has_feature (CPU_FTR_COHERENT_ICACHE ))return ;/* avoid an atomic op if possible */ -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); }void flush_icache_range (unsigned long start,unsigned long stop);
@@ -51,7 +57,7 @@ void flush_icache_user_page(struct vm_area_struct *vma, struct page *page, unsigned long addr, int len);#define flush_icache_user_page flush_icache_user_page -void flush_dcache_icache_page (struct page *page); +void flush_dcache_icache_folio (struct folio *folio);/** * flush_dcache_range(): Write any modified data cache blocks out to memory and
arch/powerpc/include/asm/kvm_ppc.h +5 -5
@@ -868,7 +868,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids);static inline void kvmppc_mmu_flush_icache (kvm_pfn_t pfn) { -struct page *page; +struct folio *folio;/* * We can only access pages that the kernel maps * as memory. Bail out for unmapped ones.
@@ -877,10 +877,10 @@ static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn)return ;/* Clear i-cache for new pages */ - page =pfn_to_page (pfn); -if (!test_bit (PG_dcache_clean, &page->flags)) { -flush_dcache_icache_page (page); -set_bit (PG_dcache_clean, &page->flags); + folio =page_folio (pfn_to_page (pfn)); +if (!test_bit (PG_dcache_clean, &folio->flags)) { +flush_dcache_icache_folio (folio); +set_bit (PG_dcache_clean, &folio->flags); } }
arch/powerpc/include/asm/nohash/pgtable.h +4 -9
@@ -166,12 +166,6 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)return __pte (pte_val (pte) & ~_PAGE_SWP_EXCLUSIVE); } -/* Insert a PTE, top-level function is out of line. It uses an inline -* low level function in the respective pgtable-* files -*/ -extern void set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep, -pte_t pte); -/* This low level function performs the actual PTE insertion * Setting the PTE depends on the MMU type and other factors. It's * an horrible mess that I'm not going to try to clean up now but
@@ -282,10 +276,11 @@ static inline int pud_huge(pud_t pud)* for the page which has just been mapped in. */ #if defined(CONFIG_PPC_E500 ) && defined(CONFIG_HUGETLB_PAGE ) -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address,pte_t *ptep); +void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,unsigned int nr);#else -static inline -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address,pte_t *ptep) {} +static inline void update_mmu_cache (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) {}#endif #endif /* __ASSEMBLY__ */
arch/powerpc/include/asm/pgtable.h +6 -0
@@ -41,6 +41,12 @@ struct mm_struct;#ifndef __ASSEMBLY__ +void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep, +pte_t pte,unsigned int nr); +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1); +#ifndef MAX_PTRS_PER_PGD #define MAX_PTRS_PER_PGD PTRS_PER_PGD#endif
arch/powerpc/mm/book3s64/hash_utils.c +6 -5
@@ -1307,18 +1307,19 @@ void hash__early_init_mmu_secondary(void)*/ unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap) { -struct page *page; +struct folio *folio;if (!pfn_valid (pte_pfn (pte)))return pp; - page =pte_page (pte); + folio =page_folio (pte_page (pte));/* page is dirty */ -if (!test_bit (PG_dcache_clean, &page->flags) && !PageReserved (page)) { +if (!test_bit (PG_dcache_clean, &folio->flags) && + !folio_test_reserved (folio)) {if (trap ==INTERRUPT_INST_STORAGE ) { -flush_dcache_icache_page (page); -set_bit (PG_dcache_clean, &page->flags); +flush_dcache_icache_folio (folio); +set_bit (PG_dcache_clean, &folio->flags); }else pp |=HPTE_R_N ; }
arch/powerpc/mm/cacheflush.c +13 -27
@@ -148,44 +148,30 @@ static void __flush_dcache_icache(void *p)invalidate_icache_range (addr, addr +PAGE_SIZE ); } -static void flush_dcache_icache_hugepage (struct page *page) +void flush_dcache_icache_folio (struct folio *folio) { -int i; -int nr =compound_nr (page); +unsigned int i, nr =folio_nr_pages (folio); -if (!PageHighMem (page)) { +if (flush_coherent_icache ()) +return ; + +if (!folio_test_highmem (folio)) { +void *addr =folio_address (folio);for (i =0 ; i < nr; i++) -__flush_dcache_icache (lowmem_page_address (page + i)); - }else { +__flush_dcache_icache (addr + i *PAGE_SIZE ); + }else if (IS_ENABLED (CONFIG_BOOKE ) ||sizeof (phys_addr_t) >sizeof (void *)) {for (i =0 ; i < nr; i++) { -void *start =kmap_local_page (page + i); +void *start =kmap_local_folio (folio, i *PAGE_SIZE );__flush_dcache_icache (start);kunmap_local (start); } - } -} - -void flush_dcache_icache_page (struct page *page) -{ -if (flush_coherent_icache ()) -return ; - -if (PageCompound (page)) -return flush_dcache_icache_hugepage (page); - -if (!PageHighMem (page)) { -__flush_dcache_icache (lowmem_page_address (page)); - }else if (IS_ENABLED (CONFIG_BOOKE ) ||sizeof (phys_addr_t) >sizeof (void *)) { -void *start =kmap_local_page (page); - -__flush_dcache_icache (start); -kunmap_local (start); }else { -flush_dcache_icache_phys (page_to_phys (page)); +unsigned long pfn =folio_pfn (folio); +for (i =0 ; i < nr; i++) +flush_dcache_icache_phys ((pfn + i) *PAGE_SIZE ); } } -EXPORT_SYMBOL (flush_dcache_icache_page);void clear_user_page (void *page,unsigned long vaddr,struct page *pg) {
arch/powerpc/mm/nohash/e500_hugetlbpage.c +2 -1
@@ -178,7 +178,8 @@ book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea, pte_t pte)* * This must always be called with the pte lock held. */ -void update_mmu_cache (struct vm_area_struct *vma,unsigned long address,pte_t *ptep) +void update_mmu_cache (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,unsigned int nr) {if (is_vm_hugetlb_page (vma))book3e_hugetlb_preload (vma, address, *ptep);
arch/powerpc/mm/pgtable.c +29 -22
119 lines not on this page · raw message
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 20/34 riscv: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio.
--- arch/riscv/include/asm/cacheflush.h | 19 +++++++++---------- arch/riscv/include/asm/pgtable.h | 26 +++++++++++++++++++------- arch/riscv/mm/cacheflush.c | 11 ++--------- 3 files changed, 30 insertions(+), 26 deletions(-)
arch/riscv/include/asm/cacheflush.h +9 -10
@@ -15,20 +15,19 @@ static inline void local_flush_icache_all(void)#define PG_dcache_clean PG_arch_1 -static inline void flush_dcache_page (struct page *page) +static inline void flush_dcache_folio (struct folio *folio) { -/* -* HugeTLB pages are always fully mapped and only head page will be -* set PG_dcache_clean (see comments in flush_icache_pte()). -*/ -if (PageHuge (page)) - page =compound_head (page); - -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); } +#define flush_dcache_folio flush_dcache_folio#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +} +/* * RISC-V doesn't have an instruction to flush parts of the instruction cache, * so instead we just flush the whole thing.
arch/riscv/include/asm/pgtable.h +19 -7
@@ -405,8 +405,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)/* Commit new configuration to MMU hardware */ -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) {/* * The kernel assumes that TLBs don't cache invalid entries, but
@@ -415,8 +415,11 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,* Relying on flush_tlb_fix_spurious_fault would suffice, but * the extra traps reduce performance. So, eagerly SFENCE.VMA. */ -local_flush_tlb_page (address); +while (nr--) +local_flush_tlb_page (address + nr *PAGE_SIZE ); } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define __HAVE_ARCH_UPDATE_MMU_TLB#define update_mmu_tlb update_mmu_cache
@@ -456,12 +459,21 @@ static inline void __set_pte_at(struct mm_struct *mm,set_pte (ptep, pteval); } -static inline void set_pte_at (struct mm_struct *mm, -unsigned long addr,pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval,unsigned int nr) { -page_table_check_ptes_set (mm, addr, ptep, pteval,1 ); -__set_pte_at (mm, addr, ptep, pteval); +page_table_check_ptes_set (mm, addr, ptep, pteval, nr); + +for (;;) { +__set_pte_at (mm, addr, ptep, pteval); +if (--nr ==0 ) +break ; + ptep++; + addr +=PAGE_SIZE ; +pte_val (pteval) +=1 << _PAGE_PFN_SHIFT; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline void pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep)
arch/riscv/mm/cacheflush.c +2 -9
@@ -81,16 +81,9 @@ void flush_icache_mm(struct mm_struct *mm, bool local)#ifdef CONFIG_MMU void flush_icache_pte (pte_t pte) { -struct page *page =pte_page (pte); +struct folio *folio =page_folio (pte_page (pte)); -/* -* HugeTLB pages are always fully mapped, so only setting head page's -* PG_dcache_clean flag is enough. -*/ -if (PageHuge (page)) - page =compound_head (page); - -if (!test_bit (PG_dcache_clean, &page->flags)) { +if (!test_bit (PG_dcache_clean, &folio->flags)) {flush_icache_all ();set_bit (PG_dcache_clean, &page->flags); }
Signature · 1 line
2.39.1
Re: [PATCH v3 20/34] riscv: Implement the new page table range API
Quoted 116 lines · On Tue, 28 Feb 2023 13:37:23 PST (-0800), [email protected] wrote:
Add
set_ptes(),update_mmu_cache_range()andflush_dcache_folio(). Change thePG_dcache_cleanflag from being per-page to per-folio.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Reviewed-by Alexandre Ghiti <[email protected]>Cc Paul Walmsley <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Albert Ou <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 19 +++++++++---------- arch/riscv/include/asm/pgtable.h | 26 +++++++++++++++++++------- arch/riscv/mm/cacheflush.c | 11 ++--------- 3 files changed, 30 insertions(+), 26 deletions(-)arch/riscv/include/asm/cacheflush.h +9
-10@@ -15,20 +15,19 @@ static inline void local_flush_icache_all(void)#define PG_dcache_clean PG_arch_1 -static inline void flush_dcache_page (struct page *page) +static inline void flush_dcache_folio (struct folio *folio) { -/* -* HugeTLB pages are always fully mapped and only head page will be -* set PG_dcache_clean (see comments in flush_icache_pte()). -*/ -if (PageHuge (page)) - page =compound_head (page); - -if (test_bit (PG_dcache_clean, &page->flags)) -clear_bit (PG_dcache_clean, &page->flags); +if (test_bit (PG_dcache_clean, &folio->flags)) +clear_bit (PG_dcache_clean, &folio->flags); } +#define flush_dcache_folio flush_dcache_folio#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +} +/* * RISC-V doesn't have an instruction to flush parts of the instruction cache, * so instead we just flush the whole thing. arch/riscv/include/asm/pgtable.h +19
-7@@ -405,8 +405,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)/* Commit new configuration to MMU hardware */ -static inline void update_mmu_cache (struct vm_area_struct *vma, -unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) {/* * The kernel assumes that TLBs don't cache invalid entries, but @@ -415,8 +415,11 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,* Relying on flush_tlb_fix_spurious_fault would suffice, but * the extra traps reduce performance. So, eagerly SFENCE.VMA. */ -local_flush_tlb_page (address); +while (nr--) +local_flush_tlb_page (address + nr *PAGE_SIZE ); } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#define __HAVE_ARCH_UPDATE_MMU_TLB#define update_mmu_tlb update_mmu_cache@@ -456,12 +459,21 @@ static inline void __set_pte_at(struct mm_struct *mm,set_pte (ptep, pteval); } -static inline void set_pte_at (struct mm_struct *mm, -unsigned long addr,pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval,unsigned int nr) { -page_table_check_ptes_set (mm, addr, ptep, pteval,1 ); -__set_pte_at (mm, addr, ptep, pteval); +page_table_check_ptes_set (mm, addr, ptep, pteval, nr); + +for (;;) { +__set_pte_at (mm, addr, ptep, pteval); +if (--nr ==0 ) +break ; + ptep++; + addr +=PAGE_SIZE ; +pte_val (pteval) +=1 << _PAGE_PFN_SHIFT; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline void pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep)arch/riscv/mm/cacheflush.c +1
-3@@ -81,16 +81,9 @@ void flush_icache_mm(struct mm_struct *mm, bool local)#ifdef CONFIG_MMU void flush_icache_pte (pte_t pte) { -struct page *page =pte_page (pte); +struct folio *folio =page_folio (pte_page (pte)); -/* -* HugeTLB pages are always fully mapped, so only setting head page's
arch/riscv/mm/cacheflush.c void flush_icache_mm(struct mm_struct *mm, bool local) · line 89
Quoted 10 lines
arch/riscv/mm/cacheflush.c +1
-6-* PG_dcache_clean flag is enough. -*/ -if (PageHuge (page)) - page =compound_head (page); - -if (!test_bit (PG_dcache_clean, &page->flags)) { +if (!test_bit (PG_dcache_clean, &folio->flags)) {flush_icache_all ();set_bit (PG_dcache_clean, &page->flags); }
Matthew Wilcox (Oracle)
maintainerPATCH v3 21/34 s390: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes() and update_mmu_cache_range().
--- arch/s390/include/asm/pgtable.h | 34 ++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
arch/s390/include/asm/pgtable.h +25 -9
@@ -50,6 +50,7 @@ void arch_report_meminfo(struct seq_file *m);* tables contain all the necessary information. */ #define update_mmu_cache (vma, address, ptep) do { } while (0) +#define update_mmu_cache_range (vma, addr, ptep, nr) do { } while (0)#define update_mmu_cache_pmd (vma, address, ptep) do { } while (0)/*
@@ -1317,21 +1318,36 @@ pgprot_t pgprot_writecombine(pgprot_t prot);pgprot_t pgprot_writethrough (pgprot_t prot);/* -* Certain architectures need to do special things when PTEs -* within a page table are directly modified. Thus, the following -* hook is made available. +* Set multiple PTEs to consecutive pages with a single call. All PTEs +* are within the same folio, PMD and VMA. */ -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t entry) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t entry,unsigned int nr) {if (pte_present (entry)) entry =clear_pte_bit (entry,__pgprot (_PAGE_UNUSED)); -if (mm_has_pgste (mm)) -ptep_set_pte_at (mm, addr, ptep, entry); -else -set_pte (ptep, entry); +if (mm_has_pgste (mm)) { +for (;;) { +ptep_set_pte_at (mm, addr, ptep, entry); +if (--nr ==0 ) +break ; + ptep++; + entry =__pte (pte_val (entry) +PAGE_SIZE ); + addr +=PAGE_SIZE ; + } + }else { +for (;;) { +set_pte (ptep, entry); +if (--nr ==0 ) +break ; + ptep++; + entry =__pte (pte_val (entry) +PAGE_SIZE ); + } + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +/* * Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to.
Signature · 1 line
2.39.1
Re: [PATCH v3 21/34] s390: Implement the new page table range API
Quoted 39 lines · On Tue, 28 Feb 2023 21:37:24 +0000 "Matthew Wilcox (Oracle)"…
Add
set_ptes()andupdate_mmu_cache_range().Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Cc Heiko Carstens <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Alexander Gordeev <[email protected]>Cc Christian Borntraeger <[email protected]>Cc Sven Schnelle <[email protected]>--- arch/s390/include/asm/pgtable.h | 34 ++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)arch/s390/include/asm/pgtable.h +5
-5@@ -50,6 +50,7 @@ void arch_report_meminfo(struct seq_file *m);* tables contain all the necessary information. */ #define update_mmu_cache (vma, address, ptep) do { } while (0) +#define update_mmu_cache_range (vma, addr, ptep, nr) do { } while (0)#define update_mmu_cache_pmd (vma, address, ptep) do { } while (0)/* @@ -1317,21 +1318,36 @@ pgprot_t pgprot_writecombine(pgprot_t prot);pgprot_t pgprot_writethrough (pgprot_t prot);/* -* Certain architectures need to do special things when PTEs -* within a page table are directly modified. Thus, the following -* hook is made available. +* Set multiple PTEs to consecutive pages with a single call. All PTEs +* are within the same folio, PMD and VMA. */ -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t entry) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t entry,unsigned int nr)
arch/s390/include/asm/pgtable.h pgprot_t pgprot_writecombine(pgprot_t prot); · line 1331
Quoted 10 lines
arch/s390/include/asm/pgtable.h +3
-4{if (pte_present (entry)) entry =clear_pte_bit (entry,__pgprot (_PAGE_UNUSED)); -if (mm_has_pgste (mm)) -ptep_set_pte_at (mm, addr, ptep, entry); -else -set_pte (ptep, entry); +if (mm_has_pgste (mm)) { +for (;;) { +ptep_set_pte_at (mm, addr, ptep, entry);
There might be room for additional optimization here, regarding the preempt_disable/enable() in ptep_set_pte_at(), i.e. move it out of ptep_set_pte_at() and do it only once in this loop.
We could add that later with an add-on patch, but for this series it all looks good.
Matthew Wilcox (Oracle)
maintainerPATCH v3 22/34 superh: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Change the PG_dcache_clean flag from being per-page to per-folio. Flush the entire folio containing the pages in flush_icache_pages() for ease of implementation.
--- arch/sh/include/asm/cacheflush.h | 21 ++++++++----- arch/sh/include/asm/pgtable.h | 6 ++-- arch/sh/include/asm/pgtable_32.h | 16 ++++++++-- arch/sh/mm/cache-j2.c | 4 +-- arch/sh/mm/cache-sh4.c | 26 ++++++++++----- arch/sh/mm/cache-sh7705.c | 26 +++++++++------ arch/sh/mm/cache.c | 54 ++++++++++++++++++-------------- arch/sh/mm/kmap.c | 3 +- 8 files changed, 101 insertions(+), 55 deletions(-)
arch/sh/include/asm/cacheflush.h +14 -7
@@ -13,9 +13,9 @@* - flush_cache_page(mm, vmaddr, pfn) flushes a single page * - flush_cache_range(vma, start, end) flushes a range of pages * -* - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache +* - flush_dcache_folio(folio) flushes(wback&invalidates) a folio for dcache * - flush_icache_range(start, end) flushes(invalidates) a range for icache -* - flush_icache_page(vma, pg) flushes(invalidates) a page for icache +* - flush_icache_pages(vma, pg, nr) flushes(invalidates) pages for icache * - flush_cache_sigtramp(vaddr) flushes the signal trampoline */ extern void (*local_flush_cache_all)(void *args);
@@ -23,9 +23,9 @@ extern void (*local_flush_cache_mm)(void *args);extern void (*local_flush_cache_dup_mm)(void *args);extern void (*local_flush_cache_page)(void *args);extern void (*local_flush_cache_range)(void *args); -extern void (*local_flush_dcache_page)(void *args); +extern void (*local_flush_dcache_folio)(void *args);extern void (*local_flush_icache_range)(void *args); -extern void (*local_flush_icache_page)(void *args); +extern void (*local_flush_icache_folio)(void *args);extern void (*local_flush_cache_sigtramp)(void *args);static inline void cache_noop (void *args) { }
@@ -42,11 +42,18 @@ extern void flush_cache_page(struct vm_area_struct *vma,extern void flush_cache_range (struct vm_area_struct *vma,unsigned long start,unsigned long end);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page (struct page *page); +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folio +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +} +extern void flush_icache_range (unsigned long start,unsigned long end);#define flush_icache_user_range flush_icache_range -extern void flush_icache_page (struct vm_area_struct *vma, -struct page *page); +void flush_icache_pages (struct vm_area_struct *vma,struct page *page, +unsigned int nr); +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1)extern void flush_cache_sigtramp (unsigned long address);struct flusher_data {
arch/sh/include/asm/pgtable.h +4 -2
@@ -102,13 +102,15 @@ extern void __update_cache(struct vm_area_struct *vma,extern void __update_tlb (struct vm_area_struct *vma,unsigned long address,pte_t pte); -static inline void -update_mmu_cache (struct vm_area_struct *vma,unsigned long address,pte_t *ptep) +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) {pte_t pte = *ptep;__update_cache (vma, address, pte);__update_tlb (vma, address, pte); } +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];extern void paging_init (void );
arch/sh/include/asm/pgtable_32.h +14 -2
@@ -307,7 +307,19 @@ static inline void set_pte(pte_t *ptep, pte_t pte)#define set_pte (pteptr, pteval) (*(pteptr) = pteval)#endif -#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; + pte =__pte (pte_val (pte) +PAGE_SIZE ); + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* * (pmds are folded into pgds so this doesn't get actually called,
@@ -323,7 +335,7 @@ static inline void set_pte(pte_t *ptep, pte_t pte)#define pte_none (x) (!pte_val(x))#define pte_present (x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE)) -#define pte_clear (mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0) +#define pte_clear (mm, addr, ptep) set_pte(ptep, __pte(0))#define pmd_none (x) (!pmd_val(x))#define pmd_present (x) (pmd_val(x))
arch/sh/mm/cache-j2.c +2 -2
@@ -55,9 +55,9 @@ void __init j2_cache_init(void) local_flush_cache_dup_mm = j2_flush_both; local_flush_cache_page = j2_flush_both; local_flush_cache_range = j2_flush_both; - local_flush_dcache_page = j2_flush_dcache; + local_flush_dcache_folio = j2_flush_dcache; local_flush_icache_range = j2_flush_icache; - local_flush_icache_page = j2_flush_icache; + local_flush_icache_folio = j2_flush_icache; local_flush_cache_sigtramp = j2_flush_icache;pr_info ("Initial J2 CCR is %.8x\n" ,__raw_readl (j2_ccr_base));
arch/sh/mm/cache-sh4.c +18 -8
@@ -107,19 +107,29 @@ static inline void flush_cache_one(unsigned long start, unsigned long phys)* Write back & invalidate the D-cache of the page. * (To avoid "alias" issues) */ -static void sh4_flush_dcache_page (void *arg) +static void sh4_flush_dcache_folio (void *arg) { -struct page *page = arg; -unsigned long addr = (unsigned long )page_address (page); +struct folio *folio = arg;#ifndef CONFIG_SMP -struct address_space *mapping =page_mapping_file (page); +struct address_space *mapping =folio_flush_mapping (folio);if (mapping && !mapping_mapped (mapping)) -clear_bit (PG_dcache_clean, &page->flags); +clear_bit (PG_dcache_clean, &folio->flags); else#endif -flush_cache_one (CACHE_OC_ADDRESS_ARRAY | - (addr & shm_align_mask),page_to_phys (page)); + { +unsigned long pfn =folio_pfn (folio); +unsigned long addr = (unsigned long )folio_address (folio); +unsigned int i, nr =folio_nr_pages (folio); + +for (i =0 ; i < nr; i++) { +flush_cache_one (CACHE_OC_ADDRESS_ARRAY | + (addr & shm_align_mask), + pfn *PAGE_SIZE ); + addr +=PAGE_SIZE ; + pfn++; + } + }wmb (); }
@@ -379,7 +389,7 @@ void __init sh4_cache_init(void) __raw_readl(CCN_PRR)); local_flush_icache_range = sh4_flush_icache_range; - local_flush_dcache_page = sh4_flush_dcache_page; + local_flush_dcache_folio = sh4_flush_dcache_folio; local_flush_cache_all = sh4_flush_cache_all; local_flush_cache_mm = sh4_flush_cache_mm; local_flush_cache_dup_mm = sh4_flush_cache_mm;
arch/sh/mm/cache-sh7705.c +16 -10
@@ -132,15 +132,20 @@ static void __flush_dcache_page(unsigned long phys)* Write back & invalidate the D-cache of the page. * (To avoid "alias" issues) */ -static void sh7705_flush_dcache_page (void *arg) +static void sh7705_flush_dcache_folio (void *arg) { -struct page *page = arg; -struct address_space *mapping =page_mapping_file (page); +struct folio *folio = arg; +struct address_space *mapping =folio_flush_mapping (folio);if (mapping && !mapping_mapped (mapping)) -clear_bit (PG_dcache_clean, &page->flags); -else -__flush_dcache_page (__pa (page_address (page))); +clear_bit (PG_dcache_clean, &folio->flags); +else { +unsigned long pfn =folio_pfn (folio); +unsigned int i, nr =folio_nr_pages (folio); + +for (i =0 ; i < nr; i++) +__flush_dcache_page ((pfn + i) *PAGE_SIZE ); + } }static void sh7705_flush_cache_all (void *args)
@@ -176,19 +181,20 @@ static void sh7705_flush_cache_page(void *args)* Not entirely sure why this is necessary on SH3 with 32K cache but * without it we get occasional "Memory fault" when loading a program. */ -static void sh7705_flush_icache_page (void *page) +static void sh7705_flush_icache_folio (void *arg) { -__flush_purge_region (page_address (page),PAGE_SIZE ); +struct folio *folio = arg; +__flush_purge_region (folio_address (folio),folio_size (folio)); }void __init sh7705_cache_init (void ) { local_flush_icache_range = sh7705_flush_icache_range; - local_flush_dcache_page = sh7705_flush_dcache_page; + local_flush_dcache_folio = sh7705_flush_dcache_folio; local_flush_cache_all = sh7705_flush_cache_all; local_flush_cache_mm = sh7705_flush_cache_all; local_flush_cache_dup_mm = sh7705_flush_cache_all; local_flush_cache_range = sh7705_flush_cache_all; local_flush_cache_page = sh7705_flush_cache_page; - local_flush_icache_page = sh7705_flush_icache_page; + local_flush_icache_folio = sh7705_flush_icache_folio; }
arch/sh/mm/cache.c +31 -23
138 lines not on this page · raw message
arch/sh/mm/kmap.c +2 -1
@@ -27,10 +27,11 @@ void __init kmap_coherent_init(void)void *kmap_coherent (struct page *page,unsigned long addr) { +struct folio *folio =page_folio (page);enum fixed_addresses idx;unsigned long vaddr; -BUG_ON (!test_bit (PG_dcache_clean, &page->flags)); +BUG_ON (!test_bit (PG_dcache_clean, &folio->flags));preempt_disable ();pagefault_disable ();
Signature · 1 line
2.39.1
Geert Uytterhoeven
maintainerRe: [PATCH v3 22/34] superh: Implement the new page table range API
Hi Willy,
Quoted 6 lines · Matthew Wilcox (Oracle)
Add
set_ptes(),update_mmu_cache_range(),flush_dcache_folio()andflush_icache_pages(). Change thePG_dcache_cleanflag from being per-page to per-folio. Flush the entire folio containing the pages inflush_icache_pages()for ease of implementation.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
Thanks for your patch!
Quoted 12 lines
arch/sh/mm/cache.c +2
-2void __flush_anon_page (struct page *page,unsigned long vmaddr) { +struct folio *folio =page_folio (page);unsigned long addr = (unsigned long )page_address (page);if (pages_do_alias (addr, vmaddr)) { -if (boot_cpu_data.dcache.n_aliases &&page_mapcount (page) && -test_bit (PG_dcache_clean, &page->flags)) { + if (boot_cpu_data.dcache.n_aliases && folio_mapped(folio) &&
arch/sh/mm/cache.c EXPORT_SYMBOL(clear_user_highpage); · line 172
Quoted 10 lines
arch/sh/mm/cache.c +2
-2+ test_bit(PG_dcache_clean, &folio->flags)) {void *kaddr; kaddr =kmap_coherent (page, vmaddr);/* XXX.. For now kunmap_coherent() does a purge */ /* __flush_purge_region((void *)kaddr, PAGE_SIZE); */ kunmap_coherent (kaddr); - }else -__flush_purge_region ((void *)addr,PAGE_SIZE ); + } else
Trailing whitespace. Please run scripts/checkpath.pl (on the full series).
arch/sh/mm/cache.c EXPORT_SYMBOL(clear_user_highpage); · line 156
Quoted 4 lines
arch/sh/mm/cache.c +2
-0+__flush_purge_region (folio_address (folio), +folio_size (folio)); } }
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Matthew Wilcox
maintainerRe: [PATCH v3 22/34] superh: Implement the new page table range API
Quoted 5 lines · Geert Uytterhoeven
Review
Quoted 3 lines
(quoted diff) +1
-2- } else - __flush_purge_region((void *)addr, PAGE_SIZE); + } elseTrailing whitespace. Please run
scripts/checkpath.pl(on the full series).
Thanks. It's pretty noisy and I don't intend to clean up many of those warnings, but it did find some legit problems.
I'll squash these fixes into v4.
arch/powerpc/include/asm/pgtable.h +1 -1
@@ -45,7 +45,7 @@ void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte, unsigned int nr);#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#define update_mmu_cache (vma, addr, ptep) \ - update_mmu_cache_range(vma, addr, ptep, 1); + update_mmu_cache_range(vma, addr, ptep, 1)#ifndef MAX_PTRS_PER_PGD #define MAX_PTRS_PER_PGD PTRS_PER_PGD
arch/sh/mm/cache.c +1 -1
@@ -169,7 +169,7 @@ void __flush_anon_page(struct page *page, unsigned long vmaddr)/* XXX.. For now kunmap_coherent() does a purge */ /* __flush_purge_region((void *)kaddr, PAGE_SIZE); */ kunmap_coherent (kaddr); - }else + }else __flush_purge_region (folio_address (folio),folio_size (folio)); }
arch/sparc/include/asm/pgtable_64.h +1 -1
@@ -924,7 +924,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, } } -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1); +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#define pte_clear (mm,addr,ptep) \ set_pte_at((mm), (addr), (ptep), __pte(0UL))
arch/xtensa/mm/cache.c +1 -1
@@ -254,7 +254,7 @@ void update_mmu_cache_range(struct vm_area_struct *vma, unsigned long addr,void *paddr =kmap_local_folio (folio, i *PAGE_SIZE );__flush_dcache_page ((unsigned long )paddr);__invalidate_icache_page ((unsigned long )paddr); -kunmap_atomic (paddr); +kunmap_local (paddr); }set_bit (PG_arch_1, &folio->flags); }
Quoted 15 lines
Review
Quoted 4 lines
(quoted diff) +2
-0+ __flush_purge_region(folio_address(folio), + folio_size(folio)); } }Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Matthew Wilcox (Oracle)
maintainerPATCH v3 23/34 sparc32: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages().
--- arch/sparc/include/asm/cacheflush_32.h | 9 +++++++-- arch/sparc/include/asm/pgtable_32.h | 15 ++++++++++++++- arch/sparc/mm/init_32.c | 13 +++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-)
arch/sparc/include/asm/cacheflush_32.h +7 -2
@@ -16,6 +16,7 @@ sparc32_cachetlb_ops->cache_page(vma, addr)#define flush_icache_range (start, end) do { } while (0)#define flush_icache_page (vma, pg) do { } while (0) +#define flush_icache_pages (vma, pg, nr) do { } while (0)#define copy_to_user_page (vma, page, vaddr, dst, src, len) \ do { \
@@ -35,11 +36,15 @@#define flush_page_for_dma (addr) \ sparc32_cachetlb_ops->page_for_dma(addr) -struct page ;void sparc_flush_page_to_ram (struct page *page); +void sparc_flush_folio_to_ram (struct folio *folio);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page (page) sparc_flush_page_to_ram(page) +#define flush_dcache_folio (folio) sparc_flush_folio_to_ram(folio) +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0)
arch/sparc/include/asm/pgtable_32.h +14 -1
@@ -101,7 +101,19 @@ static inline void set_pte(pte_t *ptep, pte_t pteval)srmmu_swap ((unsigned long *)ptep,pte_val (pteval)); } -#define set_pte_at (mm,addr,ptep,pteval) set_pte(ptep,pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline int srmmu_device_memory (unsigned long x) {
@@ -318,6 +330,7 @@ void mmu_info(struct seq_file *m);#define FAULT_CODE_USER 0x4#define update_mmu_cache (vma, address, ptep) do { } while (0) +#define update_mmu_cache_range (vma, address, ptep, nr) do { } while (0)void srmmu_mapiorange (unsigned int bus,unsigned long xpa,unsigned long xva,unsigned int len);
arch/sparc/mm/init_32.c +11 -2
@@ -297,11 +297,20 @@ void sparc_flush_page_to_ram(struct page *page) {unsigned long vaddr = (unsigned long )page_address (page); -if (vaddr) -__flush_page_to_ram (vaddr); +__flush_page_to_ram (vaddr); }EXPORT_SYMBOL (sparc_flush_page_to_ram); +void sparc_flush_folio_to_ram (struct folio *folio) +{ +unsigned long vaddr = (unsigned long )folio_address (folio); +unsigned int i, nr =folio_nr_pages (folio); + +for (i =0 ; i < nr; i++) +__flush_page_to_ram (vaddr + i *PAGE_SIZE ); +} +EXPORT_SYMBOL (sparc_flush_folio_to_ram); +static const pgprot_t protection_map[16 ] = { [VM_NONE ] =PAGE_NONE , [VM_READ ] =PAGE_READONLY ,
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 24/34 sparc64: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages(). Convert the PG_dcache_dirty flag from being per-page to per-folio.
--- arch/sparc/include/asm/cacheflush_64.h | 18 ++++-- arch/sparc/include/asm/pgtable_64.h | 25 +++++++-- arch/sparc/kernel/smp_64.c | 56 +++++++++++------- arch/sparc/mm/init_64.c | 78 +++++++++++++++----------- arch/sparc/mm/tlb.c | 5 +- 5 files changed, 117 insertions(+), 65 deletions(-)
arch/sparc/include/asm/cacheflush_64.h +12 -6
@@ -35,20 +35,26 @@ void flush_icache_range(unsigned long start, unsigned long end);void __flush_icache_page (unsigned long );void __flush_dcache_page (void *addr,int flush_icache); -void flush_dcache_page_impl (struct page *page); +void flush_dcache_folio_impl (struct folio *folio);#ifdef CONFIG_SMP -void smp_flush_dcache_page_impl (struct page *page,int cpu); -void flush_dcache_page_all (struct mm_struct *mm,struct page *page); +void smp_flush_dcache_folio_impl (struct folio *folio,int cpu); +void flush_dcache_folio_all (struct mm_struct *mm,struct folio *folio);#else -#define smp_flush_dcache_page_impl (page,cpu) flush_dcache_page_impl(page) -#define flush_dcache_page_all (mm,page) flush_dcache_page_impl(page) +#define smp_flush_dcache_folio_impl (folio, cpu) flush_dcache_folio_impl(folio) +#define flush_dcache_folio_all (mm, folio) flush_dcache_folio_impl(folio)#endif void __flush_dcache_range (unsigned long start,unsigned long end);#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page (struct page *page); +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folio +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}#define flush_icache_page (vma, pg) do { } while(0) +#define flush_icache_pages (vma, pg, nr) do { } while(0) void flush_ptrace_access(struct vm_area_struct *, struct page *, unsigned long uaddr, void *kaddr,
arch/sparc/include/asm/pgtable_64.h +20 -5
@@ -911,8 +911,20 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,maybe_tlb_batch_add (mm, addr, ptep, orig, fullmm,PAGE_SHIFT ); } -#define set_pte_at (mm,addr,ptep,pte) \ - __set_pte_at((mm), (addr), (ptep), (pte), 0) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +for (;;) { +__set_pte_at (mm, addr, ptep, pte,0 ); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + addr +=PAGE_SIZE ; + } +} + +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1);#define pte_clear (mm,addr,ptep) \ set_pte_at((mm), (addr), (ptep), __pte(0UL))
@@ -931,8 +943,8 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, \if (pfn_valid (this_pfn) && \ (((old_addr) ^ (new_addr)) & (1 <<13 ))) \ -flush_dcache_page_all (current->mm, \ -pfn_to_page (this_pfn)); \ +flush_dcache_folio_all (current->mm, \ +page_folio (pfn_to_page (this_pfn))); \ } \ newpte; \ })
@@ -947,7 +959,10 @@ struct seq_file;void mmu_info (struct seq_file *);struct vm_area_struct ; -void update_mmu_cache (struct vm_area_struct *,unsigned long ,pte_t *); +void update_mmu_cache_range (struct vm_area_struct *,unsigned long addr, +pte_t *ptep,unsigned int nr); +#define update_mmu_cache (vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1)#ifdef CONFIG_TRANSPARENT_HUGEPAGE void update_mmu_cache_pmd (struct vm_area_struct *vma,unsigned long addr,pmd_t *pmd);
arch/sparc/kernel/smp_64.c +36 -20
111 lines not on this page · raw message
arch/sparc/mm/init_64.c +46 -32
187 lines not on this page · raw message
arch/sparc/mm/tlb.c +3 -2
@@ -118,6 +118,7 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,unsigned long paddr, pfn =pte_pfn (orig);struct address_space *mapping;struct page *page; +struct folio *folio;if (!pfn_valid (pfn)) goto no_cache_flush;
@@ -127,13 +128,13 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, goto no_cache_flush;/* A real file page? */ - mapping =page_mapping_file (page); + mapping =folio_flush_mapping (folio);if (!mapping) goto no_cache_flush; paddr = (unsigned long )page_address (page);if ((paddr ^ vaddr) & (1 <<13 )) -flush_dcache_page_all (mm, page); +flush_dcache_folio_all (mm, folio); } no_cache_flush:
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 25/34 um: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes() and update_mmu_cache_range().
--- arch/um/include/asm/pgtable.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/um/include/asm/pgtable.h +12 -3
@@ -242,12 +242,20 @@ static inline void set_pte(pte_t *pteptr, pte_t pteval)if (pte_present (*pteptr)) *pteptr =pte_mknewprot (*pteptr); } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *pteptr,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { -set_pte (pteptr, pteval); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#define __HAVE_ARCH_PTE_SAMEstatic inline int pte_same (pte_t pte_a,pte_t pte_b) {
@@ -290,6 +298,7 @@ struct mm_struct;extern pte_t *virt_to_pte (struct mm_struct *mm,unsigned long addr);#define update_mmu_cache (vma,address,ptep) do {} while (0) +#define update_mmu_cache_range (vma, address, ptep, nr) do {} while (0)/* * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
Signature · 7 lines
2.39.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Matthew Wilcox (Oracle)
maintainerPATCH v3 26/34 x86: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Convert set_pte_at() into set_ptes() and add a noop update_mmu_cache_range().
--- arch/x86/include/asm/pgtable.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
arch/x86/include/asm/pgtable.h +17 -4
@@ -1019,13 +1019,22 @@ static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp)return res; } -static inline void set_pte_at (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { -page_table_check_ptes_set (mm, addr, ptep, pte,1 ); -set_pte (ptep, pte); +page_table_check_ptes_set (mm, addr, ptep, pte, nr); + +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; + pte =__pte (pte_val (pte) +PAGE_SIZE ); + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +static inline void set_pmd_at (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd) {
@@ -1291,6 +1300,10 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { } +static inline void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long addr,pte_t *ptep,unsigned int nr) +{ +}static inline void update_mmu_cache_pmd (struct vm_area_struct *vma,unsigned long addr,pmd_t *pmd) {
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 27/34 xtensa: Implement the new page table range API
In reply to Matthew Wilcox (Oracle)Add set_ptes(), update_mmu_cache_range(), flush_dcache_folio() and flush_icache_pages().
--- arch/xtensa/include/asm/cacheflush.h | 9 ++- arch/xtensa/include/asm/pgtable.h | 24 +++++--- arch/xtensa/mm/cache.c | 83 ++++++++++++++++------------ 3 files changed, 72 insertions(+), 44 deletions(-)
arch/xtensa/include/asm/cacheflush.h +8 -1
@@ -119,8 +119,14 @@ void flush_cache_page(struct vm_area_struct*,#define flush_cache_vmap (start,end) flush_cache_all()#define flush_cache_vunmap (start,end) flush_cache_all() +void flush_dcache_folio (struct folio *folio); +#define flush_dcache_folio flush_dcache_folio +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -void flush_dcache_page (struct page *); +static inline void flush_dcache_page (struct page *page) +{ +flush_dcache_folio (page_folio (page)); +}void local_flush_cache_range (struct vm_area_struct *vma,unsigned long start,unsigned long end);
@@ -156,6 +162,7 @@ void local_flush_cache_page(struct vm_area_struct *vma,/* This is not required, see Documentation/core-api/cachetlb.rst */ #define flush_icache_page (vma,page) do { } while (0) +#define flush_icache_pages (vma, page, nr) do { } while (0)#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0)
arch/xtensa/include/asm/pgtable.h +17 -7
@@ -301,17 +301,25 @@ static inline void update_pte(pte_t *ptep, pte_t pteval)struct mm_struct ; -static inline void -set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) +static inline void set_pte (pte_t *ptep,pte_t pte) { -update_pte (ptep, pteval); +update_pte (ptep, pte); } -static inline void set_pte (pte_t *ptep,pte_t pteval) +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) { -update_pte (ptep, pteval); +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; +pte_val (pte) +=PAGE_SIZE ; + } } +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +static inline void set_pmd (pmd_t *pmdp,pmd_t pmdval) {
@@ -407,8 +415,10 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)#else -extern void update_mmu_cache (struct vm_area_struct * vma, -unsigned long address,pte_t *ptep); +void update_mmu_cache_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr); +#define update_mmu_cache (vma, address, ptep) \ + update_mmu_cache_range(vma, address, ptep, 1)typedef pte_t *pte_addr_t ;
arch/xtensa/mm/cache.c +47 -36
137 lines not on this page · raw message
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 28/34 mm: Remove page_mapping_file()
In reply to Matthew Wilcox (Oracle)This function has no more users.
--- include/linux/pagemap.h | 8 -------- 1 file changed, 8 deletions(-)
include/linux/pagemap.h +0 -8
@@ -394,14 +394,6 @@ static inline struct address_space *page_file_mapping(struct page *page)return folio_file_mapping (page_folio (page)); } -/* -* For file cache pages, return the address_space, otherwise return NULL -*/ -static inline struct address_space *page_mapping_file (struct page *page) -{ -return folio_flush_mapping (page_folio (page)); -} -/** * folio_inode - Get the host inode for this folio. * @folio: The folio.
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 29/34 mm: Rationalise flush_icache_pages() and flush_icache_page()
In reply to Matthew Wilcox (Oracle)Move the default (no-op) implementation of flush_icache_pages() to <linux/cacheflush.h> from <asm-generic/cacheflush.h>. Remove the flush_icache_page() wrapper from each architecture into <linux/cacheflush.h>.
--- arch/alpha/include/asm/cacheflush.h | 5 +---- arch/arc/include/asm/cacheflush.h | 9 --------- arch/arm/include/asm/cacheflush.h | 7 ------- arch/csky/abiv1/inc/abi/cacheflush.h | 1 - arch/csky/abiv2/inc/abi/cacheflush.h | 1 - arch/hexagon/include/asm/cacheflush.h | 2 +- arch/loongarch/include/asm/cacheflush.h | 2 -- arch/m68k/include/asm/cacheflush_mm.h | 1 - arch/mips/include/asm/cacheflush.h | 6 ------ arch/nios2/include/asm/cacheflush.h | 2 +- arch/nios2/mm/cacheflush.c | 1 + arch/parisc/include/asm/cacheflush.h | 2 +- arch/sh/include/asm/cacheflush.h | 2 +- arch/sparc/include/asm/cacheflush_32.h | 2 -- arch/sparc/include/asm/cacheflush_64.h | 3 --- arch/xtensa/include/asm/cacheflush.h | 4 ---- include/asm-generic/cacheflush.h | 12 ------------ include/linux/cacheflush.h | 9 +++++++++ 18 files changed, 15 insertions(+), 56 deletions(-)
arch/alpha/include/asm/cacheflush.h +1 -4
@@ -53,10 +53,6 @@ extern void flush_icache_user_page(struct vm_area_struct *vma,#define flush_icache_user_page flush_icache_user_page#endif /* CONFIG_SMP */ -/* This is used only in __do_fault and do_swap_page. */ -#define flush_icache_page (vma, page) \ - flush_icache_user_page((vma), (page), 0, 0) -/* * Both implementations of flush_icache_user_page flush the entire * address space, so one call, no matter how many pages.
@@ -66,6 +62,7 @@ static inline void flush_icache_pages(struct vm_area_struct *vma, {flush_icache_user_page (vma, page,0 ,0 ); } +#define flush_icache_pages flush_icache_pages#include <asm-generic/cacheflush.h>
arch/arc/include/asm/cacheflush.h +0 -9
@@ -18,15 +18,6 @@#include <linux/mm.h> #include <asm/shmparam.h> -/* -* Semantically we need this because icache doesn't snoop dcache/dma. -* However ARC Cache flush requires paddr as well as vaddr, latter not available -* in the flush_icache_page() API. So we no-op it but do the equivalent work -* in update_mmu_cache() -*/ -#define flush_icache_page (vma, page) -#define flush_icache_pages (vma, page, nr) -void flush_cache_all (void );void flush_icache_range (unsigned long kstart,unsigned long kend);
arch/arm/include/asm/cacheflush.h +0 -7
@@ -321,13 +321,6 @@ static inline void flush_anon_page(struct vm_area_struct *vma,#define flush_dcache_mmap_lock (mapping) xa_lock_irq(&mapping->i_pages)#define flush_dcache_mmap_unlock (mapping) xa_unlock_irq(&mapping->i_pages) -/* -* We don't appear to need to do anything here. In fact, if we did, we'd -* duplicate cache flushing elsewhere performed by flush_dcache_page(). -*/ -#define flush_icache_page (vma,page) do { } while (0) -#define flush_icache_pages (vma, page, nr) do { } while (0) -/* * flush_cache_vmap() is used when creating mappings (eg, via vmap, * vmalloc, ioremap etc) in kernel space for pages. On non-VIPT
arch/csky/abiv1/inc/abi/cacheflush.h +0 -1
@@ -45,7 +45,6 @@ extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, u#define flush_cache_vmap (start, end) cache_wbinv_all()#define flush_cache_vunmap (start, end) cache_wbinv_all() -#define flush_icache_page (vma, page) do {} while (0);#define flush_icache_range (start, end) cache_wbinv_range(start, end)#define flush_icache_mm_range (mm, start, end) cache_wbinv_range(start, end)#define flush_icache_deferred (mm) do {} while (0);
arch/csky/abiv2/inc/abi/cacheflush.h +0 -1
@@ -33,7 +33,6 @@ static inline void flush_dcache_page(struct page *page)#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0) -#define flush_icache_page (vma, page) do { } while (0)#define flush_icache_range (start, end) cache_wbinv_range(start, end)
arch/hexagon/include/asm/cacheflush.h +1 -1
@@ -18,7 +18,7 @@* - flush_cache_range(vma, start, end) flushes a range of pages * - flush_icache_range(start, end) flush a range of instructions * - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache -* - flush_icache_page(vma, pg) flushes(invalidates) a page for icache +* - flush_icache_pages(vma, pg, nr) flushes(invalidates) nr pages for icache * * Need to doublecheck which one is really needed for ptrace stuff to work. */
arch/loongarch/include/asm/cacheflush.h +0 -2
@@ -46,8 +46,6 @@ void local_flush_icache_range(unsigned long start, unsigned long end);#define flush_cache_page (vma, vmaddr, pfn) do { } while (0)#define flush_cache_vmap (start, end) do { } while (0)#define flush_cache_vunmap (start, end) do { } while (0) -#define flush_icache_page (vma, page) do { } while (0) -#define flush_icache_pages (vma, page) do { } while (0)#define flush_icache_user_page (vma, page, addr, len) do { } while (0)#define flush_dcache_page (page) do { } while (0)#define flush_dcache_folio (folio) do { } while (0)
arch/m68k/include/asm/cacheflush_mm.h +0 -1
@@ -260,7 +260,6 @@ static inline void __flush_pages_to_ram(void *vaddr, unsigned int nr)#define flush_dcache_mmap_unlock (mapping) do { } while (0)#define flush_icache_pages (vma, page, nr) \ __flush_pages_to_ram(page_address(page), nr) -#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1)extern void flush_icache_user_page (struct vm_area_struct *vma,struct page *page,unsigned long addr,int len);
arch/mips/include/asm/cacheflush.h +0 -6
@@ -82,12 +82,6 @@ static inline void flush_anon_page(struct vm_area_struct *vma,__flush_anon_page (page, vmaddr); } -static inline void flush_icache_pages (struct vm_area_struct *vma, -struct page *page,unsigned int nr) -{ -} -#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1) -extern void (*flush_icache_range)(unsigned long start,unsigned long end);extern void (*local_flush_icache_range)(unsigned long start,unsigned long end); extern void (*__flush_icache_user_range)(unsigned long start,
arch/nios2/include/asm/cacheflush.h +1 -1
@@ -35,7 +35,7 @@ void flush_dcache_folio(struct folio *folio);extern void flush_icache_range (unsigned long start,unsigned long end);void flush_icache_pages (struct vm_area_struct *vma,struct page *page,unsigned int nr); -#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1); +#define flush_icache_pages flush_icache_pages#define flush_cache_vmap (start, end) flush_dcache_range(start, end)#define flush_cache_vunmap (start, end) flush_dcache_range(start, end)
arch/nios2/mm/cacheflush.c +1 -0
@@ -147,6 +147,7 @@ void flush_icache_pages(struct vm_area_struct *vma, struct page *page,__flush_dcache (start, end);__flush_icache (start, end); } +#define flush_icache_pages flush_icache_pagesvoid flush_cache_page (struct vm_area_struct *vma,unsigned long vmaddr,unsigned long pfn)
arch/parisc/include/asm/cacheflush.h +1 -1
@@ -59,7 +59,7 @@ static inline void flush_dcache_page(struct page *page)void flush_icache_pages (struct vm_area_struct *vma,struct page *page,unsigned int nr); -#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1) +#define flush_icache_pages flush_icache_pages#define flush_icache_range (s,e) do { \ flush_kernel_dcache_range_asm(s,e); \
arch/sh/include/asm/cacheflush.h +1 -1
@@ -53,7 +53,7 @@ extern void flush_icache_range(unsigned long start, unsigned long end);#define flush_icache_user_range flush_icache_rangevoid flush_icache_pages (struct vm_area_struct *vma,struct page *page,unsigned int nr); -#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1) +#define flush_icache_pages flush_icache_pagesextern void flush_cache_sigtramp (unsigned long address);struct flusher_data {
arch/sparc/include/asm/cacheflush_32.h +0 -2
@@ -15,8 +15,6 @@#define flush_cache_page (vma,addr,pfn) \ sparc32_cachetlb_ops->cache_page(vma, addr)#define flush_icache_range (start, end) do { } while (0) -#define flush_icache_page (vma, pg) do { } while (0) -#define flush_icache_pages (vma, pg, nr) do { } while (0)#define copy_to_user_page (vma, page, vaddr, dst, src, len) \ do { \
arch/sparc/include/asm/cacheflush_64.h +0 -3
@@ -53,9 +53,6 @@ static inline void flush_dcache_page(struct page *page)flush_dcache_folio (page_folio (page)); } -#define flush_icache_page (vma, pg) do { } while(0) -#define flush_icache_pages (vma, pg, nr) do { } while(0) -void flush_ptrace_access (struct vm_area_struct *,struct page *,unsigned long uaddr,void *kaddr,unsigned long len,int write);
arch/xtensa/include/asm/cacheflush.h +0 -4
@@ -160,10 +160,6 @@ void local_flush_cache_page(struct vm_area_struct *vma,__invalidate_icache_range (start,(end) - (start)); \ } while (0) -/* This is not required, see Documentation/core-api/cachetlb.rst */ -#define flush_icache_page (vma,page) do { } while (0) -#define flush_icache_pages (vma, page, nr) do { } while (0) -#define flush_dcache_mmap_lock (mapping) do { } while (0)#define flush_dcache_mmap_unlock (mapping) do { } while (0)
include/asm-generic/cacheflush.h +0 -12
@@ -77,18 +77,6 @@ static inline void flush_icache_range(unsigned long start, unsigned long end)#define flush_icache_user_range flush_icache_range#endif -#ifndef flush_icache_page -static inline void flush_icache_pages (struct vm_area_struct *vma, -struct page *page,unsigned int nr) -{ -} - -static inline void flush_icache_page (struct vm_area_struct *vma, -struct page *page) -{ -} -#endif -#ifndef flush_icache_user_page static inline void flush_icache_user_page(struct vm_area_struct *vma, struct page *page,
include/linux/cacheflush.h +9 -0
@@ -17,4 +17,13 @@ static inline void flush_dcache_folio(struct folio *folio)#define flush_dcache_folio flush_dcache_folio#endif /* ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE */ +#ifndef flush_icache_pages +static inline void flush_icache_pages (struct vm_area_struct *vma, +struct page *page,unsigned int nr) +{ +} +#endif + +#define flush_icache_page (vma, page) flush_icache_pages(vma, page, 1) +#endif /* _LINUX_CACHEFLUSH_H */
Signature · 1 line
2.39.1
Re: [PATCH v3 29/34] mm: Rationalise flush_icache_pages() and flush_icache_page()
Quoted 8 lines · Matthew Wilcox (Oracle)
Move the default (no-op) implementation of
flush_icache_pages()to <linux/cacheflush.h> from <asm-generic/cacheflush.h>. Remove theflush_icache_page()wrapper from each architecture into <linux/cacheflush.h>.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>arch/m68k/include/asm/cacheflush_mm.h | 1 -
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Matthew Wilcox (Oracle)
maintainerPATCH v3 30/34 mm: Use flush_icache_pages() in do_set_pmd()
In reply to Matthew Wilcox (Oracle)Push the iteration over each page down to the architectures (many can flush the entire THP without iteration).
--- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/memory.c +1 -2
@@ -4222,8 +4222,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)if (unlikely (!pmd_none (*vmf->pmd))) goto out; -for (i =0 ; i <HPAGE_PMD_NR ; i++) -flush_icache_page (vma, page + i); +flush_icache_pages (vma, page,HPAGE_PMD_NR ); entry =mk_huge_pmd (page, vma->vm_page_prot);if (write)
Signature · 1 line
2.39.1
Mike Rapoport
reviewerRe: [PATCH v3 30/34] mm: Use flush_icache_pages() in do_set_pmd()
Quoted 24 lines · Matthew Wilcox (Oracle)
Push the iteration over each page down to the architectures (many can flush the entire THP without iteration).
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/memory.c +1
-2@@ -4222,8 +4222,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)if (unlikely (!pmd_none (*vmf->pmd))) goto out; -for (i =0 ; i <HPAGE_PMD_NR ; i++) -flush_icache_page (vma, page + i); +flush_icache_pages (vma, page,HPAGE_PMD_NR ); entry =mk_huge_pmd (page, vma->vm_page_prot);if (write)Signature · 1 line
2.39.1
I get this:
CC mm/memory.o/home/mike/git/linux/mm/memory.c: In function 'do_set_pmd':/home/mike/git/linux/mm/memory.c:4191:13: warning: unused variable 'i' [-Wunused-variable]
4191 | int i;
| ^
And the patch here makes it go away:
mm/memory.c +0 -1
@@ -4188,7 +4188,6 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)bool write = vmf->flags &FAULT_FLAG_WRITE ;unsigned long haddr = vmf->address &HPAGE_PMD_MASK ;pmd_t entry; -int i;vm_fault_t ret =VM_FAULT_FALLBACK ;if (!transhuge_vma_suitable (vma, haddr))
Signature · 2 lines
Sincerely yours, Mike.
Matthew Wilcox
maintainerRe: [PATCH v3 30/34] mm: Use flush_icache_pages() in do_set_pmd()
Quoted 28 lines · Mike Rapoport
Quoted 24 lines · Matthew Wilcox (Oracle)
Push the iteration over each page down to the architectures (many can flush the entire THP without iteration).
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/memory.c +1
-2@@ -4222,8 +4222,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)if (unlikely (!pmd_none (*vmf->pmd))) goto out; -for (i =0 ; i <HPAGE_PMD_NR ; i++) -flush_icache_page (vma, page + i); +flush_icache_pages (vma, page,HPAGE_PMD_NR ); entry =mk_huge_pmd (page, vma->vm_page_prot);if (write)Signature · 1 line
2.39.1I get this:
Quoted 4 lines
CC
mm/memory.o/home/mike/git/linux/mm/memory.c: In function 'do_set_pmd':/home/mike/git/linux/mm/memory.c:4191:13: warning: unused variable 'i' [-Wunused-variable]
4191 | int i;
Yep, caught that one last night. My build test must have been with a config that didn't include THP. Thanks.
Matthew Wilcox (Oracle)
maintainerPATCH v3 31/34 filemap: Add filemap_map_folio_range()
In reply to Matthew Wilcox (Oracle)From: Yin Fengwei <[email protected]>
filemap_map_folio_range() maps partial/full folio. Comparing to original filemap_map_pages(), it updates refcount once per folio instead of per page and gets minor performance improvement for large folio.
With a will-it-scale.page_fault3 like app (change file write fault testing to read fault testing. Trying to upstream it to will-it-scale at [1]), got 2% performance gain on a 48C/96T Cascade Lake test box with 96 processes running against xfs.
[1]: https://github.com/antonblanchard/will-it-scale/pull/37
--- mm/filemap.c | 98 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-)
mm/filemap.c +54 -44
@@ -2202,16 +2202,6 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start, }EXPORT_SYMBOL (filemap_get_folios); -static inline -bool folio_more_pages (struct folio *folio,pgoff_t index,pgoff_t max) -{ -if (!folio_test_large (folio) ||folio_test_hugetlb (folio)) -return false; -if (index >= max) -return false; -return index < folio->index +folio_nr_pages (folio) -1 ; -} -/** * filemap_get_folios_contig - Get a batch of contiguous folios * @mapping: The address_space to search
@@ -3483,6 +3473,53 @@ static inline struct folio *next_map_page(struct address_space *mapping, mapping, xas, end_pgoff); } +/* +* Map page range [start_page, start_page + nr_pages) of folio. +* start_page is gotten from start by folio_page(folio, start) +*/ +static vm_fault_t filemap_map_folio_range (struct vm_fault *vmf, +struct folio *folio,unsigned long start, +unsigned long addr,unsigned int nr_pages) +{ +vm_fault_t ret =0 ; +struct vm_area_struct *vma = vmf->vma; +struct file *file = vma->vm_file; +struct page *page =folio_page (folio, start); +unsigned int mmap_miss =READ_ONCE (file->f_ra.mmap_miss); +unsigned int ref_count =0 , count =0 ; + +do { +if (PageHWPoison (page)) +continue ; + +if (mmap_miss >0 ) + mmap_miss--; + +/* +* NOTE: If there're PTE markers, we'll leave them to be +* handled in the specific fault path, and it'll prohibit the +* fault-around logic. +*/ +if (!pte_none (*vmf->pte)) +continue ; + +if (vmf->address == addr) + ret =VM_FAULT_NOPAGE ; + + ref_count++; +do_set_pte (vmf, page, addr); +update_mmu_cache (vma, addr, vmf->pte); + }while (vmf->pte++, page++, addr +=PAGE_SIZE , ++count < nr_pages); + +/* Restore the vmf->pte */ + vmf->pte -= nr_pages; + +folio_ref_add (folio, ref_count); +WRITE_ONCE (file->f_ra.mmap_miss, mmap_miss); + +return ret; +} +vm_fault_t filemap_map_pages (struct vm_fault *vmf,pgoff_t start_pgoff,pgoff_t end_pgoff) {
@@ -3493,9 +3530,9 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,unsigned long addr;XA_STATE (xas, &mapping->i_pages, start_pgoff);struct folio *folio; -struct page *page;unsigned int mmap_miss =READ_ONCE (file->f_ra.mmap_miss);vm_fault_t ret =0 ; +int nr_pages =0 ;rcu_read_lock (); folio =first_map_page (mapping, &xas, end_pgoff);
@@ -3510,45 +3547,18 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) <<PAGE_SHIFT ); vmf->pte =pte_offset_map_lock (vma->vm_mm, vmf->pmd, addr, &vmf->ptl);do { -again: - page =folio_file_page (folio, xas.xa_index); -if (PageHWPoison (page)) - goto unlock; - -if (mmap_miss >0 ) - mmap_miss--; +unsigned long end; addr += (xas.xa_index - last_pgoff) <<PAGE_SHIFT ; vmf->pte += xas.xa_index - last_pgoff; last_pgoff = xas.xa_index; + end = folio->index +folio_nr_pages (folio) -1 ; + nr_pages =min (end, end_pgoff) - xas.xa_index +1 ; -/* -* NOTE: If there're PTE markers, we'll leave them to be -* handled in the specific fault path, and it'll prohibit the -* fault-around logic. -*/ -if (!pte_none (*vmf->pte)) - goto unlock; + ret |=filemap_map_folio_range (vmf, folio, + xas.xa_index - folio->index, addr, nr_pages); + xas.xa_index += nr_pages; -/* We're about to handle the fault */ -if (vmf->address == addr) - ret =VM_FAULT_NOPAGE ; - -do_set_pte (vmf, page, addr); -/* no need to invalidate: a not-present page won't be cached */ -update_mmu_cache (vma, addr, vmf->pte); -if (folio_more_pages (folio, xas.xa_index, end_pgoff)) { - xas.xa_index++; -folio_ref_inc (folio); - goto again; - } -folio_unlock (folio); -continue ; -unlock: -if (folio_more_pages (folio, xas.xa_index, end_pgoff)) { - xas.xa_index++; - goto again; - }folio_unlock (folio);folio_put (folio); }while ((folio =next_map_page (mapping, &xas, end_pgoff)) !=NULL );
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 32/34 rmap: add folio_add_file_rmap_range()
In reply to Matthew Wilcox (Oracle)From: Yin Fengwei <[email protected]>
folio_add_file_rmap_range() allows to add pte mapping to a specific range of file folio. Comparing to page_add_file_rmap(), it batched updates __lruvec_stat for large folio.
--- include/linux/rmap.h | 2 ++ mm/rmap.c | 60 +++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 14 deletions(-)
include/linux/rmap.h +2 -0
@@ -198,6 +198,8 @@ void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address);void page_add_file_rmap (struct page *,struct vm_area_struct *,bool compound); +void folio_add_file_rmap_range (struct folio *,struct page *,unsigned int nr, +struct vm_area_struct *,bool compound);void page_remove_rmap (struct page *,struct vm_area_struct *,bool compound);
mm/rmap.c +46 -14
83 lines not on this page · raw message
Signature · 1 line
2.39.1
Re: [PATCH v3 32/34] rmap: add folio_add_file_rmap_range()
Quoted 66 lines · Matthew Wilcox (Oracle)
From: Yin Fengwei <[email protected]>
folio_add_file_rmap_range()allows to add pte mapping to a specific range of file folio. Comparing topage_add_file_rmap(), it batched updates__lruvec_statfor large folio.Signed-off-by Yin Fengwei <[email protected]>Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- include/linux/rmap.h | 2 ++ mm/rmap.c | 60 +++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 14 deletions(-)include/linux/rmap.h +2
-0@@ -198,6 +198,8 @@ void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address);void page_add_file_rmap (struct page *,struct vm_area_struct *,bool compound); +void folio_add_file_rmap_range (struct folio *,struct page *,unsigned int nr, +struct vm_area_struct *,bool compound);void page_remove_rmap (struct page *,struct vm_area_struct *,bool compound);mm/rmap.c +12
-9@@ -1303,31 +1303,39 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, }/** -* page_add_file_rmap - add pte mapping to a file page -* @page: the page to add the mapping to +* folio_add_file_rmap_range - add pte mapping to page range of a folio +* @folio: The folio to add the mapping to +* @page: The first page to add +* @nr_pages: The number of pages which will be mapped * @vma: the vm area in which the mapping is added * @compound: charge the page as compound or small page * +* The page range of folio is defined by [first_page, first_page + nr_pages) +* * The caller needs to hold the pte lock. */ -void page_add_file_rmap (struct page *page,struct vm_area_struct *vma, -bool compound) +void folio_add_file_rmap_range (struct folio *folio,struct page *page, +unsigned int nr_pages,struct vm_area_struct *vma, +bool compound) { -struct folio *folio =page_folio (page);atomic_t *mapped = &folio->_nr_pages_mapped; -int nr =0 , nr_pmdmapped =0 ; -bool first; +unsigned int nr_pmdmapped =0 , first; +int nr =0 ; -VM_BUG_ON_PAGE (compound && !PageTransHuge (page), page); +VM_WARN_ON_FOLIO (compound && !folio_test_pmd_mappable (folio), folio);/* Is page being mapped by PTE? Is this its first map to be added? */ if (likely (!compound)) { - first =atomic_inc_and_test (&page->_mapcount);
mm/rmap.c void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, · line 1333
Quoted 10 lines
mm/rmap.c +5
-5- nr = first; -if (first &&folio_test_large (folio)) { - nr =atomic_inc_return_relaxed (mapped); - nr = (nr <COMPOUND_MAPPED ); - } + do { + first = atomic_inc_and_test(&page->_mapcount); + if (first && folio_test_large(folio)) { + first = atomic_inc_return_relaxed(mapped); + first = (nr < COMPOUND_MAPPED);
Sorry. Just noticed this typo which was my bad. This should be:
first = (first < COMPOUND_MAPPED);
Regards
Yin, Fengwei
Quoted 39 lines
mm/rmap.c +29
-0+ } + +if (first) + nr++; + }while (page++, --nr_pages >0 ); }else if (folio_test_pmd_mappable (folio)) {/* That test is redundant: it's for safety or to optimize out */ @@ -1356,6 +1364,30 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma,mlock_vma_folio (folio, vma, compound); } +/** +* page_add_file_rmap - add pte mapping to a file page +* @page: the page to add the mapping to +* @vma: the vm area in which the mapping is added +* @compound: charge the page as compound or small page +* +* The caller needs to hold the pte lock. +*/ +void page_add_file_rmap (struct page *page,struct vm_area_struct *vma, +bool compound) +{ +struct folio *folio =page_folio (page); +unsigned int nr_pages; + +VM_WARN_ON_ONCE_PAGE (compound && !PageTransHuge (page), page); + +if (likely (!compound)) + nr_pages =1 ; +else + nr_pages =folio_nr_pages (folio); + +folio_add_file_rmap_range (folio, page, nr_pages, vma, compound); +} +/** * page_remove_rmap - take down pte mapping from a page * @page: page to remove mapping from
Matthew Wilcox (Oracle)
maintainerPATCH v3 33/34 mm: Convert do_set_pte() to set_pte_range()
In reply to Matthew Wilcox (Oracle)From: Yin Fengwei <[email protected]>
set_pte_range() allows to setup page table entries for a specific range. It takes advantage of batched rmap update for large folio. It now takes care of calling update_mmu_cache_range().
--- Documentation/filesystems/locking.rst | 2 +- include/linux/mm.h | 3 ++- mm/filemap.c | 3 +-- mm/memory.c | 27 +++++++++++++++------------ 4 files changed, 19 insertions(+), 16 deletions(-)
Documentation/filesystems/locking.rst +1 -1
@@ -663,7 +663,7 @@ locked. The VM will unlock the page. Filesystem should find and map pages associated with offsets from "start_pgoff" till "end_pgoff". ->map_pages() is called with page table locked and must not block. If it's not possible to reach a page without blocking, -filesystem should skip it. Filesystem should use do_set_pte() to setup +filesystem should skip it. Filesystem should use set_pte_range() to setup page table entry. Pointer to entry associated with the page is passed in "pte" field in vm_fault structure. Pointers to entries for other offsets should be calculated relative to "pte".
include/linux/mm.h +2 -1
@@ -1168,7 +1168,8 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) }vm_fault_t do_set_pmd (struct vm_fault *vmf,struct page *page); -void do_set_pte (struct vm_fault *vmf,struct page *page,unsigned long addr); +void set_pte_range (struct vm_fault *vmf,struct folio *folio, +struct page *page,unsigned int nr,unsigned long addr);vm_fault_t finish_fault (struct vm_fault *vmf);vm_fault_t finish_mkwrite_fault (struct vm_fault *vmf);
mm/filemap.c +1 -2
@@ -3507,8 +3507,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, ret =VM_FAULT_NOPAGE ; ref_count++; -do_set_pte (vmf, page, addr); -update_mmu_cache (vma, addr, vmf->pte); +set_pte_range (vmf, folio, page,1 , addr); }while (vmf->pte++, page++, addr +=PAGE_SIZE , ++count < nr_pages);/* Restore the vmf->pte */
mm/memory.c +15 -12
@@ -4255,7 +4255,8 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) }#endif -void do_set_pte (struct vm_fault *vmf,struct page *page,unsigned long addr) +void set_pte_range (struct vm_fault *vmf,struct folio *folio, +struct page *page,unsigned int nr,unsigned long addr) {struct vm_area_struct *vma = vmf->vma;bool uffd_wp =pte_marker_uffd_wp (vmf->orig_pte);
@@ -4263,7 +4264,7 @@ void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr)bool prefault = vmf->address != addr;pte_t entry; -flush_icache_page (vma, page); +flush_icache_pages (vma, page, nr); entry =mk_pte (page, vma->vm_page_prot);if (prefault &&arch_wants_old_prefaulted_pte ())
@@ -4277,14 +4278,18 @@ void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr) entry =pte_mkuffd_wp (entry);/* copy-on-write page */ if (write && !(vma->vm_flags &VM_SHARED )) { -inc_mm_counter (vma->vm_mm,MM_ANONPAGES ); -page_add_new_anon_rmap (page, vma, addr); -lru_cache_add_inactive_or_unevictable (page, vma); +add_mm_counter (vma->vm_mm,MM_ANONPAGES , nr); +VM_BUG_ON_FOLIO (nr !=1 , folio); +folio_add_new_anon_rmap (folio, vma, addr); +folio_add_lru_vma (folio, vma); }else { -inc_mm_counter (vma->vm_mm,mm_counter_file (page)); -page_add_file_rmap (page, vma, false); +add_mm_counter (vma->vm_mm,mm_counter_file (page), nr); +folio_add_file_rmap_range (folio, page, nr, vma, false); } -set_pte_at (vma->vm_mm, addr, vmf->pte, entry); +set_ptes (vma->vm_mm, addr, vmf->pte, entry, nr); + +/* no need to invalidate: a not-present page won't be cached */ +update_mmu_cache_range (vma, addr, vmf->pte, nr); }static bool vmf_pte_changed (struct vm_fault *vmf)
@@ -4357,11 +4362,9 @@ vm_fault_t finish_fault(struct vm_fault *vmf)/* Re-check under ptl */ if (likely (!vmf_pte_changed (vmf))) { -do_set_pte (vmf, page, vmf->address); - -/* no need to invalidate: a not-present page won't be cached */ -update_mmu_cache (vma, vmf->address, vmf->pte); +struct folio *folio =page_folio (page); +set_pte_range (vmf, folio, page,1 , vmf->address); ret =0 ; }else {update_mmu_tlb (vma, vmf->address, vmf->pte);
Signature · 1 line
2.39.1
Matthew Wilcox (Oracle)
maintainerPATCH v3 34/34 filemap: Batch PTE mappings
In reply to Matthew Wilcox (Oracle)From: Yin Fengwei <[email protected]>
Call set_pte_range() once per contiguous range of the folio instead of once per page. This batches the updates to mm counters and the rmap.
With a will-it-scale.page_fault3 like app (change file write fault testing to read fault testing. Trying to upstream it to will-it-scale at [1]) got 15% performance gain on a 48C/96T Cascade Lake test box with 96 processes running against xfs.
Perf data collected before/after the change:
18.73%--page_add_file_rmap
|
--11.60%--__mod_lruvec_page_state
|
|--7.40%--__mod_memcg_lruvec_state
| |
| --5.58%--cgroup_rstat_updated
|
--2.53%--__mod_lruvec_state
|
--1.48%--__mod_node_page_state9.93%--page_add_file_rmap_range
|
--2.67%--__mod_lruvec_page_state
|
|--1.95%--__mod_memcg_lruvec_state
| |
| --1.57%--cgroup_rstat_updated
|
--0.61%--__mod_lruvec_state
|
--0.54%--__mod_node_page_stateThe running time of __mode_lruvec_page_state() is reduced about 9%.
[1]: https://github.com/antonblanchard/will-it-scale/pull/37
--- mm/filemap.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
mm/filemap.c +25 -11
@@ -3486,11 +3486,12 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,struct file *file = vma->vm_file;struct page *page =folio_page (folio, start);unsigned int mmap_miss =READ_ONCE (file->f_ra.mmap_miss); -unsigned int ref_count =0 , count =0 ; +unsigned int count =0 ; +pte_t *old_ptep = vmf->pte; do { - if (PageHWPoison(page)) - continue; + if (PageHWPoison(page + count)) + goto skip; if (mmap_miss > 0) mmap_miss--;
@@ -3500,20 +3501,33 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,* handled in the specific fault path, and it'll prohibit the * fault-around logic. */ -if (!pte_none (*vmf->pte)) -continue ; +if (!pte_none (vmf->pte[count])) + goto skip;if (vmf->address == addr) ret =VM_FAULT_NOPAGE ; - ref_count++; -set_pte_range (vmf, folio, page,1 , addr); - }while (vmf->pte++, page++, addr +=PAGE_SIZE , ++count < nr_pages); + count++; +continue ; +skip: +if (count) { +set_pte_range (vmf, folio, page, count, addr); +folio_ref_add (folio, count); + } -/* Restore the vmf->pte */ - vmf->pte -= nr_pages; + count++; + page += count; + vmf->pte += count; + addr += count *PAGE_SIZE ; + count =0 ; + }while (--nr_pages >0 ); + +if (count) { +set_pte_range (vmf, folio, page, count, addr); +folio_ref_add (folio, count); + } -folio_ref_add (folio, ref_count); + vmf->pte = old_ptep;WRITE_ONCE (file->f_ra.mmap_miss, mmap_miss);return ret;
Signature · 1 line
2.39.1
Mike Rapoport
reviewerQuoted 11 lines · Matthew Wilcox (Oracle)
This patchset changes the API used by the MM to set up page table entries. The four APIs are:
set_ptes(mm, addr, ptep, pte, nr)update_mmu_cache_range(vma, addr, ptep, nr)flush_dcache_folio(folio)
flush_icache_pages(vma, page, nr)
flush_dcache_folio()isn't technically new, but no architecture implemented it, so I've done that for you. The old APIs remain around but are mostly implemented by calling the new interfaces.
Quoted 6 lines
The new APIs are based around setting up N page table entries at once. The N entries belong to the same PMD, the same folio and the same VMA, so ptep++ is a legitimate operation, and locking is taken care of for you. Some architectures can do a better job of it than just a loop, but I have hesitated to make too deep a change to architectures I don't understand well.
The new set_ptes() looks unnecessarily duplicated all over arch/ What do you say about adding the patch below on top of the series? Ideally it should be split into per-arch bits, but I can send it separately as a cleanup on top.
arch/alpha/include/asm/pgtable.h +1 -0
@@ -37,6 +37,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,pte_val (pte) +=1UL <<32 ; } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* PMD_SHIFT determines the size of the area a second-level page table can map */
arch/arc/include/asm/pgtable-bits-arcv2.h +0 -13
@@ -100,19 +100,6 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)return __pte ((pte_val (pte) & _PAGE_CHG_MASK) |pgprot_val (newprot)); } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -void update_mmu_cache_range (struct vm_area_struct *vma,unsigned long address,pte_t *ptep,unsigned int nr);
arch/arm/include/asm/pgtable.h +1 -0
@@ -209,6 +209,7 @@ extern void __sync_icache_dcache(pte_t pteval);void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval,unsigned int nr); +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline pte_t clear_pte_bit (pte_t pte,pgprot_t prot)
arch/arm64/include/asm/pgtable.h +1 -0
@@ -369,6 +369,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,pte_val (pte) +=PAGE_SIZE ; } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/*
arch/csky/include/asm/pgtable.h +0 -14
@@ -91,20 +91,6 @@ static inline void set_pte(pte_t *p, pte_t pte)smp_mb (); } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -static inline pte_t *pmd_page_vaddr (pmd_t pmd) {unsigned long ptr;
arch/hexagon/include/asm/pgtable.h +0 -20
@@ -345,26 +345,6 @@ static inline int pte_exec(pte_t pte)#define pte_pfn (pte) (pte_val(pte) >> PAGE_SHIFT)#define set_pmd (pmdptr, pmdval) (*(pmdptr) = (pmdval)) -/* -* set_ptes - update page table and do whatever magic may be -* necessary to make the underlying hardware/firmware take note. -* -* VM may require a virtual instruction to alert the MMU. -*/ -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -static inline unsigned long pmd_page_vaddr (pmd_t pmd) {return (unsigned long )__va (pmd_val (pmd) &PAGE_MASK );
arch/ia64/include/asm/pgtable.h +0 -13
@@ -303,19 +303,6 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, add, ptep, pte, 1) -/* * Make page protection values cacheable, uncacheable, or write- * combining. Note that "protection" is really a misnomer here as the
arch/loongarch/include/asm/pgtable.h +1 -0
@@ -346,6 +346,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline void pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep)
arch/m68k/include/asm/pgtable_mm.h +0 -14
@@ -32,20 +32,6 @@ *(pteptr) = (pteval); \ }while (0 ) -static inline void set_ptes(struct mm_struct *mm, unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) - /* PMD_SHIFT determines the size of the area a second-level page table can map */#if CONFIG_PGTABLE_LEVELS ==3 #define PMD_SHIFT 18
arch/microblaze/include/asm/pgtable.h +0 -14
@@ -335,20 +335,6 @@ static inline void set_pte(pte_t *ptep, pte_t pte) *ptep = pte; } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=1 <<PFN_SHIFT_OFFSET ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNGstatic inline int ptep_test_and_clear_young (struct vm_area_struct *vma,unsigned long address,pte_t *ptep)
arch/mips/include/asm/pgtable.h +1 -0
@@ -108,6 +108,7 @@ do { \static inline void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr); +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && defined(CONFIG_CPU_MIPS32 )
arch/nios2/include/asm/pgtable.h +1 -0
@@ -193,6 +193,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)static inline int pmd_none (pmd_t pmd)
arch/openrisc/include/asm/pgtable.h +0 -14
@@ -47,20 +47,6 @@ extern void paging_init(void);*/ #define set_pte (pteptr, pteval) ((*(pteptr)) = (pteval)) -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -/* * (pmds are folded into pgds so this doesn't get actually called, * but the define is needed for a generic inline function.)
arch/parisc/include/asm/pgtable.h +1 -0
@@ -73,6 +73,7 @@ extern void __update_cache(pte_t pte);mb (); \ } while(0) +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#endif /* !__ASSEMBLY__ */
arch/powerpc/include/asm/pgtable.h +1 -0
@@ -43,6 +43,7 @@ struct mm_struct;void set_ptes (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pte,unsigned int nr); +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)#define update_mmu_cache (vma, addr, ptep) \ update_mmu_cache_range(vma, addr, ptep, 1);
arch/riscv/include/asm/pgtable.h +1 -0
@@ -473,6 +473,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,pte_val (pteval) +=1 << _PAGE_PFN_SHIFT; } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) static inline void pte_clear(struct mm_struct *mm,
arch/s390/include/asm/pgtable.h +1 -0
@@ -1346,6 +1346,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/*
arch/sh/include/asm/pgtable_32.h +1 -0
@@ -319,6 +319,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/*
arch/sparc/include/asm/pgtable_32.h +0 -14
@@ -101,20 +101,6 @@ static inline void set_pte(pte_t *ptep, pte_t pteval)srmmu_swap ((unsigned long *)ptep,pte_val (pteval)); } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -static inline int srmmu_device_memory (unsigned long x) {return ((x &0xF0000000 ) !=0 );
arch/sparc/include/asm/pgtable_64.h +1 -0
@@ -924,6 +924,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr, } } +#define set_ptes set_ptes#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1);#define pte_clear (mm,addr,ptep) \
arch/um/include/asm/pgtable.h +0 -14
@@ -242,20 +242,6 @@ static inline void set_pte(pte_t *pteptr, pte_t pteval)if (pte_present (*pteptr)) *pteptr =pte_mknewprot (*pteptr); } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -#define __HAVE_ARCH_PTE_SAMEstatic inline int pte_same (pte_t pte_a,pte_t pte_b) {
arch/x86/include/asm/pgtable.h +0 -16
@@ -1019,22 +1019,6 @@ static inline pud_t native_local_pudp_get_and_clear(pud_t *pudp)return res; } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -page_table_check_ptes_set (mm, addr, ptep, pte, nr); - -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; - pte =__pte (pte_val (pte) +PAGE_SIZE ); - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -static inline void set_pmd_at (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd) {
arch/xtensa/include/asm/pgtable.h +0 -14
@@ -306,20 +306,6 @@ static inline void set_pte(pte_t *ptep, pte_t pte)update_pte (ptep, pte); } -static inline void set_ptes (struct mm_struct *mm,unsigned long addr, -pte_t *ptep,pte_t pte,unsigned int nr) -{ -for (;;) { -set_pte (ptep, pte); -if (--nr ==0 ) -break ; - ptep++; -pte_val (pte) +=PAGE_SIZE ; - } -} - -#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) -static inline void set_pmd (pmd_t *pmdp,pmd_t pmdval) {
include/linux/pgtable.h +18 -0
@@ -172,6 +172,24 @@ static inline int pmd_young(pmd_t pmd) }#endif +#ifndef set_ptes +static inline void set_ptes (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned int nr) +{ +page_table_check_ptes_set (mm, addr, ptep, pte, nr); + +for (;;) { +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + ptep++; + pte =__pte (pte_val (pte) +PAGE_SIZE ); + } +} +#define set_ptes set_ptes +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#endif +#ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep,
Signature · 2 lines
Sincerely yours, Mike.
Hi Willy,
Quoted 24 lines · Matthew Wilcox (Oracle)
This patchset changes the API used by the MM to set up page table entries. The four APIs are:
set_ptes(mm, addr, ptep, pte, nr)update_mmu_cache_range(vma, addr, ptep, nr)flush_dcache_folio(folio)
flush_icache_pages(vma, page, nr)
flush_dcache_folio()isn't technically new, but no architecture implemented it, so I've done that for you. The old APIs remain around but are mostly implemented by calling the new interfaces.The new APIs are based around setting up N page table entries at once. The N entries belong to the same PMD, the same folio and the same VMA, so ptep++ is a legitimate operation, and locking is taken care of for you. Some architectures can do a better job of it than just a loop, but I have hesitated to make too deep a change to architectures I don't understand well.
One thing I have changed in every architecture is that
PG_arch_1is now a per-folio bit instead of a per-page bit. This was something that would have to happen eventually, and it makes sense to do it now rather than iterate over every page involved in a cache flush and figure out if it needs to happen.
Quoted 6 lines
The point of all this is better performance, and Fengwei Yin has measured improvement on x86. I suspect you'll see improvement on your architecture too. Try the new will-it-scale test mentioned here:
https://lore.kernel.org/linux-mm/[email protected]/
You'll need to run it on an XFS filesystem and haveCONFIG_TRANSPARENT_HUGEPAGEset.
Thanks for your series!
Quoted 4 lines
For testing, I've only run the code on x86. If an
x86->foocompiler exists in Debian, I've built defconfig. I'm relying on the buildbots to tell me what I missed, and people who actually have the hardware to tell me if it actually works.
Seems to work fine on ARAnyM and qemu-system-m68k/virt, so
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 31 lines · Matthew Wilcox (Oracle)
This patchset changes the API used by the MM to set up page table entries. The four APIs are:
set_ptes(mm, addr, ptep, pte, nr)update_mmu_cache_range(vma, addr, ptep, nr)flush_dcache_folio(folio)
flush_icache_pages(vma, page, nr)
flush_dcache_folio()isn't technically new, but no architecture implemented it, so I've done that for you. The old APIs remain around but are mostly implemented by calling the new interfaces.The new APIs are based around setting up N page table entries at once. The N entries belong to the same PMD, the same folio and the same VMA, so ptep++ is a legitimate operation, and locking is taken care of for you. Some architectures can do a better job of it than just a loop, but I have hesitated to make too deep a change to architectures I don't understand well.
One thing I have changed in every architecture is that
PG_arch_1is now a per-folio bit instead of a per-page bit. This was something that would have to happen eventually, and it makes sense to do it now rather than iterate over every page involved in a cache flush and figure out if it needs to happen.The point of all this is better performance, and Fengwei Yin has measured improvement on x86. I suspect you'll see improvement on your architecture too. Try the new will-it-scale test mentioned here:
https://lore.kernel.org/linux-mm/[email protected]/
You'll need to run it on an XFS filesystem and haveCONFIG_TRANSPARENT_HUGEPAGEset.
Quoted 7 lines
For testing, I've only run the code on x86. If an
x86->foocompiler exists in Debian, I've built defconfig. I'm relying on the buildbots to tell me what I missed, and people who actually have the hardware to tell me if it actually works.I'd like to get this into the MM tree soon after the current merge window closes, so quick feedback would be appreciated.
I've boot-tested the series (with the Yin's typo fix for patch 32) on arm64 FVP and Ampere Altra. On the Altra, I also ran page_fault4 from will-it-scale, and see ~35% improvement from this series. So:
Thanks,
Ryan