x86/vmx: always sync PIR to IRR before vmentry
PATCH 1/1 x86/vmx: always sync PIR to IRR before vmentry
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected vlapic_has_pending_irq might not be called, and thus PIR won't be synced into IRR.
Fix this by making sure PIR is always synced to IRR in vmx_intr_assist regardless of what interrupts are pending.
While there also simplify the code in __vmx_deliver_posted_interrupt:
there's no need to raise a softirq if the destination vCPU is the one currently running on the pCPU. The sync of PIR into IRR will be performed by vmx_intr_assist regardless of whether there's a softirq pending.
--- xen/arch/x86/hvm/vmx/intr.c | 8 +++++ xen/arch/x86/hvm/vmx/vmx.c | 60 ++++++++++--------------------- xen/include/asm-x86/hvm/vmx/vmx.h | 1 + 3 files changed, 28 insertions(+), 41 deletions(-)
xen/arch/x86/hvm/vmx/intr.c +8 -0
@@ -232,6 +232,14 @@ void vmx_intr_assist(void)enum hvm_intblk intblk;int pt_vector; +if ( cpu_has_vmx_posted_intr_processing ) +/* +* Always force PIR to be synced to IRR before vmentry, this is also +* done by vlapic_has_pending_irq but it's possible other pending +* interrupts prevent the execution of that function. +*/ +vmx_sync_pir_to_irr (v); +/* Block event injection when single step with MTF. */ if (unlikely (v->arch.hvm.single_step) ) {
xen/arch/x86/hvm/vmx/vmx.c +19 -41
82 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmx.h +1 -0
@@ -101,6 +101,7 @@ void vmx_update_debug_state(struct vcpu *v);void vmx_update_exception_bitmap (struct vcpu *v);void vmx_update_cpu_exec_control (struct vcpu *v);void vmx_update_secondary_exec_control (struct vcpu *v); +void vmx_sync_pir_to_irr (struct vcpu *v);#define POSTED_INTR_ON 0#define POSTED_INTR_SN 1
Signature · 7 lines
2.24.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.
For this part, did you consider pulling ahead to the beginning of hvm_vcpu_has_pending_irq() its call to vlapic_has_pending_irq()? I ask because ...
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 241
Quoted 13 lines
xen/arch/x86/hvm/vmx/intr.c +7
-0@@ -232,6 +232,14 @@ void vmx_intr_assist(void)enum hvm_intblk intblk;int pt_vector; +if ( cpu_has_vmx_posted_intr_processing ) +/* +* Always force PIR to be synced to IRR before vmentry, this is also +* done by vlapic_has_pending_irq but it's possible other pending +* interrupts prevent the execution of that function. +*/ +vmx_sync_pir_to_irr (v);
... this addition looks more like papering over some issue than actually taking care of it.
Then again I wonder whether the PIR->IRR sync is actually legitimate to perform when v != current. If it's not, then there might be a wider set of problems (see e.g. hvm_local_events_need_delivery()). But of course the adjustment to hvm_vcpu_has_pending_irq() could also be to make the call early only when v == current.
A last question is that on the consequences of overly aggressive sync-ing - that'll harm performance, but shouldn't affect correctness if I'm not mistaken.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?
I assumed the order in hvm_vcpu_has_pending_irq is there for a reason. I could indeed move vlapic_has_pending_irq to the top, but then either the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic in vlapic_has_pending_irq), or we invert the priority of event injection.
I have to admit I have doubts about the code in hvm_vcpu_has_pending_irq. I'm not sure what's the motivation for example to give priority to HVMIRQ_callback_vector over other vectors from the lapic.
Quoted 8 lines
I ask because ...
Quoted 6 lines
xen/arch/x86/hvm/vmx/intr.c +0
-0@@ -232,6 +232,14 @@ void vmx_intr_assist(void)enum hvm_intblk intblk;int pt_vector;
Quoted 10 lines
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 241
Quoted 7 lines
xen/arch/x86/hvm/vmx/intr.c +7
-0+if ( cpu_has_vmx_posted_intr_processing ) +/* +* Always force PIR to be synced to IRR before vmentry, this is also +* done by vlapic_has_pending_irq but it's possible other pending +* interrupts prevent the execution of that function. +*/ +vmx_sync_pir_to_irr (v);... this addition looks more like papering over some issue than actually taking care of it.
Xen needs to make sure PIR is synced to IRR before entering non-root mode. I could place the call somewhere else, or alternatively Xen could disable interrupts, send a self-ipi with the posted vector and enter non-root mode. That should IMO force a resync of PIR to IRR when resuming vCPU execution, but is overly complicated.
Quoted 2 lines
Then again I wonder whether the
PIR->IRRsync is actually legitimate to perform when v != current.
IMO this is fine as long as the vCPU is not running, as in that case the hardware is not in control of IRR.
Quoted 5 lines
If it's not, then there
might be a wider set of problems (see e.g.hvm_local_events_need_delivery()). But of course the adjustment tohvm_vcpu_has_pending_irq()could also be to make the call early only when v == current.
I don't think we should be that restrictive, v == current || !vcpu_runable(v) ought to be safe. I've also forgot to send my pre-patch to introduce an assert to that effect:
https://lists.xenproject.org/archives/html/xen-devel/2019-11/msg00635.html
Quoted 3 lines
A last question is that on the consequences of overly aggressive sync-ing - that'll harm performance, but shouldn't affect correctness if I'm not mistaken.
That's correct, as long as the vcpu is the current one or it's not running.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Roger Pau Monné
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?
Quoted 6 lines
I assumed the order in
hvm_vcpu_has_pending_irqis there for a reason. I could indeed movevlapic_has_pending_irqto the top, but then either the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic invlapic_has_pending_irq), or we invert the priority of event injection.
Changing the order of events injected is not an option afaict. The pointless processing done is a valid concern, yet the suggestion was specifically to have (part of) this processing to occur early. The discarding of the result, in turn, is not a problem afaict, as a subsequent call will return the same result (unless a higher priority interrupt has surfaced in the meantime).
Quoted 4 lines
I have to admit I have doubts about the code in
hvm_vcpu_has_pending_irq. I'm not sure what's the motivation for example to give priority toHVMIRQ_callback_vectorover other vectors from the lapic.
I vaguely recall there being a reason, but I guess it would take some git archaeology to find out.
Quoted 19 lines
Quoted 8 lines
I ask because ...
Quoted 6 lines
xen/arch/x86/hvm/vmx/intr.c +0
-0@@ -232,6 +232,14 @@ void vmx_intr_assist(void)enum hvm_intblk intblk;int pt_vector;Quoted 10 lines
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 241
Quoted 7 lines
xen/arch/x86/hvm/vmx/intr.c +7
-0+if ( cpu_has_vmx_posted_intr_processing ) +/* +* Always force PIR to be synced to IRR before vmentry, this is also +* done by vlapic_has_pending_irq but it's possible other pending +* interrupts prevent the execution of that function. +*/ +vmx_sync_pir_to_irr (v);... this addition looks more like papering over some issue than actually taking care of it.
Quoted 5 lines
Xen needs to make sure PIR is synced to IRR before entering non-root mode. I could place the call somewhere else, or alternatively Xen could disable interrupts, send a self-ipi with the posted vector and enter non-root mode. That should IMO force a resync of PIR to IRR when resuming vCPU execution, but is overly complicated.
Indeed, further complicating things can't be the goal. But finding the most suitable place to make the call might still be worthwhile.
Quoted 5 lines
Quoted 2 lines
Then again I wonder whether the
PIR->IRRsync is actually legitimate to perform when v != current.IMO this is fine as long as the vCPU is not running, as in that case the hardware is not in control of IRR.
Here and ...
Quoted 10 lines
Quoted 5 lines
If it's not, then there
might be a wider set of problems (see e.g.hvm_local_events_need_delivery()). But of course the adjustment tohvm_vcpu_has_pending_irq()could also be to make the call early only when v == current.I don't think we should be that restrictive, v == current || !vcpu_runable(v) ought to be safe. I've also forgot to send my pre-patch to introduce an assert to that effect:
Quoted 8 lines
https://lists.xenproject.org/archives/html/xen-devel/2019-11/msg00635.html
Quoted 3 lines
A last question is that on the consequences of overly aggressive sync-ing - that'll harm performance, but shouldn't affect correctness if I'm not mistaken.
That's correct, as long as the vcpu is the current one or it's not running.
... here I continue to be worried of races: Any check for a vCPU to be non-running (or non-runnable) is stale the moment you inspect the result of the check. Unless, of course, you suppress scheduling (actions potentially making a vCPU runnable) during that time window.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?Quoted 6 lines
I assumed the order in
hvm_vcpu_has_pending_irqis there for a reason. I could indeed movevlapic_has_pending_irqto the top, but then either the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic invlapic_has_pending_irq), or we invert the priority of event injection.
Quoted 6 lines
Changing the order of events injected is not an option afaict. The pointless processing done is a valid concern, yet the suggestion was specifically to have (part of) this processing to occur early. The discarding of the result, in turn, is not a problem afaict, as a subsequent call will return the same result (unless a higher priority interrupt has surfaced in the meantime).
Yes, that's fine. So you would prefer to move the call to vlapic_has_pending_irq before any exit path in hvm_vcpu_has_pending_irq?
Quoted 24 lines
Quoted 5 lines
Quoted 2 lines
Then again I wonder whether the
PIR->IRRsync is actually legitimate to perform when v != current.IMO this is fine as long as the vCPU is not running, as in that case the hardware is not in control of IRR.
Here and ...
Quoted 16 lines
Quoted 5 lines
If it's not, then there
might be a wider set of problems (see e.g.hvm_local_events_need_delivery()). But of course the adjustment tohvm_vcpu_has_pending_irq()could also be to make the call early only when v == current.I don't think we should be that restrictive, v == current || !vcpu_runable(v) ought to be safe. I've also forgot to send my pre-patch to introduce an assert to that effect:
https://lists.xenproject.org/archives/html/xen-devel/2019-11/msg00635.html
Quoted 3 lines
A last question is that on the consequences of overly aggressive sync-ing - that'll harm performance, but shouldn't affect correctness if I'm not mistaken.
Quoted 7 lines
Quoted 2 lines
That's correct, as long as the vcpu is the current one or it's not running.
... here I continue to be worried of races: Any check for a vCPU to be non-running (or non-runnable) is stale the moment you inspect the result of the check. Unless, of course, you suppress scheduling (actions potentially making a vCPU runnable) during that time window.
Hm, it's indeed true that syncing PIR into IRR for a vCPU not running in the current pCPU is troublesome. Maybe syncing PIR into IRR should only be done when v == current?
The only alternative I can think of is something like:
if ( v != current )
vcpu_pause(v);
sync_pir_irr(v);
if ( v != current )
vcpu_unpause(v);Is there a need to check the IRR of vCPUs that are not running, and does it matter if the IRR is not fully updated in that case?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Roger Pau Monné
Quoted 21 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?Quoted 6 lines
I assumed the order in
hvm_vcpu_has_pending_irqis there for a reason. I could indeed movevlapic_has_pending_irqto the top, but then either the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic invlapic_has_pending_irq), or we invert the priority of event injection.Quoted 6 lines
Changing the order of events injected is not an option afaict. The pointless processing done is a valid concern, yet the suggestion was specifically to have (part of) this processing to occur early. The discarding of the result, in turn, is not a problem afaict, as a subsequent call will return the same result (unless a higher priority interrupt has surfaced in the meantime).
Quoted 3 lines
Yes, that's fine. So you would prefer to move the call to
vlapic_has_pending_irqbefore any exit path inhvm_vcpu_has_pending_irq?
"Prefer" isn't really the way I would put it. I'd like this to be considered as an alternative because, as said, I think the current placement look more like a plaster than a cure. I'm also open for other suggestions. But first of all I'd like to see what the VMX maintainers think.
Quoted 38 lines
Quoted 24 lines
Quoted 5 lines
Quoted 2 lines
Then again I wonder whether the
PIR->IRRsync is actually legitimate to perform when v != current.IMO this is fine as long as the vCPU is not running, as in that case the hardware is not in control of IRR.
Here and ...
Quoted 16 lines
Quoted 5 lines
If it's not, then there
might be a wider set of problems (see e.g.hvm_local_events_need_delivery()). But of course the adjustment tohvm_vcpu_has_pending_irq()could also be to make the call early only when v == current.I don't think we should be that restrictive, v == current || !vcpu_runable(v) ought to be safe. I've also forgot to send my pre-patch to introduce an assert to that effect:
https://lists.xenproject.org/archives/html/xen-devel/2019-11/msg00635.html
Quoted 3 lines
A last question is that on the consequences of overly aggressive sync-ing - that'll harm performance, but shouldn't affect correctness if I'm not mistaken.
Quoted 7 lines
Quoted 2 lines
That's correct, as long as the vcpu is the current one or it's not running.
... here I continue to be worried of races: Any check for a vCPU to be non-running (or non-runnable) is stale the moment you inspect the result of the check. Unless, of course, you suppress scheduling (actions potentially making a vCPU runnable) during that time window.
Hm, it's indeed true that syncing PIR into IRR for a vCPU not running in the current pCPU is troublesome. Maybe syncing PIR into IRR should only be done when v == current?
The only alternative I can think of is something like:
Quoted 8 lines
if ( v != current )
vcpu_pause(v); sync_pir_irr(v); if ( v != current ) vcpu_unpause(v);Is there a need to check the IRR of vCPUs that are not running, and does it matter if the IRR is not fully updated in that case?
That's one of the problems with function parameters decribed "struct vcpu *v" - you don't know whether there's any expectation that v == current at all times. And tracking down all uses of certain functions can be rather tedious. IOW without quite a bit of code auditing I'm afraid I can't tell whether there's possibly some corner case where this might be needed.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 34 lines · Jan Beulich
Quoted 29 lines · Roger Pau Monné
Quoted 21 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?Quoted 6 lines
I assumed the order in
hvm_vcpu_has_pending_irqis there for a reason. I could indeed movevlapic_has_pending_irqto the top, but then either the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic invlapic_has_pending_irq), or we invert the priority of event injection.Quoted 6 lines
Changing the order of events injected is not an option afaict. The pointless processing done is a valid concern, yet the suggestion was specifically to have (part of) this processing to occur early. The discarding of the result, in turn, is not a problem afaict, as a subsequent call will return the same result (unless a higher priority interrupt has surfaced in the meantime).
Quoted 3 lines
Yes, that's fine. So you would prefer to move the call to
vlapic_has_pending_irqbefore any exit path inhvm_vcpu_has_pending_irq?
Quoted 5 lines
"Prefer" isn't really the way I would put it. I'd like this to be considered as an alternative because, as said, I think the current placement look more like a plaster than a cure. I'm also open for other suggestions. But first of all I'd like to see what the VMX maintainers think.
Kevin/Jun, can we please get your opinion on the above item?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 43 lines
From: Roger Pau Monné [mailto:[email protected]]
Sent: Thursday, November 21, 2019 5:26 PMQuoted 6 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
Quoted 1 line · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
vCPU resumes execution with a stale local APIC IRR register
because
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
regardless of what interrupts are pending.
For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?I assumed the order in
hvm_vcpu_has_pending_irqis there for areason.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
I could indeed move
vlapic_has_pending_irqto the top, but theneither
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines
Quoted 4 lines
the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic in
vlapic_has_pending_irq), or we invert the priority of event injection.Changing the order of events injected is not an option afaict. The pointless processing done is a valid concern, yet the suggestion was specifically to have (part of) this processing to occur early. The discarding of the result, in turn, is not a problem afaict, as a subsequent call will return the same result (unless a higher priority interrupt has surfaced in the meantime).
Yes, that's fine. So you would prefer to move the call to
vlapic_has_pending_irqbefore any exit path inhvm_vcpu_has_pending_irq?
Quoted 7 lines
Quoted 5 lines
"Prefer" isn't really the way I would put it. I'd like this to be considered as an alternative because, as said, I think the current placement look more like a plaster than a cure. I'm also open for other suggestions. But first of all I'd like to see what the VMX maintainers think.
Kevin/Jun, can we please get your opinion on the above item?
Give me some time to catch up...
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 39 lines
From: Roger Pau Monné <[email protected]>
Sent: Thursday, November 21, 2019 5:26 PMQuoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monné
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne
When using posted interrupts on Intel hardware it's possible that the vCPU resumes execution with a stale local APIC IRR register because depending on the interrupts to be injected
vlapic_has_pending_irqmight not be called, and thus PIR won't be synced into IRR.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fix this by making sure PIR is always synced to IRR in
vmx_intr_assistregardless of what interrupts are pending.For this part, did you consider pulling ahead to the beginning of
hvm_vcpu_has_pending_irq()its call tovlapic_has_pending_irq()?I assumed the order in
hvm_vcpu_has_pending_irqis there for areason.
Quoted 17 lines
Quoted 16 lines
Quoted 6 lines
Quoted 5 lines
I could indeed move
vlapic_has_pending_irqto the top, but then either the result is discarded if for example a NMI is pending injection (in which case there's no need to go through all the logic invlapic_has_pending_irq), or we invert the priority of event injection.Quoted 6 lines
Changing the order of events injected is not an option afaict. The pointless processing done is a valid concern, yet the suggestion was specifically to have (part of) this processing to occur early. The discarding of the result, in turn, is not a problem afaict, as a subsequent call will return the same result (unless a higher priority interrupt has surfaced in the meantime).
Yes, that's fine. So you would prefer to move the call to
vlapic_has_pending_irqbefore any exit path inhvm_vcpu_has_pending_irq?
Quoted 8 lines
Quoted 5 lines
"Prefer" isn't really the way I would put it. I'd like this to be considered as an alternative because, as said, I think the current placement look more like a plaster than a cure. I'm also open for other suggestions. But first of all I'd like to see what the VMX maintainers think.
Kevin/Jun, can we please get your opinion on the above item?
putting the sync within hvm_vcpu_has_pending_irq sounds better, implying that all intermediate states must be synced back to architectural states anytime when software wants to check virtual interrupt.
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 7 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +1
-2@@ -1954,48 +1952,28 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )
I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".
In general I think "runnable" is the more appropriate state to check for, as "running" is even more likely to change behind our backs. But of course there are caveats: When observing "running", v->processor is sufficiently certain to hold the pCPU the vCPU is running on or has been running on last. For "runnable" that's less helpful, because by the time you look at v->processor it may already have changed to whichever the vCPU is (about to be) running on.
Quoted 48 lines
xen/arch/x86/hvm/vmx/vmx.c +12
-32/* -* Note: Only two cases will reach here: -* 1. The target vCPU is running on other pCPU. -* 2. The target vCPU is the current vCPU. +* If the vCPU is running on another pCPU send an IPI to the pCPU. When +* the IPI arrives, the target vCPU may be running in non-root mode, +* running in root mode, runnable or blocked. If the target vCPU is +* running in non-root mode, the hardware will sync PIR to vIRR for +* 'posted_intr_vector' is a special vector handled directly by the +* hardware. * -* Note2: Don't worry the v->processor may change. The vCPU being -* moved to another processor is guaranteed to sync PIR to vIRR, -* due to the involved scheduling cycle. +* If the target vCPU is running in root-mode, the interrupt handler +* starts to run. Considering an IPI may arrive in the window between +* the call to vmx_intr_assist() and interrupts getting disabled, the +* interrupt handler should raise a softirq to ensure events will be +* delivered in time. */ -unsigned int cpu = v->processor; +send_IPI_mask (cpumask_of (v->processor), posted_intr_vector); -/* -* For case 1, we send an IPI to the pCPU. When an IPI arrives, the -* target vCPU maybe is running in non-root mode, running in root -* mode, runnable or blocked. If the target vCPU is running in -* non-root mode, the hardware will sync PIR to vIRR for -* 'posted_intr_vector' is special to the pCPU. If the target vCPU is -* running in root-mode, the interrupt handler starts to run. -* Considering an IPI may arrive in the window between the call to -* vmx_intr_assist() and interrupts getting disabled, the interrupt -* handler should raise a softirq to ensure events will be delivered -* in time. If the target vCPU is runnable, it will sync PIR to -* vIRR next time it is chose to run. In this case, a IPI and a -* softirq is sent to a wrong vCPU which will not have any adverse -* effect. If the target vCPU is blocked, since vcpu_block() checks -* whether there is an event to be delivered through -* local_events_need_delivery() just after blocking, the vCPU must -* have synced PIR to vIRR. Similarly, there is a IPI and a softirq -* sent to a wrong vCPU. -*/ -if ( cpu !=smp_processor_id () ) -send_IPI_mask (cpumask_of (cpu), posted_intr_vector); -/* -* For case 2, raising a softirq ensures PIR will be synced to vIRR. -* As any softirq will do, as an optimization we only raise one if -* none is pending already.
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1977
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +5
-4-*/ - else if ( !softirq_pending(cpu) ) - raise_softirq(VCPU_KICK_SOFTIRQ); - } +/* +* If the vCPU is not runnable or if it's the one currently running in this +* pCPU there's nothing to do, the vmentry code will already sync the PIR +* to IRR when resuming execution. +*/ }
Just for my own understanding - the "already" here relates to the code addition you make to vmx_intr_assist()?
And then - is this true even for an interrupt hitting between vmx_intr_assist() returning and the subsequent CLI in vmx_asm_vmexit_handler()?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 14 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 7 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +1
-2@@ -1954,48 +1952,28 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of
in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".
I've missed to fix that comment, will take care in the next version. Note also that the comment is quite pointless, it only states what the code below is supposed to do, but doesn't give any reasoning as to why in_irq is relevant here.
TBH I'm not sure of the point of the in_irq check, I don't think it's relevant for the code here. It only matters whether the vCPU is running, and whether it's running in this pCPU. Whether __vmx_deliver_posted_interrupt is called from an irq context is irrelevant AFAICT.
Quoted 9 lines
In general I think "runnable" is the more appropriate state to check for, as "running" is even more likely to change behind our backs. But of course there are caveats: When observing "running",
v->processoris sufficiently certain to hold the pCPU the vCPU is running on or has been running on last. For "runnable" that's less helpful, because by the time you look atv->processorit may already have changed to whichever the vCPU is (about to be) running on.
I think this is fine. In fact it would also be fine from a safety PoV to always send a posted interrupt IPI to the pCPU in v->processor: if the vCPU is running PIR will be synced into IRR, otherwise a dummy softirq will be recorded and PIR will be synced into IRR before entering non-root mode.
v->is_running might be better in order to prevent sending pointless IPIs around, will fix in v2, since we would only like to send the IPI when the vCPU is executing on a pCPU.
Quoted 59 lines
Quoted 48 lines
xen/arch/x86/hvm/vmx/vmx.c +12
-32/* -* Note: Only two cases will reach here: -* 1. The target vCPU is running on other pCPU. -* 2. The target vCPU is the current vCPU. +* If the vCPU is running on another pCPU send an IPI to the pCPU. When +* the IPI arrives, the target vCPU may be running in non-root mode, +* running in root mode, runnable or blocked. If the target vCPU is +* running in non-root mode, the hardware will sync PIR to vIRR for +* 'posted_intr_vector' is a special vector handled directly by the +* hardware. * -* Note2: Don't worry the v->processor may change. The vCPU being -* moved to another processor is guaranteed to sync PIR to vIRR, -* due to the involved scheduling cycle. +* If the target vCPU is running in root-mode, the interrupt handler +* starts to run. Considering an IPI may arrive in the window between +* the call to vmx_intr_assist() and interrupts getting disabled, the +* interrupt handler should raise a softirq to ensure events will be +* delivered in time. */ -unsigned int cpu = v->processor; +send_IPI_mask (cpumask_of (v->processor), posted_intr_vector); -/* -* For case 1, we send an IPI to the pCPU. When an IPI arrives, the -* target vCPU maybe is running in non-root mode, running in root -* mode, runnable or blocked. If the target vCPU is running in -* non-root mode, the hardware will sync PIR to vIRR for -* 'posted_intr_vector' is special to the pCPU. If the target vCPU is -* running in root-mode, the interrupt handler starts to run. -* Considering an IPI may arrive in the window between the call to -* vmx_intr_assist() and interrupts getting disabled, the interrupt -* handler should raise a softirq to ensure events will be delivered -* in time. If the target vCPU is runnable, it will sync PIR to -* vIRR next time it is chose to run. In this case, a IPI and a -* softirq is sent to a wrong vCPU which will not have any adverse -* effect. If the target vCPU is blocked, since vcpu_block() checks -* whether there is an event to be delivered through -* local_events_need_delivery() just after blocking, the vCPU must -* have synced PIR to vIRR. Similarly, there is a IPI and a softirq -* sent to a wrong vCPU. -*/ -if ( cpu !=smp_processor_id () ) -send_IPI_mask (cpumask_of (cpu), posted_intr_vector); -/* -* For case 2, raising a softirq ensures PIR will be synced to vIRR. -* As any softirq will do, as an optimization we only raise one if -* none is pending already. xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1977
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +5
-4-*/ - else if ( !softirq_pending(cpu) ) - raise_softirq(VCPU_KICK_SOFTIRQ); - } +/* +* If the vCPU is not runnable or if it's the one currently running in this +* pCPU there's nothing to do, the vmentry code will already sync the PIR +* to IRR when resuming execution. +*/ }
Quoted 2 lines
Just for my own understanding - the "already" here relates to the code addition you make to
vmx_intr_assist()?
Yes.
Quoted 3 lines
And then - is this true even for an interrupt hitting between
vmx_intr_assist()returning and the subsequent CLI invmx_asm_vmexit_handler()?
Should be, as that IPI will raise a softirq that would force a jump into vmx_process_softirqs, which in turn will jump to the start of vmx_do_vmentry, thus calling vmx_intr_assist again.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 16 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 7 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +1
-2@@ -1954,48 +1952,28 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of
in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".
Quoted 4 lines
I've missed to fix that comment, will take care in the next version. Note also that the comment is quite pointless, it only states what the code below is supposed to do, but doesn't give any reasoning as to why
in_irqis relevant here.
It's main "value" is to refer to vcpu_kick(), which has ...
Quoted 2 lines
TBH I'm not sure of the point of the
in_irqcheck, I don't think it's relevant for the code here.
... a similar in_irq() check. Sadly that one, while having a bigger comment, also doesn't explain what it's needed for. It looks like I should recall the reason, but I'm sorry - I don't right now.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 22 lines · Jan Beulich
Quoted 16 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 7 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +1
-2@@ -1954,48 +1952,28 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of
in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".Quoted 4 lines
I've missed to fix that comment, will take care in the next version. Note also that the comment is quite pointless, it only states what the code below is supposed to do, but doesn't give any reasoning as to why
in_irqis relevant here.
Quoted 8 lines
It's main "value" is to refer to
vcpu_kick(), which has ...Quoted 2 lines
TBH I'm not sure of the point of the
in_irqcheck, I don't think it's relevant for the code here.... a similar
in_irq()check. Sadly that one, while having a bigger comment, also doesn't explain what it's needed for. It looks like I should recall the reason, but I'm sorry - I don't right now.
By reading the message of the commit that introduced the in_irq check in vcpu_kick:
"The drawback is that {vmx,svm}_intr_assist() now races new event notifications delivered by IRQ or IPI. We close down this race by having vcpu_kick() send a dummy softirq -- this gets picked up in IRQ-sage context and will cause retry of *_intr_assist(). We avoid delivering the softirq where possible by avoiding it when we are running in the non-IRQ context of the VCPU to be kicked."
AFAICT in the vcpu_kick case this is done because the softirq should only be raised when in IRQ context in order to trigger the code in vmx_do_vmentry to retry the call to vmx_intr_assist (this is relevant if vcpu_kick is issued from an irq handler executed after vmx_intr_assist and before the disabling interrupts in vmx_do_vmentry.
I think we need something along the lines of:
if ( v->is_running && v != current )
send_IPI_mask(cpumask_of(v->processor), posted_intr_vector);
else if ( v == current && in_irq() && !softirq_pending(smp_processor_id()) )
raise_softirq(VCPU_KICK_SOFTIRQ);So that vmx_intr_assist is also retried if a vector is signaled in PIR on the vCPU currently running between the call to vmx_intr_assist and the disabling of interrupts in vmx_do_vmentry.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines · Roger Pau Monné
Quoted 22 lines · Jan Beulich
Quoted 16 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 7 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +1
-2@@ -1954,48 +1952,28 @@ static void __vmx_deliver_posted_interrupt(struct vcpu *v)* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of
in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".Quoted 4 lines
I've missed to fix that comment, will take care in the next version. Note also that the comment is quite pointless, it only states what the code below is supposed to do, but doesn't give any reasoning as to why
in_irqis relevant here.Quoted 8 lines
It's main "value" is to refer to
vcpu_kick(), which has ...Quoted 2 lines
TBH I'm not sure of the point of the
in_irqcheck, I don't think it's relevant for the code here.... a similar
in_irq()check. Sadly that one, while having a bigger comment, also doesn't explain what it's needed for. It looks like I should recall the reason, but I'm sorry - I don't right now.By reading the message of the commit that introduced the
in_irqcheck invcpu_kick:"The drawback is that {vmx,svm}_intr_assist() now races new event notifications delivered by IRQ or IPI. We close down this race by having
vcpu_kick()send a dummy softirq -- this gets picked up in IRQ-sage context and will cause retry of*_intr_assist(). We avoid delivering the softirq where possible by avoiding it when we are running in the non-IRQ context of the VCPU to be kicked."AFAICT in the
vcpu_kickcase this is done because the softirq should only be raised when in IRQ context in order to trigger the code invmx_do_vmentryto retry the call tovmx_intr_assist(this is relevant ifvcpu_kickis issued from an irq handler executed aftervmx_intr_assistand before the disabling interrupts invmx_do_vmentry.I think we need something along the lines of:
Quoted 8 lines
if (
v->is_running&& v != current )send_IPI_mask(cpumask_of(v->processor), posted_intr_vector); else if ( v == current && in_irq() && !softirq_pending(smp_processor_id()) ) raise_softirq(VCPU_KICK_SOFTIRQ);So that
vmx_intr_assistis also retried if a vector is signaled in PIR on the vCPU currently running between the call tovmx_intr_assistand the disabling of interrupts invmx_do_vmentry.
Looks plausible.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 53 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, November 18, 2019 10:56 PMQuoted 4 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
Review static void
Quoted 1 line · Roger Pau Monne
(quoted diff) +0
-0@@ -1954,48 +1952,28 @@ static void
__vmx_deliver_posted_interrupt(struct vcpu *v)Quoted 18 lines
Quoted 13 lines
Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-2* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )Quoted 5 lines
I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of
in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".Quoted 4 lines
I've missed to fix that comment, will take care in the next version. Note also that the comment is quite pointless, it only states what the code below is supposed to do, but doesn't give any reasoning as to why
in_irqis relevant here.Quoted 8 lines
It's main "value" is to refer to
vcpu_kick(), which has ...Quoted 2 lines
TBH I'm not sure of the point of the
in_irqcheck, I don't think it's relevant for the code here.... a similar
in_irq()check. Sadly that one, while having a bigger comment, also doesn't explain what it's needed for. It looks like I should recall the reason, but I'm sorry - I don't right now.By reading the message of the commit that introduced the
in_irqcheck invcpu_kick:"The drawback is that {vmx,svm}_intr_assist() now races new event notifications delivered by IRQ or IPI. We close down this race by having
vcpu_kick()send a dummy softirq -- this gets picked up in IRQ-sage context and will cause retry of*_intr_assist(). We avoid delivering the softirq where possible by avoiding it when we are running in the non-IRQ context of the VCPU to be kicked."AFAICT in the
vcpu_kickcase this is done because the softirq should only be raised when in IRQ context in order to trigger the code invmx_do_vmentryto retry the call tovmx_intr_assist(this is relevant ifvcpu_kickis issued from an irq handler executed aftervmx_intr_assistand before the disabling interrupts invmx_do_vmentry.
Quoted 6 lines
I think we need something along the lines of:
if (
v->is_running&& v != current )send_IPI_mask(cpumask_of(v->processor), posted_intr_vector); else if ( v == current && in_irq() && !softirq_pending(smp_processor_id()) ) raise_softirq(VCPU_KICK_SOFTIRQ);
Then what's the difference from original logic?
Quoted 5 lines
So that
vmx_intr_assistis also retried if a vector is signaled in PIR on the vCPU currently running between the call tovmx_intr_assistand the disabling of interrupts invmx_do_vmentry.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 53 lines · Kevin
Quoted 53 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, November 18, 2019 10:56 PMQuoted 4 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
Review static void
Quoted 1 line · Roger Pau Monne
(quoted diff) +0
-0@@ -1954,48 +1952,28 @@ static void
__vmx_deliver_posted_interrupt(struct vcpu *v)Quoted 18 lines
Quoted 13 lines
Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c static void __vmx_deliver_posted_interrupt(struct vcpu *v) · line 1955
Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-2* 2. The target vCPU is the current vCPU and we're in non-interrupt * context. */ -if ( running && (in_irq () || (v != current)) ) - { +if (vcpu_runnable (v) && v != current )Quoted 5 lines
I'm afraid you need to be more careful with the running vs runnable distinction here. The comment above here becomes stale with the change (also wrt the removal of
in_irq(), which I'm at least uneasy about), and the new commentary below also largely says/assumes "running", not "runnable".Quoted 4 lines
I've missed to fix that comment, will take care in the next version. Note also that the comment is quite pointless, it only states what the code below is supposed to do, but doesn't give any reasoning as to why
in_irqis relevant here.Quoted 8 lines
It's main "value" is to refer to
vcpu_kick(), which has ...Quoted 2 lines
TBH I'm not sure of the point of the
in_irqcheck, I don't think it's relevant for the code here.... a similar
in_irq()check. Sadly that one, while having a bigger comment, also doesn't explain what it's needed for. It looks like I should recall the reason, but I'm sorry - I don't right now.By reading the message of the commit that introduced the
in_irqcheck invcpu_kick:"The drawback is that {vmx,svm}_intr_assist() now races new event notifications delivered by IRQ or IPI. We close down this race by having
vcpu_kick()send a dummy softirq -- this gets picked up in IRQ-sage context and will cause retry of*_intr_assist(). We avoid delivering the softirq where possible by avoiding it when we are running in the non-IRQ context of the VCPU to be kicked."AFAICT in the
vcpu_kickcase this is done because the softirq should only be raised when in IRQ context in order to trigger the code invmx_do_vmentryto retry the call tovmx_intr_assist(this is relevant ifvcpu_kickis issued from an irq handler executed aftervmx_intr_assistand before the disabling interrupts invmx_do_vmentry.
Quoted 8 lines
Quoted 6 lines
I think we need something along the lines of:
if (
v->is_running&& v != current )send_IPI_mask(cpumask_of(v->processor), posted_intr_vector); else if ( v == current && in_irq() && !softirq_pending(smp_processor_id()) ) raise_softirq(VCPU_KICK_SOFTIRQ);Then what's the difference from original logic?
The original logic is:
if ( running && (in_irq() || (v != current)) )
{
unsigned int cpu = v->processor;
if ( cpu != smp_processor_id() )
send_IPI_mask(cpumask_of(cpu), posted_intr_vector);
else if ( !softirq_pending(cpu) )
raise_softirq(VCPU_KICK_SOFTIRQ);
}Which I find much harder to understand. For example I'm not sure of what's the benefit of doing the cpu != smp_processor_id() check instead of simply doing v != current (like in the outer if condition). My suggestion removes one level of nesting and IMO makes the condition clearer, but maybe that's just my taste.
Also the original comments don't mention at all why a softirq should be raised if v == current && in_irq, and it took me some time to figure out why that's required. My proposed change clarifies why this is needed, and also makes it more obvious that the softirq will only be raised when in irq context.
Anyway, I'm not going to insist and will drop the change if it's not deemed useful.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Roger Pau Monné
Quoted 1 line · Kevin
Then what's the difference from original logic?
The original logic is:
if ( running && (
in_irq()|| (v != current)) ){ unsigned int cpu = v->processor; if ( cpu != smp_processor_id() ) send_IPI_mask(cpumask_of(cpu), posted_intr_vector); else if ( !softirq_pending(cpu) ) raise_softirq(VCPU_KICK_SOFTIRQ); }
Quoted 3 lines
Which I find much harder to understand. For example I'm not sure of what's the benefit of doing the cpu !=
smp_processor_id()check instead of simply doing v != current (like in the outer if condition).
There are two aspects to consider: One is that v->processor may equal smp_processor_id() also for v != current. The other is that without this check in the if() it would need adding to the else-if(). I'm not sure to what degree which of the two matters functionality wise.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Jan Beulich
Quoted 15 lines · Roger Pau Monné
Quoted 1 line · Kevin
Then what's the difference from original logic?
The original logic is:
if ( running && (
in_irq()|| (v != current)) ){ unsigned int cpu = v->processor; if ( cpu != smp_processor_id() ) send_IPI_mask(cpumask_of(cpu), posted_intr_vector); else if ( !softirq_pending(cpu) ) raise_softirq(VCPU_KICK_SOFTIRQ); }Quoted 3 lines
Which I find much harder to understand. For example I'm not sure of what's the benefit of doing the cpu !=
smp_processor_id()check instead of simply doing v != current (like in the outer if condition).
Quoted 5 lines
There are two aspects to consider: One is that
v->processormay equalsmp_processor_id()also for v != current. The other is that without this check in theif()it would need adding to the else-if(). I'm not sure to what degree which of the two matters functionality wise.
Since the vCPU is running v->processor can only equal smp_processor_id if v == current, and hence I think both checks achieve exactly the same end result, it's just that IMO doing the outer one with v != current and the inner one with cpu != smp_processor_id() is confusing.
Maybe I'm missing something else that actually requires doing the inner check with v->processor and smp_processor_id().
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Roger Pau Monné
Quoted 1 line · Kevin
Then what's the difference from original logic?
The original logic is:
if ( running && (
in_irq()|| (v != current)) ){ unsigned int cpu = v->processor; if ( cpu != smp_processor_id() ) send_IPI_mask(cpumask_of(cpu), posted_intr_vector); else if ( !softirq_pending(cpu) ) raise_softirq(VCPU_KICK_SOFTIRQ); }Which I find much harder to understand. For example I'm not sure of what's the benefit of doing the cpu !=
smp_processor_id()check instead of simply doing v != current (like in the outer if condition).
Quoted 8 lines
Quoted 5 lines
There are two aspects to consider: One is that
v->processormay equalsmp_processor_id()also for v != current. The other is that without this check in theif()it would need adding to the else-if(). I'm not sure to what degree which of the two matters functionality wise.Since the vCPU is running
v->processorcan only equalsmp_processor_idif v == current,
What tells you that it is running? It had been running at the time the flag was latched (before vcpu_unblock()), but may have got de-scheduled in the meantime.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Roger Pau Monné
Quoted 25 lines · Jan Beulich
Quoted 15 lines · Roger Pau Monné
Quoted 1 line · Kevin
Then what's the difference from original logic?
The original logic is:
if ( running && (
in_irq()|| (v != current)) ){ unsigned int cpu = v->processor; if ( cpu != smp_processor_id() ) send_IPI_mask(cpumask_of(cpu), posted_intr_vector); else if ( !softirq_pending(cpu) ) raise_softirq(VCPU_KICK_SOFTIRQ); }Quoted 3 lines
Which I find much harder to understand. For example I'm not sure of what's the benefit of doing the cpu !=
smp_processor_id()check instead of simply doing v != current (like in the outer if condition).There are two aspects to consider: One is that
v->processormay equalsmp_processor_id()also for v != current. The other is that without this check in theif()it would need adding to the else-if(). I'm not sure to what degree which of the two matters functionality wise.
Quoted 6 lines
Quoted 2 lines
Since the vCPU is running
v->processorcan only equalsmp_processor_idif v == current,What tells you that it is running? It had been running at the time the flag was latched (before
vcpu_unblock()), but may have got de-scheduled in the meantime.
Right, but if it's not running then it doesn't really matter that we send an IPI or raise a softirq, the PIR to IRR sync will happen anyway before the vCPU is resumed.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel