Tmem cleanups/improvements for v4.8.
PATCH v2 1/1 Tmem cleanups/improvements for v4.8.
Hey!
Since v1: [https://lists.xen.org/archives/html/xen-devel/2016-09/msg03035.html]
- Squashes some patches
- Added Wei's Acked-by
- Reworked some patches.
This batch of fixes slowly marches toward ripping out pieces of code in tmem that are hard to maintain and improve on code that was orginacally developed.
I had hoped that I would have had the migration support all working, but it took longer than I thought to get to this point. And it may have become a giant series too.
Anyhow please take a peek at the patches. The first couple of them should be fairly easy. The rest are more of squashing various subcommands in one.
Thanks!
The git tree with these patches is:
git://xenbits.xen.org/people/konradwilk/xen.git tmem.v4.8.v2
docs/man/xl.pod.1.in | 4 - docs/misc/xen-command-line.markdown | 6 - tools/libxc/include/xenctrl.h | 4 +- tools/libxc/xc_tmem.c | 272 ++++++++++++------------- tools/libxl/libxl.c | 30 ++- tools/libxl/xl_cmdtable.c | 1 - tools/python/xen/lowlevel/xc/xc.c | 19 +- xen/common/tmem.c | 386 ++++-------------------------------- xen/common/tmem_control.c | 211 +++++++++++--------- xen/common/tmem_xen.c | 28 --- xen/include/public/sysctl.h | 76 +++++-- xen/include/xen/tmem_xen.h | 121 +---------- 12 files changed, 388 insertions(+), 770 deletions(-)
382 lines of code deleted!!! WOOHOO
Konrad Rzeszutek Wilk (9):
libxc/tmem/restore: Remove call to XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION
tmem: Retire XEN_SYSCTL_TMEM_OP_[SET_CAP|SAVE_GET_CLIENT_CAP]
tmem: Delete deduplication (and tze) code.
tmem: Move client weight, frozen, live_migrating, and compress tmem/sysctl: Add union in struct xen_sysctl_tmem_op tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]..
tmem: Unify XEN_SYSCTL_TMEM_OP_[[SAVE_[BEGIN|END]|RESTORE_BEGIN] tmem/xc_tmem_control: Rename 'arg1' to 'len' and 'arg2' to arg.
tmem: Batch and squash XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_[FLAGS,NPAGES,UUID] in one sub-call: XEN_SYSCTL_TMEM_OP_GET_POOLS.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 1/9 libxc/tmem/restore: Remove call to XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION
The only thing this hypercall returns is TMEM_SPEC_VERSION.
The comment around is also misleading - this call does not do any domain operation.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: Initial submission.
v2: Added Wei's Ack.
--- tools/libxc/xc_tmem.c | 4 ---- 1 file changed, 4 deletions(-)
tools/libxc/xc_tmem.c +0 -4
@@ -381,16 +381,12 @@ static int xc_tmem_restore_new_pool(int xc_tmem_restore (xc_interface *xch,int dom,int io_fd) { -uint32_t save_version;uint32_t this_max_pools, this_version;uint32_t pool_id;uint32_t minusone;uint32_t weight, cap, flags;int checksum =0 ; - save_version =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION ,dom,0 ,0 ,NULL ); -if ( save_version ==-1 ) -return -1 ;/* domain doesn't exist */ if (read_exact (io_fd, &this_version,sizeof (this_version)) )return -1 ;if (read_exact (io_fd, &this_max_pools,sizeof (this_max_pools)) )
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 2/9 tmem: Retire XEN_SYSCTL_TMEM_OP_[SET_CAP|SAVE_GET_CLIENT_CAP]
In reply to Konrad Rzeszutek WilkIt is not used by anything. Its intent was to complement the 'weight' attribute but there hadn't been any request for this.
If there is a need to resurface it, it can be integrated back via the XEN_SYSCTL_TMEM_SET_CLIENT_INFO introduced in "tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE].."
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: First submission
v2: Added Wei's Ack.
Deleted ->cap from 'struct client' --- docs/man/xl.pod.1.in | 4 ---- tools/libxc/xc_tmem.c | 13 +++---------- tools/libxl/libxl.c | 4 +--- tools/libxl/xl_cmdtable.c | 1 - tools/python/xen/lowlevel/xc/xc.c | 1 - xen/common/tmem_control.c | 16 ++-------------- xen/include/public/sysctl.h | 2 -- xen/include/xen/tmem_xen.h | 1 - 8 files changed, 6 insertions(+), 36 deletions(-)
docs/man/xl.pod.1.in +0 -4
@@ -1589,10 +1589,6 @@ B<OPTIONS> Weight (int) -=item B<-c> I<CAP> - -Cap (int) - =item B<-p> I<COMPRESS> Compress (int)
tools/libxc/xc_tmem.c +3 -10
@@ -212,7 +212,7 @@ int xc_tmem_save(xc_interface *xch,int marker = field_marker;int i, j;uint32_t max_pools, version; -uint32_t weight, cap, flags; +uint32_t weight, flags;uint32_t pool_id;uint32_t minusone =-1 ;struct tmem_handle *h;
@@ -238,10 +238,7 @@ int xc_tmem_save(xc_interface *xch, weight =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT ,dom,0 ,0 ,NULL );if (write_exact (io_fd, &weight,sizeof (weight)) )return -1 ; - cap =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_CAP ,dom,0 ,0 ,NULL ); -if (write_exact (io_fd, &cap,sizeof (cap)) ) -return -1 ; -if ( flags ==-1 || weight ==-1 || cap ==-1 ) +if ( flags ==-1 || weight ==-1 )return -1 ;if (write_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ;
@@ -384,7 +381,7 @@ int xc_tmem_restore(xc_interface *xch, int dom, int io_fd)uint32_t this_max_pools, this_version;uint32_t pool_id;uint32_t minusone; -uint32_t weight, cap, flags; +uint32_t weight, flags;int checksum =0 ;if (read_exact (io_fd, &this_version,sizeof (this_version)) )
@@ -410,10 +407,6 @@ int xc_tmem_restore(xc_interface *xch, int dom, int io_fd)return -1 ;if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SET_WEIGHT ,dom,0 ,0 ,NULL ) <0 )return -1 ; -if (read_exact (io_fd, &cap,sizeof (cap)) ) -return -1 ; -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SET_CAP ,dom,0 ,0 ,NULL ) <0 ) -return -1 ;if (read_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ;while (read_exact (io_fd, &pool_id,sizeof (pool_id)) ==0 && pool_id !=-1 )
tools/libxl/libxl.c +1 -3
@@ -6156,8 +6156,6 @@ static int32_t tmem_setop_from_string(char *set_name) {if (!strcmp (set_name,"weight" ))return XEN_SYSCTL_TMEM_OP_SET_WEIGHT ; -else if (!strcmp (set_name,"cap" )) -return XEN_SYSCTL_TMEM_OP_SET_CAP ;else if (!strcmp (set_name,"compress" ))return XEN_SYSCTL_TMEM_OP_SET_COMPRESS ;else
@@ -6171,7 +6169,7 @@ int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set)GC_INIT (ctx);if (subop ==-1 ) { -LOGEV (ERROR ,-1 ,"Invalid set, valid sets are <weight|cap|compress>" ); +LOGEV (ERROR ,-1 ,"Invalid set, valid sets are <weight|compress>" ); rc =ERROR_INVAL ; goto out; }
tools/libxl/xl_cmdtable.c +0 -1
@@ -407,7 +407,6 @@ struct cmd_spec cmd_table[] = {"[<Domain>|-a] [-w[=WEIGHT]|-c[=CAP]|-p[=COMPRESS]]" ," -a Operate on all tmem\n" " -w WEIGHT Weight (int)\n" -" -c CAP Cap (int)\n" " -p COMPRESS Compress (int)" , }, { "tmem-shared-auth",
tools/python/xen/lowlevel/xc/xc.c +0 -1
@@ -1641,7 +1641,6 @@ static PyObject *pyxc_tmem_control(XcObject *self,case XEN_SYSCTL_TMEM_OP_FREEZE :case XEN_SYSCTL_TMEM_OP_DESTROY :case XEN_SYSCTL_TMEM_OP_SET_WEIGHT : -case XEN_SYSCTL_TMEM_OP_SET_CAP :case XEN_SYSCTL_TMEM_OP_SET_COMPRESS :default :break ;
xen/common/tmem_control.c +2 -14
@@ -103,9 +103,9 @@ static int tmemc_list_client(struct client *c, tmem_cli_va_param_t buf,struct tmem_pool *p;bool_t s; - n =scnprintf (info,BSIZE ,"C=CI:%d,ww:%d,ca:%d,co:%d,fr:%d," + n =scnprintf (info,BSIZE ,"C=CI:%d,ww:%d,co:%d,fr:%d," "Tc:%" PRIu64",Ge:%ld,Pp:%ld,Gp:%ld%c" , - c->cli_id, c->weight, c->cap, c->compress, c->frozen, + c->cli_id, c->weight, c->compress, c->frozen, c->total_cycles, c->succ_eph_gets, c->succ_pers_puts, c->succ_pers_gets, use_long ?',' :'\n' );if (use_long)
@@ -273,11 +273,6 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, uint32_t arg1)atomic_sub (old_weight,&tmem_global.client_weight_total);atomic_add (client->weight,&tmem_global.client_weight_total);break ; -case XEN_SYSCTL_TMEM_OP_SET_CAP : - client->cap = arg1; -tmem_client_info ("tmem: cap set to %d for %s=%d\n" , - arg1, tmem_cli_id_str, cli_id); -break ;case XEN_SYSCTL_TMEM_OP_SET_COMPRESS :if (tmem_dedup_enabled () ) {
@@ -341,11 +336,6 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id,break ; rc = client->weight ==-1 ?-2 : client->weight;break ; -case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_CAP : -if ( client ==NULL ) -break ; - rc = client->cap ==-1 ?-2 : client->cap; -break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS :if ( client ==NULL )break ;
@@ -404,7 +394,6 @@ int tmem_control(struct xen_sysctl_tmem_op *op) guest_handle_cast(op->buf, char), op->arg1, op->arg2);break ;case XEN_SYSCTL_TMEM_OP_SET_WEIGHT : -case XEN_SYSCTL_TMEM_OP_SET_CAP :case XEN_SYSCTL_TMEM_OP_SET_COMPRESS : ret =tmemc_set_var (op->cli_id, cmd, op->arg1);break ;
@@ -414,7 +403,6 @@ int tmem_control(struct xen_sysctl_tmem_op *op)case XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION :case XEN_SYSCTL_TMEM_OP_SAVE_GET_MAXPOOLS :case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT : -case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_CAP :case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS :case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS :case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES :
xen/include/public/sysctl.h +0 -2
@@ -768,14 +768,12 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_psr_cat_op_t);#define XEN_SYSCTL_TMEM_OP_DESTROY 3#define XEN_SYSCTL_TMEM_OP_LIST 4#define XEN_SYSCTL_TMEM_OP_SET_WEIGHT 5 -#define XEN_SYSCTL_TMEM_OP_SET_CAP 6#define XEN_SYSCTL_TMEM_OP_SET_COMPRESS 7#define XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB 8#define XEN_SYSCTL_TMEM_OP_SAVE_BEGIN 10#define XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION 11#define XEN_SYSCTL_TMEM_OP_SAVE_GET_MAXPOOLS 12#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT 13 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_CAP 14#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS 15#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS 16#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES 17
xen/include/xen/tmem_xen.h +0 -1
@@ -409,7 +409,6 @@ struct client {long eph_count, eph_count_max;domid_t cli_id;uint32_t weight; -uint32_t cap;bool_t compress;bool_t frozen;bool_t shared_auth_required;
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 3/9 tmem: Delete deduplication (and tze) code.
In reply to Konrad Rzeszutek WilkCouple of reasons:
- It can lead to security issues (see row-hammer, KSM and such attacks).
- Code is quite complex.
- Deduplication is good if the pages themselves are the same but that is hardly guaranteed.
- We got some gains (if pages are deduped) but at the cost of making code less maintainable.
- tze depends on deduplication code.
As such, deleting it.
---
v1: First submission.
v2: Squash " tmem: Wrap tmem dedup code with CONFIG_TMEM_DEDUP"
and "tmem: Wrap tmem tze code with CONFIG_TMEM_TZE"
--- docs/misc/xen-command-line.markdown | 6 - xen/common/tmem.c | 310 +----------------------------------- xen/common/tmem_control.c | 7 - xen/common/tmem_xen.c | 28 ---- xen/include/xen/tmem_xen.h | 115 ------------- 5 files changed, 3 insertions(+), 463 deletions(-)
docs/misc/xen-command-line.markdown +0 -6
@@ -1500,15 +1500,9 @@ pages) must also be specified via the tbuf\_size parameter. ### tmem\_compress > `= <boolean>` -### tmem\_dedup -> `= <boolean>` - ### tmem\_shared\_auth > `= <boolean>` -### tmem\_tze -> `= <integer>` - ### tsc > `= unstable | skewed | stable:socket`
xen/common/tmem.c +3 -307
407 lines not on this page · raw message
xen/common/tmem_control.c +0 -7
@@ -274,13 +274,6 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, uint32_t arg1)atomic_add (client->weight,&tmem_global.client_weight_total);break ;case XEN_SYSCTL_TMEM_OP_SET_COMPRESS : -if (tmem_dedup_enabled () ) - { -tmem_client_warn ("tmem: compression %s for all %ss, cannot be changed when tmem_dedup is enabled\n" , -tmem_compression_enabled () ?"enabled" :"disabled" , - tmem_client_str); -return -1 ; - } client->compress = arg1 ?1 :0 ;tmem_client_info ("tmem: compression %s for %s=%d\n" , arg1 ?"enabled" :"disabled" ,tmem_cli_id_str,cli_id);
xen/common/tmem_xen.c +0 -28
@@ -20,12 +20,6 @@ boolean_param("tmem", opt_tmem);bool_t __read_mostly opt_tmem_compress =0 ;boolean_param ("tmem_compress" , opt_tmem_compress); -bool_t __read_mostly opt_tmem_dedup =0 ; -boolean_param ("tmem_dedup" , opt_tmem_dedup); - -bool_t __read_mostly opt_tmem_tze =0 ; -boolean_param ("tmem_tze" , opt_tmem_tze); -bool_t __read_mostly opt_tmem_shared_auth =0 ;boolean_param ("tmem_shared_auth" , opt_tmem_shared_auth);
@@ -216,28 +210,6 @@ int tmem_decompress_to_client(xen_pfn_t cmfn, void *tmem_va,return 1 ; } -int tmem_copy_tze_to_client (xen_pfn_t cmfn,void *tmem_va, -pagesize_t len) -{ -void *cli_va; -unsigned long cli_mfn; -struct page_info *cli_pfp =NULL ; - -ASSERT (!(len & (sizeof (uint64_t )-1 ))); -ASSERT (len <=PAGE_SIZE ); -ASSERT (len >0 || tmem_va ==NULL ); - cli_va =cli_get_page (cmfn, &cli_mfn, &cli_pfp,1 ); -if ( cli_va ==NULL ) -return -EFAULT ; -if ( len >0 ) -memcpy ((char *)cli_va,(char *)tmem_va,len); -if ( len <PAGE_SIZE ) -memset ((char *)cli_va+len,0 ,PAGE_SIZE -len); -cli_put_page (cli_va, cli_pfp, cli_mfn,1 ); -smp_mb (); -return 1 ; -} -/****************** XEN-SPECIFIC HOST INITIALIZATION ********************/ static int dstmem_order, workmem_order;
xen/include/xen/tmem_xen.h +0 -115
133 lines not on this page · raw message
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 3/9] tmem: Delete deduplication (and tze) code.
Quoted 10 lines · Konrad Rzeszutek Wilk
Couple of reasons:
- It can lead to security issues (see row-hammer, KSM and such attacks).
- Code is quite complex.
- Deduplication is good if the pages themselves are the same but that is hardly guaranteed.
- We got some gains (if pages are deduped) but at the cost of making code less maintainable.
- tze depends on deduplication code.
Quoted 3 lines
As such, deleting it.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
Quoted 11 lines
---
v1: First submission.
v2: Squash " tmem: Wrap tmem dedup code withCONFIG_TMEM_DEDUP"
and "tmem: Wrap tmem tze code withCONFIG_TMEM_TZE"--- docs/misc/xen-command-line.markdown | 6 - xen/common/tmem.c | 310 +----------------------------------- xen/common/tmem_control.c | 7 - xen/common/tmem_xen.c | 28 ---- xen/include/xen/tmem_xen.h | 115 ------------- 5 files changed, 3 insertions(+), 463 deletions(-)
<3 this diffstat :)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 4/9 tmem: Move client weight, frozen, live_migrating, and compress
In reply to Konrad Rzeszutek Wilkin its own structure. This paves the way to make only one hypercall to retrieve/set this information instead of multiple ones.
---
v1: First submission.
v2: Rebase on " tmem: Retire XEN_SYSCTL_TMEM_OP_[SET_CAP|SAVE_GET_CLIENT_CAP]"
which deleted the ->cap field.
s/tmem_client/xen_tmem_client/
Deleted 'version' and 'maxpools' from the structure.
Add spaces in the title after the comma.
Added Wei's Ack
--- xen/common/tmem.c | 38 +++++++++++++++++++------------------- xen/common/tmem_control.c | 18 +++++++++--------- xen/include/public/sysctl.h | 12 ++++++++++++ xen/include/xen/tmem_xen.h | 5 +---- 4 files changed, 41 insertions(+), 32 deletions(-)
xen/common/tmem.c +19 -19
@@ -333,7 +333,7 @@ static void pgp_free(struct tmem_page_descriptor *pgp)atomic_dec (&pool->pgp_count);ASSERT (_atomic_read (pool->pgp_count) >=0 ); pgp->size =-1 ; -if (is_persistent (pool) && pool->client->live_migrating ) +if (is_persistent (pool) && pool->client->info.flags.u.migrating ) { pgp->inv_oid = pgp->us.obj->oid; pgp->pool_id = pool->pool_id;
@@ -370,7 +370,7 @@ static void pgp_delist_free(struct tmem_page_descriptor *pgp) }else { -if ( client->live_migrating ) +if ( client->info.flags.u.migrating ) {spin_lock (&pers_lists_spinlock); list_add_tail(&pgp->client_inv_pages,
@@ -791,7 +791,7 @@ static void pool_flush(struct tmem_pool *pool, domid_t cli_id)is_persistent (pool) ?"persistent" :"ephemeral" ,is_shared (pool) ?"shared" :"private" , tmem_cli_id_str, pool->client->cli_id, pool->pool_id); -if ( pool->client->live_migrating ) +if ( pool->client->info.flags.u.migrating ) {tmem_client_warn ("can't destroy pool while %s is live-migrating\n" , tmem_client_str);
@@ -843,7 +843,7 @@ static struct client *client_create(domid_t cli_id)rcu_unlock_domain (d); client->cli_id = cli_id; - client->compress =tmem_compression_enabled (); + client->info.flags.u.compress =tmem_compression_enabled (); client->shared_auth_required =tmem_shared_auth ();for ( i =0 ; i <MAX_GLOBAL_SHARED_POOLS ; i++) client->shared_auth_uuid[i][0] =
@@ -887,11 +887,11 @@ static bool_t client_over_quota(struct client *client)int total =_atomic_read (tmem_global.client_weight_total);ASSERT (client !=NULL ); -if ( (total ==0 ) || (client->weight ==0 ) || +if ( (total ==0 ) || (client->info.weight ==0 ) || (client->eph_count ==0 ) )return 0 ;return ( ((tmem_global.eph_count*100L ) / client->eph_count ) > - ((total*100L ) / client->weight) ); + ((total*100L ) / client->info.weight) ); }/************ MEMORY REVOCATION ROUTINES *******************************/
@@ -1067,10 +1067,10 @@ static int do_tmem_dup_put(struct tmem_page_descriptor *pgp, xen_pfn_t cmfn, pool = obj->pool;ASSERT (pool !=NULL ); client = pool->client; -if ( client->live_migrating ) +if ( client->info.flags.u.migrating ) goto failed_dup;/* No dups allowed when migrating. */ /* Can we successfully manipulate pgp to change out the data? */ -if ( client->compress && pgp->size !=0 ) +if ( client->info.flags.u.compress && pgp->size !=0 ) { ret =do_tmem_put_compress (pgp, cmfn, clibuf);if ( ret ==1 )
@@ -1142,7 +1142,7 @@ static int do_tmem_put(struct tmem_pool *pool,ASSERT (pool !=NULL ); client = pool->client;ASSERT (client !=NULL ); - ret = client->frozen ? -EFROZEN : -ENOMEM ; + ret = client->info.flags.u.frozen ? -EFROZEN : -ENOMEM ; pool->puts++; refind:
@@ -1156,14 +1156,14 @@ refind:else {/* No puts allowed into a frozen pool (except dup puts). */ -if ( client->frozen ) +if ( client->info.flags.u.frozen ) goto unlock_obj; } }else {/* No puts allowed into a frozen pool (except dup puts). */ -if ( client->frozen ) +if ( client->info.flags.u.frozen )return ret;if ( (obj =obj_alloc (pool, oidp)) ==NULL )return -ENOMEM ;
@@ -1198,7 +1198,7 @@ refind: pgp->index = index; pgp->size =0 ; -if ( client->compress ) +if ( client->info.flags.u.compress ) {ASSERT (pgp->pfp ==NULL ); ret =do_tmem_put_compress (pgp, cmfn, clibuf);
@@ -1390,7 +1390,7 @@ static int do_tmem_flush_page(struct tmem_pool *pool, pool->flushs_found++; out: -if ( pool->client->frozen ) +if ( pool->client->info.flags.u.frozen )return -EFROZEN ;else return 1 ;
@@ -1411,7 +1411,7 @@ static int do_tmem_flush_object(struct tmem_pool *pool,write_unlock (&pool->pool_rwlock); out: -if ( pool->client->frozen ) +if ( pool->client->info.flags.u.frozen )return -EFROZEN ;else return 1 ;
@@ -1669,10 +1669,10 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id, rc =0 ;break ; } - client->was_frozen = client->frozen; - client->frozen =1 ; + client->was_frozen = client->info.flags.u.frozen; + client->info.flags.u.frozen =1 ;if ( arg1 !=0 ) - client->live_migrating =1 ; + client->info.flags.u.migrating =1 ; rc =1 ;break ;case XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN :
@@ -1682,12 +1682,12 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id,case XEN_SYSCTL_TMEM_OP_SAVE_END :if ( client ==NULL )break ; - client->live_migrating =0 ; + client->info.flags.u.migrating =0 ;if ( !list_empty (&client->persistent_invalidated_list) )list_for_each_entry_safe (pgp,pgp2, &client->persistent_invalidated_list, client_inv_pages)__pgp_free (pgp, client->pools[pgp->pool_id]); - client->frozen = client->was_frozen; + client->info.flags.u.frozen = client->was_frozen; rc =0 ;break ; }
xen/common/tmem_control.c +9 -9
@@ -27,14 +27,14 @@ static int tmemc_freeze_pools(domid_t cli_id, int arg)if ( cli_id ==TMEM_CLI_ID_NULL ) {list_for_each_entry (client,&tmem_global.client_list,client_list) - client->frozen = freeze; + client->info.flags.u.frozen = freeze;tmem_client_info ("tmem: all pools %s for all %ss\n" , s, tmem_client_str); }else {if ( (client =tmem_client_from_cli_id (cli_id)) ==NULL )return -1 ; - client->frozen = freeze; + client->info.flags.u.frozen = freeze;tmem_client_info ("tmem: all pools %s for %s=%d\n" , s, tmem_cli_id_str, cli_id); }
@@ -105,7 +105,7 @@ static int tmemc_list_client(struct client *c, tmem_cli_va_param_t buf, n =scnprintf (info,BSIZE ,"C=CI:%d,ww:%d,co:%d,fr:%d," "Tc:%" PRIu64",Ge:%ld,Pp:%ld,Gp:%ld%c" , - c->cli_id, c->weight, c->compress, c->frozen, + c->cli_id, c->info.weight, c->info.flags.u.compress, c->info.flags.u.frozen, c->total_cycles, c->succ_eph_gets, c->succ_pers_puts, c->succ_pers_gets, use_long ?',' :'\n' );if (use_long)
@@ -266,15 +266,15 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, uint32_t arg1)switch (subop) {case XEN_SYSCTL_TMEM_OP_SET_WEIGHT : - old_weight = client->weight; - client->weight = arg1; + old_weight = client->info.weight; + client->info.weight = arg1;tmem_client_info ("tmem: weight set to %d for %s=%d\n" , arg1, tmem_cli_id_str, cli_id);atomic_sub (old_weight,&tmem_global.client_weight_total); -atomic_add (client->weight,&tmem_global.client_weight_total); +atomic_add (client->info.weight,&tmem_global.client_weight_total);break ;case XEN_SYSCTL_TMEM_OP_SET_COMPRESS : - client->compress = arg1 ?1 :0 ; + client->info.flags.u.compress = arg1 ?1 :0 ;tmem_client_info ("tmem: compression %s for %s=%d\n" , arg1 ?"enabled" :"disabled" ,tmem_cli_id_str,cli_id);break ;
@@ -327,12 +327,12 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id,case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT :if ( client ==NULL )break ; - rc = client->weight ==-1 ?-2 : client->weight; + rc = client->info.weight ==-1 ?-2 : client->info.weight;break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS :if ( client ==NULL )break ; - rc = (client->compress ?TMEM_CLIENT_COMPRESS :0 ) | + rc = (client->info.flags.u.compress ?TMEM_CLIENT_COMPRESS :0 ) | (client->was_frozen ?TMEM_CLIENT_FROZEN :0 );break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS :
xen/include/public/sysctl.h +12 -0
@@ -796,6 +796,18 @@ struct tmem_handle {xen_tmem_oid_t oid; }; +struct xen_tmem_client { +union {/* See TMEM_CLIENT_[COMPRESS,FROZEN] */ +uint32_t raw; +struct { +uint8_t frozen:1 , + compress:1 , + migrating:1 ; + } u; + } flags; +uint32_t weight; +}; +struct xen_sysctl_tmem_op {uint32_t cmd;/* IN: XEN_SYSCTL_TMEM_OP_* . */ int32_t pool_id;/* IN: 0 by default unless _SAVE_*, RESTORE_* .*/
xen/include/xen/tmem_xen.h +1 -4
@@ -293,12 +293,9 @@ struct client {struct list_head ephemeral_page_list;long eph_count, eph_count_max;domid_t cli_id; -uint32_t weight; -bool_t compress; -bool_t frozen; +struct xen_tmem_client info;bool_t shared_auth_required;/* For save/restore/migration. */ -bool_t live_migrating;bool_t was_frozen;struct list_head persistent_invalidated_list;struct tmem_page_descriptor *cur_pgp;
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 4/9] tmem: Move client weight, frozen, live_migrating, and compress
Quoted 6 lines · Konrad Rzeszutek Wilk
in its own structure. This paves the way to make only one hypercall to retrieve/set this information instead of multiple ones.
Acked-by Wei Liu <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 5/9 tmem/sysctl: Add union in struct xen_sysctl_tmem_op
In reply to Konrad Rzeszutek WilkNo functional change. We do this to prepare for another entry to be added in the union. See patch titled:
"tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]"
---
v2: New submission.
--- tools/libxc/xc_tmem.c | 4 ++-- xen/common/tmem.c | 8 ++++---- xen/common/tmem_control.c | 4 ++-- xen/include/public/sysctl.h | 4 +++- 4 files changed, 11 insertions(+), 9 deletions(-)
tools/libxc/xc_tmem.c +2 -2
@@ -81,7 +81,7 @@ int xc_tmem_control(xc_interface *xch, } } -set_xen_guest_handle (sysctl.u.tmem_op.buf, buf); +set_xen_guest_handle (sysctl.u.tmem_op.u.buf, buf); rc =do_sysctl (xch, &sysctl);
@@ -127,7 +127,7 @@ int xc_tmem_control_oid(xc_interface *xch, } } -set_xen_guest_handle (sysctl.u.tmem_op.buf, buf); +set_xen_guest_handle (sysctl.u.tmem_op.u.buf, buf); rc =do_sysctl (xch, &sysctl);
xen/common/tmem.c +4 -4
@@ -1841,19 +1841,19 @@ int do_tmem_control(struct xen_sysctl_tmem_op *op)case XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN :case XEN_SYSCTL_TMEM_OP_SAVE_END : ret =tmemc_save_subop (op->cli_id, pool_id, cmd, -guest_handle_cast (op->buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg1);break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE : ret =tmemc_save_get_next_page (op->cli_id, pool_id, -guest_handle_cast (op->buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg1);break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_INV : ret =tmemc_save_get_next_inv (op->cli_id, -guest_handle_cast (op->buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg1);break ;case XEN_SYSCTL_TMEM_OP_RESTORE_PUT_PAGE : ret =tmemc_restore_put_page (op->cli_id, pool_id, oidp, op->arg2, -guest_handle_cast (op->buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg1);break ;case XEN_SYSCTL_TMEM_OP_RESTORE_FLUSH_PAGE : ret =tmemc_restore_flush_page (op->cli_id, pool_id, oidp, op->arg2);
xen/common/tmem_control.c +2 -2
@@ -384,7 +384,7 @@ int tmem_control(struct xen_sysctl_tmem_op *op)break ;case XEN_SYSCTL_TMEM_OP_LIST : ret =tmemc_list (op->cli_id, -guest_handle_cast (op->buf, char), op->arg1, op->arg2); +guest_handle_cast (op->u.buf, char), op->arg1, op->arg2);break ;case XEN_SYSCTL_TMEM_OP_SET_WEIGHT :case XEN_SYSCTL_TMEM_OP_SET_COMPRESS :
@@ -401,7 +401,7 @@ int tmem_control(struct xen_sysctl_tmem_op *op)case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES :case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID : ret =tmemc_save_subop (op->cli_id, pool_id, cmd, -guest_handle_cast (op->buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg1);break ;default : ret =do_tmem_control (op);
xen/include/public/sysctl.h +3 -1
@@ -818,7 +818,9 @@ struct xen_sysctl_tmem_op {uint32_t arg2;/* IN: If not applicable to command use 0. */ uint32_t pad;/* Padding so structure is the same under 32 and 64. */ xen_tmem_oid_t oid;/* IN: If not applicable to command use 0s. */ -XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save and restore ops. */ +union { +XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save and restore ops. */ + } u; };typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_sysctl_tmem_op_t);
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 5/9] tmem/sysctl: Add union in struct xen_sysctl_tmem_op
Quoted 5 lines · Konrad Rzeszutek Wilk
No functional change. We do this to prepare for another entry to be added in the union. See patch titled:
"tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]"Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 6/9 tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]..
In reply to Konrad Rzeszutek WilkSpecifically:
XEN_SYSCTL_TMEM_OP_SET_[WEIGHT,COMPRESS] are now done via:
XEN_SYSCTL_TMEM_SET_CLIENT_INFO
and XEN_SYSCTL_TMEM_OP_SAVE_GET_[VERSION,MAXPOOLS, CLIENT_WEIGHT, CLIENT_FLAGS] can now be retrieved via:
XEN_SYSCTL_TMEM_GET_CLIENT_INFO
All this information is now in 'struct xen_tmem_client' and that is what we pass around.
We also rev up the XEN_SYSCTL_INTERFACE_VERSION as we are re-using the value number of the deleted ones (and henceforth the information is retrieved differently).
On the toolstack, prior to this patch, the xc_tmem_control would use the bounce buffer only when arg1 was set and the cmd was to list. With the 'XEN_SYSCTL_TMEM_OP_SET_[WEIGHT|COMPRESS]' that made sense as the 'arg1' would have the value. However for the other ones (say XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID) the 'arg1' would be the length of the 'buf'. If this confusing don't despair, patch patch titled:
tmem/xc_tmem_control: Rename 'arg1' to 'len' and 'arg2' to arg. takes care of that.
The acute reader of the toolstack code will discover that we only used the bounce buffer for LIST, not for any other subcommands that used 'buf'!?! Which means that the contents of 'buf' would never be copied back to the calleer 'buf'!
The author is not sure how this could possibly work, perhaps Xen 4.1 (when this was introduced) was more relaxed about the bounce buffer being enabled. Anyhow this fixes xc_tmem_control to do it for any subcommand that has 'arg1'.
Lastly some of the checks in xc_tmem_[restore|save] are removed as they can't ever be reached (not even sure how they could have been reached in the original submission). One of them is the check for the weight against -1 when in fact the hypervisor would never have provided that value.
Now the checks are simple - as the hypercall always returns ->version and ->maxpools (which is mirroring how it was done prior to this patch). But if one wants to check the if a guest has any tmem activity then the patch titled
"tmem: Batch and squash XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_ [FLAGS,NPAGES,UUID] in one sub-call: XEN_SYSCTL_TMEM_OP_GET_POOLS." adds an ->nr_pools to check for that.
Also we add the check for ->version and ->maxpools and remove the TODO.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: New submission.
v2: s/xen_sysctl_tmem_client/xen_tmem_client/
Remove the 'subop' check in __tmemc_set_var as there is only
one command doing it now.
- Add the 'version' and 'maxpools' in the 'xen_tmem_client_t'
- Squash in 'tmem: Check version and maxpools when XEN_SYSCTL_TMEM_SET_CLIENT_INFO'
- Squash in 'tmem: Handle 'struct tmem_info' as a seperate field in the' with some of its content moved to 'tmem/sysctl: Add union in struct xen_sysctl_tmem_op'
- Redid the commit description to include comments from:
'tmem: Handle 'struct tmem_info' as a sep..'
--- tools/libxc/xc_tmem.c | 73 +++++++++++---------------- tools/libxl/libxl.c | 26 +++++++--- tools/python/xen/lowlevel/xc/xc.c | 2 - xen/common/tmem.c | 2 + xen/common/tmem_control.c | 102 ++++++++++++++++++++++---------------- xen/include/public/sysctl.h | 23 ++++++--- xen/include/xen/tmem_xen.h | 2 +- 7 files changed, 126 insertions(+), 104 deletions(-)
tools/libxc/xc_tmem.c +29 -44
@@ -18,6 +18,7 @@*/ #include "xc_private.h" +#include <assert.h> #include <xen/tmem.h> static int do_tmem_op (xc_interface *xch,tmem_op_t *op)
@@ -67,7 +68,12 @@ int xc_tmem_control(xc_interface *xch, sysctl.u.tmem_op.oid.oid[1 ] =0 ; sysctl.u.tmem_op.oid.oid[2 ] =0 ; -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) +if ( cmd ==XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO ) + { +HYPERCALL_BOUNCE_SET_DIR (buf,XC_HYPERCALL_BUFFER_BOUNCE_IN ); + } + +if ( arg1 ) {if ( buf ==NULL ) {
@@ -85,8 +91,8 @@ int xc_tmem_control(xc_interface *xch, rc =do_sysctl (xch, &sysctl); -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) -xc_hypercall_bounce_post (xch, buf); +if ( arg1 ) +xc_hypercall_bounce_post (xch, buf);return rc; }
@@ -211,38 +217,29 @@ int xc_tmem_save(xc_interface *xch, {int marker = field_marker;int i, j; -uint32_t max_pools, version; -uint32_t weight, flags; -uint32_t pool_id; +uint32_t flags;uint32_t minusone =-1 ; +uint32_t pool_id;struct tmem_handle *h; +xen_tmem_client_t info;if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_BEGIN ,dom,live,0 ,NULL ) <=0 )return 0 ;if (write_exact (io_fd, &marker,sizeof (marker)) )return -1 ; - version =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION ,0 ,0 ,0 ,NULL ); -if (write_exact (io_fd, &version,sizeof (version)) ) -return -1 ; - max_pools =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_MAXPOOLS ,0 ,0 ,0 ,NULL ); -if (write_exact (io_fd, &max_pools,sizeof (max_pools)) ) -return -1 ; -if ( version ==-1 || max_pools ==-1 ) -return -1 ; -if (write_exact (io_fd, &minusone,sizeof (minusone)) ) -return -1 ; - flags =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS ,dom,0 ,0 ,NULL ); -if (write_exact (io_fd, &flags,sizeof (flags)) ) -return -1 ; - weight =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT ,dom,0 ,0 ,NULL ); -if (write_exact (io_fd, &weight,sizeof (weight)) ) + +if (xc_tmem_control (xch,0 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , + dom/* cli_id */ ,sizeof (info)/* arg1 */ ,0 /* arg2 */ , + &info) <0 )return -1 ; -if ( flags ==-1 || weight ==-1 ) + +if (write_exact (io_fd, &info,sizeof (info)) )return -1 ;if (write_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ; -for ( i =0 ; i < max_pools; i++ ) +for ( i =0 ; i < info.maxpools; i++ ) {uint64_t uuid[2 ];uint32_t n_pages;
@@ -378,35 +375,23 @@ static int xc_tmem_restore_new_pool(int xc_tmem_restore (xc_interface *xch,int dom,int io_fd) { -uint32_t this_max_pools, this_version;uint32_t pool_id;uint32_t minusone; -uint32_t weight, flags; +uint32_t flags; +xen_tmem_client_t info;int checksum =0 ; -if (read_exact (io_fd, &this_version,sizeof (this_version)) ) -return -1 ; -if (read_exact (io_fd, &this_max_pools,sizeof (this_max_pools)) ) -return -1 ; -/* FIXME check here to ensure no version mismatch or maxpools mismatch */ -if (read_exact (io_fd, &minusone,sizeof (minusone)) ) -return -1 ; -if ( minusone !=-1 ) +if (read_exact (io_fd, &info,sizeof (info)) )return -1 ;if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN ,dom,0 ,0 ,NULL ) <0 )return -1 ; -if (read_exact (io_fd, &flags,sizeof (flags)) ) -return -1 ; -if ( flags &TMEM_CLIENT_COMPRESS ) -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SET_COMPRESS ,dom,1 ,0 ,NULL ) <0 ) -return -1 ; -if ( flags &TMEM_CLIENT_FROZEN ) -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_FREEZE ,dom,0 ,0 ,NULL ) <0 ) -return -1 ; -if (read_exact (io_fd, &weight,sizeof (weight)) ) -return -1 ; -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SET_WEIGHT ,dom,0 ,0 ,NULL ) <0 ) + +if (xc_tmem_control (xch,0 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO , + dom/* cli_id */ ,sizeof (info)/* arg1 */ ,0 /* arg2 */ , + &info) <0 )return -1 ; +if (read_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ;while (read_exact (io_fd, &pool_id,sizeof (pool_id)) ==0 && pool_id !=-1 )
tools/libxl/libxl.c +20 -6
@@ -6152,28 +6152,42 @@ out:return rc; } -static int32_t tmem_setop_from_string (char *set_name) +static int32_t tmem_setop_from_string (char *set_name,uint32_t val, +xen_tmem_client_t *info) {if (!strcmp (set_name,"weight" )) -return XEN_SYSCTL_TMEM_OP_SET_WEIGHT ; + info->weight = val;else if (!strcmp (set_name,"compress" )) -return XEN_SYSCTL_TMEM_OP_SET_COMPRESS ; + info->flags.u.compress = val;else return -1 ; + +return 0 ; }int libxl_tmem_set (libxl_ctx *ctx,uint32_t domid,char * name,uint32_t set) {int r, rc; -int32_t subop =tmem_setop_from_string (name); +xen_tmem_client_t info;GC_INIT (ctx); -if (subop ==-1 ) { + r =xc_tmem_control (ctx->xch,-1 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , + domid,sizeof (info),0 /* arg2 */ , &info); +if (r <0 ) { +LOGE (ERROR ,"Can not get tmem data!" ); + rc =ERROR_FAIL ; + goto out; + } + rc =tmem_setop_from_string (name, set, &info); +if (rc ==-1 ) {LOGEV (ERROR ,-1 ,"Invalid set, valid sets are <weight|compress>" ); rc =ERROR_INVAL ; goto out; } - r =xc_tmem_control (ctx->xch,-1 , subop, domid, set,0 ,NULL ); + r =xc_tmem_control (ctx->xch,-1 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO , + domid,sizeof (info),0 /* arg2 */ , &info);if (r <0 ) {LOGE (ERROR ,"Can not set tmem %s" , name); rc =ERROR_FAIL ;
tools/python/xen/lowlevel/xc/xc.c +0 -2
@@ -1640,8 +1640,6 @@ static PyObject *pyxc_tmem_control(XcObject *self,case XEN_SYSCTL_TMEM_OP_THAW :case XEN_SYSCTL_TMEM_OP_FREEZE :case XEN_SYSCTL_TMEM_OP_DESTROY : -case XEN_SYSCTL_TMEM_OP_SET_WEIGHT : -case XEN_SYSCTL_TMEM_OP_SET_COMPRESS :default :break ; }
xen/common/tmem.c +2 -0
@@ -843,6 +843,8 @@ static struct client *client_create(domid_t cli_id)rcu_unlock_domain (d); client->cli_id = cli_id; + client->info.version =TMEM_SPEC_VERSION ; + client->info.maxpools =MAX_POOLS_PER_DOMAIN ; client->info.flags.u.compress =tmem_compression_enabled (); client->shared_auth_required =tmem_shared_auth ();for ( i =0 ; i <MAX_GLOBAL_SHARED_POOLS ; i++)
xen/common/tmem_control.c +59 -43
155 lines not on this page · raw message
xen/include/public/sysctl.h +15 -8
@@ -36,7 +36,7 @@#include "physdev.h" #include "tmem.h" -#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000D +#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000E/* * Read console content from Xen buffer ring.
@@ -767,14 +767,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_psr_cat_op_t);#define XEN_SYSCTL_TMEM_OP_FLUSH 2#define XEN_SYSCTL_TMEM_OP_DESTROY 3#define XEN_SYSCTL_TMEM_OP_LIST 4 -#define XEN_SYSCTL_TMEM_OP_SET_WEIGHT 5 -#define XEN_SYSCTL_TMEM_OP_SET_COMPRESS 7 +#define XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO 5 +#define XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO 6#define XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB 8#define XEN_SYSCTL_TMEM_OP_SAVE_BEGIN 10 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION 11 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_MAXPOOLS 12 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT 13 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS 15#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS 16#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES 17#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID 18
@@ -796,7 +792,14 @@ struct tmem_handle {xen_tmem_oid_t oid; }; +/* +* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT uses the 'client' in +* xen_tmem_op with this structure, which is mostly used during migration. +*/ struct xen_tmem_client { + uint32_t version; /* If mismatched we will get XEN_EOPNOTSUPP. */ + uint32_t maxpools; /* If greater than what hypervisor supports, will get + XEN_ERANGE. */ union { /* See TMEM_CLIENT_[COMPRESS,FROZEN] */ uint32_t raw; struct {
@@ -807,6 +810,8 @@ struct xen_tmem_client { } flags;uint32_t weight; }; +typedef struct xen_tmem_client xen_tmem_client_t ; +DEFINE_XEN_GUEST_HANDLE (xen_tmem_client_t);struct xen_sysctl_tmem_op {uint32_t cmd;/* IN: XEN_SYSCTL_TMEM_OP_* . */
@@ -819,7 +824,9 @@ struct xen_sysctl_tmem_op {uint32_t pad;/* Padding so structure is the same under 32 and 64. */ xen_tmem_oid_t oid;/* IN: If not applicable to command use 0s. */ union { -XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save and restore ops. */ +XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save/restore */ +XEN_GUEST_HANDLE_64 (xen_tmem_client_t) client;/* IN/OUT for */ +/* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT. */ } u; };typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t ;
xen/include/xen/tmem_xen.h +1 -1
@@ -293,7 +293,7 @@ struct client {struct list_head ephemeral_page_list;long eph_count, eph_count_max;domid_t cli_id; -struct xen_tmem_client info; +xen_tmem_client_t info;bool_t shared_auth_required;/* For save/restore/migration. */ bool_t was_frozen;
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 6/9] tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]..
Quoted 4 lines · Konrad Rzeszutek Wilk
--- tools/libxc/xc_tmem.c | 73 +++++++++++---------------- tools/libxl/libxl.c | 26 +++++++--- tools/python/xen/lowlevel/xc/xc.c | 2 -
Quoted 19 lines
xen/common/tmem.c | 2 + xen/common/tmem_control.c | 102 ++++++++++++++++++++++---------------- xen/include/public/sysctl.h | 23 ++++++--- xen/include/xen/tmem_xen.h | 2 +- 7 files changed, 126 insertions(+), 104 deletions(-)tools/libxc/xc_tmem.c +1
-0@@ -18,6 +18,7 @@*/ #include "xc_private.h" +#include <assert.h> #include <xen/tmem.h> static int do_tmem_op (xc_interface *xch,tmem_op_t *op)
tools/libxc/xc_tmem.c int xc_tmem_control(xc_interface *xch, · line 74
Quoted 8 lines
tools/libxc/xc_tmem.c +4
-1@@ -67,7 +68,12 @@ int xc_tmem_control(xc_interface *xch, sysctl.u.tmem_op.oid.oid[1 ] =0 ; sysctl.u.tmem_op.oid.oid[2 ] =0 ; -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) +if ( cmd ==XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO ) + { +HYPERCALL_BOUNCE_SET_DIR (buf,XC_HYPERCALL_BUFFER_BOUNCE_IN ); + }
"Braces should be omitted for blocks with a single statement."
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 6/9] tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]..
In reply to Konrad Rzeszutek WilkQuoted 8 lines · Konrad Rzeszutek Wilk
xen/common/tmem_control.c +0
-0@@ -258,43 +258,56 @@ static int tmemc_list(domid_t cli_id, tmem_cli_va_param_t buf, uint32_t len,return 0 ; }
xen/common/tmem_control.c static int tmemc_list(domid_t cli_id, tmem_cli_va_param_t buf, uint32_t len, · line 268
Quoted 10 lines
xen/common/tmem_control.c +4
-2-static int __tmemc_set_var (struct client *client,uint32_t subop,uint32_t arg1) +static int __tmemc_set_client_info (struct client *client, +XEN_GUEST_HANDLE (xen_tmem_client_t) buf) {domid_t cli_id = client->cli_id;uint32_t old_weight; +xen_tmem_client_t info = { }; - switch (subop) +ASSERT (client);
This ASSERT() is useless after have already dereferenced client to get cli_id. Best to defer the initialisation of the domid and keep the assert like this.
Quoted 17 lines
xen/common/tmem_control.c +6
-3@@ -303,13 +316,35 @@ static int tmemc_set_var(domid_t cli_id, uint32_t subop, uint32_t arg1) { client =tmem_client_from_cli_id (cli_id);if ( client ) - ret =__tmemc_set_var (client, subop, arg1); + ret =__tmemc_set_client_info (client, info); }return ret; } -static int tmemc_save_subop (int cli_id,uint32_t pool_id, -uint32_t subop,tmem_cli_va_param_t buf,uint32_t arg1) +static int tmemc_get_client_info (int cli_id, +XEN_GUEST_HANDLE (xen_tmem_client_t) info) +{ +struct client *client =tmem_client_from_cli_id (cli_id); +
xen/common/tmem_control.c static int tmemc_set_var(domid_t cli_id, uint32_t subop, uint32_t arg1) · line 338
Quoted 10 lines
xen/common/tmem_control.c +10
-0+if ( client ) + { +if (copy_to_guest (info, &client->info,1 ) ) +return -EFAULT ; + } +else + { +static const xen_tmem_client_t generic = { + .version =TMEM_SPEC_VERSION , + .maxpools =MAX_POOLS_PER_DOMAIN };
There is some weird alignment/tabs going on here.
With these fixed, Acked-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 6/9] tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]..
Quoted 54 lines · Andrew Cooper
Quoted 8 lines · Konrad Rzeszutek Wilk
xen/common/tmem_control.c +0
-0@@ -258,43 +258,56 @@ static int tmemc_list(domid_t cli_id, tmem_cli_va_param_t buf, uint32_t len,return 0 ; }xen/common/tmem_control.c static int tmemc_list(domid_t cli_id, tmem_cli_va_param_t buf, uint32_t len, · line 268
Quoted 10 lines
xen/common/tmem_control.c +4
-2-static int __tmemc_set_var (struct client *client,uint32_t subop,uint32_t arg1) +static int __tmemc_set_client_info (struct client *client, +XEN_GUEST_HANDLE (xen_tmem_client_t) buf) {domid_t cli_id = client->cli_id;uint32_t old_weight; +xen_tmem_client_t info = { }; - switch (subop) +ASSERT (client);This
ASSERT()is useless after have already dereferenced client to getcli_id. Best to defer the initialisation of the domid and keep the assert like this.Quoted 17 lines
xen/common/tmem_control.c +6
-3@@ -303,13 +316,35 @@ static int tmemc_set_var(domid_t cli_id, uint32_t subop, uint32_t arg1) { client =tmem_client_from_cli_id (cli_id);if ( client ) - ret =__tmemc_set_var (client, subop, arg1); + ret =__tmemc_set_client_info (client, info); }return ret; } -static int tmemc_save_subop (int cli_id,uint32_t pool_id, -uint32_t subop,tmem_cli_va_param_t buf,uint32_t arg1) +static int tmemc_get_client_info (int cli_id, +XEN_GUEST_HANDLE (xen_tmem_client_t) info) +{ +struct client *client =tmem_client_from_cli_id (cli_id); +xen/common/tmem_control.c static int tmemc_set_var(domid_t cli_id, uint32_t subop, uint32_t arg1) · line 338
Quoted 10 lines
xen/common/tmem_control.c +10
-0+if ( client ) + { +if (copy_to_guest (info, &client->info,1 ) ) +return -EFAULT ; + } +else + { +static const xen_tmem_client_t generic = { + .version =TMEM_SPEC_VERSION , + .maxpools =MAX_POOLS_PER_DOMAIN };There is some weird alignment/tabs going on here.
Quoted 1 line
With these fixed, Acked-by: Andrew Cooper <[email protected]>
Thank you!
Pls see inline:
From 1ff700e418b3090d6e230c566d7387ec47d0bad0 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 30 Sep 2016 10:53:01 -0400
Subject: [PATCH v2.1 6/9] tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE]..
Specifically:
XEN_SYSCTL_TMEM_OP_SET_[WEIGHT,COMPRESS] are now done via:
XEN_SYSCTL_TMEM_SET_CLIENT_INFO
and XEN_SYSCTL_TMEM_OP_SAVE_GET_[VERSION,MAXPOOLS, CLIENT_WEIGHT, CLIENT_FLAGS] can now be retrieved via:
XEN_SYSCTL_TMEM_GET_CLIENT_INFO
All this information is now in 'struct xen_tmem_client' and that is what we pass around.
We also rev up the XEN_SYSCTL_INTERFACE_VERSION as we are re-using the value number of the deleted ones (and henceforth the information is retrieved differently).
On the toolstack, prior to this patch, the xc_tmem_control would use the bounce buffer only when arg1 was set and the cmd was to list. With the 'XEN_SYSCTL_TMEM_OP_SET_[WEIGHT|COMPRESS]' that made sense as the 'arg1' would have the value. However for the other ones (say XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID) the 'arg1' would be the length of the 'buf'. If this confusing don't despair, patch patch titled:
tmem/xc_tmem_control: Rename 'arg1' to 'len' and 'arg2' to arg. takes care of that.
The acute reader of the toolstack code will discover that we only used the bounce buffer for LIST, not for any other subcommands that used 'buf'!?! Which means that the contents of 'buf' would never be copied back to the calleer 'buf'!
The author is not sure how this could possibly work, perhaps Xen 4.1 (when this was introduced) was more relaxed about the bounce buffer being enabled. Anyhow this fixes xc_tmem_control to do it for any subcommand that has 'arg1'.
Lastly some of the checks in xc_tmem_[restore|save] are removed as they can't ever be reached (not even sure how they could have been reached in the original submission). One of them is the check for the weight against -1 when in fact the hypervisor would never have provided that value.
Now the checks are simple - as the hypercall always returns ->version and ->maxpools (which is mirroring how it was done prior to this patch). But if one wants to check the if a guest has any tmem activity then the patch titled
"tmem: Batch and squash XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_ [FLAGS,NPAGES,UUID] in one sub-call: XEN_SYSCTL_TMEM_OP_GET_POOLS." adds an ->nr_pools to check for that.
Also we add the check for ->version and ->maxpools and remove the TODO.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: New submission.
v2: s/xen_sysctl_tmem_client/xen_tmem_client/
Remove the 'subop' check in __tmemc_set_var as there is only
one command doing it now.
- Add the 'version' and 'maxpools' in the 'xen_tmem_client_t'
- Squash in 'tmem: Check version and maxpools when XEN_SYSCTL_TMEM_SET_CLIENT_INFO'
- Squash in 'tmem: Handle 'struct tmem_info' as a seperate field in the' with some of its content moved to 'tmem/sysctl: Add union in struct xen_sysctl_tmem_op'
- Redid the commit description to include comments from:
'tmem: Handle 'struct tmem_info' as a sep..'
v2.1: Remove not needed braces.
- Don't derefence client->cli_id _before_ asserting on client.
- Fix tabs and aligmnet on generic variable.
- Added Andrew's Ack.
--- tools/libxc/xc_tmem.c | 71 ++++++++++--------------- tools/libxl/libxl.c | 26 ++++++--- tools/python/xen/lowlevel/xc/xc.c | 2 - xen/common/tmem.c | 2 + xen/common/tmem_control.c | 107 ++++++++++++++++++++++---------------- xen/include/public/sysctl.h | 23 +++++--- xen/include/xen/tmem_xen.h | 2 +- 7 files changed, 128 insertions(+), 105 deletions(-)
tools/libxc/xc_tmem.c +27 -44
@@ -18,6 +18,7 @@*/ #include "xc_private.h" +#include <assert.h> #include <xen/tmem.h> static int do_tmem_op (xc_interface *xch,tmem_op_t *op)
@@ -67,7 +68,10 @@ int xc_tmem_control(xc_interface *xch, sysctl.u.tmem_op.oid.oid[1 ] =0 ; sysctl.u.tmem_op.oid.oid[2 ] =0 ; -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) +if ( cmd ==XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO ) +HYPERCALL_BOUNCE_SET_DIR (buf,XC_HYPERCALL_BUFFER_BOUNCE_IN ); + +if ( arg1 ) {if ( buf ==NULL ) {
@@ -85,8 +89,8 @@ int xc_tmem_control(xc_interface *xch, rc =do_sysctl (xch, &sysctl); -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) -xc_hypercall_bounce_post (xch, buf); +if ( arg1 ) +xc_hypercall_bounce_post (xch, buf);return rc; }
@@ -211,38 +215,29 @@ int xc_tmem_save(xc_interface *xch, {int marker = field_marker;int i, j; -uint32_t max_pools, version; -uint32_t weight, flags; -uint32_t pool_id; +uint32_t flags;uint32_t minusone =-1 ; +uint32_t pool_id;struct tmem_handle *h; +xen_tmem_client_t info;if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_BEGIN ,dom,live,0 ,NULL ) <=0 )return 0 ;if (write_exact (io_fd, &marker,sizeof (marker)) )return -1 ; - version =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION ,0 ,0 ,0 ,NULL ); -if (write_exact (io_fd, &version,sizeof (version)) ) -return -1 ; - max_pools =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_MAXPOOLS ,0 ,0 ,0 ,NULL ); -if (write_exact (io_fd, &max_pools,sizeof (max_pools)) ) -return -1 ; -if ( version ==-1 || max_pools ==-1 ) -return -1 ; -if (write_exact (io_fd, &minusone,sizeof (minusone)) ) -return -1 ; - flags =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS ,dom,0 ,0 ,NULL ); -if (write_exact (io_fd, &flags,sizeof (flags)) ) -return -1 ; - weight =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT ,dom,0 ,0 ,NULL ); -if (write_exact (io_fd, &weight,sizeof (weight)) ) + +if (xc_tmem_control (xch,0 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , + dom/* cli_id */ ,sizeof (info)/* arg1 */ ,0 /* arg2 */ , + &info) <0 )return -1 ; -if ( flags ==-1 || weight ==-1 ) + +if (write_exact (io_fd, &info,sizeof (info)) )return -1 ;if (write_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ; -for ( i =0 ; i < max_pools; i++ ) +for ( i =0 ; i < info.maxpools; i++ ) {uint64_t uuid[2 ];uint32_t n_pages;
@@ -378,35 +373,23 @@ static int xc_tmem_restore_new_pool(int xc_tmem_restore (xc_interface *xch,int dom,int io_fd) { -uint32_t this_max_pools, this_version;uint32_t pool_id;uint32_t minusone; -uint32_t weight, flags; +uint32_t flags; +xen_tmem_client_t info;int checksum =0 ; -if (read_exact (io_fd, &this_version,sizeof (this_version)) ) -return -1 ; -if (read_exact (io_fd, &this_max_pools,sizeof (this_max_pools)) ) -return -1 ; -/* FIXME check here to ensure no version mismatch or maxpools mismatch */ -if (read_exact (io_fd, &minusone,sizeof (minusone)) ) -return -1 ; -if ( minusone !=-1 ) +if (read_exact (io_fd, &info,sizeof (info)) )return -1 ;if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN ,dom,0 ,0 ,NULL ) <0 )return -1 ; -if (read_exact (io_fd, &flags,sizeof (flags)) ) -return -1 ; -if ( flags &TMEM_CLIENT_COMPRESS ) -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SET_COMPRESS ,dom,1 ,0 ,NULL ) <0 ) -return -1 ; -if ( flags &TMEM_CLIENT_FROZEN ) -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_FREEZE ,dom,0 ,0 ,NULL ) <0 ) -return -1 ; -if (read_exact (io_fd, &weight,sizeof (weight)) ) -return -1 ; -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SET_WEIGHT ,dom,0 ,0 ,NULL ) <0 ) + +if (xc_tmem_control (xch,0 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO , + dom/* cli_id */ ,sizeof (info)/* arg1 */ ,0 /* arg2 */ , + &info) <0 )return -1 ; +if (read_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ;while (read_exact (io_fd, &pool_id,sizeof (pool_id)) ==0 && pool_id !=-1 )
tools/libxl/libxl.c +20 -6
@@ -6152,28 +6152,42 @@ out:return rc; } -static int32_t tmem_setop_from_string (char *set_name) +static int32_t tmem_setop_from_string (char *set_name,uint32_t val, +xen_tmem_client_t *info) {if (!strcmp (set_name,"weight" )) -return XEN_SYSCTL_TMEM_OP_SET_WEIGHT ; + info->weight = val;else if (!strcmp (set_name,"compress" )) -return XEN_SYSCTL_TMEM_OP_SET_COMPRESS ; + info->flags.u.compress = val;else return -1 ; + +return 0 ; }int libxl_tmem_set (libxl_ctx *ctx,uint32_t domid,char * name,uint32_t set) {int r, rc; -int32_t subop =tmem_setop_from_string (name); +xen_tmem_client_t info;GC_INIT (ctx); -if (subop ==-1 ) { + r =xc_tmem_control (ctx->xch,-1 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , + domid,sizeof (info),0 /* arg2 */ , &info); +if (r <0 ) { +LOGE (ERROR ,"Can not get tmem data!" ); + rc =ERROR_FAIL ; + goto out; + } + rc =tmem_setop_from_string (name, set, &info); +if (rc ==-1 ) {LOGEV (ERROR ,-1 ,"Invalid set, valid sets are <weight|compress>" ); rc =ERROR_INVAL ; goto out; } - r =xc_tmem_control (ctx->xch,-1 , subop, domid, set,0 ,NULL ); + r =xc_tmem_control (ctx->xch,-1 /* pool_id */ , +XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO , + domid,sizeof (info),0 /* arg2 */ , &info);if (r <0 ) {LOGE (ERROR ,"Can not set tmem %s" , name); rc =ERROR_FAIL ;
tools/python/xen/lowlevel/xc/xc.c +0 -2
@@ -1640,8 +1640,6 @@ static PyObject *pyxc_tmem_control(XcObject *self,case XEN_SYSCTL_TMEM_OP_THAW :case XEN_SYSCTL_TMEM_OP_FREEZE :case XEN_SYSCTL_TMEM_OP_DESTROY : -case XEN_SYSCTL_TMEM_OP_SET_WEIGHT : -case XEN_SYSCTL_TMEM_OP_SET_COMPRESS :default :break ; }
xen/common/tmem.c +2 -0
@@ -843,6 +843,8 @@ static struct client *client_create(domid_t cli_id)rcu_unlock_domain (d); client->cli_id = cli_id; + client->info.version =TMEM_SPEC_VERSION ; + client->info.maxpools =MAX_POOLS_PER_DOMAIN ; client->info.flags.u.compress =tmem_compression_enabled (); client->shared_auth_required =tmem_shared_auth ();for ( i =0 ; i <MAX_GLOBAL_SHARED_POOLS ; i++)
xen/common/tmem_control.c +63 -44
159 lines not on this page · raw message
xen/include/public/sysctl.h +15 -8
@@ -36,7 +36,7 @@#include "physdev.h" #include "tmem.h" -#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000D +#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000E/* * Read console content from Xen buffer ring.
@@ -767,14 +767,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_psr_cat_op_t);#define XEN_SYSCTL_TMEM_OP_FLUSH 2#define XEN_SYSCTL_TMEM_OP_DESTROY 3#define XEN_SYSCTL_TMEM_OP_LIST 4 -#define XEN_SYSCTL_TMEM_OP_SET_WEIGHT 5 -#define XEN_SYSCTL_TMEM_OP_SET_COMPRESS 7 +#define XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO 5 +#define XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO 6#define XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB 8#define XEN_SYSCTL_TMEM_OP_SAVE_BEGIN 10 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_VERSION 11 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_MAXPOOLS 12 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_WEIGHT 13 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_CLIENT_FLAGS 15#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS 16#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES 17#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID 18
@@ -796,7 +792,14 @@ struct tmem_handle {xen_tmem_oid_t oid; }; +/* +* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT uses the 'client' in +* xen_tmem_op with this structure, which is mostly used during migration. +*/ struct xen_tmem_client { + uint32_t version; /* If mismatched we will get XEN_EOPNOTSUPP. */ + uint32_t maxpools; /* If greater than what hypervisor supports, will get + XEN_ERANGE. */ union { /* See TMEM_CLIENT_[COMPRESS,FROZEN] */ uint32_t raw; struct {
@@ -807,6 +810,8 @@ struct xen_tmem_client { } flags;uint32_t weight; }; +typedef struct xen_tmem_client xen_tmem_client_t ; +DEFINE_XEN_GUEST_HANDLE (xen_tmem_client_t);struct xen_sysctl_tmem_op {uint32_t cmd;/* IN: XEN_SYSCTL_TMEM_OP_* . */
@@ -819,7 +824,9 @@ struct xen_sysctl_tmem_op {uint32_t pad;/* Padding so structure is the same under 32 and 64. */ xen_tmem_oid_t oid;/* IN: If not applicable to command use 0s. */ union { -XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save and restore ops. */ +XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save/restore */ +XEN_GUEST_HANDLE_64 (xen_tmem_client_t) client;/* IN/OUT for */ +/* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT. */ } u; };typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t ;
xen/include/xen/tmem_xen.h +1 -1
@@ -293,7 +293,7 @@ struct client {struct list_head ephemeral_page_list;long eph_count, eph_count_max;domid_t cli_id; -struct xen_tmem_client info; +xen_tmem_client_t info;bool_t shared_auth_required;/* For save/restore/migration. */ bool_t was_frozen;
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 7/9 tmem: Unify XEN_SYSCTL_TMEM_OP_[[SAVE_[BEGIN|END]|RESTORE_BEGIN]
In reply to Konrad Rzeszutek Wilkreturn values. For success they used to be 1 ([SAVE,RESTORE]_BEGIN), 0 if guest did not have any tmem (but only for SAVE_BEGIN), and -1 for any type of failure.
And SAVE_END (which you would think would mirror SAVE_BEGIN) had 0 for success and -1 if guest did not any tmem enabled for it.
This is confusing. Now the code will return 0 if the operation was success. Various XEN_EXX values are returned if tmem is not enabled or the operation could not performed.
The xc_tmem.c code only needs one place to check - where we use SAVE_BEGIN. The place where RESTORE_BEGIN is used will have errno with the proper error value and return will be -1, so will still fail properly.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: First submission
v2: Rework return value for XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN if
couldn't allocate tmem components.
Added Wei's Ack.
--- tools/libxc/xc_tmem.c | 14 +++++++++++--- xen/common/tmem.c | 17 +++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-)
tools/libxc/xc_tmem.c +11 -3
@@ -216,15 +216,23 @@ int xc_tmem_save(xc_interface *xch, int dom, int io_fd, int live, int field_marker) { int marker = field_marker; -int i, j; +int i, j, rc;uint32_t flags;uint32_t minusone =-1 ;uint32_t pool_id;struct tmem_handle *h;xen_tmem_client_t info; -if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_BEGIN ,dom,live,0 ,NULL ) <=0 ) -return 0 ; + rc =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_BEGIN , + dom, live,0 ,NULL ); +if ( rc ) + { +/* Nothing to save - no tmem enabled. */ +if ( errno ==ENOENT ) +return 0 ; + +return rc; + }if (write_exact (io_fd, &marker,sizeof (marker)) )return -1 ;
xen/common/tmem.c +9 -8
@@ -1656,30 +1656,31 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id,struct client *client =tmem_client_from_cli_id (cli_id);uint32_t p;struct tmem_page_descriptor *pgp, *pgp2; -int rc =-1 ; +int rc = -ENOENT ;switch (subop) {case XEN_SYSCTL_TMEM_OP_SAVE_BEGIN :if ( client ==NULL ) -return 0 ; +break ;for (p =0 ; p <MAX_POOLS_PER_DOMAIN ; p++)if ( client->pools[p] !=NULL )break ; +if ( p ==MAX_POOLS_PER_DOMAIN ) - { - rc =0 ;break ; - } + client->was_frozen = client->info.flags.u.frozen; client->info.flags.u.frozen =1 ;if ( arg1 !=0 ) client->info.flags.u.migrating =1 ; - rc =1 ; + rc =0 ;break ;case XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN : -if ( client ==NULL && (client =client_create (cli_id)) !=NULL ) -return 1 ; +if ( client ==NULL ) + rc =client_create (cli_id) ?0 : -ENOMEM ; +else + rc = -EEXIST ;break ;case XEN_SYSCTL_TMEM_OP_SAVE_END :if ( client ==NULL )
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 7/9] tmem: Unify XEN_SYSCTL_TMEM_OP_[[SAVE_[BEGIN|END]|RESTORE_BEGIN]
Quoted 11 lines · Konrad Rzeszutek Wilk
return values. For success they used to be 1 ([SAVE,RESTORE]_BEGIN), 0 if guest did not have any tmem (but only for
SAVE_BEGIN), and -1 for any type of failure.And
SAVE_END(which you would think would mirrorSAVE_BEGIN) had 0 for success and -1 if guest did not any tmem enabled for it.This is confusing. Now the code will return 0 if the operation was success. Various
XEN_EXXvalues are returned if tmem is not enabled or the operation could not performed.
Quoted 7 lines
The
xc_tmem.ccode only needs one place to check - where we useSAVE_BEGIN. The place whereRESTORE_BEGINis used will have errno with the proper error value and return will be -1, so will still fail properly.Acked-by Wei Liu <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 8/9 tmem/xc_tmem_control: Rename 'arg1' to 'len' and 'arg2' to arg.
In reply to Konrad Rzeszutek WilkThat is what they are used for. Lets make it more clear.
Of all the various sub-commands, the only one that needed semantic change is XEN_SYSCTL_TMEM_OP_SAVE_BEGIN. That in the past used 'arg1', and now we are moving it to use 'arg'. Since that code is only used during migration which is tied to the toolstack it is OK to change it.
We should increment the XEN_SYSCTL_INTERFACE_VERSION because of this, and that was fortunatly done in the patch titled:
"tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE].."
While at it, also fix xc_tmem_control_oid to properly handle the 'buf' and bounce it as appropiate.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: First submission.
v2: Added Wei's Ack.
Rebased on "tmem/sysctl: Add union in struct xen_sysctl_tmem_op" Expand the commit description to talk about XEN_SYSCTL_INTERFACE_VERSION.
--- tools/libxc/include/xenctrl.h | 4 ++-- tools/libxc/xc_tmem.c | 37 ++++++++++++++++++------------------- tools/libxl/libxl.c | 4 ++-- tools/python/xen/lowlevel/xc/xc.c | 16 ++++++++-------- xen/common/tmem.c | 16 ++++++++-------- xen/common/tmem_control.c | 8 ++++---- xen/include/public/sysctl.h | 4 ++-- 7 files changed, 44 insertions(+), 45 deletions(-)
tools/libxc/include/xenctrl.h +2 -2
@@ -2067,11 +2067,11 @@ int xc_disable_turbo(xc_interface *xch, int cpuid);*/ int xc_tmem_control_oid (xc_interface *xch,int32_t pool_id,uint32_t subop, -uint32_t cli_id,uint32_t arg1,uint32_t arg2, +uint32_t cli_id,uint32_t len,uint32_t arg,struct xen_tmem_oid oid,void *buf);int xc_tmem_control (xc_interface *xch,int32_t pool_id,uint32_t subop,uint32_t cli_id, -uint32_t arg1,uint32_t arg2,void *buf); +uint32_t len,uint32_t arg,void *buf);int xc_tmem_auth (xc_interface *xch,int cli_id,char *uuid_str,int arg1);int xc_tmem_save (xc_interface *xch,int dom,int live,int fd,int field_marker);int xc_tmem_save_extra (xc_interface *xch,int dom,int fd,int field_marker);
tools/libxc/xc_tmem.c +18 -19
@@ -49,20 +49,20 @@ int xc_tmem_control(xc_interface *xch,int32_t pool_id, uint32_t cmd, uint32_t cli_id, - uint32_t arg1, - uint32_t arg2, + uint32_t len, + uint32_t arg, void *buf) {DECLARE_SYSCTL ; -DECLARE_HYPERCALL_BOUNCE (buf, arg1,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +DECLARE_HYPERCALL_BOUNCE (buf, len,XC_HYPERCALL_BUFFER_BOUNCE_OUT );int rc; sysctl.cmd = XEN_SYSCTL_tmem_op; sysctl.u.tmem_op.pool_id = pool_id; sysctl.u.tmem_op.cmd = cmd; sysctl.u.tmem_op.cli_id = cli_id; - sysctl.u.tmem_op.arg1 = arg1; - sysctl.u.tmem_op.arg2 = arg2; + sysctl.u.tmem_op.len = len; + sysctl.u.tmem_op.arg = arg; sysctl.u.tmem_op.pad =0 ; sysctl.u.tmem_op.oid.oid[0 ] =0 ; sysctl.u.tmem_op.oid.oid[1 ] =0 ;
@@ -72,8 +72,7 @@ int xc_tmem_control(xc_interface *xch, {HYPERCALL_BOUNCE_SET_DIR (buf,XC_HYPERCALL_BUFFER_BOUNCE_IN ); } - -if ( arg1 ) +if ( len ) {if ( buf ==NULL ) {
@@ -91,7 +90,7 @@ int xc_tmem_control(xc_interface *xch, rc =do_sysctl (xch, &sysctl); -if ( arg1 ) +if ( len )xc_hypercall_bounce_post (xch, buf);return rc;
@@ -101,25 +100,25 @@ int xc_tmem_control_oid(xc_interface *xch,int32_t pool_id, uint32_t cmd, uint32_t cli_id, - uint32_t arg1, - uint32_t arg2, + uint32_t len, + uint32_t arg, struct xen_tmem_oid oid, void *buf) {DECLARE_SYSCTL ; -DECLARE_HYPERCALL_BOUNCE (buf, arg1,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +DECLARE_HYPERCALL_BOUNCE (buf, len,XC_HYPERCALL_BUFFER_BOUNCE_OUT );int rc; sysctl.cmd = XEN_SYSCTL_tmem_op; sysctl.u.tmem_op.pool_id = pool_id; sysctl.u.tmem_op.cmd = cmd; sysctl.u.tmem_op.cli_id = cli_id; - sysctl.u.tmem_op.arg1 = arg1; - sysctl.u.tmem_op.arg2 = arg2; + sysctl.u.tmem_op.len = len; + sysctl.u.tmem_op.arg = arg; sysctl.u.tmem_op.pad =0 ; sysctl.u.tmem_op.oid = oid; -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) +if ( len ) {if ( buf ==NULL ) {
@@ -137,8 +136,8 @@ int xc_tmem_control_oid(xc_interface *xch, rc =do_sysctl (xch, &sysctl); -if ( cmd ==XEN_SYSCTL_TMEM_OP_LIST && arg1 !=0 ) -xc_hypercall_bounce_post (xch, buf); +if ( len ) +xc_hypercall_bounce_post (xch, buf);return rc; }
@@ -224,7 +223,7 @@ int xc_tmem_save(xc_interface *xch,xen_tmem_client_t info; rc =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_BEGIN , - dom, live,0 ,NULL ); + dom,0 /* len*/ , live,NULL );if ( rc ) {/* Nothing to save - no tmem enabled. */
@@ -239,7 +238,7 @@ int xc_tmem_save(xc_interface *xch,if (xc_tmem_control (xch,0 /* pool_id */ ,XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , - dom/* cli_id */ ,sizeof (info)/* arg1 */ ,0 /* arg2 */ , + dom/* cli_id */ ,sizeof (info),0 /* arg */ , &info) <0 )return -1 ;
@@ -396,7 +395,7 @@ int xc_tmem_restore(xc_interface *xch, int dom, int io_fd)if (xc_tmem_control (xch,0 /* pool_id */ ,XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO , - dom/* cli_id */ ,sizeof (info)/* arg1 */ ,0 /* arg2 */ , + dom/* cli_id */ ,sizeof (info),0 /* arg */ , &info) <0 )return -1 ;
tools/libxl/libxl.c +2 -2
@@ -6173,7 +6173,7 @@ int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set) r =xc_tmem_control (ctx->xch,-1 /* pool_id */ ,XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , - domid,sizeof (info),0 /* arg2 */ , &info); + domid,sizeof (info),0 /* arg */ , &info);if (r <0 ) {LOGE (ERROR ,"Can not get tmem data!" ); rc =ERROR_FAIL ;
@@ -6187,7 +6187,7 @@ int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set) } r =xc_tmem_control (ctx->xch,-1 /* pool_id */ ,XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO , - domid,sizeof (info),0 /* arg2 */ , &info); + domid,sizeof (info),0 /* arg */ , &info);if (r <0 ) {LOGE (ERROR ,"Can not set tmem %s" , name); rc =ERROR_FAIL ;
tools/python/xen/lowlevel/xc/xc.c +8 -8
@@ -1612,8 +1612,8 @@ static PyObject *pyxc_tmem_control(XcObject *self,int32_t pool_id;uint32_t subop;uint32_t cli_id; -uint32_t arg1; -uint32_t arg2; +uint32_t len; +uint32_t arg;char *buf;char _buffer[32768 ], *buffer = _buffer;int rc;
@@ -1621,13 +1621,13 @@ static PyObject *pyxc_tmem_control(XcObject *self,static char *kwd_list[] = {"pool_id" ,"subop" ,"cli_id" ,"arg1" ,"arg2" ,"buf" ,NULL };if ( !PyArg_ParseTupleAndKeywords (args, kwds,"iiiiis" , kwd_list, - &pool_id, &subop, &cli_id, &arg1, &arg2, &buf) ) + &pool_id, &subop, &cli_id, &len, &arg, &buf) )return NULL ; -if ( (subop ==XEN_SYSCTL_TMEM_OP_LIST ) && (arg1 >32768 ) ) - arg1 =32768 ; +if ( (subop ==XEN_SYSCTL_TMEM_OP_LIST ) && (len >32768 ) ) + len =32768 ; -if ( (rc =xc_tmem_control (self->xc_handle, pool_id, subop, cli_id, arg1, arg2, buffer)) <0 ) +if ( (rc =xc_tmem_control (self->xc_handle, pool_id, subop, cli_id, len, arg, buffer)) <0 )return Py_BuildValue ("i" , rc);switch (subop) {
@@ -2506,8 +2506,8 @@ static PyMethodDef pyxc_methods[] = {" pool_id [int]: Identifier of the tmem pool (-1 == all).\n" " subop [int]: Supplementary Operation.\n" " cli_id [int]: Client identifier (-1 == all).\n" -" arg1 [int]: Argument.\n" -" arg2 [int]: Argument.\n" +" len [int]: Length of 'buf'.\n" +" arg [int]: Argument.\n" " buf [str]: Buffer.\n\n" "Returns: [int] 0 or [str] tmem info on success; exception on error.\n" },
xen/common/tmem.c +8 -8
@@ -1651,7 +1651,7 @@ static int tmemc_shared_pool_auth(domid_t cli_id, uint64_t uuid_lo, }static int tmemc_save_subop (int cli_id,uint32_t pool_id, -uint32_t subop,tmem_cli_va_param_t buf,uint32_t arg1) +uint32_t subop,tmem_cli_va_param_t buf,uint32_t arg) {struct client *client =tmem_client_from_cli_id (cli_id);uint32_t p;
@@ -1672,7 +1672,7 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id, client->was_frozen = client->info.flags.u.frozen; client->info.flags.u.frozen =1 ; -if ( arg1 !=0 ) +if ( arg !=0 ) client->info.flags.u.migrating =1 ; rc =0 ;break ;
@@ -1844,22 +1844,22 @@ int do_tmem_control(struct xen_sysctl_tmem_op *op)case XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN :case XEN_SYSCTL_TMEM_OP_SAVE_END : ret =tmemc_save_subop (op->cli_id, pool_id, cmd, -guest_handle_cast (op->u.buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg);break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE : ret =tmemc_save_get_next_page (op->cli_id, pool_id, -guest_handle_cast (op->u.buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->len);break ;case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_INV : ret =tmemc_save_get_next_inv (op->cli_id, -guest_handle_cast (op->u.buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->len);break ;case XEN_SYSCTL_TMEM_OP_RESTORE_PUT_PAGE : - ret =tmemc_restore_put_page (op->cli_id, pool_id, oidp, op->arg2, -guest_handle_cast (op->u.buf, char), op->arg1); + ret =tmemc_restore_put_page (op->cli_id, pool_id, oidp, op->arg, +guest_handle_cast (op->u.buf, char), op->len);break ;case XEN_SYSCTL_TMEM_OP_RESTORE_FLUSH_PAGE : - ret =tmemc_restore_flush_page (op->cli_id, pool_id, oidp, op->arg2); + ret =tmemc_restore_flush_page (op->cli_id, pool_id, oidp, op->arg);break ;default : ret =-1 ;
xen/common/tmem_control.c +4 -4
@@ -344,7 +344,7 @@ static int tmemc_get_client_info(int cli_id, }static int tmemc_save_subop (int cli_id,uint32_t pool_id,uint32_t subop, -XEN_GUEST_HANDLE_PARAM (char ) buf,uint32_t arg1) +XEN_GUEST_HANDLE_PARAM (char ) buf,uint32_t arg) {struct client *client =tmem_client_from_cli_id (cli_id);struct tmem_pool *pool = (client ==NULL || pool_id >=MAX_POOLS_PER_DOMAIN )
@@ -398,11 +398,11 @@ int tmem_control(struct xen_sysctl_tmem_op *op) ret =tmemc_freeze_pools (op->cli_id, cmd);break ;case XEN_SYSCTL_TMEM_OP_FLUSH : - ret =tmemc_flush_mem (op->cli_id,op->arg1); + ret =tmemc_flush_mem (op->cli_id, op->arg);break ;case XEN_SYSCTL_TMEM_OP_LIST : ret =tmemc_list (op->cli_id, -guest_handle_cast (op->u.buf, char), op->arg1, op->arg2); +guest_handle_cast (op->u.buf, char), op->len, op->arg);break ;case XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO : ret =tmemc_set_client_info (op->cli_id, op->u.client);
@@ -417,7 +417,7 @@ int tmem_control(struct xen_sysctl_tmem_op *op)case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES :case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID : ret =tmemc_save_subop (op->cli_id, pool_id, cmd, -guest_handle_cast (op->u.buf, char), op->arg1); +guest_handle_cast (op->u.buf, char), op->arg);break ;default : ret =do_tmem_control (op);
xen/include/public/sysctl.h +2 -2
@@ -819,8 +819,8 @@ struct xen_sysctl_tmem_op {uint32_t cli_id;/* IN: client id, 0 for XEN_SYSCTL_TMEM_QUERY_FREEABLE_MB for all others can be the domain id or XEN_SYSCTL_TMEM_OP_ALL_CLIENTS for all. */ -uint32_t arg1;/* IN: If not applicable to command use 0. */ -uint32_t arg2;/* IN: If not applicable to command use 0. */ +uint32_t len;/* IN: length of 'buf'. If not applicable to use 0. */ +uint32_t arg;/* IN: If not applicable to command use 0. */ uint32_t pad;/* Padding so structure is the same under 32 and 64. */ xen_tmem_oid_t oid;/* IN: If not applicable to command use 0s. */ union {
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 8/9] tmem/xc_tmem_control: Rename 'arg1' to 'len' and 'arg2' to arg.
Quoted 12 lines · Konrad Rzeszutek Wilk
That is what they are used for. Lets make it more clear.
Of all the various sub-commands, the only one that needed semantic change is
XEN_SYSCTL_TMEM_OP_SAVE_BEGIN. That in the past used 'arg1', and now we are moving it to use 'arg'. Since that code is only used during migration which is tied to the toolstack it is OK to change it.We should increment the
XEN_SYSCTL_INTERFACE_VERSIONbecause of this, and that was fortunatly done in the patch titled:
"tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE].."
Quoted 5 lines
While at it, also fix
xc_tmem_control_oidto properly handle the 'buf' and bounce it as appropiate.Acked-by Wei Liu <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 9/9 tmem: Batch and squash XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_[FLAGS, NPAGES, UUID] in one sub-call: XEN_SYSCTL_TMEM_OP_GET_POOLS.
In reply to Konrad Rzeszutek WilkThese operations are used during the save process of migration. Instead of doing 64 hypercalls lets do just one. We modify the 'struct xen_tmem_client' structure (used in XEN_SYSCTL_TMEM_OP_[GET|SET]_CLIENT_INFO) to have an extra field 'nr_pools'. Armed with that the code slurping up pages from the hypervisor can allocate a big enough structure (struct tmem_pool_info) to contain all the active pools. And then just iterate over each one and save it in the stream.
We are also re-using one of the subcommands numbers for this, as such the XEN_SYSCTL_INTERFACE_VERSION should be incremented and that was done in the patch titled:
"tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE].."
In the xc_tmem_[save|restore] we also added proper memory handling of the 'buf' and 'pools'. Because of the loops and to make it as easy as possible to review we add a goto label and for almost all error conditions jump in it.
The include for inttypes is required for the PRId64 macro to work (which is needed to compile this code under 32-bit).
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v1: First submission.
v2: Added Wei's Ack.
- Removed stray blanks
- Remove sysctl from xen_sysctl_tmem_pool_info name
- s/tmem_pool_info/xen_tmem_pool_info/
- Fix the >= one-off
- Used uint64_aligned_t instead of uint64_t for the uuid.
- Expand in the git commit description about the interface update
- Reuse the subcommand number 7 instead of 16.
--- tools/libxc/xc_tmem.c | 159 +++++++++++++++++++++++++------------------- xen/common/tmem.c | 3 + xen/common/tmem_control.c | 78 +++++++++++++--------- xen/include/public/sysctl.h | 33 ++++++++- 4 files changed, 172 insertions(+), 101 deletions(-)
tools/libxc/xc_tmem.c +92 -67
@@ -18,6 +18,7 @@*/ #include "xc_private.h" +#include <inttypes.h> #include <assert.h> #include <xen/tmem.h>
@@ -216,11 +217,11 @@ int xc_tmem_save(xc_interface *xch, {int marker = field_marker;int i, j, rc; -uint32_t flags;uint32_t minusone =-1 ; -uint32_t pool_id;struct tmem_handle *h;xen_tmem_client_t info; +xen_tmem_pool_info_t *pools; +char *buf =NULL ; rc =xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_SAVE_BEGIN , dom,0 /* len*/ , live,NULL );
@@ -233,72 +234,82 @@ int xc_tmem_save(xc_interface *xch,return rc; } -if (write_exact (io_fd, &marker,sizeof (marker)) ) -return -1 ; -if (xc_tmem_control (xch,0 /* pool_id */ ,XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO , dom/* cli_id */ ,sizeof (info),0 /* arg */ , &info) <0 )return -1 ; -if (write_exact (io_fd, &info,sizeof (info)) ) +/* Nothing to do. */ +if ( !info.nr_pools ) +return 0 ; + + pools =calloc (info.nr_pools,sizeof (*pools)); +if ( !pools )return -1 ; + + rc =xc_tmem_control (xch,0 /* pool_id is ignored. */ , +XEN_SYSCTL_TMEM_OP_GET_POOLS , + dom/* cli_id */ ,sizeof (*pools) * info.nr_pools, +0 /* arg */ , pools); + +if ( rc <0 || (uint32_t )rc > info.nr_pools ) + goto out_memory; + +/* Update it - as we have less pools between the two hypercalls. */ + info.nr_pools = (uint32_t )rc; + +if (write_exact (io_fd, &marker,sizeof (marker)) ) + goto out_memory; + +if (write_exact (io_fd, &info,sizeof (info)) ) + goto out_memory; +if (write_exact (io_fd, &minusone,sizeof (minusone)) ) -return -1 ; -for ( i =0 ; i < info.maxpools; i++ ) + goto out_memory; + +for ( i =0 ; i < info.nr_pools; i++ ) { -uint64_t uuid[2 ]; -uint32_t n_pages;uint32_t pagesize; -char *buf =NULL ;int bufsize =0 ;int checksum =0 ; +xen_tmem_pool_info_t *pool = &pools[i]; -/* get pool id, flags, pagesize, n_pages, uuid */ - flags =xc_tmem_control (xch,i,XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS ,dom,0 ,0 ,NULL ); -if ( flags !=-1 ) +if ( pool->flags.raw !=-1 ) { - pool_id = i; - n_pages =xc_tmem_control (xch,i,XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES ,dom,0 ,0 ,NULL ); -if ( !(flags &TMEM_POOL_PERSIST ) ) - n_pages =0 ; - (void )xc_tmem_control (xch,i,XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID ,dom,sizeof (uuid),0 ,&uuid); -if (write_exact (io_fd, &pool_id,sizeof (pool_id)) ) -return -1 ; -if (write_exact (io_fd, &flags,sizeof (flags)) ) -return -1 ; -if (write_exact (io_fd, &n_pages,sizeof (n_pages)) ) -return -1 ; -if (write_exact (io_fd, &uuid,sizeof (uuid)) ) -return -1 ; -if ( n_pages ==0 ) +if ( !pool->flags.u.persist ) + pool->n_pages =0 ; + +if (write_exact (io_fd, pool,sizeof (*pool)) ) + goto out_memory; + +if ( !pool->flags.u.persist )continue ; - pagesize =1 << (((flags >>TMEM_POOL_PAGESIZE_SHIFT ) & -TMEM_POOL_PAGESIZE_MASK ) +12 ); + pagesize =1 << (pool->flags.u.pagebits +12 );if ( pagesize > bufsize ) { bufsize = pagesize +sizeof (struct tmem_handle );if ( (buf =realloc (buf,bufsize)) ==NULL ) -return -1 ; + goto out_memory; } -for ( j = n_pages; j >0 ; j-- ) +for ( j = pool->n_pages; j >0 ; j-- ) {int ret; -if ( (ret =xc_tmem_control (xch, pool_id, +if ( (ret =xc_tmem_control (xch, pool->id,XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE , dom, bufsize,0 , buf)) >0 ) { h = (struct tmem_handle *)buf;if (write_exact (io_fd, &h->oid,sizeof (h->oid)) ) -return -1 ; + goto out_memory; +if (write_exact (io_fd, &h->index,sizeof (h->index)) ) -return -1 ; + goto out_memory; h++; checksum += *(char *)h;if (write_exact (io_fd, h, pagesize) ) -return -1 ; + goto out_memory; }else if ( ret ==0 ) {continue ; }else {
@@ -306,14 +317,22 @@ int xc_tmem_save(xc_interface *xch, h = (struct tmem_handle *)buf; h->oid.oid[0 ] = h->oid.oid[1 ] = h->oid.oid[2 ] =-1L ;if (write_exact (io_fd, &h->oid,sizeof (h->oid)) ) + { + out_memory: +free (pools); +free (buf);return -1 ; + }break ; } } -DPRINTF ("saved %d tmem pages for dom=%d pool=%d, checksum=%x\n" , - n_pages-j,dom,pool_id,checksum); +DPRINTF ("saved %" PRId64" tmem pages for dom=%d pool=%d, checksum=%x\n" , + pool->n_pages - j, dom, pool->id, checksum); } } +free (pools); +free (buf); +/* pool list terminator */ minusone =-1 ;if (write_exact (io_fd, &minusone,sizeof (minusone)) )
@@ -382,14 +401,19 @@ static int xc_tmem_restore_new_pool(int xc_tmem_restore (xc_interface *xch,int dom,int io_fd) { -uint32_t pool_id;uint32_t minusone; -uint32_t flags;xen_tmem_client_t info;int checksum =0 ; +unsigned int i; +char *buf =NULL ;if (read_exact (io_fd, &info,sizeof (info)) )return -1 ; + +/* We would never save if there weren't any pools! */ +if ( !info.nr_pools ) +return -1 ; +if (xc_tmem_control (xch,0 ,XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN ,dom,0 ,0 ,NULL ) <0 )return -1 ;
@@ -401,62 +425,63 @@ int xc_tmem_restore(xc_interface *xch, int dom, int io_fd)if (read_exact (io_fd, &minusone,sizeof (minusone)) )return -1 ; -while (read_exact (io_fd, &pool_id,sizeof (pool_id)) ==0 && pool_id !=-1 ) + +for ( i =0 ; i < info.nr_pools; i++ ) { -uint64_t uuid[2 ]; -uint32_t n_pages; -char *buf =NULL ;int bufsize =0 , pagesize;int j; +xen_tmem_pool_info_t pool; -if (read_exact (io_fd, &flags,sizeof (flags)) ) -return -1 ; -if (read_exact (io_fd, &n_pages,sizeof (n_pages)) ) -return -1 ; -if (read_exact (io_fd, &uuid,sizeof (uuid)) ) -return -1 ; -if (xc_tmem_restore_new_pool (xch, dom, pool_id, - flags, uuid[0 ], uuid[1 ]) <0 ) -return -1 ; -if ( n_pages <=0 ) +if (read_exact (io_fd, &pool,sizeof (pool)) ) + goto out_memory; + +if (xc_tmem_restore_new_pool (xch, dom, pool.id, pool.flags.raw, + pool.uuid[0 ], pool.uuid[1 ]) <0 ) + goto out_memory; + +if ( pool.n_pages <=0 )continue ; - pagesize =1 << (((flags >>TMEM_POOL_PAGESIZE_SHIFT ) & -TMEM_POOL_PAGESIZE_MASK ) +12 ); + pagesize =1 << (pool.flags.u.pagebits +12 );if ( pagesize > bufsize ) { bufsize = pagesize;if ( (buf =realloc (buf,bufsize)) ==NULL ) -return -1 ; + goto out_memory; } -for ( j = n_pages; j >0 ; j-- ) +for ( j = pool.n_pages; j >0 ; j-- ) {struct xen_tmem_oid oid;uint32_t index;int rc; +if (read_exact (io_fd, &oid,sizeof (oid)) ) -return -1 ; + goto out_memory; +if ( oid.oid[0 ] ==-1L && oid.oid[1 ] ==-1L && oid.oid[2 ] ==-1L )break ;if (read_exact (io_fd, &index,sizeof (index)) ) -return -1 ; + goto out_memory; +if (read_exact (io_fd, buf, pagesize) ) -return -1 ; + goto out_memory; + checksum += *buf; -if ( (rc =xc_tmem_control_oid (xch, pool_id, +if ( (rc =xc_tmem_control_oid (xch, pool.id,XEN_SYSCTL_TMEM_OP_RESTORE_PUT_PAGE , dom, bufsize, index, oid, buf)) <=0 ) {DPRINTF ("xc_tmem_restore: putting page failed, rc=%d\n" ,rc); + out_memory: +free (buf);return -1 ; } } -if ( n_pages ) -DPRINTF ("restored %d tmem pages for dom=%d pool=%d, check=%x\n" , - n_pages-j,dom,pool_id,checksum); +if ( pool.n_pages ) +DPRINTF ("restored %" PRId64" tmem pages for dom=%d pool=%d, check=%x\n" , + pool.n_pages - j, dom, pool.id, checksum); } -if ( pool_id !=-1 ) -return -1 ; +free (buf);return 0 ; }
xen/common/tmem.c +3 -0
@@ -880,6 +880,7 @@ static void client_flush(struct client *client)continue ;pool_flush (pool, client->cli_id); client->pools[i] =NULL ; + client->info.nr_pools--; }client_free (client); }
@@ -1430,6 +1431,7 @@ static int do_tmem_destroy_pool(uint32_t pool_id)return 0 ; client->pools[pool_id] =NULL ;pool_flush (pool, client->cli_id); + client->info.nr_pools--;return 1 ; }
@@ -1592,6 +1594,7 @@ static int do_tmem_new_pool(domid_t this_cli_id, out:tmem_client_info ("pool_id=%d\n" , d_poolid); + client->info.nr_pools++;return d_poolid; fail:
xen/common/tmem_control.c +47 -31
110 lines not on this page · raw message
xen/include/public/sysctl.h +30 -3
@@ -769,11 +769,9 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_psr_cat_op_t);#define XEN_SYSCTL_TMEM_OP_LIST 4#define XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO 5#define XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO 6 +#define XEN_SYSCTL_TMEM_OP_GET_POOLS 7#define XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB 8#define XEN_SYSCTL_TMEM_OP_SAVE_BEGIN 10 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS 16 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES 17 -#define XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID 18#define XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE 19#define XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_INV 20#define XEN_SYSCTL_TMEM_OP_SAVE_END 21
@@ -800,6 +798,7 @@ struct xen_tmem_client {uint32_t version;/* If mismatched we will get XEN_EOPNOTSUPP. */ uint32_t maxpools;/* If greater than what hypervisor supports, will get XEN_ERANGE. */ +uint32_t nr_pools;/* Current amount of pools. Ignored on SET*/ union {/* See TMEM_CLIENT_[COMPRESS,FROZEN] */ uint32_t raw;struct {
@@ -813,6 +812,31 @@ struct xen_tmem_client {typedef struct xen_tmem_client xen_tmem_client_t ;DEFINE_XEN_GUEST_HANDLE (xen_tmem_client_t); +/* +* XEN_SYSCTL_TMEM_OP_GET_POOLS uses the 'pool' array in +* xen_sysctl_tmem_op with this structure. The hypercall will +* return the number of entries in 'pool' or a negative value +* if an error was encountered. +*/ +struct xen_tmem_pool_info { +union { +uint32_t raw; +struct { +uint32_t persist:1 ,/* See TMEM_POOL_PERSIST. */ + shared:1 ,/* See TMEM_POOL_SHARED. */ + rsv:2 , + pagebits:8 ,/* TMEM_POOL_PAGESIZE_[SHIFT,MASK]. */ + rsv2:12 , + version:8 ;/* TMEM_POOL_VERSION_[SHIFT,MASK]. */ + } u; + } flags; +uint32_t id;/* Less than tmem_client.maxpools. */ +uint64_t n_pages; +uint64_aligned_t uuid[2 ]; +}; +typedef struct xen_tmem_pool_info xen_tmem_pool_info_t ; +DEFINE_XEN_GUEST_HANDLE (xen_tmem_pool_info_t); +struct xen_sysctl_tmem_op {uint32_t cmd;/* IN: XEN_SYSCTL_TMEM_OP_* . */ int32_t pool_id;/* IN: 0 by default unless _SAVE_*, RESTORE_* .*/
@@ -827,6 +851,9 @@ struct xen_sysctl_tmem_op {XEN_GUEST_HANDLE_64 (char ) buf;/* IN/OUT: Buffer to save/restore */ XEN_GUEST_HANDLE_64 (xen_tmem_client_t) client;/* IN/OUT for */ /* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT. */ +XEN_GUEST_HANDLE_64 (xen_tmem_pool_info_t) pool;/* OUT for */ +/* XEN_SYSCTL_TMEM_OP_GET_POOLS. Must have 'len' */ +/* of them. */ } u; };typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t ;
Signature · 7 lines
2.4.11 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 9/9] tmem: Batch and squash XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_[FLAGS, NPAGES, UUID] in one sub-call: XEN_SYSCTL_TMEM_OP_GET_POOLS.
Quoted 19 lines · Konrad Rzeszutek Wilk
These operations are used during the save process of migration. Instead of doing 64 hypercalls lets do just one. We modify the 'struct
xen_tmem_client' structure (used in XEN_SYSCTL_TMEM_OP_[GET|SET]_CLIENT_INFO) to have an extra field 'nr_pools'. Armed with that the code slurping up pages from the hypervisor can allocate a big enough structure (structtmem_pool_info) to contain all the active pools. And then just iterate over each one and save it in the stream.We are also re-using one of the subcommands numbers for this, as such the
XEN_SYSCTL_INTERFACE_VERSIONshould be incremented and that was done in the patch titled:
"tmem/libxc: Squash XEN_SYSCTL_TMEM_OP_[SET|SAVE].."In the xc_tmem_[save|restore] we also added proper memory handling of the 'buf' and 'pools'. Because of the loops and to make it as easy as possible to review we add a goto label and for almost all error conditions jump in it.
Quoted 5 lines
The include for inttypes is required for the PRId64 macro to work (which is needed to compile this code under 32-bit).
Acked-by Wei Liu <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel