x86: refactor trap handling code
v5 cover x86: refactor trap handling code
This series can also be found on my xenbits/xen.git wip.move-traps-v5
Wei Liu (13):
x86: move callback_op code to pv/callback.c
x86: move the compat callback ops next to the non-compat variant
x86: move do_set_trap_table to pv/callback.c
x86: move compat_set_trap_table along side the non-compat variant
x86: remove the now empty x86_64/compat/traps.c
x86: simplify guest_has_trap_callback
x86/traps: simplify and rename send_guest_trap x86/traps: factor out pv_trap_init
xen: move do_nmi_op and make it x86 only
x86/traps: move {un,}register_guest_nmi_callback to pv/callback.c x86/callback.c: slightly change {un,}register_guest_nmi_callback x86/traps: move some PV specific functions to pv/traps.c x86/traps.h: remove unused declaration of cpu_user_regs
xen/arch/x86/cpu/mcheck/vmce.c | 11 +- xen/arch/x86/irq.c | 9 +- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/oprofile/nmi_int.c | 2 +- xen/arch/x86/pv/Makefile | 1 + xen/arch/x86/pv/callback.c | 510 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/pv/traps.c | 104 ++++++++ xen/arch/x86/traps.c | 198 +------------- xen/arch/x86/x86_64/compat/traps.c | 202 --------------- xen/arch/x86/x86_64/entry.S | 4 + xen/arch/x86/x86_64/traps.c | 152 +---------- xen/common/compat/kernel.c | 5 - xen/common/kernel.c | 26 -- xen/include/asm-arm/nmi.h | 15 -- xen/include/asm-x86/nmi.h | 15 -- xen/include/asm-x86/pv/traps.h | 12 + xen/include/asm-x86/traps.h | 25 -- xen/include/xen/nmi.h | 14 - 18 files changed, 654 insertions(+), 653 deletions(-) create mode 100644 xen/arch/x86/pv/callback.c delete mode 100644 xen/arch/x86/x86_64/compat/traps.c delete mode 100644 xen/include/asm-arm/nmi.h delete mode 100644 xen/include/xen/nmi.h
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v5 1/13 x86: move callback_op code to pv/callback.c
Take the chance to change v to curr.
--- xen/arch/x86/pv/Makefile | 1 + xen/arch/x86/pv/callback.c | 183 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/traps.c | 148 ----------------------------------- 3 files changed, 184 insertions(+), 148 deletions(-) create mode 100644 xen/arch/x86/pv/callback.c
xen/arch/x86/pv/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-y += hypercall.o obj-y += traps.o +obj-y += callback.o obj-bin-y += dom0_build.init.o obj-y += domain.o obj-y += emulate.o
xen/arch/x86/pv/callback.c new file +183 -0
183 lines not on this page · raw message
xen/arch/x86/x86_64/traps.c +0 -148
160 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 01/13] x86: move callback_op code to pv/callback.c
Quoted 3 lines · Wei Liu
Take the chance to change v to curr.
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 01/13] x86: move callback_op code to pv/callback.c
In reply to Wei LiuQuoted 11 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/pv/Makefile +0
-0@@ -1,6 +1,7 @@obj-y += hypercall.o
obj-y += traps.o+obj-y += callback.o
obj-bin-y += dom0_build.init.o
obj-y += domain.o
obj-y += emulate.o
Not something to be dealt with in this patch, but - is there a reason we have two groups of object files here? I see none, and hence would have expected this to be a single sorted list instead of two.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 01/13] x86: move callback_op code to pv/callback.c
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/pv/Makefile +0
-0@@ -1,6 +1,7 @@obj-y += hypercall.o
obj-y += traps.o
Quoted 9 lines
Quoted 4 lines
+obj-y += callback.o
obj-bin-y += dom0_build.init.o
obj-y += domain.o
obj-y += emulate.oNot something to be dealt with in this patch, but - is there a reason we have two groups of object files here? I see none, and hence would have expected this to be a single sorted list instead of two.
No. It just so happened I added a newline at some point.
I will submit a patch to fix this at some point.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 01/13] x86: move callback_op code to pv/callback.c
Quoted 13 lines · Wei Liu
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/pv/Makefile +0
-0@@ -1,6 +1,7 @@obj-y += hypercall.o
obj-y += traps.o+obj-y += callback.o
obj-bin-y += dom0_build.init.o
obj-y += domain.o
obj-y += emulate.o
Quoted 7 lines
Quoted 4 lines
Not something to be dealt with in this patch, but - is there a reason we have two groups of object files here? I see none, and hence would have expected this to be a single sorted list instead of two.
No. It just so happened I added a newline at some point.
I will submit a patch to fix this at some point.
I'd suggest splitting the obj-y and obj-bin-y lists, as it will make the Makefile easier to read. That appears to have been the original intention behind the space in the first place.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 01/13] x86: move callback_op code to pv/callback.c
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Wei Liu
Quoted 16 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/pv/Makefile +0
-0@@ -1,6 +1,7 @@obj-y += hypercall.o
obj-y += traps.o+obj-y += callback.o
obj-bin-y += dom0_build.init.o
obj-y += domain.o
obj-y += emulate.oNot something to be dealt with in this patch, but - is there a reason we have two groups of object files here? I see none, and hence would have expected this to be a single sorted list instead of two.
Quoted 8 lines
Quoted 3 lines
No. It just so happened I added a newline at some point.
I will submit a patch to fix this at some point.
I'd suggest splitting the obj-y and obj-bin-y lists, as it will make the
Makefileeasier to read. That appears to have been the original intention behind the space in the first place.
That's a good suggestion.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 2/13 x86: move the compat callback ops next to the non-compat variant
In reply to Wei LiuTake the chance to change v to curr.
--- xen/arch/x86/pv/callback.c | 142 ++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/traps.c | 143 ------------------------------------- 2 files changed, 142 insertions(+), 143 deletions(-)
xen/arch/x86/pv/callback.c +142 -0
@@ -19,6 +19,7 @@#include <xen/guest_access.h> #include <xen/lib.h> #include <xen/sched.h> +#include <compat/callback.h> #include <asm/current.h> #include <asm/nmi.h>
@@ -172,6 +173,147 @@ long do_set_callbacks(unsigned long event_address,return 0 ; } +static long compat_register_guest_callback (struct compat_callback_register *reg) +{ +long ret =0 ; +struct vcpu *curr = current; + +fixup_guest_code_selector (curr->domain, reg->address.cs); + +switch ( reg->type ) + { +case CALLBACKTYPE_event: + curr->arch.pv_vcpu.event_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.event_callback_eip = reg->address.eip; +break ; + +case CALLBACKTYPE_failsafe: + curr->arch.pv_vcpu.failsafe_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip; +if ( reg->flags & CALLBACKF_mask_events ) +set_bit (_VGCF_failsafe_disables_events, + &curr->arch.vgc_flags); +else +clear_bit (_VGCF_failsafe_disables_events, + &curr->arch.vgc_flags); +break ; + +case CALLBACKTYPE_syscall32: + curr->arch.pv_vcpu.syscall32_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.syscall32_callback_eip = reg->address.eip; + curr->arch.pv_vcpu.syscall32_disables_events = + (reg->flags & CALLBACKF_mask_events) !=0 ; +break ; + +case CALLBACKTYPE_sysenter: + curr->arch.pv_vcpu.sysenter_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.sysenter_callback_eip = reg->address.eip; + curr->arch.pv_vcpu.sysenter_disables_events = + (reg->flags & CALLBACKF_mask_events) !=0 ; +break ; + +case CALLBACKTYPE_nmi: + ret =register_guest_nmi_callback (reg->address.eip); +break ; + +default : + ret = -ENOSYS ; +break ; + } + +return ret; +} + +static long compat_unregister_guest_callback ( +struct compat_callback_unregister *unreg) +{ +long ret; + +switch ( unreg->type ) + { +case CALLBACKTYPE_event: +case CALLBACKTYPE_failsafe: +case CALLBACKTYPE_syscall32: +case CALLBACKTYPE_sysenter: + ret = -EINVAL ; +break ; + +case CALLBACKTYPE_nmi: + ret =unregister_guest_nmi_callback (); +break ; + +default : + ret = -ENOSYS ; +break ; + } + +return ret; +} + +long compat_callback_op (int cmd,XEN_GUEST_HANDLE (void ) arg) +{ +long ret; + +switch ( cmd ) + { +case CALLBACKOP_register: + { +struct compat_callback_register reg; + + ret = -EFAULT ; +if (copy_from_guest (®, arg,1 ) ) +break ; + + ret =compat_register_guest_callback (®); + } +break ; + +case CALLBACKOP_unregister: + { +struct compat_callback_unregister unreg; + + ret = -EFAULT ; +if (copy_from_guest (&unreg, arg,1 ) ) +break ; + + ret =compat_unregister_guest_callback (&unreg); + } +break ; + +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +long compat_set_callbacks (unsigned long event_selector, +unsigned long event_address, +unsigned long failsafe_selector, +unsigned long failsafe_address) +{ +struct compat_callback_register event = { + .type = CALLBACKTYPE_event, + .address = { + .cs = event_selector, + .eip = event_address + } + }; +struct compat_callback_register failsafe = { + .type = CALLBACKTYPE_failsafe, + .address = { + .cs = failsafe_selector, + .eip = failsafe_address + } + }; + +compat_register_guest_callback (&event); +compat_register_guest_callback (&failsafe); + +return 0 ; +} +/* * Local variables: * mode: C
xen/arch/x86/x86_64/compat/traps.c +0 -143
149 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 02/13] x86: move the compat callback ops next to the non-compat variant
Quoted 3 lines · Wei Liu
Take the chance to change v to curr.
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 3/13 x86: move do_set_trap_table to pv/callback.c
In reply to Wei LiuThat hypercall is used to set guest callbacks for traps.
--- xen/arch/x86/pv/callback.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 50 ---------------------------------------------- 2 files changed, 50 insertions(+), 50 deletions(-)
xen/arch/x86/pv/callback.c +50 -0
@@ -16,6 +16,7 @@* License along with this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/event.h> #include <xen/guest_access.h> #include <xen/lib.h> #include <xen/sched.h>
@@ -314,6 +315,55 @@ long compat_set_callbacks(unsigned long event_selector,return 0 ; } +long do_set_trap_table (XEN_GUEST_HANDLE_PARAM (const_trap_info_t) traps) +{ +struct trap_info cur; +struct vcpu *curr = current; +struct trap_info *dst = curr->arch.pv_vcpu.trap_ctxt; +long rc =0 ; + +/* If no table is presented then clear the entire virtual IDT. */ +if (guest_handle_is_null (traps) ) + { +memset (dst,0 ,NR_VECTORS *sizeof (*dst)); +init_int80_direct_trap (curr); +return 0 ; + } + +for ( ; ; ) + { +if (copy_from_guest (&cur, traps,1 ) ) + { + rc = -EFAULT ; +break ; + } + +if ( cur.address ==0 ) +break ; + +if ( !is_canonical_address (cur.address) ) +return -EINVAL ; + +fixup_guest_code_selector (curr->domain, cur.cs); + +memcpy (&dst[cur.vector], &cur,sizeof (cur)); + +if ( cur.vector ==0x80 ) +init_int80_direct_trap (curr); + +guest_handle_add_offset (traps,1 ); + +if (hypercall_preempt_check () ) + { + rc =hypercall_create_continuation ( + __HYPERVISOR_set_trap_table,"h" , traps); +break ; + } + } + +return rc; +} +/* * Local variables: * mode: C
xen/arch/x86/traps.c +0 -50
56 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 03/13] x86: move do_set_trap_table to pv/callback.c
Quoted 3 lines · Wei Liu
That hypercall is used to set guest callbacks for traps.
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 4/13 x86: move compat_set_trap_table along side the non-compat variant
In reply to Wei Liu--- xen/arch/x86/pv/callback.c | 47 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/traps.c | 44 ----------------------------------- 2 files changed, 47 insertions(+), 44 deletions(-)
xen/arch/x86/pv/callback.c +47 -0
@@ -17,6 +17,7 @@*/ #include <xen/event.h> +#include <xen/hypercall.h> #include <xen/guest_access.h> #include <xen/lib.h> #include <xen/sched.h>
@@ -364,6 +365,52 @@ long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)return rc; } +int compat_set_trap_table (XEN_GUEST_HANDLE (trap_info_compat_t) traps) +{ +struct vcpu *curr = current; +struct compat_trap_info cur; +struct trap_info *dst = curr->arch.pv_vcpu.trap_ctxt; +long rc =0 ; + +/* If no table is presented then clear the entire virtual IDT. */ +if (guest_handle_is_null (traps) ) + { +memset (dst,0 ,NR_VECTORS *sizeof (*dst)); +init_int80_direct_trap (curr); +return 0 ; + } + +for ( ; ; ) + { +if (copy_from_guest (&cur, traps,1 ) ) + { + rc = -EFAULT ; +break ; + } + +if ( cur.address ==0 ) +break ; + +fixup_guest_code_selector (curr->domain, cur.cs); + +XLAT_trap_info (dst + cur.vector, &cur); + +if ( cur.vector ==0x80 ) +init_int80_direct_trap (curr); + +guest_handle_add_offset (traps,1 ); + +if (hypercall_preempt_check () ) + { + rc =hypercall_create_continuation ( + __HYPERVISOR_set_trap_table,"h" , traps); +break ; + } + } + +return rc; +} +/* * Local variables: * mode: C
xen/arch/x86/x86_64/compat/traps.c +0 -44
50 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 04/13] x86: move compat_set_trap_table along side the non-compat variant
Quoted 1 line · Wei Liu
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 5/13 x86: remove the now empty x86_64/compat/traps.c
In reply to Wei Liu--- xen/arch/x86/x86_64/compat/traps.c | 15 --------------- xen/arch/x86/x86_64/traps.c | 2 -- 2 files changed, 17 deletions(-) delete mode 100644 xen/arch/x86/x86_64/compat/traps.c
xen/arch/x86/x86_64/compat/traps.c deleted +0 -15
@@ -1,15 +0,0 @@ -#include <xen/event.h> -#include <asm/regs.h> -#include <compat/callback.h> -#include <compat/arch-x86_32.h> - - -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* tab-width: 4 -* indent-tabs-mode: nil -* End: -*/
xen/arch/x86/x86_64/traps.c +0 -2
@@ -335,8 +335,6 @@ void subarch_percpu_traps_init(void)wrmsrl (MSR_SYSCALL_MASK ,XEN_SYSCALL_MASK ); } -#include "compat/traps.c" -void hypercall_page_initialise (struct domain *d,void *hypercall_page) {memset (hypercall_page,0xCC ,PAGE_SIZE );
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 05/13] x86: remove the now empty x86_64/compat/traps.c
Quoted 1 line · Wei Liu
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 6/13 x86: simplify guest_has_trap_callback
In reply to Wei LiuThere is only one caller for that function. Simplify the function, move it close to the caller and rename it.
--- xen/arch/x86/cpu/mcheck/vmce.c | 11 ++++++++++- xen/arch/x86/traps.c | 18 ------------------ xen/include/asm-x86/traps.h | 8 -------- 3 files changed, 10 insertions(+), 27 deletions(-)
xen/arch/x86/cpu/mcheck/vmce.c +10 -1
@@ -359,6 +359,15 @@ static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)HVM_REGISTER_SAVE_RESTORE (VMCE_VCPU , vmce_save_vcpu_ctxt, vmce_load_vcpu_ctxt,1 ,HVMSR_PER_VCPU ); +static inline bool pv_callback_registered (const struct vcpu *v,uint8_t vector) +{ +#ifdef CONFIG_PV +return v->arch.pv_vcpu.trap_ctxt[vector].address; +#else +return false; +#endif +} +/* * for Intel MCE, broadcast vMCE to all vcpus * for AMD MCE, only inject vMCE to vcpu0
@@ -383,7 +392,7 @@ int inject_vmce(struct domain *d, int vcpu)continue ;if ( (is_hvm_domain (d) || -guest_has_trap_callback (d, v->vcpu_id, TRAP_machine_check)) && +pv_callback_registered (v, TRAP_machine_check)) && !test_and_set_bool (v->mce_pending) ) {mce_printk (MCE_VERBOSE ,"MCE: inject vMCE to %pv\n" , v);
xen/arch/x86/traps.c +0 -18
@@ -2008,24 +2008,6 @@ long unregister_guest_nmi_callback(void)return 0 ; } -int guest_has_trap_callback (struct domain *d,uint16_t vcpuid,unsigned int trap_nr) -{ -struct vcpu *v; -struct trap_info *t; - -BUG_ON (d ==NULL ); -BUG_ON (vcpuid >= d->max_vcpus); - -/* Sanity check - XXX should be more fine grained. */ -BUG_ON (trap_nr >=NR_VECTORS ); - - v = d->vcpu[vcpuid]; - t = &v->arch.pv_vcpu.trap_ctxt[trap_nr]; - -return (t->address !=0 ); -} - -int send_guest_trap (struct domain *d,uint16_t vcpuid,unsigned int trap_nr) {struct vcpu *v;
xen/include/asm-x86/traps.h +0 -8
@@ -29,14 +29,6 @@ struct cpu_user_regs;void async_exception_cleanup (struct vcpu *); -/** -* guest_has_trap_callback -* -* returns true (non-zero) if guest registered a trap handler -*/ -extern int guest_has_trap_callback (struct domain *d,uint16_t vcpuid, -unsigned int trap_nr); -/** * send_guest_trap *
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 06/13] x86: simplify guest_has_trap_callback
Quoted 4 lines · Wei Liu
There is only one caller for that function. Simplify the function, move it close to the caller and rename it.
Signed-off-by Wei Liu <[email protected]>
Good improvement. In principle, Reviewed-by: Andrew Cooper <[email protected]>, although...
Quoted 13 lines
--- xen/arch/x86/cpu/mcheck/vmce.c | 11 ++++++++++- xen/arch/x86/traps.c | 18 ------------------ xen/include/asm-x86/traps.h | 8 -------- 3 files changed, 10 insertions(+), 27 deletions(-)xen/arch/x86/cpu/mcheck/vmce.c +0
-0@@ -359,6 +359,15 @@ static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)HVM_REGISTER_SAVE_RESTORE (VMCE_VCPU , vmce_save_vcpu_ctxt, vmce_load_vcpu_ctxt,1 ,HVMSR_PER_VCPU );
xen/arch/x86/cpu/mcheck/vmce.c static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 370
Quoted 10 lines
xen/arch/x86/cpu/mcheck/vmce.c +9
-0+static inline bool pv_callback_registered (const struct vcpu *v,uint8_t vector) +{ +#ifdef CONFIG_PV +return v->arch.pv_vcpu.trap_ctxt[vector].address; +#else +return false; +#endif +} +
Isn't there a header file this would be better living in? Its certainly not vmce-specific.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 06/13] x86: simplify guest_has_trap_callback
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 06/26/17 6:58 PM >>>
Quoted 6 lines · Wei Liu
xen/arch/x86/cpu/mcheck/vmce.c +0
-0@@ -359,6 +359,15 @@ static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)HVM_REGISTER_SAVE_RESTORE (VMCE_VCPU , vmce_save_vcpu_ctxt, vmce_load_vcpu_ctxt,1 ,HVMSR_PER_VCPU );
Quoted 12 lines
xen/arch/x86/cpu/mcheck/vmce.c static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 370
Quoted 9 lines
xen/arch/x86/cpu/mcheck/vmce.c +9
-0+static inline bool pv_callback_registered (const struct vcpu *v,uint8_t vector) +{ +#ifdef CONFIG_PV +return v->arch.pv_vcpu.trap_ctxt[vector].address; +#else +return false; +#endif +} +Isn't there a header file this would be better living in? Its certainly not vmce-specific.
We certainly have the equivalent of this check in assembly code (which iirc we mean to convert to C eventually), so pv/traps.h would seem to be the right place. The function name would need to change a little though, as we're talking about exception callbacks here, not the things we call callbacks in the public interface. pv_trap_callback_registered() perhaps?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu
Reviewed-by Andrew CooperRe: [PATCH v5 06/13] x86: simplify guest_has_trap_callback
Quoted 21 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 06/26/17 6:58 PM >>>
Quoted 6 lines · Wei Liu
xen/arch/x86/cpu/mcheck/vmce.c +0
-0@@ -359,6 +359,15 @@ static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)HVM_REGISTER_SAVE_RESTORE (VMCE_VCPU , vmce_save_vcpu_ctxt, vmce_load_vcpu_ctxt,1 ,HVMSR_PER_VCPU );Quoted 12 lines
xen/arch/x86/cpu/mcheck/vmce.c static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 370
Quoted 9 lines
xen/arch/x86/cpu/mcheck/vmce.c +9
-0+static inline bool pv_callback_registered (const struct vcpu *v,uint8_t vector) +{ +#ifdef CONFIG_PV +return v->arch.pv_vcpu.trap_ctxt[vector].address; +#else +return false; +#endif +} +Isn't there a header file this would be better living in? Its certainly not vmce-specific.
Quoted 5 lines
We certainly have the equivalent of this check in assembly code (which iirc we mean to convert to C eventually), so
pv/traps.hwould seem to be the right place. The function name would need to change a little though, as we're talking about exception callbacks here, not the things we call callbacks in the public interface.pv_trap_callback_registered()perhaps?
I agree pv/traps.h is the right place and I've rename it to pv_trap_callback_registered.
I kept Andrew's Rb because those are just cosmetic changes.
---8<---
From d211f6a7aea2e8497bddf72df084f37588234e2d Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Fri, 23 Jun 2017 18:34:41 +0100
Subject: [PATCH] x86: simplify guest_has_trap_callback
Simplify that function, rename it to pv_trap_callback_registered and move it to pv/traps.h. Adjust vmce.c accordingly.
--- xen/arch/x86/cpu/mcheck/vmce.c | 3 ++- xen/arch/x86/traps.c | 18 ------------------ xen/include/asm-x86/pv/traps.h | 11 +++++++++++ xen/include/asm-x86/traps.h | 8 -------- 4 files changed, 13 insertions(+), 27 deletions(-)
xen/arch/x86/cpu/mcheck/vmce.c +2 -1
@@ -32,6 +32,7 @@#include <asm/system.h> #include <asm/msr.h> #include <asm/p2m.h> +#include <asm/pv/traps.h> #include "mce.h" #include "x86_mca.h"
@@ -383,7 +384,7 @@ int inject_vmce(struct domain *d, int vcpu)continue ;if ( (is_hvm_domain (d) || -guest_has_trap_callback (d, v->vcpu_id, TRAP_machine_check)) && +pv_trap_callback_registered (v, TRAP_machine_check)) && !test_and_set_bool (v->mce_pending) ) {mce_printk (MCE_VERBOSE ,"MCE: inject vMCE to %pv\n" , v);
xen/arch/x86/traps.c +0 -18
@@ -2008,24 +2008,6 @@ long unregister_guest_nmi_callback(void)return 0 ; } -int guest_has_trap_callback (struct domain *d,uint16_t vcpuid,unsigned int trap_nr) -{ -struct vcpu *v; -struct trap_info *t; - -BUG_ON (d ==NULL ); -BUG_ON (vcpuid >= d->max_vcpus); - -/* Sanity check - XXX should be more fine grained. */ -BUG_ON (trap_nr >=NR_VECTORS ); - - v = d->vcpu[vcpuid]; - t = &v->arch.pv_vcpu.trap_ctxt[trap_nr]; - -return (t->address !=0 ); -} - -int send_guest_trap (struct domain *d,uint16_t vcpuid,unsigned int trap_nr) {struct vcpu *v;
xen/include/asm-x86/pv/traps.h +11 -0
@@ -29,12 +29,23 @@ int pv_emulate_privileged_op(struct cpu_user_regs *regs);void pv_emulate_gate_op (struct cpu_user_regs *regs);bool pv_emulate_invalid_op (struct cpu_user_regs *regs); +static inline bool pv_trap_callback_registered (const struct vcpu *v, +uint8_t vector) +{ +return v->arch.pv_vcpu.trap_ctxt[vector].address; +} +#else /* !CONFIG_PV */ static inline int pv_emulate_privileged_op (struct cpu_user_regs *regs) {return 0 ; }static inline void pv_emulate_gate_op (struct cpu_user_regs *regs) {}static inline bool pv_emulate_invalid_op (struct cpu_user_regs *regs) {return true; } +static inline bool pv_trap_callback_registered (const struct vcpu *v, +uint8_t vector) +{ +return false; +}#endif /* CONFIG_PV */ #endif /* __X86_PV_TRAPS_H__ */
xen/include/asm-x86/traps.h +0 -8
@@ -29,14 +29,6 @@ struct cpu_user_regs;void async_exception_cleanup (struct vcpu *); -/** -* guest_has_trap_callback -* -* returns true (non-zero) if guest registered a trap handler -*/ -extern int guest_has_trap_callback (struct domain *d,uint16_t vcpuid, -unsigned int trap_nr); -/** * send_guest_trap *
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v5 7/13 x86/traps: simplify and rename send_guest_trap
In reply to Wei LiuRename it to pv_raise_interrupt. Simplify the code by using the vcpu structure already at hand in the caller.
--- xen/arch/x86/traps.c | 13 ++++--------- xen/include/asm-x86/pv/traps.h | 8 ++++++++ xen/include/asm-x86/traps.h | 9 --------- 3 files changed, 12 insertions(+), 18 deletions(-)
xen/arch/x86/traps.c +4 -9
@@ -1620,7 +1620,7 @@ static void nmi_hwdom_report(unsigned int reason_idx)set_bit (reason_idx,nmi_reason (d)); -send_guest_trap (d,0 , TRAP_nmi); +pv_raise_interrupt (d->vcpu[0 ], TRAP_nmi); }static void pci_serr_error (const struct cpu_user_regs *regs)
@@ -2008,21 +2008,16 @@ long unregister_guest_nmi_callback(void)return 0 ; } -int send_guest_trap (struct domain *d,uint16_t vcpuid,unsigned int trap_nr) +int pv_raise_interrupt (struct vcpu *v,uint8_t trap_nr) { -struct vcpu *v;struct softirq_trap *st = &per_cpu (softirq_trap,smp_processor_id ()); -BUG_ON (d ==NULL ); -BUG_ON (vcpuid >= d->max_vcpus); - v = d->vcpu[vcpuid]; -switch (trap_nr) {case TRAP_nmi:if (cmpxchgptr (&st->vcpu,NULL , v) )return -EBUSY ;if ( !test_and_set_bool (v->nmi_pending) ) { - st->domain = d; + st->domain = v->domain; st->processor = v->processor;/* not safe to wake up a vcpu here */
@@ -2040,7 +2035,7 @@ int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)* on the physical CPU that reported a machine check error. */ if ( !test_and_set_bool (v->mce_pending) ) { - st->domain = d; + st->domain = v->domain; st->processor = v->processor;/* not safe to wake up a vcpu here */
xen/include/asm-x86/pv/traps.h +8 -0
@@ -25,12 +25,20 @@#include <public/xen.h> +/* Deliver interrupt to PV guest. Return 0 on success. */ +int pv_raise_interrupt (struct vcpu *v,uint8_t vector); +int pv_emulate_privileged_op (struct cpu_user_regs *regs);void pv_emulate_gate_op (struct cpu_user_regs *regs);bool pv_emulate_invalid_op (struct cpu_user_regs *regs);#else /* !CONFIG_PV */ +#include <xen/errno.h> + +/* Deliver interrupt to PV guest. Return 0 on success. */ +static int pv_raise_interrupt (struct vcpu *v,uint8_t vector) {return -EOPNOTSUPP ; } +static inline int pv_emulate_privileged_op (struct cpu_user_regs *regs) {return 0 ; }static inline void pv_emulate_gate_op (struct cpu_user_regs *regs) {}static inline bool pv_emulate_invalid_op (struct cpu_user_regs *regs) {return true; }
xen/include/asm-x86/traps.h +0 -9
@@ -28,15 +28,6 @@ struct softirq_trap {struct cpu_user_regs ;void async_exception_cleanup (struct vcpu *); - -/** -* send_guest_trap -* -* delivers trap to guest analogous to send_guest_global_virq -* return 0 on successful delivery -*/ -extern int send_guest_trap (struct domain *d,uint16_t vcpuid, -unsigned int trap_nr);uint32_t guest_io_read (unsigned int port,unsigned int bytes,struct domain *);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 07/13] x86/traps: simplify and rename send_guest_trap
Quoted 2 lines · Wei Liu
Rename it to
pv_raise_interrupt. Simplify the code by using the vcpu structure already at hand in the caller.
double space.
Quoted 2 lines
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 07/13] x86/traps: simplify and rename send_guest_trap
In reply to Wei LiuQuoted 2 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
Rename it to
pv_raise_interrupt.
Is "interrupt" really a suitable term here? These are all exceptions being raised, not (external) interrupts.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 07/13] x86/traps: simplify and rename send_guest_trap
Quoted 4 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
Rename it to
pv_raise_interrupt.Is "interrupt" really a suitable term here? These are all exceptions being raised, not (external) interrupts.
This function is really NMIs and MCEs only, and it only gets used for the former. (on a technicality, NMIs are classified as Interrupts rather than Exceptions).
Furthermore, it is only actually used for latching an NMI as pending with dom0 from NMI context. MCEs take a different path.
I've been considering whether this mechanism can be done any better. I expect it can, but I haven't got a better plan yet.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 8/13 x86/traps: factor out pv_trap_init
In reply to Wei LiuFactor out pv_trap_init and call it at the beginning of trap_init. We then need to tune the code to generate stub handlers in entry.S. Take the chance to tune init_irq_data so that 0x80 and 0x82 can be used in !CONFIG_PV case.
While at it, fix some coding style issues in init_irq_data and replace 0x80 with LEGACY_SYSCALL_VECTOR in pv_trap_init.
--- xen/arch/x86/irq.c | 9 ++++++--- xen/arch/x86/traps.c | 23 +++++++++++++++-------- xen/arch/x86/x86_64/entry.S | 4 ++++ xen/include/asm-x86/pv/traps.h | 4 ++++ 4 files changed, 29 insertions(+), 11 deletions(-)
xen/arch/x86/irq.c +6 -3
@@ -350,7 +350,7 @@ int __init init_irq_data(void)struct irq_desc *desc;int irq, vector; -for (vector =0 ; vector <NR_VECTORS ; ++vector) +for ( vector =0 ; vector <NR_VECTORS ; ++vector )this_cpu (vector_irq)[vector] =INT_MIN ; irq_desc = xzalloc_array(struct irq_desc, nr_irqs);
@@ -358,17 +358,20 @@ int __init init_irq_data(void)if ( !irq_desc )return -ENOMEM ; -for (irq =0 ; irq < nr_irqs_gsi; irq++) { +for ( irq =0 ; irq < nr_irqs_gsi; irq++ ) + { desc =irq_to_desc (irq); desc->irq = irq;init_one_irq_desc (desc); } -for (; irq < nr_irqs; irq++) +for ( ; irq < nr_irqs; irq++ )irq_to_desc (irq)->irq = irq; +#ifdef CONFIG_PV /* Never allocate the hypercall vector or Linux/BSD fast-trap vector. */ set_bit (LEGACY_SYSCALL_VECTOR , used_vectors);set_bit (HYPERCALL_VECTOR , used_vectors); +#endif /* IRQ_MOVE_CLEANUP_VECTOR used for clean up vectors */ set_bit (IRQ_MOVE_CLEANUP_VECTOR , used_vectors);
xen/arch/x86/traps.c +15 -8
@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)this_cpu (compat_gdt_table) = boot_cpu_compat_gdt_table; } +void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ +_set_gate (idt_table +HYPERCALL_VECTOR , + SYS_DESC_trap_gate,1 , entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ +_set_gate (idt_table +LEGACY_SYSCALL_VECTOR , SYS_DESC_trap_gate,3 , + &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +} +extern void (*const autogen_entrypoints[NR_VECTORS ])(void );void __init trap_init (void ) {unsigned int vector; +pv_trap_init (); +/* Replace early pagefault with real pagefault handler. */ set_intr_gate (TRAP_page_fault, &page_fault); -/* The 32-on-64 hypercall vector is only accessible from ring 1. */ -_set_gate (idt_table +HYPERCALL_VECTOR , - SYS_DESC_trap_gate,1 , entry_int82); - -/* Fast trap for int80 (faster than taking the #GP-fixup path). */ -_set_gate (idt_table +0x80 , SYS_DESC_trap_gate,3 , &int80_direct_trap); -for ( vector =0 ; vector <NR_VECTORS ; ++vector ) {if ( autogen_entrypoints[vector] )
@@ -1968,7 +1976,6 @@ void __init trap_init(void)cpu_init (); -open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq);open_softirq (PCI_SERR_SOFTIRQ , pci_serr_softirq); }
xen/arch/x86/x86_64/entry.S +4 -0
@@ -706,7 +706,11 @@ autogen_stubs: /* Automatically generated stubs. */ .rept NR_VECTORS /* Common interrupts, heading towards do_IRQ(). */ +#ifdef CONFIG_PV .if vec >= FIRST_DYNAMIC_VECTOR && vec != HYPERCALL_VECTOR && vec != LEGACY_SYSCALL_VECTOR +#else + .if vec >= FIRST_DYNAMIC_VECTOR +#endif ALIGN 1: pushq $0
xen/include/asm-x86/pv/traps.h +4 -0
@@ -25,6 +25,8 @@#include <public/xen.h> +void pv_trap_init (void ); +/* Deliver interrupt to PV guest. Return 0 on success. */ int pv_raise_interrupt (struct vcpu *v,uint8_t vector);
@@ -36,6 +38,8 @@ bool pv_emulate_invalid_op(struct cpu_user_regs *regs);#include <xen/errno.h> +static inline void pv_trap_init (void ) {} +/* Deliver interrupt to PV guest. Return 0 on success. */ static int pv_raise_interrupt (struct vcpu *v,uint8_t vector) {return -EOPNOTSUPP ; }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 08/13] x86/traps: factor out pv_trap_init
Quoted 4 lines · Wei Liu
Factor out
pv_trap_initand call it at the beginning oftrap_init. We then need to tune the code to generate stub handlers inentry.S. Take the chance to tuneinit_irq_dataso that0x80and0x82can be used in !CONFIG_PV case.
"used for regular interrupts in ..." ?
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1940
Quoted 12 lines
xen/arch/x86/traps.c +4
-0@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)this_cpu (compat_gdt_table) = boot_cpu_compat_gdt_table; } +void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ + _set_gate(idt_table + HYPERCALL_VECTOR,
&idt_table[HYPERCALL_VECTOR]
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1944
Quoted 4 lines
xen/arch/x86/traps.c +4
-0+ SYS_DESC_trap_gate, 1, entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ + _set_gate(idt_table + LEGACY_SYSCALL_VECTOR, SYS_DESC_trap_gate, 3,
&idt_table[LEGACY_SYSCALL_VECTOR]
Otherwise, Reivewed-by: Andrew Cooper <[email protected]>
Quoted 15 lines
xen/arch/x86/traps.c +7
-0+ &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +} +extern void (*const autogen_entrypoints[NR_VECTORS ])(void );void __init trap_init (void ) {unsigned int vector; +pv_trap_init (); +/* Replace early pagefault with real pagefault handler. */ set_intr_gate (TRAP_page_fault, &page_fault);
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1962
Quoted 10 lines
xen/arch/x86/traps.c +0
-7-/* The 32-on-64 hypercall vector is only accessible from ring 1. */ -_set_gate (idt_table +HYPERCALL_VECTOR , - SYS_DESC_trap_gate,1 , entry_int82); - -/* Fast trap for int80 (faster than taking the #GP-fixup path). */ -_set_gate (idt_table +0x80 , SYS_DESC_trap_gate,3 , &int80_direct_trap); -for ( vector =0 ; vector <NR_VECTORS ; ++vector ) {if ( autogen_entrypoints[vector] )
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 08/13] x86/traps: factor out pv_trap_init
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 06/27/17 8:06 PM >>>
Quoted 6 lines · Wei Liu
xen/arch/x86/traps.c +0
-0@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)this_cpu (compat_gdt_table) = boot_cpu_compat_gdt_table; }
Quoted 6 lines
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1940
Quoted 4 lines
xen/arch/x86/traps.c +4
-0+void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ + _set_gate(idt_table + HYPERCALL_VECTOR,&idt_table[HYPERCALL_VECTOR]
I don't think we should require this. Personally I prefer the form Wei used, and iirc there's nothing in our coding style guidelines that mandates the form you suggest.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 08/13] x86/traps: factor out pv_trap_init
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 06/27/17 8:06 PM >>>
Quoted 6 lines · Wei Liu
xen/arch/x86/traps.c +0
-0@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)this_cpu (compat_gdt_table) = boot_cpu_compat_gdt_table; }
Quoted 8 lines
Quoted 5 lines
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1940
Quoted 4 lines
xen/arch/x86/traps.c +4
-0+void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ + _set_gate(idt_table + HYPERCALL_VECTOR,&idt_table[HYPERCALL_VECTOR]
I don't think we should require this. Personally I prefer the form Wei used, and iirc there's nothing in our coding style guidelines that mandates the form you suggest.
One form is obviously an array access, while one is not obvious.
I'm not overly fussed, but I would prefer the former.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 08/13] x86/traps: factor out pv_trap_init
In reply to Wei Liuxen/arch/x86/traps.c void __init init_idt_traps(void)
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/traps.c +0
-0@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)
>this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;
Quoted 4 lines
xen/arch/x86/traps.c +2
-0} +void __init pv_trap_init (void ) +{
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1948
Quoted 10 lines
xen/arch/x86/traps.c +10
-0+/* The 32-on-64 hypercall vector is only accessible from ring 1. */ +_set_gate (idt_table +HYPERCALL_VECTOR , + SYS_DESC_trap_gate,1 , entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ +_set_gate (idt_table +LEGACY_SYSCALL_VECTOR , SYS_DESC_trap_gate,3 , + &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +}
Any reason you don't move this into pv/traps.c right away?
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1952
Quoted 2 lines
xen/arch/x86/traps.c +0
-0void __init trap_init (void ) {
>unsigned int vector;
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1955
Quoted 2 lines
xen/arch/x86/traps.c +1
-0+pv_trap_init ();
I think this would better be called after ...
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1957
Quoted 1 line
xen/arch/x86/traps.c +0
-0/* Replace early pagefault with real pagefault handler. */
>set_intr_gate(TRAP_page_fault, &page_fault);
... this, i.e. in line with where most of the code was before.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 08/13] x86/traps: factor out pv_trap_init
Quoted 7 lines · Jan Beulich
xen/arch/x86/traps.c void __init init_idt_traps(void)
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/traps.c +0
-0@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)>this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;Quoted 2 lines
xen/arch/x86/traps.c +0
-0}
Quoted 14 lines
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1948
Quoted 12 lines
xen/arch/x86/traps.c +12
-0+void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ +_set_gate (idt_table +HYPERCALL_VECTOR , + SYS_DESC_trap_gate,1 , entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ +_set_gate (idt_table +LEGACY_SYSCALL_VECTOR , SYS_DESC_trap_gate,3 , + &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +}Any reason you don't move this into
pv/traps.cright away?
Because nmi_mce_softirq needs to be moved at the same time. That can't be undone until I refactor the code further in later patch(es).
Quoted 5 lines
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1952
Quoted 3 lines
xen/arch/x86/traps.c +0
-0void __init trap_init (void ) {>unsigned int vector;Quoted 1 line
Quoted 9 lines
Quoted 1 line
+
pv_trap_init();I think this would better be called after ...
Quoted 1 line
/* Replace early pagefault with real pagefault handler. */
>set_intr_gate(TRAP_page_fault, &page_fault);... this, i.e. in line with where most of the code was before.
NP.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 08/13] x86/traps: factor out pv_trap_init
Quoted 23 lines · Wei Liu
Quoted 7 lines · Jan Beulich
xen/arch/x86/traps.c void __init init_idt_traps(void)
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
xen/arch/x86/traps.c +0
-0@@ -1934,21 +1934,29 @@ void __init init_idt_traps(void)>this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;Quoted 2 lines
xen/arch/x86/traps.c +0
-0}Quoted 14 lines
xen/arch/x86/traps.c void __init init_idt_traps(void) · line 1948
Quoted 12 lines
xen/arch/x86/traps.c +12
-0+void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ +_set_gate (idt_table +HYPERCALL_VECTOR , + SYS_DESC_trap_gate,1 , entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ +_set_gate (idt_table +LEGACY_SYSCALL_VECTOR , SYS_DESC_trap_gate,3 , + &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +}Any reason you don't move this into
pv/traps.cright away?
Quoted 2 lines
Because
nmi_mce_softirqneeds to be moved at the same time. That can't be undone until I refactor the code further in later patch(es).
undone -> done
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 9/13 xen: move do_nmi_op and make it x86 only
In reply to Wei LiuSince ARM doesn't need do_nmi_op, move the hypercall handler from common/kernel.c to pv/callback.c. Drop the stubs in ARM. Delete the common and ARM nmi.h and adjust header inclusions in various files.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
ARM build test passed.
--- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/oprofile/nmi_int.c | 2 +- xen/arch/x86/pv/callback.c | 49 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/traps.c | 2 +- xen/common/compat/kernel.c | 5 ----- xen/common/kernel.c | 26 ---------------------- xen/include/asm-arm/nmi.h | 15 ------------- xen/include/xen/nmi.h | 14 ------------ 9 files changed, 53 insertions(+), 64 deletions(-) delete mode 100644 xen/include/asm-arm/nmi.h delete mode 100644 xen/include/xen/nmi.h
xen/arch/x86/nmi.c +1 -1
@@ -17,7 +17,6 @@#include <xen/lib.h> #include <xen/mm.h> #include <xen/irq.h> -#include <xen/nmi.h> #include <xen/delay.h> #include <xen/time.h> #include <xen/sched.h>
@@ -29,6 +28,7 @@#include <asm/mc146818rtc.h> #include <asm/msr.h> #include <asm/mpspec.h> +#include <asm/nmi.h> #include <asm/debugger.h> #include <asm/div64.h> #include <asm/apic.h>
xen/arch/x86/oprofile/nmi_int.c +1 -1
@@ -15,7 +15,6 @@#include <xen/types.h> #include <xen/errno.h> #include <xen/init.h> -#include <xen/nmi.h> #include <xen/string.h> #include <xen/delay.h> #include <xen/xenoprof.h>
@@ -24,6 +23,7 @@#include <asm/apic.h> #include <asm/regs.h> #include <asm/current.h> +#include <asm/nmi.h> #include "op_counter.h" #include "op_x86_model.h"
xen/arch/x86/pv/callback.c +49 -0
61 lines not on this page · raw message
xen/arch/x86/traps.c +1 -1
@@ -43,7 +43,6 @@#include <xen/domain_page.h> #include <xen/symbols.h> #include <xen/iocap.h> -#include <xen/nmi.h> #include <xen/version.h> #include <xen/kexec.h> #include <xen/trace.h>
@@ -64,6 +63,7 @@#include <asm/xstate.h> #include <asm/debugger.h> #include <asm/msr.h> +#include <asm/nmi.h> #include <asm/shared.h> #include <asm/x86_emulate.h> #include <asm/traps.h>
xen/arch/x86/x86_64/traps.c +1 -1
@@ -10,7 +10,6 @@#include <xen/console.h> #include <xen/sched.h> #include <xen/shutdown.h> -#include <xen/nmi.h> #include <xen/guest_access.h> #include <xen/watchdog.h> #include <xen/hypercall.h>
@@ -18,6 +17,7 @@#include <asm/flushtlb.h> #include <asm/traps.h> #include <asm/event.h> +#include <asm/nmi.h> #include <asm/msr.h> #include <asm/page.h> #include <asm/shared.h>
xen/common/compat/kernel.c +0 -5
@@ -9,11 +9,9 @@ asm(".file \"" __FILE__ "\"");#include <xen/errno.h> #include <xen/version.h> #include <xen/sched.h> -#include <xen/nmi.h> #include <xen/guest_access.h> #include <asm/current.h> #include <compat/xen.h> -#include <compat/nmi.h> #include <compat/version.h> extern xen_commandline_t saved_cmdline;
@@ -39,9 +37,6 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); -#define xennmi_callback compat_nmi_callback -#define xennmi_callback_t compat_nmi_callback_t -#ifdef COMPAT_VM_ASSIST_VALID #undef VM_ASSIST_VALID#define VM_ASSIST_VALID COMPAT_VM_ASSIST_VALID
xen/common/kernel.c +0 -26
@@ -10,12 +10,10 @@#include <xen/version.h> #include <xen/sched.h> #include <xen/paging.h> -#include <xen/nmi.h> #include <xen/guest_access.h> #include <xen/hypercall.h> #include <xsm/xsm.h> #include <asm/current.h> -#include <public/nmi.h> #include <public/version.h> #ifndef COMPAT
@@ -431,30 +429,6 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } -DO (nmi_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) -{ -struct xennmi_callback cb; -long rc =0 ; - -switch ( cmd ) - { -case XENNMI_register_callback: - rc = -EFAULT ; -if (copy_from_guest (&cb, arg,1 ) ) -break ; - rc =register_guest_nmi_callback (cb.handler_address); -break ; -case XENNMI_unregister_callback: - rc =unregister_guest_nmi_callback (); -break ; -default : - rc = -ENOSYS ; -break ; - } - -return rc; -} -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {
xen/include/asm-arm/nmi.h deleted +0 -15
@@ -1,15 +0,0 @@ -#ifndef ASM_NMI_H -#define ASM_NMI_H - -#define register_guest_nmi_callback (a) (-ENOSYS) -#define unregister_guest_nmi_callback () (-ENOSYS) - -#endif /* ASM_NMI_H */ -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* indent-tabs-mode: nil -* End: -*/
xen/include/xen/nmi.h deleted +0 -14
@@ -1,14 +0,0 @@ -/****************************************************************************** -* nmi.h -* -* Register and unregister NMI callbacks. -* -* Copyright (c) 2006, Ian Campbell <[email protected]> -*/ - -#ifndef __XEN_NMI_H__ -#define __XEN_NMI_H__ - -#include <asm/nmi.h> - -#endif /* __XEN_NMI_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 09/13] xen: move do_nmi_op and make it x86 only
Quoted 5 lines · Wei Liu
Since ARM doesn't need
do_nmi_op, move the hypercall handler fromcommon/kernel.ctopv/callback.c. Drop the stubs in ARM. Delete the common and ARMnmi.hand adjust header inclusions in various files.Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 09/13] xen: move do_nmi_op and make it x86 only
In reply to Wei LiuQuoted 3 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
Since ARM doesn't need
do_nmi_op, move the hypercall handler fromcommon/kernel.ctopv/callback.c.
There are two handlers you actually move, and while their neither large nor likely to change, I still somewhat dislike the code duplication you introduce. But I guess not enough to put under question the R-b you've already got from Andrew.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 09/13] xen: move do_nmi_op and make it x86 only
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
Since ARM doesn't need
do_nmi_op, move the hypercall handler fromcommon/kernel.ctopv/callback.c.There are two handlers you actually move, and while their neither large nor likely to change, I still somewhat dislike the code duplication you introduce. But I guess not enough to put under question the R-b you've already got from Andrew.
If its not obvious already, I am taking a strong stance against any code obfuscation, because obfuscation the source code is entirely detrimental to the project.
Macros such as DO() fall into the obfuscation category, so I will support all changes which reduce/remove its usage.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 09/13] xen: move do_nmi_op and make it x86 only
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:29 PM >>>
Since ARM doesn't need
do_nmi_op, move the hypercall handler fromcommon/kernel.ctopv/callback.c.There are two handlers you actually move, and while their neither large nor likely to change, I still somewhat dislike the code duplication you introduce. But I guess not enough to put under question the R-b you've already got from Andrew.
I'm with Andrew here. I deliberately unrolled all macros because the resulting code is cleaner.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 09/13] xen: move do_nmi_op and make it x86 only
In reply to Wei LiuQuoted 5 lines · Wei Liu
Since ARM doesn't need
do_nmi_op, move the hypercall handler fromcommon/kernel.ctopv/callback.c. Drop the stubs in ARM. Delete the common and ARMnmi.hand adjust header inclusions in various files.Signed-off-by Wei Liu <[email protected]>
Quoted 286 lines
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>ARM build test passed.
--- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/oprofile/nmi_int.c | 2 +- xen/arch/x86/pv/callback.c | 49 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/traps.c | 2 +- xen/common/compat/kernel.c | 5 ----- xen/common/kernel.c | 26 ---------------------- xen/include/asm-arm/nmi.h | 15 ------------- xen/include/xen/nmi.h | 14 ------------ 9 files changed, 53 insertions(+), 64 deletions(-) delete mode 100644 xen/include/asm-arm/nmi.h delete mode 100644 xen/include/xen/nmi.hxen/arch/x86/nmi.c +1
-1@@ -17,7 +17,6 @@#include <xen/lib.h> #include <xen/mm.h> #include <xen/irq.h> -#include <xen/nmi.h> #include <xen/delay.h> #include <xen/time.h> #include <xen/sched.h> @@ -29,6 +28,7 @@#include <asm/mc146818rtc.h> #include <asm/msr.h> #include <asm/mpspec.h> +#include <asm/nmi.h> #include <asm/debugger.h> #include <asm/div64.h> #include <asm/apic.h> xen/arch/x86/oprofile/nmi_int.c +1
-1@@ -15,7 +15,6 @@#include <xen/types.h> #include <xen/errno.h> #include <xen/init.h> -#include <xen/nmi.h> #include <xen/string.h> #include <xen/delay.h> #include <xen/xenoprof.h> @@ -24,6 +23,7 @@#include <asm/apic.h> #include <asm/regs.h> #include <asm/current.h> +#include <asm/nmi.h> #include "op_counter.h" #include "op_x86_model.h" xen/arch/x86/pv/callback.c +49
-0@@ -22,6 +22,7 @@#include <xen/lib.h> #include <xen/sched.h> #include <compat/callback.h> +#include <compat/nmi.h> #include <asm/current.h> #include <asm/nmi.h> @@ -411,6 +412,54 @@ int compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)return rc; } +long do_nmi_op (unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +struct xennmi_callback cb; +long rc =0 ; + +switch ( cmd ) + { +case XENNMI_register_callback: + rc = -EFAULT ; +if (copy_from_guest (&cb, arg,1 ) ) +break ; + rc =register_guest_nmi_callback (cb.handler_address); +break ; +case XENNMI_unregister_callback: + rc =unregister_guest_nmi_callback (); +break ; +default : + rc = -ENOSYS ; +break ; + } + +return rc; +} + +int compat_nmi_op (unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +struct compat_nmi_callback cb; +int rc =0 ; + +switch ( cmd ) + { +case XENNMI_register_callback: + rc = -EFAULT ; +if (copy_from_guest (&cb, arg,1 ) ) +break ; + rc =register_guest_nmi_callback (cb.handler_address); +break ; +case XENNMI_unregister_callback: + rc =unregister_guest_nmi_callback (); +break ; +default : + rc = -ENOSYS ; +break ; + } + +return rc; +} +/* * Local variables: * mode: C xen/arch/x86/traps.c +1
-1@@ -43,7 +43,6 @@#include <xen/domain_page.h> #include <xen/symbols.h> #include <xen/iocap.h> -#include <xen/nmi.h> #include <xen/version.h> #include <xen/kexec.h> #include <xen/trace.h> @@ -64,6 +63,7 @@#include <asm/xstate.h> #include <asm/debugger.h> #include <asm/msr.h> +#include <asm/nmi.h> #include <asm/shared.h> #include <asm/x86_emulate.h> #include <asm/traps.h> xen/arch/x86/x86_64/traps.c +1
-1@@ -10,7 +10,6 @@#include <xen/console.h> #include <xen/sched.h> #include <xen/shutdown.h> -#include <xen/nmi.h> #include <xen/guest_access.h> #include <xen/watchdog.h> #include <xen/hypercall.h> @@ -18,6 +17,7 @@#include <asm/flushtlb.h> #include <asm/traps.h> #include <asm/event.h> +#include <asm/nmi.h> #include <asm/msr.h> #include <asm/page.h> #include <asm/shared.h> xen/common/compat/kernel.c +0
-5@@ -9,11 +9,9 @@ asm(".file \"" __FILE__ "\"");#include <xen/errno.h> #include <xen/version.h> #include <xen/sched.h> -#include <xen/nmi.h> #include <xen/guest_access.h> #include <asm/current.h> #include <compat/xen.h> -#include <compat/nmi.h> #include <compat/version.h> extern xen_commandline_t saved_cmdline;@@ -39,9 +37,6 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); -#define xennmi_callback compat_nmi_callback -#define xennmi_callback_t compat_nmi_callback_t -#ifdef COMPAT_VM_ASSIST_VALID #undef VM_ASSIST_VALID#define VM_ASSIST_VALID COMPAT_VM_ASSIST_VALIDxen/common/kernel.c +0
-26@@ -10,12 +10,10 @@#include <xen/version.h> #include <xen/sched.h> #include <xen/paging.h> -#include <xen/nmi.h> #include <xen/guest_access.h> #include <xen/hypercall.h> #include <xsm/xsm.h> #include <asm/current.h> -#include <public/nmi.h> #include <public/version.h> #ifndef COMPAT @@ -431,30 +429,6 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } -DO (nmi_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) -{ -struct xennmi_callback cb; -long rc =0 ; - -switch ( cmd ) - { -case XENNMI_register_callback: - rc = -EFAULT ; -if (copy_from_guest (&cb, arg,1 ) ) -break ; - rc =register_guest_nmi_callback (cb.handler_address); -break ; -case XENNMI_unregister_callback: - rc =unregister_guest_nmi_callback (); -break ; -default : - rc = -ENOSYS ; -break ; - } - -return rc; -} -#ifdef VM_ASSIST_VALID DO (vm_assist)(unsigned int cmd,unsigned int type) {xen/include/asm-arm/nmi.h deleted +0
-15@@ -1,15 +0,0 @@ -#ifndef ASM_NMI_H -#define ASM_NMI_H - -#define register_guest_nmi_callback (a) (-ENOSYS) -#define unregister_guest_nmi_callback () (-ENOSYS) - -#endif /* ASM_NMI_H */ -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* indent-tabs-mode: nil -* End: -*/ xen/include/xen/nmi.h deleted +0
-14@@ -1,14 +0,0 @@ -/****************************************************************************** -* nmi.h -* -* Register and unregister NMI callbacks. -* -* Copyright (c) 2006, Ian Campbell <[email protected]> -*/ - -#ifndef __XEN_NMI_H__ -#define __XEN_NMI_H__ - -#include <asm/nmi.h> - -#endif /* __XEN_NMI_H__ */ Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 10/13 x86/traps: move {un, }register_guest_nmi_callback to pv/callback.c
In reply to Wei LiuMove these helper functions along side their users. Now all users of these functions are within the same file, make them static.
Take the chance to change v to curr and remove some unneeded parentheses.
--- xen/arch/x86/pv/callback.c | 37 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 36 ------------------------------------ xen/include/asm-x86/nmi.h | 15 --------------- 3 files changed, 37 insertions(+), 51 deletions(-)
xen/arch/x86/pv/callback.c +37 -0
@@ -26,10 +26,47 @@#include <asm/current.h> #include <asm/nmi.h> +#include <asm/shared.h> #include <asm/traps.h> #include <public/callback.h> +static long register_guest_nmi_callback (unsigned long address) +{ +struct vcpu *curr = current; +struct domain *d = curr->domain; +struct trap_info *t = &curr->arch.pv_vcpu.trap_ctxt[TRAP_nmi]; + +if ( !is_canonical_address (address) ) +return -EINVAL ; + + t->vector = TRAP_nmi; + t->flags =0 ; + t->cs = (is_pv_32bit_domain (d) ? +FLAT_COMPAT_KERNEL_CS :FLAT_KERNEL_CS ); + t->address = address; +TI_SET_IF (t,1 ); + +/* +* If no handler was registered we can 'lose the NMI edge'. Re-assert it +* now. +*/ +if ( curr->vcpu_id ==0 &&arch_get_nmi_reason (d) !=0 ) + curr->nmi_pending =1 ; + +return 0 ; +} + +static long unregister_guest_nmi_callback (void ) +{ +struct vcpu *curr = current; +struct trap_info *t = &curr->arch.pv_vcpu.trap_ctxt[TRAP_nmi]; + +memset (t,0 ,sizeof (*t)); + +return 0 ; +} +static long register_guest_callback (struct callback_register *reg) {long ret =0 ;
xen/arch/x86/traps.c +0 -36
@@ -1979,42 +1979,6 @@ void __init trap_init(void)open_softirq (PCI_SERR_SOFTIRQ , pci_serr_softirq); } -long register_guest_nmi_callback (unsigned long address) -{ -struct vcpu *v = current; -struct domain *d = v->domain; -struct trap_info *t = &v->arch.pv_vcpu.trap_ctxt[TRAP_nmi]; - -if ( !is_canonical_address (address) ) -return -EINVAL ; - - t->vector = TRAP_nmi; - t->flags =0 ; - t->cs = (is_pv_32bit_domain (d) ? -FLAT_COMPAT_KERNEL_CS :FLAT_KERNEL_CS ); - t->address = address; -TI_SET_IF (t,1 ); - -/* -* If no handler was registered we can 'lose the NMI edge'. Re-assert it -* now. -*/ -if ( (v->vcpu_id ==0 ) && (arch_get_nmi_reason (d) !=0 ) ) - v->nmi_pending =1 ; - -return 0 ; -} - -long unregister_guest_nmi_callback (void ) -{ -struct vcpu *v = current; -struct trap_info *t = &v->arch.pv_vcpu.trap_ctxt[TRAP_nmi]; - -memset (t,0 ,sizeof (*t)); - -return 0 ; -} -int pv_raise_interrupt (struct vcpu *v,uint8_t trap_nr) {struct softirq_trap *st = &per_cpu (softirq_trap,smp_processor_id ());
xen/include/asm-x86/nmi.h +0 -15
@@ -29,19 +29,4 @@ nmi_callback_t *set_nmi_callback(nmi_callback_t *callback);*/ void unset_nmi_callback (void ); -/** -* register_guest_nmi_callback -* -* The default NMI handler passes the NMI to a guest callback. This -* function registers the address of that callback. -*/ -long register_guest_nmi_callback (unsigned long address); - -/** -* unregister_guest_nmi_callback -* -* Unregister a guest NMI handler. -*/ -long unregister_guest_nmi_callback (void ); -#endif /* ASM_NMI_H */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 10/13] x86/traps: move {un, }register_guest_nmi_callback to pv/callback.c
Quoted 7 lines · Wei Liu
Move these helper functions along side their users. Now all users of these functions are within the same file, make them static.
Take the chance to change v to curr and remove some unneeded parentheses.
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 11/13 x86/callback.c: slightly change {un, }register_guest_nmi_callback
In reply to Wei LiuMake register_guest_nmi_callback return int and make unregister_guest_nmi_callback void. Adjust the callers where necessary.
---
Can be squashed into previous patch.
--- xen/arch/x86/pv/callback.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
xen/arch/x86/pv/callback.c +10 -8
@@ -31,7 +31,7 @@#include <public/callback.h> -static long register_guest_nmi_callback (unsigned long address) +static int register_guest_nmi_callback (unsigned long address) {struct vcpu *curr = current;struct domain *d = curr->domain;
@@ -57,14 +57,12 @@ static long register_guest_nmi_callback(unsigned long address)return 0 ; } -static long unregister_guest_nmi_callback (void ) +static void unregister_guest_nmi_callback (void ) {struct vcpu *curr = current;struct trap_info *t = &curr->arch.pv_vcpu.trap_ctxt[TRAP_nmi];memset (t,0 ,sizeof (*t)); - -return 0 ; }static long register_guest_callback (struct callback_register *reg)
@@ -140,7 +138,8 @@ static long unregister_guest_callback(struct callback_unregister *unreg)break ;case CALLBACKTYPE_nmi: - ret =unregister_guest_nmi_callback (); +unregister_guest_nmi_callback (); + ret =0 ;break ;default :
@@ -279,7 +278,8 @@ static long compat_unregister_guest_callback(break ;case CALLBACKTYPE_nmi: - ret =unregister_guest_nmi_callback (); +unregister_guest_nmi_callback (); + ret =0 ;break ;default :
@@ -463,7 +463,8 @@ long do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) rc =register_guest_nmi_callback (cb.handler_address);break ;case XENNMI_unregister_callback: - rc =unregister_guest_nmi_callback (); +unregister_guest_nmi_callback (); + rc =0 ;break ;default : rc = -ENOSYS ;
@@ -487,7 +488,8 @@ int compat_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) rc =register_guest_nmi_callback (cb.handler_address);break ;case XENNMI_unregister_callback: - rc =unregister_guest_nmi_callback (); +unregister_guest_nmi_callback (); + rc =0 ;break ;default : rc = -ENOSYS ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 11/13] x86/callback.c: slightly change {un, }register_guest_nmi_callback
Quoted 5 lines · Wei Liu
Make
register_guest_nmi_callbackreturn int and makeunregister_guest_nmi_callbackvoid. Adjust the callers where necessary.Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 12/13 x86/traps: move some PV specific functions to pv/traps.c
In reply to Wei LiuThose functions must be moved at the same time. Also move softirq_trap because it is only used there.
Fix some coding style issues while moving code.
--- xen/arch/x86/pv/traps.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 88 ------------------------------------- xen/include/asm-x86/traps.h | 6 --- 3 files changed, 104 insertions(+), 94 deletions(-)
xen/arch/x86/pv/traps.c +104 -0
@@ -19,9 +19,11 @@* Copyright (c) 2017 Citrix Systems Ltd. */ +#include <xen/event.h> #include <xen/hypercall.h> #include <xen/lib.h> #include <xen/trace.h> +#include <xen/softirq.h> #include <asm/apic.h> #include <asm/shared.h>
@@ -148,6 +150,108 @@ void init_int80_direct_trap(struct vcpu *v) tb->flags =TBF_EXCEPTION | (TI_GET_IF (ti) ?TBF_INTERRUPT :0 ); } +struct softirq_trap { +struct domain *domain;/* domain to inject trap */ +struct vcpu *vcpu;/* vcpu to inject trap */ +int processor;/* physical cpu to inject trap */ +}; + +static DEFINE_PER_CPU(struct softirq_trap, softirq_trap); + +static void nmi_mce_softirq (void ) +{ +int cpu =smp_processor_id (); +struct softirq_trap *st = &per_cpu (softirq_trap, cpu); + +BUG_ON (st->vcpu ==NULL ); + +/* +* Set the tmp value unconditionally, so that the check in the iret +* hypercall works. +*/ +cpumask_copy (st->vcpu->cpu_hard_affinity_tmp, + st->vcpu->cpu_hard_affinity); + +if ( (cpu != st->processor) || + (st->processor != st->vcpu->processor) ) + { + +/* +* We are on a different physical cpu. Make sure to wakeup the vcpu on +* the specified processor. +*/ +vcpu_set_hard_affinity (st->vcpu,cpumask_of (st->processor)); + +/* Affinity is restored in the iret hypercall. */ + } + +/* +* Only used to defer wakeup of domain/vcpu to a safe (non-NMI/MCE) +* context. +*/ +vcpu_kick (st->vcpu); + st->vcpu =NULL ; +} + +void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ +_set_gate (idt_table +HYPERCALL_VECTOR , + SYS_DESC_trap_gate,1 , entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ +_set_gate (idt_table +LEGACY_SYSCALL_VECTOR , SYS_DESC_trap_gate,3 , + &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +} + +int pv_raise_interrupt (struct vcpu *v,uint8_t trap_nr) +{ +struct softirq_trap *st = &per_cpu (softirq_trap,smp_processor_id ()); + +switch ( trap_nr ) + { +case TRAP_nmi: +if (cmpxchgptr (&st->vcpu,NULL , v) ) +return -EBUSY ; +if ( !test_and_set_bool (v->nmi_pending) ) + { + st->domain = v->domain; + st->processor = v->processor; + +/* Not safe to wake up a vcpu here */ +raise_softirq (NMI_MCE_SOFTIRQ ); +return 0 ; + } + st->vcpu =NULL ; +break ; + +case TRAP_machine_check: +if (cmpxchgptr (&st->vcpu,NULL , v) ) +return -EBUSY ; + +/* +* We are called by the machine check (exception or polling) handlers +* on the physical CPU that reported a machine check error. +*/ +if ( !test_and_set_bool (v->mce_pending) ) + { + st->domain = v->domain; + st->processor = v->processor; + +/* not safe to wake up a vcpu here */ +raise_softirq (NMI_MCE_SOFTIRQ ); +return 0 ; + } + st->vcpu =NULL ; +break ; + } + +/* Delivery failed */ +return -EIO ; +} +/* * Local variables: * mode: C
xen/arch/x86/traps.c +0 -88
106 lines not on this page · raw message
xen/include/asm-x86/traps.h +0 -6
@@ -19,12 +19,6 @@#ifndef ASM_TRAP_H #define ASM_TRAP_H -struct softirq_trap { -struct domain *domain;/* domain to inject trap */ -struct vcpu *vcpu;/* vcpu to inject trap */ -int processor;/* physical cpu to inject trap */ -}; -struct cpu_user_regs ;void async_exception_cleanup (struct vcpu *);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 12/13] x86/traps: move some PV specific functions to pv/traps.c
Quoted 24 lines · Wei Liu
xen/arch/x86/pv/traps.c +20
-0@@ -148,6 +150,108 @@ void init_int80_direct_trap(struct vcpu *v) tb->flags =TBF_EXCEPTION | (TI_GET_IF (ti) ?TBF_INTERRUPT :0 ); } +struct softirq_trap { +struct domain *domain;/* domain to inject trap */ +struct vcpu *vcpu;/* vcpu to inject trap */ +int processor;/* physical cpu to inject trap */ +}; + +static DEFINE_PER_CPU(struct softirq_trap, softirq_trap); + +static void nmi_mce_softirq (void ) +{ +int cpu =smp_processor_id (); +struct softirq_trap *st = &per_cpu (softirq_trap, cpu); + +BUG_ON (st->vcpu ==NULL ); + +/* +* Set the tmp value unconditionally, so that the check in the iret +* hypercall works. +*/ + cpumask_copy(st->vcpu->cpu_hard_affinity_tmp,
xen/arch/x86/pv/traps.c void init_int80_direct_trap(struct vcpu *v) · line 182
Quoted 10 lines
xen/arch/x86/pv/traps.c +10
-0+ st->vcpu->cpu_hard_affinity); + +if ( (cpu != st->processor) || + (st->processor != st->vcpu->processor) ) + { + +/* +* We are on a different physical cpu. Make sure to wakeup the vcpu on +* the specified processor. +*/
You have some stray tabs here.
Quoted 17 lines
xen/arch/x86/pv/traps.c +17
-0+vcpu_set_hard_affinity (st->vcpu,cpumask_of (st->processor)); + +/* Affinity is restored in the iret hypercall. */ + } + +/* +* Only used to defer wakeup of domain/vcpu to a safe (non-NMI/MCE) +* context. +*/ +vcpu_kick (st->vcpu); + st->vcpu =NULL ; +} + +void __init pv_trap_init (void ) +{ +/* The 32-on-64 hypercall vector is only accessible from ring 1. */ + _set_gate(idt_table + HYPERCALL_VECTOR,
xen/arch/x86/pv/traps.c void init_int80_direct_trap(struct vcpu *v) · line 209
Quoted 10 lines
xen/arch/x86/pv/traps.c +10
-0+ SYS_DESC_trap_gate, 1, entry_int82); + +/* Fast trap for int80 (faster than taking the #GP-fixup path). */ +_set_gate (idt_table +LEGACY_SYSCALL_VECTOR , SYS_DESC_trap_gate,3 , + &int80_direct_trap); + +open_softirq (NMI_MCE_SOFTIRQ , nmi_mce_softirq); +} + +int pv_raise_interrupt (struct vcpu *v,uint8_t trap_nr)
Please s/trap_nr/vector/ as you are moving it. Unlike guest_has_trap_callback(), the uint8_t here isn't important.
Quoted 18 lines
xen/arch/x86/pv/traps.c +18
-0+{ +struct softirq_trap *st = &per_cpu (softirq_trap,smp_processor_id ()); + +switch ( trap_nr ) + { +case TRAP_nmi: +if (cmpxchgptr (&st->vcpu,NULL , v) ) +return -EBUSY ; +if ( !test_and_set_bool (v->nmi_pending) ) + { + st->domain = v->domain; + st->processor = v->processor; + +/* Not safe to wake up a vcpu here */ +raise_softirq (NMI_MCE_SOFTIRQ ); +return 0 ; + } + st->vcpu =NULL ;
xen/arch/x86/pv/traps.c void init_int80_direct_trap(struct vcpu *v) · line 237
Quoted 10 lines
xen/arch/x86/pv/traps.c +10
-0+break ; + +case TRAP_machine_check: +if (cmpxchgptr (&st->vcpu,NULL , v) ) +return -EBUSY ; + +/* +* We are called by the machine check (exception or polling) handlers +* on the physical CPU that reported a machine check error. +*/
And more tabs here.
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v5 12/13] x86/traps: move some PV specific functions to pv/traps.c
In reply to Wei LiuReview void init_int80_direct_trap(struct vcpu *v)
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Wei Liu <[email protected]> 06/26/17 6:46 PM >>>
(quoted diff) +0
-0@@ -148,6 +150,108 @@ void init_int80_direct_trap(struct vcpu *v)
>tb->flags = TBF_EXCEPTION | (TI_GET_IF(ti) ? TBF_INTERRUPT : 0);
xen/arch/x86/pv/traps.c void init_int80_direct_trap(struct vcpu *v) · line 156
Quoted 6 lines
xen/arch/x86/pv/traps.c +4
-0} +struct softirq_trap { +struct domain *domain;/* domain to inject trap */ +struct vcpu *vcpu;/* vcpu to inject trap */ +int processor;/* physical cpu to inject trap */
unsigned int please as you go.
xen/arch/x86/pv/traps.c void init_int80_direct_trap(struct vcpu *v) · line 163
Quoted 3 lines
xen/arch/x86/pv/traps.c +3
-0+static void nmi_mce_softirq (void ) +{ +int cpu =smp_processor_id ();
Same here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v5 13/13 x86/traps.h: remove unused declaration of cpu_user_regs
In reply to Wei Liu--- xen/include/asm-x86/traps.h | 2 -- 1 file changed, 2 deletions(-)
xen/include/asm-x86/traps.h +0 -2
@@ -19,8 +19,6 @@#ifndef ASM_TRAP_H #define ASM_TRAP_H -struct cpu_user_regs ; -void async_exception_cleanup (struct vcpu *); uint32_t guest_io_read(unsigned int port, unsigned int bytes,
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v5 13/13] x86/traps.h: remove unused declaration of cpu_user_regs
Quoted 1 line · Wei Liu
Signed-off-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel