summaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kvm/book3s_64_mmu_host.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/kvm/book3s_64_mmu_host.c')
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_host.c129
1 files changed, 9 insertions, 120 deletions
diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c b/arch/powerpc/kvm/book3s_64_mmu_host.c
index e4b5744977f..384179a5002 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_host.c
@@ -20,6 +20,7 @@
*/
#include <linux/kvm_host.h>
+#include <linux/hash.h>
#include <asm/kvm_ppc.h>
#include <asm/kvm_book3s.h>
@@ -46,135 +47,20 @@
#define dprintk_slb(a, ...) do { } while(0)
#endif
-static void invalidate_pte(struct hpte_cache *pte)
+void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
{
- dprintk_mmu("KVM: Flushing SPT: 0x%lx (0x%llx) -> 0x%llx\n",
- pte->pte.eaddr, pte->pte.vpage, pte->host_va);
-
ppc_md.hpte_invalidate(pte->slot, pte->host_va,
MMU_PAGE_4K, MMU_SEGSIZE_256M,
false);
- pte->host_va = 0;
-
- if (pte->pte.may_write)
- kvm_release_pfn_dirty(pte->pfn);
- else
- kvm_release_pfn_clean(pte->pfn);
-}
-
-void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong guest_ea, ulong ea_mask)
-{
- int i;
-
- dprintk_mmu("KVM: Flushing %d Shadow PTEs: 0x%lx & 0x%lx\n",
- vcpu->arch.hpte_cache_offset, guest_ea, ea_mask);
- BUG_ON(vcpu->arch.hpte_cache_offset > HPTEG_CACHE_NUM);
-
- guest_ea &= ea_mask;
- for (i = 0; i < vcpu->arch.hpte_cache_offset; i++) {
- struct hpte_cache *pte;
-
- pte = &vcpu->arch.hpte_cache[i];
- if (!pte->host_va)
- continue;
-
- if ((pte->pte.eaddr & ea_mask) == guest_ea) {
- invalidate_pte(pte);
- }
- }
-
- /* Doing a complete flush -> start from scratch */
- if (!ea_mask)
- vcpu->arch.hpte_cache_offset = 0;
-}
-
-void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 guest_vp, u64 vp_mask)
-{
- int i;
-
- dprintk_mmu("KVM: Flushing %d Shadow vPTEs: 0x%llx & 0x%llx\n",
- vcpu->arch.hpte_cache_offset, guest_vp, vp_mask);
- BUG_ON(vcpu->arch.hpte_cache_offset > HPTEG_CACHE_NUM);
-
- guest_vp &= vp_mask;
- for (i = 0; i < vcpu->arch.hpte_cache_offset; i++) {
- struct hpte_cache *pte;
-
- pte = &vcpu->arch.hpte_cache[i];
- if (!pte->host_va)
- continue;
-
- if ((pte->pte.vpage & vp_mask) == guest_vp) {
- invalidate_pte(pte);
- }
- }
-}
-
-void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end)
-{
- int i;
-
- dprintk_mmu("KVM: Flushing %d Shadow pPTEs: 0x%lx & 0x%lx\n",
- vcpu->arch.hpte_cache_offset, pa_start, pa_end);
- BUG_ON(vcpu->arch.hpte_cache_offset > HPTEG_CACHE_NUM);
-
- for (i = 0; i < vcpu->arch.hpte_cache_offset; i++) {
- struct hpte_cache *pte;
-
- pte = &vcpu->arch.hpte_cache[i];
- if (!pte->host_va)
- continue;
-
- if ((pte->pte.raddr >= pa_start) &&
- (pte->pte.raddr < pa_end)) {
- invalidate_pte(pte);
- }
- }
-}
-
-struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data)
-{
- int i;
- u64 guest_vp;
-
- guest_vp = vcpu->arch.mmu.ea_to_vp(vcpu, ea, false);
- for (i=0; i<vcpu->arch.hpte_cache_offset; i++) {
- struct hpte_cache *pte;
-
- pte = &vcpu->arch.hpte_cache[i];
- if (!pte->host_va)
- continue;
-
- if (pte->pte.vpage == guest_vp)
- return &pte->pte;
- }
-
- return NULL;
-}
-
-static int kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu)
-{
- if (vcpu->arch.hpte_cache_offset == HPTEG_CACHE_NUM)
- kvmppc_mmu_pte_flush(vcpu, 0, 0);
-
- return vcpu->arch.hpte_cache_offset++;
}
/* We keep 512 gvsid->hvsid entries, mapping the guest ones to the array using
* a hash, so we don't waste cycles on looping */
static u16 kvmppc_sid_hash(struct kvm_vcpu *vcpu, u64 gvsid)
{
- return (u16)(((gvsid >> (SID_MAP_BITS * 7)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 6)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 5)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 4)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 3)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 2)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 1)) & SID_MAP_MASK) ^
- ((gvsid >> (SID_MAP_BITS * 0)) & SID_MAP_MASK));
+ return hash_64(gvsid, SID_MAP_BITS);
}
-
static struct kvmppc_sid_map *find_sid_vsid(struct kvm_vcpu *vcpu, u64 gvsid)
{
struct kvmppc_sid_map *map;
@@ -273,8 +159,7 @@ map_again:
attempt++;
goto map_again;
} else {
- int hpte_id = kvmppc_mmu_hpte_cache_next(vcpu);
- struct hpte_cache *pte = &vcpu->arch.hpte_cache[hpte_id];
+ struct hpte_cache *pte = kvmppc_mmu_hpte_cache_next(vcpu);
dprintk_mmu("KVM: %c%c Map 0x%lx: [%lx] 0x%lx (0x%llx) -> %lx\n",
((rflags & HPTE_R_PP) == 3) ? '-' : 'w',
@@ -292,6 +177,8 @@ map_again:
pte->host_va = va;
pte->pte = *orig_pte;
pte->pfn = hpaddr >> PAGE_SHIFT;
+
+ kvmppc_mmu_hpte_cache_map(vcpu, pte);
}
return 0;
@@ -418,7 +305,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)
void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
{
- kvmppc_mmu_pte_flush(vcpu, 0, 0);
+ kvmppc_mmu_hpte_destroy(vcpu);
__destroy_context(to_book3s(vcpu)->context_id);
}
@@ -436,5 +323,7 @@ int kvmppc_mmu_init(struct kvm_vcpu *vcpu)
vcpu3s->vsid_first = vcpu3s->context_id << USER_ESID_BITS;
vcpu3s->vsid_next = vcpu3s->vsid_first;
+ kvmppc_mmu_hpte_init(vcpu);
+
return 0;
}