linux-2.6 jejb
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 23 lines · James Bottomley
CVSROOT:
/var/cvs
Module name: linux-2.6
Changes by: jejb 04/04/04 20:47:40Modified files:
. :Makefile
arch/parisc/kernel:cache.cpacache.S
include/asm-parisc:cache.hcacheflush.hLog message:
Fix non current user process flushing.We have two problems:
- There's a bug in
__flush_dcache_page()that causes it to do nothing if the current process doesn't contain the page. This is incorrect since it will leave the congruent user pages incoherent with the kernel page.-
flush_cache_page()flushes everything if the mm of the requested vma isn't current (this is correct, but cumbersome and is what gives us the abysmally slow ptrace performance).
Quoted 5 lines
We can fix both of these by introducing a new API:
flush_user_cache_page_non_current()Specifically designed to flush a page in a non-current process.
===== arch/parisc/kernel/cache.c 1.7 vs edited =====
arch/parisc/kernel/cache.c +180 -1
@@ -71,9 +71,9 @@if (VALID_PAGE (page) && page->mapping &&test_bit (PG_dcache_dirty, &page->flags)) { -flush_kernel_dcache_page (page_address (page));clear_bit (PG_dcache_dirty, &page->flags); } +flush_kernel_dcache_page (page_address (page)); }void
@@ -293,6 +293,185 @@ } }EXPORT_SYMBOL (__flush_dcache_page); + +/* set to max pages to flush before a full flush. Zero means no limit */ +#define MAX_FLUSH_PAGES 0 +#undef DEBUG_PAGE_FLUSHING + +#ifdef DEBUG_PAGE_FLUSHING +#define DBG(a...) printk(a) +#else +#define DBG (...) +#endif + +#if (MAX_FLUSH_PAGES !=0 ) + +/* we get to use the bottom 12 bits of the addr for flags since the +* address must be page aligned */ +#define ICACHE_FLUSH_FLAG 0x1 + +void flush_cache_mm (struct mm_struct *mm) +{ +struct vm_area_struct *vma; +unsigned long count =0 , actual_count =0 ; +unsigned long sr3 =mfsp (3 ), cr25 =mfctl (25 ); +unsigned long *pages; + +preempt_disable (); +if (mm != current->active_mm) { +DBG ("flush_tlb_mm: current MM is not active " ); +/* FIXME: awful hack: move the process the mm belongs +* to temporarily to being the active one. This only +* works because we can never get back into user +* context from here. */ +mtctl (__pa (mm->pgd),25 ); +mtsp (mm->context,3 ); + } + + pages =kmalloc (MAX_FLUSH_PAGES *sizeof (unsigned long ),GFP_ATOMIC ); +if (!pages) { +printk (KERN_ERR "flush_tlb_mm: allocation failed: full flush\n" ); + goto full_flush; + } + +for (vma = mm->mmap; vma !=NULL ; vma = vma->vm_next) { +unsigned long start; + +pmd_t *pmd; +pgd_t *pgd; +pte_t *pte; + + count += (vma->vm_end - vma->vm_start)/PAGE_SIZE ; + +for (start = vma->vm_start; start < vma->vm_end; + start +=PAGE_SIZE ) { + pgd =pgd_offset (mm, start); + +if (pgd_none (*pgd)) { + start = (start &PGDIR_MASK ) +PGDIR_SIZE -PAGE_SIZE ; +continue ; + } + + pmd =pmd_offset (pgd, start); +if (pmd_none (*pmd)) { + start = (start &PMD_MASK ) +PMD_SIZE -PAGE_SIZE ; +continue ; + } + pte =pte_offset_map (pmd, start); +if (pte_val (*pte)==0 || !pte_present (*pte)) +continue ; + +/* FIXME: Here we could also skip over any +* shared mapping page (i.e. equivalently +* aliased) with at least one other user */ + + pages[actual_count] = start; + +if (vma->vm_flags &&VM_EXEC ) + pages[actual_count] |=ICACHE_FLUSH_FLAG ; +if (++actual_count >=MAX_FLUSH_PAGES ) + goto full_flush_free; + + } + } + +DBG ("FLUSHED %lu (actual %lu)\n" , count, actual_count); +for (count =0 ; count < actual_count; count++) { +unsigned long addr = pages[count] &PAGE_MASK ; +flush_user_dcache_page (addr); +if (pages[count] &ICACHE_FLUSH_FLAG ) +flush_user_icache_page (addr); + } + out_free: +kfree (pages); + out: +mtsp (sr3,3 ); +mtctl (cr25,25 ); +preempt_enable (); +return ; + + full_flush_free: +DBG ("flush_cache_mm: over max pages %ld (count %ld), flushing everything\n" , actual_count, count); +flush_cache_all (); + goto out_free; + + full_flush: +flush_cache_all (); + goto out; +} + +#else + +void flush_cache_mm (struct mm_struct *mm) +{ +struct vm_area_struct *vma; +unsigned long count =0 , actual_count =0 ; +unsigned long sr3 =mfsp (3 ), cr25 =mfctl (25 ); +static int flushed =0 ; + +if (unlikely (!flushed)) { +printk ("flush_cache_mm: INIT FLUSH ALL\n" ); + flushed =1 ; +flush_cache_all (); +return ; + } + +preempt_disable (); +if (mm != current->active_mm) { +DBG ("flush_tlb_mm: current MM is not active " ); +/* FIXME: awful hack: move the process the mm belongs +* to temporarily to being the active one. This only +* works because we can never get back into user +* context from here. */ +mtctl (__pa (mm->pgd),25 ); +mtsp (mm->context,3 ); + } + +for (vma = mm->mmap; vma !=NULL ; vma = vma->vm_next) { +unsigned long start; + +pmd_t *pmd; +pgd_t *pgd; +pte_t *pte; + + count += (vma->vm_end - vma->vm_start)/PAGE_SIZE ; + +for (start = vma->vm_start; start < vma->vm_end; + start +=PAGE_SIZE ) { + pgd =pgd_offset (mm, start); + +if (pgd_none (*pgd)) { + start = (start &PGDIR_MASK ) +PGDIR_SIZE -PAGE_SIZE ; +continue ; + } + + pmd =pmd_offset (pgd, start); +if (pmd_none (*pmd)) { + start = (start &PMD_MASK ) +PMD_SIZE -PAGE_SIZE ; +continue ; + } + pte =pte_offset_map (pmd, start); +if (pte_val (*pte)==0 || !pte_present (*pte)) +continue ; + +/* FIXME: Here we could also skip over any +* shared mapping page (i.e. equivalently +* aliased) with at least one other user */ + +flush_user_dcache_page (start); +if (vma->vm_flags &&VM_EXEC ) +flush_user_icache_page (start); + actual_count++; + } + } +mtsp (sr3,3 ); +mtctl (cr25,25 ); +preempt_enable (); +DBG ("FLUSHED %lu (actual %lu)\n" , count, actual_count); +} +#endif + +EXPORT_SYMBOL (flush_cache_mm);/* Defined in arch/parisc/kernel/pacache.S */ EXPORT_SYMBOL (flush_kernel_dcache_range_asm);
===== arch/parisc/kernel/pacache.S 1.4 vs edited =====
arch/parisc/kernel/pacache.S +89 -0
95 lines not on this page · raw message
===== include/asm-parisc/cacheflush.h 1.6 vs edited =====
include/asm-parisc/cacheflush.h +1 -1
@@ -12,7 +12,7 @@#ifdef CONFIG_SMP #define flush_cache_mm (mm) flush_cache_all()#else -#define flush_cache_mm (mm) flush_cache_all_local() +extern void flush_cache_mm (struct mm_struct *);#endif #define flush_kernel_dcache_range (start,size) \
===== include/asm-parisc/page.h 1.5 vs edited =====
include/asm-parisc/page.h +2 -0
@@ -20,6 +20,8 @@extern void purge_kernel_dcache_page (unsigned long );extern void copy_user_page_asm (void *to,void *from);extern void clear_user_page_asm (void *page,unsigned long vaddr); +extern void flush_user_dcache_page (unsigned long ); +extern void flush_user_icache_page (unsigned long );static inline void copy_user_page (void *vto,void *vfrom,unsigned long vaddr,struct page *pg)
And now with the correct patch attached.
James
===== arch/parisc/kernel/cache.c 1.7 vs edited =====
arch/parisc/kernel/cache.c +12 -3
@@ -231,6 +231,7 @@ {struct mm_struct *mm = current->active_mm;struct list_head *l; +struct vm_area_struct *anyvma =NULL ;flush_kernel_dcache_page (page_address (page));
@@ -242,7 +243,7 @@struct vm_area_struct *mpnt;unsigned long off; - mpnt = list_entry(l, struct vm_area_struct, shared); + anyvma = mpnt = list_entry(l, struct vm_area_struct, shared);/* * If this VMA is not in our MM, we can ignore it.
@@ -271,7 +272,7 @@struct vm_area_struct *mpnt;unsigned long off; - mpnt = list_entry(l, struct vm_area_struct, shared); + anyvma = mpnt = list_entry(l, struct vm_area_struct, shared);if (mpnt->vm_mm != mm || !(mpnt->vm_flags &VM_MAYSHARE ))
@@ -289,7 +290,15 @@/* All user shared mappings should be equivalently mapped, * so once we've flushed one we should be ok */ -break ; +return ; + } +/* This is the problem case. We failed to find the page to be +* flushed in the current vma thus we have to flush it in some +* other user process */ +if (likely (anyvma)) { +unsigned long addr = anyvma->vm_start + + ((page->index - anyvma->vm_pgoff) <<PAGE_SHIFT ); +flush_user_cache_page_non_current (anyvma, addr); } }EXPORT_SYMBOL (__flush_dcache_page);
===== arch/parisc/kernel/pacache.S 1.4 vs edited =====
arch/parisc/kernel/pacache.S +89 -0
95 lines not on this page · raw message
===== include/asm-parisc/cache.h 1.5 vs edited =====
include/asm-parisc/cache.h +2 -0
@@ -52,6 +52,8 @@extern void disable_sr_hashing_asm (int );/* low level support for above */ extern void free_sid (unsigned long );unsigned long alloc_sid (void ); +extern void flush_user_dcache_page (unsigned long ); +extern void flush_user_icache_page (unsigned long );struct seq_file ;extern void show_cache_info (struct seq_file *m);
===== include/asm-parisc/cacheflush.h 1.6 vs edited =====
include/asm-parisc/cacheflush.h +38 -14
64 lines not on this page · raw message