libxc: domain builder related enhancements
cover libxc: domain builder related enhancements
Add some more checks for having got allocated memory in the domain builder. Related to this add an INVALID_PFN macro to be able to do these checks.
Juergen Gross (2):
libxc: replace INVALID_P2M_ENTRY by INVALID_PFN
libxc: do proper return code checking of allocator in domain builder
tools/libxc/include/xc_dom.h | 2 +- tools/libxc/xc_compression.c | 10 +++++----- tools/libxc/xc_core.c | 4 ++-- tools/libxc/xc_dom_arm.c | 2 +- tools/libxc/xc_dom_core.c | 11 ++++++++--- tools/libxc/xc_dom_x86.c | 12 +++++++++++- tools/libxc/xc_offline_page.c | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-)
Signature · 1 line
2.6.2
PATCH 1/2 libxc: replace INVALID_P2M_ENTRY by INVALID_PFN
INVALID_P2M_ENTRY is defined as (xen_pfn_t)-1 and is often used according to it's type for an invalid pfn. Change the name of the macro to INVALID_PFN.
--- tools/libxc/include/xc_dom.h | 2 +- tools/libxc/xc_compression.c | 10 +++++----- tools/libxc/xc_core.c | 4 ++-- tools/libxc/xc_dom_arm.c | 2 +- tools/libxc/xc_dom_core.c | 4 ++-- tools/libxc/xc_dom_x86.c | 2 +- tools/libxc/xc_offline_page.c | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-)
tools/libxc/include/xc_dom.h +1 -1
@@ -19,7 +19,7 @@#include <xen/libelf/libelf.h> #include <xenguest.h> -#define INVALID_P2M_ENTRY ((xen_pfn_t)-1) +#define INVALID_PFN ((xen_pfn_t)-1)/* --- typedefs and structs ---------------------------------------- */
tools/libxc/xc_compression.c +5 -5
@@ -217,7 +217,7 @@ char *get_cache_page(comp_ctx *ctx, xen_pfn_t pfn,/* If the list is full, evict a page from the tail end. */ item = ctx->page_list_tail; -if (item->pfn !=INVALID_P2M_ENTRY ) +if (item->pfn !=INVALID_PFN ) ctx->pfn2cache[item->pfn] =NULL ; item->pfn = pfn;
@@ -278,7 +278,7 @@ void invalidate_cache_page(comp_ctx *ctx, xen_pfn_t pfn) ctx->page_list_tail = item; } ctx->pfn2cache[pfn] =NULL ; - (ctx->page_list_tail)->pfn =INVALID_P2M_ENTRY ; + (ctx->page_list_tail)->pfn =INVALID_PFN ; } }
@@ -295,7 +295,7 @@ int xc_compression_add_page(xc_interface *xch, comp_ctx *ctx,/* pagetable page */ if (israw)invalidate_cache_page (ctx, pfn); - ctx->sendbuf_pfns[ctx->pfns_len] = israw ?INVALID_P2M_ENTRY : pfn; + ctx->sendbuf_pfns[ctx->pfns_len] = israw ?INVALID_PFN : pfn;memcpy (ctx->inputbuf + ctx->pfns_len *XC_PAGE_SIZE , page,XC_PAGE_SIZE ); ctx->pfns_len++;
@@ -329,7 +329,7 @@ int xc_compression_compress_pages(xc_interface *xch, comp_ctx *ctx, cache_copy =NULL ; current_page = ctx->inputbuf + ctx->pfns_index *XC_PAGE_SIZE ; -if (ctx->sendbuf_pfns[ctx->pfns_index] ==INVALID_P2M_ENTRY ) +if (ctx->sendbuf_pfns[ctx->pfns_index] ==INVALID_PFN ) israw =1 ;else cache_copy = get_cache_page(ctx,
@@ -518,7 +518,7 @@ comp_ctx *xc_compression_create_context(xc_interface *xch,for (i =0 ; i < num_cache_pages; i++) { - ctx->cache[i].pfn =INVALID_P2M_ENTRY ; + ctx->cache[i].pfn =INVALID_PFN ; ctx->cache[i].page = ctx->cache_base + i *XC_PAGE_SIZE ; ctx->cache[i].prev = (i ==0 ) ?NULL : &(ctx->cache[i -1 ]); ctx->cache[i].next = ((i+1) == num_cache_pages)? NULL :
tools/libxc/xc_core.c +2 -2
@@ -808,13 +808,13 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, gmfn = p2m[i]; else gmfn = ((uint64_t *)p2m)[i]; -if ( gmfn ==INVALID_P2M_ENTRY ) +if ( gmfn ==INVALID_PFN )continue ; }else { gmfn = ((uint32_t *)p2m)[i]; -if ( gmfn == (uint32_t )INVALID_P2M_ENTRY ) +if ( gmfn == (uint32_t )INVALID_PFN )continue ; }
tools/libxc/xc_dom_arm.c +1 -1
@@ -439,7 +439,7 @@ static int meminit(struct xc_dom_image *dom)if ( dom->p2m_host ==NULL )return -EINVAL ;for ( pfn =0 ; pfn < p2m_size; pfn++ ) - dom->p2m_host[pfn] =INVALID_P2M_ENTRY ; + dom->p2m_host[pfn] =INVALID_PFN ;/* setup initial p2m and allocate guest memory */ for ( i =0 ; i <GUEST_RAM_BANKS && dom->rambank_size[i]; i++ )
tools/libxc/xc_dom_core.c +2 -2
@@ -971,7 +971,7 @@ int xc_dom_update_guest_p2m(struct xc_dom_image *dom) __FUNCTION__, dom->p2m_size); p2m_32 = dom->p2m_guest;for ( i =0 ; i < dom->p2m_size; i++ ) -if ( dom->p2m_host[i] !=INVALID_P2M_ENTRY ) +if ( dom->p2m_host[i] !=INVALID_PFN ) p2m_32[i] = dom->p2m_host[i];else p2m_32[i] = (uint32_t ) -1 ;
@@ -981,7 +981,7 @@ int xc_dom_update_guest_p2m(struct xc_dom_image *dom) __FUNCTION__, dom->p2m_size); p2m_64 = dom->p2m_guest;for ( i =0 ; i < dom->p2m_size; i++ ) -if ( dom->p2m_host[i] !=INVALID_P2M_ENTRY ) +if ( dom->p2m_host[i] !=INVALID_PFN ) p2m_64[i] = dom->p2m_host[i];else p2m_64[i] = (uint64_t ) -1 ;
tools/libxc/xc_dom_x86.c +1 -1
@@ -1172,7 +1172,7 @@ static int meminit_pv(struct xc_dom_image *dom)if ( dom->p2m_host ==NULL )return -EINVAL ;for ( pfn =0 ; pfn < dom->p2m_size; pfn++ ) - dom->p2m_host[pfn] =INVALID_P2M_ENTRY ; + dom->p2m_host[pfn] =INVALID_PFN ;/* allocate guest memory */ for ( i =0 ; i < nr_vmemranges; i++ )
tools/libxc/xc_offline_page.c +1 -1
@@ -282,7 +282,7 @@ static int change_pte(xc_interface *xch, int domid,uint64_t pte, new_pte;int j; -if ( (table_mfn ==INVALID_P2M_ENTRY ) || +if ( (table_mfn ==INVALID_PFN ) || ((minfo->pfn_type[i] &XEN_DOMCTL_PFINFO_LTAB_MASK ) ==XEN_DOMCTL_PFINFO_XTAB ) )continue ;
Signature · 1 line
2.6.2
Re: [PATCH 1/2] libxc: replace INVALID_P2M_ENTRY by INVALID_PFN
Quoted 5 lines · Juergen Gross
INVALID_P2M_ENTRYis defined as (xen_pfn_t)-1 and is often used according to it's type for an invalid pfn. Change the name of the macro toINVALID_PFN.Signed-off-by Juergen Gross <[email protected]>
PATCH 2/2 libxc: do proper return code checking of allocator in domain builder
In reply to Juergen Gross--- tools/libxc/xc_dom_core.c | 7 ++++++- tools/libxc/xc_dom_x86.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_core.c +6 -1
@@ -630,7 +630,7 @@ xen_pfn_t xc_dom_alloc_page(struct xc_dom_image *dom, char *name) pfn = dom->pfn_alloc_end - dom->rambase_pfn;if (xc_dom_chk_alloc_pages (dom, name,1 ) ) -return (xen_pfn_t)-1 ; +return INVALID_PFN ;DOMPRINTF ("%-20s: %-12s : 0x%" PRIx64" (pfn 0x%" PRIpfn")" , __FUNCTION__, name, start, pfn);
@@ -1107,7 +1107,12 @@ int xc_dom_build_image(struct xc_dom_image *dom)if ( dom->arch_hooks->alloc_pgtables (dom) !=0 ) goto err;if ( dom->alloc_bootstack ) + { dom->bootstack_pfn =xc_dom_alloc_page (dom,"boot stack" ); +if ( dom->bootstack_pfn ==INVALID_PFN ) + goto err; + } +DOMPRINTF ("%-20s: virt_alloc_end : 0x%" PRIx64"" , __FUNCTION__, dom->virt_alloc_end); DOMPRINTF("%-20s: virt_pgtab_end : 0x%" PRIx64 "",
tools/libxc/xc_dom_x86.c +10 -0
@@ -537,10 +537,20 @@ static int alloc_magic_pages(struct xc_dom_image *dom) {/* allocate special pages */ dom->start_info_pfn =xc_dom_alloc_page (dom,"start info" ); +if ( dom->start_info_pfn ==INVALID_PFN ) +return -1 ; dom->xenstore_pfn =xc_dom_alloc_page (dom,"xenstore" ); +if ( dom->xenstore_pfn ==INVALID_PFN ) +return -1 ; dom->console_pfn =xc_dom_alloc_page (dom,"console" ); +if ( dom->console_pfn ==INVALID_PFN ) +return -1 ;if (xc_dom_feature_translated (dom) ) + { dom->shared_info_pfn =xc_dom_alloc_page (dom,"shared info" ); +if ( dom->shared_info_pfn ==INVALID_PFN ) +return -1 ; + } dom->alloc_bootstack =1 ;return 0 ;
Signature · 1 line
2.6.2
Re: [PATCH 2/2] libxc: do proper return code checking of allocator in domain builder
Quoted 1 line · Juergen Gross
Signed-off-by Juergen Gross <[email protected]>
Quoted 7 lines · Juergen Gross
Add some more checks for having got allocated memory in the domain builder. Related to this add an
INVALID_PFNmacro to be able to do these checks.Juergen Gross (2):
libxc: replaceINVALID_P2M_ENTRYbyINVALID_PFN
libxc: do proper return code checking of allocator in domain builder
Both applied with Wei's ack.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel