[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v4 10/23] xen/arm: introduce allocate_memory
Hi, On 05/10/2018 19:47, Stefano Stabellini wrote: Introduce an allocate_memory function able to allocate memory for DomUs and map it at the right guest addresses, according to the guest memory map: GUEST_RAM0_BASE and GUEST_RAM1_BASE. Please add something along the line: "This is under #if 0 as not used for now". Signed-off-by: Stefano Stabellini <stefanos@xxxxxxxxxx> --- Changes in v4: - move earlier, add #if 0 - introduce allocate_bank_memory, remove insert_bank - allocate_bank_memory allocate memory and inserts the bank, while allocate_memory specifies where to do that Changes in v3: - new patch --- xen/arch/arm/domain_build.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 41f2f27..fddfd82 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -368,6 +368,89 @@ static void __init allocate_memory_11(struct domain *d, } }+#if 0+static bool __init allocate_bank_memory(struct domain *d, + struct kernel_info *kinfo, + gfn_t sgfn, + unsigned int order) +{ + int res; + struct page_info *pg; + struct membank *bank; + paddr_t gaddr = gfn_to_gaddr(sgfn), size = pfn_to_paddr(1UL << order); There is no need to have gaddr in a variable. + + pg = alloc_domheap_pages(d, order, 0); So here you impose the memory to be contiguously allocated for a given bank. There are quite a few case where you may not have enough memory to allocate contiguously. So more likely you want to add loop in this code to allocate until order is reached. + if ( !pg ) + return false; + + res = guest_physmap_add_page(d, sgfn, page_to_mfn(pg), order); + if ( res ) + { + dprintk(XENLOG_ERR, "Failed map pages to DOMU: %d", res); + goto fail; + } + + bank = &kinfo->mem.bank[kinfo->mem.nr_banks]; + bank->start = gaddr; + bank->size = size; + kinfo->mem.nr_banks++; + kinfo->unassigned_mem -= size; newline here. + return true; + +fail: + free_domheap_pages(pg, order); + return false; +} + +static void __init allocate_memory(struct domain *d, struct kernel_info *kinfo) +{ + unsigned int order = get_allocation_size(kinfo->unassigned_mem); + unsigned int order_req; + int i; unsigned. + + dprintk(XENLOG_INFO, "Allocating mappings totalling %ldMB for dom%d:\n", + /* Don't want format this as PRIpaddr (16 digit hex) */ + (unsigned long)(kinfo->unassigned_mem >> 20), d->domain_id); + + kinfo->mem.nr_banks = 0; + + order = get_allocation_size(kinfo->unassigned_mem); + if ( order > get_order_from_bytes(GUEST_RAM0_SIZE) ) + order_req = get_order_from_bytes(GUEST_RAM0_SIZE); + else + order_req = order; + if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM0_BASE), order_req) ) + goto fail; + + order -= order_req; + if ( order > 0 ) + { + if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM1_BASE), order) ) + goto fail; + } How about combining the two if to avoid an extra indentation? + + for( i = 0; i < kinfo->mem.nr_banks; i++ ) + { + dprintk(XENLOG_INFO, "Dom%d BANK[%d] %#"PRIpaddr"-%#"PRIpaddr" (%ldMB)\n", + d->domain_id, + i, + kinfo->mem.bank[i].start, + kinfo->mem.bank[i].start + kinfo->mem.bank[i].size, + /* Don't want format this as PRIpaddr (16 digit hex) */ + (unsigned long)(kinfo->mem.bank[i].size >> 20)); + } + + return; + +fail: + dprintk(XENLOG_ERR, "Failed to allocate requested domain memory." + /* Don't want format this as PRIpaddr (16 digit hex) */ + " %ldKB unallocated. Fix the VMs configurations.\n", + (unsigned long)kinfo->unassigned_mem >> 10); + BUG(); +} +#endif + static int __init write_properties(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) { Cheers, -- Julien Grall _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |