Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 SUSE Linux Products GmbH. All rights reserved. |
| 3 | * |
| 4 | * Authors: |
| 5 | * Alexander Graf <agraf@suse.de> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License, version 2, as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kvm_host.h> |
| 22 | #include <linux/hash.h> |
| 23 | #include <linux/slab.h> |
| 24 | |
| 25 | #include <asm/kvm_ppc.h> |
| 26 | #include <asm/kvm_book3s.h> |
| 27 | #include <asm/machdep.h> |
| 28 | #include <asm/mmu_context.h> |
| 29 | #include <asm/hw_irq.h> |
| 30 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 31 | #include "trace.h" |
| 32 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 33 | #define PTE_SIZE 12 |
| 34 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 35 | static struct kmem_cache *hpte_cache; |
| 36 | |
| 37 | static inline u64 kvmppc_mmu_hash_pte(u64 eaddr) |
| 38 | { |
| 39 | return hash_64(eaddr >> PTE_SIZE, HPTEG_HASH_BITS_PTE); |
| 40 | } |
| 41 | |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 42 | static inline u64 kvmppc_mmu_hash_pte_long(u64 eaddr) |
| 43 | { |
| 44 | return hash_64((eaddr & 0x0ffff000) >> PTE_SIZE, |
| 45 | HPTEG_HASH_BITS_PTE_LONG); |
| 46 | } |
| 47 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 48 | static inline u64 kvmppc_mmu_hash_vpte(u64 vpage) |
| 49 | { |
| 50 | return hash_64(vpage & 0xfffffffffULL, HPTEG_HASH_BITS_VPTE); |
| 51 | } |
| 52 | |
| 53 | static inline u64 kvmppc_mmu_hash_vpte_long(u64 vpage) |
| 54 | { |
| 55 | return hash_64((vpage & 0xffffff000ULL) >> 12, |
| 56 | HPTEG_HASH_BITS_VPTE_LONG); |
| 57 | } |
| 58 | |
| 59 | void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte) |
| 60 | { |
| 61 | u64 index; |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 62 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 63 | |
Alexander Graf | 4c4eea7 | 2010-08-02 12:51:07 +0200 | [diff] [blame] | 64 | trace_kvm_book3s_mmu_map(pte); |
| 65 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 66 | spin_lock(&vcpu3s->mmu_lock); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 67 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 68 | /* Add to ePTE list */ |
| 69 | index = kvmppc_mmu_hash_pte(pte->pte.eaddr); |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 70 | hlist_add_head_rcu(&pte->list_pte, &vcpu3s->hpte_hash_pte[index]); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 71 | |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 72 | /* Add to ePTE_long list */ |
| 73 | index = kvmppc_mmu_hash_pte_long(pte->pte.eaddr); |
| 74 | hlist_add_head_rcu(&pte->list_pte_long, |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 75 | &vcpu3s->hpte_hash_pte_long[index]); |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 76 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 77 | /* Add to vPTE list */ |
| 78 | index = kvmppc_mmu_hash_vpte(pte->pte.vpage); |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 79 | hlist_add_head_rcu(&pte->list_vpte, &vcpu3s->hpte_hash_vpte[index]); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 80 | |
| 81 | /* Add to vPTE_long list */ |
| 82 | index = kvmppc_mmu_hash_vpte_long(pte->pte.vpage); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 83 | hlist_add_head_rcu(&pte->list_vpte_long, |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 84 | &vcpu3s->hpte_hash_vpte_long[index]); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 85 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 86 | spin_unlock(&vcpu3s->mmu_lock); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static void free_pte_rcu(struct rcu_head *head) |
| 90 | { |
| 91 | struct hpte_cache *pte = container_of(head, struct hpte_cache, rcu_head); |
| 92 | kmem_cache_free(hpte_cache, pte); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static void invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte) |
| 96 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 97 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
| 98 | |
Alexander Graf | 8696ee4 | 2010-08-02 12:55:19 +0200 | [diff] [blame] | 99 | trace_kvm_book3s_mmu_invalidate(pte); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 100 | |
| 101 | /* Different for 32 and 64 bit */ |
| 102 | kvmppc_mmu_invalidate_pte(vcpu, pte); |
| 103 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 104 | spin_lock(&vcpu3s->mmu_lock); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 105 | |
Alexander Graf | e7c1d14 | 2010-08-02 21:24:48 +0200 | [diff] [blame] | 106 | /* pte already invalidated in between? */ |
| 107 | if (hlist_unhashed(&pte->list_pte)) { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 108 | spin_unlock(&vcpu3s->mmu_lock); |
Alexander Graf | e7c1d14 | 2010-08-02 21:24:48 +0200 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 112 | hlist_del_init_rcu(&pte->list_pte); |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 113 | hlist_del_init_rcu(&pte->list_pte_long); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 114 | hlist_del_init_rcu(&pte->list_vpte); |
| 115 | hlist_del_init_rcu(&pte->list_vpte_long); |
| 116 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 117 | spin_unlock(&vcpu3s->mmu_lock); |
Alexander Graf | e7c1d14 | 2010-08-02 21:24:48 +0200 | [diff] [blame] | 118 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 119 | vcpu3s->hpte_cache_count--; |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 120 | call_rcu(&pte->rcu_head, free_pte_rcu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void kvmppc_mmu_pte_flush_all(struct kvm_vcpu *vcpu) |
| 124 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 125 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 126 | struct hpte_cache *pte; |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 127 | struct hlist_node *node; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 128 | int i; |
| 129 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 130 | rcu_read_lock(); |
| 131 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 132 | for (i = 0; i < HPTEG_HASH_NUM_VPTE_LONG; i++) { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 133 | struct hlist_head *list = &vcpu3s->hpte_hash_vpte_long[i]; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 134 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 135 | hlist_for_each_entry_rcu(pte, node, list, list_vpte_long) |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 136 | invalidate_pte(vcpu, pte); |
| 137 | } |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 138 | |
| 139 | rcu_read_unlock(); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void kvmppc_mmu_pte_flush_page(struct kvm_vcpu *vcpu, ulong guest_ea) |
| 143 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 144 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 145 | struct hlist_head *list; |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 146 | struct hlist_node *node; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 147 | struct hpte_cache *pte; |
| 148 | |
| 149 | /* Find the list of entries in the map */ |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 150 | list = &vcpu3s->hpte_hash_pte[kvmppc_mmu_hash_pte(guest_ea)]; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 151 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 152 | rcu_read_lock(); |
| 153 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 154 | /* Check the list for matching entries and invalidate */ |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 155 | hlist_for_each_entry_rcu(pte, node, list, list_pte) |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 156 | if ((pte->pte.eaddr & ~0xfffUL) == guest_ea) |
| 157 | invalidate_pte(vcpu, pte); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 158 | |
| 159 | rcu_read_unlock(); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 162 | static void kvmppc_mmu_pte_flush_long(struct kvm_vcpu *vcpu, ulong guest_ea) |
| 163 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 164 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 165 | struct hlist_head *list; |
| 166 | struct hlist_node *node; |
| 167 | struct hpte_cache *pte; |
| 168 | |
| 169 | /* Find the list of entries in the map */ |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 170 | list = &vcpu3s->hpte_hash_pte_long[ |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 171 | kvmppc_mmu_hash_pte_long(guest_ea)]; |
| 172 | |
| 173 | rcu_read_lock(); |
| 174 | |
| 175 | /* Check the list for matching entries and invalidate */ |
| 176 | hlist_for_each_entry_rcu(pte, node, list, list_pte_long) |
| 177 | if ((pte->pte.eaddr & 0x0ffff000UL) == guest_ea) |
| 178 | invalidate_pte(vcpu, pte); |
| 179 | |
| 180 | rcu_read_unlock(); |
| 181 | } |
| 182 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 183 | void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong guest_ea, ulong ea_mask) |
| 184 | { |
Alexander Graf | c60b4cf | 2010-08-02 13:40:30 +0200 | [diff] [blame] | 185 | trace_kvm_book3s_mmu_flush("", vcpu, guest_ea, ea_mask); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 186 | guest_ea &= ea_mask; |
| 187 | |
| 188 | switch (ea_mask) { |
| 189 | case ~0xfffUL: |
| 190 | kvmppc_mmu_pte_flush_page(vcpu, guest_ea); |
| 191 | break; |
| 192 | case 0x0ffff000: |
Alexander Graf | 2d27fc5 | 2010-07-29 15:04:19 +0200 | [diff] [blame] | 193 | kvmppc_mmu_pte_flush_long(vcpu, guest_ea); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 194 | break; |
| 195 | case 0: |
| 196 | /* Doing a complete flush -> start from scratch */ |
| 197 | kvmppc_mmu_pte_flush_all(vcpu); |
| 198 | break; |
| 199 | default: |
| 200 | WARN_ON(1); |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /* Flush with mask 0xfffffffff */ |
| 206 | static void kvmppc_mmu_pte_vflush_short(struct kvm_vcpu *vcpu, u64 guest_vp) |
| 207 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 208 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 209 | struct hlist_head *list; |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 210 | struct hlist_node *node; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 211 | struct hpte_cache *pte; |
| 212 | u64 vp_mask = 0xfffffffffULL; |
| 213 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 214 | list = &vcpu3s->hpte_hash_vpte[kvmppc_mmu_hash_vpte(guest_vp)]; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 215 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 216 | rcu_read_lock(); |
| 217 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 218 | /* Check the list for matching entries and invalidate */ |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 219 | hlist_for_each_entry_rcu(pte, node, list, list_vpte) |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 220 | if ((pte->pte.vpage & vp_mask) == guest_vp) |
| 221 | invalidate_pte(vcpu, pte); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 222 | |
| 223 | rcu_read_unlock(); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /* Flush with mask 0xffffff000 */ |
| 227 | static void kvmppc_mmu_pte_vflush_long(struct kvm_vcpu *vcpu, u64 guest_vp) |
| 228 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 229 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 230 | struct hlist_head *list; |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 231 | struct hlist_node *node; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 232 | struct hpte_cache *pte; |
| 233 | u64 vp_mask = 0xffffff000ULL; |
| 234 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 235 | list = &vcpu3s->hpte_hash_vpte_long[ |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 236 | kvmppc_mmu_hash_vpte_long(guest_vp)]; |
| 237 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 238 | rcu_read_lock(); |
| 239 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 240 | /* Check the list for matching entries and invalidate */ |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 241 | hlist_for_each_entry_rcu(pte, node, list, list_vpte_long) |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 242 | if ((pte->pte.vpage & vp_mask) == guest_vp) |
| 243 | invalidate_pte(vcpu, pte); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 244 | |
| 245 | rcu_read_unlock(); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 guest_vp, u64 vp_mask) |
| 249 | { |
Alexander Graf | c60b4cf | 2010-08-02 13:40:30 +0200 | [diff] [blame] | 250 | trace_kvm_book3s_mmu_flush("v", vcpu, guest_vp, vp_mask); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 251 | guest_vp &= vp_mask; |
| 252 | |
| 253 | switch(vp_mask) { |
| 254 | case 0xfffffffffULL: |
| 255 | kvmppc_mmu_pte_vflush_short(vcpu, guest_vp); |
| 256 | break; |
| 257 | case 0xffffff000ULL: |
| 258 | kvmppc_mmu_pte_vflush_long(vcpu, guest_vp); |
| 259 | break; |
| 260 | default: |
| 261 | WARN_ON(1); |
| 262 | return; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end) |
| 267 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 268 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 269 | struct hlist_node *node; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 270 | struct hpte_cache *pte; |
| 271 | int i; |
| 272 | |
Alexander Graf | c60b4cf | 2010-08-02 13:40:30 +0200 | [diff] [blame] | 273 | trace_kvm_book3s_mmu_flush("p", vcpu, pa_start, pa_end); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 274 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 275 | rcu_read_lock(); |
| 276 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 277 | for (i = 0; i < HPTEG_HASH_NUM_VPTE_LONG; i++) { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 278 | struct hlist_head *list = &vcpu3s->hpte_hash_vpte_long[i]; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 279 | |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 280 | hlist_for_each_entry_rcu(pte, node, list, list_vpte_long) |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 281 | if ((pte->pte.raddr >= pa_start) && |
| 282 | (pte->pte.raddr < pa_end)) |
| 283 | invalidate_pte(vcpu, pte); |
| 284 | } |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 285 | |
| 286 | rcu_read_unlock(); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu) |
| 290 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 291 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 292 | struct hpte_cache *pte; |
| 293 | |
| 294 | pte = kmem_cache_zalloc(hpte_cache, GFP_KERNEL); |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 295 | vcpu3s->hpte_cache_count++; |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 296 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 297 | if (vcpu3s->hpte_cache_count == HPTEG_CACHE_NUM) |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 298 | kvmppc_mmu_pte_flush_all(vcpu); |
| 299 | |
| 300 | return pte; |
| 301 | } |
| 302 | |
| 303 | void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu) |
| 304 | { |
| 305 | kvmppc_mmu_pte_flush(vcpu, 0, 0); |
| 306 | } |
| 307 | |
| 308 | static void kvmppc_mmu_hpte_init_hash(struct hlist_head *hash_list, int len) |
| 309 | { |
| 310 | int i; |
| 311 | |
| 312 | for (i = 0; i < len; i++) |
| 313 | INIT_HLIST_HEAD(&hash_list[i]); |
| 314 | } |
| 315 | |
| 316 | int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu) |
| 317 | { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 318 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 319 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 320 | /* init hpte lookup hashes */ |
| 321 | kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_pte, |
| 322 | ARRAY_SIZE(vcpu3s->hpte_hash_pte)); |
| 323 | kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_pte_long, |
| 324 | ARRAY_SIZE(vcpu3s->hpte_hash_pte_long)); |
| 325 | kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte, |
| 326 | ARRAY_SIZE(vcpu3s->hpte_hash_vpte)); |
| 327 | kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte_long, |
| 328 | ARRAY_SIZE(vcpu3s->hpte_hash_vpte_long)); |
| 329 | |
| 330 | spin_lock_init(&vcpu3s->mmu_lock); |
Alexander Graf | 2e0908a | 2010-07-29 15:04:17 +0200 | [diff] [blame] | 331 | |
Alexander Graf | 7741909 | 2010-06-30 15:18:45 +0200 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | int kvmppc_mmu_hpte_sysinit(void) |
| 336 | { |
| 337 | /* init hpte slab cache */ |
| 338 | hpte_cache = kmem_cache_create("kvm-spt", sizeof(struct hpte_cache), |
| 339 | sizeof(struct hpte_cache), 0, NULL); |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | void kvmppc_mmu_hpte_sysexit(void) |
| 345 | { |
| 346 | kmem_cache_destroy(hpte_cache); |
| 347 | } |