linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] kvm: debugfs: fix memory leak in kvm_create_vm_debugfs
@ 2021-07-01 19:55 Pavel Skripkin
  2021-07-01 21:24 ` Jing Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Skripkin @ 2021-07-01 19:55 UTC (permalink / raw)
  To: pbonzini, jingzhangos; +Cc: kvm, linux-kernel, Pavel Skripkin

In commit bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
loop for filling debugfs_stat_data was copy-pasted 2 times, but
in the second loop pointers are saved over pointers allocated
in the first loop. It causes memory leak. Fix it.

Fixes: bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 7d95126cda9e..986959833d70 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -935,7 +935,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
 		stat_data->kvm = kvm;
 		stat_data->desc = pdesc;
 		stat_data->kind = KVM_STAT_VCPU;
-		kvm->debugfs_stat_data[i] = stat_data;
+		kvm->debugfs_stat_data[i + kvm_vm_stats_header.num_desc] = stat_data;
 		debugfs_create_file(pdesc->name, kvm_stats_debugfs_mode(pdesc),
 				    kvm->debugfs_dentry, stat_data,
 				    &stat_fops_per_vm);
-- 
2.32.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH next] kvm: debugfs: fix memory leak in kvm_create_vm_debugfs
  2021-07-01 19:55 [PATCH next] kvm: debugfs: fix memory leak in kvm_create_vm_debugfs Pavel Skripkin
@ 2021-07-01 21:24 ` Jing Zhang
  2021-07-08 16:58   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Jing Zhang @ 2021-07-01 21:24 UTC (permalink / raw)
  To: Pavel Skripkin; +Cc: Paolo Bonzini, KVM, linux-kernel

On Thu, Jul 1, 2021 at 2:55 PM Pavel Skripkin <paskripkin@gmail.com> wrote:
>
> In commit bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
> loop for filling debugfs_stat_data was copy-pasted 2 times, but
> in the second loop pointers are saved over pointers allocated
> in the first loop. It causes memory leak. Fix it.
>
> Fixes: bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> ---
>  virt/kvm/kvm_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 7d95126cda9e..986959833d70 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -935,7 +935,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
>                 stat_data->kvm = kvm;
>                 stat_data->desc = pdesc;
>                 stat_data->kind = KVM_STAT_VCPU;
> -               kvm->debugfs_stat_data[i] = stat_data;
> +               kvm->debugfs_stat_data[i + kvm_vm_stats_header.num_desc] = stat_data;
Pavel, thanks for fixing this.

Reviewed-by: Jing Zhang <jingzhangos@google.com>
>                 debugfs_create_file(pdesc->name, kvm_stats_debugfs_mode(pdesc),
>                                     kvm->debugfs_dentry, stat_data,
>                                     &stat_fops_per_vm);
> --
> 2.32.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH next] kvm: debugfs: fix memory leak in kvm_create_vm_debugfs
  2021-07-01 21:24 ` Jing Zhang
@ 2021-07-08 16:58   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-07-08 16:58 UTC (permalink / raw)
  To: Jing Zhang, Pavel Skripkin; +Cc: KVM, linux-kernel

On 01/07/21 23:24, Jing Zhang wrote:
> In commit bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
> loop for filling debugfs_stat_data was copy-pasted 2 times, but
> in the second loop pointers are saved over pointers allocated
> in the first loop. It causes memory leak. Fix it.
> 
> Fixes: bc9e9e672df9 ("KVM: debugfs: Reuse binary stats descriptors")
> Signed-off-by: Pavel Skripkin<paskripkin@gmail.com>
> ---

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-08 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 19:55 [PATCH next] kvm: debugfs: fix memory leak in kvm_create_vm_debugfs Pavel Skripkin
2021-07-01 21:24 ` Jing Zhang
2021-07-08 16:58   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).