Skip to contentSkip to conversation

mips: fix cpu_reset memory leak

RFC PATCH In review Blue Swirl 2 participants 3 messages Nov 8, 2009 – Nov 14, 2009

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

RFC PATCH 1/1 mips: fix cpu_reset memory leak

Both mmu_init() and mvp_init() allocate structures, so call cpu_mips_register only when creating a CPU.

In addition, maybe some of the some of the field initialization stuff in cpu_mips_register, mmu_init, mvp_init, fpu_init etc. should be moved to cpu_reset instead, in case the fields should be reset to original values during CPU reset. Maximally only the env->mvp etc. structure allocation would be left to cpu_mips_register. This is the minimal version, but it may be incorrect. Comments?

---
 target-mips/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-mips/translate.c +1 -1
index 58f483f..738efb7 100644
@@ -8601,6 +8601,7 @@ CPUMIPSState *cpu_mips_init (const char *cpu_model)
 
     cpu_exec_init(env);
     env->cpu_model_str = cpu_model;
+    cpu_mips_register(env, def);
     mips_tcg_init();
     cpu_reset(env);
     qemu_init_vcpu(env);
@@ -8654,7 +8655,6 @@ void cpu_reset (CPUMIPSState *env)
     env->hflags = MIPS_HFLAG_CP0;
 #endif
     env->exception_index = EXCP_NONE;
-    cpu_mips_register(env, env->cpu_model);
 }
 
 void gen_pc_load(CPUState *env, TranslationBlock *tb,
Signature · 1 line
1.6.2.4
#1 lore raw
Quoted 9 lines · Blue Swirl

Both mmu_init() and mvp_init() allocate structures, so call cpu_mips_register only when creating a CPU.

In addition, maybe some of the some of the field initialization stuff in cpu_mips_register, mmu_init, mvp_init, fpu_init etc. should be moved to cpu_reset instead, in case the fields should be reset to original values during CPU reset. Maximally only the env->mvp etc. structure allocation would be left to cpu_mips_register. This is the minimal version, but it may be incorrect. Comments?

There is clearly a problem with some _init functions being called at each reset. However, your solution does not reset all the registers upon reset. osme of the registers are read-only (e.g. CP0_PRid) so it's not a problem, but some other are read-write (e.g. CP0_Config2). It looks like we need more code move to fix the problem.

Quoted 30 lines
---
 target-mips/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-mips/translate.c +1 -1
index 58f483f..738efb7 100644
@@ -8601,6 +8601,7 @@ CPUMIPSState *cpu_mips_init (const char *cpu_model)
 
     cpu_exec_init(env);
     env->cpu_model_str = cpu_model;
+    cpu_mips_register(env, def);
     mips_tcg_init();
     cpu_reset(env);
     qemu_init_vcpu(env);
@@ -8654,7 +8655,6 @@ void cpu_reset (CPUMIPSState *env)
     env->hflags = MIPS_HFLAG_CP0;
 #endif
     env->exception_index = EXCP_NONE;
-    cpu_mips_register(env, env->cpu_model);
 }
 
 void gen_pc_load(CPUState *env, TranslationBlock *tb,
Signature · 1 line
1.6.2.4
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#2 lore raw
Quoted 11 lines · Aurelien Jarno
Quoted 9 lines · Blue Swirl

Both mmu_init() and mvp_init() allocate structures, so call cpu_mips_register only when creating a CPU.

In addition, maybe some of the some of the field initialization stuff in cpu_mips_register, mmu_init, mvp_init, fpu_init etc. should be moved to cpu_reset instead, in case the fields should be reset to original values during CPU reset. Maximally only the env->mvp etc. structure allocation would be left to cpu_mips_register. This is the minimal version, but it may be incorrect. Comments?

Quoted 6 lines

There is clearly a problem with some _init functions being called at each reset. However, your solution does not reset all the registers upon reset. osme of the registers are read-only (e.g. CP0_PRid) so it's not a problem, but some other are read-write (e.g. CP0_Config2). It looks like we need more code move to fix the problem.

I have just pushed a patch that should fix the problem.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net