Skip to content

Commit

Permalink
cputlb: Change tlb_flush() argument to CPUState
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Färber <[email protected]>
  • Loading branch information
afaerber committed Mar 13, 2014
1 parent 31b030d commit 00c8cb0
Show file tree
Hide file tree
Showing 41 changed files with 143 additions and 87 deletions.
6 changes: 3 additions & 3 deletions cputlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ int tlb_flush_count;
* entries from the TLB at any time, so flushing more entries than
* required is only an efficiency issue, not a correctness issue.
*/
void tlb_flush(CPUArchState *env, int flush_global)
void tlb_flush(CPUState *cpu, int flush_global)
{
CPUState *cpu = ENV_GET_CPU(env);
CPUArchState *env = cpu->env_ptr;

#if defined(DEBUG_TLB)
printf("tlb_flush:\n");
Expand Down Expand Up @@ -93,7 +93,7 @@ void tlb_flush_page(CPUState *cpu, target_ulong addr)
TARGET_FMT_lx "/" TARGET_FMT_lx ")\n",
env->tlb_flush_addr, env->tlb_flush_mask);
#endif
tlb_flush(env, 1);
tlb_flush(cpu, 1);
return;
}
/* must reset current TB so that interrupts cannot modify the
Expand Down
4 changes: 1 addition & 3 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,14 +1834,12 @@ static void tcg_commit(MemoryListener *listener)
reset the modified entries */
/* XXX: slow ! */
CPU_FOREACH(cpu) {
CPUArchState *env = cpu->env_ptr;

/* FIXME: Disentangle the cpu.h circular files deps so we can
directly get the right CPU from listener. */
if (cpu->tcg_as_listener != listener) {
continue;
}
tlb_flush(env, 1);
tlb_flush(cpu, 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion hw/sh4/sh7750.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ static void sh7750_mem_writel(void *opaque, hwaddr addr,
case SH7750_PTEH_A7:
/* If asid changes, clear all registered tlb entries. */
if ((s->cpu->env.pteh & 0xff) != (mem_value & 0xff)) {
tlb_flush(&s->cpu->env, 1);
tlb_flush(CPU(s->cpu), 1);
}
s->cpu->env.pteh = mem_value;
return;
Expand Down
4 changes: 2 additions & 2 deletions include/exec/exec-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end,
void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as);
/* cputlb.c */
void tlb_flush_page(CPUState *cpu, target_ulong addr);
void tlb_flush(CPUArchState *env, int flush_global);
void tlb_flush(CPUState *cpu, int flush_global);
void tlb_set_page(CPUArchState *env, target_ulong vaddr,
hwaddr paddr, int prot,
int mmu_idx, target_ulong size);
Expand All @@ -109,7 +109,7 @@ static inline void tlb_flush_page(CPUState *cpu, target_ulong addr)
{
}

static inline void tlb_flush(CPUArchState *env, int flush_global)
static inline void tlb_flush(CPUState *cpu, int flush_global)
{
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion target-alpha/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static void alpha_cpu_initfn(Object *obj)

cs->env_ptr = env;
cpu_exec_init(env);
tlb_flush(env, 1);
tlb_flush(cs, 1);

alpha_translate_init();

Expand Down
2 changes: 1 addition & 1 deletion target-alpha/sys_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void helper_call_pal(CPUAlphaState *env, uint64_t pc, uint64_t entry_ofs)

void helper_tbia(CPUAlphaState *env)
{
tlb_flush(env, 1);
tlb_flush(CPU(alpha_env_get_cpu(env)), 1);
}

void helper_tbis(CPUAlphaState *env, uint64_t p)
Expand Down
2 changes: 1 addition & 1 deletion target-arm/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void arm_cpu_reset(CPUState *s)
&env->vfp.fp_status);
set_float_detect_tininess(float_tininess_before_rounding,
&env->vfp.standard_fp_status);
tlb_flush(env, 1);
tlb_flush(s, 1);
/* Reset is a state change for some CPUARMState fields which we
* bake assumptions about into translated code, so we need to
* tb_flush().
Expand Down
39 changes: 29 additions & 10 deletions target-arm/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,30 +303,36 @@ void init_cpreg_list(ARMCPU *cpu)

static void dacr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
{
ARMCPU *cpu = arm_env_get_cpu(env);

env->cp15.c3 = value;
tlb_flush(env, 1); /* Flush TLB as domain not tracked in TLB */
tlb_flush(CPU(cpu), 1); /* Flush TLB as domain not tracked in TLB */
}

static void fcse_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
{
ARMCPU *cpu = arm_env_get_cpu(env);

if (env->cp15.c13_fcse != value) {
/* Unlike real hardware the qemu TLB uses virtual addresses,
* not modified virtual addresses, so this causes a TLB flush.
*/
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
env->cp15.c13_fcse = value;
}
}

static void contextidr_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
ARMCPU *cpu = arm_env_get_cpu(env);

if (env->cp15.c13_context != value && !arm_feature(env, ARM_FEATURE_MPU)) {
/* For VMSA (when not using the LPAE long descriptor page table
* format) this register includes the ASID, so do a TLB flush.
* For PMSA it is purely a process ID and no action is needed.
*/
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
}
env->cp15.c13_context = value;
}
Expand All @@ -335,7 +341,9 @@ static void tlbiall_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
/* Invalidate all (TLBIALL) */
tlb_flush(env, 1);
ARMCPU *cpu = arm_env_get_cpu(env);

tlb_flush(CPU(cpu), 1);
}

static void tlbimva_write(CPUARMState *env, const ARMCPRegInfo *ri,
Expand All @@ -351,7 +359,9 @@ static void tlbiasid_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
/* Invalidate by ASID (TLBIASID) */
tlb_flush(env, value == 0);
ARMCPU *cpu = arm_env_get_cpu(env);

tlb_flush(CPU(cpu), value == 0);
}

static void tlbimvaa_write(CPUARMState *env, const ARMCPRegInfo *ri,
Expand Down Expand Up @@ -1352,11 +1362,13 @@ static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri,
static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
ARMCPU *cpu = arm_env_get_cpu(env);

if (arm_feature(env, ARM_FEATURE_LPAE)) {
/* With LPAE the TTBCR could result in a change of ASID
* via the TTBCR.A1 bit, so do a TLB flush.
*/
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
}
vmsa_ttbcr_raw_write(env, ri, value);
}
Expand All @@ -1371,8 +1383,10 @@ static void vmsa_ttbcr_reset(CPUARMState *env, const ARMCPRegInfo *ri)
static void vmsa_tcr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
ARMCPU *cpu = arm_env_get_cpu(env);

/* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
env->cp15.c2_control = value;
}

Expand All @@ -1383,7 +1397,9 @@ static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri,
* must flush the TLB.
*/
if (cpreg_field_is_64bit(ri)) {
tlb_flush(env, 1);
ARMCPU *cpu = arm_env_get_cpu(env);

tlb_flush(CPU(cpu), 1);
}
raw_write(env, ri, value);
}
Expand Down Expand Up @@ -1708,8 +1724,9 @@ static void tlbi_aa64_asid_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
/* Invalidate by ASID (AArch64 version) */
ARMCPU *cpu = arm_env_get_cpu(env);
int asid = extract64(value, 48, 16);
tlb_flush(env, asid == 0);
tlb_flush(CPU(cpu), asid == 0);
}

static const ARMCPRegInfo v8_cp_reginfo[] = {
Expand Down Expand Up @@ -1835,10 +1852,12 @@ static const ARMCPRegInfo v8_cp_reginfo[] = {
static void sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
uint64_t value)
{
ARMCPU *cpu = arm_env_get_cpu(env);

env->cp15.c1_sys = value;
/* ??? Lots of these bits are not implemented. */
/* This may enable/disable the MMU, so do a TLB flush. */
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
}

static CPAccessResult ctr_el0_access(CPUARMState *env, const ARMCPRegInfo *ri)
Expand Down
2 changes: 1 addition & 1 deletion target-cris/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void cris_cpu_reset(CPUState *s)
vr = env->pregs[PR_VR];
memset(env, 0, offsetof(CPUCRISState, load_info));
env->pregs[PR_VR] = vr;
tlb_flush(env, 1);
tlb_flush(s, 1);

#if defined(CONFIG_USER_ONLY)
/* start in user mode with interrupts enabled. */
Expand Down
2 changes: 1 addition & 1 deletion target-i386/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,7 @@ static void x86_cpu_reset(CPUState *s)

memset(env, 0, offsetof(CPUX86State, pat));

tlb_flush(env, 1);
tlb_flush(s, 1);

env->old_exception = -1;

Expand Down
17 changes: 12 additions & 5 deletions target-i386/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,30 +385,33 @@ void x86_cpu_set_a20(X86CPU *cpu, int a20_state)

a20_state = (a20_state != 0);
if (a20_state != ((env->a20_mask >> 20) & 1)) {
CPUState *cs = CPU(cpu);

#if defined(DEBUG_MMU)
printf("A20 update: a20=%d\n", a20_state);
#endif
/* if the cpu is currently executing code, we must unlink it and
all the potentially executing TB */
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_EXITTB);
cpu_interrupt(cs, CPU_INTERRUPT_EXITTB);

/* when a20 is changed, all the MMU mappings are invalid, so
we must flush everything */
tlb_flush(env, 1);
tlb_flush(cs, 1);
env->a20_mask = ~(1 << 20) | (a20_state << 20);
}
}

void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)
{
X86CPU *cpu = x86_env_get_cpu(env);
int pe_state;

#if defined(DEBUG_MMU)
printf("CR0 update: CR0=0x%08x\n", new_cr0);
#endif
if ((new_cr0 & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK)) !=
(env->cr[0] & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK))) {
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
}

#ifdef TARGET_X86_64
Expand Down Expand Up @@ -444,24 +447,28 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)
the PDPT */
void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3)
{
X86CPU *cpu = x86_env_get_cpu(env);

env->cr[3] = new_cr3;
if (env->cr[0] & CR0_PG_MASK) {
#if defined(DEBUG_MMU)
printf("CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3);
#endif
tlb_flush(env, 0);
tlb_flush(CPU(cpu), 0);
}
}

void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
{
X86CPU *cpu = x86_env_get_cpu(env);

#if defined(DEBUG_MMU)
printf("CR4 update: CR4=%08x\n", (uint32_t)env->cr[4]);
#endif
if ((new_cr4 ^ env->cr[4]) &
(CR4_PGE_MASK | CR4_PAE_MASK | CR4_PSE_MASK |
CR4_SMEP_MASK | CR4_SMAP_MASK)) {
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
}
/* SSE handling */
if (!(env->features[FEAT_1_EDX] & CPUID_SSE)) {
Expand Down
2 changes: 1 addition & 1 deletion target-i386/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static int cpu_post_load(void *opaque, int version_id)
for (i = 0; i < DR7_MAX_BP; i++) {
hw_breakpoint_insert(env, i);
}
tlb_flush(env, 1);
tlb_flush(cs, 1);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion target-i386/svm_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
break;
case TLB_CONTROL_FLUSH_ALL_ASID:
/* FIXME: this is not 100% correct but should work for now */
tlb_flush(env, 1);
tlb_flush(cs, 1);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion target-lm32/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void lm32_cpu_reset(CPUState *s)
memset(env, 0, offsetof(CPULM32State, eba));

lm32_cpu_init_cfg_reg(cpu);
tlb_flush(env, 1);
tlb_flush(s, 1);
}

static void lm32_cpu_realizefn(DeviceState *dev, Error **errp)
Expand Down
2 changes: 1 addition & 1 deletion target-m68k/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void m68k_cpu_reset(CPUState *s)
env->cc_op = CC_OP_FLAGS;
/* TODO: We should set PC from the interrupt vector. */
env->pc = 0;
tlb_flush(env, 1);
tlb_flush(s, 1);
}

/* CPU models */
Expand Down
2 changes: 1 addition & 1 deletion target-microblaze/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void mb_cpu_reset(CPUState *s)

memset(env, 0, sizeof(CPUMBState));
env->res_addr = RES_ADDR_NONE;
tlb_flush(env, 1);
tlb_flush(s, 1);

/* Disable stack protector. */
env->shr = ~0;
Expand Down
3 changes: 2 additions & 1 deletion target-microblaze/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ uint32_t mmu_read(CPUMBState *env, uint32_t rn)

void mmu_write(CPUMBState *env, uint32_t rn, uint32_t v)
{
MicroBlazeCPU *cpu = mb_env_get_cpu(env);
unsigned int i;
D(qemu_log("%s rn=%d=%x old=%x\n", __func__, rn, v, env->mmu.regs[rn]));

Expand Down Expand Up @@ -252,7 +253,7 @@ void mmu_write(CPUMBState *env, uint32_t rn, uint32_t v)
/* Changes to the zone protection reg flush the QEMU TLB.
Fortunately, these are very uncommon. */
if (v != env->mmu.regs[rn]) {
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
}
env->mmu.regs[rn] = v;
break;
Expand Down
2 changes: 1 addition & 1 deletion target-mips/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void mips_cpu_reset(CPUState *s)
mcc->parent_reset(s);

memset(env, 0, offsetof(CPUMIPSState, mvp));
tlb_flush(env, 1);
tlb_flush(s, 1);

cpu_state_reset(env);
}
Expand Down
3 changes: 2 additions & 1 deletion target-mips/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static void load_fpu(QEMUFile *f, CPUMIPSFPUContext *fpu)
int cpu_load(QEMUFile *f, void *opaque, int version_id)
{
CPUMIPSState *env = opaque;
MIPSCPU *cpu = mips_env_get_cpu(env);
int i;

if (version_id != 3)
Expand Down Expand Up @@ -303,6 +304,6 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
load_fpu(f, &env->fpus[i]);

/* XXX: ensure compatibility for halted bit ? */
tlb_flush(env, 1);
tlb_flush(CPU(cpu), 1);
return 0;
}
Loading

0 comments on commit 00c8cb0

Please sign in to comment.