qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

cputlb: destroy CPUTLB with tlb_destroy

I was after adding qemu_spin_destroy calls, but while at
it I noticed that we are leaking some memory.

Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20200609200738.445-5-robert.foley@linaro.org>
Message-Id: <20200612190237.30436-8-alex.bennee@linaro.org>

authored by

Emilio G. Cota and committed by
Alex Bennée
816d9be5 4384a70d

+24
+15
accel/tcg/cputlb.c
··· 270 270 } 271 271 } 272 272 273 + void tlb_destroy(CPUState *cpu) 274 + { 275 + CPUArchState *env = cpu->env_ptr; 276 + int i; 277 + 278 + qemu_spin_destroy(&env_tlb(env)->c.lock); 279 + for (i = 0; i < NB_MMU_MODES; i++) { 280 + CPUTLBDesc *desc = &env_tlb(env)->d[i]; 281 + CPUTLBDescFast *fast = &env_tlb(env)->f[i]; 282 + 283 + g_free(fast->table); 284 + g_free(desc->iotlb); 285 + } 286 + } 287 + 273 288 /* flush_all_helper: run fn across all cpus 274 289 * 275 290 * If the wait flag is set then the src cpu's helper will be queued as
+1
exec.c
··· 892 892 { 893 893 CPUClass *cc = CPU_GET_CLASS(cpu); 894 894 895 + tlb_destroy(cpu); 895 896 cpu_list_remove(cpu); 896 897 897 898 if (cc->vmsd != NULL) {
+8
include/exec/exec-all.h
··· 125 125 */ 126 126 void tlb_init(CPUState *cpu); 127 127 /** 128 + * tlb_destroy - destroy a CPU's TLB 129 + * @cpu: CPU whose TLB should be destroyed 130 + */ 131 + void tlb_destroy(CPUState *cpu); 132 + /** 128 133 * tlb_flush_page: 129 134 * @cpu: CPU whose TLB should be flushed 130 135 * @addr: virtual address of page to be flushed ··· 282 287 int mmu_idx, target_ulong size); 283 288 #else 284 289 static inline void tlb_init(CPUState *cpu) 290 + { 291 + } 292 + static inline void tlb_destroy(CPUState *cpu) 285 293 { 286 294 } 287 295 static inline void tlb_flush_page(CPUState *cpu, target_ulong addr)