x86/altp2m: add altp2m_vcpu_disable_notify
PATCH 1/1 x86/altp2m: add altp2m_vcpu_disable_notify
Allow altp2m users to disable #VE/VMFUNC alone. Currently it is only possible to disable this functionality when we disable altp2m completely; #VE/VMFUNC can only be enabled once per altp2m session.
In addition to making things complete, disabling #VE is also a workaround for CFW116 ("When Virtualization Exceptions are Enabled, EPT Violations May Generate Erroneous Virtualization Exceptions") on Xeon CPUs.
--- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_altp2m.c | 22 ++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 31 +++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 12 +++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +2 -0
@@ -1932,6 +1932,8 @@ int xc_altp2m_get_domain_state(xc_interface *handle, uint32_t dom, bool *state);int xc_altp2m_set_domain_state (xc_interface *handle,uint32_t dom,bool state);int xc_altp2m_set_vcpu_enable_notify (xc_interface *handle,uint32_t domid,uint32_t vcpuid,xen_pfn_t gfn); +int xc_altp2m_set_vcpu_disable_notify (xc_interface *handle,uint32_t domid, +uint32_t vcpuid);int xc_altp2m_create_view (xc_interface *handle,uint32_t domid,xenmem_access_t default_access,uint16_t *view_id); int xc_altp2m_destroy_view(xc_interface *handle, uint32_t domid,
tools/libxc/xc_altp2m.c +22 -0
@@ -91,6 +91,28 @@ int xc_altp2m_set_vcpu_enable_notify(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_set_vcpu_disable_notify (xc_interface *handle,uint32_t domid, +uint32_t vcpuid) +{ +int rc; +DECLARE_HYPERCALL_BUFFER (xen_hvm_altp2m_op_t, arg); + + arg =xc_hypercall_buffer_alloc (handle, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + arg->version =HVMOP_ALTP2M_INTERFACE_VERSION ; + arg->cmd = HVMOP_altp2m_vcpu_disable_notify; + arg->domain = domid; + arg->u.disable_notify.vcpu_id = vcpuid; + + rc =xencall2 (handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, +HYPERCALL_BUFFER_AS_ARG (arg)); + +xc_hypercall_buffer_free (handle, arg); +return rc; +} +int xc_altp2m_create_view (xc_interface *handle,uint32_t domid,xenmem_access_t default_access,uint16_t *view_id) {
xen/arch/x86/hvm/hvm.c +31 -0
@@ -4485,6 +4485,7 @@ static int do_altp2m_op(case HVMOP_altp2m_get_domain_state:case HVMOP_altp2m_set_domain_state:case HVMOP_altp2m_vcpu_enable_notify: +case HVMOP_altp2m_vcpu_disable_notify:case HVMOP_altp2m_create_p2m:case HVMOP_altp2m_destroy_p2m:case HVMOP_altp2m_switch_p2m:
@@ -4602,6 +4603,36 @@ static int do_altp2m_op(break ; } +case HVMOP_altp2m_vcpu_disable_notify: + { +struct vcpu *v; + +if ( a.u.disable_notify.pad || + a.u.disable_notify.vcpu_id >= d->max_vcpus ) + { + rc = -EINVAL ; +break ; + } + +if ( !cpu_has_vmx_virt_exceptions ) + { + rc = -EOPNOTSUPP ; +break ; + } + + v = d->vcpu[a.u.enable_notify.vcpu_id]; + +if (gfn_eq (vcpu_altp2m (v).veinfo_gfn,INVALID_GFN ) ) + { + rc = -EINVAL ; +break ; + } + +vcpu_altp2m (v).veinfo_gfn =INVALID_GFN ; +altp2m_vcpu_update_vmfunc_ve (v); +break ; + } +case HVMOP_altp2m_create_p2m:if ( !(rc =p2m_init_next_altp2m (d, &a.u.view.view)) ) rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;
xen/include/public/hvm/hvm_op.h +11 -1
@@ -232,6 +232,13 @@ struct xen_hvm_altp2m_vcpu_enable_notify {typedef struct xen_hvm_altp2m_vcpu_enable_notify xen_hvm_altp2m_vcpu_enable_notify_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_vcpu_enable_notify_t); +struct xen_hvm_altp2m_vcpu_disable_notify { +uint32_t vcpu_id; +uint32_t pad; +}; +typedef struct xen_hvm_altp2m_vcpu_disable_notify xen_hvm_altp2m_vcpu_disable_notify_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_vcpu_disable_notify_t); +struct xen_hvm_altp2m_view {/* IN/OUT variable */ uint16_t view;
@@ -304,7 +311,7 @@ struct xen_hvm_altp2m_op {/* Get/set the altp2m state for a domain */ #define HVMOP_altp2m_get_domain_state 1#define HVMOP_altp2m_set_domain_state 2 -/* Set the current VCPU to receive altp2m event notifications */ +/* Set a given VCPU to receive altp2m event notifications */ #define HVMOP_altp2m_vcpu_enable_notify 3/* Create a new view */ #define HVMOP_altp2m_create_p2m 4
@@ -324,6 +331,8 @@ struct xen_hvm_altp2m_op {#define HVMOP_altp2m_get_suppress_ve 11/* Get the access of a page of memory from a certain view */ #define HVMOP_altp2m_get_mem_access 12 +/* Disable altp2m event notifications for a given VCPU */ +#define HVMOP_altp2m_vcpu_disable_notify 13domid_t domain;uint16_t pad1;uint32_t pad2;
@@ -338,6 +347,7 @@ struct xen_hvm_altp2m_op {struct xen_hvm_altp2m_change_gfn change_gfn;struct xen_hvm_altp2m_set_mem_access_multi set_mem_access_multi;struct xen_hvm_altp2m_suppress_ve suppress_ve; +struct xen_hvm_altp2m_vcpu_disable_notify disable_notify;uint8_t pad[64 ]; } u; };
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 14.12.18 at 18:17, <[email protected]> wrote:
Allow altp2m users to disable #VE/VMFUNC alone. Currently it is only possible to disable this functionality when we disable altp2m completely; #VE/VMFUNC can only be enabled once per altp2m session.
In addition to making things complete, disabling #VE is also a workaround for CFW116 ("When Virtualization Exceptions are Enabled, EPT Violations May Generate Erroneous Virtualization Exceptions") on Xeon CPUs.
"Xeon CPUs" is overly generic. Yes, the CFW erratum prefix allows to identify which one you mean, but only (afaik) by going through the spec updates until you've found the right one. Can you please be more specific here?
Quoted 18 lines
xen/arch/x86/hvm/hvm.c +14
-0@@ -4602,6 +4603,36 @@ static int do_altp2m_op(break ; } +case HVMOP_altp2m_vcpu_disable_notify: + { +struct vcpu *v; + +if ( a.u.disable_notify.pad || + a.u.disable_notify.vcpu_id >= d->max_vcpus ) + { + rc = -EINVAL ; +break ; + } + +if ( !cpu_has_vmx_virt_exceptions ) + { + rc = -EOPNOTSUPP ;
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4629
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+break ; + } + + v = d->vcpu[a.u.enable_notify.vcpu_id]; + +if (gfn_eq (vcpu_altp2m (v).veinfo_gfn,INVALID_GFN ) ) + { + rc = -EINVAL ; +break ; + }
Why? Disabling what is already disabled is not wrong, and hence could easily be treated as a no-op.
xen/include/public/hvm/hvm_op.h struct xen_hvm_altp2m_vcpu_enable_notify { · line 237
Quoted 9 lines
xen/include/public/hvm/hvm_op.h +3
-0@@ -232,6 +232,13 @@ struct xen_hvm_altp2m_vcpu_enable_notify {typedef struct xen_hvm_altp2m_vcpu_enable_notify xen_hvm_altp2m_vcpu_enable_notify_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_vcpu_enable_notify_t); +struct xen_hvm_altp2m_vcpu_disable_notify { +uint32_t vcpu_id; +uint32_t pad;
Why the pad field? There's no hole left.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 14.12.18 at 18:17, <[email protected]> wrote:
Allow altp2m users to disable #VE/VMFUNC alone. Currently it is only possible to disable this functionality when we disable altp2m completely; #VE/VMFUNC can only be enabled once per altp2m session.
In addition to making things complete, disabling #VE is also a workaround for CFW116 ("When Virtualization Exceptions are Enabled, EPT Violations May Generate Erroneous Virtualization Exceptions") on Xeon CPUs.
Quoted 4 lines
"Xeon CPUs" is overly generic. Yes, the CFW erratum prefix allows to identify which one you mean, but only (afaik) by going through the spec updates until you've found the right one. Can you please be more specific here?
Of course, sorry for the ambiguity. I was referring to the E-2100s:
I will update the patch description.
Quoted 23 lines
Quoted 23 lines
xen/arch/x86/hvm/hvm.c +19
-0@@ -4602,6 +4603,36 @@ static int do_altp2m_op(break ; } +case HVMOP_altp2m_vcpu_disable_notify: + { +struct vcpu *v; + +if ( a.u.disable_notify.pad || + a.u.disable_notify.vcpu_id >= d->max_vcpus ) + { + rc = -EINVAL ; +break ; + } + +if ( !cpu_has_vmx_virt_exceptions ) + { + rc = -EOPNOTSUPP ; +break ; + } + + v = d->vcpu[a.u.enable_notify.vcpu_id]; +
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4629
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +5
-0+if (gfn_eq (vcpu_altp2m (v).veinfo_gfn,INVALID_GFN ) ) + { + rc = -EINVAL ; +break ; + }Why? Disabling what is already disabled is not wrong, and hence could easily be treated as a no-op.
Just tought I'd actually report that this would be a no-op. But it's not important, so I'll make it a no-op (simply break instead of setting rc to -EINVAL).
Quoted 11 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_altp2m_vcpu_enable_notify { · line 237
Quoted 9 lines
xen/include/public/hvm/hvm_op.h +3
-0@@ -232,6 +232,13 @@ struct xen_hvm_altp2m_vcpu_enable_notify {typedef struct xen_hvm_altp2m_vcpu_enable_notify xen_hvm_altp2m_vcpu_enable_notify_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_vcpu_enable_notify_t); +struct xen_hvm_altp2m_vcpu_disable_notify { +uint32_t vcpu_id; +uint32_t pad;Why the pad field? There's no hole left.
Sorry, that was an oversight. I'll correct it.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel