Skip to contentSkip to conversation

LoongArch: KVM: Fix kvm_device leak in kvm_{pch_pic|ipi|eiointc}_destroy

PATCH In review Qiang Ma 2 participants 5 messages Dec 26, 2025 – Dec 31, 2025

Subsystems (3)
lore
Share & tools
lore

Qiang Ma

author
#0 lore raw

cover LoongArch: KVM: Fix kvm_device leak in kvm_{pch_pic|ipi|eiointc}_destroy

In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_pch_pic_destroy() is not currently doing this, that would lead to a memory leak.

So, fix it.

Qiang Ma (3):
LoongArch: KVM: Fix kvm_device leak in kvm_pch_pic_destroy
LoongArch: KVM: Fix kvm_device leak in kvm_ipi_destroy
LoongArch: KVM: Fix kvm_device leak in kvm_eiointc_destroy

 arch/loongarch/kvm/intc/eiointc.c | 2 ++
 arch/loongarch/kvm/intc/ipi.c     | 2 ++
 arch/loongarch/kvm/intc/pch_pic.c | 2 ++
 3 files changed, 6 insertions(+)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/3 LoongArch: KVM: Fix kvm_device leak in kvm_pch_pic_destroy

In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_pch_pic_destroy() is not currently doing this, that would lead to a memory leak.

So, fix it.

---
 arch/loongarch/kvm/intc/pch_pic.c | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/kvm/intc/pch_pic.c +2 -0
index a698a73de399..f710c904b40c 100644
@@ -475,6 +475,8 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev)
 	/* unregister pch pic device and free it's memory */
 	kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device);
 	kfree(s);
+	/* alloc by kvm_ioctl_create_device, free by .destroy */
+	kfree(dev);
 }
 
 static struct kvm_device_ops kvm_pch_pic_dev_ops = {
Signature · 1 line
2.20.1
author
#2 lore raw

PATCH 2/3 LoongArch: KVM: Fix kvm_device leak in kvm_ipi_destroy

In reply to Qiang Ma

In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_ipi_destroy() is not currently doing this, that would lead to a memory leak.

So, fix it.

---
 arch/loongarch/kvm/intc/ipi.c | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/kvm/intc/ipi.c +2 -0
index 05cefd29282e..77169bf49f3f 100644
@@ -459,6 +459,8 @@ static void kvm_ipi_destroy(struct kvm_device *dev)
 	ipi = kvm->arch.ipi;
 	kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &ipi->device);
 	kfree(ipi);
+	/* alloc by kvm_ioctl_create_device, free by .destroy */
+	kfree(dev);
 }
 
 static struct kvm_device_ops kvm_ipi_dev_ops = {
Signature · 1 line
2.20.1
author
#3 lore raw

PATCH 3/3 LoongArch: KVM: Fix kvm_device leak in kvm_eiointc_destroy

In reply to Qiang Ma

In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_eiointc_destroy() is not currently doing this, that would lead to a memory leak.

So, fix it.

---
 arch/loongarch/kvm/intc/eiointc.c | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/kvm/intc/eiointc.c +2 -0
index 29886876143f..cb94c7e8267a 100644
@@ -679,6 +679,8 @@ static void kvm_eiointc_destroy(struct kvm_device *dev)
 	kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device);
 	kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device_vext);
 	kfree(eiointc);
+	/* alloc by kvm_ioctl_create_device, free by .destroy */
+	kfree(dev);
 }
 
 static struct kvm_device_ops kvm_eiointc_dev_ops = {
Signature · 1 line
2.20.1
maintainer Reviewed-by on the v1 series
#4 lore raw
In reply to Qiang Ma

Hi qiang,

Thanks for the patch, it looks good to me.

For the whole series.

Regards
Bibo Mao

Quoted 17 lines · Qiang Ma

In kvm_ioctl_create_device(), kvm_device has allocated memory, kvm_device->destroy() seems to be supposed to free its kvm_device struct, but kvm_pch_pic_destroy() is not currently doing this, that would lead to a memory leak.

So, fix it.

Qiang Ma (3):
LoongArch: KVM: Fix kvm_device leak in kvm_pch_pic_destroy
LoongArch: KVM: Fix kvm_device leak in kvm_ipi_destroy
LoongArch: KVM: Fix kvm_device leak in kvm_eiointc_destroy

  arch/loongarch/kvm/intc/eiointc.c | 2 ++
  arch/loongarch/kvm/intc/ipi.c     | 2 ++
  arch/loongarch/kvm/intc/pch_pic.c | 2 ++
  3 files changed, 6 insertions(+)