]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Rework ptep_set_access_flags and fix sun4c
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Sat, 16 Jun 2007 17:16:12 +0000 (10:16 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Sat, 16 Jun 2007 20:16:16 +0000 (13:16 -0700)
Some changes done a while ago to avoid pounding on ptep_set_access_flags and
update_mmu_cache in some race situations break sun4c which requires
update_mmu_cache() to always be called on minor faults.

This patch reworks ptep_set_access_flags() semantics, implementations and
callers so that it's now responsible for returning whether an update is
necessary or not (basically whether the PTE actually changed).  This allow
fixing the sparc implementation to always return 1 on sun4c.

[akpm@linux-foundation.org: fixes, cleanups]
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: David Miller <davem@davemloft.net>
Cc: Mark Fortescue <mark@mtfhpc.demon.co.uk>
Acked-by: William Lee Irwin III <wli@holomorphy.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/asm-generic/pgtable.h
include/asm-i386/pgtable.h
include/asm-ia64/pgtable.h
include/asm-powerpc/pgtable-ppc32.h
include/asm-powerpc/pgtable-ppc64.h
include/asm-ppc/pgtable.h
include/asm-s390/pgtable.h
include/asm-sparc/pgtable.h
include/asm-x86_64/pgtable.h
mm/hugetlb.c
mm/memory.c

index dc8f99ee305fc4edd43232abdc0e5564b2c15434..7d7bcf990e9917abf9ab98208417a6d5ef59d017 100644 (file)
@@ -27,13 +27,20 @@ do {                                                                        \
  * Largely same as above, but only sets the access flags (dirty,
  * accessed, and writable). Furthermore, we know it always gets set
  * to a "more permissive" setting, which allows most architectures
- * to optimize this.
+ * to optimize this. We return whether the PTE actually changed, which
+ * in turn instructs the caller to do things like update__mmu_cache.
+ * This used to be done in the caller, but sparc needs minor faults to
+ * force that call on sun4c so we changed this macro slightly
  */
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-do {                                                                     \
-       set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry);         \
-       flush_tlb_page(__vma, __address);                                 \
-} while (0)
+({                                                                       \
+       int __changed = !pte_same(*(__ptep), __entry);                    \
+       if (__changed) {                                                  \
+               set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
+               flush_tlb_page(__vma, __address);                         \
+       }                                                                 \
+       __changed;                                                        \
+})
 #endif
 
 #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
index d62bdb029efa3d5cc6ad562a24b6f0710ab2409e..628fa7747d0cce02dfd866c181c31dbd413c952c 100644 (file)
@@ -285,13 +285,15 @@ static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
  */
 #define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 #define ptep_set_access_flags(vma, address, ptep, entry, dirty)                \
-do {                                                                   \
-       if (dirty) {                                                    \
+({                                                                     \
+       int __changed = !pte_same(*(ptep), entry);                      \
+       if (__changed && dirty) {                                       \
                (ptep)->pte_low = (entry).pte_low;                      \
                pte_update_defer((vma)->vm_mm, (address), (ptep));      \
                flush_tlb_page(vma, address);                           \
        }                                                               \
-} while (0)
+       __changed;                                                      \
+})
 
 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
 #define ptep_test_and_clear_dirty(vma, addr, ptep) ({                  \
index 670b706411b88c01c5a1785e467f387510ecfe2a..6580f31b31352c414fa55f6e5ddadcf287a9e9e3 100644 (file)
@@ -533,16 +533,23 @@ extern void lazy_mmu_prot_update (pte_t pte);
  * daccess_bit in ivt.S).
  */
 #ifdef CONFIG_SMP
-# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable)      \
-do {                                                                                   \
-       if (__safely_writable) {                                                        \
-               set_pte(__ptep, __entry);                                               \
-               flush_tlb_page(__vma, __addr);                                          \
-       }                                                                               \
-} while (0)
+# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable) \
+({                                                                     \
+       int __changed = !pte_same(*(__ptep), __entry);                  \
+       if (__changed && __safely_writable) {                           \
+               set_pte(__ptep, __entry);                               \
+               flush_tlb_page(__vma, __addr);                          \
+       }                                                               \
+       __changed;                                                      \
+})
 #else
-# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable)      \
-       ptep_establish(__vma, __addr, __ptep, __entry)
+# define ptep_set_access_flags(__vma, __addr, __ptep, __entry, __safely_writable) \
+({                                                                     \
+       int __changed = !pte_same(*(__ptep), __entry);                  \
+       if (__changed)                                                  \
+               ptep_establish(__vma, __addr, __ptep, __entry);         \
+       __changed;                                                      \
+})
 #endif
 
 #  ifdef CONFIG_VIRTUAL_MEM_MAP
index c863bdb2889c11fae3879c38be57aef299ef9fbd..7fb730c62f8332cb8cc19a37858f557a8833bf10 100644 (file)
@@ -673,10 +673,14 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
 }
 
 #define  ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-       do {                                                               \
