Linux PARISC architecture development
 help / color / mirror / Atom feed
* [parisc-linux] Re: RFC: mmap patch
@ 2003-03-06 14:14 John Marvin
  2003-03-06 14:31 ` Matthew Wilcox
  2003-03-08  6:30 ` Grant Grundler
  0 siblings, 2 replies; 27+ messages in thread
From: John Marvin @ 2003-03-06 14:14 UTC (permalink / raw)
  To: parisc-linux; +Cc: davem

>
> Looking for some vm gurus to verify that this is correct. This fixes a
> problem where the kernel-view of a page vs the user-view can get out of
> sync because of the virtually tagged cache of PA. This fixes a bug
> reported some time back where write(2)s to a mmaped fd doesn't get
> updated properly in the mmap'ed region.
>
> Many thanks to willy for his advice in putting this together :)
>
> This is tested on 2.5.64-pa1 on a500, but should also apply to 2.4.
>
> Any comments before I apply?
>

In my opinion this patch is a hack workaround for a real bug. parisc is
not the only architecture that has virtual tagged caches.  Some mips
machines, sparc and ultrasparc machines have virtual tagged caches,
although none of them have virtual tagged caches as large as parisc (the
other architectures typically have a larger physical cache at a higher
level in the cache hierarchy).

Dave Miller designed the cache flushing strategy to have hooks in the
machine independent code to support virtual tagged caches.  Probably there
is simply a cache flush that is missing that doesn't show itself as a bug
as easily on the smaller virtually tagged caches of the other
architectures. At most this particular scenario wasn't considered
for virtual tagged caches (maintaining coherence between fd writes and
mmap'ed regions) and will require a design change to fix.

The fix for this bug should be made in machine independent code, not in
our machine dependent code.

John Marvin
jsm@fc.hp.com

P.S. I am cc'ing Dave Miller to see if he cares to comment.

> Index: include/asm-parisc/cacheflush.h
> ===================================================================
> RCS file: /var/cvs/linux-2.5/include/asm-parisc/cacheflush.h,v
> retrieving revision 1.5
> diff -u -p -r1.5 cacheflush.h
> --- include/asm-parisc/cacheflush.h     6 Mar 2003 04:20:45 -0000       1.5
> +++ include/asm-parisc/cacheflush.h     6 Mar 2003 06:35:41 -0000
> @@ -67,13 +67,15 @@ flush_user_icache_range(unsigned long st
>  #endif
>  }
>
> +extern void __flush_dcache_page(struct page *page);
> +
>  static inline void flush_dcache_page(struct page *page)
>  {
>         if (page->mapping && list_empty(&page->mapping->i_mmap) &&
>                         list_empty(&page->mapping->i_mmap_shared)) {
>                 set_bit(PG_dcache_dirty, &page->flags);
>         } else {
> -               flush_kernel_dcache_page(page_address(page));
> +               __flush_dcache_page(page);
>         }
>  }
>
> Index: arch/parisc/kernel/cache.c
> ===================================================================
> RCS file: /var/cvs/linux-2.5/arch/parisc/kernel/cache.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 cache.c
> --- arch/parisc/kernel/cache.c  5 Mar 2003 21:15:37 -0000       1.9
> +++ arch/parisc/kernel/cache.c  6 Mar 2003 06:35:41 -0000
> @@ -222,3 +222,42 @@ void disable_sr_hashing(void)
>
>         disable_sr_hashing_asm(srhash_type);
>  }
> +
> +void __flush_dcache_page(struct page *page)
> +{
> +       struct mm_struct *mm = current->active_mm;
> +       struct list_head *l;
> +
> +       flush_kernel_dcache_page(page_address(page));
> +
> +       if (!page->mapping)
> +               return;
> +
> +       list_for_each(l, &page->mapping->i_mmap_shared) {
> +               struct vm_area_struct *mpnt;
> +               unsigned long off;
> +
> +               mpnt = list_entry(l, struct vm_area_struct, shared);
> +
> +               /*
> +                * If this VMA is not in our MM, we can ignore it.
> +                */
> +               if (mpnt->vm_mm != mm)
> +                       continue;
> +
> +               if (page->index < mpnt->vm_pgoff)
> +                       continue;
> +
> +               off = page->index - mpnt->vm_pgoff;
> +               if (off >= (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT)
> +                       continue;
> +
> +               flush_cache_page(mpnt, mpnt->vm_start + (off << PAGE_SHIFT));
> +
> +               /* All user shared mappings should be equivalently mapped,
> +                * so once we've flushed one we should be ok
> +                */
> +               break;
> +       }
> +}
> +
>

^ permalink raw reply	[flat|nested] 27+ messages in thread
* [parisc-linux] Re: RFC: mmap patch
@ 2003-03-09  3:42 John Marvin
  2003-03-09 21:29 ` David S. Miller
  0 siblings, 1 reply; 27+ messages in thread
From: John Marvin @ 2003-03-09  3:42 UTC (permalink / raw)
  To: parisc-linux; +Cc: davem

>
> Yes, the {copy,clear}_user_page() thing is an optimization for
> handling of cache alias issues wrt. anonymous pages.
>
I already implemented that solution on the parisc port. Well actually
only half :-). I implemented both the copy and clear user page optimizations,
but later on disabled the copy_user_page solution. I can't remember the
exact details of the problem. Based on a comment I wrote, it seems that in
some cases copy_user_page was being used for something that was going to
be executed. I can't remember the exact scenario, since copy_user_page
is only called in copy-on-write situations.

The problem is that since we have split I and D caches, the cache would
need to be flushed anyway so that the instructions could be seen for
execution.  So it didn't make any sense to set up the temporary
translation and then flush it anyway; better to just do it through the
kernel translation and flush.  I believe this isn't a problem on sparc64
because of the write-through cache.

> The PA-RISC mmap/write bug is something entirely different,
> flush_dcache_page() just isn't doing what it is defined to
> do :-)

Ok.  But looking at the sparc64 implementation of flush_dcache_page I
don't see any code to traverse user vma's.  Is there some other
architecture specific trick that is being used to flush any user mappings
that are mapped to the same physical address as the kernel address?

John Marvin
jsm@fc.hp.com

^ permalink raw reply	[flat|nested] 27+ messages in thread
* [parisc-linux] Re: RFC: mmap patch
@ 2003-03-09  3:51 John Marvin
  2003-03-09 21:31 ` David S. Miller
  0 siblings, 1 reply; 27+ messages in thread
From: John Marvin @ 2003-03-09  3:51 UTC (permalink / raw)
  To: parisc-linux; +Cc: davem

On Sat, Mar 08, 2003 at 03:00:23PM -0800, David S. Miller wrote:
> ...
> Since about Nov 2002 we have been working on better {copy,clear}_user_page()
> implementations quietly inside HP.  Unfortunately some, uhm, "issues" are
> taking a long time to resolve before the routines can be published.
> Once those issues are resolved, I think your trick with temporary
> TLB entries can get implemented.
>
The tlb trick for clear_user_page is already implemented. The code for
copy_user_page is there, but turned off due to an issue mentioned in my
last email. I believe the failure case was not a frequent path, and there
are ways of working around that problem.

The address that the copying is done through (e,g. the tlb trick) is
independent of the algorithm used to actually do the copying.

John

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2003-03-14 16:23 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-06 14:14 [parisc-linux] Re: RFC: mmap patch John Marvin
2003-03-06 14:31 ` Matthew Wilcox
2003-03-06 15:31   ` Randolph Chung
2003-03-08  6:30 ` Grant Grundler
2003-03-08  6:29   ` David S. Miller
2003-03-08 17:24     ` Grant Grundler
2003-03-08 19:04       ` David S. Miller
2003-03-08 20:42         ` Grant Grundler
2003-03-08 22:45         ` Matthew Wilcox
2003-03-08 23:00           ` David S. Miller
2003-03-08 23:27             ` Matthew Wilcox
2003-03-08 23:14               ` David S. Miller
2003-03-08 23:31             ` Randolph Chung
2003-03-08 23:15               ` David S. Miller
2003-03-09  2:15             ` Grant Grundler
2003-03-08 23:11     ` Matthew Wilcox
2003-03-08 23:02       ` David S. Miller
2003-03-09 14:42         ` Matthew Wilcox
2003-03-09 21:38           ` David S. Miller
2003-03-10  1:50             ` Matthew Wilcox
2003-03-10  5:18               ` David S. Miller
2003-03-14 13:04           ` Jochen Friedrich
2003-03-14 16:23             ` Grant Grundler
  -- strict thread matches above, loose matches on Subject: below --
2003-03-09  3:42 John Marvin
2003-03-09 21:29 ` David S. Miller
2003-03-09  3:51 John Marvin
2003-03-09 21:31 ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox