Add an altp2m subop for obtaining the page mem access
v2 cover Add an altp2m subop for obtaining the page mem access
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.
Changes in v2:
- use the _p2m_get_mem_access helper from p2m_get_mem_access
- minor Arm adjustments
- move out the addition of a memaccess helper function to a separate patch in the attempts of making the diff clearer
Adrian Pop (2):
x86/mem_access: Add a helper function for memaccess conversion x86/altp2m: Add a subop for obtaining the mem access of a page
tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 33 +++++++++++++-- xen/arch/arm/mem_access.c | 8 +++- xen/arch/x86/hvm/hvm.c | 26 ++++++++++-- xen/arch/x86/mm/mem_access.c | 73 +++++++++++++++++++++++---------- xen/common/mem_access.c | 2 +- xen/include/public/hvm/hvm_op.h | 10 +++-- xen/include/xen/mem_access.h | 3 +- 8 files changed, 121 insertions(+), 37 deletions(-)
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/2 x86/mem_access: Add a helper function for memaccess conversion
The p2m_access_to_xenmem_access() converts a p2m_access_t to a xenmem_access_t. It is complementary to xenmem_access_to_p2m_access(). It is currently only used by _p2m_get_mem_access().
--- xen/arch/x86/mm/mem_access.c | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-)
xen/arch/x86/mm/mem_access.c +24 -17
@@ -33,16 +33,12 @@#include "mm-locks.h" /* -* Get access type for a gfn. -* If gfn == INVALID_GFN, gets the default access type. +* Convert a p2m_access_t to a xenmem_access_t. */ -static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, - xenmem_access_t *access) +static int p2m_access_to_xenmem_access(struct p2m_domain *p2m, + p2m_access_t paccess, + xenmem_access_t *xaccess) { - p2m_type_t t; - p2m_access_t a; - mfn_t mfn; - static const xenmem_access_t memaccess[] = { #define ACCESS(ac) [p2m_access_##ac] = XENMEM_access_##ac ACCESS(n),
@@ -58,12 +54,27 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,#undef ACCESS }; +if ( (unsigned int )paccess >=ARRAY_SIZE (memaccess) ) +return -ERANGE ; + + *xaccess = memaccess[paccess]; +return 0 ; +} + +/* +* Get access type for a gfn. +* If gfn == INVALID_GFN, gets the default access type. +*/ +static int _p2m_get_mem_access (struct p2m_domain *p2m,gfn_t gfn, +xenmem_access_t *access) +{ +p2m_type_t t; +p2m_access_t a; +mfn_t mfn; +/* If request to get default access. */ if (gfn_eq (gfn,INVALID_GFN ) ) - { - *access = memaccess[p2m->default_access]; -return 0 ; - } +return p2m_access_to_xenmem_access (p2m, p2m->default_access, access);gfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL ,NULL );
@@ -72,11 +83,7 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,if (mfn_eq (mfn,INVALID_MFN ) )return -ESRCH ; -if ( (unsigned int )a >=ARRAY_SIZE (memaccess) ) -return -ERANGE ; - - *access = memaccess[a]; -return 0 ; +return access_to_xenmem_access (p2m, a, access); } bool p2m_mem_access_emulate_check(struct vcpu *v,
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 1/2] x86/mem_access: Add a helper function for memaccess conversion
Quoted 68 lines · Adrian Pop
The
p2m_access_to_xenmem_access()converts ap2m_access_tto axenmem_access_t. It is complementary toxenmem_access_to_p2m_access(). It is currently only used by_p2m_get_mem_access().Signed-off-by Adrian Pop <[email protected]>--- xen/arch/x86/mm/mem_access.c | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-)xen/arch/x86/mm/mem_access.c +23
-12@@ -33,16 +33,12 @@#include "mm-locks.h" /* -* Get access type for a gfn. -* If gfn == INVALID_GFN, gets the default access type. +* Convert a p2m_access_t to a xenmem_access_t. */ -static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, - xenmem_access_t *access) +static int p2m_access_to_xenmem_access(struct p2m_domain *p2m, + p2m_access_t paccess, + xenmem_access_t *xaccess) { - p2m_type_t t; - p2m_access_t a; - mfn_t mfn; - static const xenmem_access_t memaccess[] = { #define ACCESS(ac) [p2m_access_##ac] = XENMEM_access_##ac ACCESS(n),@@ -58,12 +54,27 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,#undef ACCESS }; +if ( (unsigned int )paccess >=ARRAY_SIZE (memaccess) ) +return -ERANGE ; + + *xaccess = memaccess[paccess]; +return 0 ; +} + +/* +* Get access type for a gfn. +* If gfn == INVALID_GFN, gets the default access type. +*/ +static int _p2m_get_mem_access (struct p2m_domain *p2m,gfn_t gfn, +xenmem_access_t *access) +{ +p2m_type_t t; +p2m_access_t a; +mfn_t mfn; +/* If request to get default access. */ if (gfn_eq (gfn,INVALID_GFN ) ) - { - *access = memaccess[p2m->default_access]; -return 0 ; - } +return p2m_access_to_xenmem_access (p2m, p2m->default_access, access);gfn_lock (p2m, gfn,0 ); mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL ,NULL );
xen/arch/x86/mm/mem_access.c static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, · line 86
Quoted 9 lines
xen/arch/x86/mm/mem_access.c +1
-5@@ -72,11 +83,7 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,if (mfn_eq (mfn,INVALID_MFN ) )return -ESRCH ; -if ( (unsigned int )a >=ARRAY_SIZE (memaccess) ) -return -ERANGE ; - - *access = memaccess[a]; -return 0 ; +return access_to_xenmem_access (p2m, a, access);
Shouldn't this be p2m_access_to_xenmem_access? Did you compile check this patch before sending?
Quoted 5 lines
xen/arch/x86/mm/mem_access.c +0
-1} bool p2m_mem_access_emulate_check(struct vcpu *v, --2.17.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 1/2] x86/mem_access: Add a helper function for memaccess conversion
Quoted 5 lines · Tamas K Lengyel
Quoted 4 lines · Adrian Pop
xen/arch/x86/mm/mem_access.c +0
-0@@ -72,11 +83,7 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,if (mfn_eq (mfn,INVALID_MFN ) )return -ESRCH ;
Quoted 9 lines
xen/arch/x86/mm/mem_access.c static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, · line 86
Quoted 6 lines
xen/arch/x86/mm/mem_access.c +1
-5-if ( (unsigned int )a >=ARRAY_SIZE (memaccess) ) -return -ERANGE ; - - *access = memaccess[a]; -return 0 ; +return access_to_xenmem_access (p2m, a, access);Shouldn't this be
p2m_access_to_xenmem_access? Did you compile check this patch before sending?
Oh, that's right! It seems I've mistakenly used an intermediary version of the patch when testing unfortunately.
Thank you!
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/2 x86/altp2m: Add a subop for obtaining the memaccess of a page
In reply to Adrian PopBoth altp2m get/set memaccess 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.
--- tools/libxc/include/xenctrl.h | 3 +++ tools/libxc/xc_altp2m.c | 33 ++++++++++++++++++++++++++++++--- xen/arch/arm/mem_access.c | 8 ++++++-- xen/arch/x86/hvm/hvm.c | 26 ++++++++++++++++++++++---- xen/arch/x86/mm/mem_access.c | 32 +++++++++++++++++++++++++++----- xen/common/mem_access.c | 2 +- xen/include/public/hvm/hvm_op.h | 10 ++++++---- xen/include/xen/mem_access.h | 3 ++- 8 files changed, 97 insertions(+), 20 deletions(-)
tools/libxc/include/xenctrl.h +3 -0
@@ -1962,6 +1962,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
@@ -177,9 +177,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.hvmmem_access = access; + arg->u.mem_access.gfn = gfn; rc =xencall2 (handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m,HYPERCALL_BUFFER_AS_ARG (arg));
@@ -254,3 +254,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.hvmmem_access; + +xc_hypercall_buffer_free (handle, arg); +return rc; +}
xen/arch/arm/mem_access.c +6 -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,15 @@ 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. */ +if ( altp2m_idx ) +return -EINVAL ; +p2m_read_lock (p2m); ret =__p2m_get_mem_access (d, gfn, access);p2m_read_unlock (p2m);
xen/arch/x86/hvm/hvm.c +22 -4
@@ -4509,6 +4509,7 @@ static int do_altp2m_op(case HVMOP_altp2m_switch_p2m: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 ;
@@ -4625,12 +4626,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.hvmmem_access, + a.u.mem_access.view);break ;case HVMOP_altp2m_set_mem_access_multi:
@@ -4666,6 +4667,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.hvmmem_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 +27 -5
@@ -76,9 +76,9 @@ static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn,if (gfn_eq (gfn,INVALID_GFN ) )return p2m_access_to_xenmem_access (p2m, p2m->default_access, access); -gfn_lock (p2m, gfn,0 ); +p2m_read_lock (p2m); mfn = p2m->get_entry (p2m, gfn, &t, &a,0 ,NULL ,NULL ); -gfn_unlock (p2m, gfn,0 ); +p2m_read_unlock (p2m);if (mfn_eq (mfn,INVALID_MFN ) )return -ESRCH ;
@@ -465,11 +465,33 @@ 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); +struct p2m_domain *host_p2m =p2m_get_hostp2m (d); +struct p2m_domain *p2m; +int rc; + +if ( altp2m_idx ) + { +if ( altp2m_idx >=MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] ==mfn_x (INVALID_MFN ) ) +return -EINVAL ; -return _p2m_get_mem_access (p2m, gfn, access); + p2m = d->arch.altp2m_p2m[altp2m_idx]; + } +else + p2m = host_p2m; + +if ( altp2m_idx ) +p2m_read_lock (host_p2m); + + rc =_p2m_get_mem_access (p2m, gfn, access); + +if ( altp2m_idx ) +p2m_read_unlock (host_p2m); + +return rc; }/*
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 +6 -4
@@ -234,7 +234,7 @@ 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); -struct xen_hvm_altp2m_set_mem_access { +struct xen_hvm_altp2m_mem_access {/* view */ uint16_t view;/* Memory type */
@@ -243,8 +243,8 @@ struct xen_hvm_altp2m_set_mem_access {/* 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); +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 */
@@ -296,6 +296,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 +/* Get the access of a page of memory from a certain view */ +#define HVMOP_altp2m_get_mem_access 10domid_t domain;uint16_t pad1;uint32_t pad2;
@@ -303,7 +305,7 @@ 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; -struct xen_hvm_altp2m_set_mem_access set_mem_access; +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;uint8_t pad[64 ];
xen/include/xen/mem_access.h +2 -1
@@ -76,7 +76,8 @@ long p2m_set_mem_access_multi(struct domain *d,* 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_HAS_MEM_ACCESS int mem_access_memop(unsigned long cmd,
Signature · 7 lines
2.17.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 2/2] x86/altp2m: Add a subop for obtaining the memaccess of a page
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.07.18 at 12:44, <[email protected]> wrote:
Both altp2m get/set memaccess 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]>
Looking through this patch - what's the point of patch 1? There's no further user being introduced here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 2/2] x86/altp2m: Add a subop for obtaining the memaccess of a page
Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.07.18 at 12:44, <[email protected]> wrote:
Both altp2m get/set memaccess 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]>Looking through this patch - what's the point of patch 1? There's no further user being introduced here.
I think it was meant just as code cleanup for now, probably also to be used in later patches.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 2/2] x86/altp2m: Add a subop for obtaining the memaccess of a page
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.07.18 at 12:44, <[email protected]> wrote:
Both altp2m get/set memaccess 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]>Looking through this patch - what's the point of patch 1? There's no further user being introduced here.
It's not entirely necessary. It just cleans up _p2m_get_mem_access() slightly, which would be the only user of the new function. I could drop patch 1 and if it's deemed desirable I could send it separately.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel