Guest User

Untitled

a guest
Oct 20th, 2018
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
  2. index 3ed14a4fc1..cb7bc01c2e 100644
  3. --- a/xen/arch/arm/domain_build.c
  4. +++ b/xen/arch/arm/domain_build.c
  5. @@ -373,21 +373,53 @@ static void __init allocate_memory_11(struct domain *d,
  6.  static bool __init allocate_bank_memory(struct domain *d,
  7.                                          struct kernel_info *kinfo,
  8.                                          gfn_t sgfn,
  9. -                                        unsigned int order)
  10. +                                        unsigned long size)
  11.  {
  12.      int res;
  13.      struct page_info *pg;
  14.      struct membank *bank;
  15.      paddr_t gaddr = gfn_to_gaddr(sgfn), size = pfn_to_paddr(1UL << order);
  16. +    unsigned int max_order = ~0;
  17.  
  18. -    pg = alloc_domheap_pages(d, order, 0);
  19. -    if ( !pg )
  20. -        return false;
  21. +    while ( size > 0 )
  22. +    {
  23. +        unsigned int order = get_allocation_size(size);
  24. +
  25. +        order = min(max_order, order);
  26. +
  27. +        pg = alloc_domheap_pages(d, order, 0);
  28. +        if ( !pg )
  29. +        {
  30. +            /*
  31. +             * If we can't allocate one page, then it is unlikely to
  32. +             * succeed in the next iteration. So bail out.
  33. +             */
  34. +            if ( !order )
  35. +                return false;
  36. +
  37. +            /*
  38. +             * If we can't allocate memory with order, then it is
  39. +             * unlikely to succeed in the next iteration.
  40. +             * Record the order - 1 to avoid re-trying.
  41. +             */
  42. +            max_order = order - 1;
  43. +            continue;
  44. +        }
  45. +
  46. +        res = guest_physmap_add_page(d, sgfn, page_to_mfn(pg), order);
  47. +        if ( res )
  48. +        {
  49. +            dprintk(XENLOG_ERR, "Failed map pages to DOMU: %d", res);
  50. +            return false;
  51. +        }
  52. +
  53. +        gfn = gfn_add(gfn, 1UL << order);
  54. +        size -= (1ULL << (PAGE_SHIFT + order));
  55. +    }
  56.  
  57.      res = guest_physmap_add_page(d, sgfn, page_to_mfn(pg), order);
  58.      if ( res )
  59.      {
  60. -        dprintk(XENLOG_ERR, "Failed map pages to DOMU: %d", res);
  61.          goto fail;
  62.      }
  63.  
  64. @@ -408,6 +440,7 @@ static void __init allocate_memory(struct domain *d, struct kernel_info *kinfo)
  65.      unsigned int order = get_allocation_size(kinfo->unassigned_mem);
  66.      unsigned int order_req;
  67.      int i;
  68. +    unsigned long bank_size;
  69.  
  70.      dprintk(XENLOG_INFO, "Allocating mappings totalling %ldMB for dom%d:\n",
  71.              /* Don't want format this as PRIpaddr (16 digit hex) */
  72. @@ -415,20 +448,18 @@ static void __init allocate_memory(struct domain *d, struct kernel_info *kinfo)
  73.  
  74.      kinfo->mem.nr_banks = 0;
  75.  
  76. -    order = get_allocation_size(kinfo->unassigned_mem);
  77. -    if ( order > get_order_from_bytes(GUEST_RAM0_SIZE) )
  78. -        order_req = get_order_from_bytes(GUEST_RAM0_SIZE);
  79. -    else
  80. -        order_req = order;
  81. -    if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM0_BASE), order_req) )
  82. +    bank_size = min(GUEST_RAM0_SIZE, kinfo->unassigned_mem);
  83. +    if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM0_BASE),
  84. +                               bank_size) )
  85.          goto fail;
  86.  
  87. -    order -= order_req;
  88. -    if ( order > 0 )
  89. -    {
  90. -        if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM1_BASE), order) )
  91. -            goto fail;
  92. -    }
  93. +    bank_size = min(GUEST_RAM0_SIZE, kinfo->unassigned_mem);
  94. +    if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM1_BASE),
  95. +                               bank_size) )
  96. +        goto fail;
  97. +
  98. +    if ( kinfo->unassigned_mem )
  99. +        goto fail;
  100.  
  101.      for( i = 0; i < kinfo->mem.nr_banks; i++ )
  102.      {
RAW Paste Data