-               __ptep_set_access_flags(__ptep, __entry, __dirty);         \
-               flush_tlb_page_nohash(__vma, __address);                   \
-       } while(0)
+({                                                                        \
+       int __changed = !pte_same(*(__ptep), __entry);                     \
+       if (__changed) {                                                   \
+               __ptep_set_access_flags(__ptep, __entry, __dirty);         \
+               flush_tlb_page_nohash(__vma, __address);                   \
+       }                                                                  \
+       __changed;                                                         \
+})
 
 /*
  * Macro to mark a page protection value as "uncacheable".
index 704c4e669fe0ac9a1b72818b2922d97732d980b0..3cfd98f44bfe82286b55b1ca5aa2af442e993c4c 100644 (file)
@@ -413,10 +413,14 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
        :"cc");
 }
 #define  ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-       do {                                                               \
-               __ptep_set_access_flags(__ptep, __entry, __dirty);         \
-               flush_tlb_page_nohash(__vma, __address);                   \
-       } while(0)
+({                                                                        \
+       int __changed = !pte_same(*(__ptep), __entry);                     \
+       if (__changed) {                                                   \
+               __ptep_set_access_flags(__ptep, __entry, __dirty);         \
+               flush_tlb_page_nohash(__vma, __address);                   \
+       }                                                                  \
+       __changed;                                                         \
+})
 
 /*
  * Macro to mark a page protection value as "uncacheable".
index bed452d4a5f0b1486990b223f7a1e711ae20ac81..9d0ce9ff584026df772125dff65d5e03c85395b4 100644 (file)
@@ -694,10 +694,14 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
 }
 
 #define  ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-       do {                                                               \
-               __ptep_set_access_flags(__ptep, __entry, __dirty);         \
-               flush_tlb_page_nohash(__vma, __address);                   \
-       } while(0)
+({                                                                        \
+       int __changed = !pte_same(*(__ptep), __entry);                     \
+       if (__changed) {                                                   \
+               __ptep_set_access_flags(__ptep, __entry, __dirty);         \
+               flush_tlb_page_nohash(__vma, __address);                   \
+       }                                                                  \
+       __changed;                                                         \
+})
 
 /*
  * Macro to mark a page protection value as "uncacheable".
index 8fe8d42e64c3dcafa0fc486cc8ce46ef723b5593..0a307bb2f35328d784f15c77fe27cd5f3e0814a9 100644 (file)
@@ -744,7 +744,12 @@ ptep_establish(struct vm_area_struct *vma,
 }
 
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-       ptep_establish(__vma, __address, __ptep, __entry)
+({                                                                       \
+       int __changed = !pte_same(*(__ptep), __entry);                    \
+       if (__changed)                                                    \
+               ptep_establish(__vma, __address, __ptep, __entry);        \
+       __changed;                                                        \
+})
 
 /*
  * Test and clear dirty bit in storage key.
index 4f0a5ba0d6a033cf9c8e0923f343556f550914fa..59229aeba27b9c51a15a39985c088719d8bb5811 100644 (file)
@@ -446,6 +446,17 @@ extern int io_remap_pfn_range(struct vm_area_struct *vma,
 #define GET_IOSPACE(pfn)               (pfn >> (BITS_PER_LONG - 4))
 #define GET_PFN(pfn)                   (pfn & 0x0fffffffUL)
 
+#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
+#define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
+({                                                                       \
+       int __changed = !pte_same(*(__ptep), __entry);                    \
+       if (__changed) {                                                  \
+               set_pte_at((__vma)->vm_mm, (__address), __ptep, __entry); \
+               flush_tlb_page(__vma, __address);                         \
+       }                                                                 \
+       (sparc_cpu_model == sun4c) || __changed;                          \
+})
+
 #include <asm-generic/pgtable.h>
 
 #endif /* !(__ASSEMBLY__) */
index 08b9831f2e14f1efab15d594dd594d2a326cc098..0a71e0b9a619c162235f50bdd358da0a4942ff78 100644 (file)
@@ -395,12 +395,14 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  * bit at the same time. */
 #define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
-       do {                                                              \
-               if (__dirty) {                                            \
-                       set_pte(__ptep, __entry);                         \
-                       flush_tlb_page(__vma, __address);                 \
-               }                                                         \
-       } while (0)
+({                                                                       \
+       int __changed = !pte_same(*(__ptep), __entry);                    \
+       if (__changed && __dirty) {                                       \
+               set_pte(__ptep, __entry);                                 \
+               flush_tlb_page(__vma, __address);                         \
+       }                                                                 \
+       __changed;                                                        \
+})
 
 /* Encode and de-code a swap entry */
 #define __swp_type(x)                  (((x).val >> 1) & 0x3f)
index eb7180db303326f73f7e099f84e2557e84cc87b1..a45d1f0691cecb63e088d02fb3ff287f025e4d78 100644 (file)
@@ -326,9 +326,10 @@ static void set_huge_ptep_writable(struct vm_area_struct *vma,
        pte_t entry;
 
        entry = pte_mkwrite(pte_mkdirty(*ptep));
-       ptep_set_access_flags(vma, address, ptep, entry, 1);
-       update_mmu_cache(vma, address, entry);
-       lazy_mmu_prot_update(entry);
+       if (ptep_set_access_flags(vma, address, ptep, entry, 1)) {
+               update_mmu_cache(vma, address, entry);
+               lazy_mmu_prot_update(entry);
+       }
 }
 
 
index cb94488ab96dad4eb3840fa037a7b08673154674..f64cbf9baa3633fc1755f675ec2b46c920c4ecef 100644 (file)
@@ -1691,9 +1691,10 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
                flush_cache_page(vma, address, pte_pfn(orig_pte));
                entry = pte_mkyoung(orig_pte);
                entry = maybe_mkwrite(pte_mkdirty(entry), vma);
-               ptep_set_access_flags(vma, address, page_table, entry, 1);
-               update_mmu_cache(vma, address, entry);
-               lazy_mmu_prot_update(entry);
+               if (ptep_set_access_flags(vma, address, page_table, entry,1)) {
+                       update_mmu_cache(vma, address, entry);
+                       lazy_mmu_prot_update(entry);
+               }
                ret |= VM_FAULT_WRITE;
                goto unlock;
        }
@@ -2525,10 +2526,9 @@ static inline int handle_pte_fault(struct mm_struct *mm,
                pte_t *pte, pmd_t *pmd, int write_access)
 {
        pte_t entry;
-       pte_t old_entry;
        spinlock_t *ptl;
 
-       old_entry = entry = *pte;
+       entry = *pte;
        if (!pte_present(entry)) {
                if (pte_none(entry)) {
                        if (vma->vm_ops) {
@@ -2561,8 +2561,7 @@ static inline int handle_pte_fault(struct mm_struct *mm,
                entry = pte_mkdirty(entry);
        }
        entry = pte_mkyoung(entry);
-       if (!pte_same(old_entry, entry)) {
-               ptep_set_access_flags(vma, address, pte, entry, write_access);
+       if (ptep_set_access_flags(vma, address, pte, entry, write_access)) {
                update_mmu_cache(vma, address, entry);
                lazy_mmu_prot_update(entry);
        } else {