domain: move vmtrace_alloc_buffer() invocation in vcpu_create()
PATCH 1/1 domain: move vmtrace_alloc_buffer() invocation in vcpu_create()
The label used upon the function failing is wrong. Instead of correcting the label, move the invocation up a little, to also avoid it altogether for the idle domain (where ->vmtrace_size would be zero, and hence the function would bail right away anyway).
xen/common/domain.c +3 -3
@@ -493,14 +493,14 @@ struct vcpu *vcpu_create(struct domain *set_bit (_VPF_down, &v->pause_flags);vcpu_info_reset (v);init_waitqueue_vcpu (v); + +if (vmtrace_alloc_buffer (v) !=0 ) + goto fail_wq; }if (sched_init_vcpu (v) !=0 ) goto fail_wq; -if (vmtrace_alloc_buffer (v) !=0 ) - goto fail_wq; -if (arch_vcpu_create (v) !=0 ) goto fail_sched;
Quoted 1 line · Jan Beulich
The label used upon the function failing is wrong.
Is it? Which label do you think it ought to be?
Quoted 19 lines
Instead of correcting
the label, move the invocation up a little, to also avoid it altogether for the idle domain (where ->vmtrace_size would be zero, and hence the function would bail right away anyway).Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Reported-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>xen/common/domain.c +3
-0@@ -493,14 +493,14 @@ struct vcpu *vcpu_create(struct domain *set_bit (_VPF_down, &v->pause_flags);vcpu_info_reset (v);init_waitqueue_vcpu (v); + +if (vmtrace_alloc_buffer (v) !=0 ) + goto fail_wq; }
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 506
Quoted 10 lines
xen/common/domain.c +0
-3if (sched_init_vcpu (v) !=0 ) goto fail_wq; -if (vmtrace_alloc_buffer (v) !=0 ) - goto fail_wq; -if (arch_vcpu_create (v) !=0 ) goto fail_sched;
The positioning was intentional. I just didn't get to wiring up Intel PT for Xen context yet, and tying the buffer to the idle vCPU would be the obvious choice there.
The chances of getting around to that are admittedly low, so I don't mind moving the call in principle (noting that this is a wish that likely won't materialise), but the claim over the label needs resolving.
~Andrew
Quoted 4 lines · Andrew Cooper
Quoted 1 line · Jan Beulich
The label used upon the function failing is wrong.
Is it? Which label do you think it ought to be?
fail_sched, as Roger did point out in reply to the original other patch. After all ...
Quoted 20 lines
Quoted 20 lines
Instead of correcting
the label, move the invocation up a little, to also avoid it altogether for the idle domain (where ->vmtrace_size would be zero, and hence the function would bail right away anyway).Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Reported-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>xen/common/domain.c +3
-0@@ -493,14 +493,14 @@ struct vcpu *vcpu_create(struct domain *set_bit (_VPF_down, &v->pause_flags);vcpu_info_reset (v);init_waitqueue_vcpu (v); + +if (vmtrace_alloc_buffer (v) !=0 ) + goto fail_wq; }
Quoted 2 lines
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 502
Quoted 2 lines
xen/common/domain.c +0
-0if (sched_init_vcpu (v) !=0 ) goto fail_wq;
... this comes first, and ...
Quoted 5 lines
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 505
Quoted 5 lines
xen/common/domain.c +0
-3-if (vmtrace_alloc_buffer (v) !=0 ) - goto fail_wq; -if (arch_vcpu_create (v) !=0 ) goto fail_sched;
... here the correct label is used.
Jan
Quoted 9 lines
The positioning was intentional. I just didn't get to wiring up Intel PT for Xen context yet, and tying the buffer to the idle vCPU would be the obvious choice there.
The chances of getting around to that are admittedly low, so I don't mind moving the call in principle (noting that this is a wish that likely won't materialise), but the claim over the label needs resolving.
~Andrew
Quoted 31 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
Quoted 1 line · Jan Beulich
The label used upon the function failing is wrong.
Is it? Which label do you think it ought to be?
fail_sched, as Roger did point out in reply to the original other patch. After all ...Quoted 20 lines
Quoted 20 lines
Instead of correcting
the label, move the invocation up a little, to also avoid it altogether for the idle domain (where ->vmtrace_size would be zero, and hence the function would bail right away anyway).Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Reported-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>xen/common/domain.c +3
-0@@ -493,14 +493,14 @@ struct vcpu *vcpu_create(struct domain *set_bit (_VPF_down, &v->pause_flags);vcpu_info_reset (v);init_waitqueue_vcpu (v); + +if (vmtrace_alloc_buffer (v) !=0 ) + goto fail_wq; }Quoted 2 lines
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 502
Quoted 2 lines
xen/common/domain.c +0
-0if (sched_init_vcpu (v) !=0 ) goto fail_wq;... this comes first, and ...
Quoted 6 lines
Quoted 5 lines
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 505
Quoted 5 lines
xen/common/domain.c +0
-3-if (vmtrace_alloc_buffer (v) !=0 ) - goto fail_wq; -if (arch_vcpu_create (v) !=0 ) goto fail_sched;... here the correct label is used.
Eww, yes. So multiple observations.
1) This only functions in the first place because destroy_waitqueue_vcpu() is idempotent to v->waitqueue_vcpu being NULL which covers the idle case where init_waitqueue_vcpu() was never called.
2) sched_destroy_vcpu() can be made idempotent against v->sched_unit.
Then we don't need multiple labels and this all gets a lot easier to untangle.
~Andrew
Quoted 41 lines · Andrew Cooper
Quoted 31 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
Quoted 1 line · Jan Beulich
The label used upon the function failing is wrong.
Is it? Which label do you think it ought to be?
fail_sched, as Roger did point out in reply to the original other patch. After all ...Quoted 20 lines
Quoted 20 lines
Instead of correcting
the label, move the invocation up a little, to also avoid it altogether for the idle domain (where ->vmtrace_size would be zero, and hence the function would bail right away anyway).Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Reported-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>xen/common/domain.c +3
-0@@ -493,14 +493,14 @@ struct vcpu *vcpu_create(struct domain *set_bit (_VPF_down, &v->pause_flags);vcpu_info_reset (v);init_waitqueue_vcpu (v); + +if (vmtrace_alloc_buffer (v) !=0 ) + goto fail_wq; }Quoted 2 lines
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 502
Quoted 2 lines
xen/common/domain.c +0
-0if (sched_init_vcpu (v) !=0 ) goto fail_wq;... this comes first, and ...
Quoted 6 lines
Quoted 5 lines
xen/common/domain.c struct vcpu *vcpu_create(struct domain * · line 505
Quoted 5 lines
xen/common/domain.c +0
-3-if (vmtrace_alloc_buffer (v) !=0 ) - goto fail_wq; -if (arch_vcpu_create (v) !=0 ) goto fail_sched;... here the correct label is used.
Eww, yes. So multiple observations.
Quoted 8 lines
1) This only functions in the first place because
destroy_waitqueue_vcpu()is idempotent tov->waitqueue_vcpubeing NULL which covers the idle case whereinit_waitqueue_vcpu()was never called.2)
sched_destroy_vcpu()can be made idempotent againstv->sched_unit.Then we don't need multiple labels and this all gets a lot easier to untangle.
Yes, but as a backportable fix what I have here is the most suitable first step, I'd say.
With what you suggest, I'd then want to check whether either or both of the function invocations could move into vcpu_teardown(). At least for destroy_waitqueue_vcpu() I can't really figure why it's called only in complete_domain_destroy(); for sched_destroy_vcpu() it may well be that it can't be done earlier. Or wait, looks like vm_event_cleanup() would need moving up in domain_kill(). The comment there right now explains why it can't be done later; it's not quite clear to me whether moving it ahead of (or into) domain_teardown() would introduce any problems. Tamas?
Jan
Quoted 8 lines · Jan Beulich
The label used upon the function failing is wrong. Instead of correcting the label, move the invocation up a little, to also avoid it altogether for the idle domain (where ->vmtrace_size would be zero, and hence the function would bail right away anyway).
Fixes 217dd79ee292 ("xen/domain: Add vmtrace_size domain creation parameter")Reported-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.