x86/nvmx: attempt to fix interrupt injection
cover x86/nvmx: attempt to fix interrupt injection
Hello,
This is a fixup of a wrong previous bugfix. It has been tested on the debina0 osstest host and it fixes the interrupt injection issues seen there when running the nested HVM tests. I mention this explicitly because albeit I don't expect it I don't discard it might cause issues on other boxes with a different set of VMX features.
I've tried to make the patches as small and contained as possible in order to avoid breaking other stuff.
Roger Pau Monne (3):
Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit
control is used"
x86/nvmx: clarify and fix usage of nvmx_update_apicv x86/nvmx: update exit bitmap on vmexit
xen/arch/x86/hvm/vmx/intr.c | 21 +++++++++++++-------- xen/arch/x86/hvm/vmx/vvmx.c | 19 ++++++++++++------- xen/include/asm-x86/hvm/vmx/vmx.h | 2 ++ 3 files changed, 27 insertions(+), 15 deletions(-)
Signature · 7 lines
2.25.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/3 Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
This reverts commit f96e1469ad06b61796c60193daaeb9f8a96d7458.
The commit is wrong, as the whole point of nvmx_update_apicv is to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.
--- xen/arch/x86/hvm/vmx/vvmx.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +1 -6
@@ -1456,12 +1456,7 @@ static void virtual_vmexit(struct cpu_user_regs *regs)/* updating host cr0 to sync TS bit */ __vmwrite (HOST_CR0 , v->arch.hvm.vmx.host_cr0); -if ( cpu_has_vmx_virtual_intr_delivery && -/* -* Only inject the vector if the Ack on exit bit is not set, else the -* interrupt will be signaled in the vmcs VM_EXIT_INTR_INFO field. -*/ - !(get_vvmcs (v,VM_EXIT_CONTROLS ) &VM_EXIT_ACK_INTR_ON_EXIT ) ) +if ( cpu_has_vmx_virtual_intr_delivery )nvmx_update_apicv (v); nvcpu->nv_vmswitch_in_progress =0 ;
Signature · 7 lines
2.25.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 7 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvis to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.Signed-off-by Roger Pau Monné <[email protected]>
Before anyone gets to look at the other two patches, should this be thrown in right away?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvis to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.Signed-off-by Roger Pau Monné <[email protected]>Before anyone gets to look at the other two patches, should this be thrown in right away?
I would like if possible get a confirmation from Kevin (or anyone else) that my understanding is correct. I find the nested code very confusing, and I've already made a mistake while trying to fix it. That being said, this was spotted by osstest as introducing a regression, so I guess it's safe to just toss it in now.
FWIW patch 2/3 attempts to provide a description of my understanding of how nvmx_update_apicv works.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 16 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, March 23, 2020 10:49 PMQuoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvis to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.Signed-off-by Roger Pau Monné <[email protected]>Before anyone gets to look at the other two patches, should this be thrown in right away?
Quoted 9 lines
I would like if possible get a confirmation from Kevin (or anyone else) that my understanding is correct. I find the nested code very confusing, and I've already made a mistake while trying to fix it. That being said, this was spotted by osstest as introducing a regression, so I guess it's safe to just toss it in now.
FWIW patch 2/3 attempts to provide a description of my understanding of how
nvmx_update_apicvworks.
I feel it is not good to take this patch alone, as it was introduced to fix another problem. W/o understanding whether the whole series can fix both old and new problems, we may risk putting nested interrupt logic in an even worse state...
Thanks
Kevin
Re: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 22 lines · Kevin
Quoted 22 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, March 23, 2020 10:49 PMQuoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvis to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.Signed-off-by Roger Pau Monné <[email protected]>Before anyone gets to look at the other two patches, should this be thrown in right away?
I would like if possible get a confirmation from Kevin (or anyone else) that my understanding is correct. I find the nested code very confusing, and I've already made a mistake while trying to fix it. That being said, this was spotted by osstest as introducing a regression, so I guess it's safe to just toss it in now.
Quoted 8 lines
Quoted 3 lines
FWIW patch 2/3 attempts to provide a description of my understanding of how
nvmx_update_apicvworks.I feel it is not good to take this patch alone, as it was introduced to fix another problem. W/o understanding whether the whole series can fix both old and new problems, we may risk putting nested interrupt logic in an even worse state...
Well, okay, I'll wait then, but it would seem to me that reverting wouldn't put us in a worse state than we were in before that change was put in.
Jan
Re: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 30 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 24, 2020 4:10 PMQuoted 26 lines · Kevin
Quoted 25 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, March 23, 2020 10:49 PMQuoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvis to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.Signed-off-by Roger Pau Monné <[email protected]>Before anyone gets to look at the other two patches, should this be thrown in right away?
I would like if possible get a confirmation from Kevin (or anyone else) that my understanding is correct. I find the nested code very confusing, and I've already made a mistake while trying to fix it. That being said, this was spotted by osstest as introducing a regression, so I guess it's safe to just toss it in now.
FWIW patch 2/3 attempts to provide a description of my understanding of how
nvmx_update_apicvworks.
Quoted 8 lines
Quoted 4 lines
I feel it is not good to take this patch alone, as it was introduced to fix another problem. W/o understanding whether the whole series can fix both old and new problems, we may risk putting nested interrupt logic in an even worse state...
Well, okay, I'll wait then, but it would seem to me that reverting wouldn't put us in a worse state than we were in before that change was put in.
Roger needs to make the call, i.e. which problem is more severe, old or new one.
Thanks
Kevin
Re: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 35 lines · Kevin
Quoted 35 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 24, 2020 4:10 PMQuoted 30 lines · Kevin
Quoted 16 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, March 23, 2020 10:49 PMQuoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvis to update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.Signed-off-by Roger Pau Monné <[email protected]>Before anyone gets to look at the other two patches, should this be thrown in right away?
Quoted 9 lines
I would like if possible get a confirmation from Kevin (or anyone else) that my understanding is correct. I find the nested code very confusing, and I've already made a mistake while trying to fix it. That being said, this was spotted by osstest as introducing a regression, so I guess it's safe to just toss it in now.
FWIW patch 2/3 attempts to provide a description of my understanding of how
nvmx_update_apicvworks.I feel it is not good to take this patch alone, as it was introduced to fix another problem. W/o understanding whether the whole series can fix both old and new problems, we may risk putting nested interrupt logic in an even worse state...
Quoted 6 lines
Quoted 3 lines
Well, okay, I'll wait then, but it would seem to me that reverting wouldn't put us in a worse state than we were in before that change was put in.
Roger needs to make the call, i.e. which problem is more severe, old or new one.
AFAICT those problems affect different kind of hardware, so it doesn't make much difference. IMO f96e1469ad06b6 should be reverted because it's plain wrong, and albeit it seemed to fix the issue in one of my boxes it was just luck.
I don't thinks it's going to make matters worse, as osstest is already blocked, but reverting it alone without the rest of the series is not going to unblock osstest either. If you agree it's wrong I think it could go in now, even if it's just to avoid having to repost it with newer versions of the series.
Thanks, Roger.
Tian, Kevin
Reviewed-byRe: [Xen-devel] [PATCH 1/3] Revert "x86/vvmx: fix virtual interrupt injection when Ack on exit control is used"
Quoted 53 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 6:47 PMQuoted 4 lines · Kevin
Quoted 4 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 24, 2020 4:10 PMOn 24.03.2020 06:41, Tian, Kevin wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
From: Roger Pau Monné <[email protected]>
Sent: Monday, March 23, 2020 10:49 PMQuoted 4 lines · Jan Beulich
Quoted 3 lines · Roger Pau Monne
This reverts commit
f96e1469ad06b61796c60193daaeb9f8a96d7458.The commit is wrong, as the whole point of
nvmx_update_apicvisto
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
update the guest interrupt status field when the Ack on exit VMEXIT control feature is enabled.
Signed-off-by Roger Pau Monné <[email protected]>Before anyone gets to look at the other two patches, should this be thrown in right away?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I would like if possible get a confirmation from Kevin (or anyone else) that my understanding is correct. I find the nested code very confusing, and I've already made a mistake while trying to fix it. That being said, this was spotted by osstest as introducing a regression, so I guess it's safe to just toss it in now.
FWIW patch 2/3 attempts to provide a description of my
understanding
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
of how
nvmx_update_apicvworks.I feel it is not good to take this patch alone, as it was introduced to fix another problem. W/o understanding whether the whole series can fix both old and new problems, we may risk putting nested interrupt logic in an even worse state...
Quoted 6 lines
Quoted 3 lines
Well, okay, I'll wait then, but it would seem to me that reverting wouldn't put us in a worse state than we were in before that change was put in.
Roger needs to make the call, i.e. which problem is more severe, old or new one.
AFAICT those problems affect different kind of hardware, so it doesn't make much difference. IMO
f96e1469ad06b6should be reverted because it's plain wrong, and albeit it seemed to fix the issue in one of my boxes it was just luck.
Quoted 6 lines
I don't thinks it's going to make matters worse, as osstest is already blocked, but reverting it alone without the rest of the series is not going to unblock osstest either. If you agree it's wrong I think it could go in now, even if it's just to avoid having to repost it with newer versions of the series.
yes, I agree it's wrong.
PATCH 2/3 x86/nvmx: clarify and fix usage of nvmx_update_apicv
In reply to Roger Pau MonneThe current usage of nvmx_update_apicv is not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.
The code in nvmx_update_apicv should update the SVI (in service interrupt) field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
While clarifying the usage make sure that the SVI is only updated when Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts as they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
--- xen/arch/x86/hvm/vmx/vvmx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +10 -1
@@ -1383,7 +1383,7 @@ static void nvmx_update_apicv(struct vcpu *v) {struct nestedvmx *nvmx = &vcpu_2_nvmx (v);unsigned long reason =get_vvmcs (v,VM_EXIT_REASON ); -uint32_t intr_info = nvmx->intr.intr_info; +unsigned long intr_info =get_vvmcs (v,VM_EXIT_INTR_INFO ); if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT && nvmx->intr.source == hvm_intsrc_lapic &&
@@ -1399,6 +1399,15 @@ static void nvmx_update_apicv(struct vcpu *v) ppr =vlapic_set_ppr (vlapic);WARN_ON ((ppr &0xf0 ) != (vector &0xf0 )); +/* +* SVI must be updated when the interrupt has been signaled using the +* Ack on exit feature, or else the currently in-service interrupt +* won't be respected. +* +* Note that this is specific to the fact that when doing a VMEXIT an +* interrupt might get delivered using the interrupt info vmcs field +* instead of being injected normally. +*/ status = vector <<VMX_GUEST_INTR_STATUS_SVI_OFFSET ; rvi =vlapic_has_pending_irq (v);if ( rvi !=-1 )
Signature · 7 lines
2.25.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 14 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in service interrupt) field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
Quoted 6 lines
While clarifying the usage make sure that the SVI is only updated when Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts as they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
It is insufficient. You also need to update RVI to enable virtual injection when Ack on exit is cleared.
Quoted 11 lines
Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/hvm/vmx/vvmx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)xen/arch/x86/hvm/vmx/vvmx.c +0
-0
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1386
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -1383,7 +1383,7 @@ static void nvmx_update_apicv(struct vcpu *v) {struct nestedvmx *nvmx = &vcpu_2_nvmx (v);unsigned long reason =get_vvmcs (v,VM_EXIT_REASON ); -uint32_t intr_info = nvmx->intr.intr_info; +unsigned long intr_info =get_vvmcs (v,VM_EXIT_INTR_INFO );
well, above reminds me an interesting question. Combining last and this patch, we'd see essentially that it goes back to the state before f96e1469 (at least when Ack on exit is true). iirc, that commit was introduced to enable nested x2apic with apicv, and your very first version even just removed the whole nvmx_update_apicv. Then now with the new reverted logic, are you still suffering x2apic problem? If not, does it imply the real fix is actually coming from patch 3/3 for eoi bitmap update?
Quoted 6 lines
xen/arch/x86/hvm/vmx/vvmx.c +0
-0if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT && nvmx->intr.source == hvm_intsrc_lapic &&@@ -1399,6 +1399,15 @@ static void nvmx_update_apicv(struct vcpu *v) ppr =vlapic_set_ppr (vlapic);WARN_ON ((ppr &0xf0 ) != (vector &0xf0 ));
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1410
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +9
-0+/* +* SVI must be updated when the interrupt has been signaled using the +* Ack on exit feature, or else the currently in-service interrupt +* won't be respected. +* +* Note that this is specific to the fact that when doing a VMEXIT an +* interrupt might get delivered using the interrupt info vmcs field +* instead of being injected normally. +*/
I'm not sure mentioning SVI specifically here is necessary, since all steps here are required - updating iir, isr, rvi, svi, ppr, etc. It is just an emulation of updating virtual APIC state as if a virtual interrupt delivery happens.
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +0
-1status = vector <<VMX_GUEST_INTR_STATUS_SVI_OFFSET ; rvi =vlapic_has_pending_irq (v);if ( rvi !=-1 ) --2.25.0
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 21 lines · Kevin
Quoted 14 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in service interrupt) field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.Quoted 6 lines
While clarifying the usage make sure that the SVI is only updated when Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts as they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
Quoted 2 lines
It is insufficient. You also need to update RVI to enable virtual injection when Ack on exit is cleared.
But RVI should be updated in vmx_intr_assist in that case, since nvmx_intr_intercept shouldn't intercept the interrupt, as it should be handled normally.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/hvm/vmx/vvmx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Quoted 14 lines
xen/arch/x86/hvm/vmx/vvmx.c static void (struct vcpu *v) · line 1386
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -1383,7 +1383,7 @@ static void (struct vcpu *v) {struct nestedvmx *nvmx = &vcpu_2_nvmx (v);unsigned long reason =get_vvmcs (v,VM_EXIT_REASON ); -uint32_t intr_info = nvmx->intr.intr_info; +unsigned long intr_info =get_vvmcs (v,VM_EXIT_INTR_INFO );well, above reminds me an interesting question. Combining last and this patch, we'd see essentially that it goes back to the state before
f96e1469(at least when Ack on exit is true).
Well, patch 1/3 is a revert of f96e1469, so just reverting f96e1469 gets us to that state.
This patch is an attempt to clarify that nvmx_update_apicv is closely related to the Ack on exit feature, as it modifies SVI in order to signal the vector currently being serviced by the EXIT_INTR_INFO vmcs field. This was not obvious to me, as at first sight I assumed nvmx_update_apicv was actually injecting that vector into the guest.
Quoted 5 lines
iirc, that commit was introduced to enable
nested x2apic with apicv, and your very first version even just removed the wholenvmx_update_apicv. Then now with the new reverted logic, are you still suffering x2apic problem? If not, does it imply the real fix is actually coming from patch 3/3 for eoi bitmap update?
Yes, patch 3/3 is the one that fixed the issue. Note however that strangely enough removing the call to nvmx_update_apicv (as my first attempt to solve the issue) did fix it on one of my boxes. It depends a lot on the available vmx features AFAICT.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +0
-0if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT && nvmx->intr.source == hvm_intsrc_lapic &&@@ -1399,6 +1399,15 @@ static void nvmx_update_apicv(struct vcpu *v) ppr =vlapic_set_ppr (vlapic);WARN_ON ((ppr &0xf0 ) != (vector &0xf0 ));
Quoted 13 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1410
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c +9
-0+/* +* SVI must be updated when the interrupt has been signaled using the +* Ack on exit feature, or else the currently in-service interrupt +* won't be respected. +* +* Note that this is specific to the fact that when doing a VMEXIT an +* interrupt might get delivered using the interrupt info vmcs field +* instead of being injected normally. +*/ I'm not sure mentioning SVI specifically here is necessary, since all steps here are required - updating iir, isr, rvi, svi, ppr, etc. It is just an emulation of updating virtual APIC state as if a virtual interrupt delivery happens.
Hm, it was hard for me to figure out that SVI is modified here in order to signal that the Ack on exit vector is currently in service, as opposed to being injected using the virtual interrupt delivery mechanism.
I just wanted to clarify that the purpose of this function is not to inject the vector in intr_info, but rather to signal that such vector has already been injected using a different mechanism.
I'm happy to reword this, but IMO it should be clear that the purpose of the function is not so much to inject an interrupt, but to update the virtual interrupt delivery field in order to signal that an interrupt has been injected using a different mechanism.
Thanks, Roger.
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 26 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:51 PMQuoted 7 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in serviceinterrupt)
Quoted 14 lines
Quoted 13 lines
field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
While clarifying the usage make sure that the SVI is only updated when Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts as they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
Quoted 6 lines
Quoted 2 lines
It is insufficient. You also need to update RVI to enable virtual injection when Ack on exit is cleared.
But RVI should be updated in
vmx_intr_assistin that case, sincenvmx_intr_interceptshouldn't intercept the interrupt, as it should be handled normally.
As we discussed before, vmx_intr_assist is invoked before nvmx_switch_guest. It is incorrectly to update RVI at that time since it might be still vmcs02 being active (if no pending softirq to make it invoked again).
Also nvmx_intr_intercept does intercept Ack-on-exit=0 case:
if ( intack.source == hvm_intsrc_pic ||
intack.source == hvm_intsrc_lapic )
{
vmx_inject_extint(intack.vector, intack.source);
ctrl = get_vvmcs(v, VM_EXIT_CONTROLS);
if ( ctrl & VM_EXIT_ACK_INTR_ON_EXIT )
{
/* for now, duplicate the ack path in vmx_intr_assist */
hvm_vcpu_ack_pending_irq(v, intack);
pt_intr_post(v, intack);
intack = hvm_vcpu_has_pending_irq(v);
if ( unlikely(intack.source != hvm_intsrc_none) )
vmx_enable_intr_window(v, intack);
}
else if ( !cpu_has_vmx_virtual_intr_delivery )
vmx_enable_intr_window(v, intack);
return 1; <<<<<<<<
}Quoted 23 lines
Quoted 8 lines
Review
Quoted 8 lines
Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/hvm/vmx/vvmx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/xen/arch/x86/hvm/vmx/vvmx.cQuoted 5 lines
Quoted 5 lines
index
1b8461ba30..180d01e385100644xen/arch/x86/hvm/vmx/vvmx.c +0
-0@@ -1383,7 +1383,7 @@ static void (struct vcpu *v) {Quoted 8 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1386
Quoted 4 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1struct nestedvmx *nvmx = &vcpu_2_nvmx (v);unsigned long reason =get_vvmcs (v,VM_EXIT_REASON ); -uint32_t intr_info = nvmx->intr.intr_info; +unsigned long intr_info =get_vvmcs (v,VM_EXIT_INTR_INFO );well, above reminds me an interesting question. Combining last and this patch, we'd see essentially that it goes back to the state before
f96e1469(at least when Ack on exit is true).
Quoted 2 lines
Well, patch 1/3 is a revert of
f96e1469, so just revertingf96e1469gets us to that state.
you are right. I just wanted to point out that this patch alone doesn't do any real fix for ack-on-exit=1 case. It just makes sure that ack-on-exit=0 is skipped from that function. So it won't be the one fixing your previous problem. 😊
Quoted 13 lines
This patch is an attempt to clarify that
nvmx_update_apicvis closely related to the Ack on exit feature, as it modifies SVI in order to signal the vector currently being serviced by theEXIT_INTR_INFOvmcs field. This was not obvious to me, as at first sight I assumednvmx_update_apicvwas actually injecting that vector into the guest.Quoted 5 lines
iirc, that commit was introduced to enable
nested x2apic with apicv, and your very first version even just removed the wholenvmx_update_apicv. Then now with the new reverted logic, are you still suffering x2apic problem? If not, does it imply the real fix is actually coming from patch 3/3 for eoi bitmap update?
Quoted 4 lines
Yes, patch 3/3 is the one that fixed the issue. Note however that strangely enough removing the call to
nvmx_update_apicv(as my first attempt to solve the issue) did fix it on one of my boxes. It depends a lot on the available vmx features AFAICT.
Did you confirm that with 3/3 alone can fix that issue? Just want to make sure the real gain of each patch, so we can reflect it in the commit msg in updated version.
Quoted 28 lines
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1403
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +2
-0if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT && nvmx->intr.source == hvm_intsrc_lapic &&@@ -1399,6 +1399,15 @@ static void nvmx_update_apicv(struct vcpu *v) ppr =vlapic_set_ppr (vlapic);WARN_ON ((ppr &0xf0 ) != (vector &0xf0 )); +/* +* SVI must be updated when the interrupt has been signaled using the
Quoted 11 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1410
Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +7
-0+* Ack on exit feature, or else the currently in-service interrupt +* won't be respected. +* +* Note that this is specific to the fact that when doing a VMEXIT an +* interrupt might get delivered using the interrupt info vmcs field +* instead of being injected normally. +*/ I'm not sure mentioning SVI specifically here is necessary, since all steps here are required - updating iir, isr, rvi, svi, ppr, etc. It is just an emulation of updating virtual APIC state as if a virtual interrupt delivery happens.
Hm, it was hard for me to figure out that SVI is modified here in order to signal that the Ack on exit vector is currently in service, as opposed to being injected using the virtual interrupt delivery mechanism.
Quoted 9 lines
I just wanted to clarify that the purpose of this function is not to inject the vector in
intr_info, but rather to signal that such vector has already been injected using a different mechanism.I'm happy to reword this, but IMO it should be clear that the purpose of the function is not so much to inject an interrupt, but to update the virtual interrupt delivery field in order to signal that an interrupt has been injected using a different mechanism.
reading it again I feel possibly fine to put the comment there. But I disagree the statement above. The purpose of this function is indeed for injecting an interrupt. Both RVI and SVI are additional requirements when virtual APIC page is in-use while virtual interrupt delivery is not used, i.e. when ack-on-exit is set.
Thanks
Kevin
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 52 lines · Kevin
Quoted 26 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:51 PMQuoted 7 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in serviceinterrupt)
Quoted 14 lines
Quoted 13 lines
field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
While clarifying the usage make sure that the SVI is only updated when Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts as they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
Quoted 6 lines
Quoted 2 lines
It is insufficient. You also need to update RVI to enable virtual injection when Ack on exit is cleared.
But RVI should be updated in
vmx_intr_assistin that case, sincenvmx_intr_interceptshouldn't intercept the interrupt, as it should be handled normally.As we discussed before,
vmx_intr_assistis invoked beforenvmx_switch_guest.It is incorrectly to update RVI at that time since it might be still vmcs02 being active (if no pending softirq to make it invoked again).
Also
nvmx_intr_interceptdoes intercept Ack-on-exit=0 case:if ( intack.source == hvm_intsrc_pic || intack.source == hvm_intsrc_lapic ) { vmx_inject_extint(intack.vector, intack.source); ctrl = get_vvmcs(v, VM_EXIT_CONTROLS); if ( ctrl & VM_EXIT_ACK_INTR_ON_EXIT ) { /* for now, duplicate the ack path in vmx_intr_assist */ hvm_vcpu_ack_pending_irq(v, intack); pt_intr_post(v, intack);
Quoted 8 lines
intack = hvm_vcpu_has_pending_irq(v);
if ( unlikely(intack.source != hvm_intsrc_none) )
vmx_enable_intr_window(v, intack);
}
else if ( !cpu_has_vmx_virtual_intr_delivery )
vmx_enable_intr_window(v, intack);
return 1; <<<<<<<<Right, I always get confused by the switch happening in the vmentry path.
That only happens when the vcpu is in nested mode (nestedhvm_vcpu_in_guestmode == true). That would be the case before a vmexit, at least for the first call to vmx_intr_assist if there are pending softirqs.
Note that if there are pending softirqs the second time nvmx_intr_intercept will return 0.
Quoted 25 lines
}Quoted 23 lines
Quoted 8 lines
Review
Quoted 8 lines
Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/hvm/vmx/vvmx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/xen/arch/x86/hvm/vmx/vvmx.cQuoted 13 lines
xen/arch/x86/hvm/vmx/vvmx.c static void (struct vcpu *v) · line 1386
Quoted 9 lines
index
1b8461ba30..180d01e385100644xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -1383,7 +1383,7 @@ static void (struct vcpu *v) {struct nestedvmx *nvmx = &vcpu_2_nvmx (v);unsigned long reason =get_vvmcs (v,VM_EXIT_REASON ); -uint32_t intr_info = nvmx->intr.intr_info; +unsigned long intr_info =get_vvmcs (v,VM_EXIT_INTR_INFO );well, above reminds me an interesting question. Combining last and this patch, we'd see essentially that it goes back to the state before
f96e1469(at least when Ack on exit is true).
Quoted 7 lines
Quoted 2 lines
Well, patch 1/3 is a revert of
f96e1469, so just revertingf96e1469gets us to that state.you are right. I just wanted to point out that this patch alone doesn't do any real fix for ack-on-exit=1 case. It just makes sure that ack-on-exit=0 is skipped from that function. So it won't be the one fixing your previous problem. 😊
Yes, that's correct.
Quoted 13 lines
Quoted 13 lines
This patch is an attempt to clarify that
nvmx_update_apicvis closely related to the Ack on exit feature, as it modifies SVI in order to signal the vector currently being serviced by theEXIT_INTR_INFOvmcs field. This was not obvious to me, as at first sight I assumednvmx_update_apicvwas actually injecting that vector into the guest.Quoted 5 lines
iirc, that commit was introduced to enable
nested x2apic with apicv, and your very first version even just removed the wholenvmx_update_apicv. Then now with the new reverted logic, are you still suffering x2apic problem? If not, does it imply the real fix is actually coming from patch 3/3 for eoi bitmap update?
Quoted 8 lines
Quoted 4 lines
Yes, patch 3/3 is the one that fixed the issue. Note however that strangely enough removing the call to
nvmx_update_apicv(as my first attempt to solve the issue) did fix it on one of my boxes. It depends a lot on the available vmx features AFAICT.Did you confirm that with 3/3 alone can fix that issue? Just want to make sure the real gain of each patch, so we can reflect it in the commit msg in updated version.
Yes, the patch that actually fixes the issue in the box I've been testing with is 3/3.
Xen will always use the Ack on exit feature, I currently have no way to test whether not using Ack on exit works at all.
Quoted 38 lines
Quoted 28 lines
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1403
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +2
-0if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT && nvmx->intr.source == hvm_intsrc_lapic &&@@ -1399,6 +1399,15 @@ static void nvmx_update_apicv(struct vcpu *v) ppr =vlapic_set_ppr (vlapic);WARN_ON ((ppr &0xf0 ) != (vector &0xf0 )); +/* +* SVI must be updated when the interrupt has been signaled using the
Quoted 11 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1410
Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +7
-0+* Ack on exit feature, or else the currently in-service interrupt +* won't be respected. +* +* Note that this is specific to the fact that when doing a VMEXIT an +* interrupt might get delivered using the interrupt info vmcs field +* instead of being injected normally. +*/ I'm not sure mentioning SVI specifically here is necessary, since all steps here are required - updating iir, isr, rvi, svi, ppr, etc. It is just an emulation of updating virtual APIC state as if a virtual interrupt delivery happens.
Hm, it was hard for me to figure out that SVI is modified here in order to signal that the Ack on exit vector is currently in service, as opposed to being injected using the virtual interrupt delivery mechanism.
Quoted 9 lines
I just wanted to clarify that the purpose of this function is not to inject the vector in
intr_info, but rather to signal that such vector has already been injected using a different mechanism.I'm happy to reword this, but IMO it should be clear that the purpose of the function is not so much to inject an interrupt, but to update the virtual interrupt delivery field in order to signal that an interrupt has been injected using a different mechanism.
Quoted 5 lines
reading it again I feel possibly fine to put the comment there. But I disagree the statement above. The purpose of this function is indeed for injecting an interrupt. Both RVI and SVI are additional requirements when virtual APIC page is in-use while virtual interrupt delivery is not used, i.e. when ack-on-exit is set.
Right, so if I understand this correctly:
- SVI: must be updated when Ack on exit is used, to signal the current in service interrupt which has been injected using a mechanism different than virtual interrupts.
- RVI: should always be updated if there are pending interrupts to be delivered. Note that the interrupt signaled in the INTR_INFO field if Ack on exit is enabled is not considered pending anymore.
So I think RVI should always be updated, regardless of whether Ack on exit is used or not. Do you agree?
Thanks, Roger.
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 72 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 7:23 PMQuoted 12 lines · Kevin
Quoted 12 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:51 PMQuoted 7 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in serviceinterrupt)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
While clarifying the usage make sure that the SVI is only updated
when
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts
as
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It is insufficient. You also need to update RVI to enable virtual injection when Ack on exit is cleared.
But RVI should be updated in
vmx_intr_assistin that case, sincenvmx_intr_interceptshouldn't intercept the interrupt, as it should be handled normally.As we discussed before,
vmx_intr_assistis invoked before
nvmx_switch_guest.Quoted 2 lines
It is incorrectly to update RVI at that time since it might be still vmcs02
being
Quoted 16 lines
active (if no pending softirq to make it invoked again).
Also
nvmx_intr_interceptdoes intercept Ack-on-exit=0 case:if ( intack.source == hvm_intsrc_pic || intack.source == hvm_intsrc_lapic ) { vmx_inject_extint(intack.vector, intack.source); ctrl = get_vvmcs(v, VM_EXIT_CONTROLS); if ( ctrl & VM_EXIT_ACK_INTR_ON_EXIT ) { /* for now, duplicate the ack path in vmx_intr_assist */ hvm_vcpu_ack_pending_irq(v, intack); pt_intr_post(v, intack);Quoted 8 lines
intack = hvm_vcpu_has_pending_irq(v); if ( unlikely(intack.source != hvm_intsrc_none) ) vmx_enable_intr_window(v, intack); } else if ( !cpu_has_vmx_virtual_intr_delivery ) vmx_enable_intr_window(v, intack); return 1; <<<<<<<<Right, I always get confused by the switch happening in the vmentry path.
Quoted 7 lines
That only happens when the vcpu is in nested mode (
nestedhvm_vcpu_in_guestmode== true). That would be the case before a vmexit, at least for the first call tovmx_intr_assistif there are pending softirqs.Note that if there are pending softirqs the second time
nvmx_intr_interceptwill return 0.
Exactly.
Quoted 120 lines
Quoted 24 lines
}Quoted 21 lines
Quoted 8 lines
Review
Quoted 8 lines
Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/hvm/vmx/vvmx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/xen/arch/x86/hvm/vmx/vvmx.cQuoted 12 lines
xen/arch/x86/hvm/vmx/vvmx.c static void (struct vcpu *v) · line 1386
Quoted 9 lines
index
1b8461ba30..180d01e385100644xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -1383,7 +1383,7 @@ static void (struct vcpu *v) {struct nestedvmx *nvmx = &vcpu_2_nvmx (v);unsigned long reason =get_vvmcs (v,VM_EXIT_REASON ); -uint32_t intr_info = nvmx->intr.intr_info; +unsigned long intr_info =get_vvmcs (v,VM_EXIT_INTR_INFO );well, above reminds me an interesting question. Combining last and this patch, we'd see essentially that it goes back to the state before
f96e1469Quoted 9 lines
Quoted 4 lines
Quoted 1 line
(at least when Ack on exit is true).
Well, patch 1/3 is a revert of
f96e1469, so just revertingf96e1469gets us to that state.you are right. I just wanted to point out that this patch alone doesn't do any real fix for ack-on-exit=1 case. It just makes sure that ack-on-exit=0 is skipped from that function. So it won't be the one fixing your previous problem. 😊
Yes, that's correct.
Quoted 13 lines
Quoted 13 lines
This patch is an attempt to clarify that
nvmx_update_apicvis closely related to the Ack on exit feature, as it modifies SVI in order to signal the vector currently being serviced by theEXIT_INTR_INFOvmcs field. This was not obvious to me, as at first sight I assumednvmx_update_apicvwas actually injecting that vector into the guest.Quoted 5 lines
iirc, that commit was introduced to enable
nested x2apic with apicv, and your very first version even just removed the wholenvmx_update_apicv. Then now with the new reverted logic, are you still suffering x2apic problem? If not, does it imply the real fix is actually coming from patch 3/3 for eoi bitmap update?Quoted 8 lines
Quoted 4 lines
Yes, patch 3/3 is the one that fixed the issue. Note however that strangely enough removing the call to
nvmx_update_apicv(as my first attempt to solve the issue) did fix it on one of my boxes. It depends a lot on the available vmx features AFAICT.Did you confirm that with 3/3 alone can fix that issue? Just want to make sure the real gain of each patch, so we can reflect it in the commit msg in updated version.
Yes, the patch that actually fixes the issue in the box I've been testing with is 3/3.
Xen will always use the Ack on exit feature, I currently have no way to test whether not using Ack on exit works at all.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +0
-0if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT && nvmx->intr.source == hvm_intsrc_lapic &&@@ -1399,6 +1399,15 @@ static void nvmx_update_apicv(struct vcpu*v)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v)
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +2
-0ppr =vlapic_set_ppr (vlapic);WARN_ON ((ppr &0xf0 ) != (vector &0xf0 )); +/* +* SVI must be updated when the interrupt has been signaled using
Quoted 5 lines
Quoted 5 lines
the
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/vmx/vvmx.c +4
-0+* Ack on exit feature, or else the currently in-service interrupt +* won't be respected. +* +* Note that this is specific to the fact that when doing a VMEXIT an
Quoted 1 line
Quoted 1 line
Quoted 1 line
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu · line 1408
Quoted 1 line
xen/arch/x86/hvm/vmx/vvmx.c +1
-0+* interrupt might get delivered using the interrupt info vmcs field
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_update_apicv(struct vcpu *v) · line 1410
Quoted 2 lines
xen/arch/x86/hvm/vmx/vvmx.c +2
-0+* instead of being injected normally. +*/ I'm not sure mentioning SVI specifically here is necessary, since all steps here are required - updating iir, isr, rvi, svi, ppr, etc. It is just an
emulation
Quoted 17 lines
Quoted 7 lines
Quoted 1 line
of updating virtual APIC state as if a virtual interrupt delivery happens.
Hm, it was hard for me to figure out that SVI is modified here in order to signal that the Ack on exit vector is currently in service, as opposed to being injected using the virtual interrupt delivery mechanism.
Quoted 9 lines
I just wanted to clarify that the purpose of this function is not to inject the vector in
intr_info, but rather to signal that such vector has already been injected using a different mechanism.I'm happy to reword this, but IMO it should be clear that the purpose of the function is not so much to inject an interrupt, but to update the virtual interrupt delivery field in order to signal that an interrupt has been injected using a different mechanism.
Quoted 5 lines
reading it again I feel possibly fine to put the comment there. But I disagree the statement above. The purpose of this function is indeed for injecting an interrupt. Both RVI and SVI are additional requirements when virtual APIC page is in-use while virtual interrupt delivery is not used, i.e. when ack-on-exit is set.
Right, so if I understand this correctly:
- SVI: must be updated when Ack on exit is used, to signal the current in service interrupt which has been injected using a mechanism different than virtual interrupts.
Quoted 7 lines
- RVI: should always be updated if there are pending interrupts to be delivered. Note that the interrupt signaled in the
INTR_INFOfield if Ack on exit is enabled is not considered pending anymore.So I think RVI should always be updated, regardless of whether Ack on exit is used or not. Do you agree?
Yes, I agree.
Thanks
Kevin
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 42 lines · Kevin
Quoted 42 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 7:23 PMQuoted 12 lines · Kevin
Quoted 12 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:51 PMQuoted 7 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in serviceinterrupt)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
While clarifying the usage make sure that the SVI is only updated
when
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Ack on exit is set and the nested vmcs interrupt info field is valid. Or else a guest not using the Ack on exit feature would loose interrupts
as
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info vmcs field, neither injected in any other way.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It is insufficient. You also need to update RVI to enable virtual injection when Ack on exit is cleared.
But RVI should be updated in
vmx_intr_assistin that case, sincenvmx_intr_interceptshouldn't intercept the interrupt, as it should be handled normally.As we discussed before,
vmx_intr_assistis invoked before
nvmx_switch_guest.Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
It is incorrectly to update RVI at that time since it might be still vmcs02
being
Quoted 6 lines
active (if no pending softirq to make it invoked again).
Also
nvmx_intr_interceptdoes intercept Ack-on-exit=0 case:if ( intack.source == hvm_intsrc_pic || intack.source == hvm_intsrc_lapic )
I've realized that nvmx_intr_intercept will return 1 for interrupts originating from the lapic or the pic, while nvmx_update_apicv will only update GUEST_INTR_STATUS for interrupts originating from the lapic. Is this correct?
Shouldn't both be in sync and handle the same interrupt sources?
Thanks, Roger.
Re: [Xen-devel] [PATCH 2/3] x86/nvmx: clarify and fix usage of nvmx_update_apicv
Quoted 56 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 8:19 PMQuoted 23 lines · Kevin
Quoted 23 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 7:23 PMQuoted 19 lines · Kevin
Quoted 19 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:51 PMQuoted 7 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMThe current usage of
nvmx_update_apicvis not clear: it is deeply intertwined with the Ack interrupt on exit VMEXIT control.The code in
nvmx_update_apicvshould update the SVI (in serviceinterrupt)
Quoted 7 lines
Quoted 7 lines
field of the guest interrupt status only when the Ack interrupt on exit is set, as it is used to record that the interrupt being serviced is signaled in a vmcs field, and hence hasn't been injected as on native. It's important to record the current in service interrupt on the guest interrupt status field, or else further interrupts won't respect the priority of the in service one.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
While clarifying the usage make sure that the SVI is only updated
when
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Ack on exit is set and the nested vmcs interrupt info field is valid.
Or
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
else a guest not using the Ack on exit feature would loose
interrupts
Quoted 3 lines
Quoted 3 lines
as
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
they would be signaled as being in service on the guest interrupt status field but won't actually be recorded on the interrupt info
vmcs
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
field, neither injected in any other way.
It is insufficient. You also need to update RVI to enable virtual
injection
Quoted 15 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
when Ack on exit is cleared.
But RVI should be updated in
vmx_intr_assistin that case, sincenvmx_intr_interceptshouldn't intercept the interrupt, as it should be handled normally.As we discussed before,
vmx_intr_assistis invoked before
nvmx_switch_guest.Quoted 2 lines
It is incorrectly to update RVI at that time since it might be still vmcs02
being
Quoted 4 lines
active (if no pending softirq to make it invoked again).
Also
nvmx_intr_interceptdoes intercept Ack-on-exit=0 case:
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
if ( intack.source == hvm_intsrc_pic || intack.source == hvm_intsrc_lapic )I've realized that
nvmx_intr_interceptwill return 1 for interrupts originating from the lapic or the pic, whilenvmx_update_apicvwill only updateGUEST_INTR_STATUSfor interrupts originating from the lapic. Is this correct?
Isn't apicv for virtual lapic instead of virtual pic?
Quoted 3 lines
Shouldn't both be in sync and handle the same interrupt sources?
But I do realize one potential issue about 67f9d0b9, which may break vpic delivery when ack-on-exit is off. We should always use interrupt window to handle that situation for vpic. Sorry I didn't catch it when proposing that change...
Thanks
Kevin
PATCH 3/3 x86/nvmx: update exit bitmap on vmexit
In reply to Roger Pau MonneCurrent code in nvmx_update_apicv set the guest interrupt status field but doesn't update the exit bitmap, which can cause issues of lost interrupts on the L1 hypervisor if vmx_intr_assist gets short-circuited by nvmx_intr_intercept returning true.
Extract the code to update the exit bitmap from vmx_intr_assist into a helper and use it in nvmx_update_apicv when updating the guest interrupt status field.
--- xen/arch/x86/hvm/vmx/intr.c | 21 +++++++++++++-------- xen/arch/x86/hvm/vmx/vvmx.c | 1 + xen/include/asm-x86/hvm/vmx/vmx.h | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-)
xen/arch/x86/hvm/vmx/intr.c +13 -8
@@ -224,6 +224,18 @@ static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack)return 0 ; } +void vmx_sync_exit_bitmap (struct vcpu *v) +{ +const unsigned int n =ARRAY_SIZE (v->arch.hvm.vmx.eoi_exit_bitmap); +unsigned int i; + +while ( (i =find_first_bit (&v->arch.hvm.vmx.eoi_exitmap_changed, n)) < n ) + { +clear_bit (i, &v->arch.hvm.vmx.eoi_exitmap_changed); +__vmwrite (EOI_EXIT_BITMAP (i), v->arch.hvm.vmx.eoi_exit_bitmap[i]); + } +} +void vmx_intr_assist (void ) {struct hvm_intack intack;
@@ -318,7 +330,6 @@ void vmx_intr_assist(void) intack.source != hvm_intsrc_vector ) {unsigned long status; -unsigned int i, n;/* * intack.vector is the highest priority vector. So we set eoi_exit_bitmap
@@ -379,13 +390,7 @@ void vmx_intr_assist(void) intack.vector;__vmwrite (GUEST_INTR_STATUS , status); - n =ARRAY_SIZE (v->arch.hvm.vmx.eoi_exit_bitmap); -while ( (i =find_first_bit (&v->arch.hvm.vmx.eoi_exitmap_changed, - n)) < n ) - { -clear_bit (i, &v->arch.hvm.vmx.eoi_exitmap_changed); -__vmwrite (EOI_EXIT_BITMAP (i), v->arch.hvm.vmx.eoi_exit_bitmap[i]); - } +vmx_sync_exit_bitmap (v);pt_intr_post (v, intack); }
xen/arch/x86/hvm/vmx/vvmx.c +1 -0
@@ -1414,6 +1414,7 @@ static void nvmx_update_apicv(struct vcpu *v) status |= rvi &VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK ;__vmwrite (GUEST_INTR_STATUS , status); +vmx_sync_exit_bitmap (v); } }
xen/include/asm-x86/hvm/vmx/vmx.h +2 -0
@@ -610,6 +610,8 @@ void update_guest_eip(void);void vmx_pi_per_cpu_init (unsigned int cpu);void vmx_pi_desc_fixup (unsigned int cpu); +void vmx_sync_exit_bitmap (struct vcpu *v); +#ifdef CONFIG_HVM void vmx_pi_hooks_assign (struct domain *d);void vmx_pi_hooks_deassign (struct domain *d);
Signature · 7 lines
2.25.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/3] x86/nvmx: update exit bitmap on vmexit
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMCurrent code in
nvmx_update_apicvset the guest interrupt status field but doesn't update the exit bitmap, which can cause issues of lost interrupts on the L1 hypervisor ifvmx_intr_assistgets short-circuited bynvmx_intr_interceptreturning true.
Above is not accurate. Currently Xen didn't choose to update the EOI exit bitmap every time when there is a change. Instead, it chose to batch the update before resuming to the guest. sort of optimization. So it is not related to whether SVI is changed. We should always do the bitmap update in nvmx_update_apicv, regardless of the setting of Ack-on-exit ...
Thanks
Kevin
Quoted 88 lines
Extract the code to update the exit bitmap from
vmx_intr_assistinto a helper and use it innvmx_update_apicvwhen updating the guest interrupt status field.Signed-off-by Roger Pau Monné <[email protected]>--- xen/arch/x86/hvm/vmx/intr.c | 21 +++++++++++++-------- xen/arch/x86/hvm/vmx/vvmx.c | 1 + xen/include/asm-x86/hvm/vmx/vmx.h | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-)xen/arch/x86/hvm/vmx/intr.c +12
-0@@ -224,6 +224,18 @@ static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack)return 0 ; } +void vmx_sync_exit_bitmap (struct vcpu *v) +{ +const unsigned int n =ARRAY_SIZE (v->arch.hvm.vmx.eoi_exit_bitmap); +unsigned int i; + +while ( (i =find_first_bit (&v->arch.hvm.vmx.eoi_exitmap_changed, n)) < n ) + { +clear_bit (i, &v->arch.hvm.vmx.eoi_exitmap_changed); +__vmwrite (EOI_EXIT_BITMAP (i), v->arch.hvm.vmx.eoi_exit_bitmap[i]); + } +} +void vmx_intr_assist (void ){ struct hvm_intack intack;xen/arch/x86/hvm/vmx/intr.c +1
-8@@ -318,7 +330,6 @@ void vmx_intr_assist(void) intack.source != hvm_intsrc_vector ) {unsigned long status; -unsigned int i, n;/* * intack.vector is the highest priority vector. So we set eoi_exit_bitmap @@ -379,13 +390,7 @@ void vmx_intr_assist(void) intack.vector;__vmwrite (GUEST_INTR_STATUS , status); - n =ARRAY_SIZE (v->arch.hvm.vmx.eoi_exit_bitmap); -while ( (i =find_first_bit (&v->arch.hvm.vmx.eoi_exitmap_changed, - n)) < n ) - { -clear_bit (i, &v->arch.hvm.vmx.eoi_exitmap_changed); -__vmwrite (EOI_EXIT_BITMAP (i), v->arch.hvm.vmx.eoi_exit_bitmap[i]); - } +vmx_sync_exit_bitmap (v);pt_intr_post (v, intack); }xen/arch/x86/hvm/vmx/vvmx.c +1
-0@@ -1414,6 +1414,7 @@ static void nvmx_update_apicv(struct vcpu *v) status |= rvi &VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK ;__vmwrite (GUEST_INTR_STATUS , status); +vmx_sync_exit_bitmap (v); } }xen/include/asm- renamed from xen/include/asm-x86/hvm/vmx/vmx.h +0
-0
x86/hvm/vmx/vmx.h
indexb334e1ec94..111ccd7e61100644xen/include/asm-x86/hvm/vmx/vmx.h +2
-1@@ -610,6 +610,8 @@ void update_guest_eip(void);void vmx_pi_per_cpu_init (unsigned int cpu);void vmx_pi_desc_fixup (unsigned int cpu); +void vmx_sync_exit_bitmap (struct vcpu *v); +#ifdef CONFIG_HVM void vmx_pi_hooks_assign (struct domain *d);void vmx_pi_hooks_deassign (struct domain *d); --2.25.0
Re: [Xen-devel] [PATCH 3/3] x86/nvmx: update exit bitmap on vmexit
Quoted 8 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMCurrent code in
nvmx_update_apicvset the guest interrupt status field but doesn't update the exit bitmap, which can cause issues of lost interrupts on the L1 hypervisor ifvmx_intr_assistgets short-circuited bynvmx_intr_interceptreturning true.
Quoted 6 lines
Above is not accurate. Currently Xen didn't choose to update the EOI exit bitmap every time when there is a change. Instead, it chose to batch the update before resuming to the guest. sort of optimization. So it is not related to whether SVI is changed. We should always do the bitmap update in
nvmx_update_apicv, regardless of the setting of Ack-on-exit ...
But if Ack on exit is not set the GUEST_INTR_STATUS won't be changed by nvmx_intr_intercept, and hence there's no need to update the EOI exit map?
If OTOH the GUEST_INTR_STATUS field is changed by vmx_intr_assist the bitmap will already be updated there.
Thanks, Roger.
Re: [Xen-devel] [PATCH 3/3] x86/nvmx: update exit bitmap on vmexit
Quoted 19 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:59 PMQuoted 8 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMCurrent code in
nvmx_update_apicvset the guest interrupt status field but doesn't update the exit bitmap, which can cause issues of lost interrupts on the L1 hypervisor ifvmx_intr_assistgets short-circuited bynvmx_intr_interceptreturning true.Quoted 6 lines
Above is not accurate. Currently Xen didn't choose to update the EOI exit bitmap every time when there is a change. Instead, it chose to batch the update before resuming to the guest. sort of optimization. So it is not related to whether SVI is changed. We should always do the bitmap update in
nvmx_update_apicv, regardless of the setting of Ack-on-exit ...
Quoted 7 lines
But if Ack on exit is not set the
GUEST_INTR_STATUSwon't be changed bynvmx_intr_intercept, and hence there's no need to update the EOI exit map?If OTOH the
GUEST_INTR_STATUSfield is changed byvmx_intr_assistthe bitmap will already be updated there.
If you agree with my comment in patch 2/3 about setting RVI for ack-on-exit=0, then EOI bitmap update should be done there too.
Thanks
Kevin
Re: [Xen-devel] [PATCH 3/3] x86/nvmx: update exit bitmap on vmexit
Quoted 23 lines · Kevin
Quoted 23 lines
From: Roger Pau Monné <[email protected]>
Sent: Tuesday, March 24, 2020 5:59 PMQuoted 8 lines · Kevin
Quoted 7 lines
From: Roger Pau Monne <[email protected]>
Sent: Saturday, March 21, 2020 3:08 AMCurrent code in
nvmx_update_apicvset the guest interrupt status field but doesn't update the exit bitmap, which can cause issues of lost interrupts on the L1 hypervisor ifvmx_intr_assistgets short-circuited bynvmx_intr_interceptreturning true.Quoted 6 lines
Above is not accurate. Currently Xen didn't choose to update the EOI exit bitmap every time when there is a change. Instead, it chose to batch the update before resuming to the guest. sort of optimization. So it is not related to whether SVI is changed. We should always do the bitmap update in
nvmx_update_apicv, regardless of the setting of Ack-on-exit ...But if Ack on exit is not set the
GUEST_INTR_STATUSwon't be changed bynvmx_intr_intercept, and hence there's no need to update the EOI exit map?
Quoted 6 lines
Quoted 3 lines
If OTOH the
GUEST_INTR_STATUSfield is changed byvmx_intr_assistthe bitmap will already be updated there.If you agree with my comment in patch 2/3 about setting RVI for ack-on-exit=0, then EOI bitmap update should be done there too.
Yes, I agree, see my reply to your comment. I (again) misremembered the sequence and assumed the switch will happen prior to calling vmx_intr_assist which is not the case.
Thanks, Roger.