ALSA: usb-audio: add support for Akai MPD16
[safe/jmp/linux-2.6] / mm / pagewalk.c
index d5878be..8b1a2ce 100644 (file)
@@ -1,6 +1,7 @@
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/sched.h>
+#include <linux/hugetlb.h>
 
 static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
                          struct mm_walk *walk)
@@ -79,6 +80,37 @@ static int walk_pud_range(pgd_t *pgd, unsigned long addr, unsigned long end,
        return err;
 }
 
+#ifdef CONFIG_HUGETLB_PAGE
+static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr,
+                                      unsigned long end)
+{
+       unsigned long boundary = (addr & huge_page_mask(h)) + huge_page_size(h);
+       return boundary < end ? boundary : end;
+}
+
+static int walk_hugetlb_range(struct vm_area_struct *vma,
+                             unsigned long addr, unsigned long end,
+                             struct mm_walk *walk)
+{
+       struct hstate *h = hstate_vma(vma);
+       unsigned long next;
+       unsigned long hmask = huge_page_mask(h);
+       pte_t *pte;
+       int err = 0;
+
+       do {
+               next = hugetlb_entry_end(h, addr, end);
+               pte = huge_pte_offset(walk->mm, addr & hmask);
+               if (pte && walk->hugetlb_entry)
+                       err = walk->hugetlb_entry(pte, hmask, addr, next, walk);
+               if (err)
+                       return err;
+       } while (addr = next, addr != end);
+
+       return 0;
+}
+#endif
+
 /**
  * walk_page_range - walk a memory map's page tables with a callback
  * @mm: memory map to walk
@@ -107,6 +139,7 @@ int walk_page_range(unsigned long addr, unsigned long end,
        pgd_t *pgd;
        unsigned long next;
        int err = 0;
+       struct vm_area_struct *vma;
 
        if (addr >= end)
                return err;
@@ -117,11 +150,34 @@ int walk_page_range(unsigned long addr, unsigned long end,
        pgd = pgd_offset(walk->mm, addr);
        do {
                next = pgd_addr_end(addr, end);
+
+               /*
+                * handle hugetlb vma individually because pagetable walk for
+                * the hugetlb page is dependent on the architecture and
+                * we can't handled it in the same manner as non-huge pages.
+                */
+               vma = find_vma(walk->mm, addr);
+#ifdef CONFIG_HUGETLB_PAGE
+               if (vma && is_vm_hugetlb_page(vma)) {
+                       if (vma->vm_end < next)
+                               next = vma->vm_end;
+                       /*
+                        * Hugepage is very tightly coupled with vma, so
+                        * walk through hugetlb entries within a given vma.
+                        */
+                       err = walk_hugetlb_range(vma, addr, next, walk);
+                       if (err)
+                               break;
+                       pgd = pgd_offset(walk->mm, next);
+                       continue;
+               }
+#endif
                if (pgd_none_or_clear_bad(pgd)) {
                        if (walk->pte_hole)
                                err = walk->pte_hole(addr, next, walk);
                        if (err)
                                break;
+                       pgd++;
                        continue;
                }
                if (walk->pgd_entry)
@@ -131,7 +187,8 @@ int walk_page_range(unsigned long addr, unsigned long end,
                        err = walk_pud_range(pgd, addr, next, walk);
                if (err)
                        break;
-       } while (pgd++, addr = next, addr != end);
+               pgd++;
+       } while (addr = next, addr != end);
 
        return err;
 }