x86/altp2m: Add hypercall to set a range of sve bits
PATCH 1/2 x86/altp2m: Add hypercall to set a range of sve bits
By default the sve bits are not set.
This patch adds a new hypercall, xc_altp2m_set_supress_ve_multi(), to set a range of sve bits.
The core function, p2m_set_suppress_ve_multi(), does not brake in case of a error and it is doing a best effort for setting the bits in the given range. A check for continuation is made in order to have preemption on big ranges.
--- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 25 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 28 +++++++++++++-- xen/arch/x86/mm/p2m.c | 61 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++- xen/include/xen/mem_access.h | 3 ++ 6 files changed, 121 insertions(+), 3 deletions(-)
tools/libxc/include/xenctrl.h +3 -0
@@ -1923,6 +1923,9 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid, uint16_t view_id);int xc_altp2m_set_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool sve); +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve);int xc_altp2m_get_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool *sve); int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,
tools/libxc/xc_altp2m.c +25 -0
@@ -234,6 +234,31 @@ int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve) +{ +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_set_suppress_ve_multi; + arg->domain = domid; + arg->u.suppress_ve.view = view_id; + arg->u.suppress_ve.gfn = start_gfn; + arg->u.suppress_ve.suppress_ve = sve; + arg->u.suppress_ve.nr = nr; + + 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_set_mem_access (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,xenmem_access_t access)
xen/arch/x86/hvm/hvm.c +26 -2
@@ -4535,6 +4535,7 @@ static int do_altp2m_op(case HVMOP_altp2m_destroy_p2m:case HVMOP_altp2m_switch_p2m:case HVMOP_altp2m_set_suppress_ve: +case HVMOP_altp2m_set_suppress_ve_multi:case HVMOP_altp2m_get_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi:
@@ -4681,7 +4682,7 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {
@@ -4693,8 +4694,31 @@ static int do_altp2m_op( }break ; +case HVMOP_altp2m_set_suppress_ve_multi: +if ( a.u.suppress_ve.pad1 || !a.u.suppress_ve.nr ) + rc = -EINVAL ; +else + { + rc =p2m_set_suppress_ve_multi (d, a.u.suppress_ve.gfn, + a.u.suppress_ve.nr, + a.u.suppress_ve.suppress_ve, + a.u.suppress_ve.view); + +if ( rc >0 ) + { + a.u.suppress_ve.gfn = rc; + rc = -ERESTART ; + +if (__copy_field_to_guest (guest_handle_cast (arg, + xen_hvm_altp2m_op_t), + &a, u.suppress_ve.gfn) ) + rc = -EFAULT ; + } + } +break ; +case HVMOP_altp2m_get_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {
xen/arch/x86/mm/p2m.c +61 -0
67 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +3 -1
@@ -42,7 +42,7 @@ struct xen_hvm_altp2m_suppress_ve {uint16_t view;uint8_t suppress_ve;/* Boolean type. */ uint8_t pad1; -uint32_t pad2; +uint32_t nr;uint64_t gfn; };
@@ -339,6 +339,8 @@ struct xen_hvm_altp2m_op {#define HVMOP_altp2m_vcpu_disable_notify 13/* Get the active vcpu p2m index */ #define HVMOP_altp2m_get_p2m_idx 14 +/* Set the "Supress #VE" bit for a range of pages */ +#define HVMOP_altp2m_set_suppress_ve_multi 15domid_t domain;uint16_t pad1;uint32_t pad2;
xen/include/xen/mem_access.h +3 -0
@@ -75,6 +75,9 @@ long p2m_set_mem_access_multi(struct domain *d,int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve,unsigned int altp2m_idx); +long p2m_set_suppress_ve_multi (struct domain *d,uint32_t start,uint32_t nr, +bool suppress_ve,unsigned int altp2m_idx); +int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve,unsigned int altp2m_idx);
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/2 x86/mm: Make use of the default access param from xc_altp2m_create_view
At this moment the default_access param from xc_altp2m_create_view is not used.
This patch assigns default_access to p2m->default_access at the time of initializing a new altp2m view.
--- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/mm/p2m-ept.c | 5 +++-- xen/arch/x86/mm/p2m.c | 31 ++++++++++++++++++++++++++----- xen/include/asm-x86/hvm/vmx/vmx.h | 3 ++- xen/include/asm-x86/p2m.h | 3 ++- xen/include/public/hvm/hvm_op.h | 2 -- 6 files changed, 35 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -1
@@ -4669,7 +4669,8 @@ static int do_altp2m_op( }case HVMOP_altp2m_create_p2m: -if ( !(rc =p2m_init_next_altp2m (d, &a.u.view.view)) ) +if ( !(rc =p2m_init_next_altp2m (d, &a.u.view.view, + a.u.view.hvmmem_default_access)) ) rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;break ;
xen/arch/x86/mm/p2m-ept.c +3 -2
@@ -1345,13 +1345,14 @@ void setup_ept_dump(void)register_keyhandler ('D' , ept_dump_p2m_table,"dump VT-x EPT tables" ,0 ); } -void p2m_init_altp2m_ept (struct domain *d,unsigned int i) +void p2m_init_altp2m_ept (struct domain *d,unsigned int i, +p2m_access_t default_access) {struct p2m_domain *p2m = d->arch.altp2m_p2m[i];struct p2m_domain *hostp2m =p2m_get_hostp2m (d);struct ept_data *ept; - p2m->default_access = hostp2m->default_access; + p2m->default_access = default_access; p2m->domain = hostp2m->domain; p2m->global_logdirty = hostp2m->global_logdirty;
xen/arch/x86/mm/p2m.c +26 -5
@@ -2528,7 +2528,8 @@ void p2m_flush_altp2m(struct domain *d)altp2m_list_unlock (d); } -static int p2m_activate_altp2m (struct domain *d,unsigned int idx) +static int p2m_activate_altp2m (struct domain *d,unsigned int idx, +p2m_access_t hvmmem_default_access) {struct p2m_domain *hostp2m, *p2m;int rc;
@@ -2554,7 +2555,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx) goto out; } -p2m_init_altp2m_ept (d, idx); +p2m_init_altp2m_ept (d, idx, hvmmem_default_access); out:p2m_unlock (p2m);
@@ -2565,6 +2566,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx)int p2m_init_altp2m_by_id (struct domain *d,unsigned int idx) {int rc = -EINVAL ; +struct p2m_domain *hostp2m =p2m_get_hostp2m (d);if ( idx >=MAX_ALTP2M )return rc;
@@ -2572,17 +2574,36 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx)altp2m_list_lock (d);if ( d->arch.altp2m_eptp[idx] ==mfn_x (INVALID_MFN ) ) - rc =p2m_activate_altp2m (d, idx); + rc =p2m_activate_altp2m (d, idx, hostp2m->default_access);altp2m_list_unlock (d);return rc; } -int p2m_init_next_altp2m (struct domain *d,uint16_t *idx) +int p2m_init_next_altp2m (struct domain *d,uint16_t *idx, +uint16_t hvmmem_default_access) {int rc = -EINVAL ;unsigned int i; +static const p2m_access_t memaccess[] = { +#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac + ACCESS(n), + ACCESS(r), + ACCESS(w), + ACCESS(rw), + ACCESS(x), + ACCESS(rx), + ACCESS(wx), + ACCESS(rwx), + ACCESS(rx2rw), + ACCESS(n2rwx), +#undef ACCESS + }; + +if ( hvmmem_default_access > XENMEM_access_default ) +return rc; +altp2m_list_lock (d);for ( i =0 ; i <MAX_ALTP2M ; i++ )
@@ -2590,7 +2611,7 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx)if ( d->arch.altp2m_eptp[i] !=mfn_x (INVALID_MFN ) )continue ; - rc =p2m_activate_altp2m (d, i); + rc =p2m_activate_altp2m (d, i, memaccess[hvmmem_default_access]);if ( !rc ) *idx = i;
xen/include/asm-x86/hvm/vmx/vmx.h +2 -1
@@ -598,7 +598,8 @@ void ept_p2m_uninit(struct p2m_domain *p2m);void ept_walk_table (struct domain *d,unsigned long gfn);bool_t ept_handle_misconfig (uint64_t gpa);void setup_ept_dump (void ); -void p2m_init_altp2m_ept (struct domain *d,unsigned int i); +void p2m_init_altp2m_ept (struct domain *d,unsigned int i, +p2m_access_t default_access);/* Locate an alternate p2m by its EPTP */ unsigned int p2m_find_altp2m_by_eptp (struct domain *d,uint64_t eptp);
xen/include/asm-x86/p2m.h +2 -1
@@ -884,7 +884,8 @@ bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,int p2m_init_altp2m_by_id (struct domain *d,unsigned int idx);/* Find an available alternate p2m and make it valid */ -int p2m_init_next_altp2m (struct domain *d,uint16_t *idx); +int p2m_init_next_altp2m (struct domain *d,uint16_t *idx, +uint16_t hvmmem_default_access);/* Make a specific alternate p2m invalid */ int p2m_destroy_altp2m_by_id (struct domain *d,unsigned int idx);
xen/include/public/hvm/hvm_op.h +0 -2
@@ -241,8 +241,6 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_disable_notify_t);struct xen_hvm_altp2m_view {/* IN/OUT variable */ uint16_t view; -/* Create view only: default access type -* NOTE: currently ignored */ uint16_t hvmmem_default_access;/* xenmem_access_t */ };typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t ;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH V1 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view
Quoted 8 lines · Alexandru Stefan ISAILA
At this moment the
default_accessparam fromxc_altp2m_create_viewis not used.This patch assigns
default_accesstop2m->default_accessat the time of initializing a new altp2m view.Signed-off-by Alexandru Isaila <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH V1 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view
In reply to Alexandru Stefan ISAILAQuoted 2 lines · Alexandru Stefan ISAILA
At this moment the
default_accessparam fromxc_altp2m_create_viewis not used.
Weird!
Quoted 5 lines
This patch assigns
default_accesstop2m->default_accessat the time of initializing a new altp2m view.Signed-off-by Alexandru Isaila <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH V1 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view
Quoted 5 lines · George Dunlap
Quoted 2 lines · Alexandru Stefan ISAILA
At this moment the
default_accessparam fromxc_altp2m_create_viewis not used.Weird!
Indeed, it was bugging me every time I passed throughout that code.
Alex
Quoted 9 lines
Quoted 6 lines
This patch assigns
default_accesstop2m->default_accessat the time of initializing a new altp2m view.Signed-off-by Alexandru Isaila <[email protected]>Acked-by George Dunlap <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 93 lines · Alexandru Stefan ISAILA
By default the sve bits are not set.
This patch adds a new hypercall,xc_altp2m_set_supress_ve_multi(), to set a range of sve bits.
The core function,p2m_set_suppress_ve_multi(), does not brake in case of a error and it is doing a best effort for setting the bits in the given range. A check for continuation is made in order to have preemption on big ranges.Signed-off-by Alexandru Isaila <[email protected]>--- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 25 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 28 +++++++++++++-- xen/arch/x86/mm/p2m.c | 61 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++- xen/include/xen/mem_access.h | 3 ++ 6 files changed, 121 insertions(+), 3 deletions(-)tools/libxc/include/xenctrl.h +3
-0@@ -1923,6 +1923,9 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid, uint16_t view_id);int xc_altp2m_set_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool sve); +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve);int xc_altp2m_get_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool *sve); int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,tools/libxc/xc_altp2m.c +25
-0@@ -234,6 +234,31 @@ int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve) +{ +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_set_suppress_ve_multi; + arg->domain = domid; + arg->u.suppress_ve.view = view_id; + arg->u.suppress_ve.gfn = start_gfn; + arg->u.suppress_ve.suppress_ve = sve; + arg->u.suppress_ve.nr = nr; + + 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_set_mem_access (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,xenmem_access_t access)xen/arch/x86/hvm/hvm.c +2
-1@@ -4535,6 +4535,7 @@ static int do_altp2m_op(case HVMOP_altp2m_destroy_p2m:case HVMOP_altp2m_switch_p2m:case HVMOP_altp2m_set_suppress_ve: +case HVMOP_altp2m_set_suppress_ve_multi:case HVMOP_altp2m_get_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi:@@ -4681,7 +4682,7 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {@@ -4693,8 +4694,31 @@ static int do_altp2m_op( }break ;
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4705
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +9
-0+case HVMOP_altp2m_set_suppress_ve_multi: +if ( a.u.suppress_ve.pad1 || !a.u.suppress_ve.nr ) + rc = -EINVAL ; +else + { + rc =p2m_set_suppress_ve_multi (d, a.u.suppress_ve.gfn, + a.u.suppress_ve.nr, + a.u.suppress_ve.suppress_ve, + a.u.suppress_ve.view);
I have to say I'm not a fan of stuffing the current gfn progress into rc, perhaps a separate pointer being passed in for storing that and returning -ERESTART would be cleaner.
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4709
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +3
-0+if ( rc >0 ) + { + a.u.suppress_ve.gfn = rc;
There had been discussion in the past whether its acceptable to overwrite fields that were passed in like this. This may not be the expected behavior. For the mem_sharing side at least we have introduced an "opaque" field in the structure to store that continuation value (see
https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/include/public/memory.h;h=cfdda6e2a87ed30bed590034d8d717674abfbc79;hb=HEAD#l524).
Quoted 125 lines
xen/arch/x86/hvm/hvm.c +11
-1+ rc = -ERESTART ; + +if (__copy_field_to_guest (guest_handle_cast (arg, + xen_hvm_altp2m_op_t), + &a, u.suppress_ve.gfn) ) + rc = -EFAULT ; + } + } +break ; +case HVMOP_altp2m_get_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {xen/arch/x86/mm/p2m.c +61
-0@@ -3054,6 +3054,67 @@ out:return rc; } +/* +* Set/clear the #VE suppress bit for multiple pages. Only available on VMX. +*/ +long p2m_set_suppress_ve_multi (struct domain *d,uint32_t start,uint32_t nr, +bool suppress_ve,unsigned int altp2m_idx) +{ +struct p2m_domain *host_p2m =p2m_get_hostp2m (d); +struct p2m_domain *ap2m =NULL ; +struct p2m_domain *p2m; +long rc =0 ; + +if ( altp2m_idx >0 ) + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; + + p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; + } +else + p2m = host_p2m; + +p2m_lock (host_p2m); + +if ( ap2m ) +p2m_lock (ap2m); + + +while ( start < nr ) + { +p2m_access_t a; +p2m_type_t t; +mfn_t mfn; + + rc =altp2m_get_effective_entry (p2m,_gfn (start), &mfn, &t, &a, AP2MGET_query); + +if ( rc ) + a = p2m->default_access; + + rc = p2m->set_entry (p2m,_gfn (start), mfn,PAGE_ORDER_4K , t, a, suppress_ve); + +/* Try best effort for setting the whole range. */ +if ( rc ) +continue ; + +/* Check for continuation if it's not the last iteration. */ +if ( nr > ++start &&hypercall_preempt_check () ) + { + rc = start; +break ; + } + } + +if ( ap2m ) +p2m_unlock (ap2m); + +p2m_unlock (host_p2m); + +return rc; +} +int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve,unsigned int altp2m_idx) {xen/include/public/hvm/hvm_op.h +3
-1@@ -42,7 +42,7 @@ struct xen_hvm_altp2m_suppress_ve {uint16_t view;uint8_t suppress_ve;/* Boolean type. */ uint8_t pad1; -uint32_t pad2; +uint32_t nr;uint64_t gfn; };@@ -339,6 +339,8 @@ struct xen_hvm_altp2m_op {#define HVMOP_altp2m_vcpu_disable_notify 13/* Get the active vcpu p2m index */ #define HVMOP_altp2m_get_p2m_idx 14 +/* Set the "Supress #VE" bit for a range of pages */ +#define HVMOP_altp2m_set_suppress_ve_multi 15domid_t domain;uint16_t pad1;uint32_t pad2;xen/include/xen/mem_access.h +3
-1@@ -75,6 +75,9 @@ long p2m_set_mem_access_multi(struct domain *d,int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve,unsigned int altp2m_idx); +long p2m_set_suppress_ve_multi (struct domain *d,uint32_t start,uint32_t nr, +bool suppress_ve,unsigned int altp2m_idx); +int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve,unsigned int altp2m_idx); --
Quoted 1 line
2.17.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 96 lines · Tamas K Lengyel
Quoted 94 lines · Alexandru Stefan ISAILA
By default the sve bits are not set.
This patch adds a new hypercall,xc_altp2m_set_supress_ve_multi(), to set a range of sve bits.
The core function,p2m_set_suppress_ve_multi(), does not brake in case of a error and it is doing a best effort for setting the bits in the given range. A check for continuation is made in order to have preemption on big ranges.Signed-off-by Alexandru Isaila <[email protected]>--- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 25 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 28 +++++++++++++-- xen/arch/x86/mm/p2m.c | 61 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++- xen/include/xen/mem_access.h | 3 ++ 6 files changed, 121 insertions(+), 3 deletions(-)tools/libxc/include/xenctrl.h +3
-0@@ -1923,6 +1923,9 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid, uint16_t view_id);int xc_altp2m_set_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool sve); +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve);int xc_altp2m_get_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool *sve); int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,tools/libxc/xc_altp2m.c +25
-0@@ -234,6 +234,31 @@ int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve) +{ +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_set_suppress_ve_multi; + arg->domain = domid; + arg->u.suppress_ve.view = view_id; + arg->u.suppress_ve.gfn = start_gfn; + arg->u.suppress_ve.suppress_ve = sve; + arg->u.suppress_ve.nr = nr; + + 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_set_mem_access (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,xenmem_access_t access)xen/arch/x86/hvm/hvm.c +2
-1@@ -4535,6 +4535,7 @@ static int do_altp2m_op(case HVMOP_altp2m_destroy_p2m:case HVMOP_altp2m_switch_p2m:case HVMOP_altp2m_set_suppress_ve: +case HVMOP_altp2m_set_suppress_ve_multi:case HVMOP_altp2m_get_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi:@@ -4681,7 +4682,7 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {@@ -4693,8 +4694,31 @@ static int do_altp2m_op( }break ;
Quoted 13 lines
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4705
Quoted 9 lines
xen/arch/x86/hvm/hvm.c +9
-0+case HVMOP_altp2m_set_suppress_ve_multi: +if ( a.u.suppress_ve.pad1 || !a.u.suppress_ve.nr ) + rc = -EINVAL ; +else + { + rc =p2m_set_suppress_ve_multi (d, a.u.suppress_ve.gfn, + a.u.suppress_ve.nr, + a.u.suppress_ve.suppress_ve, + a.u.suppress_ve.view);I have to say I'm not a fan of stuffing the current gfn progress into rc, perhaps a separate pointer being passed in for storing that and returning
-ERESTARTwould be cleaner.
This sounds cleaner, I will have it changed in v2.
Quoted 11 lines
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4709
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +3
-0+if ( rc >0 ) + { + a.u.suppress_ve.gfn = rc;There had been discussion in the past whether its acceptable to overwrite fields that were passed in like this. This may not be the expected behavior. For the
mem_sharingside at least we have introduced an "opaque" field in the structure to store that continuation value (see
https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/include/public/memory.h;h=cfdda6e2a87ed30bed590034d8d717674abfbc79;hb=HEAD#l524).
I wanted to keep the size of the struct. It it is ok to have a new uint64_t opaque here and then pad the rest of the structures then I will change this in v2.
Thanks,
Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 171 lines · Alexandru Stefan ISAILA
By default the sve bits are not set.
This patch adds a new hypercall,xc_altp2m_set_supress_ve_multi(), to set a range of sve bits.
The core function,p2m_set_suppress_ve_multi(), does not brake in case of a error and it is doing a best effort for setting the bits in the given range. A check for continuation is made in order to have preemption on big ranges.Signed-off-by Alexandru Isaila <[email protected]>--- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 25 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 28 +++++++++++++-- xen/arch/x86/mm/p2m.c | 61 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++- xen/include/xen/mem_access.h | 3 ++ 6 files changed, 121 insertions(+), 3 deletions(-)tools/libxc/include/xenctrl.h +3
-0@@ -1923,6 +1923,9 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid, uint16_t view_id);int xc_altp2m_set_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool sve); +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve);int xc_altp2m_get_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool *sve); int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,tools/libxc/xc_altp2m.c +25
-0@@ -234,6 +234,31 @@ int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_set_supress_ve_multi (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t start_gfn, +uint32_t nr,bool sve) +{ +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_set_suppress_ve_multi; + arg->domain = domid; + arg->u.suppress_ve.view = view_id; + arg->u.suppress_ve.gfn = start_gfn; + arg->u.suppress_ve.suppress_ve = sve; + arg->u.suppress_ve.nr = nr; + + 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_set_mem_access (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,xenmem_access_t access)xen/arch/x86/hvm/hvm.c +26
-2@@ -4535,6 +4535,7 @@ static int do_altp2m_op(case HVMOP_altp2m_destroy_p2m:case HVMOP_altp2m_switch_p2m:case HVMOP_altp2m_set_suppress_ve: +case HVMOP_altp2m_set_suppress_ve_multi:case HVMOP_altp2m_get_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi:@@ -4681,7 +4682,7 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {@@ -4693,8 +4694,31 @@ static int do_altp2m_op( }break ; +case HVMOP_altp2m_set_suppress_ve_multi: +if ( a.u.suppress_ve.pad1 || !a.u.suppress_ve.nr ) + rc = -EINVAL ; +else + { + rc =p2m_set_suppress_ve_multi (d, a.u.suppress_ve.gfn, + a.u.suppress_ve.nr, + a.u.suppress_ve.suppress_ve, + a.u.suppress_ve.view); + +if ( rc >0 ) + { + a.u.suppress_ve.gfn = rc; + rc = -ERESTART ; + +if (__copy_field_to_guest (guest_handle_cast (arg, + xen_hvm_altp2m_op_t), + &a, u.suppress_ve.gfn) ) + rc = -EFAULT ; + } + } +break ; +case HVMOP_altp2m_get_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 ) rc = -EINVAL ;else {xen/arch/x86/mm/p2m.c +41
-0@@ -3054,6 +3054,67 @@ out:return rc; } +/* +* Set/clear the #VE suppress bit for multiple pages. Only available on VMX. +*/ +long p2m_set_suppress_ve_multi (struct domain *d,uint32_t start,uint32_t nr, +bool suppress_ve,unsigned int altp2m_idx) +{ +struct p2m_domain *host_p2m =p2m_get_hostp2m (d); +struct p2m_domain *ap2m =NULL ; +struct p2m_domain *p2m; +long rc =0 ; + +if ( altp2m_idx >0 ) + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; + + p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; + } +else + p2m = host_p2m; + +p2m_lock (host_p2m); + +if ( ap2m ) +p2m_lock (ap2m); + + +while ( start < nr ) + { +p2m_access_t a; +p2m_type_t t; +mfn_t mfn; + + rc =altp2m_get_effective_entry (p2m,_gfn (start), &mfn, &t, &a, AP2MGET_query); + +if ( rc ) + a = p2m->default_access; + + rc = p2m->set_entry (p2m,_gfn (start), mfn,PAGE_ORDER_4K , t, a, suppress_ve); +
xen/arch/x86/mm/p2m.c out: · line 3107
Quoted 10 lines
xen/arch/x86/mm/p2m.c +10
-0+/* Try best effort for setting the whole range. */ +if ( rc ) +continue ; + +/* Check for continuation if it's not the last iteration. */ +if ( nr > ++start &&hypercall_preempt_check () ) + { + rc = start; +break ; + }
What's the point of the "if ( rc ) continue;"? All it's doing is preventing the loop from being preempted at that point; but there doesn't seem to be a good reason for that. In fact, if an attacker could engineer a situation where large swaths could fail, it could use this to lock up the cpu for an unreasonable amount of time.
Everything else looks OK to me.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines
Quoted 51 lines
xen/arch/x86/mm/p2m.c +49
-0+/* +* Set/clear the #VE suppress bit for multiple pages. Only available on VMX. +*/ +long p2m_set_suppress_ve_multi (struct domain *d,uint32_t start,uint32_t nr, +bool suppress_ve,unsigned int altp2m_idx) +{ +struct p2m_domain *host_p2m =p2m_get_hostp2m (d); +struct p2m_domain *ap2m =NULL ; +struct p2m_domain *p2m; +long rc =0 ; + +if ( altp2m_idx >0 ) + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; + + p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; + } +else + p2m = host_p2m; + +p2m_lock (host_p2m); + +if ( ap2m ) +p2m_lock (ap2m); + + +while ( start < nr ) + { +p2m_access_t a; +p2m_type_t t; +mfn_t mfn; + + rc =altp2m_get_effective_entry (p2m,_gfn (start), &mfn, &t, &a, AP2MGET_query); + +if ( rc ) + a = p2m->default_access; + + rc = p2m->set_entry (p2m,_gfn (start), mfn,PAGE_ORDER_4K , t, a, suppress_ve); + +/* Try best effort for setting the whole range. */ +if ( rc ) +continue ; + +/* Check for continuation if it's not the last iteration. */ +if ( nr > ++start &&hypercall_preempt_check () ) + { + rc = start;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ break; + }What's the point of the "if ( rc ) continue;"? All it's doing is preventing the loop from being preempted at that point; but there doesn't seem to be a good reason for that. In fact, if an attacker could engineer a situation where large swaths could fail, it could use this to lock up the cpu for an unreasonable amount of time.
Yes, that could be an issue. It will go in v2
Quoted 4 lines
Everything else looks OK to me.
If the changes requested by Tamas are also ok with you then I will have them all go in v2.
Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel