Skip to content

Commit 8b5d44a

Browse files
David Vrabelkonradwilk
authored andcommitted
xen: allow balloon driver to use more than one memory region
Allow the xen balloon driver to populate its list of extra pages from more than one region of memory. This will allow platforms to provide (for example) a region of low memory and a region of high memory. The maximum possible number of extra regions is 128 (== E820MAX) which is quite large so xen_extra_mem is placed in __initdata. This is safe as both xen_memory_setup() and balloon_init() are in __init. The balloon regions themselves are not altered (i.e., there is still only the one region). Signed-off-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent b1cbf9b commit 8b5d44a

3 files changed

Lines changed: 46 additions & 28 deletions

File tree

‎arch/x86/xen/setup.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern void xen_syscall_target(void);
3737
extern void xen_syscall32_target(void);
3838

3939
/* Amount of extra memory space we add to the e820 ranges */
40-
phys_addr_t xen_extra_mem_start, xen_extra_mem_size;
40+
struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
4141

4242
/* Number of pages released from the initial allocation. */
4343
unsigned long xen_released_pages;
@@ -59,7 +59,7 @@ static void __init xen_add_extra_mem(unsigned long pages)
5959
unsigned long pfn;
6060

6161
u64 size = (u64)pages * PAGE_SIZE;
62-
u64 extra_start = xen_extra_mem_start + xen_extra_mem_size;
62+
u64 extra_start = xen_extra_mem[0].start + xen_extra_mem[0].size;
6363

6464
if (!pages)
6565
return;
@@ -69,7 +69,7 @@ static void __init xen_add_extra_mem(unsigned long pages)
6969

7070
memblock_x86_reserve_range(extra_start, extra_start + size, "XEN EXTRA");
7171

72-
xen_extra_mem_size += size;
72+
xen_extra_mem[0].size += size;
7373

7474
xen_max_p2m_pfn = PFN_DOWN(extra_start + size);
7575

@@ -242,7 +242,7 @@ char * __init xen_memory_setup(void)
242242

243243
memcpy(map_raw, map, sizeof(map));
244244
e820.nr_map = 0;
245-
xen_extra_mem_start = mem_end;
245+
xen_extra_mem[0].start = mem_end;
246246
for (i = 0; i < memmap.nr_entries; i++) {
247247
unsigned long long end;
248248

@@ -270,19 +270,19 @@ char * __init xen_memory_setup(void)
270270
e820_add_region(end, delta, E820_UNUSABLE);
271271
}
272272

273-
if (map[i].size > 0 && end > xen_extra_mem_start)
274-
xen_extra_mem_start = end;
273+
if (map[i].size > 0 && end > xen_extra_mem[0].start)
274+
xen_extra_mem[0].start = end;
275275

276276
/* Add region if any remains */
277277
if (map[i].size > 0)
278278
e820_add_region(map[i].addr, map[i].size, map[i].type);
279279
}
280280
/* Align the balloon area so that max_low_pfn does not get set
281281
* to be at the _end_ of the PCI gap at the far end (fee01000).
282-
* Note that xen_extra_mem_start gets set in the loop above to be
283-
* past the last E820 region. */
284-
if (xen_initial_domain() && (xen_extra_mem_start < (1ULL<<32)))
285-
xen_extra_mem_start = (1ULL<<32);
282+
* Note that the start of balloon area gets set in the loop above
283+
* to be past the last E820 region. */
284+
if (xen_initial_domain() && (xen_extra_mem[0].start < (1ULL<<32)))
285+
xen_extra_mem[0].start = (1ULL<<32);
286286

287287
/*
288288
* In domU, the ISA region is normal, usable memory, but we

‎drivers/xen/balloon.c‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,32 @@ void free_xenballooned_pages(int nr_pages, struct page** pages)
555555
}
556556
EXPORT_SYMBOL(free_xenballooned_pages);
557557

558-
static int __init balloon_init(void)
558+
static void __init balloon_add_region(unsigned long start_pfn,
559+
unsigned long pages)
559560
{
560561
unsigned long pfn, extra_pfn_end;
561562
struct page *page;
562563

564+
/*
565+
* If the amount of usable memory has been limited (e.g., with
566+
* the 'mem' command line parameter), don't add pages beyond
567+
* this limit.
568+
*/
569+
extra_pfn_end = min(max_pfn, start_pfn + pages);
570+
571+
for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) {
572+
page = pfn_to_page(pfn);
573+
/* totalram_pages and totalhigh_pages do not
574+
include the boot-time balloon extension, so
575+
don't subtract from it. */
576+
__balloon_append(page);
577+
}
578+
}
579+
580+
static int __init balloon_init(void)
581+
{
582+
int i;
583+
563584
if (!xen_domain())
564585
return -ENODEV;
565586

@@ -587,23 +608,12 @@ static int __init balloon_init(void)
587608

588609
/*
589610
* Initialize the balloon with pages from the extra memory
590-
* region (see arch/x86/xen/setup.c).
591-
*
592-
* If the amount of usable memory has been limited (e.g., with
593-
* the 'mem' command line parameter), don't add pages beyond
594-
* this limit.
611+
* regions (see arch/x86/xen/setup.c).
595612
*/
596-
extra_pfn_end = min(max_pfn,
597-
(unsigned long)PFN_DOWN(xen_extra_mem_start
598-
+ xen_extra_mem_size));
599-
for (pfn = PFN_UP(xen_extra_mem_start);
600-
pfn < extra_pfn_end;
601-
pfn++) {
602-
page = pfn_to_page(pfn);
603-
/* totalram_pages and totalhigh_pages do not include the boot-time
604-
balloon extension, so don't subtract from it. */
605-
__balloon_append(page);
606-
}
613+
for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++)
614+
if (xen_extra_mem[i].size)
615+
balloon_add_region(PFN_UP(xen_extra_mem[i].start),
616+
PFN_DOWN(xen_extra_mem[i].size));
607617

608618
return 0;
609619
}

‎include/xen/page.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33

44
#include <asm/xen/page.h>
55

6-
extern phys_addr_t xen_extra_mem_start, xen_extra_mem_size;
6+
struct xen_memory_region {
7+
phys_addr_t start;
8+
phys_addr_t size;
9+
};
10+
11+
#define XEN_EXTRA_MEM_MAX_REGIONS 128 /* == E820MAX */
12+
13+
extern __initdata
14+
struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS];
715

816
extern unsigned long xen_released_pages;
917

0 commit comments

Comments
 (0)