Add hvmops for setting and getting the suppress #VE bit
v4 cover Add hvmops for setting and getting the suppress #VE bit
As the code stands right now, after DomU has enabled #VE using HVMOP_altp2m_vcpu_enable_notify, all its pages have the #VE suppress bit cleared, generating #VEs for any EPT violation. There is currently no way to change the value of the #VE suppress bit for a page from a domain; it can only be done in Xen internally using ept_set_entry().
Following the discussion from
https://lists.xen.org/archives/html/xen-devel/2017-03/msg01312.html these patches introduce new hvmops for setting and getting this bit and thus having control over which pages generate #VE and which VM-Exit.
Adrian Pop (2):
x86/altp2m: Add a hvmop for setting the suppress #VE bit x86/altp2m: Add a hvmop for querying the suppress #VE bit
Vlad Ioan Topan (1):
x86/mm: Change default value for suppress #VE in set_mem_access()
tools/libxc/include/xenctrl.h | 4 ++ tools/libxc/xc_altp2m.c | 50 ++++++++++++++++ xen/arch/x86/hvm/hvm.c | 33 ++++++++++ xen/arch/x86/mm/mem_access.c | 103 +++++++++++++++++++++++++++++++- xen/include/public/hvm/hvm_op.h | 13 ++++ xen/include/xen/mem_access.h | 6 ++ 6 files changed, 207 insertions(+), 2 deletions(-)
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/3 x86/mm: Change default value for suppress #VE in set_mem_access()
From: Vlad Ioan Topan <[email protected]>
The default value for the "suppress #VE" bit set by set_mem_access() currently depends on whether the call is made from the same domain (the bit is set when called from another domain and cleared if called from the same domain). This patch changes that behavior to inherit the old suppress #VE bit value if it is already set and to set it to 1 otherwise, which is safer and more reliable.
--- xen/arch/x86/mm/mem_access.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/mm/mem_access.c +1 -2
@@ -282,8 +282,7 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, } } -return ap2m->set_entry (ap2m, gfn, mfn,PAGE_ORDER_4K , t, a, - current->domain != d); +return ap2m->set_entry (ap2m, gfn, mfn,PAGE_ORDER_4K , t, a,-1 ); } static int set_mem_access(struct domain *d, struct p2m_domain *p2m,
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 2/3 x86/altp2m: Add a hvmop for setting the suppress #VE bit
In reply to Adrian PopIntroduce a new hvmop, HVMOP_altp2m_set_suppress_ve, which allows a domain to change the value of the #VE suppress bit for a page.
Add a libxc wrapper for invoking this hvmop.
---
Changes in v4:
- fix a deadlock:
If p2m_set_suppress_ve() is called by with invalid pages the code path wrongly returns without releasing the lock, resulting in a deadlock.
- remove the privileged domain check
Changes in v3:
- fix indentation (Wei Liu)
- use return values other than EINVAL where appropriate (Ian Beulich)
- remove the irrelevant comments from the xen_hvm_altp2m_set_suppress_ve struct (Ian Beulich)
- add comment for the suppress_ve field in the struct above (Ian Beulich)
- remove the typedef and DEFINE_XEN_GUEST_HANDLE for xen_hvm_altp2m_set_suppress_ve (Ian Beulich)
- use XSM_DM_PRIV check instead of domain->is_privileged (Ian Beulich)
Changes in v2:
- check if #VE has been enabled on the target domain (Tamas K Lengyel)
- check if the cpu has the #VE feature
- make the suppress_ve argument boolean (Jan Beulich)
- initialize only local variables that need initializing (Jan Beulich)
- use fewer local variables (Jan Beulich)
- fix indentation (Jan Beulich)
- remove unnecessary braces (Jan Beulich)
- use gfn_lock() instead of p2m_lock() in the non-altp2m case (Jan Beulich)
- merge patch #2 and patch #3 (Jan Beulich)
--- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_altp2m.c | 24 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 14 +++++++++ xen/arch/x86/mm/mem_access.c | 55 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 11 +++++++ xen/include/xen/mem_access.h | 3 ++ 6 files changed, 109 insertions(+)
tools/libxc/include/xenctrl.h +2 -0
@@ -1966,6 +1966,8 @@ int xc_altp2m_destroy_view(xc_interface *handle, uint32_t domid,/* Switch all vCPUs of the domain to the specified altp2m view */ 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_mem_access (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,xenmem_access_t access);
tools/libxc/xc_altp2m.c +24 -0
@@ -163,6 +163,30 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_set_suppress_ve (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t gfn,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; + arg->domain = domid; + arg->u.set_suppress_ve.view = view_id; + arg->u.set_suppress_ve.gfn = gfn; + arg->u.set_suppress_ve.suppress_ve = sve; + + 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 +14 -0
@@ -4493,6 +4493,7 @@ static int do_altp2m_op(case HVMOP_altp2m_create_p2m:case HVMOP_altp2m_destroy_p2m:case HVMOP_altp2m_switch_p2m: +case HVMOP_altp2m_set_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi:case HVMOP_altp2m_change_gfn:
@@ -4610,6 +4611,19 @@ static int do_altp2m_op( rc =p2m_switch_domain_altp2m_by_id (d, a.u.view.view);break ; +case HVMOP_altp2m_set_suppress_ve: +if ( a.u.set_suppress_ve.pad1 || a.u.set_suppress_ve.pad2 ) + rc = -EINVAL ; +else + { +gfn_t gfn =_gfn (a.u.set_mem_access.gfn); +unsigned int altp2m_idx = a.u.set_mem_access.view; +bool suppress_ve = a.u.set_suppress_ve.suppress_ve; + + rc =p2m_set_suppress_ve (d, gfn, suppress_ve, altp2m_idx); + } +break ; +case HVMOP_altp2m_set_mem_access:if ( a.u.set_mem_access.pad ) rc = -EINVAL ;
xen/arch/x86/mm/mem_access.c +55 -0
61 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +11 -0
@@ -38,6 +38,14 @@ struct xen_hvm_param {typedef struct xen_hvm_param xen_hvm_param_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_param_t); +struct xen_hvm_altp2m_set_suppress_ve { +uint16_t view; +uint8_t suppress_ve;/* Boolean type. */ +uint8_t pad1; +uint32_t pad2; +uint64_t gfn; +}; +#if __XEN_INTERFACE_VERSION__ <0x00040900 /* Set the logical level of one of a domain's PCI INTx wires. */
@@ -296,6 +304,8 @@ struct xen_hvm_altp2m_op {#define HVMOP_altp2m_change_gfn 8/* Set access for an array of pages */ #define HVMOP_altp2m_set_mem_access_multi 9 +/* Set the "Suppress #VE" bit on a page */ +#define HVMOP_altp2m_set_suppress_ve 10domid_t domain;uint16_t pad1;uint32_t pad2;
@@ -306,6 +316,7 @@ struct xen_hvm_altp2m_op {struct xen_hvm_altp2m_set_mem_access set_mem_access;struct xen_hvm_altp2m_change_gfn change_gfn;struct xen_hvm_altp2m_set_mem_access_multi set_mem_access_multi; +struct xen_hvm_altp2m_set_suppress_ve set_suppress_ve;uint8_t pad[64 ]; } u; };
xen/include/xen/mem_access.h +3 -0
@@ -72,6 +72,9 @@ long p2m_set_mem_access_multi(struct domain *d, uint32_t nr, uint32_t start, uint32_t mask, unsigned int altp2m_idx); +int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve, +unsigned int altp2m_idx); +/* * Get access type for a gfn. * If gfn == INVALID_GFN, gets the default access type.
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 3/3 x86/altp2m: Add a hvmop for querying the suppress #VE bit
In reply to Adrian Pop--- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_altp2m.c | 32 ++++++++++++++++++++--- xen/arch/x86/hvm/hvm.c | 23 +++++++++++++++-- xen/arch/x86/mm/mem_access.c | 45 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 6 +++-- xen/include/xen/mem_access.h | 3 +++ 6 files changed, 104 insertions(+), 7 deletions(-)
tools/libxc/include/xenctrl.h +2 -0
@@ -1968,6 +1968,8 @@ 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_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,uint16_t view_id,xen_pfn_t gfn,xenmem_access_t access);
tools/libxc/xc_altp2m.c +29 -3
@@ -163,6 +163,32 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid,return rc; } +int xc_altp2m_get_suppress_ve (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t gfn,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_get_suppress_ve; + arg->domain = domid; + arg->u.suppress_ve.view = view_id; + arg->u.suppress_ve.gfn = gfn; + + rc =xencall2 (handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, +HYPERCALL_BUFFER_AS_ARG (arg)); + +if ( !rc ) + *sve = arg->u.suppress_ve.suppress_ve; + +xc_hypercall_buffer_free (handle, arg); +return rc; +} +int xc_altp2m_set_suppress_ve (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t gfn,bool sve) {
@@ -176,9 +202,9 @@ int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid, arg->version =HVMOP_ALTP2M_INTERFACE_VERSION ; arg->cmd = HVMOP_altp2m_set_suppress_ve; arg->domain = domid; - arg->u.set_suppress_ve.view = view_id; - arg->u.set_suppress_ve.gfn = gfn; - arg->u.set_suppress_ve.suppress_ve = sve; + arg->u.suppress_ve.view = view_id; + arg->u.suppress_ve.gfn = gfn; + arg->u.suppress_ve.suppress_ve = sve; rc =xencall2 (handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m,HYPERCALL_BUFFER_AS_ARG (arg));
xen/arch/x86/hvm/hvm.c +21 -2
@@ -4494,6 +4494,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_get_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi:case HVMOP_altp2m_change_gfn:
@@ -4612,18 +4613,36 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_suppress_ve: -if ( a.u.set_suppress_ve.pad1 || a.u.set_suppress_ve.pad2 ) +if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) rc = -EINVAL ;else {gfn_t gfn =_gfn (a.u.set_mem_access.gfn);unsigned int altp2m_idx = a.u.set_mem_access.view; -bool suppress_ve = a.u.set_suppress_ve.suppress_ve; +bool suppress_ve = a.u.suppress_ve.suppress_ve; rc =p2m_set_suppress_ve (d, gfn, suppress_ve, altp2m_idx); }break ; +case HVMOP_altp2m_get_suppress_ve: +if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) + rc = -EINVAL ; +else + { +gfn_t gfn =_gfn (a.u.suppress_ve.gfn); +unsigned int altp2m_idx = a.u.suppress_ve.view; +bool suppress_ve; + + rc =p2m_get_suppress_ve (d, gfn, &suppress_ve, altp2m_idx); +if ( !rc ) + { + a.u.suppress_ve.suppress_ve = suppress_ve; + rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; + } + } +break ; +case HVMOP_altp2m_set_mem_access:if ( a.u.set_mem_access.pad ) rc = -EINVAL ;
xen/arch/x86/mm/mem_access.c +45 -0
51 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +4 -2
@@ -38,7 +38,7 @@ struct xen_hvm_param {typedef struct xen_hvm_param xen_hvm_param_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_param_t); -struct xen_hvm_altp2m_set_suppress_ve { +struct xen_hvm_altp2m_suppress_ve {uint16_t view;uint8_t suppress_ve;/* Boolean type. */ uint8_t pad1;
@@ -306,6 +306,8 @@ struct xen_hvm_altp2m_op {#define HVMOP_altp2m_set_mem_access_multi 9/* Set the "Suppress #VE" bit on a page */ #define HVMOP_altp2m_set_suppress_ve 10 +/* Get the "Suppress #VE" bit of a page */ +#define HVMOP_altp2m_get_suppress_ve 11domid_t domain;uint16_t pad1;uint32_t pad2;
@@ -316,7 +318,7 @@ struct xen_hvm_altp2m_op {struct xen_hvm_altp2m_set_mem_access set_mem_access;struct xen_hvm_altp2m_change_gfn change_gfn;struct xen_hvm_altp2m_set_mem_access_multi set_mem_access_multi; -struct xen_hvm_altp2m_set_suppress_ve set_suppress_ve; +struct xen_hvm_altp2m_suppress_ve suppress_ve;uint8_t pad[64 ]; } u; };
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); +int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, +unsigned int altp2m_idx); +/* * Get access type for a gfn. * If gfn == INVALID_GFN, gets the default access type.
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 3/3] x86/altp2m: Add a hvmop for querying the suppress #VE bit
xen/include/public/hvm/hvm_op.h struct xen_hvm_param { · line 41
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:18, <[email protected]> wrote:
xen/include/public/hvm/hvm_op.h +1
-1@@ -38,7 +38,7 @@ struct xen_hvm_param {typedef struct xen_hvm_param xen_hvm_param_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_param_t); -struct xen_hvm_altp2m_set_suppress_ve { +struct xen_hvm_altp2m_suppress_ve {
Please add this without the "set_" right away in patch 2.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 3/3] x86/altp2m: Add a hvmop for querying the suppress #VE bit
Quoted 11 lines · Jan Beulich
xen/include/public/hvm/hvm_op.h struct xen_hvm_param { · line 41
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 25.07.18 at 13:18, <[email protected]> wrote:
xen/include/public/hvm/hvm_op.h +1
-1@@ -38,7 +38,7 @@ struct xen_hvm_param {typedef struct xen_hvm_param xen_hvm_param_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_param_t); -struct xen_hvm_altp2m_set_suppress_ve { +struct xen_hvm_altp2m_suppress_ve {Please add this without the "
set_" right away in patch 2.
Sure. Thanks!
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel