tools: use xc_is_known_page_type
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 tools: add xc_is_known_page_type to libxenctrl
Users of xc_get_pfn_type_batch may want to sanity check the data returned by Xen. Add a simple helper for this purpose.
Signed-off-by Olaf Hering <[email protected]>
--- tools/libs/ctrl/xc_private.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
tools/libs/ctrl/xc_private.h +33 -0
@@ -421,6 +421,39 @@ void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,int xc_get_pfn_type_batch (xc_interface *xch,uint32_t dom,unsigned int num,xen_pfn_t *); +/* Sanitiy check for types returned by Xen */ +static inline bool xc_is_known_page_type (xen_pfn_t type) +{ +bool ret; + +switch (type) + { +case XEN_DOMCTL_PFINFO_NOTAB : + +case XEN_DOMCTL_PFINFO_L1TAB : +case XEN_DOMCTL_PFINFO_L1TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L2TAB : +case XEN_DOMCTL_PFINFO_L2TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L3TAB : +case XEN_DOMCTL_PFINFO_L3TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L4TAB : +case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_XTAB : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_BROKEN : + ret = true; +break ; +default : + ret = false; +break ; + } +return ret; +} +void bitmap_64_to_byte (uint8_t *bp,const uint64_t *lp,int nbits);void bitmap_byte_to_64 (uint64_t *lp,const uint8_t *bp,int nbits);
PATCH 2/3 tools: use xc_is_known_page_type
In reply to a message not in the archiveVerify pfn type on sending side, also verify incoming batch of pfns.
Signed-off-by Olaf Hering <[email protected]>
--- tools/libs/guest/xg_sr_restore.c | 3 +-- tools/libs/guest/xg_sr_save.c | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-)
tools/libs/guest/xg_sr_restore.c +1 -2
@@ -406,8 +406,7 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) } type = (pages->pfn[i] &PAGE_DATA_TYPE_MASK ) >>32 ; -if ( ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) >=5 ) && - ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) <=8 ) ) +if (xc_is_known_page_type (type) == false ) {ERROR ("Invalid type %#" PRIx32" for pfn %#" PRIpfn" (index %u)" , type, pfn, i);
tools/libs/guest/xg_sr_save.c +6 -0
@@ -147,6 +147,12 @@ static int write_batch(struct xc_sr_context *ctx)for ( i =0 ; i < nr_pfns; ++i ) { +if (xc_is_known_page_type (types[i]) == false ) + { +ERROR ("Wrong type %#" PRIpfn" for pfn %#" PRIpfn, types[i], mfns[i]); + goto err; + } +switch ( types[i] ) {case XEN_DOMCTL_PFINFO_BROKEN :
PATCH 3/3 tools: unify type checking for data pfns in migration stream
In reply to a message not in the archiveIntroduce a helper which decides if a given pfn type has data for the migration stream.
No change in behavior intended.
Signed-off-by Olaf Hering <[email protected]>
--- tools/libs/guest/xg_sr_common.h | 17 ++++++++++++++++ tools/libs/guest/xg_sr_restore.c | 34 +++++--------------------------- tools/libs/guest/xg_sr_save.c | 14 ++----------- 3 files changed, 24 insertions(+), 41 deletions(-)
tools/libs/guest/xg_sr_common.h +17 -0
@@ -455,6 +455,23 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned int count,/* Handle a STATIC_DATA_END record. */ int handle_static_data_end (struct xc_sr_context *ctx); +static inline bool page_type_has_stream_data (uint32_t type) +{ +bool ret; + +switch (type) + { +case XEN_DOMCTL_PFINFO_XTAB : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_BROKEN : + ret = false; +break ; +default : + ret = true; +break ; + } +return ret; +}#endif /* * Local variables:
tools/libs/guest/xg_sr_restore.c +5 -29
@@ -152,9 +152,8 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned int count,for ( i =0 ; i < count; ++i ) { -if ( (!types || (types && - (types[i] !=XEN_DOMCTL_PFINFO_XTAB && - types[i] !=XEN_DOMCTL_PFINFO_BROKEN ))) && +if ( (!types || + (types &&page_type_has_stream_data (types[i]) == true)) && !pfn_is_populated (ctx, original_pfns[i]) ) { rc =pfn_set_populated (ctx, original_pfns[i]);
@@ -233,25 +232,8 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned int count, { ctx->restore.ops.set_page_type (ctx, pfns[i], types[i]); -switch ( types[i] ) - { -case XEN_DOMCTL_PFINFO_NOTAB : - -case XEN_DOMCTL_PFINFO_L1TAB : -case XEN_DOMCTL_PFINFO_L1TAB |XEN_DOMCTL_PFINFO_LPINTAB : - -case XEN_DOMCTL_PFINFO_L2TAB : -case XEN_DOMCTL_PFINFO_L2TAB |XEN_DOMCTL_PFINFO_LPINTAB : - -case XEN_DOMCTL_PFINFO_L3TAB : -case XEN_DOMCTL_PFINFO_L3TAB |XEN_DOMCTL_PFINFO_LPINTAB : - -case XEN_DOMCTL_PFINFO_L4TAB : -case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : - +if (page_type_has_stream_data (types[i]) == true ) mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn (ctx, pfns[i]); -break ; - } }/* Nothing to do? */
@@ -271,14 +253,8 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned int count,for ( i =0 , j =0 ; i < count; ++i ) { -switch ( types[i] ) - { -case XEN_DOMCTL_PFINFO_XTAB : -case XEN_DOMCTL_PFINFO_BROKEN : -case XEN_DOMCTL_PFINFO_XALLOC : -/* No page data to deal with. */ +if (page_type_has_stream_data (types[i]) == false )continue ; - }if ( map_errs[j] ) {
@@ -413,7 +389,7 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) goto err; } -if ( type <XEN_DOMCTL_PFINFO_BROKEN ) +if (page_type_has_stream_data (type) == true )/* NOTAB and all L1 through L4 tables (including pinned) should * have a page worth of data in the record. */ pages_of_data++;
tools/libs/guest/xg_sr_save.c +2 -12
@@ -153,13 +153,8 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } -switch ( types[i] ) - { -case XEN_DOMCTL_PFINFO_BROKEN : -case XEN_DOMCTL_PFINFO_XALLOC : -case XEN_DOMCTL_PFINFO_XTAB : +if (page_type_has_stream_data (types[i]) == false )continue ; - } mfns[nr_pages++] = mfns[i]; }
@@ -177,13 +172,8 @@ static int write_batch(struct xc_sr_context *ctx)for ( i =0 , p =0 ; i < nr_pfns; ++i ) { -switch ( types[i] ) - { -case XEN_DOMCTL_PFINFO_BROKEN : -case XEN_DOMCTL_PFINFO_XALLOC : -case XEN_DOMCTL_PFINFO_XTAB : +if (page_type_has_stream_data (types[i]) == false )continue ; - }if ( errors[p] ) {