static inline bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
+       tlb->pages[tlb->nr++] = page;
+       VM_WARN_ON(tlb->nr > tlb->max);
        if (tlb->nr == tlb->max)
                return true;
-       tlb->pages[tlb->nr++] = page;
        return false;
 }
 
 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
-       if (__tlb_remove_page(tlb, page)) {
+       if (__tlb_remove_page(tlb, page))
                tlb_flush_mmu(tlb);
-               __tlb_remove_page(tlb, page);
-       }
 }
 
 static inline bool __tlb_remove_page_size(struct mmu_gather *tlb,
        return __tlb_remove_page(tlb, page);
 }
 
-static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb,
-                                        struct page *page)
-{
-       return __tlb_remove_page(tlb, page);
-}
-
 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
                                        struct page *page, int page_size)
 {
 
  */
 static inline bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
-       if (tlb->nr == tlb->max)
-               return true;
-
        tlb->need_flush = 1;
 
        if (!tlb->nr && tlb->pages == tlb->local)
                __tlb_alloc_page(tlb);
 
        tlb->pages[tlb->nr++] = page;
+       VM_WARN_ON(tlb->nr > tlb->max);
+       if (tlb->nr == tlb->max)
+               return true;
        return false;
 }
 
 
 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
-       if (__tlb_remove_page(tlb, page)) {
+       if (__tlb_remove_page(tlb, page))
                tlb_flush_mmu(tlb);
-               __tlb_remove_page(tlb, page);
-       }
 }
 
 static inline bool __tlb_remove_page_size(struct mmu_gather *tlb,
        return __tlb_remove_page(tlb, page);
 }
 
-static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb,
-                                        struct page *page)
-{
-       return __tlb_remove_page(tlb, page);
-}
-
 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
                                        struct page *page, int page_size)
 {
 
        return __tlb_remove_page(tlb, page);
 }
 
-static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb,
-                                        struct page *page)
-{
-       return __tlb_remove_page(tlb, page);
-}
-
 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
                                        struct page *page, int page_size)
 {
 
        return __tlb_remove_page(tlb, page);
 }
 
-static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb,
-                                        struct page *page)
-{
-       return __tlb_remove_page(tlb, page);
-}
-
 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
                                        struct page *page, int page_size)
 {
 
        return __tlb_remove_page(tlb, page);
 }
 
-static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb,
-                                        struct page *page)
-{
-       return __tlb_remove_page(tlb, page);
-}
-
 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
                                        struct page *page, int page_size)
 {
 
        struct mmu_gather_batch local;
        struct page             *__pages[MMU_GATHER_BUNDLE];
        unsigned int            batch_count;
-       /*
-        * __tlb_adjust_range  will track the new addr here,
-        * that that we can adjust the range after the flush
-        */
-       unsigned long addr;
        int page_size;
 };
 
 {
        tlb->start = min(tlb->start, address);
        tlb->end = max(tlb->end, address + range_size);
-       /*
-        * Track the last address with which we adjusted the range. This
-        * will be used later to adjust again after a mmu_flush due to
-        * failed __tlb_remove_page
-        */
-       tlb->addr = address;
 }
 
 static inline void __tlb_reset_range(struct mmu_gather *tlb)
 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
                                        struct page *page, int page_size)
 {
-       if (__tlb_remove_page_size(tlb, page, page_size)) {
+       if (__tlb_remove_page_size(tlb, page, page_size))
                tlb_flush_mmu(tlb);
-               tlb->page_size = page_size;
-               __tlb_adjust_range(tlb, tlb->addr, page_size);
-               __tlb_remove_page_size(tlb, page, page_size);
-       }
 }
 
-static bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
+static inline bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
        return __tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }
        return tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }
 
-static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb, struct page *page)
-{
-       /* active->nr should be zero when we call this */
-       VM_BUG_ON_PAGE(tlb->active->nr, page);
-       tlb->page_size = PAGE_SIZE;
-       __tlb_adjust_range(tlb, tlb->addr, PAGE_SIZE);
-       return __tlb_remove_page(tlb, page);
-}
-
 #ifndef tlb_remove_check_page_size_change
 #define tlb_remove_check_page_size_change tlb_remove_check_page_size_change
 static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb,
 
        struct mmu_gather_batch *batch;
 
        VM_BUG_ON(!tlb->end);
-
-       if (!tlb->page_size)
-               tlb->page_size = page_size;
-       else {
-               if (page_size != tlb->page_size)
-                       return true;
-       }
+       VM_WARN_ON(tlb->page_size != page_size);
 
        batch = tlb->active;
+       /*
+        * Add the page and check if we are full. If so
+        * force a flush.
+        */
+       batch->pages[batch->nr++] = page;
        if (batch->nr == batch->max) {
                if (!tlb_next_batch(tlb))
                        return true;
        }
        VM_BUG_ON_PAGE(batch->nr > batch->max, page);
 
-       batch->pages[batch->nr++] = page;
        return false;
 }
 
        pte_t *start_pte;
        pte_t *pte;
        swp_entry_t entry;
-       struct page *pending_page = NULL;
 
        tlb_remove_check_page_size_change(tlb, PAGE_SIZE);
 again:
                                print_bad_pte(vma, addr, ptent, page);
                        if (unlikely(__tlb_remove_page(tlb, page))) {
                                force_flush = 1;
-                               pending_page = page;
                                addr += PAGE_SIZE;
                                break;
                        }
        if (force_flush) {
                force_flush = 0;
                tlb_flush_mmu_free(tlb);
-               if (pending_page) {
-                       /* remove the page with new size */
-                       __tlb_remove_pte_page(tlb, pending_page);
-                       pending_page = NULL;
-               }
                if (addr != end)
                        goto again;
        }