xen: fix memory leak on error in vcpu_create
PATCH 1/1 xen: fix memory leak on error in vcpu_create
In vcpu_create after scheduler data is allocated, if vmtrace_alloc_buffer fails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.
--- xen/common/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/domain.c +1 -1
@@ -451,7 +451,7 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id) goto fail_wq;if (vmtrace_alloc_buffer (v) !=0 ) - goto fail_wq; + goto fail_sched;if (arch_vcpu_create (v) !=0 ) goto fail_sched;
base-commit: a845b50c12f3ec3a14255f5eb3062d0c9801a356
Signature · 1 line
2.50.1
Quoted 6 lines · Stewart Hildebrand
In
vcpu_createafter scheduler data is allocated, ifvmtrace_alloc_bufferfails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Signed-off-by Stewart Hildebrand <[email protected]>
Urgh, sorry for breaking this. Ultimately it comes from having two different error handling schemes.
This patch is probably ok to start with (and to backport), but a better fix would be to handle sched and wq in vcpu_teardown(). That way we get a single failure path that does the correct thing irrespective.
An unrelated observation, but there's a waitqueue vcpu allocated in the common path, but I was under the impression that only x86 had any need for wqv (and I still need to get around to fixing introspection so we can drop wait.c entirely).
~Andrew
Quoted 10 lines · Andrew Cooper
Quoted 6 lines · Stewart Hildebrand
In
vcpu_createafter scheduler data is allocated, ifvmtrace_alloc_bufferfails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Signed-off-by Stewart Hildebrand <[email protected]>Urgh, sorry for breaking this. Ultimately it comes from having two different error handling schemes.
Quoted 8 lines
This patch is probably ok to start with (and to backport), but a better fix would be to handle sched and wq in vcpu_teardown(). That way we get a single failure path that does the correct thing irrespective.
An unrelated observation, but there's a waitqueue vcpu allocated in the common path, but I was under the impression that only x86 had any need for wqv (and I still need to get around to fixing introspection so we can drop
wait.centirely).
P.S. we allocate full wqv for idle CPUs, and they definitely do not need it on any architecture. Looks like there's some low hanging fruit here too.
~Andrew
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Andrew Cooper
Quoted 6 lines · Stewart Hildebrand
In
vcpu_createafter scheduler data is allocated, ifvmtrace_alloc_bufferfails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Signed-off-by Stewart Hildebrand <[email protected]>Urgh, sorry for breaking this. Ultimately it comes from having two different error handling schemes.
This patch is probably ok to start with (and to backport), but a better fix would be to handle sched and wq in vcpu_teardown(). That way we get a single failure path that does the correct thing irrespective.
Quoted 7 lines
Quoted 4 lines
An unrelated observation, but there's a waitqueue vcpu allocated in the common path, but I was under the impression that only x86 had any need for wqv (and I still need to get around to fixing introspection so we can drop
wait.centirely).
P.S. we allocate full wqv for idle CPUs, and they definitely do not need it on any architecture. Looks like there's some low hanging fruit here too.
Hmm, the only init_waitqueue_vcpu() that I see is in an "else" to an "if ( is_idle_domain(d) )".
Jan
Quoted 8 lines · Andrew Cooper
Quoted 6 lines · Stewart Hildebrand
In
vcpu_createafter scheduler data is allocated, ifvmtrace_alloc_bufferfails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Signed-off-by Stewart Hildebrand <[email protected]>
Quoted 6 lines
Urgh, sorry for breaking this. Ultimately it comes from having two different error handling schemes.
This patch is probably ok to start with (and to backport), but a better fix would be to handle sched and wq in vcpu_teardown(). That way we get a single failure path that does the correct thing irrespective.
I agree, and that variant would apparently be as easily backportable. Stewart, are you up for going that route?
Jan
Quoted 6 lines
An unrelated observation, but there's a waitqueue vcpu allocated in the common path, but I was under the impression that only x86 had any need for wqv (and I still need to get around to fixing introspection so we can drop
wait.centirely).~Andrew
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 6 lines · Stewart Hildebrand
In
vcpu_createafter scheduler data is allocated, ifvmtrace_alloc_bufferfails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Signed-off-by Stewart Hildebrand <[email protected]>Urgh, sorry for breaking this. Ultimately it comes from having two different error handling schemes.
Quoted 6 lines
Quoted 3 lines
This patch is probably ok to start with (and to backport), but a better fix would be to handle sched and wq in vcpu_teardown(). That way we get a single failure path that does the correct thing irrespective.
I agree, and that variant would apparently be as easily backportable. Stewart, are you up for going that route?
Yep, I'll give it a try
Quoted 10 lines
Jan
Quoted 6 lines
An unrelated observation, but there's a waitqueue vcpu allocated in the common path, but I was under the impression that only x86 had any need for wqv (and I still need to get around to fixing introspection so we can drop
wait.centirely).~Andrew
Quoted 12 lines · Stewart Hildebrand
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
Quoted 6 lines · Stewart Hildebrand
In
vcpu_createafter scheduler data is allocated, ifvmtrace_alloc_bufferfails, it will jump to the wrong cleanup label resulting in a memory leak. Correct the label.Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Signed-off-by Stewart Hildebrand <[email protected]>Urgh, sorry for breaking this. Ultimately it comes from having two different error handling schemes.
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
This patch is probably ok to start with (and to backport), but a better fix would be to handle sched and wq in vcpu_teardown(). That way we get a single failure path that does the correct thing irrespective.
I agree, and that variant would apparently be as easily backportable. Stewart, are you up for going that route?
Yep, I'll give it a try
Just as a heads up before you start, the key is to ensure that anything called in *_teardown() is idempotent.
~Andrew