From: Andrew Cooper Date: Thu, 13 Apr 2017 16:40:26 +0000 (+0100) Subject: HYPERCALL_callback infrastructure for PV guests X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=637b0d1d1a02b0563cd1966bee800e9e5617e9fa;p=people%2Fandrewcoop%2Fxen-test-framework.git HYPERCALL_callback infrastructure for PV guests Signed-off-by: Andrew Cooper --- diff --git a/include/xen/arch-x86/xen-x86_32.h b/include/xen/arch-x86/xen-x86_32.h index 8ac5d2c..d7a7ef2 100644 --- a/include/xen/arch-x86/xen-x86_32.h +++ b/include/xen/arch-x86/xen-x86_32.h @@ -34,6 +34,12 @@ static inline unsigned int xen_cr3_to_pfn(unsigned int cr3) return cr3 >> 12 | cr3 << 20; } +struct xen_callback { + unsigned long cs; + unsigned long eip; +}; +typedef struct xen_callback xen_callback_t; + #endif /* __ASSEMBLY__ */ #endif /* XEN_PUBLIC_ARCH_X86_XEN_X86_32_H */ diff --git a/include/xen/arch-x86/xen-x86_64.h b/include/xen/arch-x86/xen-x86_64.h index 293fa0d..ef5f7a4 100644 --- a/include/xen/arch-x86/xen-x86_64.h +++ b/include/xen/arch-x86/xen-x86_64.h @@ -17,6 +17,12 @@ #define MACH2PHYS_VIRT_START 0xFFFF800000000000UL +#ifndef __ASSEMBLY__ + +typedef unsigned long xen_callback_t; + +#endif /* __ASSEMBLY__ */ + #endif /* XEN_PUBLIC_ARCH_X86_XEN_X86_64_H */ /* diff --git a/include/xen/callback.h b/include/xen/callback.h new file mode 100644 index 0000000..251b695 --- /dev/null +++ b/include/xen/callback.h @@ -0,0 +1,79 @@ +/* + * Xen public PV callback interface + */ + +#ifndef XEN_PUBLIC_CALLBACK_H +#define XEN_PUBLIC_CALLBACK_H + +#include "xen.h" + +/* + * Prototype for this hypercall is: + * long callback_op(int cmd, void *extra_args) + * @cmd == CALLBACKOP_??? (callback operation). + * @extra_args == Operation-specific extra arguments (NULL if none). + */ + +/* x86: Callback for event delivery. */ +#define CALLBACKTYPE_event 0 + +/* x86: Failsafe callback when guest state cannot be restored by Xen. */ +#define CALLBACKTYPE_failsafe 1 + +/* x86/64 hypervisor: Syscall by 64-bit guest app ('64-on-64-on-64'). */ +#define CALLBACKTYPE_syscall 2 + +/* + * x86/32 hypervisor: Only available on x86/32 when supervisor_mode_kernel + * feature is enabled. Do not use this callback type in new code. + */ +#define CALLBACKTYPE_sysenter_deprecated 3 + +/* x86: Callback for NMI delivery. */ +#define CALLBACKTYPE_nmi 4 + +/* + * x86: sysenter is only available as follows: + * - 32-bit hypervisor: with the supervisor_mode_kernel feature enabled + * - 64-bit hypervisor: 32-bit guest applications on Intel CPUs + * ('32-on-32-on-64', '32-on-64-on-64') + * [nb. also 64-bit guest applications on Intel CPUs + * ('64-on-64-on-64'), but syscall is preferred] + */ +#define CALLBACKTYPE_sysenter 5 + +/* + * x86/64 hypervisor: Syscall by 32-bit guest app on AMD CPUs + * ('32-on-32-on-64', '32-on-64-on-64') + */ +#define CALLBACKTYPE_syscall32 7 + +/* + * Disable event deliver during callback? This flag is ignored for event and + * NMI callbacks: event delivery is unconditionally disabled. + */ +#define _CALLBACKF_mask_events 0 +#define CALLBACKF_mask_events (1U << _CALLBACKF_mask_events) + +/* + * Register a callback. + */ +#define CALLBACKOP_register 0 +struct xen_callback_register { + uint16_t type; + uint16_t flags; + xen_callback_t address; +}; +typedef struct xen_callback_register xen_callback_register_t; + +#endif /* XEN_PUBLIC_CALLBACK_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xtf/hypercall.h b/include/xtf/hypercall.h index a51b220..aec5a12 100644 --- a/include/xtf/hypercall.h +++ b/include/xtf/hypercall.h @@ -29,6 +29,7 @@ extern uint8_t hypercall_page[PAGE_SIZE]; /* All Xen ABI for includers convenience .*/ #include #include +#include #include #include #include @@ -100,6 +101,11 @@ static inline long hypercall_sched_op(unsigned int cmd, void *arg) return HYPERCALL2(long, __HYPERVISOR_sched_op, cmd, arg); } +static inline long hypercall_callback_op(unsigned int cmd, const void *arg) +{ + return HYPERCALL2(long, __HYPERVISOR_callback_op, cmd, arg); +} + static inline long hypercall_event_channel_op(unsigned int cmd, void *arg) { return HYPERCALL2(long, __HYPERVISOR_event_channel_op, cmd, arg); @@ -138,6 +144,11 @@ static inline void hypercall_yield(void) hypercall_sched_op(SCHEDOP_yield, NULL); } +static inline int hypercall_register_callback(const xen_callback_register_t *arg) +{ + return hypercall_callback_op(CALLBACKOP_register, arg); +} + static inline int hypercall_evtchn_send(evtchn_port_t port) { return hypercall_event_channel_op(EVTCHNOP_send, &port);