Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Xen mmu operations |
| 3 | * |
| 4 | * This file contains the various mmu fetch and update operations. |
| 5 | * The most important job they must perform is the mapping between the |
| 6 | * domain's pfn and the overall machine mfns. |
| 7 | * |
| 8 | * Xen allows guests to directly update the pagetable, in a controlled |
| 9 | * fashion. In other words, the guest modifies the same pagetable |
| 10 | * that the CPU actually uses, which eliminates the overhead of having |
| 11 | * a separate shadow pagetable. |
| 12 | * |
| 13 | * In order to allow this, it falls on the guest domain to map its |
| 14 | * notion of a "physical" pfn - which is just a domain-local linear |
| 15 | * address - into a real "machine address" which the CPU's MMU can |
| 16 | * use. |
| 17 | * |
| 18 | * A pgd_t/pmd_t/pte_t will typically contain an mfn, and so can be |
| 19 | * inserted directly into the pagetable. When creating a new |
| 20 | * pte/pmd/pgd, it converts the passed pfn into an mfn. Conversely, |
| 21 | * when reading the content back with __(pgd|pmd|pte)_val, it converts |
| 22 | * the mfn back into a pfn. |
| 23 | * |
| 24 | * The other constraint is that all pages which make up a pagetable |
| 25 | * must be mapped read-only in the guest. This prevents uncontrolled |
| 26 | * guest updates to the pagetable. Xen strictly enforces this, and |
| 27 | * will disallow any pagetable update which will end up mapping a |
| 28 | * pagetable page RW, and will disallow using any writable page as a |
| 29 | * pagetable. |
| 30 | * |
| 31 | * Naively, when loading %cr3 with the base of a new pagetable, Xen |
| 32 | * would need to validate the whole pagetable before going on. |
| 33 | * Naturally, this is quite slow. The solution is to "pin" a |
| 34 | * pagetable, which enforces all the constraints on the pagetable even |
| 35 | * when it is not actively in use. This menas that Xen can be assured |
| 36 | * that it is still valid when you do load it into %cr3, and doesn't |
| 37 | * need to revalidate it. |
| 38 | * |
| 39 | * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 |
| 40 | */ |
Jeremy Fitzhardinge | f120f13 | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 41 | #include <linux/sched.h> |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 42 | #include <linux/highmem.h> |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 43 | #include <linux/debugfs.h> |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 44 | #include <linux/bug.h> |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 45 | |
| 46 | #include <asm/pgtable.h> |
| 47 | #include <asm/tlbflush.h> |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 48 | #include <asm/fixmap.h> |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 49 | #include <asm/mmu_context.h> |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 50 | #include <asm/paravirt.h> |
Jeremy Fitzhardinge | cbcd79c | 2008-07-08 15:06:27 -0700 | [diff] [blame] | 51 | #include <asm/linkage.h> |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 52 | |
| 53 | #include <asm/xen/hypercall.h> |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 54 | #include <asm/xen/hypervisor.h> |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 55 | |
| 56 | #include <xen/page.h> |
| 57 | #include <xen/interface/xen.h> |
| 58 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 59 | #include "multicalls.h" |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 60 | #include "mmu.h" |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 61 | #include "debugfs.h" |
| 62 | |
| 63 | #define MMU_UPDATE_HISTO 30 |
| 64 | |
| 65 | #ifdef CONFIG_XEN_DEBUG_FS |
| 66 | |
| 67 | static struct { |
| 68 | u32 pgd_update; |
| 69 | u32 pgd_update_pinned; |
| 70 | u32 pgd_update_batched; |
| 71 | |
| 72 | u32 pud_update; |
| 73 | u32 pud_update_pinned; |
| 74 | u32 pud_update_batched; |
| 75 | |
| 76 | u32 pmd_update; |
| 77 | u32 pmd_update_pinned; |
| 78 | u32 pmd_update_batched; |
| 79 | |
| 80 | u32 pte_update; |
| 81 | u32 pte_update_pinned; |
| 82 | u32 pte_update_batched; |
| 83 | |
| 84 | u32 mmu_update; |
| 85 | u32 mmu_update_extended; |
| 86 | u32 mmu_update_histo[MMU_UPDATE_HISTO]; |
| 87 | |
| 88 | u32 prot_commit; |
| 89 | u32 prot_commit_batched; |
| 90 | |
| 91 | u32 set_pte_at; |
| 92 | u32 set_pte_at_batched; |
| 93 | u32 set_pte_at_pinned; |
| 94 | u32 set_pte_at_current; |
| 95 | u32 set_pte_at_kernel; |
| 96 | } mmu_stats; |
| 97 | |
| 98 | static u8 zero_stats; |
| 99 | |
| 100 | static inline void check_zero(void) |
| 101 | { |
| 102 | if (unlikely(zero_stats)) { |
| 103 | memset(&mmu_stats, 0, sizeof(mmu_stats)); |
| 104 | zero_stats = 0; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #define ADD_STATS(elem, val) \ |
| 109 | do { check_zero(); mmu_stats.elem += (val); } while(0) |
| 110 | |
| 111 | #else /* !CONFIG_XEN_DEBUG_FS */ |
| 112 | |
| 113 | #define ADD_STATS(elem, val) do { (void)(val); } while(0) |
| 114 | |
| 115 | #endif /* CONFIG_XEN_DEBUG_FS */ |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 116 | |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 117 | /* |
| 118 | * Just beyond the highest usermode address. STACK_TOP_MAX has a |
| 119 | * redzone above it, so round it up to a PGD boundary. |
| 120 | */ |
| 121 | #define USER_LIMIT ((STACK_TOP_MAX + PGDIR_SIZE - 1) & PGDIR_MASK) |
| 122 | |
| 123 | |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 124 | #define P2M_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(unsigned long)) |
Jeremy Fitzhardinge | cf0923e | 2008-05-26 23:31:20 +0100 | [diff] [blame] | 125 | #define TOP_ENTRIES (MAX_DOMAIN_PAGES / P2M_ENTRIES_PER_PAGE) |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 126 | |
Jeremy Fitzhardinge | cf0923e | 2008-05-26 23:31:20 +0100 | [diff] [blame] | 127 | /* Placeholder for holes in the address space */ |
Jeremy Fitzhardinge | cbcd79c | 2008-07-08 15:06:27 -0700 | [diff] [blame] | 128 | static unsigned long p2m_missing[P2M_ENTRIES_PER_PAGE] __page_aligned_data = |
Jeremy Fitzhardinge | cf0923e | 2008-05-26 23:31:20 +0100 | [diff] [blame] | 129 | { [ 0 ... P2M_ENTRIES_PER_PAGE-1 ] = ~0UL }; |
| 130 | |
| 131 | /* Array of pointers to pages containing p2m entries */ |
Jeremy Fitzhardinge | cbcd79c | 2008-07-08 15:06:27 -0700 | [diff] [blame] | 132 | static unsigned long *p2m_top[TOP_ENTRIES] __page_aligned_data = |
Jeremy Fitzhardinge | cf0923e | 2008-05-26 23:31:20 +0100 | [diff] [blame] | 133 | { [ 0 ... TOP_ENTRIES - 1] = &p2m_missing[0] }; |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 134 | |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 135 | /* Arrays of p2m arrays expressed in mfns used for save/restore */ |
Jeremy Fitzhardinge | cbcd79c | 2008-07-08 15:06:27 -0700 | [diff] [blame] | 136 | static unsigned long p2m_top_mfn[TOP_ENTRIES] __page_aligned_bss; |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 137 | |
Jeremy Fitzhardinge | cbcd79c | 2008-07-08 15:06:27 -0700 | [diff] [blame] | 138 | static unsigned long p2m_top_mfn_list[TOP_ENTRIES / P2M_ENTRIES_PER_PAGE] |
| 139 | __page_aligned_bss; |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 140 | |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 141 | static inline unsigned p2m_top_index(unsigned long pfn) |
| 142 | { |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 143 | BUG_ON(pfn >= MAX_DOMAIN_PAGES); |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 144 | return pfn / P2M_ENTRIES_PER_PAGE; |
| 145 | } |
| 146 | |
| 147 | static inline unsigned p2m_index(unsigned long pfn) |
| 148 | { |
| 149 | return pfn % P2M_ENTRIES_PER_PAGE; |
| 150 | } |
| 151 | |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 152 | /* Build the parallel p2m_top_mfn structures */ |
| 153 | void xen_setup_mfn_list_list(void) |
| 154 | { |
| 155 | unsigned pfn, idx; |
| 156 | |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 157 | for (pfn = 0; pfn < MAX_DOMAIN_PAGES; pfn += P2M_ENTRIES_PER_PAGE) { |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 158 | unsigned topidx = p2m_top_index(pfn); |
| 159 | |
| 160 | p2m_top_mfn[topidx] = virt_to_mfn(p2m_top[topidx]); |
| 161 | } |
| 162 | |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 163 | for (idx = 0; idx < ARRAY_SIZE(p2m_top_mfn_list); idx++) { |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 164 | unsigned topidx = idx * P2M_ENTRIES_PER_PAGE; |
| 165 | p2m_top_mfn_list[idx] = virt_to_mfn(&p2m_top_mfn[topidx]); |
| 166 | } |
| 167 | |
| 168 | BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info); |
| 169 | |
| 170 | HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = |
| 171 | virt_to_mfn(p2m_top_mfn_list); |
| 172 | HYPERVISOR_shared_info->arch.max_pfn = xen_start_info->nr_pages; |
| 173 | } |
| 174 | |
| 175 | /* Set up p2m_top to point to the domain-builder provided p2m pages */ |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 176 | void __init xen_build_dynamic_phys_to_machine(void) |
| 177 | { |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 178 | unsigned long *mfn_list = (unsigned long *)xen_start_info->mfn_list; |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 179 | unsigned long max_pfn = min(MAX_DOMAIN_PAGES, xen_start_info->nr_pages); |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 180 | unsigned pfn; |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 181 | |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 182 | for (pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES_PER_PAGE) { |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 183 | unsigned topidx = p2m_top_index(pfn); |
| 184 | |
| 185 | p2m_top[topidx] = &mfn_list[pfn]; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | unsigned long get_phys_to_machine(unsigned long pfn) |
| 190 | { |
| 191 | unsigned topidx, idx; |
| 192 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 193 | if (unlikely(pfn >= MAX_DOMAIN_PAGES)) |
| 194 | return INVALID_P2M_ENTRY; |
| 195 | |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 196 | topidx = p2m_top_index(pfn); |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 197 | idx = p2m_index(pfn); |
| 198 | return p2m_top[topidx][idx]; |
| 199 | } |
Ingo Molnar | 15ce6005 | 2008-06-02 13:20:11 +0200 | [diff] [blame] | 200 | EXPORT_SYMBOL_GPL(get_phys_to_machine); |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 201 | |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 202 | static void alloc_p2m(unsigned long **pp, unsigned long *mfnp) |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 203 | { |
| 204 | unsigned long *p; |
| 205 | unsigned i; |
| 206 | |
| 207 | p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL); |
| 208 | BUG_ON(p == NULL); |
| 209 | |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 210 | for (i = 0; i < P2M_ENTRIES_PER_PAGE; i++) |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 211 | p[i] = INVALID_P2M_ENTRY; |
| 212 | |
Jeremy Fitzhardinge | cf0923e | 2008-05-26 23:31:20 +0100 | [diff] [blame] | 213 | if (cmpxchg(pp, p2m_missing, p) != p2m_missing) |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 214 | free_page((unsigned long)p); |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 215 | else |
| 216 | *mfnp = virt_to_mfn(p); |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void set_phys_to_machine(unsigned long pfn, unsigned long mfn) |
| 220 | { |
| 221 | unsigned topidx, idx; |
| 222 | |
| 223 | if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) { |
| 224 | BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY); |
| 225 | return; |
| 226 | } |
| 227 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 228 | if (unlikely(pfn >= MAX_DOMAIN_PAGES)) { |
| 229 | BUG_ON(mfn != INVALID_P2M_ENTRY); |
| 230 | return; |
| 231 | } |
| 232 | |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 233 | topidx = p2m_top_index(pfn); |
Jeremy Fitzhardinge | cf0923e | 2008-05-26 23:31:20 +0100 | [diff] [blame] | 234 | if (p2m_top[topidx] == p2m_missing) { |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 235 | /* no need to allocate a page to store an invalid entry */ |
| 236 | if (mfn == INVALID_P2M_ENTRY) |
| 237 | return; |
Jeremy Fitzhardinge | d5edbc1 | 2008-05-26 23:31:22 +0100 | [diff] [blame] | 238 | alloc_p2m(&p2m_top[topidx], &p2m_top_mfn[topidx]); |
Jeremy Fitzhardinge | d451bb7 | 2008-05-26 23:31:18 +0100 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | idx = p2m_index(pfn); |
| 242 | p2m_top[topidx][idx] = mfn; |
| 243 | } |
| 244 | |
Jeremy Fitzhardinge | ce803e7 | 2008-07-08 15:06:55 -0700 | [diff] [blame] | 245 | xmaddr_t arbitrary_virt_to_machine(void *vaddr) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 246 | { |
Jeremy Fitzhardinge | ce803e7 | 2008-07-08 15:06:55 -0700 | [diff] [blame] | 247 | unsigned long address = (unsigned long)vaddr; |
Harvey Harrison | da7bfc5 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 248 | unsigned int level; |
Chris Lalancette | 9f32d21 | 2008-10-23 17:40:25 -0700 | [diff] [blame] | 249 | pte_t *pte; |
| 250 | unsigned offset; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 251 | |
Chris Lalancette | 9f32d21 | 2008-10-23 17:40:25 -0700 | [diff] [blame] | 252 | /* |
| 253 | * if the PFN is in the linear mapped vaddr range, we can just use |
| 254 | * the (quick) virt_to_machine() p2m lookup |
| 255 | */ |
| 256 | if (virt_addr_valid(vaddr)) |
| 257 | return virt_to_machine(vaddr); |
| 258 | |
| 259 | /* otherwise we have to do a (slower) full page-table walk */ |
| 260 | |
| 261 | pte = lookup_address(address, &level); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 262 | BUG_ON(pte == NULL); |
Chris Lalancette | 9f32d21 | 2008-10-23 17:40:25 -0700 | [diff] [blame] | 263 | offset = address & ~PAGE_MASK; |
Jeremy Fitzhardinge | ebd879e | 2008-07-08 15:06:54 -0700 | [diff] [blame] | 264 | return XMADDR(((phys_addr_t)pte_mfn(*pte) << PAGE_SHIFT) + offset); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void make_lowmem_page_readonly(void *vaddr) |
| 268 | { |
| 269 | pte_t *pte, ptev; |
| 270 | unsigned long address = (unsigned long)vaddr; |
Harvey Harrison | da7bfc5 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 271 | unsigned int level; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 272 | |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame] | 273 | pte = lookup_address(address, &level); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 274 | BUG_ON(pte == NULL); |
| 275 | |
| 276 | ptev = pte_wrprotect(*pte); |
| 277 | |
| 278 | if (HYPERVISOR_update_va_mapping(address, ptev, 0)) |
| 279 | BUG(); |
| 280 | } |
| 281 | |
| 282 | void make_lowmem_page_readwrite(void *vaddr) |
| 283 | { |
| 284 | pte_t *pte, ptev; |
| 285 | unsigned long address = (unsigned long)vaddr; |
Harvey Harrison | da7bfc5 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 286 | unsigned int level; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 287 | |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame] | 288 | pte = lookup_address(address, &level); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 289 | BUG_ON(pte == NULL); |
| 290 | |
| 291 | ptev = pte_mkwrite(*pte); |
| 292 | |
| 293 | if (HYPERVISOR_update_va_mapping(address, ptev, 0)) |
| 294 | BUG(); |
| 295 | } |
| 296 | |
| 297 | |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 298 | static bool xen_page_pinned(void *ptr) |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 299 | { |
| 300 | struct page *page = virt_to_page(ptr); |
| 301 | |
| 302 | return PagePinned(page); |
| 303 | } |
| 304 | |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 305 | static void xen_extend_mmu_update(const struct mmu_update *update) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 306 | { |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 307 | struct multicall_space mcs; |
| 308 | struct mmu_update *u; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 309 | |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 310 | mcs = xen_mc_extend_args(__HYPERVISOR_mmu_update, sizeof(*u)); |
| 311 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 312 | if (mcs.mc != NULL) { |
| 313 | ADD_STATS(mmu_update_extended, 1); |
| 314 | ADD_STATS(mmu_update_histo[mcs.mc->args[1]], -1); |
| 315 | |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 316 | mcs.mc->args[1]++; |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 317 | |
| 318 | if (mcs.mc->args[1] < MMU_UPDATE_HISTO) |
| 319 | ADD_STATS(mmu_update_histo[mcs.mc->args[1]], 1); |
| 320 | else |
| 321 | ADD_STATS(mmu_update_histo[0], 1); |
| 322 | } else { |
| 323 | ADD_STATS(mmu_update, 1); |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 324 | mcs = __xen_mc_entry(sizeof(*u)); |
| 325 | MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, DOMID_SELF); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 326 | ADD_STATS(mmu_update_histo[1], 1); |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | u = mcs.args; |
| 330 | *u = *update; |
| 331 | } |
| 332 | |
| 333 | void xen_set_pmd_hyper(pmd_t *ptr, pmd_t val) |
| 334 | { |
| 335 | struct mmu_update u; |
| 336 | |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 337 | preempt_disable(); |
| 338 | |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 339 | xen_mc_batch(); |
| 340 | |
Jeremy Fitzhardinge | ce803e7 | 2008-07-08 15:06:55 -0700 | [diff] [blame] | 341 | /* ptr may be ioremapped for 64-bit pagetable setup */ |
| 342 | u.ptr = arbitrary_virt_to_machine(ptr).maddr; |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 343 | u.val = pmd_val_ma(val); |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 344 | xen_extend_mmu_update(&u); |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 345 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 346 | ADD_STATS(pmd_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); |
| 347 | |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 348 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
| 349 | |
| 350 | preempt_enable(); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 353 | void xen_set_pmd(pmd_t *ptr, pmd_t val) |
| 354 | { |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 355 | ADD_STATS(pmd_update, 1); |
| 356 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 357 | /* If page is not pinned, we can just update the entry |
| 358 | directly */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 359 | if (!xen_page_pinned(ptr)) { |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 360 | *ptr = val; |
| 361 | return; |
| 362 | } |
| 363 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 364 | ADD_STATS(pmd_update_pinned, 1); |
| 365 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 366 | xen_set_pmd_hyper(ptr, val); |
| 367 | } |
| 368 | |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 369 | /* |
| 370 | * Associate a virtual page frame with a given physical page frame |
| 371 | * and protection flags for that frame. |
| 372 | */ |
| 373 | void set_pte_mfn(unsigned long vaddr, unsigned long mfn, pgprot_t flags) |
| 374 | { |
Jeremy Fitzhardinge | 836fe2f | 2008-07-08 15:06:58 -0700 | [diff] [blame] | 375 | set_pte_vaddr(vaddr, mfn_pte(mfn, flags)); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | void xen_set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 379 | pte_t *ptep, pte_t pteval) |
| 380 | { |
Jeremy Fitzhardinge | 2bd5003 | 2008-04-02 10:54:10 -0700 | [diff] [blame] | 381 | /* updates to init_mm may be done without lock */ |
| 382 | if (mm == &init_mm) |
| 383 | preempt_disable(); |
| 384 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 385 | ADD_STATS(set_pte_at, 1); |
| 386 | // ADD_STATS(set_pte_at_pinned, xen_page_pinned(ptep)); |
| 387 | ADD_STATS(set_pte_at_current, mm == current->mm); |
| 388 | ADD_STATS(set_pte_at_kernel, mm == &init_mm); |
| 389 | |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 390 | if (mm == current->mm || mm == &init_mm) { |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 391 | if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU) { |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 392 | struct multicall_space mcs; |
| 393 | mcs = xen_mc_entry(0); |
| 394 | |
| 395 | MULTI_update_va_mapping(mcs.mc, addr, pteval, 0); |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 396 | ADD_STATS(set_pte_at_batched, 1); |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 397 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
Jeremy Fitzhardinge | 2bd5003 | 2008-04-02 10:54:10 -0700 | [diff] [blame] | 398 | goto out; |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 399 | } else |
| 400 | if (HYPERVISOR_update_va_mapping(addr, pteval, 0) == 0) |
Jeremy Fitzhardinge | 2bd5003 | 2008-04-02 10:54:10 -0700 | [diff] [blame] | 401 | goto out; |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 402 | } |
| 403 | xen_set_pte(ptep, pteval); |
Jeremy Fitzhardinge | 2bd5003 | 2008-04-02 10:54:10 -0700 | [diff] [blame] | 404 | |
| 405 | out: |
| 406 | if (mm == &init_mm) |
| 407 | preempt_enable(); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 410 | pte_t xen_ptep_modify_prot_start(struct mm_struct *mm, |
| 411 | unsigned long addr, pte_t *ptep) |
Jeremy Fitzhardinge | e57778a | 2008-06-16 04:30:02 -0700 | [diff] [blame] | 412 | { |
| 413 | /* Just return the pte as-is. We preserve the bits on commit */ |
| 414 | return *ptep; |
| 415 | } |
| 416 | |
| 417 | void xen_ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr, |
| 418 | pte_t *ptep, pte_t pte) |
| 419 | { |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 420 | struct mmu_update u; |
Jeremy Fitzhardinge | e57778a | 2008-06-16 04:30:02 -0700 | [diff] [blame] | 421 | |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 422 | xen_mc_batch(); |
| 423 | |
Chris Lalancette | 9f32d21 | 2008-10-23 17:40:25 -0700 | [diff] [blame] | 424 | u.ptr = arbitrary_virt_to_machine(ptep).maddr | MMU_PT_UPDATE_PRESERVE_AD; |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 425 | u.val = pte_val_ma(pte); |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 426 | xen_extend_mmu_update(&u); |
Jeremy Fitzhardinge | e57778a | 2008-06-16 04:30:02 -0700 | [diff] [blame] | 427 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 428 | ADD_STATS(prot_commit, 1); |
| 429 | ADD_STATS(prot_commit_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); |
| 430 | |
Jeremy Fitzhardinge | e57778a | 2008-06-16 04:30:02 -0700 | [diff] [blame] | 431 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
| 432 | } |
| 433 | |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 434 | /* Assume pteval_t is equivalent to all the other *val_t types. */ |
| 435 | static pteval_t pte_mfn_to_pfn(pteval_t val) |
| 436 | { |
| 437 | if (val & _PAGE_PRESENT) { |
Jeremy Fitzhardinge | 59438c9 | 2008-07-21 22:59:42 -0700 | [diff] [blame] | 438 | unsigned long mfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; |
Jeremy Fitzhardinge | 77be1fa | 2008-07-21 22:59:56 -0700 | [diff] [blame] | 439 | pteval_t flags = val & PTE_FLAGS_MASK; |
Jeremy Fitzhardinge | d8355ac | 2008-07-03 22:10:18 -0700 | [diff] [blame] | 440 | val = ((pteval_t)mfn_to_pfn(mfn) << PAGE_SHIFT) | flags; |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | return val; |
| 444 | } |
| 445 | |
| 446 | static pteval_t pte_pfn_to_mfn(pteval_t val) |
| 447 | { |
| 448 | if (val & _PAGE_PRESENT) { |
Jeremy Fitzhardinge | 59438c9 | 2008-07-21 22:59:42 -0700 | [diff] [blame] | 449 | unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; |
Jeremy Fitzhardinge | 77be1fa | 2008-07-21 22:59:56 -0700 | [diff] [blame] | 450 | pteval_t flags = val & PTE_FLAGS_MASK; |
Jeremy Fitzhardinge | d8355ac | 2008-07-03 22:10:18 -0700 | [diff] [blame] | 451 | val = ((pteval_t)pfn_to_mfn(pfn) << PAGE_SHIFT) | flags; |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | return val; |
| 455 | } |
| 456 | |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 457 | pteval_t xen_pte_val(pte_t pte) |
| 458 | { |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 459 | return pte_mfn_to_pfn(pte.pte); |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | pgdval_t xen_pgd_val(pgd_t pgd) |
| 463 | { |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 464 | return pte_mfn_to_pfn(pgd.pgd); |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | pte_t xen_make_pte(pteval_t pte) |
| 468 | { |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 469 | pte = pte_pfn_to_mfn(pte); |
| 470 | return native_make_pte(pte); |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | pgd_t xen_make_pgd(pgdval_t pgd) |
| 474 | { |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 475 | pgd = pte_pfn_to_mfn(pgd); |
| 476 | return native_make_pgd(pgd); |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | pmdval_t xen_pmd_val(pmd_t pmd) |
| 480 | { |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 481 | return pte_mfn_to_pfn(pmd.pmd); |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 482 | } |
Jeremy Fitzhardinge | 2849914 | 2008-05-09 12:05:57 +0100 | [diff] [blame] | 483 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 484 | void xen_set_pud_hyper(pud_t *ptr, pud_t val) |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 485 | { |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 486 | struct mmu_update u; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 487 | |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 488 | preempt_disable(); |
| 489 | |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 490 | xen_mc_batch(); |
| 491 | |
Jeremy Fitzhardinge | ce803e7 | 2008-07-08 15:06:55 -0700 | [diff] [blame] | 492 | /* ptr may be ioremapped for 64-bit pagetable setup */ |
| 493 | u.ptr = arbitrary_virt_to_machine(ptr).maddr; |
Jeremy Fitzhardinge | 400d349 | 2008-06-16 04:30:03 -0700 | [diff] [blame] | 494 | u.val = pud_val_ma(val); |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 495 | xen_extend_mmu_update(&u); |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 496 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 497 | ADD_STATS(pud_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); |
| 498 | |
Jeremy Fitzhardinge | d66bf8f | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 499 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
| 500 | |
| 501 | preempt_enable(); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 504 | void xen_set_pud(pud_t *ptr, pud_t val) |
| 505 | { |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 506 | ADD_STATS(pud_update, 1); |
| 507 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 508 | /* If page is not pinned, we can just update the entry |
| 509 | directly */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 510 | if (!xen_page_pinned(ptr)) { |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 511 | *ptr = val; |
| 512 | return; |
| 513 | } |
| 514 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 515 | ADD_STATS(pud_update_pinned, 1); |
| 516 | |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 517 | xen_set_pud_hyper(ptr, val); |
| 518 | } |
| 519 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 520 | void xen_set_pte(pte_t *ptep, pte_t pte) |
| 521 | { |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 522 | ADD_STATS(pte_update, 1); |
| 523 | // ADD_STATS(pte_update_pinned, xen_page_pinned(ptep)); |
| 524 | ADD_STATS(pte_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); |
| 525 | |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 526 | #ifdef CONFIG_X86_PAE |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 527 | ptep->pte_high = pte.pte_high; |
| 528 | smp_wmb(); |
| 529 | ptep->pte_low = pte.pte_low; |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 530 | #else |
| 531 | *ptep = pte; |
| 532 | #endif |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 535 | #ifdef CONFIG_X86_PAE |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 536 | void xen_set_pte_atomic(pte_t *ptep, pte_t pte) |
| 537 | { |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 538 | set_64bit((u64 *)ptep, native_pte_val(pte)); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 542 | { |
| 543 | ptep->pte_low = 0; |
| 544 | smp_wmb(); /* make sure low gets written first */ |
| 545 | ptep->pte_high = 0; |
| 546 | } |
| 547 | |
| 548 | void xen_pmd_clear(pmd_t *pmdp) |
| 549 | { |
Jeremy Fitzhardinge | e2426cf | 2008-05-31 01:24:27 +0100 | [diff] [blame] | 550 | set_pmd(pmdp, __pmd(0)); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 551 | } |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 552 | #endif /* CONFIG_X86_PAE */ |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 553 | |
Jeremy Fitzhardinge | abf3303 | 2008-03-17 16:37:07 -0700 | [diff] [blame] | 554 | pmd_t xen_make_pmd(pmdval_t pmd) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 555 | { |
Jeremy Fitzhardinge | ebb9cfe | 2008-06-16 15:01:56 -0700 | [diff] [blame] | 556 | pmd = pte_pfn_to_mfn(pmd); |
Jeremy Fitzhardinge | 947a69c | 2008-03-17 16:37:09 -0700 | [diff] [blame] | 557 | return native_make_pmd(pmd); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 558 | } |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 559 | |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 560 | #if PAGETABLE_LEVELS == 4 |
| 561 | pudval_t xen_pud_val(pud_t pud) |
| 562 | { |
| 563 | return pte_mfn_to_pfn(pud.pud); |
| 564 | } |
| 565 | |
| 566 | pud_t xen_make_pud(pudval_t pud) |
| 567 | { |
| 568 | pud = pte_pfn_to_mfn(pud); |
| 569 | |
| 570 | return native_make_pud(pud); |
| 571 | } |
| 572 | |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 573 | pgd_t *xen_get_user_pgd(pgd_t *pgd) |
| 574 | { |
| 575 | pgd_t *pgd_page = (pgd_t *)(((unsigned long)pgd) & PAGE_MASK); |
| 576 | unsigned offset = pgd - pgd_page; |
| 577 | pgd_t *user_ptr = NULL; |
| 578 | |
| 579 | if (offset < pgd_index(USER_LIMIT)) { |
| 580 | struct page *page = virt_to_page(pgd_page); |
| 581 | user_ptr = (pgd_t *)page->private; |
| 582 | if (user_ptr) |
| 583 | user_ptr += offset; |
| 584 | } |
| 585 | |
| 586 | return user_ptr; |
| 587 | } |
| 588 | |
| 589 | static void __xen_set_pgd_hyper(pgd_t *ptr, pgd_t val) |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 590 | { |
| 591 | struct mmu_update u; |
| 592 | |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 593 | u.ptr = virt_to_machine(ptr).maddr; |
| 594 | u.val = pgd_val_ma(val); |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 595 | xen_extend_mmu_update(&u); |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /* |
| 599 | * Raw hypercall-based set_pgd, intended for in early boot before |
| 600 | * there's a page structure. This implies: |
| 601 | * 1. The only existing pagetable is the kernel's |
| 602 | * 2. It is always pinned |
| 603 | * 3. It has no user pagetable attached to it |
| 604 | */ |
| 605 | void __init xen_set_pgd_hyper(pgd_t *ptr, pgd_t val) |
| 606 | { |
| 607 | preempt_disable(); |
| 608 | |
| 609 | xen_mc_batch(); |
| 610 | |
| 611 | __xen_set_pgd_hyper(ptr, val); |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 612 | |
| 613 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
| 614 | |
| 615 | preempt_enable(); |
| 616 | } |
| 617 | |
| 618 | void xen_set_pgd(pgd_t *ptr, pgd_t val) |
| 619 | { |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 620 | pgd_t *user_ptr = xen_get_user_pgd(ptr); |
| 621 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 622 | ADD_STATS(pgd_update, 1); |
| 623 | |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 624 | /* If page is not pinned, we can just update the entry |
| 625 | directly */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 626 | if (!xen_page_pinned(ptr)) { |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 627 | *ptr = val; |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 628 | if (user_ptr) { |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 629 | WARN_ON(xen_page_pinned(user_ptr)); |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 630 | *user_ptr = val; |
| 631 | } |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 635 | ADD_STATS(pgd_update_pinned, 1); |
| 636 | ADD_STATS(pgd_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); |
| 637 | |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 638 | /* If it's pinned, then we can at least batch the kernel and |
| 639 | user updates together. */ |
| 640 | xen_mc_batch(); |
| 641 | |
| 642 | __xen_set_pgd_hyper(ptr, val); |
| 643 | if (user_ptr) |
| 644 | __xen_set_pgd_hyper(user_ptr, val); |
| 645 | |
| 646 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
Jeremy Fitzhardinge | f6e5873 | 2008-07-08 15:06:38 -0700 | [diff] [blame] | 647 | } |
| 648 | #endif /* PAGETABLE_LEVELS == 4 */ |
| 649 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 650 | /* |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 651 | * (Yet another) pagetable walker. This one is intended for pinning a |
| 652 | * pagetable. This means that it walks a pagetable and calls the |
| 653 | * callback function on each page it finds making up the page table, |
| 654 | * at every level. It walks the entire pagetable, but it only bothers |
| 655 | * pinning pte pages which are below limit. In the normal case this |
| 656 | * will be STACK_TOP_MAX, but at boot we need to pin up to |
| 657 | * FIXADDR_TOP. |
| 658 | * |
| 659 | * For 32-bit the important bit is that we don't pin beyond there, |
| 660 | * because then we start getting into Xen's ptes. |
| 661 | * |
| 662 | * For 64-bit, we must skip the Xen hole in the middle of the address |
| 663 | * space, just after the big x86-64 virtual hole. |
| 664 | */ |
Ian Campbell | 86bbc2c | 2008-11-21 10:21:33 +0000 | [diff] [blame] | 665 | static int __xen_pgd_walk(struct mm_struct *mm, pgd_t *pgd, |
| 666 | int (*func)(struct mm_struct *mm, struct page *, |
| 667 | enum pt_level), |
| 668 | unsigned long limit) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 669 | { |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 670 | int flush = 0; |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 671 | unsigned hole_low, hole_high; |
| 672 | unsigned pgdidx_limit, pudidx_limit, pmdidx_limit; |
| 673 | unsigned pgdidx, pudidx, pmdidx; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 674 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 675 | /* The limit is the last byte to be touched */ |
| 676 | limit--; |
| 677 | BUG_ON(limit >= FIXADDR_TOP); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 678 | |
| 679 | if (xen_feature(XENFEAT_auto_translated_physmap)) |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 680 | return 0; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 681 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 682 | /* |
| 683 | * 64-bit has a great big hole in the middle of the address |
| 684 | * space, which contains the Xen mappings. On 32-bit these |
| 685 | * will end up making a zero-sized hole and so is a no-op. |
| 686 | */ |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 687 | hole_low = pgd_index(USER_LIMIT); |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 688 | hole_high = pgd_index(PAGE_OFFSET); |
| 689 | |
| 690 | pgdidx_limit = pgd_index(limit); |
| 691 | #if PTRS_PER_PUD > 1 |
| 692 | pudidx_limit = pud_index(limit); |
| 693 | #else |
| 694 | pudidx_limit = 0; |
| 695 | #endif |
| 696 | #if PTRS_PER_PMD > 1 |
| 697 | pmdidx_limit = pmd_index(limit); |
| 698 | #else |
| 699 | pmdidx_limit = 0; |
| 700 | #endif |
| 701 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 702 | for (pgdidx = 0; pgdidx <= pgdidx_limit; pgdidx++) { |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 703 | pud_t *pud; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 704 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 705 | if (pgdidx >= hole_low && pgdidx < hole_high) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 706 | continue; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 707 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 708 | if (!pgd_val(pgd[pgdidx])) |
| 709 | continue; |
| 710 | |
| 711 | pud = pud_offset(&pgd[pgdidx], 0); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 712 | |
| 713 | if (PTRS_PER_PUD > 1) /* not folded */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 714 | flush |= (*func)(mm, virt_to_page(pud), PT_PUD); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 715 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 716 | for (pudidx = 0; pudidx < PTRS_PER_PUD; pudidx++) { |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 717 | pmd_t *pmd; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 718 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 719 | if (pgdidx == pgdidx_limit && |
| 720 | pudidx > pudidx_limit) |
| 721 | goto out; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 722 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 723 | if (pud_none(pud[pudidx])) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 724 | continue; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 725 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 726 | pmd = pmd_offset(&pud[pudidx], 0); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 727 | |
| 728 | if (PTRS_PER_PMD > 1) /* not folded */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 729 | flush |= (*func)(mm, virt_to_page(pmd), PT_PMD); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 730 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 731 | for (pmdidx = 0; pmdidx < PTRS_PER_PMD; pmdidx++) { |
| 732 | struct page *pte; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 733 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 734 | if (pgdidx == pgdidx_limit && |
| 735 | pudidx == pudidx_limit && |
| 736 | pmdidx > pmdidx_limit) |
| 737 | goto out; |
| 738 | |
| 739 | if (pmd_none(pmd[pmdidx])) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 740 | continue; |
| 741 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 742 | pte = pmd_page(pmd[pmdidx]); |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 743 | flush |= (*func)(mm, pte, PT_PTE); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
Jeremy Fitzhardinge | 11ad93e | 2008-08-19 13:32:51 -0700 | [diff] [blame] | 747 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 748 | out: |
Jeremy Fitzhardinge | 11ad93e | 2008-08-19 13:32:51 -0700 | [diff] [blame] | 749 | /* Do the top level last, so that the callbacks can use it as |
| 750 | a cue to do final things like tlb flushes. */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 751 | flush |= (*func)(mm, virt_to_page(pgd), PT_PGD); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 752 | |
| 753 | return flush; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Ian Campbell | 86bbc2c | 2008-11-21 10:21:33 +0000 | [diff] [blame] | 756 | static int xen_pgd_walk(struct mm_struct *mm, |
| 757 | int (*func)(struct mm_struct *mm, struct page *, |
| 758 | enum pt_level), |
| 759 | unsigned long limit) |
| 760 | { |
| 761 | return __xen_pgd_walk(mm, mm->pgd, func, limit); |
| 762 | } |
| 763 | |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 764 | /* If we're using split pte locks, then take the page's lock and |
| 765 | return a pointer to it. Otherwise return NULL. */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 766 | static spinlock_t *xen_pte_lock(struct page *page, struct mm_struct *mm) |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 767 | { |
| 768 | spinlock_t *ptl = NULL; |
| 769 | |
Jeremy Fitzhardinge | f7d0b92 | 2008-09-09 15:43:22 -0700 | [diff] [blame] | 770 | #if USE_SPLIT_PTLOCKS |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 771 | ptl = __pte_lockptr(page); |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 772 | spin_lock_nest_lock(ptl, &mm->page_table_lock); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 773 | #endif |
| 774 | |
| 775 | return ptl; |
| 776 | } |
| 777 | |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 778 | static void xen_pte_unlock(void *v) |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 779 | { |
| 780 | spinlock_t *ptl = v; |
| 781 | spin_unlock(ptl); |
| 782 | } |
| 783 | |
| 784 | static void xen_do_pin(unsigned level, unsigned long pfn) |
| 785 | { |
| 786 | struct mmuext_op *op; |
| 787 | struct multicall_space mcs; |
| 788 | |
| 789 | mcs = __xen_mc_entry(sizeof(*op)); |
| 790 | op = mcs.args; |
| 791 | op->cmd = level; |
| 792 | op->arg1.mfn = pfn_to_mfn(pfn); |
| 793 | MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF); |
| 794 | } |
| 795 | |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 796 | static int xen_pin_page(struct mm_struct *mm, struct page *page, |
| 797 | enum pt_level level) |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 798 | { |
Christoph Lameter | d60cd46 | 2008-04-28 02:12:51 -0700 | [diff] [blame] | 799 | unsigned pgfl = TestSetPagePinned(page); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 800 | int flush; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 801 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 802 | if (pgfl) |
| 803 | flush = 0; /* already pinned */ |
| 804 | else if (PageHighMem(page)) |
| 805 | /* kmaps need flushing if we found an unpinned |
| 806 | highpage */ |
| 807 | flush = 1; |
| 808 | else { |
| 809 | void *pt = lowmem_page_address(page); |
| 810 | unsigned long pfn = page_to_pfn(page); |
| 811 | struct multicall_space mcs = __xen_mc_entry(0); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 812 | spinlock_t *ptl; |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 813 | |
| 814 | flush = 0; |
| 815 | |
Jeremy Fitzhardinge | 11ad93e | 2008-08-19 13:32:51 -0700 | [diff] [blame] | 816 | /* |
| 817 | * We need to hold the pagetable lock between the time |
| 818 | * we make the pagetable RO and when we actually pin |
| 819 | * it. If we don't, then other users may come in and |
| 820 | * attempt to update the pagetable by writing it, |
| 821 | * which will fail because the memory is RO but not |
| 822 | * pinned, so Xen won't do the trap'n'emulate. |
| 823 | * |
| 824 | * If we're using split pte locks, we can't hold the |
| 825 | * entire pagetable's worth of locks during the |
| 826 | * traverse, because we may wrap the preempt count (8 |
| 827 | * bits). The solution is to mark RO and pin each PTE |
| 828 | * page while holding the lock. This means the number |
| 829 | * of locks we end up holding is never more than a |
| 830 | * batch size (~32 entries, at present). |
| 831 | * |
| 832 | * If we're not using split pte locks, we needn't pin |
| 833 | * the PTE pages independently, because we're |
| 834 | * protected by the overall pagetable lock. |
| 835 | */ |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 836 | ptl = NULL; |
| 837 | if (level == PT_PTE) |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 838 | ptl = xen_pte_lock(page, mm); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 839 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 840 | MULTI_update_va_mapping(mcs.mc, (unsigned long)pt, |
| 841 | pfn_pte(pfn, PAGE_KERNEL_RO), |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 842 | level == PT_PGD ? UVMF_TLB_FLUSH : 0); |
| 843 | |
Jeremy Fitzhardinge | 11ad93e | 2008-08-19 13:32:51 -0700 | [diff] [blame] | 844 | if (ptl) { |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 845 | xen_do_pin(MMUEXT_PIN_L1_TABLE, pfn); |
| 846 | |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 847 | /* Queue a deferred unlock for when this batch |
| 848 | is completed. */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 849 | xen_mc_callback(xen_pte_unlock, ptl); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 850 | } |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | return flush; |
| 854 | } |
| 855 | |
| 856 | /* This is called just after a mm has been created, but it has not |
| 857 | been used yet. We need to make sure that its pagetable is all |
| 858 | read-only, and can be pinned. */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 859 | static void __xen_pgd_pin(struct mm_struct *mm, pgd_t *pgd) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 860 | { |
Jeremy Fitzhardinge | d05fdf3 | 2008-10-28 19:23:06 +1100 | [diff] [blame] | 861 | vm_unmap_aliases(); |
| 862 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 863 | xen_mc_batch(); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 864 | |
Ian Campbell | 86bbc2c | 2008-11-21 10:21:33 +0000 | [diff] [blame] | 865 | if (__xen_pgd_walk(mm, pgd, xen_pin_page, USER_LIMIT)) { |
Jeremy Fitzhardinge | d05fdf3 | 2008-10-28 19:23:06 +1100 | [diff] [blame] | 866 | /* re-enable interrupts for flushing */ |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 867 | xen_mc_issue(0); |
Jeremy Fitzhardinge | d05fdf3 | 2008-10-28 19:23:06 +1100 | [diff] [blame] | 868 | |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 869 | kmap_flush_unused(); |
Jeremy Fitzhardinge | d05fdf3 | 2008-10-28 19:23:06 +1100 | [diff] [blame] | 870 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 871 | xen_mc_batch(); |
| 872 | } |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 873 | |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 874 | #ifdef CONFIG_X86_64 |
| 875 | { |
| 876 | pgd_t *user_pgd = xen_get_user_pgd(pgd); |
| 877 | |
| 878 | xen_do_pin(MMUEXT_PIN_L4_TABLE, PFN_DOWN(__pa(pgd))); |
| 879 | |
| 880 | if (user_pgd) { |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 881 | xen_pin_page(mm, virt_to_page(user_pgd), PT_PGD); |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 882 | xen_do_pin(MMUEXT_PIN_L4_TABLE, |
| 883 | PFN_DOWN(__pa(user_pgd))); |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | #else /* CONFIG_X86_32 */ |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 887 | #ifdef CONFIG_X86_PAE |
| 888 | /* Need to make sure unshared kernel PMD is pinnable */ |
Jeremy Fitzhardinge | 47cb2ed | 2008-11-06 13:48:24 -0800 | [diff] [blame] | 889 | xen_pin_page(mm, pgd_page(pgd[pgd_index(TASK_SIZE)]), |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 890 | PT_PMD); |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 891 | #endif |
Jeremy Fitzhardinge | 2849914 | 2008-05-09 12:05:57 +0100 | [diff] [blame] | 892 | xen_do_pin(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(pgd))); |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 893 | #endif /* CONFIG_X86_64 */ |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 894 | xen_mc_issue(0); |
| 895 | } |
| 896 | |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 897 | static void xen_pgd_pin(struct mm_struct *mm) |
| 898 | { |
| 899 | __xen_pgd_pin(mm, mm->pgd); |
| 900 | } |
| 901 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 902 | /* |
| 903 | * On save, we need to pin all pagetables to make sure they get their |
| 904 | * mfns turned into pfns. Search the list for any unpinned pgds and pin |
| 905 | * them (unpinned pgds are not currently in use, probably because the |
| 906 | * process is under construction or destruction). |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 907 | * |
| 908 | * Expected to be called in stop_machine() ("equivalent to taking |
| 909 | * every spinlock in the system"), so the locking doesn't really |
| 910 | * matter all that much. |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 911 | */ |
| 912 | void xen_mm_pin_all(void) |
| 913 | { |
| 914 | unsigned long flags; |
| 915 | struct page *page; |
| 916 | |
| 917 | spin_lock_irqsave(&pgd_lock, flags); |
| 918 | |
| 919 | list_for_each_entry(page, &pgd_list, lru) { |
| 920 | if (!PagePinned(page)) { |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 921 | __xen_pgd_pin(&init_mm, (pgd_t *)page_address(page)); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 922 | SetPageSavePinned(page); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | spin_unlock_irqrestore(&pgd_lock, flags); |
| 927 | } |
| 928 | |
Eduardo Habkost | c1f2f09 | 2008-07-08 15:06:24 -0700 | [diff] [blame] | 929 | /* |
| 930 | * The init_mm pagetable is really pinned as soon as its created, but |
| 931 | * that's before we have page structures to store the bits. So do all |
| 932 | * the book-keeping now. |
| 933 | */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 934 | static __init int xen_mark_pinned(struct mm_struct *mm, struct page *page, |
| 935 | enum pt_level level) |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 936 | { |
| 937 | SetPagePinned(page); |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | void __init xen_mark_init_mm_pinned(void) |
| 942 | { |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 943 | xen_pgd_walk(&init_mm, xen_mark_pinned, FIXADDR_TOP); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 946 | static int xen_unpin_page(struct mm_struct *mm, struct page *page, |
| 947 | enum pt_level level) |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 948 | { |
Christoph Lameter | d60cd46 | 2008-04-28 02:12:51 -0700 | [diff] [blame] | 949 | unsigned pgfl = TestClearPagePinned(page); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 950 | |
| 951 | if (pgfl && !PageHighMem(page)) { |
| 952 | void *pt = lowmem_page_address(page); |
| 953 | unsigned long pfn = page_to_pfn(page); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 954 | spinlock_t *ptl = NULL; |
| 955 | struct multicall_space mcs; |
| 956 | |
Jeremy Fitzhardinge | 11ad93e | 2008-08-19 13:32:51 -0700 | [diff] [blame] | 957 | /* |
| 958 | * Do the converse to pin_page. If we're using split |
| 959 | * pte locks, we must be holding the lock for while |
| 960 | * the pte page is unpinned but still RO to prevent |
| 961 | * concurrent updates from seeing it in this |
| 962 | * partially-pinned state. |
| 963 | */ |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 964 | if (level == PT_PTE) { |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 965 | ptl = xen_pte_lock(page, mm); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 966 | |
Jeremy Fitzhardinge | 11ad93e | 2008-08-19 13:32:51 -0700 | [diff] [blame] | 967 | if (ptl) |
| 968 | xen_do_pin(MMUEXT_UNPIN_TABLE, pfn); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | mcs = __xen_mc_entry(0); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 972 | |
| 973 | MULTI_update_va_mapping(mcs.mc, (unsigned long)pt, |
| 974 | pfn_pte(pfn, PAGE_KERNEL), |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 975 | level == PT_PGD ? UVMF_TLB_FLUSH : 0); |
| 976 | |
| 977 | if (ptl) { |
| 978 | /* unlock when batch completed */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 979 | xen_mc_callback(xen_pte_unlock, ptl); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 980 | } |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | return 0; /* never need to flush on unpin */ |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /* Release a pagetables pages back as normal RW */ |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 987 | static void __xen_pgd_unpin(struct mm_struct *mm, pgd_t *pgd) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 988 | { |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 989 | xen_mc_batch(); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 990 | |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 991 | xen_do_pin(MMUEXT_UNPIN_TABLE, PFN_DOWN(__pa(pgd))); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 992 | |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 993 | #ifdef CONFIG_X86_64 |
| 994 | { |
| 995 | pgd_t *user_pgd = xen_get_user_pgd(pgd); |
| 996 | |
| 997 | if (user_pgd) { |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame^] | 998 | xen_do_pin(MMUEXT_UNPIN_TABLE, |
| 999 | PFN_DOWN(__pa(user_pgd))); |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1000 | xen_unpin_page(mm, virt_to_page(user_pgd), PT_PGD); |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | #endif |
| 1004 | |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 1005 | #ifdef CONFIG_X86_PAE |
| 1006 | /* Need to make sure unshared kernel PMD is unpinned */ |
Jeremy Fitzhardinge | 47cb2ed | 2008-11-06 13:48:24 -0800 | [diff] [blame] | 1007 | xen_unpin_page(mm, pgd_page(pgd[pgd_index(TASK_SIZE)]), |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1008 | PT_PMD); |
Jeremy Fitzhardinge | 5deb30d | 2008-07-08 15:07:06 -0700 | [diff] [blame] | 1009 | #endif |
Jeremy Fitzhardinge | d6182fb | 2008-07-08 15:07:13 -0700 | [diff] [blame] | 1010 | |
Ian Campbell | 86bbc2c | 2008-11-21 10:21:33 +0000 | [diff] [blame] | 1011 | __xen_pgd_walk(mm, pgd, xen_unpin_page, USER_LIMIT); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1012 | |
| 1013 | xen_mc_issue(0); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1016 | static void xen_pgd_unpin(struct mm_struct *mm) |
| 1017 | { |
| 1018 | __xen_pgd_unpin(mm, mm->pgd); |
| 1019 | } |
| 1020 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1021 | /* |
| 1022 | * On resume, undo any pinning done at save, so that the rest of the |
| 1023 | * kernel doesn't see any unexpected pinned pagetables. |
| 1024 | */ |
| 1025 | void xen_mm_unpin_all(void) |
| 1026 | { |
| 1027 | unsigned long flags; |
| 1028 | struct page *page; |
| 1029 | |
| 1030 | spin_lock_irqsave(&pgd_lock, flags); |
| 1031 | |
| 1032 | list_for_each_entry(page, &pgd_list, lru) { |
| 1033 | if (PageSavePinned(page)) { |
| 1034 | BUG_ON(!PagePinned(page)); |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1035 | __xen_pgd_unpin(&init_mm, (pgd_t *)page_address(page)); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1036 | ClearPageSavePinned(page); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | spin_unlock_irqrestore(&pgd_lock, flags); |
| 1041 | } |
| 1042 | |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1043 | void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next) |
| 1044 | { |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1045 | spin_lock(&next->page_table_lock); |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1046 | xen_pgd_pin(next); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1047 | spin_unlock(&next->page_table_lock); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) |
| 1051 | { |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1052 | spin_lock(&mm->page_table_lock); |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1053 | xen_pgd_pin(mm); |
Jeremy Fitzhardinge | f4f97b3 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1054 | spin_unlock(&mm->page_table_lock); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1057 | |
| 1058 | #ifdef CONFIG_SMP |
| 1059 | /* Another cpu may still have their %cr3 pointing at the pagetable, so |
| 1060 | we need to repoint it somewhere else before we can unpin it. */ |
| 1061 | static void drop_other_mm_ref(void *info) |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1062 | { |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1063 | struct mm_struct *mm = info; |
Jeremy Fitzhardinge | ce87b3d | 2008-07-08 15:06:40 -0700 | [diff] [blame] | 1064 | struct mm_struct *active_mm; |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1065 | |
Jeremy Fitzhardinge | ce87b3d | 2008-07-08 15:06:40 -0700 | [diff] [blame] | 1066 | #ifdef CONFIG_X86_64 |
| 1067 | active_mm = read_pda(active_mm); |
| 1068 | #else |
| 1069 | active_mm = __get_cpu_var(cpu_tlbstate).active_mm; |
| 1070 | #endif |
| 1071 | |
| 1072 | if (active_mm == mm) |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1073 | leave_mm(smp_processor_id()); |
Jeremy Fitzhardinge | 9f79991 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 1074 | |
| 1075 | /* If this cpu still has a stale cr3 reference, then make sure |
| 1076 | it has been flushed. */ |
| 1077 | if (x86_read_percpu(xen_current_cr3) == __pa(mm->pgd)) { |
| 1078 | load_cr3(swapper_pg_dir); |
| 1079 | arch_flush_lazy_cpu_mode(); |
| 1080 | } |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1081 | } |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1082 | |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 1083 | static void xen_drop_mm_ref(struct mm_struct *mm) |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1084 | { |
Jeremy Fitzhardinge | 9f79991 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 1085 | cpumask_t mask; |
| 1086 | unsigned cpu; |
| 1087 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1088 | if (current->active_mm == mm) { |
| 1089 | if (current->mm == mm) |
| 1090 | load_cr3(swapper_pg_dir); |
| 1091 | else |
| 1092 | leave_mm(smp_processor_id()); |
Jeremy Fitzhardinge | 9f79991 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 1093 | arch_flush_lazy_cpu_mode(); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Jeremy Fitzhardinge | 9f79991 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 1096 | /* Get the "official" set of cpus referring to our pagetable. */ |
| 1097 | mask = mm->cpu_vm_mask; |
| 1098 | |
| 1099 | /* It's possible that a vcpu may have a stale reference to our |
| 1100 | cr3, because its in lazy mode, and it hasn't yet flushed |
| 1101 | its set of pending hypercalls yet. In this case, we can |
| 1102 | look at its actual current cr3 value, and force it to flush |
| 1103 | if needed. */ |
| 1104 | for_each_online_cpu(cpu) { |
| 1105 | if (per_cpu(xen_current_cr3, cpu) == __pa(mm->pgd)) |
| 1106 | cpu_set(cpu, mask); |
| 1107 | } |
| 1108 | |
| 1109 | if (!cpus_empty(mask)) |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 1110 | smp_call_function_mask(mask, drop_other_mm_ref, mm, 1); |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1111 | } |
| 1112 | #else |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 1113 | static void xen_drop_mm_ref(struct mm_struct *mm) |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1114 | { |
| 1115 | if (current->active_mm == mm) |
| 1116 | load_cr3(swapper_pg_dir); |
| 1117 | } |
| 1118 | #endif |
| 1119 | |
| 1120 | /* |
| 1121 | * While a process runs, Xen pins its pagetables, which means that the |
| 1122 | * hypervisor forces it to be read-only, and it controls all updates |
| 1123 | * to it. This means that all pagetable updates have to go via the |
| 1124 | * hypervisor, which is moderately expensive. |
| 1125 | * |
| 1126 | * Since we're pulling the pagetable down, we switch to use init_mm, |
| 1127 | * unpin old process pagetable and mark it all read-write, which |
| 1128 | * allows further operations on it to be simple memory accesses. |
| 1129 | * |
| 1130 | * The only subtle point is that another CPU may be still using the |
| 1131 | * pagetable because of lazy tlb flushing. This means we need need to |
| 1132 | * switch all CPUs off this pagetable before we can unpin it. |
| 1133 | */ |
| 1134 | void xen_exit_mmap(struct mm_struct *mm) |
| 1135 | { |
| 1136 | get_cpu(); /* make sure we don't move around */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 1137 | xen_drop_mm_ref(mm); |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1138 | put_cpu(); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1139 | |
Jeremy Fitzhardinge | f120f13 | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1140 | spin_lock(&mm->page_table_lock); |
Jeremy Fitzhardinge | df912ea | 2007-09-25 11:50:00 -0700 | [diff] [blame] | 1141 | |
| 1142 | /* pgd may not be pinned in the error exit path of execve */ |
Jeremy Fitzhardinge | 7708ad6 | 2008-08-19 13:34:22 -0700 | [diff] [blame] | 1143 | if (xen_page_pinned(mm->pgd)) |
Jeremy Fitzhardinge | eefb47f | 2008-10-08 13:01:39 -0700 | [diff] [blame] | 1144 | xen_pgd_unpin(mm); |
Jeremy Fitzhardinge | 7426071 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 1145 | |
Jeremy Fitzhardinge | f120f13 | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1146 | spin_unlock(&mm->page_table_lock); |
Jeremy Fitzhardinge | 3b827c1 | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1147 | } |
Jeremy Fitzhardinge | 994025c | 2008-08-20 17:02:19 -0700 | [diff] [blame] | 1148 | |
| 1149 | #ifdef CONFIG_XEN_DEBUG_FS |
| 1150 | |
| 1151 | static struct dentry *d_mmu_debug; |
| 1152 | |
| 1153 | static int __init xen_mmu_debugfs(void) |
| 1154 | { |
| 1155 | struct dentry *d_xen = xen_init_debugfs(); |
| 1156 | |
| 1157 | if (d_xen == NULL) |
| 1158 | return -ENOMEM; |
| 1159 | |
| 1160 | d_mmu_debug = debugfs_create_dir("mmu", d_xen); |
| 1161 | |
| 1162 | debugfs_create_u8("zero_stats", 0644, d_mmu_debug, &zero_stats); |
| 1163 | |
| 1164 | debugfs_create_u32("pgd_update", 0444, d_mmu_debug, &mmu_stats.pgd_update); |
| 1165 | debugfs_create_u32("pgd_update_pinned", 0444, d_mmu_debug, |
| 1166 | &mmu_stats.pgd_update_pinned); |
| 1167 | debugfs_create_u32("pgd_update_batched", 0444, d_mmu_debug, |
| 1168 | &mmu_stats.pgd_update_pinned); |
| 1169 | |
| 1170 | debugfs_create_u32("pud_update", 0444, d_mmu_debug, &mmu_stats.pud_update); |
| 1171 | debugfs_create_u32("pud_update_pinned", 0444, d_mmu_debug, |
| 1172 | &mmu_stats.pud_update_pinned); |
| 1173 | debugfs_create_u32("pud_update_batched", 0444, d_mmu_debug, |
| 1174 | &mmu_stats.pud_update_pinned); |
| 1175 | |
| 1176 | debugfs_create_u32("pmd_update", 0444, d_mmu_debug, &mmu_stats.pmd_update); |
| 1177 | debugfs_create_u32("pmd_update_pinned", 0444, d_mmu_debug, |
| 1178 | &mmu_stats.pmd_update_pinned); |
| 1179 | debugfs_create_u32("pmd_update_batched", 0444, d_mmu_debug, |
| 1180 | &mmu_stats.pmd_update_pinned); |
| 1181 | |
| 1182 | debugfs_create_u32("pte_update", 0444, d_mmu_debug, &mmu_stats.pte_update); |
| 1183 | // debugfs_create_u32("pte_update_pinned", 0444, d_mmu_debug, |
| 1184 | // &mmu_stats.pte_update_pinned); |
| 1185 | debugfs_create_u32("pte_update_batched", 0444, d_mmu_debug, |
| 1186 | &mmu_stats.pte_update_pinned); |
| 1187 | |
| 1188 | debugfs_create_u32("mmu_update", 0444, d_mmu_debug, &mmu_stats.mmu_update); |
| 1189 | debugfs_create_u32("mmu_update_extended", 0444, d_mmu_debug, |
| 1190 | &mmu_stats.mmu_update_extended); |
| 1191 | xen_debugfs_create_u32_array("mmu_update_histo", 0444, d_mmu_debug, |
| 1192 | mmu_stats.mmu_update_histo, 20); |
| 1193 | |
| 1194 | debugfs_create_u32("set_pte_at", 0444, d_mmu_debug, &mmu_stats.set_pte_at); |
| 1195 | debugfs_create_u32("set_pte_at_batched", 0444, d_mmu_debug, |
| 1196 | &mmu_stats.set_pte_at_batched); |
| 1197 | debugfs_create_u32("set_pte_at_current", 0444, d_mmu_debug, |
| 1198 | &mmu_stats.set_pte_at_current); |
| 1199 | debugfs_create_u32("set_pte_at_kernel", 0444, d_mmu_debug, |
| 1200 | &mmu_stats.set_pte_at_kernel); |
| 1201 | |
| 1202 | debugfs_create_u32("prot_commit", 0444, d_mmu_debug, &mmu_stats.prot_commit); |
| 1203 | debugfs_create_u32("prot_commit_batched", 0444, d_mmu_debug, |
| 1204 | &mmu_stats.prot_commit_batched); |
| 1205 | |
| 1206 | return 0; |
| 1207 | } |
| 1208 | fs_initcall(xen_mmu_debugfs); |
| 1209 | |
| 1210 | #endif /* CONFIG_XEN_DEBUG_FS */ |