Make mem_access APIs and hypercalls generic
v3 cover Make mem_access APIs and hypercalls generic
This is a precusor patch to the one that enables mem_access for PV domains.
The mem_access APIs, hypercalls and structures all have HVM specific naming. As a first step to making this work for PV domains, this patch renames them in a more generic fashion.
x86/mem_access: Make the mem_access ops generic tools/libxc: Make the mem_access APIs generic tools/xen-access: Use the new mem_access APIs tools/libxc: Remove xc_hvm_[sg]et_mem_access() APIs x86/mem_access: Deprecate the HVM mem_access ops
tools/libxc/xc_mem_access.c | 54 +++++++++++++++++++++++--- tools/libxc/xc_misc.c | 61 ------------------------------ tools/libxc/xenctrl.h | 32 ++++++++-------- tools/tests/xen-access/xen-access.c | 34 ++++++++--------- xen/arch/x86/hvm/hvm.c | 74 +----------------------------------- xen/arch/x86/mm.c | 6 ++- xen/arch/x86/mm/mem_access.c | 75 ++++++++++++++++++++++++++++++++++--- xen/arch/x86/mm/mem_event.c | 3 -- xen/arch/x86/mm/p2m.c | 31 ++++++++------- xen/arch/x86/x86_64/compat/mm.c | 16 +++++--- xen/arch/x86/x86_64/mm.c | 11 +++++- xen/common/compat/memory.c | 2 + xen/common/memory.c | 2 +- xen/include/asm-x86/mem_access.h | 3 +- xen/include/asm-x86/mm.h | 6 +-- xen/include/asm-x86/p2m.h | 6 +-- xen/include/public/hvm/hvm_op.h | 42 +-------------------- xen/include/public/memory.h | 53 ++++++++++++++++++++++++-- xen/include/xlat.lst | 1 + 19 files changed, 256 insertions(+), 256 deletions(-)
Signature · 1 line
1.8.3.2
PATCH v3 1/5 x86/mem_access: Make the mem_access ops generic
This patch does the following:
1. Add mem_access ops under XENMEM_access_ops.
2. Add enums and structs whose names are generic.
---
Changes from version 2 of the patch:
1. Move deprecation of HVM ops and removal of enums and structs associated with them to a seperate patch.
2. Fix return on errors in mem_access_memop().
3. Use XENMEM_access_op when setting up hypercall continuation.
4. Remove pointless opening braces.
Changes from version 1 of the patch:
1. Use MEMOP_CMD_MASK instead of introducing a new mask.
2. Pass "cmd" down from do_memory_op() instead of "op" and "start_extent".
3. Pass typed handle to mem_access_memop() and use __copy_field_to_guest().
4. Use ACCESS() macro to remove ordering dependency.
5. Add compat verification for xen_mem_access_op_t.
6. Fix formatting.
Changes from the RFC version of the patch:
1. Removed pointless braces.
2. Change preemption handling to use upper "cmd" bits from do_memory_op().
3. Delete old interface enum and structs.
4. Remove xenmem_ prefix.
5. Make access uint8_t and place above domid.
xen/arch/x86/hvm/hvm.c +1 -1
@@ -4632,7 +4632,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) {struct xen_hvm_get_mem_access a;struct domain *d; -hvmmem_access_t access; +xenmem_access_t access;if (copy_from_guest (&a, arg,1 ) )return -EFAULT ;
xen/arch/x86/mm.c +4 -2
@@ -104,6 +104,7 @@#include <xen/xmalloc.h> #include <xen/efi.h> #include <xen/grant_table.h> +#include <xen/hypercall.h> #include <asm/paging.h> #include <asm/shadow.h> #include <asm/page.h>
@@ -4631,9 +4632,10 @@ int xenmem_add_to_physmap_one(return rc; } -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) +long arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {int rc; +int op = cmd &MEMOP_CMD_MASK ;switch ( op ) {
@@ -4853,7 +4855,7 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg) }default : -return subarch_memory_op (op, arg); +return subarch_memory_op (cmd, arg); }return 0 ;
xen/arch/x86/mm/mem_access.c +69 -6
100 lines not on this page · raw message
xen/arch/x86/mm/mem_event.c +0 -3
@@ -458,9 +458,6 @@ int do_mem_event_op(int op, uint32_t domain, void *arg)case XENMEM_paging_op: ret =mem_paging_memop (d, (xen_mem_event_op_t *) arg);break ; -case XENMEM_access_op: - ret =mem_access_memop (d, (xen_mem_event_op_t *) arg); -break ;case XENMEM_sharing_op: ret =mem_sharing_memop (d, (xen_mem_sharing_op_t *) arg);break ;
xen/arch/x86/mm/p2m.c +17 -14
@@ -1350,7 +1350,7 @@ void p2m_mem_access_resume(struct domain *d)/* Set access type for a region of pfns. * If start_pfn == -1ul, sets the default access type */ long p2m_set_mem_access (struct domain *d,unsigned long pfn,uint32_t nr, -uint32_t start,uint32_t mask,hvmmem_access_t access) +uint32_t start,uint32_t mask,xenmem_access_t access) {struct p2m_domain *p2m =p2m_get_hostp2m (d);p2m_access_t a, _a;
@@ -1359,7 +1359,7 @@ long p2m_set_mem_access(struct domain *d, unsigned long pfn, uint32_t nr,long rc =0 ;static const p2m_access_t memaccess[] = { -#define ACCESS(ac) [HVMMEM_access_##ac] = p2m_access_##ac +#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac ACCESS(n), ACCESS(r), ACCESS(w),
@@ -1378,7 +1378,7 @@ long p2m_set_mem_access(struct domain *d, unsigned long pfn, uint32_t nr, case 0 ... ARRAY_SIZE(memaccess) - 1: a = memaccess[access];break ; -case HVMMEM_access_default: +case XENMEM_access_default: a = p2m->default_access;break ;default :
@@ -1416,23 +1416,26 @@ long p2m_set_mem_access(struct domain *d, unsigned long pfn, uint32_t nr,/* Get access type for a pfn * If pfn == -1ul, gets the default access type */ int p2m_get_mem_access (struct domain *d,unsigned long pfn, -hvmmem_access_t *access) +xenmem_access_t *access) {struct p2m_domain *p2m =p2m_get_hostp2m (d);p2m_type_t t;p2m_access_t a;mfn_t mfn; -static const hvmmem_access_t memaccess[] = { - HVMMEM_access_n, - HVMMEM_access_r, - HVMMEM_access_w, - HVMMEM_access_rw, - HVMMEM_access_x, - HVMMEM_access_rx, - HVMMEM_access_wx, - HVMMEM_access_rwx, - HVMMEM_access_rx2rw +static const xenmem_access_t memaccess[] = { +#define ACCESS(ac) [XENMEM_access_##ac] = XENMEM_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 request to get default access */
xen/arch/x86/x86_64/compat/mm.c +11 -5
@@ -4,6 +4,7 @@#include <compat/xen.h> #include <asm/mem_event.h> #include <asm/mem_sharing.h> +#include <asm/mem_access.h> int compat_set_gdt (XEN_GUEST_HANDLE_PARAM (uint) frame_list,unsigned int entries) {
@@ -44,7 +45,7 @@ int compat_update_descriptor(u32 pa_lo, u32 pa_hi, u32 desc_lo, u32 desc_hi) desc_lo | ((u64)desc_hi << 32)); } -int compat_arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) +int compat_arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct compat_machphys_mfn_list xmml;l2_pgentry_t l2e;
@@ -52,6 +53,7 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)compat_pfn_t mfn;unsigned int i;int rc =0 ; +int op = cmd &MEMOP_CMD_MASK ;switch ( op ) {
@@ -68,7 +70,7 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)XLAT_foreign_memory_map (nat, &cmp);#undef XLAT_memory_map_HNDL_buffer - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); + rc =arch_memory_op (cmd,guest_handle_from_ptr (nat, void));break ; }
@@ -87,7 +89,7 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)XLAT_memory_map (nat, &cmp);#undef XLAT_memory_map_HNDL_buffer - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); + rc =arch_memory_op (cmd,guest_handle_from_ptr (nat, void));if ( rc <0 )break ;
@@ -111,7 +113,7 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)XLAT_pod_target (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); + rc =arch_memory_op (cmd,guest_handle_from_ptr (nat, void));if ( rc <0 )break ;
@@ -185,7 +187,6 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)return mem_sharing_get_nr_shared_mfns ();case XENMEM_paging_op: -case XENMEM_access_op: {xen_mem_event_op_t meo;if (copy_from_guest (&meo, arg,1 ) )
@@ -195,6 +196,11 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)return -EFAULT ;break ; } + +case XENMEM_access_op: + rc =mem_access_memop (cmd,guest_handle_cast (arg, xen_mem_access_op_t)); +break ; +case XENMEM_sharing_op: {xen_mem_sharing_op_t mso;
xen/arch/x86/x86_64/mm.c +9 -2
@@ -25,6 +25,7 @@#include <xen/numa.h> #include <xen/nodemask.h> #include <xen/guest_access.h> +#include <xen/hypercall.h> #include <asm/current.h> #include <asm/asm_defns.h> #include <asm/page.h>
@@ -36,6 +37,7 @@#include <asm/numa.h> #include <asm/mem_event.h> #include <asm/mem_sharing.h> +#include <asm/mem_access.h> #include <public/memory.h> /* Parameters for PFN/MADDR compression. */
@@ -948,7 +950,7 @@ void __init subarch_init_memory(void) } } -long subarch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) +long subarch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct xen_machphys_mfn_list xmml;l3_pgentry_t l3e;
@@ -957,6 +959,7 @@ long subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)xen_pfn_t mfn, last_mfn;unsigned int i;long rc =0 ; +int op = cmd &MEMOP_CMD_MASK ;switch ( op ) {
@@ -1007,7 +1010,6 @@ long subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)return mem_sharing_get_nr_shared_mfns ();case XENMEM_paging_op: -case XENMEM_access_op: {xen_mem_event_op_t meo;if (copy_from_guest (&meo, arg,1 ) )
@@ -1017,6 +1019,11 @@ long subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)return -EFAULT ;break ; } + +case XENMEM_access_op: + rc =mem_access_memop (cmd,guest_handle_cast (arg, xen_mem_access_op_t)); +break ; +case XENMEM_sharing_op: {xen_mem_sharing_op_t mso;
xen/common/compat/memory.c +2 -0
@@ -13,6 +13,8 @@ CHECK_TYPE(domid);#undef compat_domid_t#undef xen_domid_t +CHECK_mem_access_op; +int compat_memory_op (unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) compat) {int split, op = cmd &MEMOP_CMD_MASK ;
xen/common/memory.c +1 -1
@@ -964,7 +964,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ;default : - rc =arch_memory_op (op, arg); + rc =arch_memory_op (cmd, arg);break ; }
xen/include/asm-x86/mem_access.h +2 -1
@@ -23,7 +23,8 @@#ifndef _XEN_ASM_MEM_ACCESS_H#define _XEN_ASM_MEM_ACCESS_H -int mem_access_memop (struct domain *d,xen_mem_event_op_t *meo); +int mem_access_memop (unsigned long cmd, +XEN_GUEST_HANDLE_PARAM (xen_mem_access_op_t) arg);int mem_access_send_req (struct domain *d,mem_event_request_t *req);#endif /* _XEN_ASM_MEM_ACCESS_H */
xen/include/asm-x86/mm.h +3 -3
@@ -561,9 +561,9 @@ void *do_page_walk(struct vcpu *v, unsigned long addr);int __sync_local_execstate (void );/* Arch-specific portion of memory_op hypercall. */ -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg); -long subarch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg); -int compat_arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void )); +long arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +long subarch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +int compat_arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ));int compat_subarch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void )); int steal_page(
xen/include/asm-x86/p2m.h +3 -3
@@ -577,12 +577,12 @@ void p2m_mem_access_resume(struct domain *d);/* Set access type for a region of pfns. * If start_pfn == -1ul, sets the default access type */ long p2m_set_mem_access (struct domain *d,unsigned long start_pfn,uint32_t nr, -uint32_t start,uint32_t mask,hvmmem_access_t access); +uint32_t start,uint32_t mask,xenmem_access_t access);/* Get access type for a pfn * If pfn == -1ul, gets the default access type */ -int p2m_get_mem_access (struct domain *d,unsigned long pfn, -hvmmem_access_t *access); +int p2m_get_mem_access (struct domain *d,unsigned long pfn, +xenmem_access_t *access);/* * Internal functions, only called by other p2m code
xen/include/public/memory.h +50 -3
65 lines not on this page · raw message
xen/include/xlat.lst +1 -0
@@ -60,6 +60,7 @@ ! memory_exchange memory.h ! memory_map memory.h ! memory_reservation memory.h +? mem_access_op memory.h ! pod_target memory.h ! remove_from_physmap memory.h ? physdev_eoi physdev.h
Signature · 1 line
1.8.3.2
Re: [PATCH v3 1/5] x86/mem_access: Make the mem_access ops generic
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.04.14 at 02:25, <[email protected]> wrote:
This patch does the following:
1. Addmem_accessops underXENMEM_access_ops.
2. Add enums and structs whose names are generic.Signed-off-by Aravindh Puthiyaparambil <[email protected]>Cc Keir Fraser <[email protected]>
Quoted 1 line
Cc Tim Deegan <[email protected]>
PATCH v3 2/5 tools/libxc: Make the mem_access APIs generic
In reply to Aravindh PuthiyaparambilAdd new xc_[sg]et_mem_access() APIs.
---
Changes from version 2 of the patch:
1. Move removal of xc_hvm_[sg]et_mem_access() APIs into a seperate patch.
Changes from version 1 of the patch:
1. Remove unused "gfn" from the parameter list of xc_mem_access_resume().
2. Use structure initialisation.
3. Write "access" back only in the case of do_memory_op returning success.
4. Fix formatting.
Changes from the RFC version of the patch:
1. Remove xc_mem_access_memop() wrapper.
2. Remove xc_hvm_[sg]et_mem_access() APIs.
tools/libxc/xc_mem_access.c +48 -6
@@ -22,7 +22,7 @@*/ #include "xc_private.h" - +#include <xen/memory.h> int xc_mem_access_enable (xc_interface *xch,domid_t domain_id,uint32_t *port)
@@ -47,12 +47,54 @@ int xc_mem_access_disable(xc_interface *xch, domid_t domain_id) NULL); } -int xc_mem_access_resume (xc_interface *xch,domid_t domain_id,unsigned long gfn) +int xc_mem_access_resume (xc_interface *xch,domid_t domain_id) +{ +xen_mem_access_op_t mao = + { + .op = XENMEM_access_op_resume, + .domid = domain_id + }; + +return do_memory_op (xch, XENMEM_access_op, &mao,sizeof (mao)); +} + +int xc_set_mem_access (xc_interface *xch, +domid_t domain_id, +xenmem_access_t access, +uint64_t first_pfn, +uint32_t nr) { -return xc_mem_event_memop (xch, domain_id, - XENMEM_access_op_resume, - XENMEM_access_op, - gfn,NULL ); +xen_mem_access_op_t mao = + { + .op = XENMEM_access_op_set_access, + .domid = domain_id, + .access = access, + .pfn = first_pfn, + .nr = nr + }; + +return do_memory_op (xch, XENMEM_access_op, &mao,sizeof (mao)); +} + +int xc_get_mem_access (xc_interface *xch, +domid_t domain_id, +uint64_t pfn, +xenmem_access_t *access) +{ +int rc; +xen_mem_access_op_t mao = + { + .op = XENMEM_access_op_get_access, + .domid = domain_id, + .pfn = pfn + }; + + rc =do_memory_op (xch, XENMEM_access_op, &mao,sizeof (mao)); + +if ( rc ==0 ) + *access = mao.access; + +return rc; }/*
tools/libxc/xenctrl.h +16 -2
@@ -2059,8 +2059,22 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,*/ int xc_mem_access_enable (xc_interface *xch,domid_t domain_id,uint32_t *port);int xc_mem_access_disable (xc_interface *xch,domid_t domain_id); -int xc_mem_access_resume (xc_interface *xch,domid_t domain_id, -unsigned long gfn); +int xc_mem_access_resume (xc_interface *xch,domid_t domain_id); + +/* +* Set a range of memory to a specific access. +* Allowed types are XENMEM_access_default, XENMEM_access_n, any combination of +* XENMEM_access_ + (rwx), and XENMEM_access_rx2rw +*/ +int xc_set_mem_access (xc_interface *xch,domid_t domain_id, +xenmem_access_t access,uint64_t first_pfn, +uint32_t nr); + +/* +* Gets the mem access for the given page (returned in access on success) +*/ +int xc_get_mem_access (xc_interface *xch,domid_t domain_id, +uint64_t pfn,xenmem_access_t *access);/*** * Memory sharing operations.
Signature · 1 line
1.8.3.2
Re: [PATCH v3 2/5] tools/libxc: Make the mem_access APIs generic
Quoted 5 lines · Aravindh Puthiyaparambil
Add new xc_[sg]et_mem_access() APIs.
Signed-off-by Aravindh Puthiyaparambil <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>
(I assume this will be committed by a hypervisor person along with the hypercall bits of the series)
Re: [PATCH v3 2/5] tools/libxc: Make the mem_access APIs generic
In reply to Aravindh PuthiyaparambilQuoted 116 lines · Aravindh Puthiyaparambil
Add new xc_[sg]et_mem_access() APIs.
Signed-off-by Aravindh Puthiyaparambil <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>---
Changes from version 2 of the patch:
1. Move removal of xc_hvm_[sg]et_mem_access() APIs into a seperate patch.Changes from version 1 of the patch:
1. Remove unused "gfn" from the parameter list ofxc_mem_access_resume().
2. Use structure initialisation.
3. Write "access" back only in the case ofdo_memory_opreturning success.
4. Fix formatting.Changes from the RFC version of the patch:
1. Removexc_mem_access_memop()wrapper.
2. Remove xc_hvm_[sg]et_mem_access() APIs.tools/libxc/xc_mem_access.c +48
-6@@ -22,7 +22,7 @@*/ #include "xc_private.h" - +#include <xen/memory.h> int xc_mem_access_enable (xc_interface *xch,domid_t domain_id,uint32_t *port)@@ -47,12 +47,54 @@ int xc_mem_access_disable(xc_interface *xch, domid_t domain_id) NULL); } -int xc_mem_access_resume (xc_interface *xch,domid_t domain_id,unsigned long gfn) +int xc_mem_access_resume (xc_interface *xch,domid_t domain_id) +{ +xen_mem_access_op_t mao = + { + .op = XENMEM_access_op_resume, + .domid = domain_id + }; + +return do_memory_op (xch, XENMEM_access_op, &mao,sizeof (mao)); +} + +int xc_set_mem_access (xc_interface *xch, +domid_t domain_id, +xenmem_access_t access, +uint64_t first_pfn, +uint32_t nr) { -return xc_mem_event_memop (xch, domain_id, - XENMEM_access_op_resume, - XENMEM_access_op, - gfn,NULL ); +xen_mem_access_op_t mao = + { + .op = XENMEM_access_op_set_access, + .domid = domain_id, + .access = access, + .pfn = first_pfn, + .nr = nr + }; + +return do_memory_op (xch, XENMEM_access_op, &mao,sizeof (mao)); +} + +int xc_get_mem_access (xc_interface *xch, +domid_t domain_id, +uint64_t pfn, +xenmem_access_t *access) +{ +int rc; +xen_mem_access_op_t mao = + { + .op = XENMEM_access_op_get_access, + .domid = domain_id, + .pfn = pfn + }; + + rc =do_memory_op (xch, XENMEM_access_op, &mao,sizeof (mao)); + +if ( rc ==0 ) + *access = mao.access; + +return rc; }/*
tools/libxc/xenctrl.h +5
-2@@ -2059,8 +2059,22 @@ int xc_mem_paging_load(xc_interface *xch, domid_tdomain_id, */ int xc_mem_access_enable (xc_interface *xch,domid_t domain_id,uint32_t *port);int xc_mem_access_disable (xc_interface *xch,domid_t domain_id); -int xc_mem_access_resume (xc_interface *xch,domid_t domain_id, -unsigned long gfn); +int xc_mem_access_resume (xc_interface *xch,domid_t domain_id); + +/* +* Set a range of memory to a specific access. +* Allowed types are XENMEM_access_default, XENMEM_access_n, any
Quoted 4 lines
combination of
+ *XENMEM_access_+ (rwx), andXENMEM_access_rx2rw
+ */
What about XENMEM_access_n2rwx?
Quoted 16 lines
tools/libxc/xenctrl.h +9
-1+int xc_set_mem_access (xc_interface *xch,domid_t domain_id, +xenmem_access_t access,uint64_t first_pfn, +uint32_t nr); + +/* +* Gets the mem access for the given page (returned in access on success) +*/ +int xc_get_mem_access (xc_interface *xch,domid_t domain_id, +uint64_t pfn,xenmem_access_t *access);/*** * Memory sharing operations. -- 1.8.3.2
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 2/5] tools/libxc: Make the mem_access APIs generic
Quoted 18 lines
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index e3a32f2..3513ddb 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2059,8 +2059,22 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id, */ int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
uint32_t*port);
intxc_mem_access_disable(xc_interface *xch, domid_t domain_id);
-int xc_mem_access_resume(xc_interface *xch,domid_tdomain_id,
- unsigned long gfn);
+int xc_mem_access_resume(xc_interface *xch,domid_tdomain_id); + +/* + * Set a range of memory to a specific access. + * Allowed types are XENMEM_access_default, XENMEM_access_n,
Quoted 7 lines
any combination of
+ *XENMEM_access_+ (rwx), andXENMEM_access_rx2rw
+ */What about
XENMEM_access_n2rwx?
That should work too. The patch does add or remove any functionality. I just copied the API description over from the original xc_hvm_set_mem_access(). So whoever added access_n2rwx did not update the description. I have more patches in this area so I will update it in the next go around or you can submit a patch once this one goes in.
Thanks,
Aravindh
Re: [PATCH v3 2/5] tools/libxc: Make the mem_access APIs generic
Quoted 26 lines · Aravindh Puthiyaparambil (aravindp)
Quoted 24 lines
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index e3a32f2..3513ddb 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2059,8 +2059,22 @@ int xc_mem_paging_load(xc_interface*xch,
domid_tdomain_id,
*/
int xc_mem_access_enable(xc_interface *xch,domid_tdomain_id,uint32_t*port);
intxc_mem_access_disable(xc_interface *xch, domid_t domain_id);
-int xc_mem_access_resume(xc_interface *xch,domid_tdomain_id,
- unsigned long gfn);
+int xc_mem_access_resume(xc_interface *xch,domid_tdomain_id);
+
+/*
+ * Set a range of memory to a specific access.
+ * Allowed types areXENMEM_access_default,XENMEM_access_n,
any combination of
+ *XENMEM_access_+ (rwx), andXENMEM_access_rx2rw
+ */Quoted 1 line
What about
XENMEM_access_n2rwx?
Quoted 10 lines
That should work too. The patch does add or remove any functionality. I just copied the API description over from the original
xc_hvm_set_mem_access(). So whoever addedaccess_n2rwxdid not update the description. I have more patches in this area so I will update it in the next go around or you can submit a patch once this one goes in.Thanks,
Aravindh
If you are already at it, might as well fix the comment too.
Thanks!
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v3 3/5 tools/xen-access: Use the new mem_access APIs
In reply to Aravindh PuthiyaparambilModify the xen-access test program to use the new mem_access APIs.
---
No changes from version 2 of the patch.
Changes from version 1 of the patch:
Remove extra "gfn" parameter from xc_mem_access_resume() call.
tools/tests/xen-access/xen-access.c +17 -17
@@ -410,8 +410,7 @@ static int xenaccess_resume_page(xenaccess_t *paging, mem_event_response_t *rsp) goto out;/* Tell Xen page is ready */ - ret =xc_mem_access_resume (paging->xc_handle, paging->mem_event.domain_id, - rsp->gfn); + ret =xc_mem_access_resume (paging->xc_handle, paging->mem_event.domain_id); ret =xc_evtchn_notify (paging->mem_event.xce_handle, paging->mem_event.port);
@@ -440,8 +439,8 @@ int main(int argc, char *argv[])int rc =-1 ;int rc1;xc_interface *xch; -hvmmem_access_t default_access = HVMMEM_access_rwx; -hvmmem_access_t after_first_access = HVMMEM_access_rwx; +xenmem_access_t default_access = XENMEM_access_rwx; +xenmem_access_t after_first_access = XENMEM_access_rwx;int required =0 ;int int3 =0 ;int shutting_down =0 ;
@@ -475,13 +474,13 @@ int main(int argc, char *argv[])if ( !strcmp (argv[0 ],"write" ) ) { - default_access = HVMMEM_access_rx; - after_first_access = HVMMEM_access_rwx; + default_access = XENMEM_access_rx; + after_first_access = XENMEM_access_rwx; }else if ( !strcmp (argv[0 ],"exec" ) ) { - default_access = HVMMEM_access_rw; - after_first_access = HVMMEM_access_rwx; + default_access = XENMEM_access_rw; + after_first_access = XENMEM_access_rwx; }else if ( !strcmp (argv[0 ],"int3" ) ) {
@@ -520,15 +519,15 @@ int main(int argc, char *argv[]) }/* Set the default access type and convert all pages to it */ - rc =xc_hvm_set_mem_access (xch, domain_id, default_access, ~0ull ,0 ); + rc =xc_set_mem_access (xch, domain_id, default_access, ~0ull ,0 );if ( rc <0 ) {ERROR ("Error %d setting default mem access type\n" , rc); goto exit; } - rc =xc_hvm_set_mem_access (xch, domain_id, default_access,0 , - xenaccess->domain_info->max_pages); + rc =xc_set_mem_access (xch, domain_id, default_access,0 , + xenaccess->domain_info->max_pages);if ( rc <0 ) { ERROR("Error %d setting all memory to access type %d\n", rc,
@@ -554,8 +553,9 @@ int main(int argc, char *argv[])DPRINTF ("xenaccess shutting down on signal %d\n" , interrupted);/* Unregister for every event */ - rc =xc_hvm_set_mem_access (xch, domain_id, HVMMEM_access_rwx, ~0ull ,0 ); - rc =xc_hvm_set_mem_access (xch, domain_id, HVMMEM_access_rwx,0 , xenaccess->domain_info->max_pages); + rc =xc_set_mem_access (xch, domain_id, XENMEM_access_rwx, ~0ull ,0 ); + rc =xc_set_mem_access (xch, domain_id, XENMEM_access_rwx,0 , + xenaccess->domain_info->max_pages); rc =xc_set_hvm_param (xch, domain_id,HVM_PARAM_MEMORY_EVENT_INT3 , HVMPME_mode_disabled); shutting_down =1 ;
@@ -575,7 +575,7 @@ int main(int argc, char *argv[])while (RING_HAS_UNCONSUMED_REQUESTS (&xenaccess->mem_event.back_ring) ) { -hvmmem_access_t access; +xenmem_access_t access; rc =get_request (&xenaccess->mem_event, &req);if ( rc !=0 )
@@ -591,7 +591,7 @@ int main(int argc, char *argv[])switch (req.reason) {case MEM_EVENT_REASON_VIOLATION : - rc =xc_hvm_get_mem_access (xch, domain_id, req.gfn, &access); + rc =xc_get_mem_access (xch, domain_id, req.gfn, &access);if (rc <0 ) {ERROR ("Error %d getting mem_access event\n" , rc);
@@ -611,8 +611,8 @@ int main(int argc, char *argv[])if ( default_access != after_first_access ) { - rc =xc_hvm_set_mem_access (xch, domain_id, - after_first_access, req.gfn,1 ); + rc =xc_set_mem_access (xch, domain_id, after_first_access, + req.gfn,1 );if (rc <0 ) { ERROR("Error %d setting gfn to access_type %d\n", rc,
Signature · 1 line
1.8.3.2
Re: [PATCH v3 3/5] tools/xen-access: Use the new mem_access APIs
Quoted 5 lines · Aravindh Puthiyaparambil
Modify the xen-access test program to use the new
mem_accessAPIs.Signed-off-by Aravindh Puthiyaparambil <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>
PATCH v3 4/5 tools/libxc: Remove xc_hvm_[sg]et_mem_access() APIs
In reply to Aravindh PuthiyaparambilRemove xc_hvm_[sg]et_mem_access() APIs which have been replaced by xc_[sg]_mem_access() APIs.
---
This was part of "tools/libxc: Make the mem_access APIs generic" in the earlier versions of the series and is now a seperate patch.
tools/libxc/xc_misc.c +0 -61
@@ -593,67 +593,6 @@ int xc_hvm_set_mem_type(return rc; } -int xc_hvm_set_mem_access ( -xc_interface *xch,domid_t dom,hvmmem_access_t mem_access,uint64_t first_pfn,uint64_t nr) -{ -DECLARE_HYPERCALL ; - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_access, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { -PERROR ("Could not allocate memory for xc_hvm_set_mem_access hypercall" ); -return -1 ; - } - - arg->domid = dom; - arg->hvmmem_access = mem_access; - arg->first_pfn = first_pfn; - arg->nr = nr; - - hypercall.op = __HYPERVISOR_hvm_op; - hypercall.arg[0 ] = HVMOP_set_mem_access; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); - - rc =do_xen_hypercall (xch, &hypercall); - -xc_hypercall_buffer_free (xch, arg); - -return rc; -} - -int xc_hvm_get_mem_access ( -xc_interface *xch,domid_t dom,uint64_t pfn,hvmmem_access_t * mem_access) -{ -DECLARE_HYPERCALL ; - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_get_mem_access, arg); -int rc; - - arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); -if ( arg ==NULL ) - { -PERROR ("Could not allocate memory for xc_hvm_get_mem_access hypercall" ); -return -1 ; - } - - arg->domid = dom; - arg->pfn = pfn; - - hypercall.op = __HYPERVISOR_hvm_op; - hypercall.arg[0 ] = HVMOP_get_mem_access; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); - - rc =do_xen_hypercall (xch, &hypercall); - -if ( !rc ) - *mem_access = arg->hvmmem_access; - -xc_hypercall_buffer_free (xch, arg); - -return rc; -} - int xc_hvm_inject_trap( xc_interface *xch, domid_t dom, int vcpu, uint32_t vector, uint32_t type, uint32_t error_code, uint32_t insn_len,
tools/libxc/xenctrl.h +0 -14
@@ -1729,20 +1729,6 @@ int xc_hvm_set_mem_type( xc_interface *xch, domid_t dom, hvmmem_type_t memtype, uint64_t first_pfn, uint64_t nr);/* -* Set a range of memory to a specific access. -* Allowed types are HVMMEM_access_default, HVMMEM_access_n, any combination of -* HVM_access_ + (rwx), and HVM_access_rx2rw -*/ -int xc_hvm_set_mem_access ( -xc_interface *xch,domid_t dom,hvmmem_access_t memaccess,uint64_t first_pfn,uint64_t nr); - -/* -* Gets the mem access for the given page (returned in memacess on success) -*/ -int xc_hvm_get_mem_access ( -xc_interface *xch,domid_t dom,uint64_t pfn,hvmmem_access_t * memaccess); - -/* * Injects a hardware/software CPU trap, to take effect the next time the HVM * resumes. */
Signature · 1 line
1.8.3.2
Re: [PATCH v3 4/5] tools/libxc: Remove xc_hvm_[sg]et_mem_access() APIs
Quoted 6 lines · Aravindh Puthiyaparambil
Remove xc_hvm_[sg]et_mem_access() APIs which have been replaced by xc_[sg]_mem_access() APIs.
Signed-off-by Aravindh Puthiyaparambil <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>
PATCH v3 5/5 x86/mem_access: Deprecate the HVM mem_access ops
In reply to Aravindh PuthiyaparambilThis patch does the following:
1. Deprecate the HVMOP_[sg]et_mem_access HVM ops.
2. Remove the enums and structs associated with the HVM ops.
---
This was part of "x86/mem_access: Make the mem_access ops generic" in the earlier versions of the series and is now a seperate patch.
xen/arch/x86/hvm/hvm.c +1 -73
@@ -4589,81 +4589,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) }case HVMOP_set_mem_access: - { -struct xen_hvm_set_mem_access a; -struct domain *d; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - rc =rcu_lock_remote_domain_by_id (a.domid, &d); -if ( rc !=0 ) -return rc; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto param_fail5; - - rc =xsm_hvm_param (XSM_TARGET , d, op); -if ( rc ) - goto param_fail5; - - rc = -EINVAL ; -if ( (a.first_pfn != ~0ull ) && - (a.nr < start_iter || - ((a.first_pfn + a.nr -1 ) < a.first_pfn) || - ((a.first_pfn + a.nr -1 ) >domain_get_maximum_gpfn (d))) ) - goto param_fail5; - - rc =p2m_set_mem_access (d, a.first_pfn, a.nr, start_iter, - HVMOP_op_mask, a.hvmmem_access); -if ( rc >0 ) - { - start_iter = rc; - rc = -EAGAIN ; - } - - param_fail5: -rcu_unlock_domain (d); -break ; - } -case HVMOP_get_mem_access: - { -struct xen_hvm_get_mem_access a; -struct domain *d; -xenmem_access_t access; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - rc =rcu_lock_remote_domain_by_id (a.domid, &d); -if ( rc !=0 ) -return rc; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto param_fail6; - - rc =xsm_hvm_param (XSM_TARGET , d, op); -if ( rc ) - goto param_fail6; - - rc = -EINVAL ; -if ( (a.pfn >domain_get_maximum_gpfn (d)) && a.pfn != ~0ull ) - goto param_fail6; - - rc =p2m_get_mem_access (d, a.pfn, &access); -if ( rc !=0 ) - goto param_fail6; - - a.hvmmem_access = access; - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; - - param_fail6: -rcu_unlock_domain (d); + rc = -ENOSYS ;break ; - }case HVMOP_pagetable_dying: {
xen/include/public/hvm/hvm_op.h +2 -40
51 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v3 5/5] x86/mem_access: Deprecate the HVM mem_access ops
Quoted 73 lines
Quoted 1 line
Quoted 1 line · On 16.04.14 at 02:25, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0
-65@@ -4589,81 +4589,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) }case HVMOP_set_mem_access: - { -struct xen_hvm_set_mem_access a; -struct domain *d; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - rc =rcu_lock_remote_domain_by_id (a.domid, &d); -if ( rc !=0 ) -return rc; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto param_fail5; - - rc =xsm_hvm_param (XSM_TARGET , d, op); -if ( rc ) - goto param_fail5; - - rc = -EINVAL ; -if ( (a.first_pfn != ~0ull ) && - (a.nr < start_iter || - ((a.first_pfn + a.nr -1 ) < a.first_pfn) || - ((a.first_pfn + a.nr -1 ) >domain_get_maximum_gpfn (d))) ) - goto param_fail5; - - rc =p2m_set_mem_access (d, a.first_pfn, a.nr, start_iter, - HVMOP_op_mask, a.hvmmem_access); -if ( rc >0 ) - { - start_iter = rc; - rc = -EAGAIN ; - } - - param_fail5: -rcu_unlock_domain (d); -break ; - } -case HVMOP_get_mem_access: - { -struct xen_hvm_get_mem_access a; -struct domain *d; -xenmem_access_t access; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - rc =rcu_lock_remote_domain_by_id (a.domid, &d); -if ( rc !=0 ) -return rc; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto param_fail6; - - rc =xsm_hvm_param (XSM_TARGET , d, op); -if ( rc ) - goto param_fail6; - - rc = -EINVAL ; -if ( (a.pfn >domain_get_maximum_gpfn (d)) && a.pfn != ~0ull ) - goto param_fail6; - - rc =p2m_get_mem_access (d, a.pfn, &access); -if ( rc !=0 )
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 4666
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-8- goto param_fail6; - - a.hvmmem_access = access; - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; - - param_fail6: -rcu_unlock_domain (d); + rc = -ENOSYS ;break ; - }
I can't see why these need to remain here - just have them be handled by the default case (which at once gives you back your log message).
Jan
Re: [PATCH v3 5/5] x86/mem_access: Deprecate the HVM mem_access ops
Quoted 78 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op,
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -4589,81 +4589,9 @@ long do_hvm_op(unsigned long op,
XEN_GUEST_HANDLE_PARAM(void)arg)Quoted 74 lines
xen/arch/x86/hvm/hvm.c +0
-70}case HVMOP_set_mem_access: - { -struct xen_hvm_set_mem_access a; -struct domain *d; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - rc =rcu_lock_remote_domain_by_id (a.domid, &d); -if ( rc !=0 ) -return rc; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto param_fail5; - - rc =xsm_hvm_param (XSM_TARGET , d, op); -if ( rc ) - goto param_fail5; - - rc = -EINVAL ; -if ( (a.first_pfn != ~0ull ) && - (a.nr < start_iter || - ((a.first_pfn + a.nr -1 ) < a.first_pfn) || - ((a.first_pfn + a.nr -1 ) >domain_get_maximum_gpfn (d))) ) - goto param_fail5; - - rc =p2m_set_mem_access (d, a.first_pfn, a.nr, start_iter, - HVMOP_op_mask, a.hvmmem_access); -if ( rc >0 ) - { - start_iter = rc; - rc = -EAGAIN ; - } - - param_fail5: -rcu_unlock_domain (d); -break ; - } -case HVMOP_get_mem_access: - { -struct xen_hvm_get_mem_access a; -struct domain *d; -xenmem_access_t access; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - rc =rcu_lock_remote_domain_by_id (a.domid, &d); -if ( rc !=0 ) -return rc; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto param_fail6; - - rc =xsm_hvm_param (XSM_TARGET , d, op); -if ( rc ) - goto param_fail6; - - rc = -EINVAL ; -if ( (a.pfn >domain_get_maximum_gpfn (d)) && a.pfn != ~0ull ) - goto param_fail6; - - rc =p2m_get_mem_access (d, a.pfn, &access); -if ( rc !=0 ) - goto param_fail6; - - a.hvmmem_access = access; - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -
Quoted 8 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 4666
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1
-3- param_fail6: -rcu_unlock_domain (d); + rc = -ENOSYS ;break ; - }I can't see why these need to remain here - just have them be handled by the default case (which at once gives you back your log message).
OK, I will get rid of them. Should I resubmit the whole series again as v4 or just this patch again?
Thanks,
Aravindh
Re: [PATCH v3 5/5] x86/mem_access: Deprecate the HVM mem_access ops
Quoted 6 lines
Quoted 3 lines
Quoted 1 line · On 16.04.14 at 17:18, <[email protected]> wrote:
I can't see why these need to remain here - just have them be handled by the default case (which at once gives you back your log message).
OK, I will get rid of them. Should I resubmit the whole series again as v4 or just this patch again?
If you don't get any other comments on the other patches, just resending this one would seem fine to me.
Jan
Quoted 6 lines · Aravindh Puthiyaparambil
This is a precusor patch to the one that enables
mem_accessfor PV domains.The
mem_accessAPIs, hypercalls and structures all have HVM specific naming. As a first step to making this work for PV domains, this patch renames them in a more generic fashion.
Quoted 7 lines
Signed-off-by Aravindh Puthiyaparambil <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Tim Deegan <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Ian Campbell <[email protected]>
Applied (using v4 of patch 5/5), thanks.
Tim.