x86: Introduce X86_ET_* constants in x86-defns.h
PATCH 1/1 x86: Introduce X86_ET_* constants in x86-defns.h
The FRED spec architecturalises the Event Type encoding, previously exposed only in VMCB/VMCS fields.
Introduce the constants in x86-defns.h, making them a bit more consice, and retire enum x86_event_type.
Take the opportunity to introduce X86_ET_OTHER. It's absence appears to be a bug in Introspection's Monitor Trap Flag support, when considering VECTORING events during another VMExit.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- tools/include/xendevicemodel.h | 2 +- xen/arch/x86/hvm/hvm.c | 8 ++--- xen/arch/x86/hvm/svm/intr.c | 4 +-- xen/arch/x86/hvm/svm/svm.c | 47 +++++++++++++------------- xen/arch/x86/hvm/vmx/vmx.c | 42 +++++++++++------------ xen/arch/x86/hvm/vmx/vvmx.c | 12 +++---- xen/arch/x86/include/asm/domain.h | 8 ++--- xen/arch/x86/include/asm/hvm/hvm.h | 4 +-- xen/arch/x86/include/asm/x86-defns.h | 9 +++++ xen/arch/x86/mm/shadow/multi.c | 2 +- xen/arch/x86/pv/ro-page-fault.c | 2 +- xen/arch/x86/pv/traps.c | 6 ++-- xen/arch/x86/x86_emulate/x86_emulate.c | 26 +++++++------- xen/arch/x86/x86_emulate/x86_emulate.h | 19 ++--------- xen/include/public/hvm/dm_op.h | 2 +- 15 files changed, 91 insertions(+), 102 deletions(-)
tools/include/xendevicemodel.h +1 -1
@@ -308,7 +308,7 @@ int xendevicemodel_set_mem_type(* @parm domid the domain id to be serviced * @parm vcpu the vcpu id * @parm vector the interrupt vector -* @parm type the event type (see the definition of enum x86_event_type) +* @parm type the event type (see x86-defns.h:X86_ET_*) * @parm error_code the error code or ~0 to skip * @parm insn_len the instruction length * @parm extra type-specific extra data (%cr2 for #PF, pending_dbg for #DB)
xen/arch/x86/hvm/hvm.c +4 -4
@@ -219,10 +219,10 @@ int hvm_event_needs_reinjection(uint8_t type, uint8_t vector) {switch ( type ) { -case X86_EVENTTYPE_EXT_INTR : -case X86_EVENTTYPE_NMI : +case X86_ET_EXT_INTR : +case X86_ET_NMI :return 1 ; -case X86_EVENTTYPE_HW_EXCEPTION : +case X86_ET_HW_EXC :/* * SVM uses type 3 ("HW Exception") for #OF and #BP. We explicitly * check for these vectors, as they are really SW Exceptions. SVM has
@@ -1738,7 +1738,7 @@ void hvm_inject_event(const struct x86_event *event) {struct vcpu *curr = current;const uint8_t vector = event->vector; -const bool has_ec = ((event->type ==X86_EVENTTYPE_HW_EXCEPTION ) && +const bool has_ec = ((event->type ==X86_ET_HW_EXC ) && (vector <32 ) && ((X86_EXC_HAVE_EC & (1u << vector))));ASSERT (vector == event->vector);/* Confirm no truncation. */
xen/arch/x86/hvm/svm/intr.c +2 -2
@@ -35,7 +35,7 @@ static void svm_inject_nmi(struct vcpu *v) event.raw =0 ; event.v = true; - event.type =X86_EVENTTYPE_NMI ; + event.type =X86_ET_NMI ; event.vector =X86_EXC_NMI ;ASSERT (!vmcb->event_inj.v);
@@ -56,7 +56,7 @@ static void svm_inject_extint(struct vcpu *v, int vector) event.raw =0 ; event.v = true; - event.type =X86_EVENTTYPE_EXT_INTR ; + event.type =X86_ET_EXT_INTR ; event.vector = vector;ASSERT (!vmcb->event_inj.v);
xen/arch/x86/hvm/svm/svm.c +23 -24
150 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vmx.c +19 -23
135 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vvmx.c +6 -6
@@ -1346,7 +1346,7 @@ static void sync_exception_state(struct vcpu *v)switch (MASK_EXTR (nvmx->intr.intr_info,INTR_INFO_INTR_TYPE_MASK ) ) { -case X86_EVENTTYPE_EXT_INTR : +case X86_ET_EXT_INTR :/* rename exit_reason to EXTERNAL_INTERRUPT */ set_vvmcs (v,VM_EXIT_REASON ,EXIT_REASON_EXTERNAL_INTERRUPT );set_vvmcs (v,EXIT_QUALIFICATION ,0 );
@@ -1355,14 +1355,14 @@ static void sync_exception_state(struct vcpu *v) : 0);break ; -case X86_EVENTTYPE_HW_EXCEPTION : -case X86_EVENTTYPE_SW_INTERRUPT : -case X86_EVENTTYPE_SW_EXCEPTION : +case X86_ET_HW_EXC : +case X86_ET_SW_INT : +case X86_ET_SW_EXC :/* throw to L1 */ set_vvmcs (v,VM_EXIT_INTR_INFO , nvmx->intr.intr_info);set_vvmcs (v,VM_EXIT_INTR_ERROR_CODE , nvmx->intr.error_code);break ; -case X86_EVENTTYPE_NMI : +case X86_ET_NMI :set_vvmcs (v,VM_EXIT_REASON ,EXIT_REASON_EXCEPTION_NMI );set_vvmcs (v,EXIT_QUALIFICATION ,0 );set_vvmcs (v,VM_EXIT_INTR_INFO , nvmx->intr.intr_info);
@@ -2445,7 +2445,7 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,case EXIT_REASON_EXCEPTION_NMI : {unsigned long intr_info; -u32 valid_mask =MASK_INSR (X86_EVENTTYPE_HW_EXCEPTION , +u32 valid_mask =MASK_INSR (X86_ET_HW_EXC ,INTR_INFO_INTR_TYPE_MASK ) |INTR_INFO_VALID_MASK ;u64 exec_bitmap;
xen/arch/x86/include/asm/domain.h +4 -4
@@ -724,7 +724,7 @@ static inline void pv_inject_hw_exception(unsigned int vector, int errcode) {const struct x86_event event = { .vector = vector, - .type =X86_EVENTTYPE_HW_EXCEPTION , + .type =X86_ET_HW_EXC , .error_code = errcode, };
@@ -735,7 +735,7 @@ static inline void pv_inject_DB(unsigned long pending_dbg) {struct x86_event event = { .vector =X86_EXC_DB , - .type =X86_EVENTTYPE_HW_EXCEPTION , + .type =X86_ET_HW_EXC , .error_code =X86_EVENT_NO_EC , };
@@ -748,7 +748,7 @@ static inline void pv_inject_page_fault(int errcode, unsigned long cr2) {struct x86_event event = { .vector =X86_EXC_PF , - .type =X86_EVENTTYPE_HW_EXCEPTION , + .type =X86_ET_HW_EXC , .error_code = errcode, };
@@ -761,7 +761,7 @@ static inline void pv_inject_sw_interrupt(unsigned int vector) {const struct x86_event event = { .vector = vector, - .type =X86_EVENTTYPE_SW_INTERRUPT , + .type =X86_ET_SW_INT , .error_code =X86_EVENT_NO_EC , };
xen/arch/x86/include/asm/hvm/hvm.h +2 -2
@@ -522,7 +522,7 @@ static inline void hvm_inject_hw_exception(unsigned int vector, int errcode) {struct x86_event event = { .vector = vector, - .type =X86_EVENTTYPE_HW_EXCEPTION , + .type =X86_ET_HW_EXC , .error_code = errcode, };
@@ -533,7 +533,7 @@ static inline void hvm_inject_page_fault(int errcode, unsigned long cr2) {struct x86_event event = { .vector =X86_EXC_PF , - .type =X86_EVENTTYPE_HW_EXCEPTION , + .type =X86_ET_HW_EXC , .error_code = errcode, };
xen/arch/x86/include/asm/x86-defns.h +9 -0
@@ -204,4 +204,13 @@#define X86_MT_UCM 0x07/* UC- */ #define X86_NUM_MT 0x08 +/* Event Types. */ +#define X86_ET_EXT_INTR 0/* External Interrupt */ +#define X86_ET_NMI 2/* NMI */ +#define X86_ET_HW_EXC 3/* Hardware Exception (#PF/#GP/etc) */ +#define X86_ET_SW_INT 4/* Software Interrupt (INT $n) */ +#define X86_ET_PRIV_SW_EXC 5/* Privileged Software Exception (ICEBP/INT1) */ +#define X86_ET_SW_EXC 6/* Software Exception (INT3, INTO) */ +#define X86_ET_OTHER 7/* Misc event: MTF=0, SYSCALL=1, SYSENTER=2 */ +#endif /* __XEN_X86_DEFNS_H__ */
xen/arch/x86/mm/shadow/multi.c +1 -1
@@ -2701,7 +2701,7 @@ static int cf_check sh_page_fault(* else is an emulation bug, or a guest playing with the instruction * stream under Xen's feet. */ - if ( emul_ctxt.ctxt.event.type == X86_EVENTTYPE_HW_EXCEPTION && + if ( emul_ctxt.ctxt.event.type == X86_ET_HW_EXC && ((emul_ctxt.ctxt.event.vector == X86_EXC_PF) || (((emul_ctxt.ctxt.event.vector == X86_EXC_GP) || (emul_ctxt.ctxt.event.vector == X86_EXC_SS)) &&
xen/arch/x86/pv/ro-page-fault.c +1 -1
@@ -379,7 +379,7 @@ int pv_ro_page_fault(unsigned long addr, struct cpu_user_regs *regs)* concurrent pagetable update). Anything else is an emulation bug, * or a guest playing with the instruction stream under Xen's feet. */ -if ( ctxt.event.type ==X86_EVENTTYPE_HW_EXCEPTION && +if ( ctxt.event.type ==X86_ET_HW_EXC && ctxt.event.vector ==X86_EXC_PF )pv_inject_event (&ctxt.event);else
xen/arch/x86/pv/traps.c +3 -3
@@ -29,14 +29,14 @@ void pv_inject_event(const struct x86_event *event)bool use_error_code;ASSERT (vector == event->vector);/* Confirm no truncation. */ -if ( event->type ==X86_EVENTTYPE_HW_EXCEPTION ) +if ( event->type ==X86_ET_HW_EXC ) {ASSERT (vector <32 ); use_error_code =X86_EXC_HAVE_EC & (1u << vector); }else { -ASSERT (event->type ==X86_EVENTTYPE_SW_INTERRUPT ); +ASSERT (event->type ==X86_ET_SW_INT ); use_error_code = false; }if ( use_error_code )
@@ -51,7 +51,7 @@ void pv_inject_event(const struct x86_event *event) tb->cs = ti->cs; tb->eip = ti->address; -switch ( vector | -(event->type ==X86_EVENTTYPE_SW_INTERRUPT ) ) +switch ( vector | -(event->type ==X86_ET_SW_INT ) ) {case X86_EXC_PF : curr->arch.pv.ctrlreg[2 ] = event->cr2;
xen/arch/x86/x86_emulate/x86_emulate.c +12 -14
@@ -2372,19 +2372,19 @@ x86_emulate( {case 0xcc :/* int3 */ ctxt->event.vector =X86_EXC_BP ; - ctxt->event.type =X86_EVENTTYPE_SW_EXCEPTION ; + ctxt->event.type =X86_ET_SW_EXC ;break ;case 0xcd :/* int imm8 */ ctxt->event.vector = imm1; - ctxt->event.type =X86_EVENTTYPE_SW_INTERRUPT ; + ctxt->event.type =X86_ET_SW_INT ;break ;case 0xce :/* into */ ctxt->event.vector =X86_EXC_OF ; - ctxt->event.type =X86_EVENTTYPE_SW_EXCEPTION ; + ctxt->event.type =X86_ET_SW_EXC ;break ;case 0xf1 :/* icebp */ ctxt->event.vector =X86_EXC_DB ; - ctxt->event.type =X86_EVENTTYPE_PRI_SW_EXCEPTION ; + ctxt->event.type =X86_ET_PRIV_SW_EXC ;break ; } ctxt->event.error_code =X86_EVENT_NO_EC ;
@@ -8597,16 +8597,14 @@ static void __init __maybe_unused build_assertions(void)BUILD_BUG_ON (x86_seg_fs !=4 );BUILD_BUG_ON (x86_seg_gs !=5 ); -/* -* Check X86_EVENTTYPE_* against VMCB EVENTINJ and VMCS INTR_INFO type -* fields. -*/ -BUILD_BUG_ON (X86_EVENTTYPE_EXT_INTR !=0 ); -BUILD_BUG_ON (X86_EVENTTYPE_NMI !=2 ); -BUILD_BUG_ON (X86_EVENTTYPE_HW_EXCEPTION !=3 ); -BUILD_BUG_ON (X86_EVENTTYPE_SW_INTERRUPT !=4 ); -BUILD_BUG_ON (X86_EVENTTYPE_PRI_SW_EXCEPTION !=5 ); -BUILD_BUG_ON (X86_EVENTTYPE_SW_EXCEPTION !=6 ); +/* Check X86_ET_* against VMCB EVENTINJ and VMCS INTR_INFO type fields. */ +BUILD_BUG_ON (X86_ET_EXT_INTR !=0 ); +BUILD_BUG_ON (X86_ET_NMI !=2 ); +BUILD_BUG_ON (X86_ET_HW_EXC !=3 ); +BUILD_BUG_ON (X86_ET_SW_INT !=4 ); +BUILD_BUG_ON (X86_ET_PRIV_SW_EXC !=5 ); +BUILD_BUG_ON (X86_ET_SW_EXC !=6 ); +BUILD_BUG_ON (X86_ET_OTHER !=7 ); }#ifndef NDEBUG
xen/arch/x86/x86_emulate/x86_emulate.h +3 -16
@@ -59,24 +59,11 @@ static inline bool is_x86_system_segment(enum x86_segment seg)return seg >= x86_seg_tr && seg < x86_seg_none; } -/* -* x86 event types. This enumeration is valid for: -* Intel VMX: {VM_ENTRY,VM_EXIT,IDT_VECTORING}_INTR_INFO[10:8] -* AMD SVM: eventinj[10:8] and exitintinfo[10:8] (types 0-4 only) -*/ -enum x86_event_type { -X86_EVENTTYPE_EXT_INTR ,/* External interrupt */ -X86_EVENTTYPE_NMI =2 ,/* NMI */ -X86_EVENTTYPE_HW_EXCEPTION ,/* Hardware exception */ -X86_EVENTTYPE_SW_INTERRUPT ,/* Software interrupt (CD nn) */ -X86_EVENTTYPE_PRI_SW_EXCEPTION ,/* ICEBP (F1) */ -X86_EVENTTYPE_SW_EXCEPTION ,/* INT3 (CC), INTO (CE) */ -};#define X86_EVENT_NO_EC (-1)/* No error code. */ struct x86_event {int16_t vector; -uint8_t type;/* X86_EVENTTYPE_* */ +uint8_t type;/* X86_ET_* */ uint8_t insn_len;/* Instruction length */ int32_t error_code;/* X86_EVENT_NO_EC if n/a */ union {
@@ -821,7 +808,7 @@ static inline void x86_emul_hw_exception(ASSERT (!ctxt->event_pending); ctxt->event.vector = vector; - ctxt->event.type =X86_EVENTTYPE_HW_EXCEPTION ; + ctxt->event.type =X86_ET_HW_EXC ; ctxt->event.error_code = error_code; ctxt->event_pending = true;
@@ -833,7 +820,7 @@ static inline void x86_emul_pagefault(ASSERT (!ctxt->event_pending); ctxt->event.vector =X86_EXC_PF ; - ctxt->event.type =X86_EVENTTYPE_HW_EXCEPTION ; + ctxt->event.type =X86_ET_HW_EXC ; ctxt->event.error_code = error_code; ctxt->event.cr2 = cr2;
xen/include/public/hvm/dm_op.h +1 -1
@@ -302,7 +302,7 @@ struct xen_dm_op_inject_event {uint8_t vector;/* IN - event type (DMOP_EVENT_* ) */ uint8_t type; -/* NB. This enumeration precisely matches hvm.h:X86_EVENTTYPE_* */ +/* NB. This enumeration precisely matches x86-defns.h:X86_ET_* */ # define XEN_DMOP_EVENT_ext_int 0/* external interrupt */ # define XEN_DMOP_EVENT_nmi 2/* nmi */ # define XEN_DMOP_EVENT_hw_exc 3/* hardware exception */
Signature · 1 line
2.39.5
Quoted 6 lines · Andrew Cooper
The FRED spec architecturalises the Event Type encoding, previously exposed only in VMCB/VMCS fields.
Introduce the constants in
x86-defns.h, making them a bit more consice, and retire enumx86_event_type.
Quoted 7 lines
Take the opportunity to introduce
X86_ET_OTHER. It's absence appears to be a bug in Introspection's Monitor Trap Flag support, when considering VECTORING events during another VMExit.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 4 lines
xen/arch/x86/include/asm/x86-defns.h +0
-0@@ -204,4 +204,13 @@#define X86_MT_UCM 0x07/* UC- */
xen/arch/x86/include/asm/x86-defns.h line 214
Quoted 10 lines
xen/arch/x86/include/asm/x86-defns.h +8
-0#define X86_NUM_MT 0x08 +/* Event Types. */ +#define X86_ET_EXT_INTR 0/* External Interrupt */ +#define X86_ET_NMI 2/* NMI */ +#define X86_ET_HW_EXC 3/* Hardware Exception (#PF/#GP/etc) */ +#define X86_ET_SW_INT 4/* Software Interrupt (INT $n) */ +#define X86_ET_PRIV_SW_EXC 5/* Privileged Software Exception (ICEBP/INT1) */ +#define X86_ET_SW_EXC 6/* Software Exception (INT3, INTO) */ +#define X86_ET_OTHER 7/* Misc event: MTF=0, SYSCALL=1, SYSENTER=2 */
ET could of course mean a lot of things; sadly no sufficiently short but still less ambiguous alternative comes to mind, so ET is going to be it.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
The FRED spec architecturalises the Event Type encoding, previously exposed only in VMCB/VMCS fields.
Introduce the constants in
x86-defns.h, making them a bit more consice, and retire enumx86_event_type.
Quoted 8 lines
Quoted 7 lines
Take the opportunity to introduce
X86_ET_OTHER. It's absence appears to be a bug in Introspection's Monitor Trap Flag support, when considering VECTORING events during another VMExit.No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/include/asm/x86-defns.h +0
-0@@ -204,4 +204,13 @@#define X86_MT_UCM 0x07/* UC- */ #define X86_NUM_MT 0x08
Quoted 10 lines
xen/arch/x86/include/asm/x86-defns.h line 214
Quoted 8 lines
xen/arch/x86/include/asm/x86-defns.h +8
-0+/* Event Types. */ +#define X86_ET_EXT_INTR 0/* External Interrupt */ +#define X86_ET_NMI 2/* NMI */ +#define X86_ET_HW_EXC 3/* Hardware Exception (#PF/#GP/etc) */ +#define X86_ET_SW_INT 4/* Software Interrupt (INT $n) */ +#define X86_ET_PRIV_SW_EXC 5/* Privileged Software Exception (ICEBP/INT1) */ +#define X86_ET_SW_EXC 6/* Software Exception (INT3, INTO) */ +#define X86_ET_OTHER 7/* Misc event: MTF=0, SYSCALL=1, SYSENTER=2 */ ET could of course mean a lot of things; sadly no sufficiently short but still less ambiguous alternative comes to mind, so ET is going to be it.
Yeah, I considered this quite a lot before settling on X86_ET_*. By coincidence, X86_MT_* are visible in context, so we do have prior art here.
~Andrew