Message ID | 20220321141409.3112932-6-mark.kanda@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vCPU hotunplug related memory leaks | expand |
On 21/3/22 15:14, Mark Kanda wrote: > Create KVM and HVF specific destory_vcpu_thread() routines to free Typo "destroy" > env->xsave_buf. > > vCPU hotunplug related leak reported by Valgrind: > > ==132362== 4,096 bytes in 1 blocks are definitely lost in loss record 8,440 of 8,549 > ==132362== at 0x4C3B15F: memalign (vg_replace_malloc.c:1265) > ==132362== by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429) > ==132362== by 0xB41195: qemu_try_memalign (memalign.c:53) > ==132362== by 0xB41204: qemu_memalign (memalign.c:73) > ==132362== by 0x7131CB: kvm_init_xsave (kvm.c:1601) > ==132362== by 0x7148ED: kvm_arch_init_vcpu (kvm.c:2031) > ==132362== by 0x91D224: kvm_init_vcpu (kvm-all.c:516) > ==132362== by 0x9242C9: kvm_vcpu_thread_fn (kvm-accel-ops.c:40) > ==132362== by 0xB2EB26: qemu_thread_start (qemu-thread-posix.c:556) > ==132362== by 0x7EB2159: start_thread (in /usr/lib64/libpthread-2.28.so) > ==132362== by 0x9D45DD2: clone (in /usr/lib64/libc-2.28.so) > > Signed-off-by: Mark Kanda <mark.kanda@oracle.com> > --- > accel/hvf/hvf-accel-ops.c | 11 ++++++++++- > accel/kvm/kvm-accel-ops.c | 11 ++++++++++- > 2 files changed, 20 insertions(+), 2 deletions(-) Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
On 21/3/22 23:04, Philippe Mathieu-Daudé wrote: > On 21/3/22 15:14, Mark Kanda wrote: >> Create KVM and HVF specific destory_vcpu_thread() routines to free > > Typo "destroy" > >> env->xsave_buf. >> >> vCPU hotunplug related leak reported by Valgrind: >> >> ==132362== 4,096 bytes in 1 blocks are definitely lost in loss record >> 8,440 of 8,549 >> ==132362== at 0x4C3B15F: memalign (vg_replace_malloc.c:1265) >> ==132362== by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429) >> ==132362== by 0xB41195: qemu_try_memalign (memalign.c:53) >> ==132362== by 0xB41204: qemu_memalign (memalign.c:73) >> ==132362== by 0x7131CB: kvm_init_xsave (kvm.c:1601) >> ==132362== by 0x7148ED: kvm_arch_init_vcpu (kvm.c:2031) >> ==132362== by 0x91D224: kvm_init_vcpu (kvm-all.c:516) >> ==132362== by 0x9242C9: kvm_vcpu_thread_fn (kvm-accel-ops.c:40) >> ==132362== by 0xB2EB26: qemu_thread_start (qemu-thread-posix.c:556) >> ==132362== by 0x7EB2159: start_thread (in >> /usr/lib64/libpthread-2.28.so) >> ==132362== by 0x9D45DD2: clone (in /usr/lib64/libc-2.28.so) >> >> Signed-off-by: Mark Kanda <mark.kanda@oracle.com> >> --- >> accel/hvf/hvf-accel-ops.c | 11 ++++++++++- >> accel/kvm/kvm-accel-ops.c | 11 ++++++++++- >> 2 files changed, 20 insertions(+), 2 deletions(-) > > Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> I meant: Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
On 21/3/22 23:08, Philippe Mathieu-Daudé wrote: > On 21/3/22 23:04, Philippe Mathieu-Daudé wrote: >> On 21/3/22 15:14, Mark Kanda wrote: >>> Create KVM and HVF specific destory_vcpu_thread() routines to free >> >> Typo "destroy" >> >>> env->xsave_buf. >>> >>> vCPU hotunplug related leak reported by Valgrind: >>> >>> ==132362== 4,096 bytes in 1 blocks are definitely lost in loss record >>> 8,440 of 8,549 >>> ==132362== at 0x4C3B15F: memalign (vg_replace_malloc.c:1265) >>> ==132362== by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429) >>> ==132362== by 0xB41195: qemu_try_memalign (memalign.c:53) >>> ==132362== by 0xB41204: qemu_memalign (memalign.c:73) >>> ==132362== by 0x7131CB: kvm_init_xsave (kvm.c:1601) >>> ==132362== by 0x7148ED: kvm_arch_init_vcpu (kvm.c:2031) >>> ==132362== by 0x91D224: kvm_init_vcpu (kvm-all.c:516) >>> ==132362== by 0x9242C9: kvm_vcpu_thread_fn (kvm-accel-ops.c:40) >>> ==132362== by 0xB2EB26: qemu_thread_start (qemu-thread-posix.c:556) >>> ==132362== by 0x7EB2159: start_thread (in >>> /usr/lib64/libpthread-2.28.so) >>> ==132362== by 0x9D45DD2: clone (in /usr/lib64/libc-2.28.so) >>> >>> Signed-off-by: Mark Kanda <mark.kanda@oracle.com> >>> --- >>> accel/hvf/hvf-accel-ops.c | 11 ++++++++++- >>> accel/kvm/kvm-accel-ops.c | 11 ++++++++++- >>> 2 files changed, 20 insertions(+), 2 deletions(-) >> >> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > > I meant: > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Withdrawing these tags with HVF. First xsave_buf is only allocated by KVM, second accel/ directory is meant to be target agnostic, so x86-specific code there is not right.
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index b23a67881c..bc53890352 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -462,12 +462,21 @@ static void hvf_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } +static void hvf_destroy_vcpu_thread(CPUState *cpu) +{ + X86CPU *x86_cpu = X86_CPU(cpu); + CPUX86State *env = &x86_cpu->env; + + g_free(env->xsave_buf); + generic_destroy_vcpu_thread(cpu); +} + static void hvf_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); ops->create_vcpu_thread = hvf_start_vcpu_thread; - ops->destroy_vcpu_thread = generic_destroy_vcpu_thread; + ops->destroy_vcpu_thread = hvf_destroy_vcpu_thread; ops->kick_vcpu_thread = hvf_kick_vcpu_thread; ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset; diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 5a7a9ae79c..0345a30139 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -74,6 +74,15 @@ static void kvm_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } +static void kvm_destroy_vcpu_thread(CPUState *cpu) +{ + X86CPU *x86_cpu = X86_CPU(cpu); + CPUX86State *env = &x86_cpu->env; + + g_free(env->xsave_buf); + generic_destroy_vcpu_thread(cpu); +} + static bool kvm_vcpu_thread_is_idle(CPUState *cpu) { return !kvm_halt_in_kernel(); @@ -89,7 +98,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); ops->create_vcpu_thread = kvm_start_vcpu_thread; - ops->destroy_vcpu_thread = generic_destroy_vcpu_thread; + ops->destroy_vcpu_thread = kvm_destroy_vcpu_thread; ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle; ops->cpus_are_resettable = kvm_cpus_are_resettable; ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
Create KVM and HVF specific destory_vcpu_thread() routines to free env->xsave_buf. vCPU hotunplug related leak reported by Valgrind: ==132362== 4,096 bytes in 1 blocks are definitely lost in loss record 8,440 of 8,549 ==132362== at 0x4C3B15F: memalign (vg_replace_malloc.c:1265) ==132362== by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429) ==132362== by 0xB41195: qemu_try_memalign (memalign.c:53) ==132362== by 0xB41204: qemu_memalign (memalign.c:73) ==132362== by 0x7131CB: kvm_init_xsave (kvm.c:1601) ==132362== by 0x7148ED: kvm_arch_init_vcpu (kvm.c:2031) ==132362== by 0x91D224: kvm_init_vcpu (kvm-all.c:516) ==132362== by 0x9242C9: kvm_vcpu_thread_fn (kvm-accel-ops.c:40) ==132362== by 0xB2EB26: qemu_thread_start (qemu-thread-posix.c:556) ==132362== by 0x7EB2159: start_thread (in /usr/lib64/libpthread-2.28.so) ==132362== by 0x9D45DD2: clone (in /usr/lib64/libc-2.28.so) Signed-off-by: Mark Kanda <mark.kanda@oracle.com> --- accel/hvf/hvf-accel-ops.c | 11 ++++++++++- accel/kvm/kvm-accel-ops.c | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-)