struct id { unsignedlong val; struct id **pentry;
};
#define NUM_TIDS 256
/* * This table provide mappings from: * (guestAS,guestTID,guestPR) --> ID of physical cpu * guestAS [0..1] * guestTID [0..255] * guestPR [0..1] * ID [1..255] * Each vcpu keeps one vcpu_id_table.
*/ struct vcpu_id_table { struct id id[2][NUM_TIDS][2];
};
/* * This table provide reversed mappings of vcpu_id_table: * ID --> address of vcpu_id_table item. * Each physical core has one pcpu_id_table.
*/ struct pcpu_id_table { struct id *entry[NUM_TIDS];
};
/* This variable keeps last used shadow ID on local core.
* The valid range of shadow ID is [1..255] */ static DEFINE_PER_CPU(unsignedlong, pcpu_last_used_sid);
/* * Allocate a free shadow id and setup a valid sid mapping in given entry. * A mapping is only valid when vcpu_id_table and pcpu_id_table are match. * * The caller must have preemption disabled, and keep it that way until * it has finished with the returned shadow id (either written into the * TLB or arch.shadow_pid, or discarded).
*/ staticinlineint local_sid_setup_one(struct id *entry)
{ unsignedlong sid; int ret = -1;
sid = __this_cpu_inc_return(pcpu_last_used_sid); if (sid < NUM_TIDS) {
__this_cpu_write(pcpu_sids.entry[sid], entry);
entry->val = sid;
entry->pentry = this_cpu_ptr(&pcpu_sids.entry[sid]);
ret = sid;
}
/* * If sid == NUM_TIDS, we've run out of sids. We return -1, and * the caller will invalidate everything and start over. * * sid > NUM_TIDS indicates a race, which we disable preemption to * avoid.
*/
WARN_ON(sid > NUM_TIDS);
return ret;
}
/* * Check if given entry contain a valid shadow id mapping. * An ID mapping is considered valid only if * both vcpu and pcpu know this mapping. * * The caller must have preemption disabled, and keep it that way until * it has finished with the returned shadow id (either written into the * TLB or arch.shadow_pid, or discarded).
*/ staticinlineint local_sid_lookup(struct id *entry)
{ if (entry && entry->val != 0 &&
__this_cpu_read(pcpu_sids.entry[entry->val]) == entry &&
entry->pentry == this_cpu_ptr(&pcpu_sids.entry[entry->val])) return entry->val; return -1;
}
/* Invalidate all id mappings on local core -- call with preempt disabled */ staticinlinevoid local_sid_destroy_all(void)
{
__this_cpu_write(pcpu_last_used_sid, 0);
memset(this_cpu_ptr(&pcpu_sids), 0, sizeof(pcpu_sids));
}
/* Map guest pid to shadow. * We use PID to keep shadow of current guest non-zero PID, * and use PID1 to keep shadow of guest zero PID.
* So that guest tlbe with TID=0 can be accessed at any time */ staticvoid kvmppc_e500_recalc_shadow_pid(struct kvmppc_vcpu_e500 *vcpu_e500)
{
preempt_disable();
vcpu_e500->vcpu.arch.shadow_pid = kvmppc_e500_get_sid(vcpu_e500,
get_cur_as(&vcpu_e500->vcpu),
get_cur_pid(&vcpu_e500->vcpu),
get_cur_pr(&vcpu_e500->vcpu), 1);
vcpu_e500->vcpu.arch.shadow_pid1 = kvmppc_e500_get_sid(vcpu_e500,
get_cur_as(&vcpu_e500->vcpu), 0,
get_cur_pr(&vcpu_e500->vcpu), 1);
preempt_enable();
}
/* Invalidate all mappings on vcpu */ staticvoid kvmppc_e500_id_table_reset_all(struct kvmppc_vcpu_e500 *vcpu_e500)
{
memset(vcpu_e500->idt, 0, sizeof(struct vcpu_id_table));
/* Update shadow pid when mappings are changed */
kvmppc_e500_recalc_shadow_pid(vcpu_e500);
}
/* Invalidate one ID mapping on vcpu */ staticinlinevoid kvmppc_e500_id_table_reset_one( struct kvmppc_vcpu_e500 *vcpu_e500, int as, int pid, int pr)
{ struct vcpu_id_table *idt = vcpu_e500->idt;
/* Update shadow pid when mappings are changed */
kvmppc_e500_recalc_shadow_pid(vcpu_e500);
}
/* * Map guest (vcpu,AS,ID,PR) to physical core shadow id. * This function first lookup if a valid mapping exists, * if not, then creates a new one. * * The caller must have preemption disabled, and keep it that way until * it has finished with the returned shadow id (either written into the * TLB or arch.shadow_pid, or discarded).
*/ unsignedint kvmppc_e500_get_sid(struct kvmppc_vcpu_e500 *vcpu_e500, unsignedint as, unsignedint gid, unsignedint pr, int avoid_recursion)
{ struct vcpu_id_table *idt = vcpu_e500->idt; int sid;
/* gtlbe must not be mapped by more than one host tlbe */ void kvmppc_e500_tlbil_one(struct kvmppc_vcpu_e500 *vcpu_e500, struct kvm_book3e_206_tlb_entry *gtlbe)
{ struct vcpu_id_table *idt = vcpu_e500->idt; unsignedint pr, tid, ts; int pid;
u32 val, eaddr; unsignedlong flags;
ts = get_tlb_ts(gtlbe);
tid = get_tlb_tid(gtlbe);
preempt_disable();
/* One guest ID may be mapped to two shadow IDs */ for (pr = 0; pr < 2; pr++) { /* * The shadow PID can have a valid mapping on at most one * host CPU. In the common case, it will be valid on this * CPU, in which case we do a local invalidation of the * specific address. * * If the shadow PID is not valid on the current host CPU, * we invalidate the entire shadow PID.
*/
pid = local_sid_lookup(&idt->id[ts][tid][pr]); if (pid <= 0) {
kvmppc_e500_id_table_reset_one(vcpu_e500, ts, tid, pr); continue;
}
/* * The guest is invalidating a 4K entry which is in a PID * that has a valid shadow mapping on this host CPU. We * search host TLB to invalidate it's shadow TLB entry, * similar to __tlbil_va except that we need to look in AS1.
*/
val = (pid << MAS6_SPID_SHIFT) | MAS6_SAS;
eaddr = get_tlb_eaddr(gtlbe);
local_irq_save(flags);
mtspr(SPRN_MAS6, val); asmvolatile("tlbsx 0, %[eaddr]" : : [eaddr] "r" (eaddr));
val = mfspr(SPRN_MAS1); if (val & MAS1_VALID) {
mtspr(SPRN_MAS1, val & ~MAS1_VALID); asmvolatile("tlbwe");
}
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.