x86/vm_event: block interrupt injection for sync vm_events
PATCH 1/1 x86/vm_event: block interrupt injection for sync vm_events
Block interrupts (in vmx_intr_assist()) for the duration of processing a sync vm_event (similarly to the strategy currently used for single-stepping). Otherwise, attempting to emulate an instruction when requested by a vm_event reply may legitimately need to call hvm_inject_page_fault(), which then overwrites the active interrupt in the VMCS.
--- xen/arch/x86/hvm/vm_event.c | 2 ++ xen/arch/x86/hvm/vmx/intr.c | 8 ++++++++ xen/arch/x86/vm_event.c | 5 +++++ xen/common/monitor.c | 6 ++++++ xen/include/asm-arm/vm_event.h | 6 ++++++ xen/include/asm-x86/vm_event.h | 8 ++++++++ 6 files changed, 35 insertions(+)
xen/arch/x86/hvm/vm_event.c +2 -0
@@ -124,6 +124,8 @@ void hvm_vm_event_do_resume(struct vcpu *v) w->do_write.msr =0 ; } + +vm_event_block_interrupts (v, false); }/*
xen/arch/x86/hvm/vmx/intr.c +8 -0
@@ -22,6 +22,7 @@#include <xen/errno.h> #include <xen/trace.h> #include <xen/event.h> +#include <xen/vm_event.h> #include <asm/apicdef.h> #include <asm/current.h> #include <asm/cpufeature.h>
@@ -37,6 +38,7 @@#include <asm/hvm/nestedhvm.h> #include <public/hvm/ioreq.h> #include <asm/hvm/trace.h> +#include <asm/vm_event.h> /* * A few notes on virtual NMI and INTR delivery, and interactions with
@@ -239,6 +241,12 @@ void vmx_intr_assist(void)return ; } +/* Block event injection while handling a sync vm_event. */ +if (unlikely (v->arch.vm_event) && +vm_event_check_ring (v->domain->vm_event_monitor) && + v->arch.vm_event->intr_block ) +return ; +/* Crank the handle on interrupt state. */ pt_vector =pt_update_irq (v);
xen/arch/x86/vm_event.c +5 -0
@@ -122,6 +122,11 @@ void vm_event_monitor_next_interrupt(struct vcpu *v) v->arch.monitor.next_interrupt_enabled = true; } +void vm_event_block_interrupts (struct vcpu *v,bool value) +{ + v->arch.vm_event->intr_block = value; +} +#ifdef CONFIG_HVM static void vm_event_pack_segment_register (enum x86_segment segment,struct vm_event_regs_x86 *reg)
xen/common/monitor.c +6 -0
@@ -113,6 +113,12 @@ int monitor_traps(struct vcpu *v, bool sync, vm_event_request_t *req)if ( sync ) { req->flags |=VM_EVENT_FLAG_VCPU_PAUSED ; +/* +* It only makes sense to block interrupts for the duration of +* processing blocking vm_events, since that is the only case where +* emulating the current instruction really applies. +*/ +vm_event_block_interrupts (v, true);vm_event_vcpu_pause (v); rc =1 ; }
xen/include/asm-arm/vm_event.h +6 -0
@@ -52,4 +52,10 @@ void vm_event_emulate_check(struct vcpu *v, vm_event_response_t *rsp) /* Not supported on ARM. */ } +static inline +void vm_event_block_interrupts (struct vcpu *v,bool value) +{ +/* Not supported on ARM. */ +} +#endif /* __ASM_ARM_VM_EVENT_H__ */
xen/include/asm-x86/vm_event.h +8 -0
@@ -34,6 +34,12 @@ struct arch_vm_event {struct monitor_write_data write_data;struct vm_event_regs_x86 gprs;bool set_gprs; +/* +* Block interrupts until this vm_event is done handling (after the +* fashion of single-step). Meant for the cases where the vm_event +* reply asks for emulation of the current instruction. +*/ +bool intr_block; };int vm_event_init_domain (struct domain *d);
@@ -47,4 +53,6 @@ void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp);void vm_event_emulate_check (struct vcpu *v,vm_event_response_t *rsp); +void vm_event_block_interrupts (struct vcpu *v,bool value); +#endif /* __ASM_X86_VM_EVENT_H__ */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.12.18 at 21:48, <[email protected]> wrote:
Block interrupts (in
vmx_intr_assist()) for the duration of processing a syncvm_event(similarly to the strategy currently used for single-stepping). Otherwise, attempting to emulate an instruction when requested by avm_eventreply may legitimately need to callhvm_inject_page_fault(), which then overwrites the active interrupt in the VMCS.
I take it that hvm_inject_page_fault() is just the most prominent example. If so, wold you mind adding "e.g."?
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 246
Quoted 7 lines
xen/arch/x86/hvm/vmx/intr.c +3
-0@@ -239,6 +241,12 @@ void vmx_intr_assist(void)return ; } +/* Block event injection while handling a sync vm_event. */ + if ( unlikely(v->arch.vm_event) && + vm_event_check_ring(v->domain->vm_event_monitor) &&
Is this check really needed?
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 247
Quoted 1 line
xen/arch/x86/hvm/vmx/intr.c +1
-0+ v->arch.vm_event->intr_block )
This part certainly doesn't look to depend on it. Perhaps ->intr_block would better be cleared when tearing down a ring?
Also is there really no similar change needed on the AMD (SVM) side?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.12.18 at 21:48, <[email protected]> wrote:
Block interrupts (in
vmx_intr_assist()) for the duration of processing a syncvm_event(similarly to the strategy currently used for single-stepping). Otherwise, attempting to emulate an instruction when requested by avm_eventreply may legitimately need to callhvm_inject_page_fault(), which then overwrites the active interrupt in the VMCS.I take it that
hvm_inject_page_fault()is just the most prominent example. If so, wold you mind adding "e.g."?
Indeed. I'll add "e.g.".
Quoted 10 lines
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 246
Quoted 7 lines
xen/arch/x86/hvm/vmx/intr.c +3
-0@@ -239,6 +241,12 @@ void vmx_intr_assist(void)return ; } +/* Block event injection while handling a sync vm_event. */ + if ( unlikely(v->arch.vm_event) && + vm_event_check_ring(v->domain->vm_event_monitor) &&Is this check really needed?
Quoted 4 lines
xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 247
Quoted 1 line
xen/arch/x86/hvm/vmx/intr.c +1
-0+ v->arch.vm_event->intr_block )This part certainly doesn't look to depend on it. Perhaps ->intr_block would better be cleared when tearing down a ring?
True, that would look cleaner.
Quoted 2 lines
Also is there really no similar change needed on the AMD (SVM) side?
Well, for all practical purposes no, since we don't currently have NPT-fault vm_events on AMD (I'll have to dig up the old thread to remember where that got left off), and those are the only events for which it is sane to reply with "please emulate".
But I see your point, it would be better to add that code for SVM as well while we're at it rather than have a surprise once everything else is in place. So I'll add that early return to svm_intr_assist() as well.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel