| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright 2010 Tilera Corporation. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *   modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  *   as published by the Free Software Foundation, version 2. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  |  *   WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | 
					
						
							|  |  |  |  *   NON INFRINGEMENT.  See the GNU General Public License for | 
					
						
							|  |  |  |  *   more details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/sched.h>
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/errno.h>
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/swap.h>
 | 
					
						
							|  |  |  | #include <linux/highmem.h>
 | 
					
						
							|  |  |  | #include <linux/slab.h>
 | 
					
						
							|  |  |  | #include <linux/pagemap.h>
 | 
					
						
							|  |  |  | #include <linux/spinlock.h>
 | 
					
						
							|  |  |  | #include <linux/cpumask.h>
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/io.h>
 | 
					
						
							|  |  |  | #include <linux/vmalloc.h>
 | 
					
						
							|  |  |  | #include <linux/smp.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asm/pgtable.h>
 | 
					
						
							|  |  |  | #include <asm/pgalloc.h>
 | 
					
						
							|  |  |  | #include <asm/fixmap.h>
 | 
					
						
							|  |  |  | #include <asm/tlb.h>
 | 
					
						
							|  |  |  | #include <asm/tlbflush.h>
 | 
					
						
							|  |  |  | #include <asm/homecache.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define K(x) ((x) << (PAGE_SHIFT-10))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * The normal show_free_areas() is too verbose on Tile, with dozens | 
					
						
							|  |  |  |  * of processors and often four NUMA zones each with high and lowmem. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-03-24 15:18:15 -07:00
										 |  |  | void show_mem(unsigned int filter) | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct zone *zone; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:04:17 -04:00
										 |  |  | 	pr_err("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu" | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	       " free:%lu\n slab:%lu mapped:%lu pagetables:%lu bounce:%lu" | 
					
						
							|  |  |  | 	       " pagecache:%lu swap:%lu\n", | 
					
						
							|  |  |  | 	       (global_page_state(NR_ACTIVE_ANON) + | 
					
						
							|  |  |  | 		global_page_state(NR_ACTIVE_FILE)), | 
					
						
							|  |  |  | 	       (global_page_state(NR_INACTIVE_ANON) + | 
					
						
							|  |  |  | 		global_page_state(NR_INACTIVE_FILE)), | 
					
						
							|  |  |  | 	       global_page_state(NR_FILE_DIRTY), | 
					
						
							|  |  |  | 	       global_page_state(NR_WRITEBACK), | 
					
						
							|  |  |  | 	       global_page_state(NR_UNSTABLE_NFS), | 
					
						
							|  |  |  | 	       global_page_state(NR_FREE_PAGES), | 
					
						
							|  |  |  | 	       (global_page_state(NR_SLAB_RECLAIMABLE) + | 
					
						
							|  |  |  | 		global_page_state(NR_SLAB_UNRECLAIMABLE)), | 
					
						
							|  |  |  | 	       global_page_state(NR_FILE_MAPPED), | 
					
						
							|  |  |  | 	       global_page_state(NR_PAGETABLE), | 
					
						
							|  |  |  | 	       global_page_state(NR_BOUNCE), | 
					
						
							|  |  |  | 	       global_page_state(NR_FILE_PAGES), | 
					
						
							| 
									
										
											  
											
												swap: add per-partition lock for swapfile
swap_lock is heavily contended when I test swap to 3 fast SSD (even
slightly slower than swap to 2 such SSD).  The main contention comes
from swap_info_get().  This patch tries to fix the gap with adding a new
per-partition lock.
Global data like nr_swapfiles, total_swap_pages, least_priority and
swap_list are still protected by swap_lock.
nr_swap_pages is an atomic now, it can be changed without swap_lock.  In
theory, it's possible get_swap_page() finds no swap pages but actually
there are free swap pages.  But sounds not a big problem.
Accessing partition specific data (like scan_swap_map and so on) is only
protected by swap_info_struct.lock.
Changing swap_info_struct.flags need hold swap_lock and
swap_info_struct.lock, because scan_scan_map() will check it.  read the
flags is ok with either the locks hold.
If both swap_lock and swap_info_struct.lock must be hold, we always hold
the former first to avoid deadlock.
swap_entry_free() can change swap_list.  To delete that code, we add a
new highest_priority_index.  Whenever get_swap_page() is called, we
check it.  If it's valid, we use it.
It's a pity get_swap_page() still holds swap_lock().  But in practice,
swap_lock() isn't heavily contended in my test with this patch (or I can
say there are other much more heavier bottlenecks like TLB flush).  And
BTW, looks get_swap_page() doesn't really need the lock.  We never free
swap_info[] and we check SWAP_WRITEOK flag.  The only risk without the
lock is we could swapout to some low priority swap, but we can quickly
recover after several rounds of swap, so sounds not a big deal to me.
But I'd prefer to fix this if it's a real problem.
"swap: make each swap partition have one address_space" improved the
swapout speed from 1.7G/s to 2G/s.  This patch further improves the
speed to 2.3G/s, so around 15% improvement.  It's a multi-process test,
so TLB flush isn't the biggest bottleneck before the patches.
[arnd@arndb.de: fix it for nommu]
[hughd@google.com: add missing unlock]
[minchan@kernel.org: get rid of lockdep whinge on sys_swapon]
Signed-off-by: Shaohua Li <shli@fusionio.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
											
										 
											2013-02-22 16:34:38 -08:00
										 |  |  | 	       get_nr_swap_pages()); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for_each_zone(zone) { | 
					
						
							|  |  |  | 		unsigned long flags, order, total = 0, largest_order = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!populated_zone(zone)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		spin_lock_irqsave(&zone->lock, flags); | 
					
						
							|  |  |  | 		for (order = 0; order < MAX_ORDER; order++) { | 
					
						
							|  |  |  | 			int nr = zone->free_area[order].nr_free; | 
					
						
							|  |  |  | 			total += nr << order; | 
					
						
							|  |  |  | 			if (nr) | 
					
						
							|  |  |  | 				largest_order = order; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&zone->lock, flags); | 
					
						
							| 
									
										
										
										
											2010-06-25 17:04:17 -04:00
										 |  |  | 		pr_err("Node %d %7s: %lukB (largest %luKb)\n", | 
					
						
							|  |  |  | 		       zone_to_nid(zone), zone->name, | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 		       K(total), largest_order ? K(1UL) << largest_order : 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * shatter_huge_page() - ensure a given address is mapped by a small page. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This function converts a huge PTE mapping kernel LOWMEM into a bunch | 
					
						
							|  |  |  |  * of small PTEs with the same caching.  No cache flush required, but we | 
					
						
							|  |  |  |  * must do a global TLB flush. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Any caller that wishes to modify a kernel mapping that might | 
					
						
							|  |  |  |  * have been made with a huge page should call this function, | 
					
						
							|  |  |  |  * since doing so properly avoids race conditions with installing the | 
					
						
							|  |  |  |  * newly-shattered page and then flushing all the TLB entries. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @addr: Address at which to shatter any existing huge page. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void shatter_huge_page(unsigned long addr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pgd_t *pgd; | 
					
						
							|  |  |  | 	pud_t *pud; | 
					
						
							|  |  |  | 	pmd_t *pmd; | 
					
						
							|  |  |  | 	unsigned long flags = 0;  /* happy compiler */ | 
					
						
							|  |  |  | #ifdef __PAGETABLE_PMD_FOLDED
 | 
					
						
							|  |  |  | 	struct list_head *pos; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get a pointer to the pmd entry that we need to change. */ | 
					
						
							|  |  |  | 	addr &= HPAGE_MASK; | 
					
						
							|  |  |  | 	BUG_ON(pgd_addr_invalid(addr)); | 
					
						
							|  |  |  | 	BUG_ON(addr < PAGE_OFFSET);  /* only for kernel LOWMEM */ | 
					
						
							|  |  |  | 	pgd = swapper_pg_dir + pgd_index(addr); | 
					
						
							|  |  |  | 	pud = pud_offset(pgd, addr); | 
					
						
							|  |  |  | 	BUG_ON(!pud_present(*pud)); | 
					
						
							|  |  |  | 	pmd = pmd_offset(pud, addr); | 
					
						
							|  |  |  | 	BUG_ON(!pmd_present(*pmd)); | 
					
						
							|  |  |  | 	if (!pmd_huge_page(*pmd)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 15:50:08 -04:00
										 |  |  | 	spin_lock_irqsave(&init_mm.page_table_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	if (!pmd_huge_page(*pmd)) { | 
					
						
							|  |  |  | 		/* Lost the race to convert the huge page. */ | 
					
						
							| 
									
										
										
										
											2012-03-29 15:50:08 -04:00
										 |  |  | 		spin_unlock_irqrestore(&init_mm.page_table_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Shatter the huge page into the preallocated L2 page table. */ | 
					
						
							| 
									
										
										
										
											2013-09-13 11:14:25 -04:00
										 |  |  | 	pmd_populate_kernel(&init_mm, pmd, get_prealloc_pte(pmd_pfn(*pmd))); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __PAGETABLE_PMD_FOLDED
 | 
					
						
							|  |  |  | 	/* Walk every pgd on the system and update the pmd there. */ | 
					
						
							| 
									
										
										
										
											2012-03-29 15:50:08 -04:00
										 |  |  | 	spin_lock(&pgd_lock); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	list_for_each(pos, &pgd_list) { | 
					
						
							|  |  |  | 		pmd_t *copy_pmd; | 
					
						
							|  |  |  | 		pgd = list_to_pgd(pos) + pgd_index(addr); | 
					
						
							|  |  |  | 		pud = pud_offset(pgd, addr); | 
					
						
							|  |  |  | 		copy_pmd = pmd_offset(pud, addr); | 
					
						
							|  |  |  | 		__set_pmd(copy_pmd, *pmd); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-29 15:50:08 -04:00
										 |  |  | 	spin_unlock(&pgd_lock); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Tell every cpu to notice the change. */ | 
					
						
							|  |  |  | 	flush_remote(0, 0, NULL, addr, HPAGE_SIZE, HPAGE_SIZE, | 
					
						
							|  |  |  | 		     cpu_possible_mask, NULL, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Hold the lock until the TLB flush is finished to avoid races. */ | 
					
						
							| 
									
										
										
										
											2012-03-29 15:50:08 -04:00
										 |  |  | 	spin_unlock_irqrestore(&init_mm.page_table_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * List of all pgd's needed so it can invalidate entries in both cached | 
					
						
							|  |  |  |  * and uncached pgd's. This is essentially codepath-based locking | 
					
						
							|  |  |  |  * against pageattr.c; it is the unique case in which a valid change | 
					
						
							|  |  |  |  * of kernel pagetables can't be lazily synchronized by vmalloc faults. | 
					
						
							|  |  |  |  * vmalloc faults work because attached pagetables are never freed. | 
					
						
							| 
									
										
										
										
											2012-03-29 15:50:08 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The lock is always taken with interrupts disabled, unlike on x86 | 
					
						
							|  |  |  |  * and other platforms, because we need to take the lock in | 
					
						
							|  |  |  |  * shatter_huge_page(), which may be called from an interrupt context. | 
					
						
							|  |  |  |  * We are not at risk from the tlbflush IPI deadlock that was seen on | 
					
						
							|  |  |  |  * x86, since we use the flush_remote() API to have the hypervisor do | 
					
						
							|  |  |  |  * the TLB flushes regardless of irq disabling. | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | DEFINE_SPINLOCK(pgd_lock); | 
					
						
							|  |  |  | LIST_HEAD(pgd_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void pgd_list_add(pgd_t *pgd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	list_add(pgd_to_list(pgd), &pgd_list); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void pgd_list_del(pgd_t *pgd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	list_del(pgd_to_list(pgd)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define KERNEL_PGD_INDEX_START pgd_index(PAGE_OFFSET)
 | 
					
						
							|  |  |  | #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_INDEX_START)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pgd_ctor(pgd_t *pgd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(pgd, 0, KERNEL_PGD_INDEX_START*sizeof(pgd_t)); | 
					
						
							|  |  |  | 	spin_lock_irqsave(&pgd_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef __tilegx__
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Check that the user interrupt vector has no L2. | 
					
						
							|  |  |  | 	 * It never should for the swapper, and new page tables | 
					
						
							|  |  |  | 	 * should always start with an empty user interrupt vector. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	BUG_ON(((u64 *)swapper_pg_dir)[pgd_index(MEM_USER_INTRPT)] != 0); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	memcpy(pgd + KERNEL_PGD_INDEX_START, | 
					
						
							|  |  |  | 	       swapper_pg_dir + KERNEL_PGD_INDEX_START, | 
					
						
							|  |  |  | 	       KERNEL_PGD_PTRS * sizeof(pgd_t)); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pgd_list_add(pgd); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&pgd_lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pgd_dtor(pgd_t *pgd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; /* can be called from interrupt context */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&pgd_lock, flags); | 
					
						
							|  |  |  | 	pgd_list_del(pgd); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&pgd_lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pgd_t *pgd_alloc(struct mm_struct *mm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pgd_t *pgd = kmem_cache_alloc(pgd_cache, GFP_KERNEL); | 
					
						
							|  |  |  | 	if (pgd) | 
					
						
							|  |  |  | 		pgd_ctor(pgd); | 
					
						
							|  |  |  | 	return pgd; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pgd_free(struct mm_struct *mm, pgd_t *pgd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pgd_dtor(pgd); | 
					
						
							|  |  |  | 	kmem_cache_free(pgd_cache, pgd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define L2_USER_PGTABLE_PAGES (1 << L2_USER_PGTABLE_ORDER)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | struct page *pgtable_alloc_one(struct mm_struct *mm, unsigned long address, | 
					
						
							|  |  |  | 			       int order) | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	gfp_t flags = GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO; | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	struct page *p; | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	p = alloc_pages(flags, L2_USER_PGTABLE_ORDER); | 
					
						
							|  |  |  | 	if (p == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 14:31:43 -08:00
										 |  |  | 	if (!pgtable_page_ctor(p)) { | 
					
						
							|  |  |  | 		__free_pages(p, L2_USER_PGTABLE_ORDER); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Make every page have a page_count() of one, not just the first. | 
					
						
							|  |  |  | 	 * We don't use __GFP_COMP since it doesn't look like it works | 
					
						
							|  |  |  | 	 * correctly with tlb_remove_page(). | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | 	for (i = 1; i < order; ++i) { | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 		init_page_count(p+i); | 
					
						
							|  |  |  | 		inc_zone_page_state(p+i, NR_PAGETABLE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	return p; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Free page immediately (used in __pte_alloc if we raced with another | 
					
						
							|  |  |  |  * process).  We have to correct whatever pte_alloc_one() did before | 
					
						
							|  |  |  |  * returning the pages to the allocator. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | void pgtable_free(struct mm_struct *mm, struct page *p, int order) | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	pgtable_page_dtor(p); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	__free_page(p); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | 	for (i = 1; i < order; ++i) { | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 		__free_page(p+i); | 
					
						
							|  |  |  | 		dec_zone_page_state(p+i, NR_PAGETABLE); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | void __pgtable_free_tlb(struct mmu_gather *tlb, struct page *pte, | 
					
						
							|  |  |  | 			unsigned long address, int order) | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pgtable_page_dtor(pte); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	tlb_remove_page(tlb, pte); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | 	for (i = 1; i < order; ++i) { | 
					
						
							| 
									
										
										
										
											2011-01-25 18:31:12 +01:00
										 |  |  | 		tlb_remove_page(tlb, pte + i); | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 		dec_zone_page_state(pte + i, NR_PAGETABLE); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef __tilegx__
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * FIXME: needs to be atomic vs hypervisor writes.  For now we make the | 
					
						
							|  |  |  |  * window of vulnerability a bit smaller by doing an unlocked 8-bit update. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | int ptep_test_and_clear_young(struct vm_area_struct *vma, | 
					
						
							|  |  |  | 			      unsigned long addr, pte_t *ptep) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if HV_PTE_INDEX_ACCESSED < 8 || HV_PTE_INDEX_ACCESSED >= 16
 | 
					
						
							|  |  |  | # error Code assumes HV_PTE "accessed" bit in second byte
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	u8 *tmp = (u8 *)ptep; | 
					
						
							|  |  |  | 	u8 second_byte = tmp[1]; | 
					
						
							|  |  |  | 	if (!(second_byte & (1 << (HV_PTE_INDEX_ACCESSED - 8)))) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	tmp[1] = second_byte & ~(1 << (HV_PTE_INDEX_ACCESSED - 8)); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * This implementation is atomic vs hypervisor writes, since the hypervisor | 
					
						
							|  |  |  |  * always writes the low word (where "accessed" and "dirty" are) and this | 
					
						
							|  |  |  |  * routine only writes the high word. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void ptep_set_wrprotect(struct mm_struct *mm, | 
					
						
							|  |  |  | 			unsigned long addr, pte_t *ptep) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if HV_PTE_INDEX_WRITABLE < 32
 | 
					
						
							|  |  |  | # error Code assumes HV_PTE "writable" bit in high word
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	u32 *tmp = (u32 *)ptep; | 
					
						
							|  |  |  | 	tmp[1] = tmp[1] & ~(1 << (HV_PTE_INDEX_WRITABLE - 32)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 15:08:09 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Return a pointer to the PTE that corresponds to the given | 
					
						
							|  |  |  |  * address in the given page table.  A NULL page table just uses | 
					
						
							|  |  |  |  * the standard kernel page table; the preferred API in this case | 
					
						
							|  |  |  |  * is virt_to_kpte(). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The returned pointer can point to a huge page in other levels | 
					
						
							|  |  |  |  * of the page table than the bottom, if the huge page is present | 
					
						
							|  |  |  |  * in the page table.  For bottom-level PTEs, the returned pointer | 
					
						
							|  |  |  |  * can point to a PTE that is either present or not. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | pte_t *virt_to_pte(struct mm_struct* mm, unsigned long addr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pgd_t *pgd; | 
					
						
							|  |  |  | 	pud_t *pud; | 
					
						
							|  |  |  | 	pmd_t *pmd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pgd_addr_invalid(addr)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pgd = mm ? pgd_offset(mm, addr) : swapper_pg_dir + pgd_index(addr); | 
					
						
							|  |  |  | 	pud = pud_offset(pgd, addr); | 
					
						
							|  |  |  | 	if (!pud_present(*pud)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2013-08-10 13:15:46 -04:00
										 |  |  | 	if (pud_huge_page(*pud)) | 
					
						
							|  |  |  | 		return (pte_t *)pud; | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	pmd = pmd_offset(pud, addr); | 
					
						
							|  |  |  | 	if (!pmd_present(*pmd)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2013-08-12 15:08:09 -04:00
										 |  |  | 	if (pmd_huge_page(*pmd)) | 
					
						
							|  |  |  | 		return (pte_t *)pmd; | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	return pte_offset_kernel(pmd, addr); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-10 13:15:46 -04:00
										 |  |  | EXPORT_SYMBOL(virt_to_pte); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-12 15:08:09 -04:00
										 |  |  | pte_t *virt_to_kpte(unsigned long kaddr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BUG_ON(kaddr < PAGE_OFFSET); | 
					
						
							|  |  |  | 	return virt_to_pte(NULL, kaddr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(virt_to_kpte); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | pgprot_t set_remote_cache_cpu(pgprot_t prot, int cpu) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int width = smp_width; | 
					
						
							|  |  |  | 	int x = cpu % width; | 
					
						
							|  |  |  | 	int y = cpu / width; | 
					
						
							|  |  |  | 	BUG_ON(y >= smp_height); | 
					
						
							|  |  |  | 	BUG_ON(hv_pte_get_mode(prot) != HV_PTE_MODE_CACHE_TILE_L3); | 
					
						
							|  |  |  | 	BUG_ON(cpu < 0 || cpu >= NR_CPUS); | 
					
						
							|  |  |  | 	BUG_ON(!cpu_is_valid_lotar(cpu)); | 
					
						
							|  |  |  | 	return hv_pte_set_lotar(prot, HV_XY_TO_LOTAR(x, y)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int get_remote_cache_cpu(pgprot_t prot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	HV_LOTAR lotar = hv_pte_get_lotar(prot); | 
					
						
							|  |  |  | 	int x = HV_LOTAR_X(lotar); | 
					
						
							|  |  |  | 	int y = HV_LOTAR_Y(lotar); | 
					
						
							|  |  |  | 	BUG_ON(hv_pte_get_mode(prot) != HV_PTE_MODE_CACHE_TILE_L3); | 
					
						
							|  |  |  | 	return x + y * smp_width; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Convert a kernel VA to a PA and homing information. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | int va_to_cpa_and_pte(void *va, unsigned long long *cpa, pte_t *pte) | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	struct page *page = virt_to_page(va); | 
					
						
							|  |  |  | 	pte_t null_pte = { 0 }; | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	*cpa = __pa(va); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Note that this is not writing a page table, just returning a pte. */ | 
					
						
							|  |  |  | 	*pte = pte_set_home(null_pte, page_home(page)); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 	return 0; /* return non-zero if not hfh? */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(va_to_cpa_and_pte); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void __set_pte(pte_t *ptep, pte_t pte) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | #ifdef __tilegx__
 | 
					
						
							|  |  |  | 	*ptep = pte; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | # if HV_PTE_INDEX_PRESENT >= 32 || HV_PTE_INDEX_MIGRATING >= 32
 | 
					
						
							|  |  |  | #  error Must write the present and migrating bits last
 | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  | 	if (pte_present(pte)) { | 
					
						
							|  |  |  | 		((u32 *)ptep)[1] = (u32)(pte_val(pte) >> 32); | 
					
						
							|  |  |  | 		barrier(); | 
					
						
							|  |  |  | 		((u32 *)ptep)[0] = (u32)(pte_val(pte)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		((u32 *)ptep)[0] = (u32)(pte_val(pte)); | 
					
						
							|  |  |  | 		barrier(); | 
					
						
							|  |  |  | 		((u32 *)ptep)[1] = (u32)(pte_val(pte) >> 32); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif /* __tilegx__ */
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void set_pte(pte_t *ptep, pte_t pte) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 15:36:53 -04:00
										 |  |  | 	if (pte_present(pte) && | 
					
						
							|  |  |  | 	    (!CHIP_HAS_MMIO() || hv_pte_get_mode(pte) != HV_PTE_MODE_MMIO)) { | 
					
						
							|  |  |  | 		/* The PTE actually references physical memory. */ | 
					
						
							|  |  |  | 		unsigned long pfn = pte_pfn(pte); | 
					
						
							|  |  |  | 		if (pfn_valid(pfn)) { | 
					
						
							|  |  |  | 			/* Update the home of the PTE from the struct page. */ | 
					
						
							|  |  |  | 			pte = pte_set_home(pte, page_home(pfn_to_page(pfn))); | 
					
						
							|  |  |  | 		} else if (hv_pte_get_mode(pte) == 0) { | 
					
						
							|  |  |  | 			/* remap_pfn_range(), etc, must supply PTE mode. */ | 
					
						
							|  |  |  | 			panic("set_pte(): out-of-range PFN and mode 0\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-28 16:37:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	__set_pte(ptep, pte); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Can this mm load a PTE with cached_priority set? */ | 
					
						
							|  |  |  | static inline int mm_is_priority_cached(struct mm_struct *mm) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | 	return mm->context.priority_cached != 0; | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Add a priority mapping to an mm_context and | 
					
						
							|  |  |  |  * notify the hypervisor if this is the first one. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void start_mm_caching(struct mm_struct *mm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!mm_is_priority_cached(mm)) { | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | 		mm->context.priority_cached = -1UL; | 
					
						
							|  |  |  | 		hv_set_caching(-1UL); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Validate and return the priority_cached flag.  We know if it's zero | 
					
						
							|  |  |  |  * that we don't need to scan, since we immediately set it non-zero | 
					
						
							|  |  |  |  * when we first consider a MAP_CACHE_PRIORITY mapping. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * We only _try_ to acquire the mmap_sem semaphore; if we can't acquire it, | 
					
						
							|  |  |  |  * since we're in an interrupt context (servicing switch_mm) we don't | 
					
						
							|  |  |  |  * worry about it and don't unset the "priority_cached" field. | 
					
						
							|  |  |  |  * Presumably we'll come back later and have more luck and clear | 
					
						
							|  |  |  |  * the value then; for now we'll just keep the cache marked for priority. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-03-29 13:58:43 -04:00
										 |  |  | static unsigned long update_priority_cached(struct mm_struct *mm) | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (mm->context.priority_cached && down_write_trylock(&mm->mmap_sem)) { | 
					
						
							|  |  |  | 		struct vm_area_struct *vm; | 
					
						
							|  |  |  | 		for (vm = mm->mmap; vm; vm = vm->vm_next) { | 
					
						
							|  |  |  | 			if (hv_pte_get_cached_priority(vm->vm_page_prot)) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (vm == NULL) | 
					
						
							|  |  |  | 			mm->context.priority_cached = 0; | 
					
						
							|  |  |  | 		up_write(&mm->mmap_sem); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return mm->context.priority_cached; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Set caching correctly for an mm that we are switching to. */ | 
					
						
							|  |  |  | void check_mm_caching(struct mm_struct *prev, struct mm_struct *next) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!mm_is_priority_cached(next)) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * If the new mm doesn't use priority caching, just see if we | 
					
						
							|  |  |  | 		 * need the hv_set_caching(), or can assume it's already zero. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (mm_is_priority_cached(prev)) | 
					
						
							|  |  |  | 			hv_set_caching(0); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		hv_set_caching(update_priority_cached(next)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if CHIP_HAS_MMIO()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Map an arbitrary MMIO address, homed according to pgprot, into VA space. */ | 
					
						
							|  |  |  | void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, | 
					
						
							|  |  |  | 			   pgprot_t home) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void *addr; | 
					
						
							|  |  |  | 	struct vm_struct *area; | 
					
						
							|  |  |  | 	unsigned long offset, last_addr; | 
					
						
							|  |  |  | 	pgprot_t pgprot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Don't allow wraparound or zero size */ | 
					
						
							|  |  |  | 	last_addr = phys_addr + size - 1; | 
					
						
							|  |  |  | 	if (!size || last_addr < phys_addr) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Create a read/write, MMIO VA mapping homed at the requested shim. */ | 
					
						
							|  |  |  | 	pgprot = PAGE_KERNEL; | 
					
						
							|  |  |  | 	pgprot = hv_pte_set_mode(pgprot, HV_PTE_MODE_MMIO); | 
					
						
							|  |  |  | 	pgprot = hv_pte_set_lotar(pgprot, hv_pte_get_lotar(home)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Mappings have to be page-aligned | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	offset = phys_addr & ~PAGE_MASK; | 
					
						
							|  |  |  | 	phys_addr &= PAGE_MASK; | 
					
						
							|  |  |  | 	size = PAGE_ALIGN(last_addr+1) - phys_addr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Ok, go for it.. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	area = get_vm_area(size, VM_IOREMAP /* | other flags? */); | 
					
						
							|  |  |  | 	if (!area) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	area->phys_addr = phys_addr; | 
					
						
							|  |  |  | 	addr = area->addr; | 
					
						
							|  |  |  | 	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size, | 
					
						
							|  |  |  | 			       phys_addr, pgprot)) { | 
					
						
							| 
									
										
										
										
											2013-08-07 15:42:34 -04:00
										 |  |  | 		free_vm_area(area); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (__force void __iomem *) (offset + (char *)addr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(ioremap_prot); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Unmap an MMIO VA mapping. */ | 
					
						
							|  |  |  | void iounmap(volatile void __iomem *addr_in) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	volatile void __iomem *addr = (volatile void __iomem *) | 
					
						
							|  |  |  | 		(PAGE_MASK & (unsigned long __force)addr_in); | 
					
						
							|  |  |  | #if 1
 | 
					
						
							|  |  |  | 	vunmap((void * __force)addr); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	/* x86 uses this complicated flow instead of vunmap().  Is
 | 
					
						
							|  |  |  | 	 * there any particular reason we should do the same? */ | 
					
						
							|  |  |  | 	struct vm_struct *p, *o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Use the vm area unlocked, assuming the caller
 | 
					
						
							|  |  |  | 	   ensures there isn't another iounmap for the same address | 
					
						
							|  |  |  | 	   in parallel. Reuse of the virtual address is prevented by | 
					
						
							|  |  |  | 	   leaving it in the global lists until we're done with it. | 
					
						
							|  |  |  | 	   cpa takes care of the direct mappings. */ | 
					
						
							| 
									
										
										
										
											2013-04-29 15:07:27 -07:00
										 |  |  | 	p = find_vm_area((void *)addr); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!p) { | 
					
						
							| 
									
										
										
										
											2010-06-25 17:04:17 -04:00
										 |  |  | 		pr_err("iounmap: bad address %p\n", addr); | 
					
						
							| 
									
										
										
										
											2010-05-28 23:09:12 -04:00
										 |  |  | 		dump_stack(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Finally remove it */ | 
					
						
							|  |  |  | 	o = remove_vm_area((void *)addr); | 
					
						
							|  |  |  | 	BUG_ON(p != o || o == NULL); | 
					
						
							|  |  |  | 	kfree(p); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(iounmap); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* CHIP_HAS_MMIO() */
 |