libs/xg: allow caller to provide extra memflags for populate physmap
PATCH 1/1 libs/xg: allow caller to provide extra memflags for populate physmap
Introduce an additional memflags field to the xc_dom_image and xc_sr_context structures and use it to pass additional memflags to use when populating the domain physmap.
No meaningful usages of this new field are added as part of the patch. The only know usage will be from the XAPI domain builder, which lives in a different repository.
--- tools/include/xenguest.h | 8 +++++++- tools/libs/guest/xg_dom_x86.c | 13 ++++++++----- tools/libs/guest/xg_nomigrate.c | 3 ++- tools/libs/guest/xg_sr_common.h | 3 +++ tools/libs/guest/xg_sr_restore.c | 9 ++++++--- tools/libs/light/libxl_save_helper.c | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-)
tools/include/xenguest.h +7 -1
@@ -242,6 +242,9 @@ struct xc_dom_image {/* Number of vCPUs */ unsigned int max_vcpus; + +/* Caller provided memflags to use when populating physmap. */ +unsigned int memflags; };/* --- arch specific hooks ----------------------------------------- */
@@ -611,6 +614,8 @@ struct restore_callbacks {* specific data * @param send_back_fd Only used for XC_STREAM_COLO. Contains backchannel to * the source side. +* @param memflags Optional memflags to pass in +* xc_domain_populate_physmap{_exact}() calls. * @return 0 on success, -1 on failure */ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
@@ -618,7 +623,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, uint32_t store_domid, unsigned int console_evtchn, unsigned long *console_mfn, uint32_t console_domid, xc_stream_type_t stream_type, - struct restore_callbacks *callbacks, int send_back_fd); + struct restore_callbacks *callbacks, int send_back_fd, + unsigned int memflags);/** * This function will create a domain for a paravirtualized Linux
tools/libs/guest/xg_dom_x86.c +8 -5
@@ -1260,14 +1260,15 @@ static int meminit_pv(struct xc_dom_image *dom)/* allocate guest memory */ for ( i =0 ; i < nr_vmemranges; i++ ) { -unsigned int memflags; +unsigned int memflags = dom->memflags;uint64_t pages, super_pages;unsigned int pnode = vnode_to_pnode[vmemranges[i].nid];xen_pfn_t extents[SUPERPAGE_BATCH_SIZE ];xen_pfn_t pfn_base_idx; - memflags =0 ; -if ( pnode !=XC_NUMA_NO_NODE ) +if ( pnode !=XC_NUMA_NO_NODE && +/* Only set the node if the caller hasn't done so. */ +XENMEMF_get_node (memflags) ==0xFFU ) memflags |=XENMEMF_exact_node (pnode); pages = (vmemranges[i].end - vmemranges[i].start) >>PAGE_SHIFT ;
@@ -1354,7 +1355,7 @@ static int meminit_hvm(struct xc_dom_image *dom)int rc;unsigned long stat_normal_pages =0 , stat_2mb_pages =0 , stat_1gb_pages =0 ; -unsigned int memflags =0 ; +unsigned int memflags = dom->memflags;int claim_enabled = dom->claim_enabled;uint64_t total_pages;xen_vmemrange_t dummy_vmemrange[2 ];
@@ -1500,7 +1501,9 @@ static int meminit_hvm(struct xc_dom_image *dom)unsigned int vnode = vmemranges[vmemid].nid;unsigned int pnode = vnode_to_pnode[vnode]; -if ( pnode !=XC_NUMA_NO_NODE ) +if ( pnode !=XC_NUMA_NO_NODE && +/* Only set the node if the caller hasn't done so. */ +XENMEMF_get_node (new_memflags) ==0xFFU ) new_memflags |=XENMEMF_exact_node (pnode); end_pages = vmemranges[vmemid].end >>PAGE_SHIFT ;
tools/libs/guest/xg_nomigrate.c +2 -1
@@ -33,7 +33,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, uint32_t store_domid, unsigned int console_evtchn, unsigned long *console_mfn, uint32_t console_domid, xc_stream_type_t stream_type, - struct restore_callbacks *callbacks, int send_back_fd) + struct restore_callbacks *callbacks, int send_back_fd, + unsigned int memflags) { errno =ENOSYS ;return -1 ;
tools/libs/guest/xg_sr_common.h +3 -0
@@ -295,6 +295,9 @@ struct xc_sr_context/* Sender has invoked verify mode on the stream. */ bool verify; + +/* memflags to pass to xc_domain_populate_physmap{_exact}(). */ +unsigned int memflags; } restore; };
tools/libs/guest/xg_sr_restore.c +6 -3
@@ -141,7 +141,8 @@ static bool populate_small_superpage(struct xc_sr_context *ctx, xen_pfn_t gfn)xen_pfn_t mfn = gfn;if (xc_domain_populate_physmap_exact ( - ctx->xch, ctx->domid,1 ,SMALL_SUPERPAGE_ORDER ,0 , &mfn) ) + ctx->xch, ctx->domid,1 ,SMALL_SUPERPAGE_ORDER , ctx->restore.memflags, + &mfn) )return false;/*
@@ -217,7 +218,7 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned int count,if ( nr_pfns ) { rc =xc_domain_populate_physmap_exact ( - xch, ctx->domid, nr_pfns,0 ,0 , mfns); + xch, ctx->domid, nr_pfns,0 , ctx->restore.memflags, mfns);if ( rc ) {PERROR ("Failed to populate physmap" );
@@ -901,7 +902,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, uint32_t store_domid, unsigned int console_evtchn, unsigned long *console_gfn, uint32_t console_domid, xc_stream_type_t stream_type, - struct restore_callbacks *callbacks, int send_back_fd) + struct restore_callbacks *callbacks, int send_back_fd, + unsigned int memflags) { bool hvm;xen_pfn_t nr_pfns;
@@ -918,6 +920,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, ctx.restore.xenstore_domid = store_domid; ctx.restore.callbacks = callbacks; ctx.restore.send_back_fd = send_back_fd; + ctx.restore.memflags = memflags;/* Sanity check stream_type-related parameters */ switch ( stream_type )
tools/libs/light/libxl_save_helper.c +1 -1
@@ -285,7 +285,7 @@ int main(int argc, char **argv) r =xc_domain_restore (xch, io_fd, dom, store_evtchn, &store_mfn, store_domid, console_evtchn, &console_mfn, - console_domid, stream_type, &cb, send_back_fd); + console_domid, stream_type, &cb, send_back_fd,0 );helper_stub_restore_results (store_mfn,console_mfn,0 );complete (r);
Signature · 1 line
2.51.0
Quoted 9 lines · Roger Pau Monne
tools/libs/guest/xg_dom_x86.c +1
-1@@ -1260,14 +1260,15 @@ static int meminit_pv(struct xc_dom_image *dom)/* allocate guest memory */ for ( i =0 ; i < nr_vmemranges; i++ ) { -unsigned int memflags; +unsigned int memflags = dom->memflags;uint64_t pages, super_pages;
tools/libs/guest/xg_dom_x86.c static int meminit_pv(struct xc_dom_image *dom) · line 1272
Quoted 10 lines
tools/libs/guest/xg_dom_x86.c +3
-2unsigned int pnode = vnode_to_pnode[vmemranges[i].nid];xen_pfn_t extents[SUPERPAGE_BATCH_SIZE ];xen_pfn_t pfn_base_idx; - memflags =0 ; -if ( pnode !=XC_NUMA_NO_NODE ) +if ( pnode !=XC_NUMA_NO_NODE && +/* Only set the node if the caller hasn't done so. */ +XENMEMF_get_node (memflags) ==0xFFU ) memflags |=XENMEMF_exact_node (pnode);
I'd like to suggest to avoid open-coding the 0xff here and elsewhere. XENMEMF_get_node(0) will be less fragile overall, imo.
Jan
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monne
tools/libs/guest/xg_dom_x86.c +1
-1@@ -1260,14 +1260,15 @@ static int meminit_pv(struct xc_dom_image *dom)/* allocate guest memory */ for ( i =0 ; i < nr_vmemranges; i++ ) { -unsigned int memflags; +unsigned int memflags = dom->memflags;uint64_t pages, super_pages;unsigned int pnode = vnode_to_pnode[vmemranges[i].nid];xen_pfn_t extents[SUPERPAGE_BATCH_SIZE ];xen_pfn_t pfn_base_idx;
Quoted 8 lines
tools/libs/guest/xg_dom_x86.c static int meminit_pv(struct xc_dom_image *dom) · line 1272
Quoted 6 lines
tools/libs/guest/xg_dom_x86.c +3
-2- memflags =0 ; -if ( pnode !=XC_NUMA_NO_NODE ) +if ( pnode !=XC_NUMA_NO_NODE && +/* Only set the node if the caller hasn't done so. */ +XENMEMF_get_node (memflags) ==0xFFU ) memflags |=XENMEMF_exact_node (pnode);I'd like to suggest to avoid open-coding the
0xffhere and elsewhere.XENMEMF_get_node(0)will be less fragile overall, imo.
XENMEMF_get_node(0) is even more meaningless than 0xFF, which is at least obviously a sentinel value.
~Andrew
Quoted 24 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monne
tools/libs/guest/xg_dom_x86.c +1
-1@@ -1260,14 +1260,15 @@ static int meminit_pv(struct xc_dom_image *dom)/* allocate guest memory */ for ( i =0 ; i < nr_vmemranges; i++ ) { -unsigned int memflags; +unsigned int memflags = dom->memflags;uint64_t pages, super_pages;unsigned int pnode = vnode_to_pnode[vmemranges[i].nid];xen_pfn_t extents[SUPERPAGE_BATCH_SIZE ];xen_pfn_t pfn_base_idx;Quoted 8 lines
tools/libs/guest/xg_dom_x86.c static int meminit_pv(struct xc_dom_image *dom) · line 1272
Quoted 6 lines
tools/libs/guest/xg_dom_x86.c +3
-2- memflags =0 ; -if ( pnode !=XC_NUMA_NO_NODE ) +if ( pnode !=XC_NUMA_NO_NODE && +/* Only set the node if the caller hasn't done so. */ +XENMEMF_get_node (memflags) ==0xFFU ) memflags |=XENMEMF_exact_node (pnode);I'd like to suggest to avoid open-coding the
0xffhere and elsewhere.XENMEMF_get_node(0)will be less fragile overall, imo.
Quoted 2 lines
XENMEMF_get_node(0)is even more meaningless than0xFF, which is at least obviously a sentinel value.
How that? XENMEMF_get_node(0) is the node that is used when no flags (0) were specified. I.e. the equivalent of NUMA_NO_NODE. The underlying (pretty abstract) point being that if we ever made a binary-incompatible, but source-compatible change to how wide the node representation is in the flags (e.g. by the consumer defining some manifest constant to engage the alternate behavior), XENMEMF_get_node(0) will continue to work while 0xFF won't.
Otherwise at the very least I would strongly suggest libxg to make itself a #define for this (repeatedly used) 0xFFU.
Jan
Quoted 28 lines · Jan Beulich
Quoted 24 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monne
tools/libs/guest/xg_dom_x86.c +1
-1@@ -1260,14 +1260,15 @@ static int meminit_pv(struct xc_dom_image *dom)/* allocate guest memory */ for ( i =0 ; i < nr_vmemranges; i++ ) { -unsigned int memflags; +unsigned int memflags = dom->memflags;uint64_t pages, super_pages;unsigned int pnode = vnode_to_pnode[vmemranges[i].nid];xen_pfn_t extents[SUPERPAGE_BATCH_SIZE ];xen_pfn_t pfn_base_idx;Quoted 8 lines
tools/libs/guest/xg_dom_x86.c static int meminit_pv(struct xc_dom_image *dom) · line 1272
Quoted 6 lines
tools/libs/guest/xg_dom_x86.c +3
-2- memflags =0 ; -if ( pnode !=XC_NUMA_NO_NODE ) +if ( pnode !=XC_NUMA_NO_NODE && +/* Only set the node if the caller hasn't done so. */ +XENMEMF_get_node (memflags) ==0xFFU ) memflags |=XENMEMF_exact_node (pnode);I'd like to suggest to avoid open-coding the
0xffhere and elsewhere.XENMEMF_get_node(0)will be less fragile overall, imo.Quoted 2 lines
XENMEMF_get_node(0)is even more meaningless than0xFF, which is at least obviously a sentinel value.
Quoted 7 lines
How that?
XENMEMF_get_node(0)is the node that is used when no flags (0) were specified. I.e. the equivalent ofNUMA_NO_NODE. The underlying (pretty abstract) point being that if we ever made a binary-incompatible, but source-compatible change to how wide the node representation is in the flags (e.g. by the consumer defining some manifest constant to engage the alternate behavior),XENMEMF_get_node(0)will continue to work while0xFFwon't.
I didn't use XENMEMF_get_node(0) because I found it confusing to read. When I read that construct I internally associate with node 0, while it's actually no node set, as the value passed to XENMEMF_get_node() is the memflags, not a node ID.
Quoted 2 lines
Otherwise at the very least I would strongly suggest libxg to make itself a #define for this (repeatedly used)
0xFFU.
I didn't want to introduce that because there's already a define in libxc for no NUMA node ID, which is wider than 0xff.
Anyway, will do the change and send v2.
Thanks, Roger.