x86: guest resource mapping
PATCH v7 1/12 x86/mm: allow a privileged PV domain to map guest mfns
In reply to Paul DurrantIn the case where a PV domain is mapping guest resources then it needs make the HYPERVISOR_mmu_update call using DOMID_SELF, rather than the guest domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.
This patch removes a check which currently disallows mapping of a page when the owner of the page tables matches the domain passed to HYPERVISOR_mmu_update, but that domain is not the real owner of the page. The check was introduced by patch d3c6a215ca9 ("x86: Clean up get_page_from_l1e() to correctly distinguish between owner-of-pte and owner-of-data-page in all cases") but it's not clear why it was needed.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- xen/arch/x86/mm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
xen/arch/x86/mm.c +8 -5
@@ -1024,12 +1024,15 @@ get_page_from_l1e( (real_pg_owner != dom_cow) ) ) {/* -* Let privileged domains transfer the right to map their target -* domain's pages. This is used to allow stub-domain pvfb export to -* dom0, until pvfb supports granted mappings. At that time this -* minor hack can go away. +* If the real page owner is not the domain specified in the +* hypercall then establish that the specified domain has +* mapping privilege over the page owner. +* This is used to allow stub-domain pvfb export to dom0. It is +* also used to allow a privileged PV domain to map mfns using +* DOMID_SELF, which is needed for mapping guest resources such +* grant table frames. */ -if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
v7 cover x86: guest resource mapping
This series introduces support for direct mapping of guest resources. The resources are:
- Grant tables
- IOREQ server pages
NOTE: This series is based on a master re-base of Juergen Gross's patch "xen: move XENMAPSPACE_grant_table code into grant_table.c". For convenience the code is also available on a branch at:
http://xenbits.xen.org/gitweb/?p=people/pauldu/xen.git;a=shortlog;h=refs/heads/ioreq11
v7:
- Fixed assertion failure hit during domain destroy.
v6:
- Responded to missed comments from Roger.
v5:
- Responded to review comments from Wei.
v4:
- Responded to further review comments from Roger.
v3:
- Dropped original patch #1 since it is covered by Juergen's patch.
- Added new xenforeignmemorycleanup patch (#4).
- Replaced the patch introducing the ioreq server 'is_default' flag with one that changes the ioreq server list into an array (#8).
Paul Durrant (12):
x86/mm: allow a privileged PV domain to map guest mfns x86/mm: add HYPERVISOR_memory_op to acquire guest resources tools/libxenforeignmemory: add support for resource mapping tools/libxenforeignmemory: reduce xenforeignmemory_restrict code
footprint
tools/libxenctrl: use new xenforeignmemory API to seed grant table x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn x86/hvm/ioreq: use bool rather than bool_t
x86/hvm/ioreq: maintain an array of ioreq servers rather than a list x86/hvm/ioreq: simplify code and use consistent naming x86/hvm/ioreq: use gfn_t in struct hvm_ioreq_page x86/hvm/ioreq: defer mapping gfns until they are actually requsted x86/hvm/ioreq: add a new mappable resource type...
tools/include/xen-sys/Linux/privcmd.h | 11 + tools/libs/devicemodel/core.c | 18 +- tools/libs/devicemodel/include/xendevicemodel.h | 14 +- tools/libs/foreignmemory/Makefile | 2 +- tools/libs/foreignmemory/core.c | 53 ++ tools/libs/foreignmemory/freebsd.c | 7 - .../libs/foreignmemory/include/xenforeignmemory.h | 41 + tools/libs/foreignmemory/libxenforeignmemory.map | 5 + tools/libs/foreignmemory/linux.c | 45 ++ tools/libs/foreignmemory/minios.c | 7 - tools/libs/foreignmemory/netbsd.c | 7 - tools/libs/foreignmemory/private.h | 43 +- tools/libs/foreignmemory/solaris.c | 7 - tools/libxc/include/xc_dom.h | 8 +- tools/libxc/xc_dom_boot.c | 114 ++- tools/libxc/xc_sr_restore_x86_hvm.c | 10 +- tools/libxc/xc_sr_restore_x86_pv.c | 2 +- tools/libxl/libxl_dom.c | 1 - tools/python/xen/lowlevel/xc/xc.c | 6 +- xen/arch/x86/hvm/dm.c | 11 +- xen/arch/x86/hvm/hvm.c | 8 +- xen/arch/x86/hvm/io.c | 4 +- xen/arch/x86/hvm/ioreq.c | 869 +++++++++++---------- xen/arch/x86/mm.c | 151 +++- xen/arch/x86/mm/p2m.c | 3 +- xen/common/grant_table.c | 56 +- xen/include/asm-x86/hvm/domain.h | 21 +- xen/include/asm-x86/hvm/ioreq.h | 24 +- xen/include/asm-x86/p2m.h | 3 + xen/include/public/hvm/dm_op.h | 46 +- xen/include/public/memory.h | 41 +- xen/include/xen/grant_table.h | 1 + 32 files changed, 1081 insertions(+), 558 deletions(-)
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 5/12 tools/libxenctrl: use new xenforeignmemory API to seed grant table
A previous patch added support for priv-mapping guest resources directly (rather than having to foreign-map, which requires P2M modification for HVM guests).
This patch makes use of the new API to seed the guest grant table unless the underlying infrastructure (i.e. privcmd) doesn't support it, in which case the old scheme is used.
NOTE: The call to xc_dom_gnttab_hvm_seed() in hvm_build_set_params() was
actually unnecessary, as the grant table has already been seeded by a prior call to xc_dom_gnttab_init() made by libxl__build_dom().
---
Cc: Ian Jackson <[email protected]>
v4:
- Minor cosmetic fix suggested by Roger.
v3:
- Introduced xc_dom_set_gnttab_entry() to avoid duplicated code.
--- tools/libxc/include/xc_dom.h | 8 +-- tools/libxc/xc_dom_boot.c | 114 +++++++++++++++++++++++++----------- tools/libxc/xc_sr_restore_x86_hvm.c | 10 ++-- tools/libxc/xc_sr_restore_x86_pv.c | 2 +- tools/libxl/libxl_dom.c | 1 - tools/python/xen/lowlevel/xc/xc.c | 6 +- 6 files changed, 92 insertions(+), 49 deletions(-)
tools/libxc/include/xc_dom.h +2 -6
@@ -323,12 +323,8 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,int xc_dom_boot_image (struct xc_dom_image *dom);int xc_dom_compat_check (struct xc_dom_image *dom);int xc_dom_gnttab_init (struct xc_dom_image *dom); -int xc_dom_gnttab_hvm_seed (xc_interface *xch,domid_t domid, -xen_pfn_t console_gmfn, -xen_pfn_t xenstore_gmfn, -domid_t console_domid, -domid_t xenstore_domid); -int xc_dom_gnttab_seed(xc_interface *xch, domid_t domid, +int xc_dom_gnttab_seed(xc_interface *xch, domid_t guest_domid, + bool is_hvm, xen_pfn_t console_gmfn, xen_pfn_t xenstore_gmfn, domid_t console_domid,
tools/libxc/xc_dom_boot.c +81 -33
146 lines not on this page · raw message
tools/libxc/xc_sr_restore_x86_hvm.c +5 -5
@@ -207,11 +207,11 @@ static int x86_hvm_stream_complete(struct xc_sr_context *ctx)return rc; } - rc =xc_dom_gnttab_hvm_seed (xch, ctx->domid, - ctx->restore.console_gfn, - ctx->restore.xenstore_gfn, - ctx->restore.console_domid, - ctx->restore.xenstore_domid); + rc =xc_dom_gnttab_seed (xch, ctx->domid, true, + ctx->restore.console_gfn, + ctx->restore.xenstore_gfn, + ctx->restore.console_domid, + ctx->restore.xenstore_domid);if ( rc ) {PERROR ("Failed to seed grant table" );
tools/libxc/xc_sr_restore_x86_pv.c +1 -1
@@ -1104,7 +1104,7 @@ static int x86_pv_stream_complete(struct xc_sr_context *ctx)if ( rc )return rc; - rc = xc_dom_gnttab_seed(xch, ctx->domid, + rc = xc_dom_gnttab_seed(xch, ctx->domid, false, ctx->restore.console_gfn, ctx->restore.xenstore_gfn, ctx->restore.console_domid,
tools/libxl/libxl_dom.c +0 -1
@@ -851,7 +851,6 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid, *store_mfn = str_mfn; *console_mfn = cons_mfn; -xc_dom_gnttab_hvm_seed (handle, domid, *console_mfn, *store_mfn, console_domid, store_domid);return 0 ; }
tools/python/xen/lowlevel/xc/xc.c +3 -3
@@ -800,9 +800,9 @@ static PyObject *pyxc_gnttab_hvm_seed(XcObject *self, &console_domid, &xenstore_domid) )return NULL ; -if (xc_dom_gnttab_hvm_seed (self->xc_handle, dom, - console_gmfn, xenstore_gmfn, - console_domid, xenstore_domid) !=0 ) +if (xc_dom_gnttab_seed (self->xc_handle, dom, true, + console_gmfn, xenstore_gmfn, + console_domid, xenstore_domid) !=0 )return pyxc_error_to_exception (self->xc_handle);return Py_None;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 4/12 tools/libxenforeignmemory: reduce xenforeignmemory_restrict code footprint
In reply to Paul DurrantBy using a static inline stub in private.h for OS where this functionality is not implemented, the various duplicate stubs in the OS-specific source modules can be avoided.
---
Cc: Ian Jackson <[email protected]>
v4:
- Removed extraneous freebsd code.
v3:
- Patch added in response to review comments.
--- tools/libs/foreignmemory/freebsd.c | 7 ------- tools/libs/foreignmemory/minios.c | 7 ------- tools/libs/foreignmemory/netbsd.c | 7 ------- tools/libs/foreignmemory/private.h | 12 +++++++++--- tools/libs/foreignmemory/solaris.c | 7 ------- 5 files changed, 9 insertions(+), 31 deletions(-)
tools/libs/foreignmemory/freebsd.c +0 -7
@@ -95,13 +95,6 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,return munmap (addr, num <<PAGE_SHIFT ); } -int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, -domid_t domid) -{ - errno = -EOPNOTSUPP ; -return -1 ; -} -/* * Local variables: * mode: C
tools/libs/foreignmemory/minios.c +0 -7
@@ -58,13 +58,6 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,return munmap (addr, num <<PAGE_SHIFT ); } -int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, -domid_t domid) -{ - errno = -EOPNOTSUPP ; -return -1 ; -} -/* * Local variables: * mode: C
tools/libs/foreignmemory/netbsd.c +0 -7
@@ -100,13 +100,6 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,return munmap (addr, num*XC_PAGE_SIZE ); } -int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, -domid_t domid) -{ - errno = -EOPNOTSUPP ; -return -1 ; -} -/* * Local variables: * mode: C
tools/libs/foreignmemory/private.h +9 -3
@@ -32,9 +32,6 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem,void *addr,size_t num); -int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, -domid_t domid); -#if defined(__NetBSD__) || defined(__sun__)/* Strictly compat for those two only only */ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
@@ -54,6 +51,13 @@ struct xenforeignmemory_resource_handle { };#ifndef __linux__ +static inline int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, +domid_t domid) +{ + errno =EOPNOTSUPP ; +return -1 ; +} +static inline int osdep_xenforeignmemory_map_resource (xenforeignmemory_handle *fmem,xenforeignmemory_resource_handle *fres) {
@@ -67,6 +71,8 @@ static inline int osdep_xenforeignmemory_unmap_resource(return 0 ; }#else +int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, +domid_t domid);int osdep_xenforeignmemory_map_resource (xenforeignmemory_handle *fmem,xenforeignmemory_resource_handle *fres); int osdep_xenforeignmemory_unmap_resource(
tools/libs/foreignmemory/solaris.c +0 -7
@@ -97,13 +97,6 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,return munmap (addr, num*XC_PAGE_SIZE ); } -int osdep_xenforeignmemory_restrict (xenforeignmemory_handle *fmem, -domid_t domid) -{ - errno = -EOPNOTSUPP ; -return -1 ; -} -/* * Local variables: * mode: C
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 2/12 x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Paul DurrantCertain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
This patch adds a new memory op to allow such a resource to be priv-mapped directly, by either a PV or HVM tools domain: grant table frames.
NOTE: Whilst the new op is not intrinsicly specific to the x86 architecture,
I have no means to test it on an ARM platform and so cannot verify that it functions correctly. Hence it is currently only implemented for x86.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v5:
- Switched __copy_to/from_guest_offset() to copy_to/from_guest_offset().
--- xen/arch/x86/mm.c | 111 ++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/p2m.c | 3 +- xen/common/grant_table.c | 56 ++++++++++++++------- xen/include/asm-x86/p2m.h | 3 ++ xen/include/public/memory.h | 38 ++++++++++++++- xen/include/xen/grant_table.h | 1 + 6 files changed, 191 insertions(+), 21 deletions(-)
xen/arch/x86/mm.c +111 -0
@@ -4768,6 +4768,107 @@ int xenmem_add_to_physmap_one(return rc; } +static int xenmem_acquire_grant_table (struct domain *d, +unsigned long frame, +unsigned long nr_frames, +unsigned long mfn_list[]) +{ +unsigned int i; + +/* +* Iterate through the list backwards so that gnttab_get_frame() is +* first called for the highest numbered frame. This means that the +* out-of-bounds check will be done on the first iteration and, if +* the table needs to grow, it will only grow once. +*/ + i = nr_frames; +while ( i-- !=0 ) + { +mfn_t mfn =gnttab_get_frame (d, frame + i); + +if (mfn_eq (mfn,INVALID_MFN ) ) +return -EINVAL ; + + mfn_list[i] =mfn_x (mfn); + } + +return 0 ; +} + +static int xenmem_acquire_resource (xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long *mfn_list; +int rc; + +if ( xmar->nr_frames ==0 ) +return -EINVAL ; + + d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d); +if ( rc ) + goto out; + + mfn_list = xmalloc_array(unsigned long, xmar->nr_frames); + + rc = -ENOMEM ; +if ( !mfn_list ) + goto out; + +switch ( xmar->type ) + { +case XENMEM_resource_grant_table: + rc = -EINVAL ; +if ( xmar->id )/* must be zero for grant_table */ +break ; + + rc =xenmem_acquire_grant_table (d, xmar->frame, xmar->nr_frames, + mfn_list); +break ; + +default : + rc = -EOPNOTSUPP ; +break ; + } + +if ( rc ) + goto free_and_out; + +if ( !paging_mode_translate (currd) ) + { +if (copy_to_guest_offset (xmar->gmfn_list,0 , mfn_list, + xmar->nr_frames) ) + rc = -EFAULT ; + } +else + { +unsigned int i; + +for ( i =0 ; i < xmar->nr_frames; i++ ) + { +xen_pfn_t gfn; + + rc = -EFAULT ; +if (copy_from_guest_offset (&gfn, xmar->gmfn_list, i,1 ) ) + goto free_and_out; + + rc =set_foreign_p2m_entry (currd, gfn,_mfn (mfn_list[i])); +if ( rc ) + goto free_and_out; + } + } + + free_and_out: +xfree (mfn_list); + + out: +rcu_unlock_domain (d); +return rc; +} +long arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {int rc;
@@ -4990,6 +5091,16 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return rc; } +case XENMEM_acquire_resource: + { +xen_mem_acquire_resource_t xmar; + +if (copy_from_guest (&xmar, arg,1 ) ) +return -EFAULT ; + +return xenmem_acquire_resource (&xmar); + } +default :return subarch_memory_op (cmd, arg); }
xen/arch/x86/mm/p2m.c +1 -2
@@ -1121,8 +1121,7 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn, }/* Set foreign mfn in the given guest's p2m table. */ -static int set_foreign_p2m_entry (struct domain *d,unsigned long gfn, -mfn_t mfn) +int set_foreign_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn) {return set_typed_p2m_entry (d, gfn, mfn,PAGE_ORDER_4K , p2m_map_foreign,p2m_get_hostp2m (d)->default_access);
xen/common/grant_table.c +38 -18
76 lines not on this page · raw message
xen/include/asm-x86/p2m.h +3 -0
@@ -613,6 +613,9 @@ void p2m_memory_type_changed(struct domain *d);int p2m_is_logdirty_range (struct p2m_domain *,unsigned long start,unsigned long end); +/* Set foreign entry in the p2m table (for priv-mapping) */ +int set_foreign_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn); +/* Set mmio addresses in the p2m table (for pass-through) */ int set_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn,unsigned int order,p2m_access_t access);
xen/include/public/memory.h +37 -1
@@ -650,7 +650,43 @@ struct xen_vnuma_topology_info {typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t ;DEFINE_XEN_GUEST_HANDLE (xen_vnuma_topology_info_t); -/* Next available subop number is 28 */ +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +/* +* Get the pages for a particular guest resource, so that they can be +* mapped directly by a tools domain. +*/ +#define XENMEM_acquire_resource 28 +struct xen_mem_acquire_resource { +/* IN - the domain whose resource is to be mapped */ +domid_t domid; +/* IN - the type of resource (defined below) */ +uint16_t type; + +#define XENMEM_resource_grant_table 0 + +/* +* IN - a type-specific resource identifier, which must be zero +* unless stated otherwise. +*/ +uint32_t id; +/* IN - number of (4K) frames of the resource to be mapped */ +uint32_t nr_frames; +/* IN - the index of the initial frame to be mapped */ +uint64_aligned_t frame; +/* IN/OUT - If the tools domain is PV then, upon return, gmfn_list +* will be populated with the MFNs of the resource. +* If the tools domain is HVM then it is expected that, on +* entry, gmfn_list will be populated with a list of GFNs +* that will be mapped to the MFNs of the resource. +*/ +XEN_GUEST_HANDLE (xen_pfn_t) gmfn_list; +}; +typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t ; + +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ + +/* Next available subop number is 29 */ #endif /* __XEN_PUBLIC_MEMORY_H__ */
xen/include/xen/grant_table.h +1 -0
@@ -136,6 +136,7 @@ static inline unsigned int grant_to_status_frames(int grant_frames)int mem_sharing_gref_to_gfn (struct grant_table *gt,grant_ref_t ref,gfn_t *gfn,uint16_t *status); +mfn_t gnttab_get_frame (struct domain *d,unsigned long idx);int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn,mfn_t *mfn);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 7/12 x86/hvm/ioreq: use bool rather than bool_t
In reply to Paul DurrantThis patch changes use of bool_t to bool in the ioreq server code. It also fixes an incorrect indentation in a continuation line.
This patch is purely cosmetic. No semantic or functional change.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/io.c | 4 +- xen/arch/x86/hvm/ioreq.c | 100 +++++++++++++++++++-------------------- xen/include/asm-x86/hvm/domain.h | 6 +-- xen/include/asm-x86/hvm/ioreq.h | 14 +++--- 6 files changed, 64 insertions(+), 64 deletions(-)
xen/arch/x86/hvm/dm.c +1 -1
@@ -409,7 +409,7 @@ static int dm_op(const struct dmop_args *op_args)if ( data->pad[0 ] || data->pad[1 ] || data->pad[2 ] )break ; - rc =hvm_create_ioreq_server (d, curr_d->domain_id,0 , + rc =hvm_create_ioreq_server (d, curr_d->domain_id, false, data->handle_bufioreq, &data->id);break ; }
xen/arch/x86/hvm/hvm.c +1 -1
@@ -4361,7 +4361,7 @@ static int hvmop_get_param( {domid_t domid = d->arch.hvm_domain.params[HVM_PARAM_DM_DOMAIN ]; - rc =hvm_create_ioreq_server (d, domid,1 , + rc =hvm_create_ioreq_server (d, domid, true,HVM_IOREQSRV_BUFIOREQ_LEGACY ,NULL );if ( rc !=0 && rc != -EEXIST ) goto out;
xen/arch/x86/hvm/io.c +2 -2
@@ -59,7 +59,7 @@ void send_timeoffset_req(unsigned long timeoff)if ( timeoff ==0 )return ; -if (hvm_broadcast_ioreq (&p,1 ) !=0 ) +if (hvm_broadcast_ioreq (&p, true) !=0 )gprintk (XENLOG_ERR ,"Unsuccessful timeoffset update\n" ); }
@@ -73,7 +73,7 @@ void send_invalidate_req(void) .data = ~0UL, /* flush all */ }; -if (hvm_broadcast_ioreq (&p,0 ) !=0 ) +if (hvm_broadcast_ioreq (&p, false) !=0 )gprintk (XENLOG_ERR ,"Unsuccessful map-cache invalidate\n" ); }
xen/arch/x86/hvm/ioreq.c +50 -50
335 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +3 -3
@@ -45,7 +45,7 @@ struct hvm_ioreq_vcpu {struct list_head list_entry;struct vcpu *vcpu;evtchn_port_t ioreq_evtchn; -bool_t pending; +bool pending; };#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1)
@@ -69,8 +69,8 @@ struct hvm_ioreq_server {spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn;struct rangeset *range[NR_IO_RANGE_TYPES ]; -bool_t enabled; -bool_t bufioreq_atomic; +bool enabled; +bool bufioreq_atomic; };/*
xen/include/asm-x86/hvm/ioreq.h +7 -7
@@ -19,12 +19,12 @@#ifndef __ASM_X86_HVM_IOREQ_H__#define __ASM_X86_HVM_IOREQ_H__ -bool_t hvm_io_pending (struct vcpu *v); -bool_t handle_hvm_io_completion (struct vcpu *v); -bool_t is_ioreq_server_page (struct domain *d,const struct page_info *page); +bool hvm_io_pending (struct vcpu *v); +bool handle_hvm_io_completion (struct vcpu *v); +bool is_ioreq_server_page (struct domain *d,const struct page_info *page);int hvm_create_ioreq_server (struct domain *d,domid_t domid, -bool_t is_default,int bufioreq_handling, +bool is_default,int bufioreq_handling,ioservid_t *id);int hvm_destroy_ioreq_server (struct domain *d,ioservid_t id); int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,
@@ -40,7 +40,7 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,int hvm_map_mem_type_to_ioreq_server (struct domain *d,ioservid_t id,uint32_t type,uint32_t flags);int hvm_set_ioreq_server_state (struct domain *d,ioservid_t id, -bool_t enabled); +bool enabled);int hvm_all_ioreq_servers_add_vcpu (struct domain *d,struct vcpu *v);void hvm_all_ioreq_servers_remove_vcpu (struct domain *d,struct vcpu *v);
@@ -51,8 +51,8 @@ int hvm_set_dm_domain(struct domain *d, domid_t domid);struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d,ioreq_t *p);int hvm_send_ioreq (struct hvm_ioreq_server *s,ioreq_t *proto_p, -bool_t buffered); -unsigned int hvm_broadcast_ioreq (ioreq_t *p,bool_t buffered); +bool buffered); +unsigned int hvm_broadcast_ioreq (ioreq_t *p,bool buffered);void hvm_ioreq_init (struct domain *d);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 9/12 x86/hvm/ioreq: simplify code and use consistent naming
In reply to Paul DurrantThis patch re-works much of the ioreq server initialization and teardown code:
- The hvm_map/unmap_ioreq_gfn() functions are expanded to call through to hvm_alloc/free_ioreq_gfn() rather than expecting them to be called separately by outer functions.
- Several functions now test the validity of the hvm_ioreq_page gfn value to determine whether they need to act. This means can be safely called for the bufioreq page even when it is not used.
- hvm_add/remove_ioreq_gfn() simply return in the case of the default IOREQ server so callers no longer need to test before calling.
- hvm_ioreq_server_setup_pages() is renamed to hvm_ioreq_server_map_pages() to mirror the existing hvm_ioreq_server_unmap_pages().
All of this significantly shortens the code.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v3:
- Rebased on top of 's->is_default' to 'IS_DEFAULT(s)' changes.
- Minor updates in response to review comments from Roger.
--- xen/arch/x86/hvm/ioreq.c | 183 ++++++++++++++++++----------------------------- 1 file changed, 69 insertions(+), 114 deletions(-)
xen/arch/x86/hvm/ioreq.c +69 -114
@@ -211,63 +211,75 @@ bool handle_hvm_io_completion(struct vcpu *v)return true; } -static int hvm_alloc_ioreq_gfn (struct domain *d,unsigned long *gfn) +static unsigned long hvm_alloc_ioreq_gfn (struct hvm_ioreq_server *s) { +struct domain *d = s->domain;unsigned int i; -int rc; - rc = -ENOMEM ; +ASSERT (!IS_DEFAULT (s)); +for ( i =0 ; i <sizeof (d->arch.hvm_domain.ioreq_gfn.mask) *8 ; i++ ) {if (test_and_clear_bit (i, &d->arch.hvm_domain.ioreq_gfn.mask) ) - { - *gfn = d->arch.hvm_domain.ioreq_gfn.base + i; - rc =0 ; -break ; - } +return d->arch.hvm_domain.ioreq_gfn.base + i; } -return rc; +return gfn_x (INVALID_GFN ); } -static void hvm_free_ioreq_gfn (struct domain *d,unsigned long gfn) +static void hvm_free_ioreq_gfn (struct hvm_ioreq_server *s, +unsigned long gfn) { +struct domain *d = s->domain;unsigned int i = gfn - d->arch.hvm_domain.ioreq_gfn.base; -if ( gfn !=gfn_x (INVALID_GFN ) ) -set_bit (i, &d->arch.hvm_domain.ioreq_gfn.mask); +ASSERT (!IS_DEFAULT (s)); +ASSERT (gfn !=gfn_x (INVALID_GFN )); + +set_bit (i, &d->arch.hvm_domain.ioreq_gfn.mask); } -static void hvm_unmap_ioreq_page (struct hvm_ioreq_server *s,bool buf) +static void hvm_unmap_ioreq_gfn (struct hvm_ioreq_server *s,bool buf) {struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; +if ( iorp->gfn ==gfn_x (INVALID_GFN ) ) +return ; +destroy_ring_for_helper (&iorp->va, iorp->page); + iorp->page =NULL ; + +if ( !IS_DEFAULT (s) ) +hvm_free_ioreq_gfn (s, iorp->gfn); + + iorp->gfn =gfn_x (INVALID_GFN ); } -static int hvm_map_ioreq_page ( -struct hvm_ioreq_server *s,bool buf,unsigned long gfn) +static int hvm_map_ioreq_gfn (struct hvm_ioreq_server *s,bool buf) {struct domain *d = s->domain;struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; -struct page_info *page; -void *va;int rc; -if ( (rc =prepare_ring_for_helper (d, gfn, &page, &va)) ) -return rc; - -if ( (iorp->va !=NULL ) || d->is_dying ) - { -destroy_ring_for_helper (&va, page); +if ( d->is_dying )return -EINVAL ; - } - iorp->va = va; - iorp->page = page; - iorp->gfn = gfn; +if (IS_DEFAULT (s) ) + iorp->gfn = buf ? + d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN ] : + d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN ]; +else + iorp->gfn =hvm_alloc_ioreq_gfn (s); + +if ( iorp->gfn ==gfn_x (INVALID_GFN ) ) +return -ENOMEM ; -return 0 ; + rc =prepare_ring_for_helper (d, iorp->gfn, &iorp->page, &iorp->va); + +if ( rc ) +hvm_unmap_ioreq_gfn (s, buf); + +return rc; }bool is_ioreq_server_page (struct domain *d,const struct page_info *page)
@@ -283,8 +295,7 @@ bool is_ioreq_server_page(struct domain *d, const struct page_info *page)if ( !s )continue ; -if ( (s->ioreq.va && s->ioreq.page == page) || - (s->bufioreq.va && s->bufioreq.page == page) ) +if ( (s->ioreq.page == page) || (s->bufioreq.page == page) ) { found = true;break ;
@@ -296,20 +307,30 @@ bool is_ioreq_server_page(struct domain *d, const struct page_info *page)return found; } -static void hvm_remove_ioreq_gfn ( -struct domain *d,struct hvm_ioreq_page *iorp) +static void hvm_remove_ioreq_gfn (struct hvm_ioreq_server *s,bool buf) + { +struct domain *d = s->domain; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; + +if (IS_DEFAULT (s) || iorp->gfn ==gfn_x (INVALID_GFN ) ) +return ; +if (guest_physmap_remove_page (d,_gfn (iorp->gfn),_mfn (page_to_mfn (iorp->page)),0 ) )domain_crash (d);clear_page (iorp->va); } -static int hvm_add_ioreq_gfn ( -struct domain *d,struct hvm_ioreq_page *iorp) +static int hvm_add_ioreq_gfn (struct hvm_ioreq_server *s,bool buf) { +struct domain *d = s->domain; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;int rc; +if (IS_DEFAULT (s) || iorp->gfn ==gfn_x (INVALID_GFN ) ) +return 0 ; +clear_page (iorp->va); rc = guest_physmap_add_page(d, _gfn(iorp->gfn),
@@ -333,7 +354,6 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, } } -static int hvm_ioreq_server_add_vcpu (struct hvm_ioreq_server *s,struct vcpu *v) {
@@ -445,78 +465,25 @@ static void hvm_ioreq_server_remove_all_vcpus(struct hvm_ioreq_server *s) }static int hvm_ioreq_server_map_pages (struct hvm_ioreq_server *s, -unsigned long ioreq_gfn, -unsigned long bufioreq_gfn) +bool handle_bufioreq) {int rc; - rc =hvm_map_ioreq_page (s, false, ioreq_gfn); -if ( rc ) -return rc; - -if ( bufioreq_gfn !=gfn_x (INVALID_GFN ) ) - rc =hvm_map_ioreq_page (s, true, bufioreq_gfn); - -if ( rc ) -hvm_unmap_ioreq_page (s, false); - -return rc; -} - -static int hvm_ioreq_server_setup_pages (struct hvm_ioreq_server *s, -bool handle_bufioreq) -{ -struct domain *d = s->domain; -unsigned long ioreq_gfn =gfn_x (INVALID_GFN ); -unsigned long bufioreq_gfn =gfn_x (INVALID_GFN ); -int rc; - -if (IS_DEFAULT (s) ) - { -/* -* The default ioreq server must handle buffered ioreqs, for -* backwards compatibility. -*/ -ASSERT (handle_bufioreq); -return hvm_ioreq_server_map_pages (s, - d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN ], - d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN ]); - } - - rc =hvm_alloc_ioreq_gfn (d, &ioreq_gfn); + rc =hvm_map_ioreq_gfn (s, false);if ( !rc && handle_bufioreq ) - rc =hvm_alloc_ioreq_gfn (d, &bufioreq_gfn); - -if ( !rc ) - rc =hvm_ioreq_server_map_pages (s, ioreq_gfn, bufioreq_gfn); + rc =hvm_map_ioreq_gfn (s, true);if ( rc ) - { -hvm_free_ioreq_gfn (d, ioreq_gfn); -hvm_free_ioreq_gfn (d, bufioreq_gfn); - } +hvm_unmap_ioreq_gfn (s, false);return rc; }static void hvm_ioreq_server_unmap_pages (struct hvm_ioreq_server *s) { -struct domain *d = s->domain; -bool handle_bufioreq = !!s->bufioreq.va; - -if ( handle_bufioreq ) -hvm_unmap_ioreq_page (s, true); - -hvm_unmap_ioreq_page (s, false); - -if ( !IS_DEFAULT (s) ) - { -if ( handle_bufioreq ) -hvm_free_ioreq_gfn (d, s->bufioreq.gfn); - -hvm_free_ioreq_gfn (d, s->ioreq.gfn); - } +hvm_unmap_ioreq_gfn (s, true); +hvm_unmap_ioreq_gfn (s, false); }static void hvm_ioreq_server_free_rangesets (struct hvm_ioreq_server *s)
@@ -574,22 +541,15 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,static void hvm_ioreq_server_enable (struct hvm_ioreq_server *s) { -struct domain *d = s->domain;struct hvm_ioreq_vcpu *sv; -bool handle_bufioreq = !!s->bufioreq.va;spin_lock (&s->lock);if ( s->enabled ) goto done; -if ( !IS_DEFAULT (s) ) - { -hvm_remove_ioreq_gfn (d, &s->ioreq); - -if ( handle_bufioreq ) -hvm_remove_ioreq_gfn (d, &s->bufioreq); - } +hvm_remove_ioreq_gfn (s, false); +hvm_remove_ioreq_gfn (s, true); s->enabled = true;
@@ -604,21 +564,13 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s)static void hvm_ioreq_server_disable (struct hvm_ioreq_server *s) { -struct domain *d = s->domain; -bool handle_bufioreq = !!s->bufioreq.va; -spin_lock (&s->lock);if ( !s->enabled ) goto done; -if ( !IS_DEFAULT (s) ) - { -if ( handle_bufioreq ) -hvm_add_ioreq_gfn (d, &s->bufioreq); - -hvm_add_ioreq_gfn (d, &s->ioreq); - } +hvm_add_ioreq_gfn (s, true); +hvm_add_ioreq_gfn (s, false); s->enabled = false;
@@ -640,6 +592,9 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s,INIT_LIST_HEAD (&s->ioreq_vcpu_list);spin_lock_init (&s->bufioreq_lock); + s->ioreq.gfn =gfn_x (INVALID_GFN ); + s->bufioreq.gfn =gfn_x (INVALID_GFN ); + rc =hvm_ioreq_server_alloc_rangesets (s, id);if ( rc )return rc;
@@ -647,7 +602,7 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s,if ( bufioreq_handling ==HVM_IOREQSRV_BUFIOREQ_ATOMIC ) s->bufioreq_atomic = true; - rc =hvm_ioreq_server_setup_pages ( + rc =hvm_ioreq_server_map_pages ( s, bufioreq_handling !=HVM_IOREQSRV_BUFIOREQ_OFF );if ( rc ) goto fail_map;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 3/12 tools/libxenforeignmemory: add support for resource mapping
In reply to Paul DurrantA previous patch introduced a new HYPERVISOR_memory_op to acquire guest resources for direct priv-mapping.
This patch adds new functionality into libxenforeignmemory to make use of a new privcmd ioctl [1] that uses the new memory op to make such resources available via mmap(2).
[1] http://xenbits.xen.org/gitweb/?p=people/pauldu/linux.git;a=commit;h=ce59a05e6712
---
Cc: Ian Jackson <[email protected]>
v4:
- Fixed errno and removed single-use label
- The unmap call now returns a status
- Use C99 initialization for ioctl struct
v2:
- Bump minor version up to 3.
--- tools/include/xen-sys/Linux/privcmd.h | 11 +++++ tools/libs/foreignmemory/Makefile | 2 +- tools/libs/foreignmemory/core.c | 53 ++++++++++++++++++++++ .../libs/foreignmemory/include/xenforeignmemory.h | 41 +++++++++++++++++ tools/libs/foreignmemory/libxenforeignmemory.map | 5 ++ tools/libs/foreignmemory/linux.c | 45 ++++++++++++++++++ tools/libs/foreignmemory/private.h | 31 +++++++++++++ 7 files changed, 187 insertions(+), 1 deletion(-)
tools/include/xen-sys/Linux/privcmd.h +11 -0
@@ -86,6 +86,15 @@ typedef struct privcmd_dm_op {const privcmd_dm_op_buf_t __user *ubufs; } privcmd_dm_op_t; +typedef struct privcmd_mmap_resource { +domid_t dom; +__u32 type; +__u32 id; +__u32 idx; +__u64 num; +__u64 addr; +}privcmd_mmap_resource_t ; +/* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t
@@ -103,5 +112,7 @@ typedef struct privcmd_dm_op { _IOC(_IOC_NONE, 'P', 5, sizeof(privcmd_dm_op_t))#define IOCTL_PRIVCMD_RESTRICT \ _IOC(_IOC_NONE, 'P', 6, sizeof(domid_t)) +#define IOCTL_PRIVCMD_MMAP_RESOURCE \ + _IOC(_IOC_NONE, 'P', 7, sizeof(privcmd_mmap_resource_t))#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
tools/libs/foreignmemory/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 2 +MINOR = 3 SHLIB_LDFLAGS += -Wl,--version-script=libxenforeignmemory.map CFLAGS += -Werror -Wmissing-prototypes
tools/libs/foreignmemory/core.c +53 -0
65 lines not on this page · raw message
tools/libs/foreignmemory/include/xenforeignmemory.h +41 -0
47 lines not on this page · raw message
tools/libs/foreignmemory/libxenforeignmemory.map +5 -0
@@ -14,3 +14,8 @@ VERS_1.2 { global: xenforeignmemory_map2; } VERS_1.1; +VERS_1.3 { + global: + xenforeignmemory_map_resource; + xenforeignmemory_unmap_resource; +} VERS_1.2;
tools/libs/foreignmemory/linux.c +45 -0
51 lines not on this page · raw message
tools/libs/foreignmemory/private.h +31 -0
@@ -42,6 +42,37 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom, xen_pfn_t *arr, int num);#endif +struct xenforeignmemory_resource_handle { +domid_t domid; +unsigned int type; +unsigned int id; +unsigned long frame; +unsigned long nr_frames; +void *addr; +int prot; +int flags; +}; + +#ifndef __linux__ +static inline int osdep_xenforeignmemory_map_resource ( +xenforeignmemory_handle *fmem,xenforeignmemory_resource_handle *fres) +{ + errno =EOPNOTSUPP ; +return -1 ; +} + +static inline int osdep_xenforeignmemory_unmap_resource ( +xenforeignmemory_handle *fmem,xenforeignmemory_resource_handle *fres) +{ +return 0 ; +} +#else +int osdep_xenforeignmemory_map_resource ( +xenforeignmemory_handle *fmem,xenforeignmemory_resource_handle *fres); +int osdep_xenforeignmemory_unmap_resource ( +xenforeignmemory_handle *fmem,xenforeignmemory_resource_handle *fres); +#endif + #define PERROR(_f...) \ xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 6/12 x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn
In reply to Paul DurrantSince ioreq servers are only relevant to HVM guests and all the names in question unequivocally refer to guest frame numbers, name them all .*gfn to avoid any confusion.
This patch is purely cosmetic. No semantic or functional change.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- tools/libs/devicemodel/core.c | 10 ++-- tools/libs/devicemodel/include/xendevicemodel.h | 12 ++-- xen/arch/x86/hvm/dm.c | 4 +- xen/arch/x86/hvm/hvm.c | 6 +- xen/arch/x86/hvm/ioreq.c | 74 ++++++++++++------------- xen/include/asm-x86/hvm/domain.h | 4 +- xen/include/asm-x86/hvm/ioreq.h | 4 +- xen/include/public/hvm/dm_op.h | 20 +++---- 8 files changed, 67 insertions(+), 67 deletions(-)
tools/libs/devicemodel/core.c +5 -5
@@ -174,7 +174,7 @@ int xendevicemodel_create_ioreq_server(int xendevicemodel_get_ioreq_server_info (xendevicemodel_handle *dmod,domid_t domid,ioservid_t id, -xen_pfn_t *ioreq_pfn,xen_pfn_t *bufioreq_pfn, +xen_pfn_t *ioreq_gfn,xen_pfn_t *bufioreq_gfn,evtchn_port_t *bufioreq_port) {struct xen_dm_op op;
@@ -192,11 +192,11 @@ int xendevicemodel_get_ioreq_server_info(if (rc)return rc; -if (ioreq_pfn) - *ioreq_pfn = data->ioreq_pfn; +if (ioreq_gfn) + *ioreq_gfn = data->ioreq_gfn; -if (bufioreq_pfn) - *bufioreq_pfn = data->bufioreq_pfn; +if (bufioreq_gfn) + *bufioreq_gfn = data->bufioreq_gfn;if (bufioreq_port) *bufioreq_port = data->bufioreq_port;
tools/libs/devicemodel/include/xendevicemodel.h +6 -6
@@ -60,17 +60,17 @@ int xendevicemodel_create_ioreq_server(* @parm dmod a handle to an open devicemodel interface. * @parm domid the domain id to be serviced * @parm id the IOREQ Server id. -* @parm ioreq_pfn pointer to a xen_pfn_t to receive the synchronous ioreq -* gmfn -* @parm bufioreq_pfn pointer to a xen_pfn_t to receive the buffered ioreq -* gmfn +* @parm ioreq_gfn pointer to a xen_pfn_t to receive the synchronous ioreq +* gfn +* @parm bufioreq_gfn pointer to a xen_pfn_t to receive the buffered ioreq +* gfn * @parm bufioreq_port pointer to a evtchn_port_t to receive the buffered * ioreq event channel * @return 0 on success, -1 on failure. */ int xendevicemodel_get_ioreq_server_info (xendevicemodel_handle *dmod,domid_t domid,ioservid_t id, -xen_pfn_t *ioreq_pfn,xen_pfn_t *bufioreq_pfn, +xen_pfn_t *ioreq_gfn,xen_pfn_t *bufioreq_gfn,evtchn_port_t *bufioreq_port);/**
@@ -168,7 +168,7 @@ int xendevicemodel_destroy_ioreq_server(* This function sets IOREQ Server state. An IOREQ Server * will not be passed emulation requests until it is in * the enabled state. -* Note that the contents of the ioreq_pfn and bufioreq_pfn are +* Note that the contents of the ioreq_gfn and bufioreq_gfn are * not meaningful until the IOREQ Server is in the enabled state. * * @parm dmod a handle to an open devicemodel interface.
xen/arch/x86/hvm/dm.c +2 -2
@@ -426,8 +426,8 @@ static int dm_op(const struct dmop_args *op_args)break ; rc =hvm_get_ioreq_server_info (d, data->id, - &data->ioreq_pfn, - &data->bufioreq_pfn, + &data->ioreq_gfn, + &data->bufioreq_gfn, &data->bufioreq_port);break ; }
xen/arch/x86/hvm/hvm.c +3 -3
@@ -4185,20 +4185,20 @@ static int hvmop_set_param( rc = -EINVAL ;break ;case HVM_PARAM_IOREQ_SERVER_PFN : - d->arch.hvm_domain.ioreq_gmfn.base = a.value; + d->arch.hvm_domain.ioreq_gfn.base = a.value;break ;case HVM_PARAM_NR_IOREQ_SERVER_PAGES : {unsigned int i;if ( a.value ==0 || - a.value >sizeof (d->arch.hvm_domain.ioreq_gmfn.mask) *8 ) + a.value >sizeof (d->arch.hvm_domain.ioreq_gfn.mask) *8 ) { rc = -EINVAL ;break ; }for ( i =0 ; i < a.value; i++ ) -set_bit (i, &d->arch.hvm_domain.ioreq_gmfn.mask); +set_bit (i, &d->arch.hvm_domain.ioreq_gfn.mask);break ; }
xen/arch/x86/hvm/ioreq.c +37 -37
200 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +2 -2
@@ -36,7 +36,7 @@#include <public/hvm/dm_op.h> struct hvm_ioreq_page { -unsigned long gmfn; +unsigned long gfn;struct page_info *page;void *va; };
@@ -105,7 +105,7 @@ struct hvm_domain {struct {unsigned long base;unsigned long mask; - } ioreq_gmfn; + } ioreq_gfn;/* Lock protects all other values in the sub-struct and the default */ struct {
xen/include/asm-x86/hvm/ioreq.h +2 -2
@@ -28,8 +28,8 @@ int hvm_create_ioreq_server(struct domain *d, domid_t domid, ioservid_t *id);int hvm_destroy_ioreq_server (struct domain *d,ioservid_t id);int hvm_get_ioreq_server_info (struct domain *d,ioservid_t id, -unsigned long *ioreq_pfn, -unsigned long *bufioreq_pfn, +unsigned long *ioreq_gfn, +unsigned long *bufioreq_gfn,evtchn_port_t *bufioreq_port); int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id, uint32_t type, uint64_t start,
xen/include/public/hvm/dm_op.h +10 -10
@@ -41,9 +41,9 @@* A domain supports a single 'legacy' IOREQ Server which is instantiated if * parameter... * -* HVM_PARAM_IOREQ_PFN is read (to get the gmfn containing the synchronous +* HVM_PARAM_IOREQ_PFN is read (to get the gfn containing the synchronous * ioreq structures), or... -* HVM_PARAM_BUFIOREQ_PFN is read (to get the gmfn containing the buffered +* HVM_PARAM_BUFIOREQ_PFN is read (to get the gfn containing the buffered * ioreq ring), or... * HVM_PARAM_BUFIOREQ_EVTCHN is read (to get the event channel that Xen uses * to request buffered I/O emulation).
@@ -81,14 +81,14 @@ struct xen_dm_op_create_ioreq_server {* * The emulator needs to map the synchronous ioreq structures and buffered * ioreq ring (if it exists) that Xen uses to request emulation. These are -* hosted in the target domain's gmfns <ioreq_pfn> and <bufioreq_pfn> +* hosted in the target domain's gmfns <ioreq_gfn> and <bufioreq_gfn> * respectively. In addition, if the IOREQ Server is handling buffered * emulation requests, the emulator needs to bind to event channel * <bufioreq_port> to listen for them. (The event channels used for * synchronous emulation requests are specified in the per-CPU ioreq -* structures in <ioreq_pfn>). +* structures in <ioreq_gfn>). * If the IOREQ Server is not handling buffered emulation requests then the -* values handed back in <bufioreq_pfn> and <bufioreq_port> will both be 0. +* values handed back in <bufioreq_gfn> and <bufioreq_port> will both be 0. */ #define XEN_DMOP_get_ioreq_server_info 2
@@ -98,10 +98,10 @@ struct xen_dm_op_get_ioreq_server_info {uint16_t pad;/* OUT - buffered ioreq port */ evtchn_port_t bufioreq_port; -/* OUT - sync ioreq pfn */ -uint64_aligned_t ioreq_pfn; -/* OUT - buffered ioreq pfn */ -uint64_aligned_t bufioreq_pfn; +/* OUT - sync ioreq gfn */ +uint64_aligned_t ioreq_gfn; +/* OUT - buffered ioreq gfn */ +uint64_aligned_t bufioreq_gfn; };/*
@@ -150,7 +150,7 @@ struct xen_dm_op_ioreq_server_range {* * The IOREQ Server will not be passed any emulation requests until it is * in the enabled state. -* Note that the contents of the ioreq_pfn and bufioreq_fn (see +* Note that the contents of the ioreq_gfn and bufioreq_gfn (see * XEN_DMOP_get_ioreq_server_info) are not meaningful until the IOREQ Server * is in the enabled state. */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 8/12 x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
In reply to Paul DurrantA subsequent patch will remove the current implicit limitation on creation of ioreq servers which is due to the allocation of gfns for the ioreq structures and buffered ioreq ring.
It will therefore be necessary to introduce an explicit limit and, since this limit should be small, it simplifies the code to maintain an array of that size rather than using a list.
Also, by reserving an array slot for the default server and populating array slots early in create, the need to pass an 'is_default' boolean to sub-functions can be avoided.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v7:
- Fixed assertion failure found in testing.
v6:
- Updated according to comments made by Roger on v4 that I'd missed.
v5:
- Switched GET/SET_IOREQ_SERVER() macros to get/set_ioreq_server() functions to avoid possible double-evaluation issues.
v4:
- Introduced more helper macros and relocated them to the top of the code.
v3:
- New patch (replacing "move is_default into struct hvm_ioreq_server") in response to review comments.
--- xen/arch/x86/hvm/ioreq.c | 512 +++++++++++++++++++-------------------- xen/include/asm-x86/hvm/domain.h | 11 +- 2 files changed, 261 insertions(+), 262 deletions(-)
xen/arch/x86/hvm/ioreq.c +255 -257
@@ -33,6 +33,32 @@#include <public/hvm/ioreq.h> +static void set_ioreq_server (struct domain *d,unsigned int id, +struct hvm_ioreq_server *s) +{ +ASSERT (id <MAX_NR_IOREQ_SERVERS ); +ASSERT (!s || !d->arch.hvm_domain.ioreq_server.server[id]); + + d->arch.hvm_domain.ioreq_server.server[id] = s; +} + +static struct hvm_ioreq_server *get_ioreq_server (struct domain *d, +unsigned int id) +{ +if ( id >=MAX_NR_IOREQ_SERVERS ) +return NULL ; + +return d->arch.hvm_domain.ioreq_server.server[id]; +} + +#define IS_DEFAULT (s) \ + ((s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID)) + +#define FOR_EACH_IOREQ_SERVER (d, id, s) \ + for ( (id) = 0, (s) = get_ioreq_server((d), (id)); \ + (id) < MAX_NR_IOREQ_SERVERS; \ + (s) = get_ioreq_server((d), ++(id)) ) +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) {shared_iopage_t *p = s->ioreq.va;
@@ -47,13 +73,15 @@ bool hvm_io_pending(struct vcpu *v) {struct domain *d = v->domain;struct hvm_ioreq_server *s; +unsigned int id; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) {struct hvm_ioreq_vcpu *sv; +if ( !s ) +continue ; +list_for_each_entry ( sv, &s->ioreq_vcpu_list, list_entry )
@@ -127,13 +155,15 @@ bool handle_hvm_io_completion(struct vcpu *v)struct hvm_vcpu_io *vio = &v->arch.hvm_vcpu.hvm_io;struct hvm_ioreq_server *s;enum hvm_io_completion io_completion; +unsigned int id; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) {struct hvm_ioreq_vcpu *sv; +if ( !s ) +continue ; +list_for_each_entry ( sv, &s->ioreq_vcpu_list, list_entry )
@@ -243,14 +273,16 @@ static int hvm_map_ioreq_page(bool is_ioreq_server_page (struct domain *d,const struct page_info *page) {const struct hvm_ioreq_server *s; +unsigned int id;bool found = false;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { +if ( !s ) +continue ; +if ( (s->ioreq.va && s->ioreq.page == page) || (s->bufioreq.va && s->bufioreq.page == page) ) {
@@ -301,8 +333,9 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, } } +static int hvm_ioreq_server_add_vcpu (struct hvm_ioreq_server *s, -bool is_default,struct vcpu *v) +struct vcpu *v) {struct hvm_ioreq_vcpu *sv;int rc;
@@ -331,7 +364,7 @@ static int hvm_ioreq_server_add_vcpu(struct hvm_ioreq_server *s, goto fail3; s->bufioreq_evtchn = rc; -if ( is_default ) +if (IS_DEFAULT (s) ) d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_EVTCHN ] = s->bufioreq_evtchn; }
@@ -431,7 +464,6 @@ static int hvm_ioreq_server_map_pages(struct hvm_ioreq_server *s, }static int hvm_ioreq_server_setup_pages (struct hvm_ioreq_server *s, -bool is_default,bool handle_bufioreq) {struct domain *d = s->domain;
@@ -439,7 +471,7 @@ static int hvm_ioreq_server_setup_pages(struct hvm_ioreq_server *s,unsigned long bufioreq_gfn =gfn_x (INVALID_GFN );int rc; -if ( is_default ) +if (IS_DEFAULT (s) ) {/* * The default ioreq server must handle buffered ioreqs, for
@@ -468,8 +500,7 @@ static int hvm_ioreq_server_setup_pages(struct hvm_ioreq_server *s,return rc; } -static void hvm_ioreq_server_unmap_pages (struct hvm_ioreq_server *s, -bool is_default) +static void hvm_ioreq_server_unmap_pages (struct hvm_ioreq_server *s) {struct domain *d = s->domain;bool handle_bufioreq = !!s->bufioreq.va;
@@ -479,7 +510,7 @@ static void hvm_ioreq_server_unmap_pages(struct hvm_ioreq_server *s,hvm_unmap_ioreq_page (s, false); -if ( !is_default ) +if ( !IS_DEFAULT (s) ) {if ( handle_bufioreq )hvm_free_ioreq_gfn (d, s->bufioreq.gfn);
@@ -488,12 +519,11 @@ static void hvm_ioreq_server_unmap_pages(struct hvm_ioreq_server *s, } } -static void hvm_ioreq_server_free_rangesets (struct hvm_ioreq_server *s, -bool is_default) +static void hvm_ioreq_server_free_rangesets (struct hvm_ioreq_server *s) {unsigned int i; -if ( is_default ) +if (IS_DEFAULT (s) )return ;for ( i =0 ; i <NR_IO_RANGE_TYPES ; i++ )
@@ -501,19 +531,19 @@ static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s, } static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s, - bool is_default) + ioservid_t id) { unsigned int i; int rc; - if ( is_default ) + if ( IS_DEFAULT(s) ) goto done; for ( i = 0; i < NR_IO_RANGE_TYPES; i++ ) { char *name; - rc = asprintf(&name, "ioreq_server %d %s", s->id, + rc = asprintf(&name, "ioreq_server %d %s", id, (i == XEN_DMOP_IO_RANGE_PORT) ? "port" : (i == XEN_DMOP_IO_RANGE_MEMORY) ? "memory" : (i == XEN_DMOP_IO_RANGE_PCI) ? "pci" :
@@ -537,13 +567,12 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,return 0 ; fail: -hvm_ioreq_server_free_rangesets (s, false); +hvm_ioreq_server_free_rangesets (s);return rc; } -static void hvm_ioreq_server_enable (struct hvm_ioreq_server *s, -bool is_default) +static void hvm_ioreq_server_enable (struct hvm_ioreq_server *s) {struct domain *d = s->domain;struct hvm_ioreq_vcpu *sv;
@@ -554,7 +583,7 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s,if ( s->enabled ) goto done; -if ( !is_default ) +if ( !IS_DEFAULT (s) ) {hvm_remove_ioreq_gfn (d, &s->ioreq);
@@ -573,8 +602,7 @@ static void hvm_ioreq_server_enable(struct hvm_ioreq_server *s,spin_unlock (&s->lock); } -static void hvm_ioreq_server_disable (struct hvm_ioreq_server *s, -bool is_default) +static void hvm_ioreq_server_disable (struct hvm_ioreq_server *s) {struct domain *d = s->domain;bool handle_bufioreq = !!s->bufioreq.va;
@@ -584,7 +612,7 @@ static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s,if ( !s->enabled ) goto done; -if ( !is_default ) +if ( !IS_DEFAULT (s) ) {if ( handle_bufioreq )hvm_add_ioreq_gfn (d, &s->bufioreq);
@@ -600,13 +628,11 @@ static void hvm_ioreq_server_disable(struct hvm_ioreq_server *s,static int hvm_ioreq_server_init (struct hvm_ioreq_server *s,struct domain *d,domid_t domid, -bool is_default,int bufioreq_handling, -ioservid_t id) +int bufioreq_handling,ioservid_t id) {struct vcpu *v;int rc; - s->id = id; s->domain = d; s->domid = domid;
@@ -614,7 +640,7 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s,INIT_LIST_HEAD (&s->ioreq_vcpu_list);spin_lock_init (&s->bufioreq_lock); - rc =hvm_ioreq_server_alloc_rangesets (s, is_default); + rc =hvm_ioreq_server_alloc_rangesets (s, id);if ( rc )return rc;
@@ -622,13 +648,13 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, s->bufioreq_atomic = true; rc =hvm_ioreq_server_setup_pages ( - s, is_default, bufioreq_handling !=HVM_IOREQSRV_BUFIOREQ_OFF ); + s, bufioreq_handling !=HVM_IOREQSRV_BUFIOREQ_OFF );if ( rc ) goto fail_map; for_each_vcpu ( d, v ) { - rc =hvm_ioreq_server_add_vcpu (s, is_default, v); + rc =hvm_ioreq_server_add_vcpu (s, v);if ( rc ) goto fail_add; }
@@ -637,47 +663,20 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, fail_add:hvm_ioreq_server_remove_all_vcpus (s); -hvm_ioreq_server_unmap_pages (s, is_default); +hvm_ioreq_server_unmap_pages (s); fail_map: -hvm_ioreq_server_free_rangesets (s, is_default); +hvm_ioreq_server_free_rangesets (s);return rc; } -static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s, -bool is_default) +static void hvm_ioreq_server_deinit (struct hvm_ioreq_server *s) {ASSERT (!s->enabled);hvm_ioreq_server_remove_all_vcpus (s); -hvm_ioreq_server_unmap_pages (s, is_default); -hvm_ioreq_server_free_rangesets (s, is_default); -} - -static ioservid_t next_ioservid (struct domain *d) -{ -struct hvm_ioreq_server *s; -ioservid_t id; - -ASSERT (spin_is_locked (&d->arch.hvm_domain.ioreq_server.lock)); - - id = d->arch.hvm_domain.ioreq_server.id; - - again: - id++; - -/* Check for uniqueness */ -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( id == s->id ) - goto again; - } - - d->arch.hvm_domain.ioreq_server.id = id; - -return id; +hvm_ioreq_server_unmap_pages (s); +hvm_ioreq_server_free_rangesets (s); } int hvm_create_ioreq_server(struct domain *d, domid_t domid,
@@ -685,52 +684,66 @@ int hvm_create_ioreq_server(struct domain *d, domid_t domid, ioservid_t *id) {struct hvm_ioreq_server *s; +unsigned int i;int rc;if ( bufioreq_handling >HVM_IOREQSRV_BUFIOREQ_ATOMIC )return -EINVAL ; - rc = -ENOMEM ; s = xzalloc(struct hvm_ioreq_server);if ( !s ) - goto fail1; +return -ENOMEM ;domain_pause (d);spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -EEXIST ; -if ( is_default && d->arch.hvm_domain.default_ioreq_server !=NULL ) - goto fail2; - - rc =hvm_ioreq_server_init (s, d, domid, is_default, bufioreq_handling, -next_ioservid (d)); -if ( rc ) - goto fail3; - -list_add (&s->list_entry, - &d->arch.hvm_domain.ioreq_server.list); -if ( is_default ) { - d->arch.hvm_domain.default_ioreq_server = s; -hvm_ioreq_server_enable (s, true); + i =DEFAULT_IOSERVID ; + + rc = -EEXIST ; +if (get_ioreq_server (d, i) ) + goto fail; + } +else + { +for ( i =0 ; i <MAX_NR_IOREQ_SERVERS ; i++ ) + { +if ( i !=DEFAULT_IOSERVID && !get_ioreq_server (d, i) ) +break ; + } + + rc = -ENOSPC ; +if ( i >=MAX_NR_IOREQ_SERVERS ) + goto fail; } +set_ioreq_server (d, i, s); + + rc =hvm_ioreq_server_init (s, d, domid, bufioreq_handling, i); +if ( rc ) + goto fail; + +if (IS_DEFAULT (s) ) +hvm_ioreq_server_enable (s); +if ( id ) - *id = s->id; + *id = i; + + d->arch.hvm_domain.ioreq_server.count++;spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);domain_unpause (d);return 0 ; - fail3: - fail2: + fail: +set_ioreq_server (d, i,NULL ); +spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);domain_unpause (d);xfree (s); - fail1:return rc; }
@@ -741,35 +754,34 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id); -if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; -domain_pause (d); + rc = -EPERM ; +if (IS_DEFAULT (s) ) + goto out; -p2m_set_ioreq_server (d,0 , s); +domain_pause (d); -hvm_ioreq_server_disable (s, false); +p2m_set_ioreq_server (d,0 , s); -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); -hvm_ioreq_server_deinit (s, false); +domain_unpause (d); -domain_unpause (d); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count; -xfree (s); +set_ioreq_server (d, id,NULL ); +xfree (s); - rc =0 ; -break ; - } + rc =0 ; + out:spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);return rc;
@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id); -if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; - *ioreq_gfn = s->ioreq.gfn; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out; -if ( s->bufioreq.va !=NULL ) - { - *bufioreq_gfn = s->bufioreq.gfn; - *bufioreq_port = s->bufioreq_evtchn; - } + *ioreq_gfn = s->ioreq.gfn; - rc =0 ; -break ; +if ( s->bufioreq.va !=NULL ) + { + *bufioreq_gfn = s->bufioreq.gfn; + *bufioreq_port = s->bufioreq_evtchn; } + rc =0 ; + + out:spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);return rc;
@@ -818,48 +828,45 @@ int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id, uint64_t end) {struct hvm_ioreq_server *s; +struct rangeset *r;int rc;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + s =get_ioreq_server (d, id); + rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; +if ( !s ) + goto out; -if ( s->id == id ) - { -struct rangeset *r; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out; -switch ( type ) - { -case XEN_DMOP_IO_RANGE_PORT : -case XEN_DMOP_IO_RANGE_MEMORY : -case XEN_DMOP_IO_RANGE_PCI : - r = s->range[type]; -break ; +switch ( type ) + { +case XEN_DMOP_IO_RANGE_PORT : +case XEN_DMOP_IO_RANGE_MEMORY : +case XEN_DMOP_IO_RANGE_PCI : + r = s->range[type]; +break ; -default : - r =NULL ; -break ; - } +default : + r =NULL ; +break ; + } - rc = -EINVAL ; -if ( !r ) -break ; + rc = -EINVAL ; +if ( !r ) + goto out; - rc = -EEXIST ; -if (rangeset_overlaps_range (r, start, end) ) -break ; + rc = -EEXIST ; +if (rangeset_overlaps_range (r, start, end) ) + goto out; - rc =rangeset_add_range (r, start, end); -break ; - } - } + rc =rangeset_add_range (r, start, end); + out:spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);return rc;
@@ -870,48 +877,45 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id, uint64_t end) {struct hvm_ioreq_server *s; +struct rangeset *r;int rc;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + s =get_ioreq_server (d, id); + rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; +if ( !s ) + goto out; -if ( s->id == id ) - { -struct rangeset *r; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out; -switch ( type ) - { -case XEN_DMOP_IO_RANGE_PORT : -case XEN_DMOP_IO_RANGE_MEMORY : -case XEN_DMOP_IO_RANGE_PCI : - r = s->range[type]; -break ; +switch ( type ) + { +case XEN_DMOP_IO_RANGE_PORT : +case XEN_DMOP_IO_RANGE_MEMORY : +case XEN_DMOP_IO_RANGE_PCI : + r = s->range[type]; +break ; -default : - r =NULL ; -break ; - } +default : + r =NULL ; +break ; + } - rc = -EINVAL ; -if ( !r ) -break ; + rc = -EINVAL ; +if ( !r ) + goto out; - rc = -ENOENT ; -if ( !rangeset_contains_range (r, start, end) ) -break ; + rc = -ENOENT ; +if ( !rangeset_contains_range (r, start, end) ) + goto out; - rc =rangeset_remove_range (r, start, end); -break ; - } - } + rc =rangeset_remove_range (r, start, end); + out:spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);return rc;
@@ -939,20 +943,14 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id); -if ( s->id == id ) - { - rc =p2m_set_ioreq_server (d, flags, s); -break ; - } - } +if ( !s ) + rc = -ENOENT ; +else if (IS_DEFAULT (s) ) + rc = -EOPNOTSUPP ; +else + rc =p2m_set_ioreq_server (d, flags, s);spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);
@@ -970,38 +968,33 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,int hvm_set_ioreq_server_state (struct domain *d,ioservid_t id,bool enabled) { -struct list_head *entry; +struct hvm_ioreq_server *s;int rc;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each ( entry, - &d->arch.hvm_domain.ioreq_server.list ) - { -struct hvm_ioreq_server *s =list_entry (entry, - struct hvm_ioreq_server, - list_entry); + s =get_ioreq_server (d, id); -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; -if ( s->id != id ) -continue ; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out; -domain_pause (d); +domain_pause (d); -if ( enabled ) -hvm_ioreq_server_enable (s, false); -else -hvm_ioreq_server_disable (s, false); +if ( enabled ) +hvm_ioreq_server_enable (s); +else +hvm_ioreq_server_disable (s); -domain_unpause (d); +domain_unpause (d); - rc =0 ; -break ; - } + rc =0 ; + out:spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);return rc; }
@@ -1009,17 +1002,17 @@ int hvm_set_ioreq_server_state(struct domain *d, ioservid_t id,int hvm_all_ioreq_servers_add_vcpu (struct domain *d,struct vcpu *v) {struct hvm_ioreq_server *s; +unsigned int id;int rc;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { -bool is_default = (s == d->arch.hvm_domain.default_ioreq_server); +if ( !s ) +continue ; - rc =hvm_ioreq_server_add_vcpu (s, is_default, v); + rc =hvm_ioreq_server_add_vcpu (s, v);if ( rc ) goto fail; }
@@ -1029,10 +1022,15 @@ int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)return 0 ; fail: -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) +while ( id-- !=0 ) + { + s =get_ioreq_server (d, id); + +if ( !s ) +continue ; +hvm_ioreq_server_remove_vcpu (s, v); + }spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);
@@ -1042,43 +1040,45 @@ int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)void hvm_all_ioreq_servers_remove_vcpu (struct domain *d,struct vcpu *v) {struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) + { +if ( !s ) +continue ; +hvm_ioreq_server_remove_vcpu (s, v); + }spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); }void hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */ -list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { -bool is_default = (s == d->arch.hvm_domain.default_ioreq_server); - -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ; +if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); -hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count; +set_ioreq_server (d, id,NULL );xfree (s); } +ASSERT (!d->arch.hvm_domain.ioreq_server.count);spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); }
@@ -1111,7 +1111,7 @@ int hvm_set_dm_domain(struct domain *d, domid_t domid)* still be set and thus, when the server is created, it will have * the correct domid. */ - s = d->arch.hvm_domain.default_ioreq_server; + s =get_ioreq_server (d,DEFAULT_IOSERVID );if ( !s ) goto done;
@@ -1164,12 +1164,13 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,uint32_t cf8;uint8_t type;uint64_t addr; +unsigned int id; -if (list_empty (&d->arch.hvm_domain.ioreq_server.list) ) +if ( !d->arch.hvm_domain.ioreq_server.count )return NULL ;if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) -return d->arch.hvm_domain.default_ioreq_server; +return get_ioreq_server (d,DEFAULT_IOSERVID ); cf8 = d->arch.hvm_domain.pci_cf8;
@@ -1209,16 +1210,11 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, addr = p->addr; } -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) {struct rangeset *r; -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; - -if ( !s->enabled ) +if ( !s ||IS_DEFAULT (s) )continue ; r = s->range[type];
@@ -1251,7 +1247,7 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d, } } -return d->arch.hvm_domain.default_ioreq_server; +return get_ioreq_server (d,DEFAULT_IOSERVID ); }static int hvm_send_buffered_ioreq (struct hvm_ioreq_server *s,ioreq_t *p)
@@ -1410,13 +1406,16 @@ unsigned int hvm_broadcast_ioreq(ioreq_t *p, bool buffered) {struct domain *d = current->domain;struct hvm_ioreq_server *s; -unsigned int failed =0 ; +unsigned int id, failed =0 ; + + FOR_EACH_IOREQ_SERVER(d, id, s) + { +if ( !s ) +continue ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry )if (hvm_send_ioreq (s, p, buffered) ==X86EMUL_UNHANDLEABLE ) failed++; + }return failed; }
@@ -1436,7 +1435,6 @@ static int hvm_access_cf8(void hvm_ioreq_init (struct domain *d) {spin_lock_init (&d->arch.hvm_domain.ioreq_server.lock); -INIT_LIST_HEAD (&d->arch.hvm_domain.ioreq_server.list);register_portio_handler (d,0xcf8 ,4 , hvm_access_cf8); }
xen/include/asm-x86/hvm/domain.h +6 -5
@@ -60,7 +60,6 @@ struct hvm_ioreq_server {/* Domain id of emulating domain */ domid_t domid; -ioservid_t id;struct hvm_ioreq_page ioreq;struct list_head ioreq_vcpu_list;struct hvm_ioreq_page bufioreq;
@@ -100,6 +99,9 @@ struct hvm_pi_ops {void (*do_resume)(struct vcpu *v); }; +#define MAX_NR_IOREQ_SERVERS 8 +#define DEFAULT_IOSERVID 0 +struct hvm_domain {/* Guest page range used for non-default ioreq servers */ struct {
@@ -109,11 +111,10 @@ struct hvm_domain {/* Lock protects all other values in the sub-struct and the default */ struct { -spinlock_t lock; -ioservid_t id; -struct list_head list; +spinlock_t lock; +struct hvm_ioreq_server *server[MAX_NR_IOREQ_SERVERS ]; +unsigned int count; } ioreq_server; -struct hvm_ioreq_server *default_ioreq_server;/* Cached CF8 for guest PCI config cycles */ uint32_t pci_cf8;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 12/12 x86/hvm/ioreq: add a new mappable resource type...
In reply to Paul Durrant... XENMEM_resource_ioreq_server
This patch adds support for a new resource type that can be mapped using the XENMEM_acquire_resource memory op.
If an emulator makes use of this resource type then, instead of mapping gfns, the IOREQ server will allocate pages from the heap. These pages will never be present in the P2M of the guest at any point and so are not vulnerable to any direct attack by the guest. They are only ever accessible by Xen and any domain that has mapping privilege over the guest (which may or may not be limited to the domain running the emulator).
NOTE: Use of the new resource type is not compatible with use of
XEN_DMOP_get_ioreq_server_info unless the XEN_DMOP_no_gfns flag is set.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
v5:
- Use get_ioreq_server() function rather than indexing array directly.
- Add more explanation into comments to state than mapping guest frames and allocation of pages for ioreq servers are not simultaneously permitted.
- Add a comment into asm/ioreq.h stating the meaning of the index value passed to hvm_get_ioreq_server_frame().
--- xen/arch/x86/hvm/ioreq.c | 131 +++++++++++++++++++++++++++++++++++++++- xen/arch/x86/mm.c | 27 +++++++++ xen/include/asm-x86/hvm/ioreq.h | 6 ++ xen/include/public/hvm/dm_op.h | 4 ++ xen/include/public/memory.h | 3 + 5 files changed, 170 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/ioreq.c +130 -1
@@ -260,6 +260,19 @@ static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;int rc; +if ( iorp->page ) + { +/* +* If a page has already been allocated (which will happen on +* demand if hvm_get_ioreq_server_frame() is called), then +* mapping a guest frame is not permitted. +*/ +if (gfn_eq (iorp->gfn,INVALID_GFN ) ) +return -EPERM ; + +return 0 ; + } +if ( d->is_dying )return -EINVAL ;
@@ -282,6 +295,61 @@ static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)return rc; } +static int hvm_alloc_ioreq_mfn (struct hvm_ioreq_server *s,bool buf) +{ +struct domain *currd = current->domain; +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; + +if ( iorp->page ) + { +/* +* If a guest frame has already been mapped (which may happen +* on demand if hvm_get_ioreq_server_info() is called), then +* allocating a page is not permitted. +*/ +if ( !gfn_eq (iorp->gfn,INVALID_GFN ) ) +return -EPERM ; + +return 0 ; + } + +/* +* Allocated IOREQ server pages are assigned to the emulating +* domain, not the target domain. This is because the emulator is +* likely to be destroyed after the target domain has been torn +* down, and we must use MEMF_no_refcount otherwise page allocation +* could fail if the emulating domain has already reached its +* maximum allocation. +*/ + iorp->page =alloc_domheap_page (currd, MEMF_no_refcount); +if ( !iorp->page ) +return -ENOMEM ; + + iorp->va =__map_domain_page_global (iorp->page); +if ( !iorp->va ) + { + iorp->page =NULL ; +return -ENOMEM ; + } + +clear_page (iorp->va); +return 0 ; +} + +static void hvm_free_ioreq_mfn (struct hvm_ioreq_server *s,bool buf) +{ +struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; + +if ( !iorp->page ) +return ; + +unmap_domain_page_global (iorp->va); + iorp->va =NULL ; + +put_page (iorp->page); + iorp->page =NULL ; +} +bool is_ioreq_server_page (struct domain *d,const struct page_info *page) {const struct hvm_ioreq_server *s;
@@ -488,6 +556,27 @@ static void hvm_ioreq_server_unmap_pages(struct hvm_ioreq_server *s)hvm_unmap_ioreq_gfn (s, false); } +static int hvm_ioreq_server_alloc_pages (struct hvm_ioreq_server *s) +{ +int rc; + + rc =hvm_alloc_ioreq_mfn (s, false); + +if ( !rc && (s->bufioreq_handling !=HVM_IOREQSRV_BUFIOREQ_OFF ) ) + rc =hvm_alloc_ioreq_mfn (s, true); + +if ( rc ) +hvm_free_ioreq_mfn (s, false); + +return rc; +} + +static void hvm_ioreq_server_free_pages (struct hvm_ioreq_server *s) +{ +hvm_free_ioreq_mfn (s, true); +hvm_free_ioreq_mfn (s, false); +} +static void hvm_ioreq_server_free_rangesets (struct hvm_ioreq_server *s) {unsigned int i;
@@ -614,7 +703,18 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, fail_add:hvm_ioreq_server_remove_all_vcpus (s); + +/* +* NOTE: It is safe to call both hvm_ioreq_server_unmap_pages() and +* hvm_ioreq_server_free_pages() in that order. +* This is because the former will do nothing if the pages +* are not mapped, leaving the page to be freed by the latter. +* However if the pages are mapped then the former will set +* the page_info pointer to NULL, meaning the latter will do +* nothing. +*/ hvm_ioreq_server_unmap_pages (s); +hvm_ioreq_server_free_pages (s);return rc; }
@@ -624,6 +724,7 @@ static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s)ASSERT (!s->enabled);hvm_ioreq_server_remove_all_vcpus (s);hvm_ioreq_server_unmap_pages (s); +hvm_ioreq_server_free_pages (s);hvm_ioreq_server_free_rangesets (s); }
@@ -762,7 +863,8 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, goto out; } - *ioreq_gfn =gfn_x (s->ioreq.gfn); +if ( ioreq_gfn ) + *ioreq_gfn =gfn_x (s->ioreq.gfn);if (HANDLE_BUFIOREQ (s) ) {
@@ -780,6 +882,33 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,return rc; } +mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); + +if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) ) + goto out; + +if (hvm_ioreq_server_alloc_pages (s) ) + goto out; + +if ( idx ==0 ) + mfn =_mfn (page_to_mfn (s->bufioreq.page)); +else if ( idx ==1 ) + mfn =_mfn (page_to_mfn (s->ioreq.page)); + + out: +spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +return mfn; +} +int hvm_map_io_range_to_ioreq_server (struct domain *d,ioservid_t id,uint32_t type,uint64_t start,uint64_t end)
xen/arch/x86/mm.c +27 -0
@@ -122,6 +122,7 @@#include <asm/fixmap.h> #include <asm/io_apic.h> #include <asm/pci.h> +#include <asm/hvm/ioreq.h> #include <asm/hvm/grant_table.h> #include <asm/pv/grant_table.h>
@@ -4795,6 +4796,27 @@ static int xenmem_acquire_grant_table(struct domain *d,return 0 ; } +static int xenmem_acquire_ioreq_server (struct domain *d, +unsigned int id, +unsigned long frame, +unsigned long nr_frames, +unsigned long mfn_list[]) +{ +unsigned int i; + +for ( i =0 ; i < nr_frames; i++ ) + { +mfn_t mfn =hvm_get_ioreq_server_frame (d, id, frame + i); + +if (mfn_eq (mfn,INVALID_MFN ) ) +return -EINVAL ; + + mfn_list[i] =mfn_x (mfn); + } + +return 0 ; +} +static int xenmem_acquire_resource (xen_mem_acquire_resource_t *xmar) {struct domain *d, *currd = current->domain;
@@ -4829,6 +4851,11 @@ static int xenmem_acquire_resource(xen_mem_acquire_resource_t *xmar) mfn_list);break ; +case XENMEM_resource_ioreq_server: + rc =xenmem_acquire_ioreq_server (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ; +default : rc = -EOPNOTSUPP ;break ;
xen/include/asm-x86/hvm/ioreq.h +6 -0
@@ -31,6 +31,12 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,unsigned long *ioreq_gfn, unsigned long *bufioreq_gfn, evtchn_port_t *bufioreq_port); +/* +* Get the mfn of either the buffered or synchronous ioreq frame. +* (idx == 0 -> buffered, idx == 1 -> synchronous). +*/ +mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx);int hvm_map_io_range_to_ioreq_server (struct domain *d,ioservid_t id,uint32_t type,uint64_t start,uint64_t end);
xen/include/public/hvm/dm_op.h +4 -0
@@ -90,6 +90,10 @@ struct xen_dm_op_create_ioreq_server {* the frame numbers passed back in gfns <ioreq_gfn> and <bufioreq_gfn> * respectively. (If the IOREQ Server is not handling buffered emulation * only <ioreq_gfn> will be valid). +* +* NOTE: To access the synchronous ioreq structures and buffered ioreq +* ring, it is preferable to use the XENMEM_acquire_resource memory +* op specifying resource type XENMEM_resource_ioreq_server. */ #define XEN_DMOP_get_ioreq_server_info 2
xen/include/public/memory.h +3 -0
@@ -664,10 +664,13 @@ struct xen_mem_acquire_resource {uint16_t type;#define XENMEM_resource_grant_table 0 +#define XENMEM_resource_ioreq_server 1/* * IN - a type-specific resource identifier, which must be zero * unless stated otherwise. +* +* type == XENMEM_resource_ioreq_server -> id == ioreq server id */ uint32_t id;/* IN - number of (4K) frames of the resource to be mapped */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 10/12 x86/hvm/ioreq: use gfn_t in struct hvm_ioreq_page
In reply to Paul DurrantThis patch adjusts the ioreq server code to use type-safe gfn_t values where possible. No functional change.
---
Cc: Andrew Cooper <[email protected]>
Cc: Jan Beulich <[email protected]>
--- xen/arch/x86/hvm/ioreq.c | 44 ++++++++++++++++++++-------------------- xen/include/asm-x86/hvm/domain.h | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-)
xen/arch/x86/hvm/ioreq.c +22 -22
@@ -211,7 +211,7 @@ bool handle_hvm_io_completion(struct vcpu *v)return true; } -static unsigned long hvm_alloc_ioreq_gfn (struct hvm_ioreq_server *s) +static gfn_t hvm_alloc_ioreq_gfn (struct hvm_ioreq_server *s) {struct domain *d = s->domain;unsigned int i;
@@ -221,20 +221,19 @@ static unsigned long hvm_alloc_ioreq_gfn(struct hvm_ioreq_server *s)for ( i =0 ; i <sizeof (d->arch.hvm_domain.ioreq_gfn.mask) *8 ; i++ ) {if (test_and_clear_bit (i, &d->arch.hvm_domain.ioreq_gfn.mask) ) -return d->arch.hvm_domain.ioreq_gfn.base + i; +return _gfn (d->arch.hvm_domain.ioreq_gfn.base + i); } -return gfn_x (INVALID_GFN ); +return INVALID_GFN ; } -static void hvm_free_ioreq_gfn (struct hvm_ioreq_server *s, -unsigned long gfn) +static void hvm_free_ioreq_gfn (struct hvm_ioreq_server *s,gfn_t gfn) {struct domain *d = s->domain; -unsigned int i = gfn - d->arch.hvm_domain.ioreq_gfn.base; +unsigned int i =gfn_x (gfn) - d->arch.hvm_domain.ioreq_gfn.base;ASSERT (!IS_DEFAULT (s)); -ASSERT (gfn !=gfn_x (INVALID_GFN )); +ASSERT (!gfn_eq (gfn,INVALID_GFN ));set_bit (i, &d->arch.hvm_domain.ioreq_gfn.mask); }
@@ -243,7 +242,7 @@ static void hvm_unmap_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) {struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; -if ( iorp->gfn ==gfn_x (INVALID_GFN ) ) +if (gfn_eq (iorp->gfn,INVALID_GFN ) )return ;destroy_ring_for_helper (&iorp->va, iorp->page);
@@ -252,7 +251,7 @@ static void hvm_unmap_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)if ( !IS_DEFAULT (s) )hvm_free_ioreq_gfn (s, iorp->gfn); - iorp->gfn =gfn_x (INVALID_GFN ); + iorp->gfn =INVALID_GFN ; }static int hvm_map_ioreq_gfn (struct hvm_ioreq_server *s,bool buf)
@@ -265,16 +264,17 @@ static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)return -EINVAL ;if (IS_DEFAULT (s) ) - iorp->gfn = buf ? - d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN ] : - d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN ]; + iorp->gfn =_gfn (buf ? + d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN ] : + d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN ]);else iorp->gfn =hvm_alloc_ioreq_gfn (s); -if ( iorp->gfn ==gfn_x (INVALID_GFN ) ) +if (gfn_eq (iorp->gfn,INVALID_GFN ) )return -ENOMEM ; - rc =prepare_ring_for_helper (d, iorp->gfn, &iorp->page, &iorp->va); + rc =prepare_ring_for_helper (d,gfn_x (iorp->gfn), &iorp->page, + &iorp->va);if ( rc )hvm_unmap_ioreq_gfn (s, buf);
@@ -313,10 +313,10 @@ static void hvm_remove_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)struct domain *d = s->domain;struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; -if (IS_DEFAULT (s) || iorp->gfn ==gfn_x (INVALID_GFN ) ) +if (IS_DEFAULT (s) ||gfn_eq (iorp->gfn,INVALID_GFN ) )return ; -if (guest_physmap_remove_page (d,_gfn (iorp->gfn), +if (guest_physmap_remove_page (d, iorp->gfn,_mfn (page_to_mfn (iorp->page)),0 ) )domain_crash (d);clear_page (iorp->va);
@@ -328,12 +328,12 @@ static int hvm_add_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq;int rc; -if (IS_DEFAULT (s) || iorp->gfn ==gfn_x (INVALID_GFN ) ) +if (IS_DEFAULT (s) ||gfn_eq (iorp->gfn,INVALID_GFN ) )return 0 ;clear_page (iorp->va); - rc =guest_physmap_add_page (d,_gfn (iorp->gfn), + rc =guest_physmap_add_page (d, iorp->gfn,_mfn (page_to_mfn (iorp->page)),0 );if ( rc ==0 )paging_mark_dirty (d,_mfn (page_to_mfn (iorp->page)));
@@ -592,8 +592,8 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s,INIT_LIST_HEAD (&s->ioreq_vcpu_list);spin_lock_init (&s->bufioreq_lock); - s->ioreq.gfn =gfn_x (INVALID_GFN ); - s->bufioreq.gfn =gfn_x (INVALID_GFN ); + s->ioreq.gfn =INVALID_GFN ; + s->bufioreq.gfn =INVALID_GFN ; rc =hvm_ioreq_server_alloc_rangesets (s, id);if ( rc )
@@ -762,11 +762,11 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,if (IS_DEFAULT (s) ) goto out; - *ioreq_gfn = s->ioreq.gfn; + *ioreq_gfn =gfn_x (s->ioreq.gfn);if ( s->bufioreq.va !=NULL ) { - *bufioreq_gfn = s->bufioreq.gfn; + *bufioreq_gfn =gfn_x (s->bufioreq.gfn); *bufioreq_port = s->bufioreq_evtchn; }
xen/include/asm-x86/hvm/domain.h +1 -1
@@ -36,7 +36,7 @@#include <public/hvm/dm_op.h> struct hvm_ioreq_page { -unsigned long gfn; +gfn_t gfn;struct page_info *page;void *va; };
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v7 11/12 x86/hvm/ioreq: defer mapping gfns until they are actually requsted
In reply to Paul DurrantA subsequent patch will introduce a new scheme to allow an emulator to map ioreq server pages directly from Xen rather than the guest P2M.
This patch lays the groundwork for that change by deferring mapping of gfns until their values are requested by an emulator. To that end, the pad field of the xen_dm_op_get_ioreq_server_info structure is re-purposed to a flags field and new flag, XEN_DMOP_no_gfns, defined which modifies the behaviour of XEN_DMOP_get_ioreq_server_info to allow the caller to avoid requesting the gfn values.
---
Cc: Ian Jackson <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
v3:
- Updated in response to review comments from Wei and Roger.
- Added a HANDLE_BUFIOREQ macro to make the code neater.
- This patch no longer introduces a security vulnerability since there is now an explicit limit on the number of ioreq servers that may be created for any one domain.
--- tools/libs/devicemodel/core.c | 8 +++++ tools/libs/devicemodel/include/xendevicemodel.h | 6 ++-- xen/arch/x86/hvm/dm.c | 9 ++++-- xen/arch/x86/hvm/ioreq.c | 41 +++++++++++++------------ xen/include/asm-x86/hvm/domain.h | 2 +- xen/include/public/hvm/dm_op.h | 32 +++++++++++-------- 6 files changed, 59 insertions(+), 39 deletions(-)
tools/libs/devicemodel/core.c +8 -0
@@ -188,6 +188,14 @@ int xendevicemodel_get_ioreq_server_info( data->id = id; +/* +* If the caller is not requesting gfn values then instruct the +* hypercall not to retrieve them as this may cause them to be +* mapped. +*/ +if (!ioreq_gfn && !bufioreq_gfn) + data->flags |= XEN_DMOP_no_gfns; + rc =xendevicemodel_op (dmod, domid,1 , &op,sizeof (op));if (rc)return rc;
tools/libs/devicemodel/include/xendevicemodel.h +3 -3
@@ -61,11 +61,11 @@ int xendevicemodel_create_ioreq_server(* @parm domid the domain id to be serviced * @parm id the IOREQ Server id. * @parm ioreq_gfn pointer to a xen_pfn_t to receive the synchronous ioreq -* gfn +* gfn. (May be NULL if not required) * @parm bufioreq_gfn pointer to a xen_pfn_t to receive the buffered ioreq -* gfn +* gfn. (May be NULL if not required) * @parm bufioreq_port pointer to a evtchn_port_t to receive the buffered -* ioreq event channel +* ioreq event channel. (May be NULL if not required) * @return 0 on success, -1 on failure. */ int xendevicemodel_get_ioreq_server_info(
xen/arch/x86/hvm/dm.c +6 -3
@@ -418,16 +418,19 @@ static int dm_op(const struct dmop_args *op_args) {struct xen_dm_op_get_ioreq_server_info *data = &op.u.get_ioreq_server_info; +const uint16_t valid_flags = XEN_DMOP_no_gfns; const_op = false; rc = -EINVAL ; -if ( data->pad ) +if ( data->flags & ~valid_flags )break ; rc =hvm_get_ioreq_server_info (d, data->id, - &data->ioreq_gfn, - &data->bufioreq_gfn, + (data->flags & XEN_DMOP_no_gfns) ? +NULL : &data->ioreq_gfn, + (data->flags & XEN_DMOP_no_gfns) ? +NULL : &data->bufioreq_gfn, &data->bufioreq_port);break ; }
xen/arch/x86/hvm/ioreq.c +22 -19
103 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +1 -1
@@ -68,8 +68,8 @@ struct hvm_ioreq_server {spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn;struct rangeset *range[NR_IO_RANGE_TYPES ]; +int bufioreq_handling;bool enabled; -bool bufioreq_atomic; };/*
xen/include/public/hvm/dm_op.h +19 -13
@@ -79,28 +79,34 @@ struct xen_dm_op_create_ioreq_server {* XEN_DMOP_get_ioreq_server_info: Get all the information necessary to * access IOREQ Server <id>. * -* The emulator needs to map the synchronous ioreq structures and buffered -* ioreq ring (if it exists) that Xen uses to request emulation. These are -* hosted in the target domain's gmfns <ioreq_gfn> and <bufioreq_gfn> -* respectively. In addition, if the IOREQ Server is handling buffered -* emulation requests, the emulator needs to bind to event channel -* <bufioreq_port> to listen for them. (The event channels used for -* synchronous emulation requests are specified in the per-CPU ioreq -* structures in <ioreq_gfn>). -* If the IOREQ Server is not handling buffered emulation requests then the -* values handed back in <bufioreq_gfn> and <bufioreq_port> will both be 0. +* If the IOREQ Server is handling buffered emulation requests, the +* emulator needs to bind to event channel <bufioreq_port> to listen for +* them. (The event channels used for synchronous emulation requests are +* specified in the per-CPU ioreq structures). +* In addition, if the XENMEM_acquire_resource memory op cannot be used, +* the emulator will need to map the synchronous ioreq structures and +* buffered ioreq ring (if it exists) from guest memory. If <flags> does +* not contain XEN_DMOP_no_gfns then these pages will be made available and +* the frame numbers passed back in gfns <ioreq_gfn> and <bufioreq_gfn> +* respectively. (If the IOREQ Server is not handling buffered emulation +* only <ioreq_gfn> will be valid). */ #define XEN_DMOP_get_ioreq_server_info 2struct xen_dm_op_get_ioreq_server_info {/* IN - server id */ ioservid_t id; -uint16_t pad; +/* IN - flags */ +uint16_t flags; + +#define _XEN_DMOP_no_gfns 0 +#define XEN_DMOP_no_gfns (1u << _XEN_DMOP_no_gfns) +/* OUT - buffered ioreq port */ evtchn_port_t bufioreq_port; -/* OUT - sync ioreq gfn */ +/* OUT - sync ioreq gfn (see block comment above) */ uint64_aligned_t ioreq_gfn; -/* OUT - buffered ioreq gfn */ +/* OUT - buffered ioreq gfn (see block comment above)*/ uint64_aligned_t bufioreq_gfn; };
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v7 03/12] tools/libxenforeignmemory: add support for resource mapping
In reply to Paul DurrantPaul Durrant writes ("[PATCH v7 03/12] tools/libxenforeignmemory: add support for resource mapping"):
Quoted 8 lines
A previous patch introduced a new
HYPERVISOR_memory_opto acquire guest resources for direct priv-mapping.This patch adds new functionality into libxenforeignmemory to make use of a new privcmd ioctl [1] that uses the new memory op to make such resources available via mmap(2).
[1] http://xenbits.xen.org/gitweb/?p=people/pauldu/linux.git;a=commit;h=ce59a05e6712
This looks plausible to me.
I wonder whether this, particularly for the ioreq server page, will make it possible to deprivilege earlier than I did in my own series on Friday.
(With my series, I do the depriv on entering the `running' state, which is quite late. It's after reading the migration stream, which is not ideal. But it did mean that qemu had already aquired the ioreq page by then so it worked. Unless that's just because my Xen was a bit old?)
Anyway,
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...
In reply to Paul DurrantQuoted 12 lines · Paul Durrant
...
XENMEM_resource_ioreq_serverThis patch adds support for a new resource type that can be mapped using the
XENMEM_acquire_resourcememory op.If an emulator makes use of this resource type then, instead of mapping gfns, the IOREQ server will allocate pages from the heap. These pages will never be present in the P2M of the guest at any point and so are not vulnerable to any direct attack by the guest. They are only ever accessible by Xen and any domain that has mapping privilege over the guest (which may or may not be limited to the domain running the emulator).
Quoted 7 lines
NOTE: Use of the new resource type is not compatible with use of
XEN_DMOP_get_ioreq_server_infounless theXEN_DMOP_no_gfnsflag is set.Signed-off-by Paul Durrant <[email protected]>Acked-by George Dunlap <[email protected]>Reviewed-by Wei Liu <[email protected]>
Just one nit below.
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 895
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +11
-0+mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); + +if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) )
If you use get_ioreq_server the id >= MAX_NR_IOREQ_SERVERS check is pointless, get_ioreq_server will already return NULL in that case.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...
Quoted 38 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 18 September 2017 17:18
To: Paul Durrant <[email protected]>
Cc: [email protected]; Stefano Stabellini <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Tim (Xen.org) <[email protected]>; Jan Beulich <[email protected]>
Subject: Re: [Xen-devel] [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...Quoted 11 lines · Paul Durrant
...
XENMEM_resource_ioreq_serverThis patch adds support for a new resource type that can be mapped using the
XENMEM_acquire_resourcememory op.If an emulator makes use of this resource type then, instead of mapping gfns, the IOREQ server will allocate pages from the heap. These pages will never be present in the P2M of the guest at any point and so are not vulnerable to any direct attack by the guest. They are only ever accessible by Xen and any domain that has mapping privilege over the guest (which may or may not be limited to the domain running the
emulator).
Quoted 3 lines
NOTE: Use of the new resource type is not compatible with use of
XEN_DMOP_get_ioreq_server_infounless theXEN_DMOP_no_gfnsflag is
Quoted 5 lines
set.
Signed-off-by Paul Durrant <[email protected]>Acked-by George Dunlap <[email protected]>Reviewed-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Just one nit below.
Quoted 16 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 895
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +11
-0+mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); + +if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) )If you use
get_ioreq_serverthe id >=MAX_NR_IOREQ_SERVERScheck is pointless,get_ioreq_serverwill already return NULL in that case.
True. Possibly not worth a v8 in itself, but if there are any more changes needed I'll fix it up.
Thanks,
Paul
Quoted 2 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 03/12] tools/libxenforeignmemory: add support for resource mapping
In reply to Ian JacksonQuoted 19 lines
-----Original Message-----
From: Ian Jackson [mailto:[email protected]]
Sent: 18 September 2017 17:16
To: Paul Durrant <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v7 03/12]tools/libxenforeignmemory: add support for resource mappingPaul Durrant writes ("[PATCH v7 03/12]
tools/libxenforeignmemory: add support for resource mapping"):Quoted 1 line
A previous patch introduced a new
HYPERVISOR_memory_opto acquireguest
Quoted 7 lines
resources for direct priv-mapping.
This patch adds new functionality into libxenforeignmemory to make use of a new privcmd ioctl [1] that uses the new memory op to make such resources available via mmap(2).
[1]
Quoted 9 lines
http://xenbits.xen.org/gitweb/?p=people/pauldu/linux.git;a=commit;h=ce5
9a05e6712This looks plausible to me.
I wonder whether this, particularly for the ioreq server page, will make it possible to deprivilege earlier than I did in my own series on Friday.
It should, eventually. The necessary changes to privcmd would also need to make it into dom0, as well as the changes to QEMU (both of which I have on branches ready to go).
Quoted 5 lines
(With my series, I do the depriv on entering the `running' state, which is quite late. It's after reading the migration stream, which is not ideal. But it did mean that qemu had already aquired the ioreq page by then so it worked. Unless that's just because my Xen was a bit old?)
The acquisition of the ioreq pages is towards the end of the hvm init routine, so depriv any time after that (under the old scheme) should be doable.
Quoted 4 lines
Anyway,
Acked-by Ian Jackson <[email protected]>
Great. Thanks,
Paul
Quoted 2 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Paul DurrantPing?
Quoted 24 lines
-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 18 September 2017 16:31
To: [email protected]
Cc: Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>
Subject: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsIn the case where a PV domain is mapping guest resources then it needs make
theHYPERVISOR_mmu_updatecall usingDOMID_SELF, rather than the guest domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.This patch removes a check which currently disallows mapping of a page when
the owner of the page tables matches the domain passed toHYPERVISOR_mmu_update, but that domain is not the real owner of the page.
The check was introduced by patchd3c6a215ca9("x86: Clean upget_page_from_l1e()to correctly distinguish between owner-of-pte and owner-of-data-page in all cases") but it's not clear why it was needed.
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>
I believe this is now the only patch in the series without a R-b or A-b.
Paul
Quoted 33 lines
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>--- xen/arch/x86/mm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)xen/arch/x86/mm.c +8
-6@@ -1024,12 +1024,15 @@ get_page_from_l1e( (real_pg_owner != dom_cow) ) ) {/* -* Let privileged domains transfer the right to map their target -* domain's pages. This is used to allow stub-domain pvfb export to -* dom0, until pvfb supports granted mappings. At that time this -* minor hack can go away. +* If the real page owner is not the domain specified in the +* hypercall then establish that the specified domain has +* mapping privilege over the page owner. +* This is used to allow stub-domain pvfb export to dom0. It is +* also used to allow a privileged PV domain to map mfns using +* DOMID_SELF, which is needed for mapping guest resources such +* grant table frames. */ -if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING, --
Quoted 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 14:51, <[email protected]> wrote:
Ping?
Your patch series hasn't been forgotten, but I can't currently predict when I would be able to look at it (together with the well over 100 other patches sitting in the queue). I can only promise: As soon as other, often higher priority, work permits me to get there (unless Andrew manages to get there earlier).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Paul DurrantQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
In the case where a PV domain is mapping guest resources then it needs make the
HYPERVISOR_mmu_updatecall usingDOMID_SELF, rather than the guest domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.
Since things are presently working fine, I think the description is not really accurate. You only require the new behavior if you don't know the GFN of the page you want to map, and that it has to be DOMID_SELF that should be passed also doesn't appear to derive from anything else. To properly judge about the need for this patch it would help if it was briefly explained why being able to map by GFN is no longer sufficient, and to re-word the DOMID_SELF part.
The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.
Quoted 6 lines
This patch removes a check which currently disallows mapping of a page when the owner of the page tables matches the domain passed to
HYPERVISOR_mmu_update, but that domain is not the real owner of the page. The check was introduced by patchd3c6a215ca9("x86: Clean upget_page_from_l1e()to correctly distinguish between owner-of-pte and owner-of-data-page in all cases") but it's not clear why it was needed.
I think the goal here simply was to not permit anything that doesn't really need permitting. Furthermore the check being "introduced" there was, afaict, replacing the earlier d != curr->domain.
Quoted 7 lines
xen/arch/x86/mm.c +0
-1@@ -1024,12 +1024,15 @@ get_page_from_l1e( (real_pg_owner != dom_cow) ) ) {/* -* Let privileged domains transfer the right to map their target
xen/arch/x86/mm.c get_page_from_l1e( · line 1033
Quoted 10 lines
xen/arch/x86/mm.c +7
-3-* domain's pages. This is used to allow stub-domain pvfb export to -* dom0, until pvfb supports granted mappings. At that time this -* minor hack can go away. +* If the real page owner is not the domain specified in the +* hypercall then establish that the specified domain has +* mapping privilege over the page owner. +* This is used to allow stub-domain pvfb export to dom0. It is +* also used to allow a privileged PV domain to map mfns using +* DOMID_SELF, which is needed for mapping guest resources such +* grant table frames.
How do grant table frames come into the picture here? So far I had assumed only ioreq server pages are in need of this.
xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
xen/arch/x86/mm.c +1
-1*/ -if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,
I'm concerned of the effect of the change on the code paths which you're not really interested in: alloc_l1_table(), ptwr_emulated_update(), and shadow_get_page_from_l1e() all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to __do_update_va_mapping() calling mod_l1_table().
I therefore wonder whether the solution to your problem wouldn't rather be MMU_FOREIGN_PT_UPDATE (name subject to improvement suggestions). This at the same time would address my concern regarding the misleading DOMID_SELF passing when really a foreign domain's page is meant.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
In the case where a PV domain is mapping guest resources then it needs make the
HYPERVISOR_mmu_updatecall usingDOMID_SELF, rather than the guest domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.
Quoted 7 lines
Since things are presently working fine, I think the description is not really accurate. You only require the new behavior if you don't know the GFN of the page you want to map, and that it has to be
DOMID_SELFthat should be passed also doesn't appear to derive from anything else. To properly judge about the need for this patch it would help if it was briefly explained why being able to map by GFN is no longer sufficient, and to re-word theDOMID_SELFpart.
I think there is still confusion as to the purpose here.
For security and scalability reasons, we explicitly want to be able to create frames which are not part of a guests p2m. We still need to map these frames however.
The frames are referred to in an abstract way by a space id/offset. To create mappings of these frames, PV guests pass an array which Xen fills in with MFNs, while HVM guests pass an array of GFNs which have their mappings updated.
The problem is trying to map an MFN belonging to a target domain, because Xen interprets the frame under the targets paging mode. Passing DOMID_SELF here is Pauls way of getting Xen to interpret the frame under current's paging mode.
Alternative suggestions welcome.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Paul DurrantQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
For grant tables I can see this as the primary issue, but isn't the goal of not exposing IOREQ server pages an even more important aspect, and hence more relevant to mention here?
Quoted 4 lines
NOTE: Whilst the new op is not intrinsicly specific to the x86 architecture,
I have no means to test it on an ARM platform and so cannot verify that it functions correctly. Hence it is currently only implemented for x86.
Which will require things to be moved around later on. May I instead suggest to put it in common code and simply have a small #ifdef somewhere causing the operation to fail early for ARM?
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 4771
Quoted 7 lines
xen/arch/x86/mm.c +1
-0@@ -4768,6 +4768,107 @@ int xenmem_add_to_physmap_one(return rc; } +static int xenmem_acquire_grant_table(struct domain *d,
I don't think static functions need a xenmem_ prefix.
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 4798
Quoted 1 line
xen/arch/x86/mm.c +1
-0+static int xenmem_acquire_resource (xen_mem_acquire_resource_t *xmar)
const?
Quoted 7 lines
xen/arch/x86/mm.c +7
-0+{ +struct domain *d, *currd = current->domain; +unsigned long *mfn_list; +int rc; + +if ( xmar->nr_frames ==0 ) +return -EINVAL ;
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 4815
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+ + d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d); +if ( rc ) + goto out; + + mfn_list = xmalloc_array(unsigned long, xmar->nr_frames);
Despite XSA-77 there should not be any new disaggregation related security risks (here: memory exhaustion and long lasting loops). Large requests need to be refused or broken up.
Quoted 17 lines
xen/common/grant_table.c +4
-5@@ -3607,38 +3607,58 @@ int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, }#endif -int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn, -mfn_t *mfn) -{ -int rc =0 ; -grant_write_lock (d->grant_table); +static mfn_t gnttab_get_frame_locked (struct domain *d,unsigned long idx) +{ +struct grant_table *gt = d->grant_table; +mfn_t mfn =INVALID_MFN ;
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, · line 3622
Quoted 10 lines
xen/common/grant_table.c +3
-3-if ( d->grant_table->gt_version ==0 ) - d->grant_table->gt_version =1 ; +if ( gt->gt_version ==0 ) + gt->gt_version =1 ; -if ( d->grant_table->gt_version ==2 && +if ( gt->gt_version ==2 && (idx & XENMAPIDX_grant_table_status) ) { idx &= ~XENMAPIDX_grant_table_status;
I don't see the use of this bit mentioned anywhere in the public header addition.
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, · line 3645
Quoted 7 lines
xen/common/grant_table.c +7
-0+mfn_t gnttab_get_frame (struct domain *d,unsigned long idx) +{ +mfn_t mfn; + +grant_write_lock (d->grant_table); + mfn =gnttab_get_frame_locked (d, idx); +grant_write_unlock (d->grant_table);
Hmm, a read lock is insufficient here only because of the possible bumping of the version from 0 to 1 afaict, but I don't really see why what now becomes gnttab_get_frame_locked() does that in the first place.
Quoted 21 lines
xen/include/public/memory.h +14
-1@@ -650,7 +650,43 @@ struct xen_vnuma_topology_info {typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t ;DEFINE_XEN_GUEST_HANDLE (xen_vnuma_topology_info_t); -/* Next available subop number is 28 */ +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +/* + * Get the pages for a particular guest resource, so that they can be + * mapped directly by a tools domain. + */ +#define XENMEM_acquire_resource 28 +struct xen_mem_acquire_resource { + /* IN - the domain whose resource is to be mapped */ + domid_t domid; + /* IN - the type of resource (defined below) */ + uint16_t type; + +#define XENMEM_resource_grant_table 0
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 676
Quoted 10 lines
xen/include/public/memory.h +10
-0+ +/* +* IN - a type-specific resource identifier, which must be zero +* unless stated otherwise. +*/ +uint32_t id; +/* IN - number of (4K) frames of the resource to be mapped */ +uint32_t nr_frames; +/* IN - the index of the initial frame to be mapped */ +uint64_aligned_t frame;
There are 32 bits of unnamed padding ahead of this field - please name it and check it's set to zero.
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 679
Quoted 3 lines
xen/include/public/memory.h +3
-0+/* IN/OUT - If the tools domain is PV then, upon return, gmfn_list +* will be populated with the MFNs of the resource. +* If the tools domain is HVM then it is expected that, on
s/tools domain/calling domain/ (twice)?
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 680
Quoted 1 line
xen/include/public/memory.h +1
-0+* entry, gmfn_list will be populated with a list of GFNs
s/will be/is/ to further emphasize the input vs output difference?
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 683
Quoted 3 lines
xen/include/public/memory.h +3
-0+* that will be mapped to the MFNs of the resource. +*/ +XEN_GUEST_HANDLE (xen_pfn_t) gmfn_list;
What about a 32-bit x86 tool stack domain as caller here? I don't think you want to limit it to just the low 16Tb? Nor are you adding a compat translation layer.
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 687
Quoted 4 lines
xen/include/public/memory.h +4
-0+}; +typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t ; + +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
Also please group this with the other similar section, without introducing a second identical #if. After all we have ...
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 689
Quoted 1 line
xen/include/public/memory.h +1
-0+/* Next available subop number is 29 */
... this to eliminate the need to have things numerically sorted in this file.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Andrew CooperQuoted 17 lines
Quoted 1 line
Quoted 1 line · On 25.09.17 at 15:29, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
In the case where a PV domain is mapping guest resources then it needs make the
HYPERVISOR_mmu_updatecall usingDOMID_SELF, rather than the guest domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.Quoted 7 lines
Since things are presently working fine, I think the description is not really accurate. You only require the new behavior if you don't know the GFN of the page you want to map, and that it has to be
DOMID_SELFthat should be passed also doesn't appear to derive from anything else. To properly judge about the need for this patch it would help if it was briefly explained why being able to map by GFN is no longer sufficient, and to re-word theDOMID_SELFpart.I think there is still confusion as to the purpose here.
Quoted 8 lines
For security and scalability reasons, we explicitly want to be able to create frames which are not part of a guests p2m. We still need to map these frames however.
The frames are referred to in an abstract way by a space id/offset. To create mappings of these frames, PV guests pass an array which Xen fills in with MFNs, while HVM guests pass an array of GFNs which have their mappings updated.
In the course of reviewing patch 2 I've gained some more understanding of the intentions. Still it would have been helpful to have an abstract understanding already before even looking at patch 1, i.e. presented in the overview mail.
Quoted 6 lines
The problem is trying to map an MFN belonging to a target domain, because Xen interprets the frame under the targets paging mode. Passing
DOMID_SELFhere is Pauls way of getting Xen to interpret the frame under current's paging mode.Alternative suggestions welcome.
I've given one in the earlier reply.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Paul DurrantQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one, xc_core_arch_get_scratch_gpfn() could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 06/12] x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn
In reply to Paul DurrantQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Since ioreq servers are only relevant to HVM guests and all the names in question unequivocally refer to guest frame numbers, name them all .*gfn to avoid any confusion.
This patch is purely cosmetic. No semantic or functional change.
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
Are there any dependencies here on prior patches in the series (at the first glance it looks like there might not be)? I.e. could it go in ahead of the earlier parts?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 07/12] x86/hvm/ioreq: use bool rather than bool_t
In reply to Paul DurrantQuoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
This patch changes use of
bool_tto bool in the ioreq server code. It also fixes an incorrect indentation in a continuation line.This patch is purely cosmetic. No semantic or functional change.
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>
with the same question as on patch 6.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 06/12] x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn
In reply to Jan BeulichQuoted 14 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:29
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 06/12] x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfnQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Since ioreq servers are only relevant to HVM guests and all the names in question unequivocally refer to guest frame numbers, name them all .*gfn to avoid any confusion.
Quoted 8 lines
Quoted 5 lines
This patch is purely cosmetic. No semantic or functional change.
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Wei Liu <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 3 lines
Are there any dependencies here on prior patches in the series (at the first glance it looks like there might not be)? I.e. could it go in ahead of the earlier parts?
No, I don' believe there are any dependencies (same for patch #7).
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Jan BeulichQuoted 17 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
In the case where a PV domain is mapping guest resources then it needs
make
Quoted 1 line
the
HYPERVISOR_mmu_updatecall usingDOMID_SELF, rather than theguest
Quoted 2 lines
domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.
Quoted 7 lines
Since things are presently working fine, I think the description is not really accurate. You only require the new behavior if you don't know the GFN of the page you want to map, and that it has to be
DOMID_SELFthat should be passed also doesn't appear to derive from anything else. To properly judge about the need for this patch it would help if it was briefly explained why being able to map by GFN is no longer sufficient, and to re-word theDOMID_SELFpart.
Ok, I can expand the explanation.
Quoted 8 lines
The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use
XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.
The hypercall is PV-only. For a PVH/HVM tools domain things are handled by doing an add-to-physmap to gfns specified by the tools domain. I have tested both PV and HVM clients of my new memory op.
Quoted 5 lines
Quoted 2 lines
This patch removes a check which currently disallows mapping of a page
when
Quoted 2 lines
the owner of the page tables matches the domain passed to
HYPERVISOR_mmu_update, but that domain is not the real owner of the
Quoted 8 lines
page.
Quoted 3 lines
The check was introduced by patch
d3c6a215ca9("x86: Clean upget_page_from_l1e()to correctly distinguish between owner-of-pte and owner-of-data-page in all cases") but it's not clear why it was needed.I think the goal here simply was to not permit anything that doesn't really need permitting. Furthermore the check being "introduced" there was, afaict, replacing the earlier d !=
curr->domain.
I'm not entirely sure why that check was there though.
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/mm.c +2
-4@@ -1024,12 +1024,15 @@ get_page_from_l1e( (real_pg_owner != dom_cow) ) ) {/* -* Let privileged domains transfer the right to map their target -* domain's pages. This is used to allow stub-domain pvfb export to -* dom0, until pvfb supports granted mappings. At that time this -* minor hack can go away. +* If the real page owner is not the domain specified in the +* hypercall then establish that the specified domain has
Quoted 9 lines
xen/arch/x86/mm.c get_page_from_l1e( · line 1033
Quoted 5 lines
xen/arch/x86/mm.c +5
-0+* mapping privilege over the page owner. +* This is used to allow stub-domain pvfb export to dom0. It is +* also used to allow a privileged PV domain to map mfns using +* DOMID_SELF, which is needed for mapping guest resources such +* grant table frames. How do grant table frames come into the picture here? So far I had assumed only ioreq server pages are in need of this.
Grant frames required less re-work in other places so I started with them. Nothing to prevent the series from being re-ordered now that it's complete.
Quoted 14 lines
xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
xen/arch/x86/mm.c +1
-1*/ -if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().
Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.
Ok. I'm not familiar with MMU_FOREIGN_PT_UPDATE so I'd need to investigate. I just need a mechanism for a privileged PV guest to map pages belonging to another guest that don't appear in that guests P2M. As I said above, it's much simpler if the tools domain is PVH or HVM.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 12 lines
Quoted 11 lines
Quoted 1 line · On 25.09.17 at 16:42, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use
XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.
Quoted 3 lines
The hypercall is PV-only. For a PVH/HVM tools domain things are handled by doing an add-to-physmap to gfns specified by the tools domain. I have tested both PV and HVM clients of my new memory op.
And how is this add-to-physmap any better superpage shattering wise than the old mechansim?
Quoted 19 lines
Quoted 13 lines
xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 5 lines
xen/arch/x86/mm.c +1
-1-if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.
Quoted 4 lines
Ok. I'm not familiar with
MMU_FOREIGN_PT_UPDATEso I'd need to investigate. I just need a mechanism for a privileged PV guest to map pages belonging to another guest that don't appear in that guests P2M. As I said above, it's much simpler if the tools domain is PVH or HVM.
Hmm, looks like I wasn't able to express things such that it becomes clear the MMU_FOREIGN_PT_UPDATE is the proposed (sub-optimal) name for a new sub-op.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Jan BeulichQuoted 25 lines
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 25 September 2017 14:50
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
For grant tables I can see this as the primary issue, but isn't the goal of not exposing IOREQ server pages an even more important aspect, and hence more relevant to mention here?
Quoted 4 lines
NOTE: Whilst the new op is not intrinsicly specific to the x86 architecture,
I have no means to test it on an ARM platform and so cannot verify that it functions correctly. Hence it is currently only implemented for x86.
Quoted 4 lines
Which will require things to be moved around later on. May I instead suggest to put it in common code and simply have a small #ifdef somewhere causing the operation to fail early for ARM?
Ok. If you prefer that approach then I'll do that.
Quoted 11 lines
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 4771
Quoted 8 lines
xen/arch/x86/mm.c +1
-0@@ -4768,6 +4768,107 @@ int xenmem_add_to_physmap_one(return rc; } +static int xenmem_acquire_grant_table(struct domain *d,I don't think static functions need a
xenmem_prefix.
Ok.
Quoted 4 lines
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 4772
Quoted 1 line
xen/arch/x86/mm.c +1
-0+static int xenmem_acquire_resource(xen_mem_acquire_resource_t*xmar)
const?
Yes.
Quoted 14 lines
Quoted 14 lines
xen/arch/x86/mm.c +13
-0+{ +struct domain *d, *currd = current->domain; +unsigned long *mfn_list; +int rc; + +if ( xmar->nr_frames ==0 ) +return -EINVAL ; + + d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d);
Quoted 8 lines
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 4815
Quoted 4 lines
xen/arch/x86/mm.c +4
-0+if ( rc ) + goto out; + + mfn_list = xmalloc_array(unsigned long, xmar->nr_frames);Despite XSA-77 there should not be any new disaggregation related security risks (here: memory exhaustion and long lasting loops). Large requests need to be refused or broken up.
Ok, I'll put an upper limit on frames.
Quoted 25 lines
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct
Quoted 4 lines
xen/common/grant_table.c +0
-0@@ -3607,38 +3607,58 @@ int mem_sharing_gref_to_gfn(struct
grant_table*gt,grant_ref_tref,xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref,
Quoted 10 lines
xen/common/grant_table.c +1
-5}#endif -int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn, -mfn_t *mfn) -{ -int rc =0 ; -grant_write_lock (d->grant_table); +static mfn_t gnttab_get_frame_locked(struct domain *d, unsigned longidx)
Quoted 9 lines
xen/common/grant_table.c +5
-2+{ +struct grant_table *gt = d->grant_table; +mfn_t mfn =INVALID_MFN ; -if ( d->grant_table->gt_version ==0 ) - d->grant_table->gt_version =1 ; +if ( gt->gt_version ==0 ) + gt->gt_version =1 ;
Quoted 8 lines
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, · line 3622
Quoted 5 lines
xen/common/grant_table.c +1
-1-if ( d->grant_table->gt_version ==2 && +if ( gt->gt_version ==2 && (idx & XENMAPIDX_grant_table_status) ) { idx &= ~XENMAPIDX_grant_table_status;I don't see the use of this bit mentioned anywhere in the public header addition.
Good point, I do need to mention v2 now that Juergen has revived it.
Quoted 13 lines
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, · line 3645
Quoted 8 lines
xen/common/grant_table.c +7
-0+mfn_t gnttab_get_frame (struct domain *d,unsigned long idx) +{ +mfn_t mfn; + +grant_write_lock (d->grant_table); + mfn =gnttab_get_frame_locked (d, idx); +grant_write_unlock (d->grant_table);Hmm, a read lock is insufficient here only because of the possible bumping of the version from 0 to 1 afaict, but I don't really see why what now becomes
gnttab_get_frame_locked()does that in the first place.
It may be the case that, after Juergen's recent re-arrangements, that the version will always be set by this point. I'll check and drop to and ASSERT on the version and read-lock if I can.
Quoted 27 lines
Quoted 27 lines
xen/include/public/memory.h +19
-1@@ -650,7 +650,43 @@ struct xen_vnuma_topology_info {typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t ;DEFINE_XEN_GUEST_HANDLE (xen_vnuma_topology_info_t); -/* Next available subop number is 28 */ +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +/* + * Get the pages for a particular guest resource, so that they can be + * mapped directly by a tools domain. + */ +#define XENMEM_acquire_resource 28 +struct xen_mem_acquire_resource { + /* IN - the domain whose resource is to be mapped */ + domid_t domid; + /* IN - the type of resource (defined below) */ + uint16_t type; + +#define XENMEM_resource_grant_table 0 + + /* + * IN - a type-specific resource identifier, which must be zero + * unless stated otherwise. + */
Quoted 8 lines
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 676
Quoted 5 lines
xen/include/public/memory.h +5
-0+uint32_t id; +/* IN - number of (4K) frames of the resource to be mapped */ +uint32_t nr_frames; +/* IN - the index of the initial frame to be mapped */ +uint64_aligned_t frame;There are 32 bits of unnamed padding ahead of this field - please name it and check it's set to zero.
Ah yes, for some reason the #define above had made me think things were aligned at this point.
Quoted 6 lines
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 679
Quoted 4 lines
xen/include/public/memory.h +3
-0+/* IN/OUT - If the tools domain is PV then, upon return, gmfn_list +* will be populated with the MFNs of the resource. +* If the tools domain is HVM then it is expected that, on s/tools domain/calling domain/ (twice)?
Ok.
Quoted 4 lines
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 680
Quoted 2 lines
xen/include/public/memory.h +1
-0+* entry, gmfn_list will be populated with a list of GFNs s/will be/is/ to further emphasize the input vs output difference?
Ok.
Quoted 8 lines
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 683
Quoted 4 lines
xen/include/public/memory.h +3
-0+* that will be mapped to the MFNs of the resource. +*/ +XEN_GUEST_HANDLE (xen_pfn_t) gmfn_list;What about a 32-bit x86 tool stack domain as caller here? I don't think you want to limit it to just the low 16Tb? Nor are you adding a compat translation layer.
Ok. Good point, even though somewhat unlikely.
Quoted 10 lines
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 685
Quoted 3 lines
xen/include/public/memory.h +2
-0+}; +typedef struct xen_mem_acquire_resource
xen_mem_acquire_resource_t;xen/include/public/memory.h struct xen_vnuma_topology_info { · line 687
Quoted 2 lines
xen/include/public/memory.h +2
-0+ +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ Also please group this with the other similar section, without introducing a second identical #if. After all we have ...
Quoted 4 lines
xen/include/public/memory.h struct xen_vnuma_topology_info { · line 689
Quoted 1 line
xen/include/public/memory.h +1
-0+/* Next available subop number is 29 */ ... this to eliminate the need to have things numerically sorted in this file.
Ok.
Paul
Quoted 7 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Jan BeulichQuoted 22 lines
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 25 September 2017 15:50
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 12 lines
Quoted 11 lines
Quoted 1 line · On 25.09.17 at 16:42, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use
XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.
Quoted 8 lines
Quoted 1 line
The hypercall is PV-only. For a PVH/HVM tools domain things are handled
by
Quoted 1 line
doing an add-to-physmap to gfns specified by the tools domain. I have
tested
Quoted 1 line
both PV and HVM clients of my new memory op.
And how is this add-to-physmap any better superpage shattering wise than the old mechansim?
Because the calling domain can make an intelligent choice about what gfns to use?
Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
xen/arch/x86/mm.c +1
-1-if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().Quoted 7 lines
Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.Ok. I'm not familiar with
MMU_FOREIGN_PT_UPDATEso I'd need toinvestigate.
Quoted 9 lines
Quoted 1 line
I just need a mechanism for a privileged PV guest to map pages belonging
to
Quoted 2 lines
another guest that don't appear in that guests P2M. As I said above, it's much simpler if the tools domain is PVH or HVM.
Hmm, looks like I wasn't able to express things such that it becomes clear the
MMU_FOREIGN_PT_UPDATEis the proposed (sub-optimal) name for a new sub-op.
Ok. I see what you mean now.
Paul
Quoted 7 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Jan BeulichQuoted 15 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
Quoted 7 lines
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one,xc_core_arch_get_scratch_gpfn()could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...
The shattering was Andrew's observation. Andrew, can you comment?
Even if it's not the case, it's suboptimal to have to write-lock and update the guest's P2M twice just to map a page of grants, which I will mention in the commit comment too.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
In reply to Paul DurrantQuoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +0
-0@@ -33,6 +33,32 @@#include <public/hvm/ioreq.h>
xen/arch/x86/hvm/ioreq.c line 45
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+static void set_ioreq_server (struct domain *d,unsigned int id, +struct hvm_ioreq_server *s) +{ +ASSERT (id <MAX_NR_IOREQ_SERVERS ); +ASSERT (!s || !d->arch.hvm_domain.ioreq_server.server[id]); + + d->arch.hvm_domain.ioreq_server.server[id] = s; +} + +static struct hvm_ioreq_server *get_ioreq_server(struct domain *d,
const (for the parameter)?
xen/arch/x86/hvm/ioreq.c line 55
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+ unsigned int id) +{ +if ( id >=MAX_NR_IOREQ_SERVERS ) +return NULL ; + +return d->arch.hvm_domain.ioreq_server.server[id]; +} + +#define IS_DEFAULT (s) \ + ((s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID))
Is it really useful to go through get_ioreq_server() here?
xen/arch/x86/hvm/ioreq.c line 60
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +4
-0+#define FOR_EACH_IOREQ_SERVER (d, id, s) \ + for ( (id) = 0, (s) = get_ioreq_server((d), (id)); \ + (id) < MAX_NR_IOREQ_SERVERS; \ + (s) = get_ioreq_server((d), ++(id)) )
There are three instances of stray pairs of parentheses here, each time when a macro parameter gets passed unaltered to get_ioreq_server().
xen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, · line 337
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +1
-0@@ -301,8 +333,9 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, } } + static int hvm_ioreq_server_add_vcpu(struct hvm_ioreq_server *s,
Stray addition of a blank line?
xen/arch/x86/hvm/ioreq.c static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s, · line 540
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +2
-2@@ -501,19 +531,19 @@ static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s, }static int hvm_ioreq_server_alloc_rangesets (struct hvm_ioreq_server *s, -bool is_default) +ioservid_t id) {unsigned int i;int rc; -if ( is_default ) +if (IS_DEFAULT (s) ) goto done;
Wouldn't comparing the ID be even cheaper in cases like this one? And perhaps assert that ID and server actually match?
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +1
-7@@ -741,35 +754,34 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id);
xen/arch/x86/hvm/ioreq.c int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) · line 765
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +6
-3-if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; -domain_pause (d); + rc = -EPERM ; +if (IS_DEFAULT (s) ) + goto out;
Here I think it is particularly strange to not use the ID in the check; this could even be done without holding the lock. Same in other functions below.
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c +1
-7@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id);
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 808
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +6
-3-if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; - *ioreq_gfn = s->ioreq.gfn; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out;
Why EOPNOTSUPP when it was just the same ENOENT as no server at all before (same further down)?
Quoted 22 lines
xen/arch/x86/hvm/ioreq.c +3
-11void hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */ -list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { -bool is_default = (s == d->arch.hvm_domain.default_ioreq_server); - -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ;
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v) · line 1076
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +6
-2+if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); -hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;
Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
xen/arch/x86/hvm/ioreq.c int hvm_set_dm_domain(struct domain *d, domid_t domid) · line 1114
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +1
-1@@ -1111,7 +1111,7 @@ int hvm_set_dm_domain(struct domain *d, domid_t domid)* still be set and thus, when the server is created, it will have * the correct domid. */ - s = d->arch.hvm_domain.default_ioreq_server; + s =get_ioreq_server (d,DEFAULT_IOSERVID );
Similar to above, is it really useful to go through get_ioreq_server() here (and in other similar cases)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 09/12] x86/hvm/ioreq: simplify code and use consistent naming
In reply to Paul DurrantQuoted 15 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
This patch re-works much of the ioreq server initialization and teardown code:
- The hvm_map/unmap_ioreq_gfn() functions are expanded to call through to hvm_alloc/free_ioreq_gfn() rather than expecting them to be called separately by outer functions.
- Several functions now test the validity of thehvm_ioreq_pagegfn value to determine whether they need to act. This means can be safely called for the bufioreq page even when it is not used.
- hvm_add/remove_ioreq_gfn() simply return in the case of the default IOREQ server so callers no longer need to test before calling.
-hvm_ioreq_server_setup_pages()is renamed tohvm_ioreq_server_map_pages()to mirror the existinghvm_ioreq_server_unmap_pages().
Quoted 5 lines
All of this significantly shortens the code.
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>
(in case it matters)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 10/12] x86/hvm/ioreq: use gfn_t in struct hvm_ioreq_page
In reply to Paul DurrantQuoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
This patch adjusts the ioreq server code to use type-safe
gfn_tvalues where possible. No functional change.Signed-off-by Paul Durrant <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>
Again in case it matters
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Paul DurrantQuoted 26 lines
Quoted 26 lines
Quoted 1 line · On 25.09.17 at 16:56, <[email protected]> wrote:
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 25 September 2017 15:50
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 12 lines
Quoted 11 lines
Quoted 1 line · On 25.09.17 at 16:42, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use
XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.Quoted 1 line
The hypercall is PV-only. For a PVH/HVM tools domain things are handled
by
Quoted 1 line
doing an add-to-physmap to gfns specified by the tools domain. I have
Quoted 8 lines
Quoted 5 lines
tested
Quoted 1 line
both PV and HVM clients of my new memory op.
And how is this add-to-physmap any better superpage shattering wise than the old mechansim?
Because the calling domain can make an intelligent choice about what gfns to use?
And why was an intelligent choice not possible with the old mechanism? The calling domain is the tool stack one in both cases, isn't it?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 43 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 16:31
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [Xen-devel] [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 3 lines
Quoted 3 lines
Quoted 1 line · On 25.09.17 at 16:56, <[email protected]> wrote:
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf OfJan
Quoted 20 lines
Quoted 20 lines
Beulich
Sent: 25 September 2017 15:50
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 12 lines
Quoted 11 lines
Quoted 1 line · On 25.09.17 at 16:42, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use
XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.Quoted 1 line
Quoted 1 line
Quoted 1 line
The hypercall is PV-only. For a PVH/HVM tools domain things are
handled
Quoted 8 lines
Quoted 7 lines
by
Quoted 1 line
doing an add-to-physmap to gfns specified by the tools domain. I have
tested
Quoted 1 line
both PV and HVM clients of my new memory op.
And how is this add-to-physmap any better superpage shattering wise than the old mechansim?
Quoted 7 lines
Quoted 1 line
Because the calling domain can make an intelligent choice about what gfns
to
Quoted 1 line
use?
And why was an intelligent choice not possible with the old mechanism? The calling domain is the tool stack one in both cases, isn't it?
True, I suppose.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 11/12] x86/hvm/ioreq: defer mapping gfns until they are actually requsted
In reply to Paul Durrantxen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, · line 358
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +2
-0@@ -354,6 +354,9 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, } } +#define HANDLE_BUFIOREQ (s) \ + (s->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
(s)
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 758
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +1
-0@@ -762,11 +755,20 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,if (IS_DEFAULT (s) ) goto out; +if ( ioreq_gfn || bufioreq_gfn )
This conditional together with ...
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 765
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ { + rc =hvm_ioreq_server_map_pages (s); +if ( rc ) + goto out; + } + *ioreq_gfn =gfn_x (s->ioreq.gfn);
... this unconditional dereference is suspicious.
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 71
Quoted 7 lines
xen/include/asm-x86/hvm/domain.h +1
-0@@ -68,8 +68,8 @@ struct hvm_ioreq_server {spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn;struct rangeset *range[NR_IO_RANGE_TYPES ]; +int bufioreq_handling;
Does this need to be plain int (i.e. signed and 32 bits wide)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 11/12] x86/hvm/ioreq: defer mapping gfns until they are actually requsted
Quoted 42 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 17:00
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: Re: [PATCH v7 11/12] x86/hvm/ioreq: defer mapping gfns until they are actually requstedxen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +0
-0@@ -354,6 +354,9 @@ static void hvm_update_ioreq_evtchn(struct
hvm_ioreq_server*s,xen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, · line 358
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +2
-0} } +#define HANDLE_BUFIOREQ (s) \ + (s->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)(s)
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain
Quoted 1 line
xen/arch/x86/hvm/ioreq.c +0
-0@@ -762,11 +755,20 @@ int hvm_get_ioreq_server_info(struct domain*d,
ioservid_tid,xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 758
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +1
-0if (IS_DEFAULT (s) ) goto out; +if ( ioreq_gfn || bufioreq_gfn )This conditional together with ...
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 765
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ { + rc =hvm_ioreq_server_map_pages (s); +if ( rc ) + goto out; + } + *ioreq_gfn =gfn_x (s->ioreq.gfn);
Quoted 1 line
... this unconditional dereference is suspicious.
True, it should be protected.
Quoted 10 lines
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 71
Quoted 8 lines
xen/include/asm-x86/hvm/domain.h +1
-0@@ -68,8 +68,8 @@ struct hvm_ioreq_server {spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn;struct rangeset *range[NR_IO_RANGE_TYPES ]; +int bufioreq_handling;Does this need to be plain int (i.e. signed and 32 bits wide)?
No, I can shrink it.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
In reply to Jan BeulichQuoted 16 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +0
-0@@ -33,6 +33,32 @@#include <public/hvm/ioreq.h>
Quoted 13 lines
xen/arch/x86/hvm/ioreq.c line 45
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+static void set_ioreq_server (struct domain *d,unsigned int id, +struct hvm_ioreq_server *s) +{ +ASSERT (id <MAX_NR_IOREQ_SERVERS ); +ASSERT (!s || !d->arch.hvm_domain.ioreq_server.server[id]); + + d->arch.hvm_domain.ioreq_server.server[id] = s; +} + +static struct hvm_ioreq_server *get_ioreq_server(struct domain *d,const (for the parameter)?
Ok.
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +4
-0+ unsigned int id) +{ +if ( id >=MAX_NR_IOREQ_SERVERS ) +return NULL ;
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c line 55
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ +return d->arch.hvm_domain.ioreq_server.server[id]; +} + +#define IS_DEFAULT (s) \ + ((s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID))Is it really useful to go through
get_ioreq_server()here?
No, I'll change to direct array dereference.
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c line 60
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +4
-0+#define FOR_EACH_IOREQ_SERVER (d, id, s) \ + for ( (id) = 0, (s) = get_ioreq_server((d), (id)); \ + (id) < MAX_NR_IOREQ_SERVERS; \ + (s) = get_ioreq_server((d), ++(id)) )There are three instances of stray pairs of parentheses here, each time when a macro parameter gets passed unaltered to
get_ioreq_server().
OK.
Quoted 11 lines
xen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct
Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -301,8 +333,9 @@ static void hvm_update_ioreq_evtchn(struct
hvm_ioreq_server*s,xen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, · line 337
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +1
-0} } + static int hvm_ioreq_server_add_vcpu(struct hvm_ioreq_server *s,Stray addition of a blank line?
Yep. I'll get rid of that.
Quoted 11 lines
xen/arch/x86/hvm/ioreq.c static void
Quoted 1 line
xen/arch/x86/hvm/ioreq.c +0
-0@@ -501,19 +531,19 @@ static voidhvm_ioreq_server_free_rangesets(struct
hvm_ioreq_server*s,Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +1
-1}static int hvm_ioreq_server_alloc_rangesets (struct hvm_ioreq_server *s, -bool is_default) +ioservid_t id) {unsigned int i;int rc;
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c static void hvm_ioreq_server_free_rangesets(struct hvm_ioreq_server *s, · line 540
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c +1
-1-if ( is_default ) +if (IS_DEFAULT (s) ) goto done;Wouldn't comparing the ID be even cheaper in cases like this one? And perhaps assert that ID and server actually match?
Ok. If id is available I'll use that.
Quoted 50 lines
xen/arch/x86/hvm/ioreq.c int hvm_destroy_ioreq_server(struct domain *d,
Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -741,35 +754,34 @@ int hvm_destroy_ioreq_server(struct domain *d,
ioservid_tid)Quoted 12 lines
xen/arch/x86/hvm/ioreq.c +1
-7spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id);xen/arch/x86/hvm/ioreq.c int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id) · line 765
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +6
-3-if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; -domain_pause (d); + rc = -EPERM ; +if (IS_DEFAULT (s) ) + goto out;Here I think it is particularly strange to not use the ID in the check; this could even be done without holding the lock. Same in other functions below.
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain
Quoted 1 line
xen/arch/x86/hvm/ioreq.c +0
-0@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(struct domain*d,
ioservid_tid,Quoted 18 lines
xen/arch/x86/hvm/ioreq.c +4
-9spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id); -if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out;
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 808
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +3
-1- *ioreq_gfn = s->ioreq.gfn; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out;Why EOPNOTSUPP when it was just the same ENOENT as no server at all before (same further down)?
This was because of comments from Roger. In some cases I think a return of EOPNOTSUPP is more appropriate. Passing the default id is a distinct failure case.
Quoted 29 lines
Quoted 29 lines
xen/arch/x86/hvm/ioreq.c +7
-12void hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */ -list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { -bool is_default = (s == d->arch.hvm_domain.default_ioreq_server); - -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ; +if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s);
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v) · line 1076
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c +2
-1-hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
The specific case is in hvm_select_ioreq_server(). If there was no count then the array would have to be searched for the initial test.
Quoted 11 lines
xen/arch/x86/hvm/ioreq.c int hvm_set_dm_domain(struct domain *d,
Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -1111,7 +1111,7 @@ int hvm_set_dm_domain(struct domain *d,
domid_tdomid)xen/arch/x86/hvm/ioreq.c int hvm_set_dm_domain(struct domain *d, domid_t domid) · line 1114
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +1
-1* still be set and thus, when the server is created, it will have * the correct domid. */ - s = d->arch.hvm_domain.default_ioreq_server; + s =get_ioreq_server (d,DEFAULT_IOSERVID );Similar to above, is it really useful to go through
get_ioreq_server()here (and in other similar cases)?
Perhaps I should re-introduce GET_IOREQ_SERVER() for array lookup without the bounds check and use that instead of the inline func in places such as this.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
Quoted 29 lines
Quoted 29 lines
Quoted 1 line · On 26.09.17 at 12:55, <[email protected]> wrote:
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>Review int hvm_get_ioreq_server_info(struct domain
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(struct domain*d,
ioservid_tid,Quoted 22 lines
xen/arch/x86/hvm/ioreq.c +7
-10spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id); -if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; - *ioreq_gfn = s->ioreq.gfn; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out;
Quoted 7 lines
Quoted 3 lines
Why EOPNOTSUPP when it was just the same ENOENT as no server at all before (same further down)?
This was because of comments from Roger. In some cases I think a return of EOPNOTSUPP is more appropriate. Passing the default id is a distinct failure case.
And I think the change is fine as long as the commit message makes clear it's an intentional change.
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
xen/arch/x86/hvm/ioreq.c +7
-12void hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */ -list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { -bool is_default = (s == d->arch.hvm_domain.default_ioreq_server); - -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ; +if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s);Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v) · line 1076
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c +2
-1-hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
Quoted 2 lines
The specific case is in
hvm_select_ioreq_server(). If there was no count then the array would have to be searched for the initial test.
And is this something that happens frequently, i.e. the performance of which matters?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
Quoted 89 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 12:45
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 29 lines
Quoted 29 lines
Quoted 1 line · On 26.09.17 at 12:55, <[email protected]> wrote:
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>Review int hvm_get_ioreq_server_info(struct domain
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(struct domain*d,
ioservid_tid,Quoted 22 lines
xen/arch/x86/hvm/ioreq.c +7
-10spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); - rc = -ENOENT ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) - { -if ( s == d->arch.hvm_domain.default_ioreq_server ) -continue ; + s =get_ioreq_server (d, id); -if ( s->id != id ) -continue ; + rc = -ENOENT ; +if ( !s ) + goto out; - *ioreq_gfn = s->ioreq.gfn; + rc = -EOPNOTSUPP ; +if (IS_DEFAULT (s) ) + goto out;Quoted 5 lines
Quoted 3 lines
Why EOPNOTSUPP when it was just the same ENOENT as no server at all before (same further down)?
This was because of comments from Roger. In some cases I think a return
of
Quoted 2 lines
EOPNOTSUPP is more appropriate. Passing the default id is a distinct failure case.
And I think the change is fine as long as the commit message makes clear it's an intentional change.
Quoted 39 lines
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +2
-1void hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */ Quoted 7 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-5-list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { - bool is_default = (s == d-arch.hvm_domain.default_ioreq_server);
Quoted 20 lines
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +0
-5- -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ;xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v) · line 1076
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +6
-2+if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); -hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
Quoted 5 lines
Quoted 2 lines
The specific case is in
hvm_select_ioreq_server(). If there was no count then the array would have to be searched for the initial test.And is this something that happens frequently, i.e. the performance of which matters?
Yes, this is on the critical emulation path. I.e. it is a per-io call.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Paul DurrantQuoted 33 lines
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 25 September 2017 16:00
To: 'Jan Beulich' <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 15 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
Quoted 7 lines
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one,xc_core_arch_get_scratch_gpfn()could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...
Quoted 2 lines
The shattering was Andrew's observation. Andrew, can you comment?
Andrew commented verbally on this. It's not actually a shattering as such... The issue, apparently, is that adding the 4k grant table frame into the guest p2m will potentially cause creation of all layers of page table but removing it again will only remove the L1 entry. Thus it is no longer possible to use a superpage for that mapping at any point subsequently.
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 34 lines
Quoted 34 lines
Quoted 1 line · On 26.09.17 at 14:20, <[email protected]> wrote:
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 25 September 2017 16:00
To: 'Jan Beulich' <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 22 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which risks shattering a super-page mapping.
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one,xc_core_arch_get_scratch_gpfn()could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...
Quoted 8 lines
Quoted 2 lines
The shattering was Andrew's observation. Andrew, can you comment?
Andrew commented verbally on this. It's not actually a shattering as such... The issue, apparently, is that adding the 4k grant table frame into the guest p2m will potentially cause creation of all layers of page table but removing it again will only remove the L1 entry. Thus it is no longer possible to use a superpage for that mapping at any point subsequently.
First of all - what would cause a mapping to appear at that slot (or in a range covering that slot). And then, while re-combining contiguous mappings indeed doesn't exist right now, replacing a non-leaf entry (page table) with a large page is very well supported (see e.g. ept_set_entry(), which even has a comment to that effect). Hence I continue to be confused why we need a new mechanism for seeding the grant tables.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
In reply to Paul DurrantQuoted 47 lines
Quoted 47 lines
Quoted 1 line · On 26.09.17 at 14:12, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 12:45Quoted 44 lines
Quoted 15 lines
Quoted 1 line · On 26.09.17 at 12:55, <[email protected]> wrote:
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +2
-1@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(struct domainvoid hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */ Quoted 7 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
Quoted 7 lines
xen/arch/x86/hvm/ioreq.c +1
-5-list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { - bool is_default = (s == d-arch.hvm_domain.default_ioreq_server);
Quoted 20 lines
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +0
-5- -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ;xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v) · line 1076
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +6
-2+if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); -hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
The specific case is in
hvm_select_ioreq_server(). If there was no count then the array would have to be searched for the initial test.And is this something that happens frequently, i.e. the performance of which matters?
Yes, this is on the critical emulation path. I.e. it is a per-io call.
That's not answering the question, because you leave out implied
context: Is it a performance critical path to get here with no ioreq server registers (i.e. count being zero)? After all if count is non-zero, you get past the early-out conditional there anyway.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
Quoted 64 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:38
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 8 lines
Quoted 8 lines
Quoted 1 line · On 26.09.17 at 14:12, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 12:45Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 26.09.17 at 12:55, <[email protected]> wrote:
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>Review int hvm_get_ioreq_server_info(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(structdomain
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
Quoted 9 lines
xen/arch/x86/hvm/ioreq.c +2
-1void hvm_destroy_all_ioreq_servers (struct domain *d) { -struct hvm_ioreq_server *s, *next; +struct hvm_ioreq_server *s; +unsigned int id;spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock);/* No need to domain_pause() as the domain is being torn down */
Quoted 36 lines
Quoted 35 lines
Quoted 30 lines
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v)
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c +1
-5-list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { - bool is_default = (s == d-arch.hvm_domain.default_ioreq_server);
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/hvm/ioreq.c +4
-6- -hvm_ioreq_server_disable (s, is_default); - -if ( is_default ) - d->arch.hvm_domain.default_ioreq_server =NULL ; +if ( !s ) +continue ; -list_del (&s->list_entry); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s);Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_all_ioreq_servers_add_vcpu(struct domain *d, struct vcpu *v) · line 1076
Quoted 3 lines
xen/arch/x86/hvm/ioreq.c +2
-1-hvm_ioreq_server_deinit (s, is_default); +ASSERT (d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
Quoted 2 lines
The specific case is in
hvm_select_ioreq_server(). If there was no count then the array would have to be searched for the initial test.And is this something that happens frequently, i.e. the performance of which matters?
Quoted 7 lines
Quoted 1 line
Yes, this is on the critical emulation path. I.e. it is a per-io call.
That's not answering the question, because you leave out implied
context: Is it a performance critical path to get here with no ioreq server registers (i.e. count being zero)? After all if count is non-zero, you get past the early-out conditional there anyway.
Clearly, only emulation that does not hit any IOREQ servers would be impacted. Generally you'd hope that the guest would not hit memory ranges that don't exist too often but, if it does, then by not maintaining a count there would be a small performance regression over the code as it stands now.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Jan BeulichQuoted 54 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:35
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 11 lines
Quoted 11 lines
Quoted 1 line · On 26.09.17 at 14:20, <[email protected]> wrote:
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 25 September 2017 16:00
To: 'Jan Beulich' <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
acquire guest resources
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which
risks
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
shattering a super-page mapping.
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one,xc_core_arch_get_scratch_gpfn()could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...Quoted 8 lines
Quoted 2 lines
The shattering was Andrew's observation. Andrew, can you comment?
Andrew commented verbally on this. It's not actually a shattering as such... The issue, apparently, is that adding the 4k grant table frame into the guest p2m will potentially cause creation of all layers of page table but removing it again will only remove the L1 entry. Thus it is no longer possible to use a superpage for that mapping at any point subsequently.
Quoted 7 lines
First of all - what would cause a mapping to appear at that slot (or in a range covering that slot). And then, while re-combining contiguous mappings indeed doesn't exist right now, replacing a non-leaf entry (page table) with a large page is very well supported (see e.g.
ept_set_entry(), which even has a comment to that effect). Hence I continue to be confused why we need a new mechanism for seeding the grant tables.
I'll have to defer to Andrew to answer at this point.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...
In reply to Paul Durrantxen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 867
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +2
-1@@ -762,7 +863,8 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, goto out; } - *ioreq_gfn =gfn_x (s->ioreq.gfn); +if ( ioreq_gfn ) + *ioreq_gfn =gfn_x (s->ioreq.gfn);
Ah, this is what actually wants to be in patch 11. Considering what you say in the description regarding the XEN_DMOP_no_gfns I wonder whether you wouldn't better return "invalid" indicators in the GFN output fields of the hypercall when the pages haven't been mapped to a GFN.
Quoted 14 lines
xen/arch/x86/hvm/ioreq.c +10
-0@@ -780,6 +882,33 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,return rc; } +mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); +
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 904
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) ) + goto out; + +if (hvm_ioreq_server_alloc_pages (s) ) + goto out; + +if ( idx ==0 ) + mfn =_mfn (page_to_mfn (s->bufioreq.page)); +else if ( idx ==1 ) + mfn =_mfn (page_to_mfn (s->ioreq.page));
else <some sort of error>? Also with buffered I/O being optional, wouldn't it be more natural for index 0 representing the synchronous page? And with buffered I/O not enabled, aren't you returning rubbish (NULL translated by page_to_mfn())?
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 909
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +4
-0+ out: +spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +return mfn;
The unspecific error (INVALID_MFN) here makes me wonder ...
Quoted 8 lines
xen/arch/x86/mm.c +4
-0@@ -4795,6 +4796,27 @@ static int xenmem_acquire_grant_table(struct domain *d,return 0 ; } +static int xenmem_acquire_ioreq_server(struct domain *d, + unsigned int id, + unsigned long frame, + unsigned long nr_frames,
xen/arch/x86/mm.c static int xenmem_acquire_grant_table(struct domain *d, · line 4812
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+ unsigned long mfn_list[]) +{ +unsigned int i; + +for ( i =0 ; i < nr_frames; i++ ) + { +mfn_t mfn =hvm_get_ioreq_server_frame (d, id, frame + i); + +if (mfn_eq (mfn,INVALID_MFN ) ) +return -EINVAL ;
... how meaningful EINVAL here is. In particular if page allocation failed, ENOMEM would certainly be more appropriate (and give the caller a better idea of what needs to be done).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
In reply to Paul DurrantQuoted 73 lines
Quoted 65 lines
Quoted 1 line · On 26.09.17 at 14:41, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:38
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 8 lines
Quoted 8 lines
Quoted 1 line · On 26.09.17 at 14:12, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 12:45Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 26.09.17 at 12:55, <[email protected]> wrote:
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>Review int hvm_get_ioreq_server_info(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(structdomain
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Review int hvm_get_ioreq_server_info(struct · line 804
Quoted 9 lines
(quoted diff) +2
-1void hvm_destroy_all_ioreq_servers(struct domain *d) { - struct hvm_ioreq_server *s, *next; + struct hvm_ioreq_server *s; + unsigned int id; spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock); /* No need to domain_pause() as the domain is being torn down*/
Quoted 36 lines
Quoted 35 lines
Quoted 30 lines
Quoted 8 lines
Review int hvm_get_ioreq_server_info(struct · line 797
Quoted 8 lines
(quoted diff) +1
-5- list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { - bool is_default = (s == d-arch.hvm_domain.default_ioreq_server);
Quoted 12 lines
Quoted 12 lines
(quoted diff) +4
-6- - hvm_ioreq_server_disable(s, is_default); - - if ( is_default ) - d->arch.hvm_domain.default_ioreq_server = NULL; + if ( !s ) + continue; - list_del(&s->list_entry); + hvm_ioreq_server_disable(s); + hvm_ioreq_server_deinit(s);Quoted 8 lines
Review int hvm_get_ioreq_server_info(struct · line 814
Quoted 3 lines
(quoted diff) +2
-1- hvm_ioreq_server_deinit(s, is_default); + ASSERT(d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
Quoted 2 lines
The specific case is in
hvm_select_ioreq_server(). If there was no count then the array would have to be searched for the initial test.And is this something that happens frequently, i.e. the performance of which matters?
Quoted 7 lines
Quoted 1 line
Yes, this is on the critical emulation path. I.e. it is a per-io call.
That's not answering the question, because you leave out implied
context: Is it a performance critical path to get here with no ioreq server registers (i.e. count being zero)? After all if count is non-zero, you get past the early-out conditional there anyway.
Quoted 4 lines
Clearly, only emulation that does not hit any IOREQ servers would be impacted. Generally you'd hope that the guest would not hit memory ranges that don't exist too often but, if it does, then by not maintaining a count there would be a small performance regression over the code as it stands now.
By "now" you mean with this patch in place as is, rather than the current tip of the tree? I don't see a regression compared to current staging, and I question the need to performance optimize a corner case a guest should not have much interest getting into. Anyway - I'm not meaning to block the patch because of the presence of this field (the more that you're the maintainer of this code anyway), it merely seems to me that the patch would be ending up smaller but no worse in quality if the field wasn't there.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...
In reply to Jan BeulichQuoted 46 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:59
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...Review int hvm_get_ioreq_server_info(struct domain *d,
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -762,7 +863,8 @@ int hvm_get_ioreq_server_info(struct domain *d,
ioservid_tid,xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 867
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +2
-1goto out; } - *ioreq_gfn =gfn_x (s->ioreq.gfn); +if ( ioreq_gfn ) + *ioreq_gfn =gfn_x (s->ioreq.gfn);Ah, this is what actually wants to be in patch 11. Considering what you say in the description regarding the
XEN_DMOP_no_gfnsI wonder whether you wouldn't better return "invalid" indicators in the GFN output fields of the hypercall when the pages haven't been mapped to a GFN.Review int hvm_get_ioreq_server_info(struct domain *d,
Quoted 1 line
(quoted diff) +0
-0@@ -780,6 +882,33 @@ int hvm_get_ioreq_server_info(struct domain *d,
ioservid_tid,Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +14
-0return rc; } +mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); + +if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) ) + goto out; + +if (hvm_ioreq_server_alloc_pages (s) )
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 904
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ goto out; + +if ( idx ==0 ) + mfn =_mfn (page_to_mfn (s->bufioreq.page)); +else if ( idx ==1 ) + mfn =_mfn (page_to_mfn (s->ioreq.page));else <some sort of error>?
I set mfn to INVALID above. Is that not enough?
Quoted 4 lines
Also with buffered I/O being optional,
wouldn't it be more natural for index 0 representing the synchronous page? And with buffered I/O not enabled, aren't you returning rubbish (NULL translated bypage_to_mfn())?
Good point. I should leave the mfn set to invalid if the buffered page is not there. As for making it zero, and putting the synchronous ones afterwards, that was intentional because more synchronous pages will need to be added if we needs to support more vCPUs, whereas there should only ever need to be one buffered page.
Paul
Quoted 32 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 909
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +4
-0+ out: +spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +return mfn;The unspecific error (
INVALID_MFN) here makes me wonder ...Review static int xenmem_acquire_grant_table(struct
Quoted 1 line
(quoted diff) +0
-0@@ -4795,6 +4796,27 @@ static int xenmem_acquire_grant_table(structdomain *d,
Quoted 7 lines
xen/arch/x86/mm.c +4
-0return 0 ; } +static int xenmem_acquire_ioreq_server(struct domain *d, + unsigned int id, + unsigned long frame, + unsigned long nr_frames,xen/arch/x86/mm.c static int xenmem_acquire_grant_table(struct domain *d, · line 4812
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+ unsigned long mfn_list[]) +{ +unsigned int i; + +for ( i =0 ; i < nr_frames; i++ ) + { +mfn_t mfn =hvm_get_ioreq_server_frame (d, id, frame + i); + +if (mfn_eq (mfn,INVALID_MFN ) ) +return -EINVAL ;... how meaningful EINVAL here is. In particular if page allocation failed, ENOMEM would certainly be more appropriate (and give the caller a better idea of what needs to be done).
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...
Quoted 32 lines
Quoted 23 lines
Quoted 1 line · On 26.09.17 at 15:05, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:59Review int hvm_get_ioreq_server_info(struct domain *d,
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -780,6 +882,33 @@ int hvm_get_ioreq_server_info(struct domain *d,
ioservid_tid,Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +14
-0return rc; } +mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); + +if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) ) + goto out; + +if (hvm_ioreq_server_alloc_pages (s) )Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 904
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ goto out; + +if ( idx ==0 ) + mfn =_mfn (page_to_mfn (s->bufioreq.page)); +else if ( idx ==1 ) + mfn =_mfn (page_to_mfn (s->ioreq.page));else <some sort of error>?
Quoted 1 line
I set mfn to INVALID above. Is that not enough?
Together with ...
Quoted 7 lines
Quoted 4 lines
Also with buffered I/O being optional,
wouldn't it be more natural for index 0 representing the synchronous page? And with buffered I/O not enabled, aren't you returning rubbish (NULL translated bypage_to_mfn())?Good point. I should leave the mfn set to invalid if the buffered page is not there.
... this - no, I don't think so. The two cases would be indistinguishable. An invalid index should be EINVAL or EDOM or some such.
Quoted 4 lines
As for making it zero, and putting the synchronous ones afterwards, that was intentional because more synchronous pages will need to be added if we needs to support more vCPUs, whereas there should only ever need to be one buffered page.
Ah, I see.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
In reply to Jan BeulichQuoted 88 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 14:04
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 19 lines
Quoted 19 lines
Quoted 1 line · On 26.09.17 at 14:41, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:38
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 08/12] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 8 lines
Quoted 8 lines
Quoted 1 line · On 26.09.17 at 14:12, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 12:45Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 26.09.17 at 12:55, <[email protected]> wrote:
Sent: 25 September 2017 16:17
To: Paul Durrant <[email protected]>Review int hvm_get_ioreq_server_info(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -785,29 +797,27 @@ int hvm_get_ioreq_server_info(structdomain
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Review int hvm_get_ioreq_server_info(struct · line 802
Quoted 7 lines
(quoted diff) +2
-1void hvm_destroy_all_ioreq_servers(struct domain *d) { - struct hvm_ioreq_server *s, *next; + struct hvm_ioreq_server *s; + unsigned int id; spin_lock_recursive(&d-arch.hvm_domain.ioreq_server.lock);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0
-0/* No need to domain_pause() as the domain is being torndown
Quoted 31 lines
Quoted 31 lines
*/
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 8 lines
Review int hvm_get_ioreq_server_info(struct · line 796
Quoted 8 lines
(quoted diff) +1
-5- list_for_each_entry_safe ( s, - next, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) { - bool is_default = (s == d-arch.hvm_domain.default_ioreq_server);
Quoted 20 lines
Quoted 5 lines
(quoted diff) +0
-5- - hvm_ioreq_server_disable(s, is_default); - - if ( is_default ) - d->arch.hvm_domain.default_ioreq_server = NULL;Review int hvm_get_ioreq_server_info(struct · line 813
Quoted 10 lines
(quoted diff) +6
-2+ if ( !s ) + continue; - list_del(&s->list_entry); + hvm_ioreq_server_disable(s); + hvm_ioreq_server_deinit(s); - hvm_ioreq_server_deinit(s, is_default); + ASSERT(d->arch.hvm_domain.ioreq_server.count); + --d->arch.hvm_domain.ioreq_server.count;Seeing this - do you actually need the count as a separate field? I.e. are there performance critical uses of it, where going through the array would be too expensive? Most of the uses are just ASSERT()s anyway.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
The specific case is in
hvm_select_ioreq_server(). If there was nocount
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
then the array would have to be searched for the initial test.
And is this something that happens frequently, i.e. the performance of which matters?
Yes, this is on the critical emulation path. I.e. it is a per-io call.
Quoted 8 lines
Quoted 5 lines
That's not answering the question, because you leave out implied
context: Is it a performance critical path to get here with no ioreq server registers (i.e. count being zero)? After all if count is non-zero, you get past the early-out conditional there anyway.Clearly, only emulation that does not hit any IOREQ servers would be impacted. Generally you'd hope that the guest would not hit memory
ranges
Quoted 8 lines
Quoted 2 lines
that don't exist too often but, if it does, then by not maintaining a count there would be a small performance regression over the code as it stands
now.
By "now" you mean with this patch in place as is, rather than the current tip of the tree? I don't see a regression compared to current staging, and I question the need to performance optimize a corner case a guest should not have much interest getting into.
I mean against current master, which has the following test at:
http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/arch/x86/hvm/ioreq.c;hb=HEAD#l1168
if ( list_empty(&d->arch.hvm_domain.ioreq_server.list) )
return NULL;Without a count then the array would need to be searched, which is clearly slower than testing the emptiness a linked list.
Quoted 5 lines
Anyway - I'm not meaning to block the patch because of the presence of this field (the more that you're the maintainer of this code anyway), it merely seems to me that the patch would be ending up smaller but no worse in quality if the field wasn't there.
Agreed it's a corner case though so the regression is not of great concern. I'll get rid of the count for now... It can always be put back if it proves to be a real issue.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...
In reply to Jan BeulichQuoted 53 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 14:11
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]; KonradRzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: RE: [PATCH v7 12/12] x86/hvm/ioreq: add a new mappable resource type...Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 26.09.17 at 15:05, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:59Review int hvm_get_ioreq_server_info(struct domain
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
(quoted diff) +0
-0@@ -780,6 +882,33 @@ int hvm_get_ioreq_server_info(struct domain*d,
Quoted 27 lines
Quoted 18 lines
ioservid_tid,Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +14
-0return rc; } +mfn_t hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx) +{ +struct hvm_ioreq_server *s; +mfn_t mfn =INVALID_MFN ; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + + s =get_ioreq_server (d, id); + +if ( id >=MAX_NR_IOREQ_SERVERS || !s ||IS_DEFAULT (s) ) + goto out; + +if (hvm_ioreq_server_alloc_pages (s) )Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 904
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ goto out; + +if ( idx ==0 ) + mfn =_mfn (page_to_mfn (s->bufioreq.page)); +else if ( idx ==1 ) + mfn =_mfn (page_to_mfn (s->ioreq.page));else <some sort of error>?
Quoted 1 line
I set mfn to INVALID above. Is that not enough?
Together with ...
Quoted 5 lines
Quoted 4 lines
Also with buffered I/O being optional,
wouldn't it be more natural for index 0 representing the synchronous page? And with buffered I/O not enabled, aren't you returning rubbish (NULL translated bypage_to_mfn())?
Quoted 7 lines
Quoted 2 lines
Good point. I should leave the mfn set to invalid if the buffered page is not there.
... this - no, I don't think so. The two cases would be indistinguishable. An invalid index should be EINVAL or EDOM or some such.
Ok, I'll change the function to return an errno to distinguish the cases.
Paul
Quoted 10 lines
Quoted 2 lines
As for making it zero, and putting the synchronous ones afterwards, that was intentional because more synchronous pages will
need to
Quoted 1 line
be added if we needs to support more vCPUs, whereas there should only
ever
Quoted 1 line
need to be one buffered page.
Ah, I see.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Jan BeulichQuoted 81 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 2 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
In the case where a PV domain is mapping guest resources then it needs
make
Quoted 1 line
the
HYPERVISOR_mmu_updatecall usingDOMID_SELF, rather than theguest
Quoted 2 lines
domid, so that the passed in gmfn values are correctly treated as mfns rather than gfns present in the guest p2m.
Since things are presently working fine, I think the description is not really accurate. You only require the new behavior if you don't know the GFN of the page you want to map, and that it has to be
DOMID_SELFthat should be passed also doesn't appear to derive from anything else. To properly judge about the need for this patch it would help if it was briefly explained why being able to map by GFN is no longer sufficient, and to re-word theDOMID_SELFpart.The other aspect I don't understand is why this is needed for PV Dom0, but not for PVH. The answer here can't be "because PVH Dom0 isn't supported yet", because it eventually will be, and then there will still be the problem of PVH supposedly having no notion of MFNs (be their own or foreign guest ones). The answer also can't be "since it would use
XENMAPSPACE_gmfn_foreign", as that's acting in terms of GFN too.Quoted 1 line
This patch removes a check which currently disallows mapping of a page
when
Quoted 2 lines
the owner of the page tables matches the domain passed to
HYPERVISOR_mmu_update, but that domain is not the real owner of thepage.
Quoted 3 lines
The check was introduced by patch
d3c6a215ca9("x86: Clean upget_page_from_l1e()to correctly distinguish between owner-of-pte and owner-of-data-page in all cases") but it's not clear why it was needed.I think the goal here simply was to not permit anything that doesn't really need permitting. Furthermore the check being "introduced" there was, afaict, replacing the earlier d !=
curr->domain.Quoted 7 lines
xen/arch/x86/mm.c +0
-1@@ -1024,12 +1024,15 @@ get_page_from_l1e( (real_pg_owner != dom_cow) ) ) {/* -* Let privileged domains transfer the right to map their target xen/arch/x86/mm.c get_page_from_l1e( · line 1033
Quoted 10 lines
xen/arch/x86/mm.c +7
-3-* domain's pages. This is used to allow stub-domain pvfb export to -* dom0, until pvfb supports granted mappings. At that time this -* minor hack can go away. +* If the real page owner is not the domain specified in the +* hypercall then establish that the specified domain has +* mapping privilege over the page owner. +* This is used to allow stub-domain pvfb export to dom0. It is +* also used to allow a privileged PV domain to map mfns using +* DOMID_SELF, which is needed for mapping guest resources such +* grant table frames. How do grant table frames come into the picture here? So far I had assumed only ioreq server pages are in need of this.
xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
xen/arch/x86/mm.c +1
-1*/ -if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().
Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.
Looking at this I wonder whether a cleaner solution would be to introduce a new domid: DOMID_ANY. This meaning of this would be along the same sort of lines as DOMID_XEN or DOMID_IO and would be used in mmu_update to mean 'any page over which the caller has privilege'. Does that sound reasonable?
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Paul DurrantQuoted 45 lines · Paul Durrant
Quoted 45 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:35
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 11 lines
Quoted 11 lines
Quoted 1 line · On 26.09.17 at 14:20, <[email protected]> wrote:
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 25 September 2017 16:00
To: 'Jan Beulich' <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
acquire guest resources
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which
risks
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 1 line
shattering a super-page mapping.
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one,xc_core_arch_get_scratch_gpfn()could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...The shattering was Andrew's observation. Andrew, can you comment?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Andrew commented verbally on this. It's not actually a shattering as such... The issue, apparently, is that adding the 4k grant table frame into the guest p2m will potentially cause creation of all layers of page table but removing it again will only remove the L1 entry. Thus it is no longer possible to use a superpage for that mapping at any point subsequently.
First of all - what would cause a mapping to appear at that slot (or in a range covering that slot).
???
At the moment, the toolstack's *only* way of editing the grant table of an HVM guest is to add it into the p2m, map the gfn, write two values, and unmap it. That is how a 4k mapping gets added, which forces an allocation or shattering to cause a L1 table to exist.
This is a kludge and is architecturally unclean.
Quoted 4 lines
Quoted 4 lines
And then, while re-combining contiguous
mappings indeed doesn't exist right now, replacing a non-leaf entry (page table) with a large page is very well supported (see e.g.ept_set_entry(), which even has a comment to that effect).
I don't see anything equivalent in the NPT or IOMMU logic.
Quoted 4 lines
Quoted 3 lines
Hence
I continue to be confused why we need a new mechanism for seeding the grant tables.I'll have to defer to Andrew to answer at this point.
Joao's improvements for network transmit require a trusted backend to be able to map the full grant table.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Paul DurrantQuoted 23 lines
Quoted 17 lines
Quoted 1 line · On 27.09.17 at 13:18, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/mm.c +1
-1-if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.
Quoted 4 lines
Looking at this I wonder whether a cleaner solution would be to introduce a new domid:
DOMID_ANY. This meaning of this would be along the same sort of lines asDOMID_XENorDOMID_IOand would be used inmmu_updateto mean 'any page over which the caller has privilege'. Does that sound reasonable?
Not really, no. Even if the caller has privilege over multiple domains, it should still specify which one it means. Otherwise we may end up with a page transferring ownership behind its back, and it doing something to one domain which was meant to be done to another.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 35 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 27 September 2017 13:47
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 17 lines
Quoted 17 lines
Quoted 1 line · On 27.09.17 at 13:18, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/mm.c +1
-1-if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().Quoted 8 lines
Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.Looking at this I wonder whether a cleaner solution would be to introduce a new domid:
DOMID_ANY. This meaning of this would be along the samesort of
Quoted 9 lines
Quoted 1 line
lines as
DOMID_XENorDOMID_IOand would be used inmmu_updatetomean 'any
Quoted 1 line
page over which the caller has privilege'. Does that sound reasonable?
Not really, no. Even if the caller has privilege over multiple domains, it should still specify which one it means. Otherwise we may end up with a page transferring ownership behind its back, and it doing something to one domain which was meant to be done to another.
Ok, I'll claim the final cmd value then.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 02/12] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Andrew CooperQuoted 55 lines
Quoted 1 line
Quoted 1 line · On 27.09.17 at 13:34, <[email protected]> wrote:
Quoted 45 lines · Paul Durrant
Quoted 45 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 26 September 2017 13:35
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 11 lines
Quoted 11 lines
Quoted 1 line · On 26.09.17 at 14:20, <[email protected]> wrote:
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 25 September 2017 16:00
To: 'Jan Beulich' <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v7 02/12] x86/mm: addHYPERVISOR_memory_opto
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
acquire guest resources
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
Certain memory resources associated with a guest are not necessarily present in the guest P2M and so are not necessarily available to be foreign-mapped by a tools domain unless they are inserted, which
risks
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 1 line
shattering a super-page mapping.
Btw., I'm additionally having trouble seeing this shattering of a
superpage: For one,xc_core_arch_get_scratch_gpfn()could be a little less simplistic. And then even with the currently chosen value (outside of the range of valid GFNs at that point in time) there shouldn't be a larger page to be shattered, as there should be no mapping at all at that index. But perhaps I'm just blind and don't see the obvious ...The shattering was Andrew's observation. Andrew, can you comment?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Andrew commented verbally on this. It's not actually a shattering as such... The issue, apparently, is that adding the 4k grant table frame into the guest p2m will potentially cause creation of all layers of page table but removing it again will only remove the L1 entry. Thus it is no longer possible to use a superpage for that mapping at any point subsequently.
First of all - what would cause a mapping to appear at that slot (or in a range covering that slot).
Quoted 8 lines
???
At the moment, the toolstack's *only* way of editing the grant table of an HVM guest is to add it into the p2m, map the gfn, write two values, and unmap it. That is how a 4k mapping gets added, which forces an allocation or shattering to cause a L1 table to exist.
This is a kludge and is architecturally unclean.
Well, if the grant table related parts of series here was presented to be simply cleaning up a kludge, I'd probably be fine. But so far it has been claimed that there are other bad effects, besides this just being (as I would call it) sub-optimal.
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
And then, while re-combining contiguous
mappings indeed doesn't exist right now, replacing a non-leaf entry (page table) with a large page is very well supported (see e.g.ept_set_entry(), which even has a comment to that effect).I don't see anything equivalent in the NPT or IOMMU logic.
Look for intermediate_entry in p2m_pt_set_entry(). In AMD IOMMU code see iommu_merge_pages(). For VT-d I agree.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
In reply to Paul DurrantQuoted 40 lines
Quoted 40 lines
Quoted 1 line · On 27.09.17 at 14:49, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 27 September 2017 13:47
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 17 lines
Quoted 17 lines
Quoted 1 line · On 27.09.17 at 13:18, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03xen/arch/x86/mm.c get_page_from_l1e( · line 1038
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/mm.c +1
-1-if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) ||xsm_priv_mapping (XSM_TARGET , pg_owner, real_pg_owner) ) { gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().Quoted 8 lines
Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.Looking at this I wonder whether a cleaner solution would be to introduce a new domid:
DOMID_ANY. This meaning of this would be along the samesort of
Quoted 1 line
lines as
DOMID_XENorDOMID_IOand would be used inmmu_updatetomean 'any
Quoted 1 line
page over which the caller has privilege'. Does that sound reasonable?
Quoted 7 lines
Quoted 5 lines
Not really, no. Even if the caller has privilege over multiple domains, it should still specify which one it means. Otherwise we may end up with a page transferring ownership behind its back, and it doing something to one domain which was meant to be done to another.
Ok, I'll claim the final cmd value then.
Final? We've got 5 left (for a total of 3 bits) afaict.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 59 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 27 September 2017 14:31
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 8 lines
Quoted 8 lines
Quoted 1 line · On 27.09.17 at 14:49, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 27 September 2017 13:47
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v7 01/12] x86/mm: allow a privileged PV domain tomap
Quoted 9 lines
Quoted 9 lines
guest mfns
Quoted 7 lines
Quoted 7 lines
Quoted 1 line · On 27.09.17 at 13:18, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 25 September 2017 14:03Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.09.17 at 17:31, <[email protected]> wrote:
xen/arch/x86/mm.c +1
-1-if ( (real_pg_owner ==NULL ) || (pg_owner == l1e_owner) || +if ( (real_pg_owner ==NULL ) || xsm_priv_mapping(XSM_TARGET, pg_owner,
real_pg_owner) )Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
{ gdprintk(XENLOG_WARNING,I'm concerned of the effect of the change on the code paths which you're not really interested in:
alloc_l1_table(),ptwr_emulated_update(), andshadow_get_page_from_l1e()all explicitly pass both domains identical, and are now suddenly able to do things they weren't supposed to do. A similar concern applies to__do_update_va_mapping()callingmod_l1_table().Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I therefore wonder whether the solution to your problem wouldn't rather be
MMU_FOREIGN_PT_UPDATE(name subject to improvement suggestions). This at the same time would address my concern regarding the misleadingDOMID_SELFpassing when really a foreign domain's page is meant.Looking at this I wonder whether a cleaner solution would be to
introduce a
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
new domid:
DOMID_ANY. This meaning of this would be along the samesort of
Quoted 1 line
lines as
DOMID_XENorDOMID_IOand would be used inmmu_updateto
Quoted 9 lines
Quoted 8 lines
mean 'any
Quoted 1 line
page over which the caller has privilege'. Does that sound reasonable?
Not really, no. Even if the caller has privilege over multiple domains, it should still specify which one it means. Otherwise we may end up with a page transferring ownership behind its back, and it doing something to one domain which was meant to be done to another.
Quoted 3 lines
Quoted 1 line
Ok, I'll claim the final cmd value then.
Final? We've got 5 left (for a total of 3 bits) afaict.
Really? Maybe I misread... looks like only 2 bits to me.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 9 lines
Quoted 7 lines
Quoted 1 line · On 27.09.17 at 16:22, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 27 September 2017 14:31Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 27.09.17 at 14:49, <[email protected]> wrote:
Ok, I'll claim the final cmd value then.
Final? We've got 5 left (for a total of 3 bits) afaict.
Really? Maybe I misread... looks like only 2 bits to me.
Maybe you and I looked in different places. I'm deriving this from
cmd = req.ptr & (sizeof(l1_pgentry_t)-1);
switch ( cmd )
in do_mmu_update(). Only 32-bit non-PAE guests would have been limited to 2 bits.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfns
Quoted 20 lines
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 27 September 2017 15:42
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v7 01/12] x86/mm: allow a privileged PV domain to map guest mfnsQuoted 9 lines
Quoted 7 lines
Quoted 1 line · On 27.09.17 at 16:22, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 27 September 2017 14:31Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 27.09.17 at 14:49, <[email protected]> wrote:
Ok, I'll claim the final cmd value then.
Final? We've got 5 left (for a total of 3 bits) afaict.
Really? Maybe I misread... looks like only 2 bits to me.
Quoted 8 lines
Maybe you and I looked in different places. I'm deriving this from
cmd = req.ptr & (sizeof(l1_pgentry_t)-1);
switch ( cmd )
in
do_mmu_update(). Only 32-bit non-PAE guests would have been limited to 2 bits.
Ah, ok. I was going off what it says in the header, where the comments state that [0:1] are command bits and [:2] are address bits, but for 64-bit or PAE guests then it makes sense that bit 2 is up for grabs. Anyway I can use 3, which still fits in bits [0:1].
Paul
Quoted 8 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel