From: Zhang Wei Date: Fri, 25 Jan 2008 07:12:58 +0000 Subject: [kvm-ppc-devel] [PATCH 4/5] Refactor TLB codes about 44x to general Message-Id: <1201245181735-git-send-email-wei.zhang@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm-ppc@vger.kernel.org Signed-off-by: Zhang Wei --- arch/powerpc/kvm/44x_tlb.c | 309 +++++++++++++++++------------------------ arch/powerpc/kvm/44x_tlb.h | 5 - arch/powerpc/kvm/Makefile | 2 +- arch/powerpc/kvm/emulate.c | 4 +- arch/powerpc/kvm/powerpc.c | 34 ++--- arch/powerpc/kvm/tlb.c | 226 ++++++++++++++++++++++++++++++ arch/powerpc/kvm/tlb.h | 54 +++++++ include/asm-powerpc/kvm_asm.h | 2 +- 8 files changed, 426 insertions(+), 210 deletions(-) create mode 100644 arch/powerpc/kvm/tlb.c create mode 100644 arch/powerpc/kvm/tlb.h diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c index 241fa0e..599ec6a 100644 --- a/arch/powerpc/kvm/44x_tlb.c +++ b/arch/powerpc/kvm/44x_tlb.c @@ -15,200 +15,147 @@ * Copyright IBM Corp. 2007 * * Authors: Hollis Blanchard + * + * The original 44x_tlb.c is moved to tlb.c. + * + * The file implements some TLB operations on PowerPC 44x processor. + * + * Copyright (C) 2008 Freescale Semiconductor, Inc. + * + * Zhang Wei */ #include #include #include +#include "tlb.h" #include "44x_tlb.h" -#define PPC44x_TLB_USER_PERM_MASK (PPC44x_TLB_UX|PPC44x_TLB_UR|PPC44x_TLB_UW) -#define PPC44x_TLB_SUPER_PERM_MASK (PPC44x_TLB_SX|PPC44x_TLB_SR|PPC44x_TLB_SW) - -static unsigned int tlb_index = 1; - -static u32 tlb_shadow_attrib(u32 attrib, int usermode) -{ - /* XXX remove mask when Linux is fixed */ - attrib &= 0xf03f; - - if (!usermode) { - /* Guest is in supervisor mode, so we need to translate guest - * supervisor permissions into user permissions. */ - attrib &= ~PPC44x_TLB_USER_PERM_MASK; - attrib |= (attrib & PPC44x_TLB_SUPER_PERM_MASK) << 3; - } - - /* Make sure host can always access this memory. */ - attrib |= PPC44x_TLB_SX|PPC44x_TLB_SR|PPC44x_TLB_SW; - - return attrib; -} - -/* Search the guest TLB for a matching entry. */ -int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, unsigned int pid, - unsigned int as) -{ - int i; - - /* XXX Replace loop with fancy data structures. */ - for (i = 0; i < PPC44x_TLB_SIZE; i++) { - struct tlbe *tlbe = &vcpu->arch.guest_tlb[i]; - unsigned int tid; - - if (eaddr < get_tlb_eaddr(tlbe)) - continue; - - if (eaddr > get_tlb_end(tlbe)) - continue; - - tid = get_tlb_tid(tlbe); - if (tid && (tid != pid)) - continue; - - if (!get_tlb_v(tlbe)) - continue; - - if (get_tlb_ts(tlbe) != as) - continue; - - return i; - } - - return -1; -} - -struct tlbe *kvmppc_44x_itlb_search(struct kvm_vcpu *vcpu, gva_t eaddr) -{ - unsigned int as = !!(vcpu->arch.guest_msr & MSR_IS); - unsigned int index; - - index = kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as); - if (index = -1) - return NULL; - return &vcpu->arch.guest_tlb[index]; -} - -struct tlbe *kvmppc_44x_dtlb_search(struct kvm_vcpu *vcpu, gva_t eaddr) -{ - unsigned int as = !!(vcpu->arch.guest_msr & MSR_DS); - unsigned int index; - - index = kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as); - if (index = -1) - return NULL; - return &vcpu->arch.guest_tlb[index]; -} - /* 440 host */ - -static hpa_t kvmppc_gpa_to_hpa(struct kvm *kvm, gfn_t gfn) +/* TLB helper functions */ +void kvmppc_set_tlbe(struct tlbe *tlbes, u32 entry, u32 tid, gva_t ep, gpa_t rp, size_t size, u32 flags) { - struct page *page; - - down_write(¤t->mm->mmap_sem); - page = gfn_to_page(kvm, gfn); - up_write(¤t->mm->mmap_sem); - - if (is_error_page(page)) { - printk(KERN_ERR "Couldn't get guest page!\n"); - kvm_release_page_clean(page); - return (hpa_t)-1; - } - - return page_to_phys(page); + int bit; + struct tlbe *tlbe = tlbes + entry; + + tlbe->tid = tid & 0xff; + tlbe->word0 = (ep & PPC44x_TLB_EPN_MASK) | + ((__ilog2(size >> 10) / 2) << 4); + tlbe->word1 = (((u32)rp) & PPC44x_TLB_RPN_MASK) | + ((rp >> 32) & PPC44x_TLB_ERPN_MASK); + tlbe->word2 = 0; + for_each_bit(bit, &flags, sizeof(u32) * BITS_PER_BYTE) + switch (BIT(bit)) { + case TLBE_VALID: + tlbe->word0 |= PPC44x_TLB_VALID; + break; + case TLBE_TS: + tlbe->word0 |= PPC44x_TLB_TS; + break; + case TLBE_U0: + tlbe->word2 |= PPC44x_TLB_U0; + break; + case TLBE_U1: + tlbe->word2 |= PPC44x_TLB_U1; + break; + case TLBE_U2: + tlbe->word2 |= PPC44x_TLB_U2; + break; + case TLBE_U3: + tlbe->word2 |= PPC44x_TLB_U3; + break; + case TLBE_W: + tlbe->word2 |= PPC44x_TLB_W; + break; + case TLBE_I: + tlbe->word2 |= PPC44x_TLB_I; + break; + case TLBE_M: + tlbe->word2 |= PPC44x_TLB_M; + break; + case TLBE_G: + tlbe->word2 |= PPC44x_TLB_G; + break; + case TLBE_E: + tlbe->word2 |= PPC44x_TLB_E; + break; + case TLBE_UX: + tlbe->word2 |= PPC44x_TLB_UX; + break; + case TLBE_SX: + tlbe->word2 |= PPC44x_TLB_SX; + break; + case TLBE_UW: + tlbe->word2 |= PPC44x_TLB_UW; + break; + case TLBE_SW: + tlbe->word2 |= PPC44x_TLB_SW; + break; + case TLBE_UR: + tlbe->word2 |= PPC44x_TLB_UR; + break; + case TLBE_SR: + tlbe->word2 |= PPC44x_TLB_SR; + break; + } } -/* Caller must ensure that the specified guest TLB entry is safe to insert into - * the shadow TLB. */ -void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn, u64 asid, - u32 flags) +u32 flags_to_tlbe(const struct tlbe *tlbe) { - struct tlbe *stlbe; - hpa_t hpaddr; - unsigned int victim; - - /* Future optimization: don't overwrite the TLB entry containing the - * current PC (or stack?). */ - do { - victim = tlb_index++; - if (tlb_index >= PPC44x_TLB_SIZE) - tlb_index = 0; - } while (victim = vcpu->arch.trampoline_tlbe); - - stlbe = &vcpu->arch.shadow_tlb[victim]; - - /* Determine the host physical address to put into the hardware TLB. */ - hpaddr = kvmppc_gpa_to_hpa(vcpu->kvm, gfn); - if (hpaddr = (hpa_t)-1) - return; - - /* XXX Make sure (va, size) doesn't overlap any other - * entries. 440x6 user manual says the result would be - * "undefined." */ - - /* XXX what about AS? */ - - stlbe->tid = asid & 0xff; - - /* Force TS=1 for all guest mappings. */ - /* For now we hardcode 4KB mappings, but it will be important to - * use host large pages in the future. */ - stlbe->word0 = (gvaddr & PAGE_MASK) | PPC44x_TLB_VALID | PPC44x_TLB_TS - | PPC44x_TLB_4K; - - stlbe->word1 = (hpaddr & 0xfffffc00) | ((hpaddr >> 32) & 0xf); - stlbe->word2 = tlb_shadow_attrib(flags, vcpu->arch.guest_msr & MSR_PR); - -#if 0 - printk("stlbe %2d: %08x %08x %08x %08x\n", victim, - stlbe->tid, stlbe->word0, - stlbe->word1, stlbe->word2); -#endif + int bit; + u32 r = 0; + u32 flags = tlbe->word2 & 0xffff; + + for_each_bit(bit, &flags, sizeof(u32) * BITS_PER_BYTE) + switch (BIT(bit)) { + case PPC44x_TLB_U0: + r |= TLBE_U0; + break; + case PPC44x_TLB_U1: + r |= TLBE_U1; + break; + case PPC44x_TLB_U2: + r |= TLBE_U2; + break; + case PPC44x_TLB_U3: + r |= TLBE_U3; + break; + case PPC44x_TLB_W: + r |= TLBE_W; + break; + case PPC44x_TLB_I: + r |= TLBE_I; + break; + case PPC44x_TLB_M: + r |= TLBE_M; + break; + case PPC44x_TLB_G: + r |= TLBE_G; + break; + case PPC44x_TLB_E: + r |= TLBE_E; + break; + case PPC44x_TLB_UX: + r |= TLBE_UX; + break; + case PPC44x_TLB_UW: + r |= TLBE_UW; + break; + case PPC44x_TLB_UR: + r |= TLBE_UR; + break; + case PPC44x_TLB_SX: + r |= TLBE_SX; + break; + case PPC44x_TLB_SW: + r |= TLBE_SW; + break; + case PPC44x_TLB_SR: + r |= TLBE_SR; + break; + } + return r; } -void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, u64 eaddr, u64 asid) -{ - unsigned int pid = asid & 0xff; - int i; - unsigned long track[2] = {0, 0}; - - /* XXX Replace loop with fancy data structures. */ - for (i = 0; i < PPC44x_TLB_SIZE; i++) { - struct tlbe *stlbe = &vcpu->arch.shadow_tlb[i]; - unsigned int tid; - - if (eaddr < get_tlb_eaddr(stlbe)) - continue; - - if (eaddr > get_tlb_end(stlbe)) - continue; - - tid = get_tlb_tid(stlbe); - if (tid && (tid != pid)) - continue; - set_bit(i, track); - stlbe->word0 = 0; - } - -#if 0 - printk("%s: %016llx %016llx inv %lx %lx\n", __func__, eaddr, asid, - track[1], track[0]); -#endif -} - -/* Invalidate all mappings, so that when they fault back in they will get the - * proper permission bits. */ -void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode) -{ - int i; - - /* XXX Replace loop with fancy data structures. */ - for (i = 0; i < PPC44x_TLB_SIZE; i++) { - if (i = vcpu->arch.trampoline_tlbe) - continue; - vcpu->arch.shadow_tlb[i].word0 = 0; - } -} diff --git a/arch/powerpc/kvm/44x_tlb.h b/arch/powerpc/kvm/44x_tlb.h index 2ccd46b..e2b5836 100644 --- a/arch/powerpc/kvm/44x_tlb.h +++ b/arch/powerpc/kvm/44x_tlb.h @@ -23,11 +23,6 @@ #include #include -extern int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, - unsigned int pid, unsigned int as); -extern struct tlbe *kvmppc_44x_dtlb_search(struct kvm_vcpu *vcpu, gva_t eaddr); -extern struct tlbe *kvmppc_44x_itlb_search(struct kvm_vcpu *vcpu, gva_t eaddr); - /* TLB helper functions */ static inline unsigned int get_tlb_size(const struct tlbe *tlbe) { diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile index 9d672d1..b342ef3 100644 --- a/arch/powerpc/kvm/Makefile +++ b/arch/powerpc/kvm/Makefile @@ -9,7 +9,7 @@ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o) kvm-objs := $(common-objs) obj-$(CONFIG_KVM) += kvm.o -kvm-powerpc-objs := powerpc.o emulate.o 44x_tlb.o booke_interrupts.o +kvm-powerpc-objs := powerpc.o emulate.o 44x_tlb.o booke_interrupts.o tlb.o obj-$(CONFIG_KVM_POWERPC) += kvm-powerpc.o AFLAGS_booke_interrupts.o := -I$(obj) diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index b4b1442..ad4a26a 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -27,7 +27,7 @@ #include #include -#include "44x_tlb.h" +#include "tlb.h" #define DCRN_CPR0_CFGADDR 0xc #define DCRN_CPR0_CFGDATA 0xd @@ -561,7 +561,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) if (ra) ea += vcpu->arch.gpr[ra]; - index = kvmppc_44x_tlb_index(vcpu, ea, pid, as); + index = kvmppc_tlb_index(vcpu, ea, pid, as); if (rc) { if (index < 0) vcpu->arch.cr &= ~0x20000000; diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 9866b3c..ebe26a1 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -27,7 +27,7 @@ #include #include -#include "44x_tlb.h" +#include "tlb.h" struct kvm_stats_debugfs_item debugfs_entries[] = { { NULL } @@ -219,7 +219,7 @@ int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, gfn_t gfn; /* Check the guest TLB. */ - gtlbe = kvmppc_44x_dtlb_search(vcpu, eaddr); + gtlbe = kvmppc_dtlb_search(vcpu, eaddr); if (!gtlbe) { /* The guest didn't have a mapping for it. */ kvmppc_sync_interrupt(vcpu, exit_nr); @@ -263,7 +263,7 @@ int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, r = RESUME_GUEST; /* Check the guest TLB. */ - gtlbe = kvmppc_44x_itlb_search(vcpu, eaddr); + gtlbe = kvmppc_itlb_search(vcpu, eaddr); if (!gtlbe) { /* The guest didn't have a mapping for it. */ kvmppc_sync_interrupt(vcpu, exit_nr); @@ -555,11 +555,10 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) /* Insert mapping for the trampoline. */ tlbe = &vcpu->arch.shadow_tlb[vcpu->arch.trampoline_tlbe]; - tlbe->tid = 0; - tlbe->word0 = (unsigned long)vcpu->arch.trampoline - | VCPU_TLB_PGSZ | PPC44x_TLB_VALID; - tlbe->word1 = __pa(handlers); - tlbe->word2 = PPC44x_TLB_SX|PPC44x_TLB_SW|PPC44x_TLB_SR; + kvmppc_set_tlbe(vcpu->arch.shadow_tlb, vcpu->arch.trampoline_tlbe, + 0, (unsigned long)vcpu->arch.trampoline, __pa(handlers), + 0x10000, /* 64K */ + TLBE_VALID | TLBE_SX | TLBE_SW | TLBE_SR); printk("tlb[%d]: %x %x %x %x\n", vcpu->arch.trampoline_tlbe, tlbe->tid, tlbe->word0, @@ -580,19 +579,14 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) { - struct tlbe *tlbe = &vcpu->arch.guest_tlb[0]; + kvmppc_set_tlbe(vcpu->arch.guest_tlb, 0, 0, + 0, 0, 0x1000000, /* ep = 0, rp = 0, size = 16MB */ + TLBE_VALID | TLBE_SX | TLBE_SW | TLBE_SR); - tlbe->tid = 0; - tlbe->word0 = PPC44x_TLB_16M | PPC44x_TLB_VALID; - tlbe->word1 = 0; - tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR; - - tlbe++; - tlbe->tid = 0; - tlbe->word0 = 0xef600000 | PPC44x_TLB_4K | PPC44x_TLB_VALID; - tlbe->word1 = 0xef600000; - tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR - | PPC44x_TLB_I | PPC44x_TLB_G; + kvmppc_set_tlbe(vcpu->arch.guest_tlb, 1, 0, + 0xef600000, 0xef600000, 4096, + TLBE_VALID | TLBE_SX | TLBE_SW | TLBE_SR + | TLBE_I | TLBE_G); vcpu->arch.pc = 0; vcpu->arch.guest_msr = 0; diff --git a/arch/powerpc/kvm/tlb.c b/arch/powerpc/kvm/tlb.c new file mode 100644 index 0000000..c474174 --- /dev/null +++ b/arch/powerpc/kvm/tlb.c @@ -0,0 +1,226 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright IBM Corp. 2007 + * + * Authors: Hollis Blanchard + * + * The file is almost moved from 44x_tlb.c. Function + * names, MMU operations and definitions are changed + * from 44x only to general. Those should be also fit for + * other PowerPC processors. + * + * Copyright (C) 2008 Freescale Semiconductor, Inc. + * + * Zhang Wei + */ + +#include +#include +#include + +#include "tlb.h" +#include "44x_tlb.h" + +#define TLBE_USER_PERM_MASK (TLBE_UX|TLBE_UR|TLBE_UW) +#define TLBE_SUPER_PERM_MASK (TLBE_SX|TLBE_SR|TLBE_SW) + +static unsigned int tlb_index = 1; + +static u32 tlb_shadow_attrib(u32 attrib, int usermode) +{ + /* XXX remove mask when Linux is fixed + * attrib &= 0xf03f; + */ + /* The mask is changed from 0xf03f to new definitions */ + attrib &= TLBE_U0 | TLBE_U1 | TLBE_U2 | TLBE_U3 + | TLBE_USER_PERM_MASK | TLBE_SUPER_PERM_MASK; + + if (!usermode) { + /* Guest is in supervisor mode, so we need to translate guest + * supervisor permissions into user permissions. */ + attrib &= ~TLBE_USER_PERM_MASK; + attrib |= (attrib & TLBE_SUPER_PERM_MASK) << 3; + } + + /* Make sure host can always access this memory. */ + attrib |= TLBE_SX|TLBE_SR|TLBE_SW; + + return attrib; +} + +/* Search the guest TLB for a matching entry. */ +int kvmppc_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, unsigned int pid, + unsigned int as) +{ + int i; + + /* XXX Replace loop with fancy data structures. */ + for (i = 0; i < KVMPPC_HOST_TLB_SIZE; i++) { + struct tlbe *tlbe = &vcpu->arch.guest_tlb[i]; + unsigned int tid; + + if (eaddr < get_tlb_eaddr(tlbe)) + continue; + + if (eaddr > get_tlb_end(tlbe)) + continue; + + tid = get_tlb_tid(tlbe); + if (tid && (tid != pid)) + continue; + + if (!get_tlb_v(tlbe)) + continue; + + if (get_tlb_ts(tlbe) != as) + continue; + + return i; + } + + return -1; +} + +struct tlbe *kvmppc_itlb_search(struct kvm_vcpu *vcpu, gva_t eaddr) +{ + unsigned int as = !!(vcpu->arch.guest_msr & MSR_IS); + unsigned int index; + + index = kvmppc_tlb_index(vcpu, eaddr, vcpu->arch.pid, as); + if (index = -1) + return NULL; + return &vcpu->arch.guest_tlb[index]; +} + +struct tlbe *kvmppc_dtlb_search(struct kvm_vcpu *vcpu, gva_t eaddr) +{ + unsigned int as = !!(vcpu->arch.guest_msr & MSR_DS); + unsigned int index; + + index = kvmppc_tlb_index(vcpu, eaddr, vcpu->arch.pid, as); + if (index = -1) + return NULL; + return &vcpu->arch.guest_tlb[index]; +} + +static hpa_t kvmppc_gpa_to_hpa(struct kvm *kvm, gfn_t gfn) +{ + struct page *page; + + down_write(¤t->mm->mmap_sem); + page = gfn_to_page(kvm, gfn); + up_write(¤t->mm->mmap_sem); + + if (is_error_page(page)) { + printk(KERN_ERR "Couldn't get guest page!\n"); + kvm_release_page_clean(page); + return (hpa_t)-1; + } + + return page_to_phys(page); +} + +/* Caller must ensure that the specified guest TLB entry is safe to insert into + * the shadow TLB. */ +void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn, u64 asid, + u32 flags) +{ + struct tlbe *stlbe; + hpa_t hpaddr; + unsigned int victim; + + /* Future optimization: don't overwrite the TLB entry containing the + * current PC (or stack?). */ + do { + victim = tlb_index++; + if (tlb_index >= KVMPPC_HOST_TLB_SIZE) + tlb_index = 0; + } while (victim = vcpu->arch.trampoline_tlbe); + + stlbe = &vcpu->arch.shadow_tlb[victim]; + + /* Determine the host physical address to put into the hardware TLB. */ + hpaddr = kvmppc_gpa_to_hpa(vcpu->kvm, gfn); + if (hpaddr = (hpa_t)-1) + return; + + /* XXX Make sure (va, size) doesn't overlap any other + * entries. 440x6 user manual says the result would be + * "undefined." */ + + /* XXX what about AS? */ + + /* Force TS=1 for all guest mappings. */ + /* For now we hardcode 4KB mappings, but it will be important to + * use host large pages in the future. */ + kvmppc_set_tlbe(vcpu->arch.shadow_tlb, victim, asid & TID_MASK, gvaddr, + hpaddr, PAGE_SIZE, + TLBE_VALID | TLBE_TS | + tlb_shadow_attrib(flags, vcpu->arch.guest_msr & MSR_PR)); +#if 0 + printk("stlbe %2d: %08x %08x %08x %08x\n", victim, + stlbe->tid, stlbe->word0, + stlbe->word1, stlbe->word2); +#endif +} + +void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, u64 eaddr, u64 asid) +{ + unsigned int pid = asid & 0xff; + int i; + unsigned long track[2] = {0, 0}; + + /* XXX Replace loop with fancy data structures. */ + for (i = 0; i < KVMPPC_HOST_TLB_SIZE; i++) { + struct tlbe *stlbe = &vcpu->arch.shadow_tlb[i]; + unsigned int tid; + + if (eaddr < get_tlb_eaddr(stlbe)) + continue; + + if (eaddr > get_tlb_end(stlbe)) + continue; + + tid = get_tlb_tid(stlbe); + if (tid && (tid != pid)) + continue; + + set_bit(i, track); + kvmppc_set_tlbe(vcpu->arch.shadow_tlb, i, tid, 0, 0, + PAGE_SIZE, 0); + } + +#if 0 + printk("%s: %016llx %016llx inv %lx %lx\n", __func__, eaddr, asid, + track[1], track[0]); +#endif +} + +/* Invalidate all mappings, so that when they fault back in they will get the + * proper permission bits. */ +void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode) +{ + int i; + + /* XXX Replace loop with fancy data structures. */ + for (i = 0; i < KVMPPC_HOST_TLB_SIZE; i++) { + if (i = vcpu->arch.trampoline_tlbe) + continue; + kvmppc_set_tlbe(vcpu->arch.shadow_tlb, i, 0, 0, 0, + PAGE_SIZE, 0); + } +} + + diff --git a/arch/powerpc/kvm/tlb.h b/arch/powerpc/kvm/tlb.h new file mode 100644 index 0000000..c3ca81d --- /dev/null +++ b/arch/powerpc/kvm/tlb.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2008 Freescale Semiconductor. + * + * Author: Zhang Wei + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + */ + +#ifndef __ARCH_POWERPC_KVM_TLB_H__ +#define __ARCH_POWERPC_KVM_TLB_H__ + +#include +#include + +#if defined(CONFIG_KVM_POWERPC_440) +#include "44x_tlb.h" +#endif + +/* TLB Flags */ +#define TLBE_VALID BIT(0) +#define TLBE_TS BIT(1) +#define TLBE_U0 BIT(2) +#define TLBE_U1 BIT(3) +#define TLBE_U2 BIT(4) +#define TLBE_U3 BIT(5) +#define TLBE_W BIT(6) +#define TLBE_I BIT(7) +#define TLBE_M BIT(8) +#define TLBE_G BIT(9) +#define TLBE_E BIT(10) +#define TLBE_SX BIT(11) +#define TLBE_SW BIT(12) +#define TLBE_SR BIT(13) +#define TLBE_UX BIT(14) +#define TLBE_UW BIT(15) +#define TLBE_UR BIT(16) + +#define AS_BIT 0x80000000 /* Used for as of 'asid' */ +#define TID_MASK 0x3fffffff /* Used for id of 'asid' */ + +/* TLB helper functions */ +extern void kvmppc_set_tlbe(struct tlbe *tlbes, u32 entry, u32 tid, gva_t ep, gpa_t rp, size_t size, u32 flags); +extern u32 flags_to_tlbe(const struct tlbe *tlbe); + +extern int kvmppc_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, + unsigned int pid, unsigned int as); +extern struct tlbe *kvmppc_dtlb_search(struct kvm_vcpu *vcpu, gva_t eaddr); +extern struct tlbe *kvmppc_itlb_search(struct kvm_vcpu *vcpu, gva_t eaddr); + +#endif /* __ARCH_POWERPC_KVM_TLB_H__ */ diff --git a/include/asm-powerpc/kvm_asm.h b/include/asm-powerpc/kvm_asm.h index 3c5da1d..6bd9878 100644 --- a/include/asm-powerpc/kvm_asm.h +++ b/include/asm-powerpc/kvm_asm.h @@ -23,7 +23,6 @@ /* IVPR must be 64KiB-aligned. */ #define VCPU_SIZE_ORDER 4 #define VCPU_SIZE_LOG (VCPU_SIZE_ORDER + 12) -#define VCPU_TLB_PGSZ PPC44x_TLB_64K #define VCPU_SIZE_BYTES (1<