x86/altp2m: Add a subop for obtaining the mem access of a page
PATCH v6 1/1 x86/altp2m: Add a subop for obtaining the mem access of a page
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new HVMOP_altp2m_get_mem_access adds this functionality.
Both altp2m get/set mem access functions use the struct xen_hvm_altp2m_mem_access which has now dropped the `set' part and has been renamed from xen_hvm_altp2m_set_mem_access.
---
Changes since V5:
- Fixed the build by conditionally-compiling the altp2m code gated on CONFIG_HVM being #defined.
--- tools/libxc/include/xenctrl.h | 3 +++ tools/libxc/xc_altp2m.c | 33 ++++++++++++++++++++++++++++++--- xen/arch/arm/mem_access.c | 7 +++++-- xen/arch/x86/hvm/hvm.c | 30 ++++++++++++++++++++++++------ xen/arch/x86/mm/mem_access.c | 21 ++++++++++++++++++++- xen/common/mem_access.c | 2 +- xen/include/public/hvm/hvm_op.h | 21 ++++++++++++++++++++- xen/include/public/xen-compat.h | 2 +- xen/include/xen/mem_access.h | 3 ++- 9 files changed, 106 insertions(+), 16 deletions(-)
tools/libxc/include/xenctrl.h +3 -0
@@ -1949,6 +1949,9 @@ int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,int xc_altp2m_set_mem_access_multi (xc_interface *handle,uint32_t domid,uint16_t view_id,uint8_t *access,uint64_t *gfns,uint32_t nr); +int xc_altp2m_get_mem_access (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t gfn, +xenmem_access_t *access);int xc_altp2m_change_gfn (xc_interface *handle,uint32_t domid,uint16_t view_id,xen_pfn_t old_gfn,xen_pfn_t new_gfn);
tools/libxc/xc_altp2m.c +30 -3
@@ -226,9 +226,9 @@ int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid, arg->version =HVMOP_ALTP2M_INTERFACE_VERSION ; arg->cmd = HVMOP_altp2m_set_mem_access; arg->domain = domid; - arg->u.set_mem_access.view = view_id; - arg->u.set_mem_access.hvmmem_access = access; - arg->u.set_mem_access.gfn = gfn; + arg->u.mem_access.view = view_id; + arg->u.mem_access.access = access; + arg->u.mem_access.gfn = gfn; rc =xencall2 (handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m,HYPERCALL_BUFFER_AS_ARG (arg));
@@ -303,3 +303,30 @@ int xc_altp2m_set_mem_access_multi(xc_interface *xch, uint32_t domid,return rc; } + +int xc_altp2m_get_mem_access (xc_interface *handle,uint32_t domid, +uint16_t view_id,xen_pfn_t gfn, +xenmem_access_t *access) +{ +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_mem_access; + arg->domain = domid; + arg->u.mem_access.view = view_id; + arg->u.mem_access.gfn = gfn; + + rc =xencall2 (handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, +HYPERCALL_BUFFER_AS_ARG (arg)); + +if ( !rc ) + *access = arg->u.mem_access.access; + +xc_hypercall_buffer_free (handle, arg); +return rc; +}
xen/arch/arm/mem_access.c +5 -2
@@ -236,7 +236,7 @@ bool p2m_mem_access_check(paddr_t gpa, vaddr_t gla, const struct npfec npfec)if ( !p2m->mem_access_enabled )return true; - rc =p2m_get_mem_access (v->domain,gaddr_to_gfn (gpa), &xma); + rc =p2m_get_mem_access (v->domain,gaddr_to_gfn (gpa), &xma,0 );if ( rc )return true;
@@ -441,11 +441,14 @@ long p2m_set_mem_access_multi(struct domain *d, }int p2m_get_mem_access (struct domain *d,gfn_t gfn, -xenmem_access_t *access) +xenmem_access_t *access,unsigned int altp2m_idx) {int ret;struct p2m_domain *p2m =p2m_get_hostp2m (d); +/* altp2m is not yet implemented on Arm. The altp2m_idx should be 0. */ +ASSERT (altp2m_idx ==0 ); +p2m_read_lock (p2m); ret =__p2m_get_mem_access (d, gfn, access);p2m_read_unlock (p2m);
xen/arch/x86/hvm/hvm.c +24 -6
@@ -4473,6 +4473,7 @@ static int do_altp2m_op(case HVMOP_altp2m_get_suppress_ve:case HVMOP_altp2m_set_mem_access:case HVMOP_altp2m_set_mem_access_multi: +case HVMOP_altp2m_get_mem_access:case HVMOP_altp2m_change_gfn:break ;
@@ -4600,8 +4601,8 @@ static int do_altp2m_op( rc = -EINVAL ; else { -gfn_t gfn =_gfn (a.u.set_mem_access.gfn); -unsigned int altp2m_idx = a.u.set_mem_access.view; +gfn_t gfn =_gfn (a.u.mem_access.gfn); +unsigned int altp2m_idx = a.u.mem_access.view;bool suppress_ve = a.u.suppress_ve.suppress_ve; rc =p2m_set_suppress_ve (d, gfn, suppress_ve, altp2m_idx);
@@ -4627,12 +4628,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access: -if ( a.u.set_mem_access.pad ) +if ( a.u.mem_access.pad ) rc = -EINVAL ;else - rc =p2m_set_mem_access (d,_gfn (a.u.set_mem_access.gfn),1 ,0 ,0 , - a.u.set_mem_access.hvmmem_access, - a.u.set_mem_access.view); + rc =p2m_set_mem_access (d,_gfn (a.u.mem_access.gfn),1 ,0 ,0 , + a.u.mem_access.access, + a.u.mem_access.view);break ;case HVMOP_altp2m_set_mem_access_multi:
@@ -4668,6 +4669,23 @@ static int do_altp2m_op( }break ; +case HVMOP_altp2m_get_mem_access: +if ( a.u.mem_access.pad ) + rc = -EINVAL ; +else + { +xenmem_access_t access; + + rc =p2m_get_mem_access (d,_gfn (a.u.mem_access.gfn), &access, + a.u.mem_access.view); +if ( !rc ) + { + a.u.mem_access.access = access; + rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; + } + } +break ; +case HVMOP_altp2m_change_gfn:if ( a.u.change_gfn.pad1 || a.u.change_gfn.pad2 ) rc = -EINVAL ;
xen/arch/x86/mm/mem_access.c +20 -1
@@ -486,10 +486,29 @@ long p2m_set_mem_access_multi(struct domain *d,return rc; } -int p2m_get_mem_access (struct domain *d,gfn_t gfn,xenmem_access_t *access) +int p2m_get_mem_access (struct domain *d,gfn_t gfn,xenmem_access_t *access, +unsigned int altp2m_idx) {struct p2m_domain *p2m =p2m_get_hostp2m (d); +#ifdef CONFIG_HVM +if ( !altp2m_active (d) ) + { +if ( altp2m_idx ) +return -EINVAL ; + } +else + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; + + p2m = d->arch.altp2m_p2m[altp2m_idx]; + } +#else +ASSERT (!altp2m_idx); +#endif +return _p2m_get_mem_access (p2m, gfn, access); }
xen/common/mem_access.c +1 -1
@@ -99,7 +99,7 @@ int mem_access_memop(unsigned long cmd,if ( (mao.pfn >domain_get_maximum_gpfn (d)) && mao.pfn != ~0ull )break ; - rc =p2m_get_mem_access (d,_gfn (mao.pfn), &access); + rc =p2m_get_mem_access (d,_gfn (mao.pfn), &access,0 );if ( rc !=0 )break ;
xen/include/public/hvm/hvm_op.h +20 -1
@@ -242,17 +242,31 @@ struct xen_hvm_altp2m_view {typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_view_t); +#if __XEN_INTERFACE_VERSION__ <0x00040a00 struct xen_hvm_altp2m_set_mem_access {/* view */ uint16_t view;/* Memory type */ -uint16_t hvmmem_access;/* xenmem_access_t */ +uint16_t access;/* xenmem_access_t */ uint32_t pad;/* gfn */ uint64_t gfn; };typedef struct xen_hvm_altp2m_set_mem_access xen_hvm_altp2m_set_mem_access_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_set_mem_access_t); +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040a00 */ + +struct xen_hvm_altp2m_mem_access { +/* view */ +uint16_t view; +/* Memory type */ +uint16_t access;/* xenmem_access_t */ +uint32_t pad; +/* gfn */ +uint64_t gfn; +}; +typedef struct xen_hvm_altp2m_mem_access xen_hvm_altp2m_mem_access_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_altp2m_mem_access_t);struct xen_hvm_altp2m_set_mem_access_multi {/* view */
@@ -308,6 +322,8 @@ struct xen_hvm_altp2m_op {#define HVMOP_altp2m_set_suppress_ve 10/* Get the "Suppress #VE" bit of a page */ #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 12domid_t domain;uint16_t pad1;uint32_t pad2;
@@ -315,7 +331,10 @@ struct xen_hvm_altp2m_op {struct xen_hvm_altp2m_domain_state domain_state;struct xen_hvm_altp2m_vcpu_enable_notify enable_notify;struct xen_hvm_altp2m_view view; +#if __XEN_INTERFACE_VERSION__ <0x00040a00 struct xen_hvm_altp2m_set_mem_access set_mem_access; +#endif /* __XEN_INTERFACE_VERSION__ < 0x00040a00 */ +struct xen_hvm_altp2m_mem_access 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_suppress_ve suppress_ve;
xen/include/public/xen-compat.h +1 -1
@@ -27,7 +27,7 @@#ifndef __XEN_PUBLIC_XEN_COMPAT_H__#define __XEN_PUBLIC_XEN_COMPAT_H__ -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040900 +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040a00#if defined(__XEN__) || defined(__XEN_TOOLS__)/* Xen is built with matching headers and implements the latest interface. */
xen/include/xen/mem_access.h +2 -1
@@ -82,7 +82,8 @@ int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve,* Get access type for a gfn. * If gfn == INVALID_GFN, gets the default access type. */ -int p2m_get_mem_access (struct domain *d,gfn_t gfn,xenmem_access_t *access); +int p2m_get_mem_access (struct domain *d,gfn_t gfn,xenmem_access_t *access, +unsigned int altp2m_idx);#ifdef CONFIG_MEM_ACCESS int mem_access_memop(unsigned long cmd,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>
Quoted 7 lines
---
Changes since V5:
- Fixed the build by conditionally-compiling the altp2m code gated onCONFIG_HVMbeing #defined.--- tools/libxc/include/xenctrl.h | 3 +++ tools/libxc/xc_altp2m.c | 33 ++++++++++++++++++++++++++++++---
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Wei Liu
Quoted 11 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>Quoted 7 lines
---
Changes since V5:
- Fixed the build by conditionally-compiling the altp2m code gated onCONFIG_HVMbeing #defined.--- tools/libxc/include/xenctrl.h | 3 +++ tools/libxc/xc_altp2m.c | 33 ++++++++++++++++++++++++++++++---
Quoted 1 line
Acked-by Wei Liu <[email protected]>
Thanks! Tamas, George, is the patch OK with you?
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>
LGTM
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Tamas K Lengyel
Quoted 9 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>LGTM
Acked-by Tamas K Lengyel <[email protected]>
Thanks! If I'm not mistaken, we now only need George's ack to commit this patch (which concludes our #VE-related series - the only thing still remaining after this is to fix the logdirty VGA issue as far as we're concerned).
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>
Sorry it took so long to get to this:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · George Dunlap
Quoted 8 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>Sorry it took so long to get to this:
Reviewed-by George Dunlap <[email protected]>
Although -- looking through the patch, I don't think this needed my ack.
All the code was either directly memaccess or toolstack related; Wei
and Tamas' acks should have been enough for it to go in.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · George Dunlap
Quoted 8 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>Sorry it took so long to get to this:
Reviewed-by George Dunlap <[email protected]>
No problem at all. Thanks!
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>
I'm not sure if this patch has been applied. If not I will do it during my next sweep.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Wei Liu
Quoted 8 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>I'm not sure if this patch has been applied. If not I will do it during my next sweep.
Hello Wei,
It's been applied:
https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=7559ab7830c3e1594cd73efd3f1acbb171036728
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Razvan Cojocaru
Quoted 12 lines · Wei Liu
Quoted 10 lines · Razvan Cojocaru
Currently there is a subop for setting the memaccess of a page, but not for consulting it. The new
HVMOP_altp2m_get_mem_accessadds this functionality.Both altp2m get/set mem access functions use the struct
xen_hvm_altp2m_mem_accesswhich has now dropped the `set' part and has been renamed fromxen_hvm_altp2m_set_mem_access.Signed-off-by Adrian Pop <[email protected]>Signed-off-by Razvan Cojocaru <[email protected]>
Quoted 7 lines
Quoted 2 lines
I'm not sure if this patch has been applied. If not I will do it during my next sweep.
Hello Wei,
It's been applied:
https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=7559ab7830c3e1594cd73efd3f1acbb171036728
Thanks for letting me know.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel