Skip to content

Commit 0c34657

Browse files
lixianglaigaosong-loongson
authored andcommitted
target/loongarch: Fix the cpu unplug resource leak
When the cpu is created, qemu_add_vm_change_state_handler is called in the kvm_arch_init_vcpu function to create the VMChangeStateEntry resource. However, the resource is not released when the cpu is destroyed. This results in a qemu process segment error when the virtual machine restarts after the cpu is unplugged. This patch solves the problem by adding the corresponding resource release process to the kvm_arch_destroy_vcpu function. Signed-off-by: Xianglai Li <[email protected]> Reviewed-by: Bibo Mao <[email protected]> Message-Id: <[email protected]> Signed-off-by: Song Gao <[email protected]>
1 parent b876e72 commit 0c34657

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

target/loongarch/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ struct ArchCPU {
426426
const char *dtb_compatible;
427427
/* used by KVM_REG_LOONGARCH_COUNTER ioctl to access guest time counters */
428428
uint64_t kvm_state_counter;
429+
VMChangeStateEntry *vmsentry;
429430
};
430431

431432
/**

target/loongarch/kvm/kvm.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
10801080
uint64_t val;
10811081
int ret;
10821082
Error *local_err = NULL;
1083+
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
10831084

1084-
qemu_add_vm_change_state_handler(kvm_loongarch_vm_stage_change, cs);
1085+
cpu->vmsentry = qemu_add_vm_change_state_handler(
1086+
kvm_loongarch_vm_stage_change, cs);
10851087

10861088
if (!kvm_get_one_reg(cs, KVM_REG_LOONGARCH_DEBUG_INST, &val)) {
10871089
brk_insn = val;
@@ -1197,6 +1199,9 @@ void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
11971199

11981200
int kvm_arch_destroy_vcpu(CPUState *cs)
11991201
{
1202+
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
1203+
1204+
qemu_del_vm_change_state_handler(cpu->vmsentry);
12001205
return 0;
12011206
}
12021207

0 commit comments

Comments
 (0)