staticinlineunsignedint tlb1_max_shadow_size(void)
{ /* reserve one entry for magic page */ return host_tlb_params[1].entries - tlbcam_index - 1;
}
staticinline u32 e500_shadow_mas3_attrib(u32 mas3, bool writable, int usermode)
{ /* Mask off reserved bits. */
mas3 &= MAS3_ATTRIB_MASK;
if (!writable)
mas3 &= ~(MAS3_UW|MAS3_SW);
#ifndef CONFIG_KVM_BOOKE_HV if (!usermode) { /* Guest is in supervisor mode, * so we need to translate guest
* supervisor permissions into user permissions. */
mas3 &= ~E500_TLB_USER_PERM_MASK;
mas3 |= (mas3 & E500_TLB_SUPER_PERM_MASK) << 1;
}
mas3 |= E500_TLB_SUPER_PERM_MASK; #endif return mas3;
}
/* * Acquire a mas0 with victim hint, as if we just took a TLB miss. * * We don't care about the address we're searching for, other than that it's * in the right set and is not present in the TLB. Using a zero PID and a * userspace address means we don't have to set and then restore MAS5, or * calculate a proper MAS6 value.
*/ static u32 get_host_mas0(unsignedlong eaddr)
{ unsignedlong flags;
u32 mas0;
u32 mas4;
/* sesel is for tlb1 only */ staticinlinevoid write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel, int sesel, struct kvm_book3e_206_tlb_entry *stlbe)
{
u32 mas0;
/* sesel is for tlb1 only */ staticvoid write_stlbe(struct kvmppc_vcpu_e500 *vcpu_e500, struct kvm_book3e_206_tlb_entry *gtlbe, struct kvm_book3e_206_tlb_entry *stlbe, int stlbsel, int sesel)
{ int stid;
if (tlbsel == 1 && ref->flags & E500_TLB_TLB0) { /* * TLB1 entry is backed by 4k pages. This should happen * rarely and is not worth optimizing. Invalidate everything.
*/
kvmppc_e500_tlbil_all(vcpu_e500);
ref->flags &= ~(E500_TLB_TLB0 | E500_TLB_VALID);
}
/* * If TLB entry is still valid then it's a TLB0 entry, and thus * backed by at most one host tlbe per shadow pid
*/ if (ref->flags & E500_TLB_VALID)
kvmppc_e500_tlbil_one(vcpu_e500, gtlbe);
/* Mark the TLB as not backed by the host anymore */
ref->flags = 0;
}
/* used to check for invalidations in progress */
mmu_seq = kvm->mmu_invalidate_seq;
smp_rmb();
/* * Translate guest physical to true physical, acquiring * a page reference if it is normal, non-reserved memory. * * gfn_to_memslot() must succeed because otherwise we wouldn't * have gotten this far. Eventually we should just pass the slot * pointer through from the first lookup.
*/
slot = gfn_to_memslot(vcpu_e500->vcpu.kvm, gfn);
hva = gfn_to_hva_memslot(slot, gfn);
pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, &writable, &page); if (is_error_noslot_pfn(pfn)) { if (printk_ratelimit())
pr_err("%s: real page not found for gfn %lx\n",
__func__, (long)gfn); return -EINVAL;
}
spin_lock(&kvm->mmu_lock); if (mmu_invalidate_retry(kvm, mmu_seq)) {
ret = -EAGAIN; goto out;
}
pgdir = vcpu_e500->vcpu.arch.pgdir; /* * We are just looking at the wimg bits, so we don't * care much about the trans splitting bit. * We are holding kvm->mmu_lock so a notifier invalidate * can't run hence pfn won't change.
*/
local_irq_save(flags);
ptep = find_linux_pte(pgdir, hva, NULL, &psize); if (ptep) {
pte_t pte = READ_ONCE(*ptep);
/* * Any page size that doesn't satisfy the host mapping * will fail the start and end tests.
*/
tsize = min(psize - PAGE_SHIFT + BOOK3E_PAGESZ_4K, tsize);
/* * e500 doesn't implement the lowest tsize bit, * or 1K pages.
*/
tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1);
/* * Now find the largest tsize (up to what the guest * requested) that will cover gfn, stay within the * range, and for which gfn and pfn are mutually * aligned.
*/
/* XXX only map the one-one case, for now use TLB0 */ staticint kvmppc_e500_tlb0_map(struct kvmppc_vcpu_e500 *vcpu_e500, int esel, struct kvm_book3e_206_tlb_entry *stlbe)
{ struct kvm_book3e_206_tlb_entry *gtlbe; struct tlbe_ref *ref; int stlbsel = 0; int sesel = 0; int r;
/* Caller must ensure that the specified guest TLB entry is safe to insert into
* the shadow TLB. */ /* For both one-one and one-to-many */ staticint kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 *vcpu_e500,
u64 gvaddr, gfn_t gfn, struct kvm_book3e_206_tlb_entry *gtlbe, struct kvm_book3e_206_tlb_entry *stlbe, int esel)
{ struct tlbe_ref *ref = &vcpu_e500->gtlb_priv[1][esel].ref; int sesel; int r;
r = kvmppc_e500_shadow_map(vcpu_e500, gvaddr, gfn, gtlbe, 1, stlbe,
ref); if (r) return r;
/* Use TLB0 when we can only map a page with 4k */ if (get_tlb_tsize(stlbe) == BOOK3E_PAGESZ_4K) {
vcpu_e500->gtlb_priv[1][esel].ref.flags |= E500_TLB_TLB0;
write_stlbe(vcpu_e500, gtlbe, stlbe, 0, 0); return 0;
}
/* * If the TLB entry for guest pc was evicted, return to the guest. * There are high chances to find a valid TLB entry next time.
*/ if (!(mas1 & MAS1_VALID)) return EMULATE_AGAIN;
/* * Another thread may rewrite the TLB entry in parallel, don't * execute from the address if the execute permission is not set
*/
pr = vcpu->arch.shared->msr & MSR_PR; if (unlikely((pr && !(mas3 & MAS3_UX)) ||
(!pr && !(mas3 & MAS3_SX)))) {
pr_err_ratelimited( "%s: Instruction emulation from guest address %08lx without execute permission\n",
__func__, geaddr); return EMULATE_AGAIN;
}
/* * The real address will be mapped by a cacheable, memory coherent, * write-back page. Check for mismatches when LRAT is used.
*/ if (has_feature(vcpu, VCPU_FTR_MMU_V2) &&
unlikely((mas2 & MAS2_I) || (mas2 & MAS2_W) || !(mas2 & MAS2_M))) {
pr_err_ratelimited( "%s: Instruction emulation from guest address %08lx mismatches storage attributes\n",
__func__, geaddr); return EMULATE_AGAIN;
}
/* Guard against emulation from devices area */ if (unlikely(!page_is_ram(pfn))) {
pr_err_ratelimited("%s: Instruction emulation from non-RAM host address %08llx is not supported\n",
__func__, addr); return EMULATE_AGAIN;
}
/* Map a page and get guest's instruction */
page = pfn_to_page(pfn);
eaddr = (unsignedlong)kmap_atomic(page);
*instr = *(u32 *)(eaddr | (unsignedlong)(addr & ~PAGE_MASK));
kunmap_atomic((u32 *)eaddr);
staticbool kvm_e500_mmu_unmap_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
{ /* * Flush all shadow tlb entries everywhere. This is slow, but * we are 100% sure that we catch the to be unmapped page
*/ returntrue;
}
/* * This should never happen on real e500 hardware, but is * architecturally possible -- e.g. in some weird nested * virtualization case.
*/ if (host_tlb_params[0].entries == 0 ||
host_tlb_params[1].entries == 0) {
pr_err("%s: need to know host tlb size\n", __func__); return -ENODEV;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.