| .. | .. |
|---|
| 25 | 25 | #define KVM_MMU_CACHE_MIN_PAGES 2 |
|---|
| 26 | 26 | #endif |
|---|
| 27 | 27 | |
|---|
| 28 | | -static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache, |
|---|
| 29 | | - int min, int max) |
|---|
| 30 | | -{ |
|---|
| 31 | | - void *page; |
|---|
| 32 | | - |
|---|
| 33 | | - BUG_ON(max > KVM_NR_MEM_OBJS); |
|---|
| 34 | | - if (cache->nobjs >= min) |
|---|
| 35 | | - return 0; |
|---|
| 36 | | - while (cache->nobjs < max) { |
|---|
| 37 | | - page = (void *)__get_free_page(GFP_KERNEL); |
|---|
| 38 | | - if (!page) |
|---|
| 39 | | - return -ENOMEM; |
|---|
| 40 | | - cache->objects[cache->nobjs++] = page; |
|---|
| 41 | | - } |
|---|
| 42 | | - return 0; |
|---|
| 43 | | -} |
|---|
| 44 | | - |
|---|
| 45 | | -static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc) |
|---|
| 46 | | -{ |
|---|
| 47 | | - while (mc->nobjs) |
|---|
| 48 | | - free_page((unsigned long)mc->objects[--mc->nobjs]); |
|---|
| 49 | | -} |
|---|
| 50 | | - |
|---|
| 51 | | -static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc) |
|---|
| 52 | | -{ |
|---|
| 53 | | - void *p; |
|---|
| 54 | | - |
|---|
| 55 | | - BUG_ON(!mc || !mc->nobjs); |
|---|
| 56 | | - p = mc->objects[--mc->nobjs]; |
|---|
| 57 | | - return p; |
|---|
| 58 | | -} |
|---|
| 59 | | - |
|---|
| 60 | 28 | void kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu) |
|---|
| 61 | 29 | { |
|---|
| 62 | | - mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); |
|---|
| 30 | + kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); |
|---|
| 63 | 31 | } |
|---|
| 64 | 32 | |
|---|
| 65 | 33 | /** |
|---|
| .. | .. |
|---|
| 136 | 104 | static pte_t *kvm_mips_walk_pgd(pgd_t *pgd, struct kvm_mmu_memory_cache *cache, |
|---|
| 137 | 105 | unsigned long addr) |
|---|
| 138 | 106 | { |
|---|
| 107 | + p4d_t *p4d; |
|---|
| 139 | 108 | pud_t *pud; |
|---|
| 140 | 109 | pmd_t *pmd; |
|---|
| 141 | 110 | |
|---|
| .. | .. |
|---|
| 145 | 114 | BUG(); |
|---|
| 146 | 115 | return NULL; |
|---|
| 147 | 116 | } |
|---|
| 148 | | - pud = pud_offset(pgd, addr); |
|---|
| 117 | + p4d = p4d_offset(pgd, addr); |
|---|
| 118 | + pud = pud_offset(p4d, addr); |
|---|
| 149 | 119 | if (pud_none(*pud)) { |
|---|
| 150 | 120 | pmd_t *new_pmd; |
|---|
| 151 | 121 | |
|---|
| 152 | 122 | if (!cache) |
|---|
| 153 | 123 | return NULL; |
|---|
| 154 | | - new_pmd = mmu_memory_cache_alloc(cache); |
|---|
| 124 | + new_pmd = kvm_mmu_memory_cache_alloc(cache); |
|---|
| 155 | 125 | pmd_init((unsigned long)new_pmd, |
|---|
| 156 | 126 | (unsigned long)invalid_pte_table); |
|---|
| 157 | 127 | pud_populate(NULL, pud, new_pmd); |
|---|
| .. | .. |
|---|
| 162 | 132 | |
|---|
| 163 | 133 | if (!cache) |
|---|
| 164 | 134 | return NULL; |
|---|
| 165 | | - new_pte = mmu_memory_cache_alloc(cache); |
|---|
| 135 | + new_pte = kvm_mmu_memory_cache_alloc(cache); |
|---|
| 166 | 136 | clear_page(new_pte); |
|---|
| 167 | 137 | pmd_populate_kernel(NULL, pmd, new_pte); |
|---|
| 168 | 138 | } |
|---|
| 169 | | - return pte_offset(pmd, addr); |
|---|
| 139 | + return pte_offset_kernel(pmd, addr); |
|---|
| 170 | 140 | } |
|---|
| 171 | 141 | |
|---|
| 172 | 142 | /* Caller must hold kvm->mm_lock */ |
|---|
| .. | .. |
|---|
| 185 | 155 | static bool kvm_mips_flush_gpa_pte(pte_t *pte, unsigned long start_gpa, |
|---|
| 186 | 156 | unsigned long end_gpa) |
|---|
| 187 | 157 | { |
|---|
| 188 | | - int i_min = __pte_offset(start_gpa); |
|---|
| 189 | | - int i_max = __pte_offset(end_gpa); |
|---|
| 158 | + int i_min = pte_index(start_gpa); |
|---|
| 159 | + int i_max = pte_index(end_gpa); |
|---|
| 190 | 160 | bool safe_to_remove = (i_min == 0 && i_max == PTRS_PER_PTE - 1); |
|---|
| 191 | 161 | int i; |
|---|
| 192 | 162 | |
|---|
| .. | .. |
|---|
| 204 | 174 | { |
|---|
| 205 | 175 | pte_t *pte; |
|---|
| 206 | 176 | unsigned long end = ~0ul; |
|---|
| 207 | | - int i_min = __pmd_offset(start_gpa); |
|---|
| 208 | | - int i_max = __pmd_offset(end_gpa); |
|---|
| 177 | + int i_min = pmd_index(start_gpa); |
|---|
| 178 | + int i_max = pmd_index(end_gpa); |
|---|
| 209 | 179 | bool safe_to_remove = (i_min == 0 && i_max == PTRS_PER_PMD - 1); |
|---|
| 210 | 180 | int i; |
|---|
| 211 | 181 | |
|---|
| .. | .. |
|---|
| 213 | 183 | if (!pmd_present(pmd[i])) |
|---|
| 214 | 184 | continue; |
|---|
| 215 | 185 | |
|---|
| 216 | | - pte = pte_offset(pmd + i, 0); |
|---|
| 186 | + pte = pte_offset_kernel(pmd + i, 0); |
|---|
| 217 | 187 | if (i == i_max) |
|---|
| 218 | 188 | end = end_gpa; |
|---|
| 219 | 189 | |
|---|
| .. | .. |
|---|
| 232 | 202 | { |
|---|
| 233 | 203 | pmd_t *pmd; |
|---|
| 234 | 204 | unsigned long end = ~0ul; |
|---|
| 235 | | - int i_min = __pud_offset(start_gpa); |
|---|
| 236 | | - int i_max = __pud_offset(end_gpa); |
|---|
| 205 | + int i_min = pud_index(start_gpa); |
|---|
| 206 | + int i_max = pud_index(end_gpa); |
|---|
| 237 | 207 | bool safe_to_remove = (i_min == 0 && i_max == PTRS_PER_PUD - 1); |
|---|
| 238 | 208 | int i; |
|---|
| 239 | 209 | |
|---|
| .. | .. |
|---|
| 258 | 228 | static bool kvm_mips_flush_gpa_pgd(pgd_t *pgd, unsigned long start_gpa, |
|---|
| 259 | 229 | unsigned long end_gpa) |
|---|
| 260 | 230 | { |
|---|
| 231 | + p4d_t *p4d; |
|---|
| 261 | 232 | pud_t *pud; |
|---|
| 262 | 233 | unsigned long end = ~0ul; |
|---|
| 263 | 234 | int i_min = pgd_index(start_gpa); |
|---|
| .. | .. |
|---|
| 269 | 240 | if (!pgd_present(pgd[i])) |
|---|
| 270 | 241 | continue; |
|---|
| 271 | 242 | |
|---|
| 272 | | - pud = pud_offset(pgd + i, 0); |
|---|
| 243 | + p4d = p4d_offset(pgd, 0); |
|---|
| 244 | + pud = pud_offset(p4d + i, 0); |
|---|
| 273 | 245 | if (i == i_max) |
|---|
| 274 | 246 | end = end_gpa; |
|---|
| 275 | 247 | |
|---|
| .. | .. |
|---|
| 308 | 280 | unsigned long end) \ |
|---|
| 309 | 281 | { \ |
|---|
| 310 | 282 | int ret = 0; \ |
|---|
| 311 | | - int i_min = __pte_offset(start); \ |
|---|
| 312 | | - int i_max = __pte_offset(end); \ |
|---|
| 283 | + int i_min = pte_index(start); \ |
|---|
| 284 | + int i_max = pte_index(end); \ |
|---|
| 313 | 285 | int i; \ |
|---|
| 314 | 286 | pte_t old, new; \ |
|---|
| 315 | 287 | \ |
|---|
| .. | .. |
|---|
| 334 | 306 | int ret = 0; \ |
|---|
| 335 | 307 | pte_t *pte; \ |
|---|
| 336 | 308 | unsigned long cur_end = ~0ul; \ |
|---|
| 337 | | - int i_min = __pmd_offset(start); \ |
|---|
| 338 | | - int i_max = __pmd_offset(end); \ |
|---|
| 309 | + int i_min = pmd_index(start); \ |
|---|
| 310 | + int i_max = pmd_index(end); \ |
|---|
| 339 | 311 | int i; \ |
|---|
| 340 | 312 | \ |
|---|
| 341 | 313 | for (i = i_min; i <= i_max; ++i, start = 0) { \ |
|---|
| 342 | 314 | if (!pmd_present(pmd[i])) \ |
|---|
| 343 | 315 | continue; \ |
|---|
| 344 | 316 | \ |
|---|
| 345 | | - pte = pte_offset(pmd + i, 0); \ |
|---|
| 317 | + pte = pte_offset_kernel(pmd + i, 0); \ |
|---|
| 346 | 318 | if (i == i_max) \ |
|---|
| 347 | 319 | cur_end = end; \ |
|---|
| 348 | 320 | \ |
|---|
| .. | .. |
|---|
| 357 | 329 | int ret = 0; \ |
|---|
| 358 | 330 | pmd_t *pmd; \ |
|---|
| 359 | 331 | unsigned long cur_end = ~0ul; \ |
|---|
| 360 | | - int i_min = __pud_offset(start); \ |
|---|
| 361 | | - int i_max = __pud_offset(end); \ |
|---|
| 332 | + int i_min = pud_index(start); \ |
|---|
| 333 | + int i_max = pud_index(end); \ |
|---|
| 362 | 334 | int i; \ |
|---|
| 363 | 335 | \ |
|---|
| 364 | 336 | for (i = i_min; i <= i_max; ++i, start = 0) { \ |
|---|
| .. | .. |
|---|
| 378 | 350 | unsigned long end) \ |
|---|
| 379 | 351 | { \ |
|---|
| 380 | 352 | int ret = 0; \ |
|---|
| 353 | + p4d_t *p4d; \ |
|---|
| 381 | 354 | pud_t *pud; \ |
|---|
| 382 | 355 | unsigned long cur_end = ~0ul; \ |
|---|
| 383 | 356 | int i_min = pgd_index(start); \ |
|---|
| .. | .. |
|---|
| 388 | 361 | if (!pgd_present(pgd[i])) \ |
|---|
| 389 | 362 | continue; \ |
|---|
| 390 | 363 | \ |
|---|
| 391 | | - pud = pud_offset(pgd + i, 0); \ |
|---|
| 364 | + p4d = p4d_offset(pgd, 0); \ |
|---|
| 365 | + pud = pud_offset(p4d + i, 0); \ |
|---|
| 392 | 366 | if (i == i_max) \ |
|---|
| 393 | 367 | cur_end = end; \ |
|---|
| 394 | 368 | \ |
|---|
| .. | .. |
|---|
| 513 | 487 | } |
|---|
| 514 | 488 | |
|---|
| 515 | 489 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, |
|---|
| 516 | | - bool blockable) |
|---|
| 490 | + unsigned flags) |
|---|
| 517 | 491 | { |
|---|
| 518 | 492 | handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL); |
|---|
| 519 | 493 | |
|---|
| .. | .. |
|---|
| 552 | 526 | (pte_dirty(old_pte) && !pte_dirty(hva_pte)); |
|---|
| 553 | 527 | } |
|---|
| 554 | 528 | |
|---|
| 555 | | -void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) |
|---|
| 529 | +int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) |
|---|
| 556 | 530 | { |
|---|
| 557 | 531 | unsigned long end = hva + PAGE_SIZE; |
|---|
| 558 | 532 | int ret; |
|---|
| .. | .. |
|---|
| 560 | 534 | ret = handle_hva_to_gpa(kvm, hva, end, &kvm_set_spte_handler, &pte); |
|---|
| 561 | 535 | if (ret) |
|---|
| 562 | 536 | kvm_mips_callbacks->flush_shadow_all(kvm); |
|---|
| 537 | + return 0; |
|---|
| 563 | 538 | } |
|---|
| 564 | 539 | |
|---|
| 565 | 540 | static int kvm_age_hva_handler(struct kvm *kvm, gfn_t gfn, gfn_t gfn_end, |
|---|
| .. | .. |
|---|
| 705 | 680 | goto out; |
|---|
| 706 | 681 | |
|---|
| 707 | 682 | /* We need a minimum of cached pages ready for page table creation */ |
|---|
| 708 | | - err = mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES, |
|---|
| 709 | | - KVM_NR_MEM_OBJS); |
|---|
| 683 | + err = kvm_mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES); |
|---|
| 710 | 684 | if (err) |
|---|
| 711 | 685 | goto out; |
|---|
| 712 | 686 | |
|---|
| .. | .. |
|---|
| 790 | 764 | int ret; |
|---|
| 791 | 765 | |
|---|
| 792 | 766 | /* We need a minimum of cached pages ready for page table creation */ |
|---|
| 793 | | - ret = mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES, |
|---|
| 794 | | - KVM_NR_MEM_OBJS); |
|---|
| 767 | + ret = kvm_mmu_topup_memory_cache(memcache, KVM_MMU_CACHE_MIN_PAGES); |
|---|
| 795 | 768 | if (ret) |
|---|
| 796 | 769 | return NULL; |
|---|
| 797 | 770 | |
|---|
| .. | .. |
|---|
| 836 | 809 | static bool kvm_mips_flush_gva_pte(pte_t *pte, unsigned long start_gva, |
|---|
| 837 | 810 | unsigned long end_gva) |
|---|
| 838 | 811 | { |
|---|
| 839 | | - int i_min = __pte_offset(start_gva); |
|---|
| 840 | | - int i_max = __pte_offset(end_gva); |
|---|
| 812 | + int i_min = pte_index(start_gva); |
|---|
| 813 | + int i_max = pte_index(end_gva); |
|---|
| 841 | 814 | bool safe_to_remove = (i_min == 0 && i_max == PTRS_PER_PTE - 1); |
|---|
| 842 | 815 | int i; |
|---|
| 843 | 816 | |
|---|
| .. | .. |
|---|
| 862 | 835 | { |
|---|
| 863 | 836 | pte_t *pte; |
|---|
| 864 | 837 | unsigned long end = ~0ul; |
|---|
| 865 | | - int i_min = __pmd_offset(start_gva); |
|---|
| 866 | | - int i_max = __pmd_offset(end_gva); |
|---|
| 838 | + int i_min = pmd_index(start_gva); |
|---|
| 839 | + int i_max = pmd_index(end_gva); |
|---|
| 867 | 840 | bool safe_to_remove = (i_min == 0 && i_max == PTRS_PER_PMD - 1); |
|---|
| 868 | 841 | int i; |
|---|
| 869 | 842 | |
|---|
| .. | .. |
|---|
| 871 | 844 | if (!pmd_present(pmd[i])) |
|---|
| 872 | 845 | continue; |
|---|
| 873 | 846 | |
|---|
| 874 | | - pte = pte_offset(pmd + i, 0); |
|---|
| 847 | + pte = pte_offset_kernel(pmd + i, 0); |
|---|
| 875 | 848 | if (i == i_max) |
|---|
| 876 | 849 | end = end_gva; |
|---|
| 877 | 850 | |
|---|
| .. | .. |
|---|
| 890 | 863 | { |
|---|
| 891 | 864 | pmd_t *pmd; |
|---|
| 892 | 865 | unsigned long end = ~0ul; |
|---|
| 893 | | - int i_min = __pud_offset(start_gva); |
|---|
| 894 | | - int i_max = __pud_offset(end_gva); |
|---|
| 866 | + int i_min = pud_index(start_gva); |
|---|
| 867 | + int i_max = pud_index(end_gva); |
|---|
| 895 | 868 | bool safe_to_remove = (i_min == 0 && i_max == PTRS_PER_PUD - 1); |
|---|
| 896 | 869 | int i; |
|---|
| 897 | 870 | |
|---|
| .. | .. |
|---|
| 916 | 889 | static bool kvm_mips_flush_gva_pgd(pgd_t *pgd, unsigned long start_gva, |
|---|
| 917 | 890 | unsigned long end_gva) |
|---|
| 918 | 891 | { |
|---|
| 892 | + p4d_t *p4d; |
|---|
| 919 | 893 | pud_t *pud; |
|---|
| 920 | 894 | unsigned long end = ~0ul; |
|---|
| 921 | 895 | int i_min = pgd_index(start_gva); |
|---|
| .. | .. |
|---|
| 927 | 901 | if (!pgd_present(pgd[i])) |
|---|
| 928 | 902 | continue; |
|---|
| 929 | 903 | |
|---|
| 930 | | - pud = pud_offset(pgd + i, 0); |
|---|
| 904 | + p4d = p4d_offset(pgd, 0); |
|---|
| 905 | + pud = pud_offset(p4d + i, 0); |
|---|
| 931 | 906 | if (i == i_max) |
|---|
| 932 | 907 | end = end_gva; |
|---|
| 933 | 908 | |
|---|