x86: guest resource mapping
v9 cover x86: guest resource mapping
This series introduces support for direct mapping of guest resources. The resources are:
- IOREQ server pages
- Grant tables
v9:
- Change to patch #1 only.
v8:
- Re-ordered series and dropped two patches that have already been committed.
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 (11):
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/mm: add HYPERVISOR_memory_op to acquire guest resources x86/hvm/ioreq: add a new mappable resource type...
x86/mm: add an extra command to HYPERVISOR_mmu_update... tools/libxenforeignmemory: add support for resource mapping tools/libxenforeignmemory: reduce xenforeignmemory_restrict code
footprint
common: add a new mappable resource type: XENMEM_resource_grant_table tools/libxenctrl: use new xenforeignmemory API to seed grant table
tools/include/xen-sys/Linux/privcmd.h | 11 + tools/libs/devicemodel/core.c | 8 + tools/libs/devicemodel/include/xendevicemodel.h | 6 +- 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 | 9 +- xen/arch/x86/hvm/ioreq.c | 824 ++++++++++++--------- xen/arch/x86/mm.c | 39 +- xen/arch/x86/mm/p2m.c | 3 +- xen/common/compat/memory.c | 52 ++ xen/common/grant_table.c | 32 +- xen/common/memory.c | 112 +++ xen/include/asm-x86/hvm/domain.h | 14 +- xen/include/asm-x86/hvm/ioreq.h | 6 + xen/include/asm-x86/mm.h | 5 + xen/include/asm-x86/p2m.h | 3 + xen/include/public/hvm/dm_op.h | 36 +- xen/include/public/memory.h | 48 +- xen/include/public/xen.h | 12 +- xen/include/xen/grant_table.h | 1 + xen/include/xlat.lst | 1 + 35 files changed, 1087 insertions(+), 493 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 v9 1/11 x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
A 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.
Some function return values are changed by this patch: Specifically, in the case where the id of the default ioreq server is passed in, -EOPNOTSUPP is now returned rather than -ENOENT.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v9:
- modified FOR_EACH... macro as requested by Andrew.
v8:
- Addressed various comments from Jan.
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 | 509 +++++++++++++++++++-------------------- xen/include/asm-x86/hvm/domain.h | 10 +- 2 files changed, 252 insertions(+), 267 deletions(-)
xen/arch/x86/hvm/ioreq.c +247 -262
@@ -33,6 +33,44 @@#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; +} + +#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm_domain.ioreq_server.server[id] + +static struct hvm_ioreq_server *get_ioreq_server (const struct domain *d, +unsigned int id) +{ +if ( id >=MAX_NR_IOREQ_SERVERS ) +return NULL ; + +return GET_IOREQ_SERVER (d, id); +} + +#define IS_DEFAULT (s) \ + ((s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID)) + +/* +* Iterate over all possible ioreq servers. The use of inline function +* get_ioreq_server() in the increment is deliberate as use of the +* GET_IOREQ_SERVER() macro will cause gcc to complain about an array +* overflow. +*/ +#define FOR_EACH_IOREQ_SERVER (d, id, s) \ + for ( (id) = 0, (s) = GET_IOREQ_SERVER(d, 0); \ + (id) < MAX_NR_IOREQ_SERVERS; \ + (s) = get_ioreq_server(d, ++(id)) ) \ + if ( !s ) \ + continue; \ + else +static ioreq_t *get_ioreq (struct hvm_ioreq_server *s,struct vcpu *v) {shared_iopage_t *p = s->ioreq.va;
@@ -47,10 +85,9 @@ 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;
@@ -127,10 +164,9 @@ 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;
@@ -243,13 +279,12 @@ 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->ioreq.va && s->ioreq.page == page) || (s->bufioreq.va && s->bufioreq.page == page) )
@@ -302,7 +337,7 @@ 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 +366,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 +466,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 +473,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 +502,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 +512,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 +521,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 +533,21 @@ 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 ( id == DEFAULT_IOSERVID ) goto done; + ASSERT(!IS_DEFAULT(s)); + 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 +571,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 +587,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 +606,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 +616,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 +632,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 +644,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 +652,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 +667,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 +688,64 @@ 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 ( i ==DEFAULT_IOSERVID ) +hvm_ioreq_server_enable (s);if ( id ) - *id = s->id; + *id = i;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; }
@@ -739,37 +754,34 @@ int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)struct hvm_ioreq_server *s;int rc; -spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); +if ( id ==DEFAULT_IOSERVID ) +return -EPERM ; - 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 ; +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); -if ( s->id != id ) -continue ; + s =get_ioreq_server (d, id); -domain_pause (d); + rc = -ENOENT ; +if ( !s ) + goto out; -p2m_set_ioreq_server (d,0 , s); +ASSERT (!IS_DEFAULT (s)); -hvm_ioreq_server_disable (s, false); +domain_pause (d); -list_del (&s->list_entry); +p2m_set_ioreq_server (d,0 , s); -hvm_ioreq_server_deinit (s, false); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); -domain_unpause (d); +domain_unpause (d); -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;
@@ -783,31 +795,30 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,struct hvm_ioreq_server *s;int rc; +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; +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; +ASSERT (!IS_DEFAULT (s)); -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 +829,46 @@ 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; +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; +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; +ASSERT (!IS_DEFAULT (s)); -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 +879,46 @@ 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; +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; +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; +ASSERT (!IS_DEFAULT (s)); -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;
@@ -931,6 +938,9 @@ int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,struct hvm_ioreq_server *s;int rc; +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; +if ( type != HVMMEM_ioreq_server )return -EINVAL ;
@@ -939,19 +949,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 + { +ASSERT (!IS_DEFAULT (s)); + rc =p2m_set_ioreq_server (d, flags, s); }spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);
@@ -970,38 +975,34 @@ 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; +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; +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 ; +ASSERT (!IS_DEFAULT (s)); -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 +1010,14 @@ 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); - - rc =hvm_ioreq_server_add_vcpu (s, is_default, v); + rc =hvm_ioreq_server_add_vcpu (s, v);if ( rc ) goto fail; }
@@ -1029,10 +1027,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,12 +1045,11 @@ 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)hvm_ioreq_server_remove_vcpu (s, v);spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock);
@@ -1055,28 +1057,19 @@ void hvm_all_ioreq_servers_remove_vcpu(struct domain *d, struct vcpu *v)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 ; - -list_del (&s->list_entry); - -hvm_ioreq_server_deinit (s, is_default); +hvm_ioreq_server_disable (s); +hvm_ioreq_server_deinit (s); +set_ioreq_server (d, id,NULL );xfree (s); }
@@ -1111,7 +1104,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 +1157,10 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,uint32_t cf8;uint8_t type;uint64_t addr; - -if (list_empty (&d->arch.hvm_domain.ioreq_server.list) ) -return NULL ; +unsigned int id;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 +1200,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 (IS_DEFAULT (s) )continue ; r = s->range[type];
@@ -1251,7 +1237,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 +1396,13 @@ 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 ; -list_for_each_entry ( s, - &d->arch.hvm_domain.ioreq_server.list, - list_entry ) + FOR_EACH_IOREQ_SERVER(d, id, s) + {if (hvm_send_ioreq (s, p, buffered) ==X86EMUL_UNHANDLEABLE ) failed++; + }return failed; }
@@ -1436,7 +1422,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 +5 -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,9 @@ 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 ]; } 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
Re: [PATCH v9 01/11] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +13
-0@@ -33,6 +33,44 @@#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; +} + +#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm_domain.ioreq_server.server[id] + +static struct hvm_ioreq_server *get_ioreq_server(const struct domain *d,
xen/arch/x86/hvm/ioreq.c line 58
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+ unsigned int id) +{ +if ( id >=MAX_NR_IOREQ_SERVERS ) +return NULL ; + +return GET_IOREQ_SERVER (d, id); +} + +#define IS_DEFAULT (s) \ + ((s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID))
While at this point it looks like all users of this macro either explicitly check s to be non-NULL before invoking the macro or are being called with s guaranteed non-NULL, going forward it may easily be that NULL might be handed here. Therefore I think it would be better to either add an ASSERT() or do
#define IS_DEFAULT(s) \
((s) && (s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID)).
xen/arch/x86/hvm/ioreq.c line 64
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +5
-0+/* +* Iterate over all possible ioreq servers. The use of inline function +* get_ioreq_server() in the increment is deliberate as use of the +* GET_IOREQ_SERVER() macro will cause gcc to complain about an array +* overflow.
I think you shouldn't accuse gcc of complaining, but simply state that there _will be_ an array overflow otherwise.
xen/arch/x86/hvm/ioreq.c line 70
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+*/ +#define FOR_EACH_IOREQ_SERVER (d, id, s) \ + for ( (id) = 0, (s) = GET_IOREQ_SERVER(d, 0); \ + (id) < MAX_NR_IOREQ_SERVERS; \ + (s) = get_ioreq_server(d, ++(id)) ) \ + if ( !s ) \
Alternatively, how about folding both macro and inline function invocation be putting them in the if() here?
Quoted 38 lines
xen/arch/x86/hvm/ioreq.c +5
-16@@ -685,52 +688,64 @@ 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 ;
xen/arch/x86/hvm/ioreq.c int hvm_create_ioreq_server(struct domain *d, domid_t domid, · line 718
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +9
-0+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 ; + }
Strictly speaking the braces here are pointless. But you're the maintainer, so you know what you like.
Everything else looks fine to me now.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 01/11] x86/hvm/ioreq: maintain an array of ioreq servers rather than a list
Quoted 47 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 13:40
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v9 01/11] x86/hvm/ioreq: maintain an array of ioreq servers rather than a listQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +3
-0@@ -33,6 +33,44 @@#include <public/hvm/ioreq.h> +static void set_ioreq_server (struct domain *d,unsigned int id, +struct hvm_ioreq_server *s) +{xen/arch/x86/hvm/ioreq.c line 48
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+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; +} + +#define GET_IOREQ_SERVER (d, id) \ + (d)->arch.hvm_domain.ioreq_server.server[id] + +static struct hvm_ioreq_server *get_ioreq_server(const struct domain*d,
xen/arch/x86/hvm/ioreq.c line 58
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+ unsigned int id) +{ +if ( id >=MAX_NR_IOREQ_SERVERS ) +return NULL ; + +return GET_IOREQ_SERVER (d, id); +} + +#define IS_DEFAULT (s) \ + ((s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID))While at this point it looks like all users of this macro either explicitly check s to be non-NULL before invoking the macro or are being called with s guaranteed non-NULL, going forward it may easily be that NULL might be handed here. Therefore I think it would be better to either add an
ASSERT()or do
Quoted 3 lines
#define IS_DEFAULT(s) \
((s) && (s) == get_ioreq_server((s)->domain, DEFAULT_IOSERVID))Ok, I'll code it as you suggest.
Quoted 18 lines
.
xen/arch/x86/hvm/ioreq.c line 64
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +5
-0+/* +* Iterate over all possible ioreq servers. The use of inline function +* get_ioreq_server() in the increment is deliberate as use of the +* GET_IOREQ_SERVER() macro will cause gcc to complain about an array +* overflow. I think you shouldn't accuse gcc of complaining, but simply state that there
_willbe_an array overflow otherwise.xen/arch/x86/hvm/ioreq.c line 70
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+*/ +#define FOR_EACH_IOREQ_SERVER (d, id, s) \ + for ( (id) = 0, (s) = GET_IOREQ_SERVER(d, 0); \ + (id) < MAX_NR_IOREQ_SERVERS; \ + (s) = get_ioreq_server(d, ++(id)) ) \ + if ( !s ) \
Quoted 2 lines
Alternatively, how about folding both macro and inline function invocation be putting them in the
if()here?
I guess that now the if is there I could do that... probably will look neater.
Quoted 45 lines
xen/arch/x86/hvm/ioreq.c int hvm_create_ioreq_server(struct domain *d,
Quoted 2 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -685,52 +688,64 @@ int hvm_create_ioreq_server(struct domain *d,
domid_tdomid,Quoted 42 lines
xen/arch/x86/hvm/ioreq.c +9
-16ioservid_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 + {
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_create_ioreq_server(struct domain *d, domid_t domid, · line 718
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +5
-0+for ( i =0 ; i <MAX_NR_IOREQ_SERVERS ; i++ ) + { +if ( i !=DEFAULT_IOSERVID && !GET_IOREQ_SERVER (d, i) ) +break ; + }Strictly speaking the braces here are pointless. But you're the maintainer, so you know what you like.
Yes, I prefer to keep them.
Quoted 3 lines
Everything else looks fine to me now.
Cool. Thanks,
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 2/11 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: 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 | 182 ++++++++++++++++++----------------------------- 1 file changed, 69 insertions(+), 113 deletions(-)
xen/arch/x86/hvm/ioreq.c +69 -113
@@ -217,63 +217,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); -return 0 ; +if ( iorp->gfn ==gfn_x (INVALID_GFN ) ) +return -ENOMEM ; + + 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)
@@ -286,8 +298,7 @@ bool is_ioreq_server_page(struct domain *d, const struct page_info *page) FOR_EACH_IOREQ_SERVER(d, id, s) { -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 ;
@@ -299,20 +310,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),
@@ -447,78 +468,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)
@@ -578,22 +546,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;
@@ -608,21 +569,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;
@@ -644,6 +597,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;
@@ -651,7 +607,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 v9 3/11 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]>
--- 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
@@ -217,7 +217,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;
@@ -227,20 +227,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); }
@@ -249,7 +248,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);
@@ -258,7 +257,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)
@@ -271,16 +270,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);
@@ -316,10 +316,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);
@@ -331,12 +331,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)));
@@ -597,8 +597,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 )
@@ -764,11 +764,11 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,ASSERT (!IS_DEFAULT (s)); - *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 v9 4/11 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]>
v8:
- For safety make all of the pointers passed to
hvm_get_ioreq_server_info() optional.
- Shrink bufioreq_handling down to a uint8_t.
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 | 47 ++++++++++++++----------- xen/include/asm-x86/hvm/domain.h | 2 +- xen/include/public/hvm/dm_op.h | 32 ++++++++++------- 6 files changed, 63 insertions(+), 41 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
@@ -416,16 +416,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 +26 -21
108 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +1 -1
@@ -69,7 +69,7 @@ struct hvm_ioreq_server {evtchn_port_t bufioreq_evtchn;struct rangeset *range[NR_IO_RANGE_TYPES ];bool enabled; -bool bufioreq_atomic; +uint8_t bufioreq_handling; };/*
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 v9 04/11] x86/hvm/ioreq: defer mapping gfns until they are actually requsted
xen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, · line 361
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +2
-0@@ -357,6 +357,9 @@ static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, } } +#define HANDLE_BUFIOREQ (s) \ + (s->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
Didn't I point out already that s wants to be parenthesized here? Or was that on another macro? With this taken care of
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 04/11] x86/hvm/ioreq: defer mapping gfns until they are actually requsted
Quoted 17 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 13:46
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 v9 04/11] 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 06.10.17 at 14:25, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +0
-0@@ -357,6 +357,9 @@ static void hvm_update_ioreq_evtchn(struct
hvm_ioreq_server*s,
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c static void hvm_update_ioreq_evtchn(struct hvm_ioreq_server *s, · line 361
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +2
-0} } +#define HANDLE_BUFIOREQ (s) \ + (s->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)Didn't I point out already that s wants to be parenthesized here? Or was that on another macro?
Sorry, I think you did.... I just forgot.
Quoted 3 lines
With this taken care of
Reviewed-by Jan Beulich <[email protected]>
Ok, thanks.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 5/11 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.
This patch adds the boilerplate for new memory op to allow such a resource to be priv-mapped directly, by either a PV or HVM tools domain.
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: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
v8:
- Move the code into common as requested by Jan.
- Make the gmfn_list handle a 64-bit type to avoid limiting the MFN range for a 32-bit tools domain.
- Add missing pad.
- Add compat code.
- Make this patch deal with purely boilerplate.
- Drop George's A-b and Wei's R-b because the changes are non-trivial, and update Cc list now the boilerplate is common.
v5:
- Switched __copy_to/from_guest_offset() to copy_to/from_guest_offset().
--- xen/arch/x86/mm/p2m.c | 3 +- xen/common/compat/memory.c | 52 ++++++++++++++++++++++++++++++ xen/common/memory.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/p2m.h | 3 ++ xen/include/public/memory.h | 32 ++++++++++++++++++- xen/include/xlat.lst | 1 + 6 files changed, 165 insertions(+), 3 deletions(-)
xen/arch/x86/mm/p2m.c +1 -2
@@ -1131,8 +1131,7 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn_l, }/* 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/compat/memory.c +52 -0
76 lines not on this page · raw message
xen/common/memory.c +77 -0
89 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 +31 -1
@@ -599,6 +599,36 @@ struct xen_reserved_device_memory_map {typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t ;DEFINE_XEN_GUEST_HANDLE (xen_reserved_device_memory_map_t); +/* +* 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 */ +uint16_t type; +/* +* 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; +uint32_t pad; +/* 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_ulong_t) gmfn_list; +}; +typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t ; +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ /*
@@ -650,7 +680,7 @@ 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 */ +/* Next available subop number is 29 */ #endif /* __XEN_PUBLIC_MEMORY_H__ */
xen/include/xlat.lst +1 -0
@@ -83,6 +83,7 @@ ! memory_map memory.h ! memory_reservation memory.h ! mem_access_op memory.h +! mem_acquire_resource memory.h ! pod_target memory.h ! remove_from_physmap memory.h ! reserved_device_memory_map memory.h
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/compat/memory.c +2
-0@@ -395,6 +397,39 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) }#endif +case XENMEM_acquire_resource: + {
xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 411
Quoted 10 lines
xen/common/compat/memory.c +10
-0+xen_ulong_t *gmfn_list = (xen_ulong_t *)(nat.mar +1 ); + +if (copy_from_guest (&cmp.mar, compat,1 ) || + !compat_handle_okay (cmp.mar.gmfn_list, + cmp.mar.nr_frames) ) +return -EFAULT ; + +if (sizeof (*gmfn_list) * cmp.mar.nr_frames > +COMPAT_ARG_XLAT_SIZE -sizeof (*nat.mar) ) +return -E2BIG ;
With the actual handler accepting no more than 2 entries this is certainly good enough for now, but since larger arrays could be handled here perhaps a comment would be helpful to clarify why this is sufficient atm.
Quoted 8 lines
xen/common/compat/memory.c +4
-0@@ -535,6 +570,23 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) rc = -EFAULT ;break ; +case XENMEM_acquire_resource: + { +xen_ulong_t *gmfn_list = (xen_ulong_t *)(nat.mar +1 ); +
xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 586
Quoted 10 lines
xen/common/compat/memory.c +10
-0+for ( i =0 ; i < cmp.mar.nr_frames; i++ ) + { +compat_ulong_t gmfn = gmfn_list[i]; + +if ( gmfn != gmfn_list[i] ) +return -ERANGE ; + +if (__copy_to_compat_offset (cmp.mar.gmfn_list, i, + &gmfn,1 ) ) +return -EFAULT ;
While I consider it acceptable to leave kind of inconsistent state in this latter case (as it's under guest control to avoid the situation), I'm not sure the -ERANGE return above wouldn't better be accompanied by undoing the operation. Undoing in both cases would become imperative once set_foreign_p2m_entry() acquires proper page references.
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 968
Quoted 7 lines
xen/common/memory.c +1
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain *d, unsigned int space)return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86
Could you try to (a) have only a single such #ifdef and (b) reduce its scope as much as possible? Even if for now the code is dead on ARM, making sure it continues to compile there would be helpful.
Quoted 24 lines
xen/common/memory.c +24
-0+static int acquire_resource (const xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 ) +return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; + + 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; + +switch ( xmar->type ) + { +default : + rc = -EOPNOTSUPP ;
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 1002
Quoted 10 lines
xen/common/memory.c +10
-0+break ; + } + +if ( rc ) + goto out; + +if ( !paging_mode_translate (currd) ) + { +if (copy_to_guest_offset (xmar->gmfn_list,0 , mfn_list, + xmar->nr_frames) )
Just copy_to_guest()?
Quoted 7 lines
xen/common/memory.c +7
-0+ rc = -EFAULT ; + } +else + { +unsigned int i; + +for ( i =0 ; i < xmar->nr_frames; i++ )
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 1019
Quoted 10 lines
xen/common/memory.c +10
-0+ { +xen_pfn_t gfn; + + rc = -EFAULT ; +if (copy_from_guest_offset (&gfn, xmar->gmfn_list, i,1 ) ) + goto out; + + rc =set_foreign_p2m_entry (currd, gfn,_mfn (mfn_list[i])); +if ( rc ) + goto out;
Perhaps partial success indication would be necessary here, so the caller knows what to undo later. Or alternatively (just like said for the compat wrapper) you may want/need to clean up yourself.
Quoted 16 lines
xen/include/public/memory.h +10
-0@@ -599,6 +599,36 @@ struct xen_reserved_device_memory_map {typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t ;DEFINE_XEN_GUEST_HANDLE (xen_reserved_device_memory_map_t); +/* +* 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 */ +uint16_t type;
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 621
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; +uint32_t pad; +/* IN - the index of the initial frame to be mapped */ +uint64_aligned_t frame;
Does this really need to be 64 bits wide?
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 628
Quoted 7 lines
xen/include/public/memory.h +7
-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 +* 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_ulong_t) gmfn_list;
Why not xen_pfn_t?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 27 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 14:06
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[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 v9 05/11] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesReview int compat_memory_op(unsigned int cmd,
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
(quoted diff) +0
-0@@ -395,6 +397,39 @@ int compat_memory_op(unsigned int cmd,
XEN_GUEST_HANDLE_PARAM(void)compat)Quoted 12 lines
xen/common/compat/memory.c +9
-0}#endif +case XENMEM_acquire_resource: + { +xen_ulong_t *gmfn_list = (xen_ulong_t *)(nat.mar +1 ); + +if (copy_from_guest (&cmp.mar, compat,1 ) || + !compat_handle_okay (cmp.mar.gmfn_list, + cmp.mar.nr_frames) ) +return -EFAULT ; +
Quoted 8 lines
xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 411
Quoted 3 lines
xen/common/compat/memory.c +3
-0+if (sizeof (*gmfn_list) * cmp.mar.nr_frames > +COMPAT_ARG_XLAT_SIZE -sizeof (*nat.mar) ) +return -E2BIG ;With the actual handler accepting no more than 2 entries this is certainly good enough for now, but since larger arrays could be handled here perhaps a comment would be helpful to clarify why this is sufficient atm.
Ok.
Quoted 19 lines
Review int compat_memory_op(unsigned int cmd,
Quoted 2 lines
(quoted diff) +0
-0@@ -535,6 +570,23 @@ int compat_memory_op(unsigned int cmd,
XEN_GUEST_HANDLE_PARAM(void)compat)Quoted 16 lines
xen/common/compat/memory.c +13
-0rc = -EFAULT ;break ; +case XENMEM_acquire_resource: + { +xen_ulong_t *gmfn_list = (xen_ulong_t *)(nat.mar +1 ); + +for ( i =0 ; i < cmp.mar.nr_frames; i++ ) + { +compat_ulong_t gmfn = gmfn_list[i]; + +if ( gmfn != gmfn_list[i] ) +return -ERANGE ; + +if (__copy_to_compat_offset (cmp.mar.gmfn_list, i, + &gmfn,1 ) )
Quoted 8 lines
Review int compat_memory_op(unsigned int cmd, · line 586
Quoted 1 line
(quoted diff) +1
-0+ return -EFAULT;While I consider it acceptable to leave kind of inconsistent state in this latter case (as it's under guest control to avoid the situation), I'm not sure the
-ERANGEreturn above wouldn't better be accompanied by undoing the operation. Undoing in both cases would become imperative onceset_foreign_p2m_entry()acquires proper page references.
Ok. I'll try to make sure things get left in a consistent state.
Quoted 5 lines
xen/common/memory.c static long xatp_permission_check(struct domain
Quoted 4 lines
xen/common/memory.c +0
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain*d, unsigned int space)
Quoted 9 lines
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 968
Quoted 4 lines
xen/common/memory.c +1
-0return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86 Could you try to (a) have only a single such #ifdef and (b) reduce its scope as much as possible? Even if for now the code is dead on ARM, making sure it continues to compile there would be helpful.
Ok. I don't have an arm machine to build on so I can't tell if anything is broken though.
Quoted 28 lines
Quoted 28 lines
xen/common/memory.c +28
-0+static int acquire_resource (const xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 ) +return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; + + 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; + +switch ( xmar->type ) + { +default : + rc = -EOPNOTSUPP ; +break ; + } + +if ( rc )
Quoted 9 lines
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 1002
Quoted 6 lines
xen/common/memory.c +6
-0+ goto out; + +if ( !paging_mode_translate (currd) ) + { +if (copy_to_guest_offset (xmar->gmfn_list,0 , mfn_list, + xmar->nr_frames) )Just
copy_to_guest()?
Ok, if that is preferable.
Quoted 14 lines
Quoted 14 lines
xen/common/memory.c +14
-0+ 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 out; +
Quoted 8 lines
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 1019
Quoted 3 lines
xen/common/memory.c +3
-0+ rc =set_foreign_p2m_entry (currd, gfn,_mfn (mfn_list[i])); +if ( rc ) + goto out;Perhaps partial success indication would be necessary here, so the caller knows what to undo later. Or alternatively (just like said for the compat wrapper) you may want/need to clean up yourself.
OK.
Quoted 22 lines
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 599
Quoted 5 lines
xen/include/public/memory.h +0
-0@@ -599,6 +599,36 @@ struct xen_reserved_device_memory_map { typedef struct xen_reserved_device_memory_map
xen_reserved_device_memory_map_t;Quoted 16 lines
xen/include/public/memory.h +14
-0DEFINE_XEN_GUEST_HANDLE (xen_reserved_device_memory_map_t); +/* +* 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 */ +uint16_t type; +/* +* IN - a type-specific resource identifier, which must be zero +* unless stated otherwise. +*/
Quoted 9 lines
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 621
Quoted 6 lines
xen/include/public/memory.h +6
-0+uint32_t id; +/* IN - number of (4K) frames of the resource to be mapped */ +uint32_t nr_frames; +uint32_t pad; +/* IN - the index of the initial frame to be mapped */ +uint64_aligned_t frame;Does this really need to be 64 bits wide?
I'd prefer not to limit to 32 bits just in case we want to use this hypercall to map something with a large frame space.
Quoted 9 lines
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 628
Quoted 7 lines
xen/include/public/memory.h +7
-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 +* 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_ulong_t) gmfn_list;Why not
xen_pfn_t?
I've debated this with myself a few times. I'm not convinced that something that could be an mfn or a gfn should have a xen_pfn_t type.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 13 lines
Quoted 13 lines
Quoted 1 line · On 10.10.17 at 15:26, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 14:06xen/common/memory.c static long xatp_permission_check(struct domain
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/memory.c +0
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain*d, unsigned int space)
Quoted 4 lines
xen/common/memory.c +1
-0return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86
Quoted 7 lines
Quoted 4 lines
Could you try to (a) have only a single such #ifdef and (b) reduce its scope as much as possible? Even if for now the code is dead on ARM, making sure it continues to compile there would be helpful.
Ok. I don't have an arm machine to build on so I can't tell if anything is broken though.
Well, that's the case for most of us x86 people. I use a cross compiler to be able to at least check the ARM build is okay.
Quoted 30 lines
Quoted 21 lines
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 599
Quoted 4 lines
xen/include/public/memory.h +0
-0@@ -599,6 +599,36 @@ struct xen_reserved_device_memory_map { typedef struct xen_reserved_device_memory_map
xen_reserved_device_memory_map_t;Quoted 16 lines
xen/include/public/memory.h +14
-0DEFINE_XEN_GUEST_HANDLE (xen_reserved_device_memory_map_t); +/* +* 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 */ +uint16_t type; +/* +* IN - a type-specific resource identifier, which must be zero +* unless stated otherwise. +*/ Quoted 8 lines
xen/include/public/memory.h struct xen_reserved_device_memory_map { · line 621
Quoted 6 lines
xen/include/public/memory.h +6
-0+uint32_t id; +/* IN - number of (4K) frames of the resource to be mapped */ +uint32_t nr_frames; +uint32_t pad; +/* IN - the index of the initial frame to be mapped */ +uint64_aligned_t frame;Does this really need to be 64 bits wide?
Quoted 2 lines
I'd prefer not to limit to 32 bits just in case we want to use this hypercall to map something with a large frame space.
In which case you'll need to take care of the truncation issues I've pointed out elsewhere.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
xen/include/public/memory.h +7
-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 +* 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_ulong_t) gmfn_list;
Quoted 4 lines
Quoted 1 line
Why not
xen_pfn_t?I've debated this with myself a few times. I'm not convinced that something that could be an mfn or a gfn should have a
xen_pfn_ttype.
Well, looking over the present uses of xen_pfn_t it looks like quite a few are for mixed meaning uses between PV and HVM. And btw, since we try to get rid of the term "GMFN", perhaps "frame_list" might be a better field name here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
In reply to Paul DurrantQuoted 15 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/memory.c +8
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain *d, unsigned int space)return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86 +static int acquire_resource (const xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 )
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 985
Quoted 10 lines
xen/common/memory.c +10
-0+return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; + + d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d);
Looking at the description of patch 6 - why is this XSM_TARGET rather than XSM_DM_PRIV?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 33 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[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 v9 05/11] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesxen/common/memory.c static long xatp_permission_check(struct domain
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/memory.c +0
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain*d, unsigned int space)
Quoted 16 lines
xen/common/memory.c +13
-0return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86 +static int acquire_resource (const xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 ) +return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; +
Quoted 8 lines
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 985
Quoted 5 lines
xen/common/memory.c +5
-0+ d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d);Looking at the description of patch 6 - why is this
XSM_TARGETrather thanXSM_DM_PRIV?
Good point. I was using the priv mapping code as a guide, but XSM_DM_PRIV is probably the right thing to use in this case.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 55 lines
-----Original Message-----
From: Paul Durrant
Sent: 10 October 2017 15:10
To: 'Jan Beulich' <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[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 v9 05/11] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 8 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 15:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; KonradRzeszutek
Quoted 25 lines
Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: Re: [PATCH v9 05/11] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesxen/common/memory.c static long xatp_permission_check(struct domain
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/memory.c +0
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain*d, unsigned int space)
Quoted 16 lines
xen/common/memory.c +13
-0return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86 +static int acquire_resource (const xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 ) +return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; +Quoted 8 lines
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 985
Quoted 5 lines
xen/common/memory.c +5
-0+ d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d);Looking at the description of patch 6 - why is this
XSM_TARGETrather thanXSM_DM_PRIV?
Quoted 3 lines
Good point. I was using the priv mapping code as a guide, but
XSM_DM_PRIVis probably the right thing to use in this case.
Actually that's not possible. There is an assertion in xsm_domain_memory_map() that the action is XSM_TARGET.
Paul
Quoted 4 lines
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 36 lines
Quoted 36 lines
Quoted 1 line · On 10.10.17 at 16:37, <[email protected]> wrote:
From: Paul Durrant
Sent: 10 October 2017 15:10Quoted 32 lines
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 15:23
To: Paul Durrant <[email protected]>xen/common/memory.c static long xatp_permission_check(struct domain
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/memory.c +0
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(struct domain*d, unsigned int space)
Quoted 11 lines
xen/common/memory.c +8
-0return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86 +static int acquire_resource (const xen_mem_acquire_resource_t *xmar) +{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 )xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 985
Quoted 10 lines
xen/common/memory.c +10
-0+return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; + + d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d);Looking at the description of patch 6 - why is this
XSM_TARGETrather thanXSM_DM_PRIV?
Quoted 6 lines
Quoted 3 lines
Good point. I was using the priv mapping code as a guide, but
XSM_DM_PRIVis probably the right thing to use in this case.Actually that's not possible. There is an assertion in
xsm_domain_memory_map()that the action isXSM_TARGET.
Well, I was afraid of this being the case, but this only complicates your job, it doesn't make XSM_TARGET the right choice here. But wait, maybe it can be considered sufficient, but then this needs to be prominently pointed out by a comment added at a suitable
place: For the ioreq pages, them being owned by the emulating domain, page ownership validations while trying to make use of the MFNs would prevent mis-use by the domain the emulation is being done for. And for grant table pages the guest is able to access them another way anyway.
Which basically leaves the question of this being an information leak for ioreq pages, as the guest is not supposed to know the MFNs, but could obtain them here. I for one would consider such a leak a security issue, even if knowledge of the MFNs alone is not enough to exploit anything, but maybe others think differently.
But the grant table aspect suggests anyway that perhaps the permission to be checked here needs to depend on resource type.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 69 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 11 October 2017 09:31
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'xen- [email protected]' <[email protected]>; 'KonradRzeszutek Wilk' <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: RE: [PATCH v9 05/11] x86/mm: addHYPERVISOR_memory_opto acquire guest resourcesQuoted 10 lines
Quoted 10 lines
Quoted 1 line · On 10.10.17 at 16:37, <[email protected]> wrote:
From: Paul Durrant
Sent: 10 October 2017 15:10Quoted 7 lines
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 15:23
To: Paul Durrant <[email protected]>xen/common/memory.c static long xatp_permission_check(struct
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/memory.c +0
-0@@ -965,6 +965,67 @@ static long xatp_permission_check(structdomain
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
*d, unsigned int space)
xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space)
Quoted 5 lines
xen/common/memory.c +2
-0return xsm_add_to_physmap (XSM_TARGET , current->domain, d); } +#ifdef CONFIG_X86 +static int acquire_resource(const xen_mem_acquire_resource_t*xmar)
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 6 lines
xen/common/memory.c +6
-0+{ +struct domain *d, *currd = current->domain; +unsigned long mfn_list[2 ]; +int rc; + +if ( xmar->nr_frames ==0 || xmar->pad !=0 )xen/common/memory.c static long xatp_permission_check(struct domain *d, unsigned int space) · line 985
Quoted 10 lines
xen/common/memory.c +10
-0+return -EINVAL ; + +if ( xmar->nr_frames >ARRAY_SIZE (mfn_list) ) +return -E2BIG ; + + d =rcu_lock_domain_by_any_id (xmar->domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_domain_memory_map (XSM_TARGET , d);Looking at the description of patch 6 - why is this
XSM_TARGETrather thanXSM_DM_PRIV?Quoted 1 line
Quoted 1 line
Good point. I was using the priv mapping code as a guide, but
XSM_DM_PRIVQuoted 5 lines
Quoted 2 lines
is probably the right thing to use in this case.
Actually that's not possible. There is an assertion in
xsm_domain_memory_map()that the action isXSM_TARGET.Well, I was afraid of this being the case, but this only complicates your job, it doesn't make
XSM_TARGETthe right choice here. But wait, maybe it can be considered sufficient, but then this needs to be prominently pointed out by a comment added at a suitable
place: For the ioreq pages, them being owned by the emulating domain, page ownership validations while trying to make use of the MFNs would prevent mis-use by the domain the emulation is being done for. And for grant table pages the guest is able to access them another way anyway.
Quoted 6 lines
Which basically leaves the question of this being an information leak for ioreq pages, as the guest is not supposed to know the MFNs, but could obtain them here. I for one would consider such a leak a security issue, even if knowledge of the MFNs alone is not enough to exploit anything, but maybe others think differently.
I agree with you. Now you point it out, it does rather defeat the purpose of having the separate resource map hypercall.
Quoted 2 lines
But the grant table aspect suggests anyway that perhaps the permission to be checked here needs to depend on resource type.
Separate permissions could be an option, but maybe it would be better just to introduce a new resource mapping permission. I'll probably go with the latter.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 05/11] x86/mm: add HYPERVISOR_memory_op to acquire guest resources
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.10.17 at 10:38, <[email protected]> wrote:
Separate permissions could be an option, but maybe it would be better just to introduce a new resource mapping permission. I'll probably go with the latter.
Oh, I'm certainly fine with that, it just means more changes.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 6/11 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]>
v8:
- Re-base on new boilerplate.
- Adjust function signature of hvm_get_ioreq_server_frame(), and test whether the bufioreq page is present.
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 | 140 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm.c | 22 +++++++ xen/common/memory.c | 5 ++ xen/include/asm-x86/hvm/ioreq.h | 6 ++ xen/include/asm-x86/mm.h | 5 ++ xen/include/public/hvm/dm_op.h | 4 ++ xen/include/public/memory.h | 13 +++- 7 files changed, 194 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/ioreq.c +140 -0
@@ -266,6 +266,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 ;
@@ -288,6 +301,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;
@@ -491,6 +559,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;
@@ -619,7 +708,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; }
@@ -629,6 +729,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); }
@@ -784,6 +885,45 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,return rc; } +int hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx,mfn_t *mfn) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; + + s =get_ioreq_server (d, id); + +ASSERT (!IS_DEFAULT (s)); + + rc =hvm_ioreq_server_alloc_pages (s); +if ( rc ) + goto out; + +if ( idx ==0 ) + { + rc = -ENOENT ; +if ( !HANDLE_BUFIOREQ (s) ) + goto out; + + *mfn =_mfn (page_to_mfn (s->bufioreq.page)); + rc =0 ; + } +else if ( idx ==1 ) + *mfn =_mfn (page_to_mfn (s->ioreq.page)); +else + rc = -EINVAL ; + + out: +spin_unlock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +return rc; +} +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 +22 -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>
@@ -3866,6 +3867,27 @@ int xenmem_add_to_physmap_one(return rc; } +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; +int rc =hvm_get_ioreq_server_frame (d, id, frame + i, &mfn); + +if ( rc ) +return rc; + + mfn_list[i] =mfn_x (mfn); + } + +return 0 ; +} +long arch_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {int rc;
xen/common/memory.c +5 -0
@@ -988,6 +988,11 @@ static int acquire_resource(const xen_mem_acquire_resource_t *xmar)switch ( xmar->type ) { +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). +*/ +int hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx,mfn_t *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/include/asm-x86/mm.h +5 -0
@@ -615,4 +615,9 @@ static inline bool arch_mfn_in_directmap(unsigned long mfn) return mfn <= (virt_to_mfn(eva - 1) + 1); } +int xenmem_acquire_ioreq_server (struct domain *d,unsigned int id, +unsigned long frame, +unsigned long nr_frames, +unsigned long mfn_list[]); +#endif /* __ASM_X86_MM_H__ */
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 +12 -1
@@ -609,15 +609,26 @@ struct xen_mem_acquire_resource {domid_t domid;/* IN - the type of resource */ uint16_t type; + +#define XENMEM_resource_ioreq_server 0 +/* * 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 */ uint32_t nr_frames;uint32_t pad; -/* IN - the index of the initial frame to be mapped */ +/* IN - the index of the initial frame to be mapped +* +* type == XENMEM_resource_ioreq_server -> frame == 0 -> bufioreq +* page +* frame == 1 -> ioreq +* page +*/ 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.
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v9 06/11] x86/hvm/ioreq: add a new mappable resource type...
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/arch/x86/hvm/ioreq.c +17
-0@@ -288,6 +301,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 ; + }
xen/arch/x86/hvm/ioreq.c static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) · line 330
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-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);
Whichever domain you assign the page to, you need to prevent it becoming usable as e.g. a page table or descriptor table page. IOW I think your missing a get_page_type(..., PGT_writable) here, with the put_page() on the free path below then needing to become put_page_and_type().
Quoted 14 lines
xen/arch/x86/hvm/ioreq.c +10
-0@@ -784,6 +885,45 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,return rc; } +int hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx,mfn_t *mfn) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ;
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 907
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+ + s =get_ioreq_server (d, id); + +ASSERT (!IS_DEFAULT (s)); + + rc =hvm_ioreq_server_alloc_pages (s); +if ( rc ) + goto out; + +if ( idx ==0 )
switch() ?
Quoted 5 lines
xen/arch/x86/mm.c +1
-0@@ -3866,6 +3867,27 @@ int xenmem_add_to_physmap_one(return rc; } +int xenmem_acquire_ioreq_server(struct domain *d, unsigned int id,
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 3880
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+unsigned long frame, + unsigned long nr_frames, + unsigned long mfn_list[]) +{ + unsigned int i; + +for ( i =0 ; i < nr_frames; i++ ) + { +mfn_t mfn; +int rc =hvm_get_ioreq_server_frame (d, id, frame + i, &mfn);
Coming back to the question of the size of the "frame" interface structure field, note how you silently truncate the upper 32 bits here.
Quoted 17 lines
xen/include/public/memory.h +5
-0@@ -609,15 +609,26 @@ struct xen_mem_acquire_resource {domid_t domid;/* IN - the type of resource */ uint16_t type; + +#define XENMEM_resource_ioreq_server 0 +/* * 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 */
xen/include/public/memory.h struct xen_mem_acquire_resource { · line 631
Quoted 10 lines
xen/include/public/memory.h +7
-1uint32_t nr_frames;uint32_t pad; -/* IN - the index of the initial frame to be mapped */ +/* IN - the index of the initial frame to be mapped +* +* type == XENMEM_resource_ioreq_server -> frame == 0 -> bufioreq +* page +* frame == 1 -> ioreq +* page +*/
Long comment or not I think you want to introduce constants for these two numbers.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 06/11] x86/hvm/ioreq: add a new mappable resource type...
Quoted 46 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 16:21
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 v9 06/11] x86/hvm/ioreq: add a new mappable resource type...Review static int hvm_map_ioreq_gfn(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
(quoted diff) +0
-0@@ -288,6 +301,61 @@ static int hvm_map_ioreq_gfn(struct
hvm_ioreq_server*s, bool buf)Quoted 16 lines
xen/arch/x86/hvm/ioreq.c +13
-0return 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 ) )xen/arch/x86/hvm/ioreq.c static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf)
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+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
xen/arch/x86/hvm/ioreq.c static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) · line 330
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +4
-0+* could fail if the emulating domain has already reached its +* maximum allocation. +*/ + iorp->page =alloc_domheap_page (currd, MEMF_no_refcount);
Quoted 5 lines
Whichever domain you assign the page to, you need to prevent it becoming usable as e.g. a page table or descriptor table page. IOW I think your missing a
get_page_type(..., PGT_writable)here, with theput_page()on the free path below then needing to becomeput_page_and_type().
Ok.
Quoted 20 lines
Review int hvm_get_ioreq_server_info(struct domain *d,
Quoted 2 lines
(quoted diff) +0
-0@@ -784,6 +885,45 @@ int hvm_get_ioreq_server_info(struct domain *d,
ioservid_tid,Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +14
-0return rc; } +int hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx,mfn_t *mfn) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; + + s =get_ioreq_server (d, id); + +ASSERT (!IS_DEFAULT (s));
Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 907
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ + rc =hvm_ioreq_server_alloc_pages (s); +if ( rc ) + goto out; + +if ( idx ==0 )
switch()?
Yes, but if idx can exceed 1 in future (which would need to be the case to support greater numbers of vcpus) then I guess it may change back.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -3866,6 +3867,27 @@ int xenmem_add_to_physmap_one(return rc; }
Quoted 15 lines
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 3880
Quoted 11 lines
xen/arch/x86/mm.c +11
-0+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; +int rc =hvm_get_ioreq_server_frame (d, id, frame + i, &mfn);Coming back to the question of the size of the "frame" interface structure field, note how you silently truncate the upper 32 bits here.
OK. For this resource type I can't see 64-bits being needed, but I'll carry them through.
Quoted 23 lines
Quoted 23 lines
xen/include/public/memory.h +7
-1@@ -609,15 +609,26 @@ struct xen_mem_acquire_resource {domid_t domid;/* IN - the type of resource */ uint16_t type; + +#define XENMEM_resource_ioreq_server 0 +/* * 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 */ uint32_t nr_frames;uint32_t pad; -/* IN - the index of the initial frame to be mapped */ +/* IN - the index of the initial frame to be mapped +*
Quoted 9 lines
xen/include/public/memory.h struct xen_mem_acquire_resource { · line 631
Quoted 5 lines
xen/include/public/memory.h +5
-0+* type == XENMEM_resource_ioreq_server -> frame == 0 -> bufioreq +* page +* frame == 1 -> ioreq +* page +*/ Long comment or not I think you want to introduce constants for these two numbers.
Yes, that would probably be better although increasing the number of supported vcpus may mean that >1 becomes valid in future.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 06/11] x86/hvm/ioreq: add a new mappable resource type...
Quoted 32 lines
Quoted 23 lines
Quoted 1 line · On 10.10.17 at 16:45, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 09 October 2017 16:21Review int hvm_get_ioreq_server_info(struct domain *d,
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
(quoted diff) +0
-0@@ -784,6 +885,45 @@ int hvm_get_ioreq_server_info(struct domain *d,
ioservid_tid,Quoted 17 lines
xen/arch/x86/hvm/ioreq.c +14
-0return rc; } +int hvm_get_ioreq_server_frame (struct domain *d,ioservid_t id, +unsigned int idx,mfn_t *mfn) +{ +struct hvm_ioreq_server *s; +int rc; + +spin_lock_recursive (&d->arch.hvm_domain.ioreq_server.lock); + +if ( id ==DEFAULT_IOSERVID ) +return -EOPNOTSUPP ; + + s =get_ioreq_server (d, id); + +ASSERT (!IS_DEFAULT (s));Quoted 8 lines
xen/arch/x86/hvm/ioreq.c int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, · line 907
Quoted 6 lines
xen/arch/x86/hvm/ioreq.c +6
-0+ + rc =hvm_ioreq_server_alloc_pages (s); +if ( rc ) + goto out; + +if ( idx ==0 )
switch()?
Quoted 2 lines
Yes, but if idx can exceed 1 in future (which would need to be the case to support greater numbers of vcpus) then I guess it may change back.
If you anticipate that to not be expressable by case labels (not even by range ones), then perhaps indeed better stick to if/else.
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/ioreq.c +0
-0@@ -3866,6 +3867,27 @@ int xenmem_add_to_physmap_one(return rc; }Quoted 15 lines
xen/arch/x86/mm.c int xenmem_add_to_physmap_one( · line 3880
Quoted 11 lines
xen/arch/x86/mm.c +11
-0+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; +int rc =hvm_get_ioreq_server_frame (d, id, frame + i, &mfn);Coming back to the question of the size of the "frame" interface structure field, note how you silently truncate the upper 32 bits here.
Quoted 2 lines
OK. For this resource type I can't see 64-bits being needed, but I'll carry them through.
Carrying the full value through is one option. The other is to bail early when finding the upper bits set.
Quoted 32 lines
Quoted 22 lines
Quoted 22 lines
xen/include/public/memory.h +7
-1@@ -609,15 +609,26 @@ struct xen_mem_acquire_resource {domid_t domid;/* IN - the type of resource */ uint16_t type; + +#define XENMEM_resource_ioreq_server 0 +/* * 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 */ uint32_t nr_frames;uint32_t pad; -/* IN - the index of the initial frame to be mapped */ +/* IN - the index of the initial frame to be mapped +* Quoted 9 lines
xen/include/public/memory.h struct xen_mem_acquire_resource { · line 631
Quoted 5 lines
xen/include/public/memory.h +5
-0+* type == XENMEM_resource_ioreq_server -> frame == 0 -> bufioreq +* page +* frame == 1 -> ioreq +* page +*/ Long comment or not I think you want to introduce constants for these two numbers.
Quoted 2 lines
Yes, that would probably be better although increasing the number of supported vcpus may mean that >1 becomes valid in future.
Sure, but that would then still better be expressed by a suitable macro (perhaps one long the lines of MSR_P6_PERFCTR()).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 7/11 x86/mm: add an extra command to HYPERVISOR_mmu_update...
In reply to Paul Durrant...to allow the calling domain to prevent translation of specified l1e value.
Despite what the comment in public/xen.h might imply, specifying a command value of MMU_NORMAL_PT_UPDATE will not simply update an l1e with the specified value. Instead, mod_l1_entry() tests whether foreign_dom has PG_translate set in its paging mode and, if it does, assumes that the the pfn value in the l1e is a gfn rather than an mfn.
To allow PV tools domain to map mfn values from a previously issued HYPERVISOR_memory_op:XENMEM_acquire_resource, there needs to be a way to tell HYPERVISOR_mmu_update that the specific l1e value does not require translation regardless of the paging mode of foreign_dom. This patch therefore defines a new command value, MMU_PT_UPDATE_NO_TRANSLATE, which has the same semantics as MMU_NORMAL_PT_UPDATE except that the paging mode of foreign_dom is ignored and the l1e value is used verbatim.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
v8:
- New in this version, replacing "allow a privileged PV domain to map guest mfns".
--- xen/arch/x86/mm.c | 17 ++++++++++------- xen/include/public/xen.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-)
xen/arch/x86/mm.c +10 -7
@@ -1619,9 +1619,10 @@ void page_unlock(struct page_info *page)/* Update the L1 entry at pl1e to new value nl1e. */ static int mod_l1_entry (l1_pgentry_t *pl1e,l1_pgentry_t nl1e, -unsigned long gl1mfn,int preserve_ad, +unsigned long gl1mfn,int cmd,struct vcpu *pt_vcpu,struct domain *pg_dom) { +bool preserve_ad = (cmd ==MMU_PT_UPDATE_PRESERVE_AD );l1_pgentry_t ol1e;struct domain *pt_dom = pt_vcpu->domain;int rc =0 ;
@@ -1643,7 +1644,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,return -EINVAL ; } -if (paging_mode_translate (pg_dom) ) +if ( cmd !=MMU_PT_UPDATE_NO_TRANSLATE && +paging_mode_translate (pg_dom) ) { page =get_page_from_gfn (pg_dom,l1e_get_pfn (nl1e),NULL ,P2M_ALLOC );if ( !page )
@@ -3258,6 +3260,7 @@ long do_mmu_update(*/ case MMU_NORMAL_PT_UPDATE :case MMU_PT_UPDATE_PRESERVE_AD : +case MMU_PT_UPDATE_NO_TRANSLATE : {p2m_type_t p2mt;
@@ -3323,7 +3326,8 @@ long do_mmu_update(p2m_query_t q = (l1e_get_flags (l1e) & _PAGE_RW) ?P2M_UNSHARE :P2M_ALLOC ; -if (paging_mode_translate (pg_owner) ) +if ( cmd !=MMU_PT_UPDATE_NO_TRANSLATE && +paging_mode_translate (pg_owner) ) target =get_page_from_gfn (pg_owner,l1e_get_pfn (l1e), &l1e_p2mt, q);
@@ -3350,9 +3354,7 @@ long do_mmu_update(break ; } - rc =mod_l1_entry (va, l1e, mfn, - cmd ==MMU_PT_UPDATE_PRESERVE_AD , v, - pg_owner); + rc =mod_l1_entry (va, l1e, mfn, cmd, v, pg_owner);if ( target )put_page (target); }
@@ -3630,7 +3632,8 @@ static int __do_update_va_mapping( goto out; } - rc =mod_l1_entry (pl1e, val,mfn_x (gl1mfn),0 , v, pg_owner); + rc =mod_l1_entry (pl1e, val,mfn_x (gl1mfn),MMU_NORMAL_PT_UPDATE , v, + pg_owner);page_unlock (gl1pg);put_page (gl1pg);
xen/include/public/xen.h +9 -3
@@ -268,6 +268,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);* As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed * with those in @val. * +* ptr[1:0] == MMU_PT_UPDATE_NO_TRANSLATE: +* As MMU_NORMAL_PT_UPDATE above, but @val is not translated though FD +* page tables. +* * @val is usually the machine frame number along with some attributes. * The attributes by default follow the architecture defined bits. Meaning that * if this is a X86_64 machine and four page table layout is used, the layout
@@ -334,9 +338,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);* * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7. */ -#define MMU_NORMAL_PT_UPDATE 0/* checked '*ptr = val'. ptr is MA. */ -#define MMU_MACHPHYS_UPDATE 1/* ptr = MA of frame to modify entry for */ -#define MMU_PT_UPDATE_PRESERVE_AD 2/* atomically: *ptr = val | (*ptr&(A|D)) */ +#define MMU_NORMAL_PT_UPDATE 0/* checked '*ptr = val'. ptr is MA. */ +#define MMU_MACHPHYS_UPDATE 1/* ptr = MA of frame to modify entry for */ +#define MMU_PT_UPDATE_PRESERVE_AD 2/* atomically: *ptr = val | (*ptr&(A|D)) */ +#define MMU_PT_UPDATE_NO_TRANSLATE 3/* checked '*ptr = val'. prt is MA. */ +/* val never translated. */ /* * MMU EXTENDED OPERATIONS
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v9 07/11] x86/mm: add an extra command to HYPERVISOR_mmu_update...
xen/arch/x86/mm.c void page_unlock(struct page_info *page) · line 1622
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/arch/x86/mm.c +1
-1@@ -1619,9 +1619,10 @@ void page_unlock(struct page_info *page)/* Update the L1 entry at pl1e to new value nl1e. */ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, - unsigned long gl1mfn, int preserve_ad, + unsigned long gl1mfn, int cmd,
unsigned int
With that
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 8/11 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 v9 9/11 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 v9 10/11 common: add a new mappable resource type: XENMEM_resource_grant_table
In reply to Paul DurrantThis patch allows grant table frames to be mapped using the XENMEM_acquire_resource memory op.
---
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]>
v8:
- The functionality was originally incorporated into the earlier patch "x86/mm: add HYPERVISOR_memory_op to acquire guest resources".
--- xen/common/grant_table.c | 32 ++++++++++++++++++++++++++++---- xen/common/memory.c | 30 ++++++++++++++++++++++++++++++ xen/include/public/memory.h | 5 +++++ xen/include/xen/grant_table.h | 1 + 4 files changed, 64 insertions(+), 4 deletions(-)
xen/common/grant_table.c +28 -4
@@ -3756,14 +3756,13 @@ 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) +/* Caller must hold write lock as version may change and table may grow */ +static int gnttab_get_frame_locked (struct domain *d,unsigned long idx, +mfn_t *mfn) {int rc =0 ;struct grant_table *gt = d->grant_table; -grant_write_lock (gt); -if ( gt->gt_version ==0 ) gt->gt_version =1 ;
@@ -3787,6 +3786,19 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, rc = -EINVAL ; } +return rc; +} + +int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn, +mfn_t *mfn) +{ +struct grant_table *gt = d->grant_table; +int rc; + +grant_write_lock (gt); + + rc =gnttab_get_frame_locked (d, idx, mfn); +if ( !rc )gnttab_set_frame_gfn (gt, idx, gfn);
@@ -3795,6 +3807,18 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn,return rc; } +int gnttab_get_frame (struct domain *d,unsigned long idx,mfn_t *mfn) +{ +struct grant_table *gt = d->grant_table; +int rc; + +grant_write_lock (gt);/* write lock is required as table may grow */ + rc =gnttab_get_frame_locked (d, idx, mfn); +grant_write_unlock (gt); + +return rc; +} +static void gnttab_usage_print (struct domain *rd) {int first =1 ;
xen/common/memory.c +30 -0
@@ -23,6 +23,7 @@#include <xen/numa.h> #include <xen/mem_access.h> #include <xen/trace.h> +#include <xen/grant_table.h> #include <asm/current.h> #include <asm/hardirq.h> #include <asm/p2m.h>
@@ -966,6 +967,30 @@ static long xatp_permission_check(struct domain *d, unsigned int space) }#ifdef CONFIG_X86 +static int acquire_grant_table (struct domain *d,unsigned int id, +unsigned long frame, +unsigned long nr_frames, +unsigned long mfn_list[]) +{ +unsigned int i = nr_frames; + +if ( id !=0 ) +return -EINVAL ; + +while ( i-- !=0 ) + { +mfn_t mfn =INVALID_MFN ; +int rc =gnttab_get_frame (d, frame + i, &mfn); + +if ( rc ) +return rc; + + mfn_list[i] =mfn_x (mfn); + } + +return 0 ; +} +static int acquire_resource (const xen_mem_acquire_resource_t *xmar) {struct domain *d, *currd = current->domain;
@@ -993,6 +1018,11 @@ static int acquire_resource(const xen_mem_acquire_resource_t *xmar) xmar->nr_frames, mfn_list);break ; +case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ; +default : rc = -EOPNOTSUPP ;break ;
xen/include/public/memory.h +5 -0
@@ -611,6 +611,7 @@ struct xen_mem_acquire_resource {uint16_t type;#define XENMEM_resource_ioreq_server 0 +#define XENMEM_resource_grant_table 1/* * IN - a type-specific resource identifier, which must be zero
@@ -628,6 +629,10 @@ struct xen_mem_acquire_resource {* page * frame == 1 -> ioreq * page +* type == XENMEM_resource_grant_table -> frame has same semantics +* as idx passed to +* XENMEM_add_to_physmap for +* XENMAPSPACE_grant_table. */ uint64_aligned_t frame;/* IN/OUT - If the tools domain is PV then, upon return, gmfn_list
xen/include/xen/grant_table.h +1 -0
@@ -55,6 +55,7 @@ int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref,int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn,mfn_t *mfn); +int gnttab_get_frame (struct domain *d,unsigned long idx,mfn_t *mfn);unsigned int gnttab_dom0_frames (void );
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, · line 3761
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/grant_table.c +3
-2@@ -3756,14 +3756,13 @@ 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) +/* Caller must hold write lock as version may change and table may grow */ +static int gnttab_get_frame_locked (struct domain *d,unsigned long idx, +mfn_t *mfn)
I don't think this helper function needs to be passed d; gt appears to suffice.
Quoted 21 lines
xen/common/grant_table.c +13
-0@@ -3787,6 +3786,19 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, rc = -EINVAL ; } +return rc; +} + +int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn, +mfn_t *mfn) +{ +struct grant_table *gt = d->grant_table; +int rc; + +grant_write_lock (gt); + + rc =gnttab_get_frame_locked (d, idx, mfn); +if ( !rc )gnttab_set_frame_gfn (gt, idx, gfn);
xen/common/grant_table.c int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, · line 3810
Quoted 4 lines
xen/common/grant_table.c +1
-0@@ -3795,6 +3807,18 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn,return rc; } +int gnttab_get_frame (struct domain *d,unsigned long idx,mfn_t *mfn)
const struct domain * (I realize now that the same should have been done for gnttab_map_frame() when it was introduced; perhaps you could change that at the same time).
xen/common/grant_table.c static long xatp_permission_check(struct domain *d, · line 971
Quoted 6 lines
xen/common/grant_table.c +1
-0@@ -966,6 +967,30 @@ static long xatp_permission_check(struct domain *d, unsigned int space) }#ifdef CONFIG_X86 +static int acquire_grant_table(struct domain *d, unsigned int id,
This clearly isn't x86-specific code.
xen/common/grant_table.c static long xatp_permission_check(struct domain *d, · line 976
Quoted 5 lines
xen/common/grant_table.c +5
-0+unsigned long frame, + unsigned long nr_frames, + unsigned long mfn_list[]) +{ + unsigned int i = nr_frames;
Silent truncation just like in the earlier patch.
xen/common/grant_table.c static long xatp_permission_check(struct domain *d, · line 977
Quoted 1 line
xen/common/grant_table.c +1
-0+if ( id !=0 )
Do we want a constant here again? Also acquiring the status page MFNs via separate ID would seem better than re-using XENMAPIDX_grant_table_status here, the more that this uses bit 31 while right now your interface structure field is still 64 bits wide.
xen/common/grant_table.c static int acquire_resource(const xen_mem_acquire_resource_t *xmar) · line 1024
Quoted 8 lines
xen/common/grant_table.c +4
-0@@ -993,6 +1018,11 @@ static int acquire_resource(const xen_mem_acquire_resource_t *xmar) xmar->nr_frames, mfn_list);break ; +case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ;
Is this really generally useful with mfn_list[] having just two entries?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
Quoted 25 lines
-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 10 October 2017 11:26
To: Paul Durrant <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; KonradRzeszutek Wilk <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Tim (Xen.org) <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH v9 10/11] common: add a new mappable resource type:XENMEM_resource_grant_tablexen/common/grant_table.c int mem_sharing_gref_to_gfn(struct
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.10.17 at 14:25, <[email protected]> wrote:
xen/common/grant_table.c +0
-0@@ -3756,14 +3756,13 @@ 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 6 lines
xen/common/grant_table.c +1
-2}#endif -int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn, -mfn_t *mfn) +/* Caller must hold write lock as version may change and table may grow */
Quoted 5 lines
xen/common/grant_table.c int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, · line 3761
Quoted 2 lines
xen/common/grant_table.c +2
-0+static int gnttab_get_frame_locked (struct domain *d,unsigned long idx, +mfn_t *mfn)I don't think this helper function needs to be passed d; gt appears to suffice.
Alas it does not. It calls through to gnttab_grow_table() which requires the domain.
Quoted 24 lines
xen/common/grant_table.c int gnttab_map_frame(struct domain *d,
Quoted 2 lines
xen/common/grant_table.c +0
-0@@ -3787,6 +3786,19 @@ int gnttab_map_frame(struct domain *d,unsigned long idx,
gfn_tgfn,xen/common/grant_table.c int gnttab_map_frame(struct domain *d,
Quoted 20 lines
xen/common/grant_table.c +13
-0rc = -EINVAL ; } +return rc; +} + +int gnttab_map_frame (struct domain *d,unsigned long idx,gfn_t gfn, +mfn_t *mfn) +{ +struct grant_table *gt = d->grant_table; +int rc; + +grant_write_lock (gt); + + rc =gnttab_get_frame_locked (d, idx, mfn); +if ( !rc )gnttab_set_frame_gfn (gt, idx, gfn);@@ -3795,6 +3807,18 @@ int gnttab_map_frame(struct domain *d,unsigned long idx,
gfn_tgfn,
Quoted 8 lines
xen/common/grant_table.c int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn, · line 3810
Quoted 4 lines
xen/common/grant_table.c +1
-0return rc; } +int gnttab_get_frame (struct domain *d,unsigned long idx,mfn_t *mfn)const struct domain * (I realize now that the same should have been done for
gnttab_map_frame()when it was introduced; perhaps you could change that at the same time).
Again, the problem is that grow_table and functions it calls don't take a const pointer. I tried cascading the const through to the underlying function but the patch started to balloon so I think such work should be deferred.
Quoted 10 lines
xen/common/grant_table.c static long xatp_permission_check(struct domain
Quoted 2 lines
xen/common/grant_table.c +0
-0@@ -966,6 +967,30 @@ static long xatp_permission_check(struct domain*d,
xen/common/grant_table.c static long xatp_permission_check(struct domain · line 971
Quoted 5 lines
xen/common/grant_table.c +1
-0unsigned int space) }#ifdef CONFIG_X86 +static int acquire_grant_table(struct domain *d, unsigned int id,This clearly isn't x86-specific code.
Ok.
Quoted 8 lines
xen/common/grant_table.c static long xatp_permission_check(struct domain · line 976
Quoted 6 lines
xen/common/grant_table.c +5
-0+unsigned long frame, + unsigned long nr_frames, + unsigned long mfn_list[]) +{ + unsigned int i = nr_frames;Silent truncation just like in the earlier patch.
Yes, nr_frames should be an unsigned int.
Quoted 8 lines
xen/common/grant_table.c static long xatp_permission_check(struct domain · line 977
Quoted 2 lines
xen/common/grant_table.c +1
-0+if ( id !=0 )Do we want a constant here again? Also acquiring the status page MFNs via separate ID would seem better than re-using
XENMAPIDX_grant_table_statushere, the more that this uses bit 31 while right now your interface structure field is still 64 bits wide.
Ok, that's a better way to do it.
Quoted 5 lines
xen/common/grant_table.c static int acquire_resource(const
Quoted 1 line
xen/common/grant_table.c +0
-0@@ -993,6 +1018,11 @@ static int acquire_resource(const
xen_mem_acquire_resource_t*xmar)Quoted 3 lines
xen/common/grant_table.c +0
-0xmar->nr_frames, mfn_list);break ;
Quoted 7 lines
xen/common/grant_table.c static int acquire_resource(const · line 1024
Quoted 4 lines
xen/common/grant_table.c +4
-0+case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ;Is this really generally useful with mfn_list[] having just two entries?
Good point. I'll increase the size of the array in this patch (to the default table size of 32... I think that's a reasonable value to choose).
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 v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
Quoted 8 lines
Quoted 8 lines
Review int gnttab_map_frame(struct domain *d,
Quoted 2 lines · On 10.10.17 at 18:01, <[email protected]> wrote:
(quoted diff) +0
-0@@ -3795,6 +3807,18 @@ int gnttab_map_frame(struct domain *d,unsigned long idx,
gfn_tgfn,Quoted 4 lines
xen/common/grant_table.c +1
-0return rc; } +int gnttab_get_frame (struct domain *d,unsigned long idx,mfn_t *mfn)
Quoted 7 lines
Quoted 3 lines
const struct domain * (I realize now that the same should have been done for
gnttab_map_frame()when it was introduced; perhaps you could change that at the same time).Again, the problem is that
grow_tableand functions it calls don't take a const pointer. I tried cascading the const through to the underlying function but the patch started to balloon so I think such work should be deferred.
Right, I had overlooked that. And it won't work, as share_xen_page_with_guest() can't be passed a const pointer.
Quoted 10 lines
Quoted 10 lines
Review static int acquire_resource(const
Quoted 1 line
(quoted diff) +0
-0@@ -993,6 +1018,11 @@ static int acquire_resource(const
xen_mem_acquire_resource_t*xmar)Quoted 7 lines
xen/common/memory.c +4
-0xmar->nr_frames, mfn_list);break ; +case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ;
Quoted 5 lines
Quoted 2 lines
Is this really generally useful with mfn_list[] having just two entries?
Good point. I'll increase the size of the array in this patch (to the default table size of 32... I think that's a reasonable value to choose).
I suppose for the only current use you have for this (seeding the grant table from the tool stack) even the two entries you have right now would suffice. If, however, a full grant table is supposed to be accessible this way, I can't see how a static upper limit will do. Or if you intend the caller to do multiple invocations in such a case, there ought to be a way to find out the (implementation) limit.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
Quoted 48 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 11 October 2017 09:47
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]; KonradRzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: RE: [Xen-devel] [PATCH v9 10/11] common: add a new mappable resource type:XENMEM_resource_grant_tableQuoted 7 lines
Quoted 7 lines
Review int gnttab_map_frame(struct domain *d,
Quoted 2 lines · On 10.10.17 at 18:01, <[email protected]> wrote:
(quoted diff) +0
-0@@ -3795,6 +3807,18 @@ int gnttab_map_frame(struct domain *d,unsigned long idx,
gfn_tgfn,Quoted 4 lines
xen/common/grant_table.c +1
-0return rc; } +int gnttab_get_frame(struct domain *d, unsigned long idx, mfn_t*mfn)
Quoted 8 lines
Quoted 4 lines
const struct domain * (I realize now that the same should have been done for
gnttab_map_frame()when it was introduced; perhaps you could change that at the same time).Again, the problem is that
grow_tableand functions it calls don't take a const pointer. I tried cascading the const through to the underlying function but the patch started to balloon so I think such work should be deferred.Right, I had overlooked that. And it won't work, as
share_xen_page_with_guest()can't be passed a const pointer.Quoted 10 lines
Quoted 10 lines
Review static int acquire_resource(const
Quoted 1 line
(quoted diff) +0
-0@@ -993,6 +1018,11 @@ static int acquire_resource(const
xen_mem_acquire_resource_t*xmar)Quoted 7 lines
xen/common/memory.c +4
-0xmar->nr_frames, mfn_list);break ; +case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ;Quoted 5 lines
Quoted 2 lines
Is this really generally useful with mfn_list[] having just two entries?
Good point. I'll increase the size of the array in this patch (to the default table size of 32... I think that's a reasonable value to choose).
Quoted 6 lines
I suppose for the only current use you have for this (seeding the grant table from the tool stack) even the two entries you have right now would suffice. If, however, a full grant table is supposed to be accessible this way, I can't see how a static upper limit will do. Or if you intend the caller to do multiple invocations in such a case, there ought to be a way to find out the (implementation) limit.
I'm open to ideas but there clearly needs to be some sort of upper limit, or we do away with being able to map multiple frames in a single invocation. The dm_op hypercalls currently have a similar upper limit on the size of the buffer array. I'd rather not have to introduce another hypercall just to find out such a thing. It's a tools-only hypercall so could I not just add a comment on what the limit currently is?
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
Quoted 27 lines
Quoted 20 lines
Quoted 1 line · On 11.10.17 at 10:54, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 11 October 2017 09:47Quoted 11 lines
Quoted 11 lines
Review static int acquire_resource(const
Quoted 2 lines · On 10.10.17 at 18:01, <[email protected]> wrote:
(quoted diff) +0
-0@@ -993,6 +1018,11 @@ static int acquire_resource(const
xen_mem_acquire_resource_t*xmar)Quoted 7 lines
xen/common/memory.c +4
-0xmar->nr_frames, mfn_list);break ; +case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ;Quoted 5 lines
Quoted 2 lines
Is this really generally useful with mfn_list[] having just two entries?
Good point. I'll increase the size of the array in this patch (to the default table size of 32... I think that's a reasonable value to choose).
Quoted 6 lines
I suppose for the only current use you have for this (seeding the grant table from the tool stack) even the two entries you have right now would suffice. If, however, a full grant table is supposed to be accessible this way, I can't see how a static upper limit will do. Or if you intend the caller to do multiple invocations in such a case, there ought to be a way to find out the (implementation) limit.
Quoted 6 lines
I'm open to ideas but there clearly needs to be some sort of upper limit, or we do away with being able to map multiple frames in a single invocation. The
dm_ophypercalls currently have a similar upper limit on the size of the buffer array. I'd rather not have to introduce another hypercall just to find out such a thing. It's a tools-only hypercall so could I not just add a comment on what the limit currently is?
Hmm, that would be an option, but I'd prefer if we could get away without. And no, I wasn't suggesting to introduce yet another hypercall. Instead how about the handle being a null one asking for the implementation limit to be returned in nr_frames (or, to keep that IN only, in the re-purposed pad field)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
Quoted 49 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 11 October 2017 10:43
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]; KonradRzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: RE: [Xen-devel] [PATCH v9 10/11] common: add a new mappable resource type:XENMEM_resource_grant_tableQuoted 27 lines
Quoted 20 lines
Quoted 1 line · On 11.10.17 at 10:54, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 11 October 2017 09:47Quoted 11 lines
Quoted 11 lines
Review static int acquire_resource(const
Quoted 2 lines · On 10.10.17 at 18:01, <[email protected]> wrote:
(quoted diff) +0
-0@@ -993,6 +1018,11 @@ static int acquire_resource(const
xen_mem_acquire_resource_t*xmar)Quoted 7 lines
xen/common/memory.c +4
-0xmar->nr_frames, mfn_list);break ; +case XENMEM_resource_grant_table: + rc =acquire_grant_table (d, xmar->id, xmar->frame, + xmar->nr_frames, mfn_list); +break ;Quoted 5 lines
Quoted 2 lines
Is this really generally useful with mfn_list[] having just two entries?
Good point. I'll increase the size of the array in this patch (to the default table size of 32... I think that's a reasonable value to choose).
Quoted 6 lines
I suppose for the only current use you have for this (seeding the grant table from the tool stack) even the two entries you have right now would suffice. If, however, a full grant table is supposed to be accessible this way, I can't see how a static upper limit will do. Or if you intend the caller to do multiple invocations in such a case, there ought to be a way to find out the (implementation) limit.
Quoted 2 lines
I'm open to ideas but there clearly needs to be some sort of upper limit, or we do away with being able to map multiple frames in a single invocation.
The
Quoted 4 lines
dm_ophypercalls currently have a similar upper limit on the size of the buffer array. I'd rather not have to introduce another hypercall just to find out such a thing. It's a tools-only hypercall so could I not just add a comment on what the limit currently is?
Quoted 6 lines
Hmm, that would be an option, but I'd prefer if we could get away without. And no, I wasn't suggesting to introduce yet another hypercall. Instead how about the handle being a null one asking for the implementation limit to be returned in
nr_frames(or, to keep that IN only, in the re-purposed pad field)?
Ok, I'll make nr_frames IN/OUT. I guess I could define it to be set to the implementation limit if the hypercall returns -E2BIG.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v9 10/11] common: add a new mappable resource type: XENMEM_resource_grant_table
Quoted 10 lines
Quoted 9 lines
Quoted 1 line · On 11.10.17 at 11:54, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 11 October 2017 10:43
Hmm, that would be an option, but I'd prefer if we could get away without. And no, I wasn't suggesting to introduce yet another hypercall. Instead how about the handle being a null one asking for the implementation limit to be returned innr_frames(or, to keep that IN only, in the re-purposed pad field)?
Quoted 2 lines
Ok, I'll make
nr_framesIN/OUT. I guess I could define it to be set to the implementation limit if the hypercall returns-E2BIG.
Sure, but please don't make this the _only_ way to find out the limit.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v9 11/11 tools/libxenctrl: use new xenforeignmemory API to seed grant table
In reply to Paul DurrantA 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
@@ -325,12 +325,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
@@ -903,7 +903,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