LoongArch: KVM: Fix memory leak in kvm_loongarch_env_init() error path
Subsystems (3)
PATCH 1/1 LoongArch: KVM: Fix memory leak in kvm_loongarch_env_init() error path
kvm_loongarch_env_init() allocates the per-CPU kvm_context (vmcs) and kvm_loongarch_ops, and registers the perf callbacks, before registering the IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices. If any of those device registrations fails, the function returned the error directly without freeing vmcs and kvm_loongarch_ops or unregistering the perf callbacks. kvm_loongarch_init() propagates the error without calling kvm_loongarch_env_exit(), so these resources are leaked.
Unwind the already-acquired resources on the error path, mirroring kvm_loongarch_env_exit().
--- arch/loongarch/kvm/main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
arch/loongarch/kvm/main.c +15 -4
@@ -385,22 +385,33 @@ static int kvm_loongarch_env_init(void)/* Register LoongArch IPI interrupt controller interface. */ ret =kvm_loongarch_register_ipi_device ();if (ret) -return ret; + goto err;/* Register LoongArch EIOINTC interrupt controller interface. */ ret =kvm_loongarch_register_eiointc_device ();if (ret) -return ret; + goto err;/* Register LoongArch PCH-PIC interrupt controller interface. */ ret =kvm_loongarch_register_pch_pic_device ();if (ret) -return ret; + goto err;/* Register LoongArch DMSINTC interrupt contrroller interface */ -if (cpu_has_msgint) +if (cpu_has_msgint) { ret =kvm_loongarch_register_dmsintc_device (); +if (ret) + goto err; + } +return 0 ; + +err: +kvm_unregister_perf_callbacks (); +kfree (kvm_loongarch_ops); + kvm_loongarch_ops =NULL ; +free_percpu (vmcs); + vmcs =NULL ;return ret; }
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] If kvm_init() fails inside kvm_loongarch_init(), the resources successfully allocated by kvm_loongarch_env_init() are never cleaned up, resulting in memory leaks and a Use-After-Free vulnerability in the perf subsystem. --
--- Patch [1]: [PATCH] LoongArch: KVM: Fix memory leak in kvm_loongarch_env_init() error path --- commit 3316df872b1f0235601822bdf17b8099f74a1eed
Author: Chaithanya Lagisetty <[email protected]>
LoongArch: KVM: Fix memory leak in kvm_loongarch_env_init() error path
kvm_loongarch_env_init() allocates the per-CPU kvm_context (vmcs) and kvm_loongarch_ops, and registers the perf callbacks, before registering the IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices. If any of those device registrations fails, the function returned the error directly without freeing vmcs and kvm_loongarch_ops or unregistering the perf callbacks. kvm_loongarch_init() propagates the error without calling kvm_loongarch_env_exit(), so these resources are leaked.
Unwind the already-acquired resources on the error path, mirroring kvm_loongarch_env_exit().
Quoted 5 lines
arch/loongarch/kvm/main.c +0
-0@@ -384,22 +384,33 @@ static int kvm_loongarch_env_init(void)
[ ... ]
arch/loongarch/kvm/main.c static int kvm_loongarch_env_init(void) · line 416
Quoted 8 lines
arch/loongarch/kvm/main.c +6
-0+err: +kvm_unregister_perf_callbacks (); +kfree (kvm_loongarch_ops); + kvm_loongarch_ops =NULL ; +free_percpu (vmcs); + vmcs =NULL ;return ret; }
[Severity: High]
This is a pre-existing issue, but since we are fixing leaks in this area, what happens if kvm_loongarch_env_init() succeeds but kvm_init() fails?
Looking at the caller kvm_loongarch_init():
static int kvm_loongarch_init(void)
{
...
r = kvm_loongarch_env_init();
if (r)
return r;
return kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
}If kvm_init() fails, its error is propagated directly without calling kvm_loongarch_env_exit() to unwind the environment.
Does this mean the resources allocated by kvm_loongarch_env_init() are still leaked in that error path?
If the perf callbacks remain registered when the module load fails, could this result in a use-after-free in the perf core since the module memory will be freed?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Huacai Chen
maintainerHi, Bibo,
What do you think about this?
Huacai
Quoted 63 lines · Chaithanya Lagisetty
kvm_loongarch_env_init()allocates the per-CPUkvm_context(vmcs) andkvm_loongarch_ops, and registers the perf callbacks, before registering the IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices. If any of those device registrations fails, the function returned the error directly without freeing vmcs andkvm_loongarch_opsor unregistering the perf callbacks.kvm_loongarch_init()propagates the error without callingkvm_loongarch_env_exit(), so these resources are leaked.Unwind the already-acquired resources on the error path, mirroring
kvm_loongarch_env_exit().Fixes c532de5a67a7 ("LoongArch: KVM: Add IPI device support")Signed-off-by Chaithanya Lagisetty <[email protected]>--- arch/loongarch/kvm/main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)arch/loongarch/kvm/main.c +15
-5@@ -385,22 +385,33 @@ static int kvm_loongarch_env_init(void)/* Register LoongArch IPI interrupt controller interface. */ ret =kvm_loongarch_register_ipi_device ();if (ret) -return ret; + goto err;/* Register LoongArch EIOINTC interrupt controller interface. */ ret =kvm_loongarch_register_eiointc_device ();if (ret) -return ret; + goto err;/* Register LoongArch PCH-PIC interrupt controller interface. */ ret =kvm_loongarch_register_pch_pic_device ();if (ret) -return ret; + goto err;/* Register LoongArch DMSINTC interrupt contrroller interface */ -if (cpu_has_msgint) +if (cpu_has_msgint) { ret =kvm_loongarch_register_dmsintc_device (); +if (ret) + goto err; + } +return 0 ; + +err: +kvm_unregister_perf_callbacks (); +kfree (kvm_loongarch_ops); + kvm_loongarch_ops =NULL ; +free_percpu (vmcs); + vmcs =NULL ;return ret; } --2.43.0
Bibo Mao
maintainerQuoted 29 lines · Chaithanya Lagisetty
kvm_loongarch_env_init()allocates the per-CPUkvm_context(vmcs) andkvm_loongarch_ops, and registers the perf callbacks, before registering the IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices. If any of those device registrations fails, the function returned the error directly without freeing vmcs andkvm_loongarch_opsor unregistering the perf callbacks.kvm_loongarch_init()propagates the error without callingkvm_loongarch_env_exit(), so these resources are leaked.Unwind the already-acquired resources on the error path, mirroring
kvm_loongarch_env_exit().Fixes c532de5a67a7 ("LoongArch: KVM: Add IPI device support")Signed-off-by Chaithanya Lagisetty <[email protected]>--- arch/loongarch/kvm/main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)arch/loongarch/kvm/main.c +1
-1@@ -385,22 +385,33 @@ static int kvm_loongarch_env_init(void)/* Register LoongArch IPI interrupt controller interface. */ ret =kvm_loongarch_register_ipi_device ();if (ret) -return ret; + goto err;/* Register LoongArch EIOINTC interrupt controller interface. */
arch/loongarch/kvm/main.c static int kvm_loongarch_env_init(void) · line 398
Quoted 10 lines
arch/loongarch/kvm/main.c +2
-2ret =kvm_loongarch_register_eiointc_device ();if (ret) -return ret; + goto err;/* Register LoongArch PCH-PIC interrupt controller interface. */ ret =kvm_loongarch_register_pch_pic_device ();if (ret) -return ret; + goto err;
It will be better if there is wrapped unregister function, to remove previous registered callback. The same with eiointc/dmsintc driver, something like this:
+
+void kvm_loongarch_unregister_pch_pic_device(void)
+{
+ return kvm_unregister_device_ops(KVM_DEV_TYPE_LOONGARCH_PCHPIC);
+}
Regards
Bibo Mao
Quoted 21 lines
arch/loongarch/kvm/main.c +12
-1/* Register LoongArch DMSINTC interrupt contrroller interface */ -if (cpu_has_msgint) +if (cpu_has_msgint) { ret =kvm_loongarch_register_dmsintc_device (); +if (ret) + goto err; + } +return 0 ; + +err: +kvm_unregister_perf_callbacks (); +kfree (kvm_loongarch_ops); + kvm_loongarch_ops =NULL ; +free_percpu (vmcs); + vmcs =NULL ;return ret; }
v2 cover LoongArch: KVM: Fix kvm_loongarch_env_init() error path
In reply to Chaithanya Lagisettykvm_loongarch_env_init() leaves everything it has already acquired behind when one of the IPI/EIOINTC/PCH-PIC/DMSINTC device registrations fails, and kvm_loongarch_init() does not call kvm_loongarch_env_exit() on that error, so nothing else cleans up either.
v1 unwound only the memory and the perf callbacks. Bibo Mao pointed out that the device registrations should be undone through wrapped unregister helpers, so patch 1 adds those and patch 2 uses them to unwind the error path in reverse order of registration. Patch 2 also uses them in kvm_loongarch_env_exit(), so that the device ops are unregistered on normal teardown as well.
v2:
- Add unregister helpers as suggested by Bibo Mao
- Unwind device registrations in reverse order
- Use unregister helpers in kvm_loongarch_env_exit()
- Split into two patches, so the fix only uses the helpers
- Reword commit message to avoid implementation-specific details, and retitle from "memory leak" to "resource leak"
Compile-tested only, no LoongArch hardware: loongson64_defconfig with CONFIG_KVM=m and CONFIG_KVM=y, W=1, each patch built individually, no new warnings.
Chaithanya Lagisetty (2):
LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error
path
arch/loongarch/include/asm/kvm_dmsintc.h | 1 + arch/loongarch/include/asm/kvm_eiointc.h | 1 + arch/loongarch/include/asm/kvm_ipi.h | 1 + arch/loongarch/include/asm/kvm_pch_pic.h | 1 + arch/loongarch/kvm/intc/dmsintc.c | 5 ++++ arch/loongarch/kvm/intc/eiointc.c | 5 ++++ arch/loongarch/kvm/intc/ipi.c | 5 ++++ arch/loongarch/kvm/intc/pch_pic.c | 5 ++++ arch/loongarch/kvm/main.c | 32 +++++++++++++++++++++--- 9 files changed, 52 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
The IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices each have a helper that registers their kvm_device_ops, but there is no counterpart to remove them again, so a caller that needs to undo a registration has to open-code kvm_unregister_device_ops() with the matching device type.
Add kvm_loongarch_unregister_{ipi,eiointc,pch_pic,dmsintc}_device() next to the existing register helpers. kvm_unregister_device_ops() is a no-op when the corresponding device type is not currently registered.
No functional change, as there are no callers yet.
--- arch/loongarch/include/asm/kvm_dmsintc.h | 1 + arch/loongarch/include/asm/kvm_eiointc.h | 1 + arch/loongarch/include/asm/kvm_ipi.h | 1 + arch/loongarch/include/asm/kvm_pch_pic.h | 1 + arch/loongarch/kvm/intc/dmsintc.c | 5 +++++ arch/loongarch/kvm/intc/eiointc.c | 5 +++++ arch/loongarch/kvm/intc/ipi.c | 5 +++++ arch/loongarch/kvm/intc/pch_pic.c | 5 +++++ 8 files changed, 24 insertions(+)
arch/loongarch/include/asm/kvm_dmsintc.h +1 -0
@@ -20,6 +20,7 @@ struct dmsintc_state { };int kvm_loongarch_register_dmsintc_device (void ); +void kvm_loongarch_unregister_dmsintc_device (void );void dmsintc_inject_irq (struct kvm_vcpu *vcpu);int dmsintc_set_irq (struct kvm *kvm,u64 addr,int data,int level);int dmsintc_deliver_msi_to_vcpu (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 vector,int level);
arch/loongarch/include/asm/kvm_eiointc.h +1 -0
@@ -79,6 +79,7 @@ struct loongarch_eiointc { };int kvm_loongarch_register_eiointc_device (void ); +void kvm_loongarch_unregister_eiointc_device (void );void eiointc_set_irq (struct loongarch_eiointc *s,int irq,int level);#endif /* __ASM_KVM_EIOINTC_H */
arch/loongarch/include/asm/kvm_ipi.h +1 -0
@@ -41,5 +41,6 @@ struct ipi_state {#define IOCSR_ANY_SEND 0x158int kvm_loongarch_register_ipi_device (void ); +void kvm_loongarch_unregister_ipi_device (void );#endif
arch/loongarch/include/asm/kvm_pch_pic.h +1 -0
@@ -70,6 +70,7 @@ struct loongarch_pch_pic {struct kvm_kernel_irq_routing_entry ;int kvm_loongarch_register_pch_pic_device (void ); +void kvm_loongarch_unregister_pch_pic_device (void );void pch_pic_set_irq (struct loongarch_pch_pic *s,int irq,int level);int pch_msi_set_irq (struct kvm *kvm,struct kvm_kernel_irq_routing_entry *e,int level);
arch/loongarch/kvm/intc/dmsintc.c +5 -0
@@ -180,3 +180,8 @@ int kvm_loongarch_register_dmsintc_device(void) {return kvm_register_device_ops (&kvm_dmsintc_dev_ops,KVM_DEV_TYPE_LOONGARCH_DMSINTC ); } + +void kvm_loongarch_unregister_dmsintc_device (void ) +{ +kvm_unregister_device_ops (KVM_DEV_TYPE_LOONGARCH_DMSINTC ); +}
arch/loongarch/kvm/intc/eiointc.c +5 -0
@@ -695,3 +695,8 @@ int kvm_loongarch_register_eiointc_device(void) {return kvm_register_device_ops (&kvm_eiointc_dev_ops,KVM_DEV_TYPE_LOONGARCH_EIOINTC ); } + +void kvm_loongarch_unregister_eiointc_device (void ) +{ +kvm_unregister_device_ops (KVM_DEV_TYPE_LOONGARCH_EIOINTC ); +}
arch/loongarch/kvm/intc/ipi.c +5 -0
@@ -463,3 +463,8 @@ int kvm_loongarch_register_ipi_device(void) {return kvm_register_device_ops (&kvm_ipi_dev_ops,KVM_DEV_TYPE_LOONGARCH_IPI ); } + +void kvm_loongarch_unregister_ipi_device (void ) +{ +kvm_unregister_device_ops (KVM_DEV_TYPE_LOONGARCH_IPI ); +}
arch/loongarch/kvm/intc/pch_pic.c +5 -0
@@ -500,3 +500,8 @@ int kvm_loongarch_register_pch_pic_device(void) {return kvm_register_device_ops (&kvm_pch_pic_dev_ops,KVM_DEV_TYPE_LOONGARCH_PCHPIC ); } + +void kvm_loongarch_unregister_pch_pic_device (void ) +{ +kvm_unregister_device_ops (KVM_DEV_TYPE_LOONGARCH_PCHPIC ); +}
Signature · 1 line
2.43.0
PATCH v2 2/2 LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error path
In reply to Chaithanya Lagisettykvm_loongarch_env_init() allocates the per-CPU kvm_context (vmcs) and kvm_loongarch_ops, registers the perf callbacks, and then registers the IPI/EIOINTC/PCH-PIC/DMSINTC KVM devices. If any of those device registrations fails, the function returned the error directly, leaving everything acquired so far in place: vmcs and kvm_loongarch_ops are never freed, the perf callbacks stay registered, and previously registered KVM device ops remain registered. kvm_loongarch_init() propagates the error without calling kvm_loongarch_env_exit(), so nothing else cleans up either.
Unwind the error path in reverse order of registration, so that each failure only undoes what had actually been set up. Use the same helpers in kvm_loongarch_env_exit() to remove the device registrations during normal teardown as well.
--- arch/loongarch/kvm/main.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)
arch/loongarch/kvm/main.c +28 -4
@@ -385,27 +385,51 @@ static int kvm_loongarch_env_init(void)/* Register LoongArch IPI interrupt controller interface. */ ret =kvm_loongarch_register_ipi_device ();if (ret) -return ret; + goto err_env;/* Register LoongArch EIOINTC interrupt controller interface. */ ret =kvm_loongarch_register_eiointc_device ();if (ret) -return ret; + goto err_ipi;/* Register LoongArch PCH-PIC interrupt controller interface. */ ret =kvm_loongarch_register_pch_pic_device ();if (ret) -return ret; + goto err_eiointc;/* Register LoongArch DMSINTC interrupt contrroller interface */ -if (cpu_has_msgint) +if (cpu_has_msgint) { ret =kvm_loongarch_register_dmsintc_device (); +if (ret) + goto err_pch_pic; + } + +return 0 ; + +err_pch_pic: +kvm_loongarch_unregister_pch_pic_device (); +err_eiointc: +kvm_loongarch_unregister_eiointc_device (); +err_ipi: +kvm_loongarch_unregister_ipi_device (); +err_env: +kvm_unregister_perf_callbacks (); +kfree (kvm_loongarch_ops); + kvm_loongarch_ops =NULL ; +free_percpu (vmcs); + vmcs =NULL ;return ret; }static void kvm_loongarch_env_exit (void ) { +if (cpu_has_msgint) +kvm_loongarch_unregister_dmsintc_device (); +kvm_loongarch_unregister_pch_pic_device (); +kvm_loongarch_unregister_eiointc_device (); +kvm_loongarch_unregister_ipi_device (); +if (vmcs)free_percpu (vmcs);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 2/2] LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error path
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Resources allocated by kvm_loongarch_env_init() are leaked and lead to a Use-After-Free if kvm_init() fails in kvm_loongarch_init(). --
commit 694694d624a3a8bfec5f756c533d743cd130b9fa
Author: Chaithanya Lagisetty <[email protected]>
LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error path
This commit fixes a resource leak in the error path of kvm_loongarch_env_init(). It ensures that previously acquired resources and device registrations are unwound in reverse order if any subsequent registration fails.
Quoted 4 lines
arch/loongarch/kvm/main.c +0
-0
[ ... ]
Quoted 34 lines
arch/loongarch/kvm/main.c +15
-4@@ -385,27 +385,51 @@ static int kvm_loongarch_env_init(void)/* Register LoongArch IPI interrupt controller interface. */ ret =kvm_loongarch_register_ipi_device ();if (ret) -return ret; + goto err_env;/* Register LoongArch EIOINTC interrupt controller interface. */ ret =kvm_loongarch_register_eiointc_device ();if (ret) -return ret; + goto err_ipi;/* Register LoongArch PCH-PIC interrupt controller interface. */ ret =kvm_loongarch_register_pch_pic_device ();if (ret) -return ret; + goto err_eiointc;/* Register LoongArch DMSINTC interrupt contrroller interface */ -if (cpu_has_msgint) +if (cpu_has_msgint) { ret =kvm_loongarch_register_dmsintc_device (); +if (ret) + goto err_pch_pic; + } + +return 0 ; + +err_pch_pic: +kvm_loongarch_unregister_pch_pic_device (); +err_eiointc: +kvm_loongarch_unregister_eiointc_device (); +err_ipi:
arch/loongarch/kvm/main.c static int kvm_loongarch_env_init(void) · line 423
Quoted 10 lines
arch/loongarch/kvm/main.c +7
-0+kvm_loongarch_unregister_ipi_device (); +err_env: +kvm_unregister_perf_callbacks (); +kfree (kvm_loongarch_ops); + kvm_loongarch_ops =NULL ; +free_percpu (vmcs); + vmcs =NULL ;return ret; }
[Severity: High]
This is a pre-existing issue, but does this leak the vmcs, kvm_loongarch_ops, and device registrations when kvm_init() fails in kvm_loongarch_init()?
arch/loongarch/kvm/main.c:kvm_loongarch_init() {
...
r = kvm_loongarch_env_init();
if (r)
return r;
return kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
}If kvm_init() fails, kvm_loongarch_init() returns the error directly without calling kvm_loongarch_env_exit() to clean up the successful kvm_loongarch_env_init() setup.
Could this leave dangling function pointers in the perf core that lead to a kernel panic upon the next performance counter event?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 0/2] LoongArch: KVM: Fix kvm_loongarch_env_init() error path
In reply to Chaithanya LagisettyQuoted 31 lines · Chaithanya Lagisetty
kvm_loongarch_env_init()leaves everything it has already acquired behind when one of the IPI/EIOINTC/PCH-PIC/DMSINTC device registrations fails, andkvm_loongarch_init()does not callkvm_loongarch_env_exit()on that error, so nothing else cleans up either.v1 unwound only the memory and the perf callbacks. Bibo Mao pointed out that the device registrations should be undone through wrapped unregister helpers, so patch 1 adds those and patch 2 uses them to unwind the error path in reverse order of registration. Patch 2 also uses them in
kvm_loongarch_env_exit(), so that the device ops are unregistered on normal teardown as well.v2:
- Add unregister helpers as suggested by Bibo Mao
- Unwind device registrations in reverse order
- Use unregister helpers inkvm_loongarch_env_exit()
- Split into two patches, so the fix only uses the helpers
- Reword commit message to avoid implementation-specific details, and retitle from "memory leak" to "resource leak"Compile-tested only, no LoongArch hardware:
loongson64_defconfigwithCONFIG_KVM=mandCONFIG_KVM=y, W=1, each patch built individually, no new warnings.Chaithanya Lagisetty (2):
LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
LoongArch: KVM: Fix resource leak inkvm_loongarch_env_init()error
path
Quoted 11 lines
arch/loongarch/include/asm/kvm_dmsintc.h | 1 + arch/loongarch/include/asm/kvm_eiointc.h | 1 + arch/loongarch/include/asm/kvm_ipi.h | 1 + arch/loongarch/include/asm/kvm_pch_pic.h | 1 + arch/loongarch/kvm/intc/dmsintc.c | 5 ++++ arch/loongarch/kvm/intc/eiointc.c | 5 ++++ arch/loongarch/kvm/intc/ipi.c | 5 ++++ arch/loongarch/kvm/intc/pch_pic.c | 5 ++++ arch/loongarch/kvm/main.c | 32 +++++++++++++++++++++--- 9 files changed, 52 insertions(+), 4 deletions(-)
For this series:
Re: [PATCH v2 0/2] LoongArch: KVM: Fix kvm_loongarch_env_init() error path
In reply to Chaithanya LagisettyApplied, thanks.
Huacai
Quoted 46 lines · Chaithanya Lagisetty
kvm_loongarch_env_init()leaves everything it has already acquired behind when one of the IPI/EIOINTC/PCH-PIC/DMSINTC device registrations fails, andkvm_loongarch_init()does not callkvm_loongarch_env_exit()on that error, so nothing else cleans up either.v1 unwound only the memory and the perf callbacks. Bibo Mao pointed out that the device registrations should be undone through wrapped unregister helpers, so patch 1 adds those and patch 2 uses them to unwind the error path in reverse order of registration. Patch 2 also uses them in
kvm_loongarch_env_exit(), so that the device ops are unregistered on normal teardown as well.v2:
- Add unregister helpers as suggested by Bibo Mao
- Unwind device registrations in reverse order
- Use unregister helpers inkvm_loongarch_env_exit()
- Split into two patches, so the fix only uses the helpers
- Reword commit message to avoid implementation-specific details, and retitle from "memory leak" to "resource leak"Compile-tested only, no LoongArch hardware:
loongson64_defconfigwithCONFIG_KVM=mandCONFIG_KVM=y, W=1, each patch built individually, no new warnings.Chaithanya Lagisetty (2):
LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
LoongArch: KVM: Fix resource leak inkvm_loongarch_env_init()error
patharch/loongarch/include/asm/kvm_dmsintc.h | 1 + arch/loongarch/include/asm/kvm_eiointc.h | 1 + arch/loongarch/include/asm/kvm_ipi.h | 1 + arch/loongarch/include/asm/kvm_pch_pic.h | 1 + arch/loongarch/kvm/intc/dmsintc.c | 5 ++++ arch/loongarch/kvm/intc/eiointc.c | 5 ++++ arch/loongarch/kvm/intc/ipi.c | 5 ++++ arch/loongarch/kvm/intc/pch_pic.c | 5 ++++ arch/loongarch/kvm/main.c | 32 +++++++++++++++++++++--- 9 files changed, 52 insertions(+), 4 deletions(-)--
2.43.0