parisc: Rewrite cache flush code for PA8800/PA8900
PATCH v3 1/1 parisc: Rewrite cache flush code for PA8800/PA8900
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.
The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a flush_cache_dup_mm routine. flush_cache_mm and flush_cache_dup_mm differ in that flush_cache_mm calls purge_cache_pages and flush_cache_dup_mm calls flush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.
V2:
1) Add flush_cache_page_check_pte routine.
2) Use it in copy_to_user_page and copy_from_user_page.
3) flush_anon_page moved to cache.c and updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised comment regarding alias boundary for PA8800/PA8900 processors.
5) Removed struct mm_struct * argument from flush_cache_pages.
6) Fixed thinko in flush_cache_range. It increased the number of pages flushed and slowed performance.
7) Removed sync changes from pacache.S.
V3:
1) copy_to_user_page and copy_from_user_page moved to cache.c to improve inlining.
2) Replaced copy_user_page with copy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings in flush_dcache_page.
5) Return early from mm_total_size if size exceeds parisc_cache_flush_threshold.
6) Disable non-access TLB warning in handle_nadtlb_fault. Warning happens occassionally handling flushes for COW faults.
7) Remove flush_cache_dup_mm.
8) Flush entire cache in flush_cache_mm and flush_cache_range on processors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
9) Tested on rp3440, c8000 and c3750.
---
arch/parisc/include/asm/cacheflush.h +3 -23
@@ -59,19 +59,8 @@ void flush_dcache_page(struct page *page);flush_kernel_icache_range_asm (s,e); \ }while (0 ) -#define copy_to_user_page (vma, page, vaddr, dst, src, len) \ -do { \ - flush_cache_page(vma, vaddr, page_to_pfn(page)); \ - memcpy(dst, src, len); \ - flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len); \ -} while (0) - -#define copy_from_user_page (vma, page, vaddr, dst, src, len) \ -do { \ - flush_cache_page(vma, vaddr, page_to_pfn(page)); \ - memcpy(dst, src, len); \ -} while (0) - +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,unsigned long user_vaddr,void *dst,void *src,int len);void flush_cache_page (struct vm_area_struct *vma,unsigned long vmaddr,unsigned long pfn);void flush_cache_range (struct vm_area_struct *vma,unsigned long start,unsigned long end);
@@ -80,16 +69,7 @@ void flush_cache_range(struct vm_area_struct *vma,void flush_dcache_page_asm (unsigned long phys_addr,unsigned long vaddr);#define ARCH_HAS_FLUSH_ANON_PAGE -static inline void -flush_anon_page (struct vm_area_struct *vma,struct page *page,unsigned long vmaddr) -{ -if (PageAnon (page)) { -flush_tlb_page (vma, vmaddr); -preempt_disable (); -flush_dcache_page_asm (page_to_phys (page), vmaddr); -preempt_enable (); - } -} +void flush_anon_page (struct vm_area_struct *vma,struct page *page,unsigned long vmaddr);#define ARCH_HAS_FLUSH_ON_KUNMAP static inline void kunmap_flush_on_unmap (void *addr)
arch/parisc/include/asm/page.h +3 -2
@@ -26,12 +26,13 @@#define copy_page (to, from) copy_page_asm((void *)(to), (void *)(from))struct page ; +struct vm_area_struct ;void clear_page_asm (void *page);void copy_page_asm (void *to,void *from);#define clear_user_page (vto, vaddr, page) clear_page_asm(vto) -void copy_user_page (void *vto,void *vfrom,unsigned long vaddr, -struct page *pg); +void copy_user_highpage (struct page *to,struct page *from,unsigned long vaddr,struct vm_area_struct *vma); +#define __HAVE_ARCH_COPY_USER_HIGHPAGE/* * These are used to make use of C type-checking..
arch/parisc/kernel/cache.c +209 -101
419 lines not on this page · raw message
arch/parisc/mm/fault.c +5 -1
@@ -22,6 +22,8 @@#include <asm/traps.h> +/* #define DEBUG_NATLB 1 */ +/* Various important other fields */ #define bit22set (x) (x & 0x00000200)#define bits23_25set (x) (x & 0x000001c0)
@@ -450,10 +452,12 @@ handle_nadtlb_fault(struct pt_regs *regs) fallthrough;case 0x380 :/* PDC and FIC instructions */ +#ifdef DEBUG_NATLB if (printk_ratelimit ()) { -pr_warn ("BUG: nullifying cache flush/purge instruction\n" ); +pr_warn ("WARNING: nullifying cache flush/purge instruction\n" );show_regs (regs); } +#endif if (insn &0x20 ) {/* Base modification */ breg = (insn >>21 ) &0x1f ;
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 40 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised comment regarding alias boundary for PA8800/PA8900 processors.
5) Removed structmm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pages flushed and slowed performance.
7) Removed sync changes frompacache.S.
Quoted 15 lines
V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.cto improve inlining.
2) Replacedcopy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceedsparisc_cache_flush_threshold.
6) Disable non-access TLB warning inhandle_nadtlb_fault. Warning happens occassionally handling flushes for COW faults.
7) Removeflush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeon processors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
9) Tested on rp3440, c8000 and c3750.
Given how long these changelogs are, and how fragile the whole caching is I think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.
Helge Deller
maintainerQuoted 57 lines · Rolf Eike Beer
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 40 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised comment regarding alias boundary for PA8800/PA8900 processors.
5) Removed structmm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pages flushed and slowed performance.
7) Removed sync changes frompacache.S.Quoted 15 lines
V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.cto improve inlining.
2) Replacedcopy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceedsparisc_cache_flush_threshold.
6) Disable non-access TLB warning inhandle_nadtlb_fault. Warning happens occassionally handling flushes for COW faults.
7) Removeflush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeon processors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
9) Tested on rp3440, c8000 and c3750.
Quoted 3 lines
Given how long these changelogs are, and how fragile the whole caching is I think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Helge
Quoted 4 lines · Helge Deller
[snip]
Hi Helge,
Quoted 3 lines
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Should I be testing with for-next (which contains this patch) or for-next-next (which has some smaller bits)?
best,
sam
Quoted 1 line
Helge
Quoted 4 lines · Sam James
Quoted 3 lines
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Should I be testing with for-next (which contains this patch) or for-next-next (which has some smaller bits)?
The change in for-next-next shouldn't affect functionality. The patch for-next is the one to test.
Dave
Signature · 1 line
John David Anglin [email protected]
Helge Deller
maintainerQuoted 10 lines · Sam James
Quoted 3 lines · Helge Deller
[snip]
Hi Helge,
Quoted 3 lines
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Should I be testing with for-next (which contains this patch) or for-next-next (which has some smaller bits)?
for-next is for v5.18.
for-next-next is planed to for v5.19
so, please use for-next, since we want to get 5.18 finally fixed.
Thanks!
Helge
Quoted 14 lines · Helge Deller
Quoted 9 lines · Sam James
Quoted 3 lines · Helge Deller
[snip]
Hi Helge,
Quoted 3 lines
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Quoted 8 lines
Quoted 1 line
Should I be testing with for-next (which contains this patch) or for-next-next (which has some smaller bits)?
for-next is for v5.18.
for-next-next is planed to for v5.19
so, please use for-next, since we want to get 5.18 finally fixed.
Got it, thanks to both you and Dave!
I'll be testing it on RP3440 (PA8800) and C8000 (PA8900). If you need it, I can test on C3600 (PA8600) too.
Best,
sam
Quoted 2 lines
Thanks!
Helge
Quoted 1 line · Sam James
I'll be testing it on RP3440 (PA8800) and C8000 (PA8900). If you need it, I can test on C3600 (PA8600) too.
I would test all three. The latest version affects them all.
Watch for random segmentation faults, malloc corruption, etc.
Thanks,
Dave
Signature · 1 line
John David Anglin [email protected]
Am Montag, 16. Mai 2022, 23:49:10 CEST schrieb Helge Deller:
Quoted 70 lines · Rolf Eike Beer
Quoted 69 lines
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 67 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised commentregarding alias boundary for PA8800/PA8900 processors.
5) Removed struct
mm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pagesflushed and slowed performance.
7) Removed sync changes from
pacache.S.V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.ctoimprove inlining.
2) Replaced
copy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceeds
parisc_cache_flush_threshold.6) Disable non-access TLB warning in
handle_nadtlb_fault. Warninghappens occassionally handling flushes for COW faults.
7) Remove
flush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeonprocessors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
9) Tested on rp3440, c8000 and c3750.
Quoted 7 lines
Quoted 4 lines
Given how long these changelogs are, and how fragile the whole caching is I
think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Why did you modify get_ptep()? Until now it was just moved around in the file, and IMHO it becomes less readable because all these needless variables are batched up at the start of the function now. The only point I would see in moving them all to the front is if there would be no nesting anymore, and every condition was inverted:
if (pgd_none(*pgd))
return NULL;
[…]
return pte_offset_map(pmd, addr);
Bit this would as well be a different commit.
Helge Deller
maintainerQuoted 76 lines · Rolf Eike Beer
Am Montag, 16. Mai 2022, 23:49:10 CEST schrieb Helge Deller:
Quoted 75 lines · Rolf Eike Beer
Quoted 73 lines
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 60 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised commentregarding alias boundary for PA8800/PA8900 processors.
5) Removed struct
mm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pagesflushed and slowed performance.
7) Removed sync changes from
pacache.S.V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.ctoimprove inlining.
2) Replaced
copy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceeds
parisc_cache_flush_threshold.6) Disable non-access TLB warning in
handle_nadtlb_fault. Warninghappens occassionally handling flushes for COW faults.
Quoted 7 lines
7) Remove
flush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeonprocessors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
9) Tested on rp3440, c8000 and c3750.
Given how long these changelogs are, and how fragile the whole caching is I
think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.
Quoted 8 lines
Quoted 2 lines
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Why did you modify
get_ptep()? Until now it was just moved around in the file, and IMHO it becomes less readable because all these needless variables are batched up at the start of the function now. The only point I would see in moving them all to the front is if there would be no nesting anymore, and every condition was inverted:
Dave's original patch did not moved the variables to the beginning. That change was me - just because checkpatch complained otherwise.
I agree that it's less readable.
Helge
Quoted 82 lines · Helge Deller
Quoted 74 lines · Rolf Eike Beer
Am Montag, 16. Mai 2022, 23:49:10 CEST schrieb Helge Deller:
Quoted 73 lines · Rolf Eike Beer
Quoted 72 lines
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 60 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised commentregarding alias boundary for PA8800/PA8900 processors.
5) Removed struct
mm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pagesflushed and slowed performance.
7) Removed sync changes from
pacache.S.V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.ctoimprove inlining.
2) Replaced
copy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceeds
parisc_cache_flush_threshold.6) Disable non-access TLB warning in
handle_nadtlb_fault. Warninghappens occassionally handling flushes for COW faults.
Quoted 7 lines
7) Remove
flush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeonprocessors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
9) Tested on rp3440, c8000 and c3750.
Given how long these changelogs are, and how fragile the whole caching is I
think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.Quoted 7 lines
Quoted 2 lines
FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Why did you modify
get_ptep()? Until now it was just moved around in the file, and IMHO it becomes less readable because all these needless variables are batched up at the start of the function now. The only point I would see in moving them all to the front is if there would be no nesting anymore, and every condition was inverted:
Quoted 4 lines
Dave's original patch did not moved the variables to the beginning. That change was me - just because checkpatch complained otherwise.
I agree that it's less readable.
The get_ptep code was originally based on the vmalloc_to_page code in vmalloc.c. vmalloc_to_page code. This code has now changed, so I think get_ptep needs updating. See get_old_pud in mremap.c. It looks good to me.
Dave
Signature · 1 line
John David Anglin [email protected]
Helge Deller
maintainerQuoted 83 lines · John David Anglin
Quoted 82 lines · Helge Deller
Quoted 81 lines · Rolf Eike Beer
Am Montag, 16. Mai 2022, 23:49:10 CEST schrieb Helge Deller:
Quoted 68 lines · Rolf Eike Beer
Quoted 67 lines
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 66 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised commentregarding alias boundary for PA8800/PA8900 processors.
5) Removed struct
mm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pagesflushed and slowed performance.
7) Removed sync changes from
pacache.S.V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.ctoimprove inlining.
2) Replaced
copy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceeds
parisc_cache_flush_threshold.6) Disable non-access TLB warning in
handle_nadtlb_fault. Warninghappens occassionally handling flushes for COW faults.
7) Remove
flush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeonprocessors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
9) Tested on rp3440, c8000 and c3750.
Given how long these changelogs are, and how fragile the whole caching is I
think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Why did you modify
get_ptep()? Until now it was just moved around in the file, and IMHO it becomes less readable because all these needless variables are batched up at the start of the function now. The only point I would see in moving them all to the front is if there would be no nesting anymore, and every condition was inverted:
Quoted 7 lines
Quoted 4 lines
Dave's original patch did not moved the variables to the beginning. That change was me - just because checkpatch complained otherwise.
I agree that it's less readable.
The
get_ptepcode was originally based on thevmalloc_to_pagecode invmalloc.c.vmalloc_to_pagecode. This code has now changed, so I thinkget_ptepneeds updating. Seeget_old_pudin mremap.c. It looks good to me.
So, what's the consense of this discussion now?
I can easily split out the pr_warn("WARNING").
Moving the get_ptep() back to the original place seems ok, and I'll keep the strange indenting which checkpatch want.
Is that ok?
Helge
Am Dienstag, 17. Mai 2022, 20:11:38 CEST schrieb Helge Deller:
Quoted 1 line
I can easily split out the
pr_warn("WARNING").
Would make sense IMHO.
Quoted 2 lines
Moving the
get_ptep()back to the original place seems ok, and I'll keep the strange indenting which checkpatch want.
If its back at the original place then there is no need to change as checkpatch will not complain on unmodified lines. If it needs to be moved and changed then I would say do it in it's own patch as well.
Eike
Quoted 5 lines · Rolf Eike Beer
Quoted 2 lines
Moving the
get_ptep()back to the original place seems ok, and I'll keep the strange indenting which checkpatch want.If its back at the original place then there is no need to change as checkpatch will not complain on unmodified lines. If it needs to be moved and changed then I would say do it in it's own patch as well.
I moved it forward because there are new references. Otherwise, a static declaration is needed.
I wanted the "copy" routines together.
Dave
Signature · 1 line
John David Anglin [email protected]
Helge Deller
maintainerQuoted 5 lines · Rolf Eike Beer
Am Dienstag, 17. Mai 2022, 20:11:38 CEST schrieb Helge Deller:
Quoted 1 line
I can easily split out the
pr_warn("WARNING").Would make sense IMHO.
I split that patch out now.
Dave, can you please check if you are ok with it?
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/commit/?h=for-next&id=67c35a3b646cc68598ff0bb28de5f8bd7b2e81b3
I used the wording from your other mail.
Quoted 5 lines
Quoted 2 lines
Moving the
get_ptep()back to the original place seems ok, and I'll keep the strange indenting which checkpatch want.If its back at the original place then there is no need to change as checkpatch will not complain on unmodified lines.
I meant "back to the place where it was versions before". So, it has to move anyway now.
Quoted 2 lines
If it needs to be moved and
changed then I would say do it in it's own patch as well.
I kept it in the way Dave sent it (with the checkpatch fixups I added).
Just pushed a new "for-next" tree at the usual place:
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/log/?h=for-next
Helge
Quoted 9 lines · Helge Deller
Quoted 4 lines · Rolf Eike Beer
Am Dienstag, 17. Mai 2022, 20:11:38 CEST schrieb Helge Deller:
Quoted 1 line
I can easily split out the
pr_warn("WARNING").Would make sense IMHO.
I split that patch out now.
Dave, can you please check if you are ok with it?
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/commit/?h=for-next&id=67c35a3b646cc68598ff0bb28de5f8bd7b2e81b3
I used the wording from your other mail.
Looks better than what I sent!
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Moving the
get_ptep()back to the original place seems ok, and I'll keep the strange indenting which checkpatch want.If its back at the original place then there is no need to change as checkpatch will not complain on unmodified lines.
I meant "back to the place where it was versions before". So, it has to move anyway now.
Quoted 6 lines
Quoted 2 lines
If it needs to be moved and
changed then I would say do it in it's own patch as well.I kept it in the way Dave sent it (with the checkpatch fixups I added).
Just pushed a new "for-next" tree at the usual place:
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/log/?h=for-next
Will test.
Dave
Signature · 1 line
John David Anglin [email protected]
Quoted 91 lines · Helge Deller
Quoted 83 lines · John David Anglin
Quoted 82 lines · Helge Deller
Quoted 81 lines · Rolf Eike Beer
Am Montag, 16. Mai 2022, 23:49:10 CEST schrieb Helge Deller:
Quoted 68 lines · Rolf Eike Beer
Quoted 67 lines
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 66 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.V2:
1) Addflush_cache_page_check_pteroutine.
2) Use it incopy_to_user_pageandcopy_from_user_page.
3)flush_anon_pagemoved tocache.cand updated.
4) Changed alias boundary to 64 MB for 64-bit kernels. Revised commentregarding alias boundary for PA8800/PA8900 processors.
5) Removed struct
mm_struct* argument fromflush_cache_pages.
6) Fixed thinko inflush_cache_range. It increased the number of pagesflushed and slowed performance.
7) Removed sync changes from
pacache.S.V3:
1)copy_to_user_pageandcopy_from_user_pagemoved tocache.ctoimprove inlining.
2) Replaced
copy_user_pagewithcopy_user_highpage.
3) Fixed cache threshold calculation on 32-bit kernels.
4) Don't warn on inequivalent private mappings inflush_dcache_page.
5) Return early frommm_total_sizeif size exceeds
parisc_cache_flush_threshold.6) Disable non-access TLB warning in
handle_nadtlb_fault. Warninghappens occassionally handling flushes for COW faults.
7) Remove
flush_cache_dup_mm.
8) Flush entire cache inflush_cache_mmandflush_cache_rangeonprocessors with aliasing caches. Only flush small cache ranges on machines with PA8800/PA8900 processors.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
9) Tested on rp3440, c8000 and c3750.
Given how long these changelogs are, and how fragile the whole caching is I
think it is a good idea to split this patch into smaller ones, to improve readability and being able to bisect it.FWIW, I've done some cleanups to this patch and committed it to my for-next tree. In case it's split up, please use the revised version.
Why did you modify
get_ptep()? Until now it was just moved around in the file, and IMHO it becomes less readable because all these needless variables are batched up at the start of the function now. The only point I would see in moving them all to the front is if there would be no nesting anymore, and every condition was inverted:Quoted 7 lines
Quoted 4 lines
Dave's original patch did not moved the variables to the beginning. That change was me - just because checkpatch complained otherwise.
I agree that it's less readable.
The
get_ptepcode was originally based on thevmalloc_to_pagecode invmalloc.c.vmalloc_to_pagecode. This code has now changed, so I thinkget_ptepneeds updating. Seeget_old_pudin mremap.c. It looks good to me.
Quoted 6 lines
So, what's the consense of this discussion now?
I can easily split out the
pr_warn("WARNING").
Moving theget_ptep()back to the original place seems ok, and I'll keep the strange indenting which checkpatch want.
Is that ok?
It's okay with me. But maybe we need to add pgd_leaf and pgd_bad checks (etc). That's what is concerning me.
Dave
Signature · 1 line
John David Anglin [email protected]
Am Montag, 16. Mai 2022, 17:14:47 CEST schrieb John David Anglin:
Quoted 43 lines
Originally, I was convinced that we needed to use tmpalias flushes everwhere, for both user and kernel flushes. However, when I modified
flush_kernel_dcache_page_addr, to use a tmpalias flush, my c8000 would crash quite early when booting.The PDC returns alias values of 0 for the icache and dcache. This indicates that either the alias boundary is greater than 16MB or equivalent aliasing doesn't work. I modified the tmpalias code to make it easy to try alternate boundaries. I tried boundaries up to 128MB but still kernel tmpalias flushes didn't work on c8000.
This led me to conclude that tmpalias flushes don't work on PA8800 and PA8900 machines, and that we needed to flush directly using the virtual address of user and kernel pages. This is likely the major cause of instability on the c8000 and rp34xx machines.
Flushing user pages requires doing a temporary context switch as we have to flush pages that don't belong to the current context. Further, we have to deal with pages that aren't present. If a page isn't present, the flush instructions fault on every line.
Other code has been rearranged and simplified based on testing. For example, I introduced a
flush_cache_dup_mmroutine.flush_cache_mmandflush_cache_dup_mmdiffer in thatflush_cache_mmcallspurge_cache_pagesandflush_cache_dup_mmcallsflush_cache_pages. In some implementations, pdc is more efficient than fdc. Based on my testing, I don't believe there's any performance benefit on the c8000.arch/parisc/mm/fault.c +2
-0@@ -22,6 +22,8 @@#include <asm/traps.h> +/* #define DEBUG_NATLB 1 */ +/* Various important other fields */ #define bit22set (x) (x & 0x00000200)#define bits23_25set (x) (x & 0x000001c0)
arch/parisc/mm/fault.c handle_nadtlb_fault(struct pt_regs *regs) · line 454
Quoted 6 lines
arch/parisc/mm/fault.c +1
-1@@ -450,10 +452,12 @@ handle_nadtlb_fault(struct pt_regs *regs) fallthrough;case 0x380 :/* PDC and FIC instructions */ +#ifdef DEBUG_NATLB if (printk_ratelimit ()) { - pr_warn("BUG: nullifying cache flush/purge
instruction\n");
arch/parisc/mm/fault.c handle_nadtlb_fault(struct pt_regs *regs) · line 457
Quoted 1 line
arch/parisc/mm/fault.c +1
-0+ pr_warn("WARNING: nullifying cache flush/
purge instruction\n");
arch/parisc/mm/fault.c handle_nadtlb_fault(struct pt_regs *regs) · line 463
Quoted 6 lines
arch/parisc/mm/fault.c +1
-0show_regs(regs); } +#endif if (insn &0x20 ) {/* Base modification */ breg = (insn >>21 ) &0x1f ;
This surely deserves it's own commit as it has nothing to do with the actual change. I wonder if it is actually intended to go upstream or if this was just a local debug hack?
Eike
Quoted 16 lines · Rolf Eike Beer
arch/parisc/mm/fault.c handle_nadtlb_fault(struct pt_regs *regs) · line 454
Quoted 7 lines
arch/parisc/mm/fault.c +1
-1@@ -450,10 +452,12 @@ handle_nadtlb_fault(struct pt_regs *regs) fallthrough;case 0x380 :/* PDC and FIC instructions */ +#ifdef DEBUG_NATLB if (printk_ratelimit ()) { - pr_warn("BUG: nullifying cache flush/purgeinstruction\n");
Review handle_nadtlb_fault(struct pt_regs *regs) · line 457
Quoted 1 line
(quoted diff) +1
-0+ pr_warn("WARNING: nullifying cache flush/purge instruction\n");
arch/parisc/mm/fault.c handle_nadtlb_fault(struct pt_regs *regs) · line 463
Quoted 6 lines
arch/parisc/mm/fault.c +1
-0show_regs(regs); } +#endif if (insn &0x20 ) {/* Base modification */ breg = (insn >>21 ) &0x1f ;
Quoted 3 lines
This surely deserves it's own commit as it has nothing to do with the actual change. I wonder if it is actually intended to go upstream or if this was just a local debug hack?
I changed "BUG" to "WARNING" and disabled the message because it triggers occasionally in spite of the check in flush_cache_page_if_present.
The pte value extracted for the "from" page in copy_user_highpage is racy and occasionally the pte is cleared before the flush is complete. I assume that the page is simultaneously flushed by flush_cache_mm before the pte is cleared as nullifying the fdc doesn't seem to cause problems.
I investigated various locking scenarios but I wasn't able to find a way to sequence the flushes. This code is called for every COW break and locks impact performance.
This is related to this patch because we need the pte on PA8800/PA8900 to flush using the vma context.
I have also seen this from copy_to_user_page and copy_from_user_page.
The messages appear infrequently when enabled.
Dave
Signature · 1 line
John David Anglin [email protected]