Skip to content

Commit 43dc2a0

Browse files
committed
xen: move max_pfn in xen_memory_setup() out of function scope
Instead of having max_pfn as a local variable of xen_memory_setup(), make it a static variable in setup.c instead. This avoids having to pass it to subfunctions, which will be needed in more cases in future. Rename it to ini_nr_pages, as the value denotes the currently usable number of memory pages as passed from the hypervisor at boot time. Signed-off-by: Juergen Gross <[email protected]> Tested-by: Marek Marczykowski-Górecki <[email protected]> Reviewed-by: Jan Beulich <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent c4498ae commit 43dc2a0

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

arch/x86/xen/setup.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ bool xen_pv_pci_possible;
4646
/* E820 map used during setting up memory. */
4747
static struct e820_table xen_e820_table __initdata;
4848

49+
/* Number of initially usable memory pages. */
50+
static unsigned long ini_nr_pages __initdata;
51+
4952
/*
5053
* Buffer used to remap identity mapped pages. We only need the virtual space.
5154
* The physical page behind this address is remapped as needed to different
@@ -212,15 +215,15 @@ static int __init xen_free_mfn(unsigned long mfn)
212215
* as a fallback if the remapping fails.
213216
*/
214217
static void __init xen_set_identity_and_release_chunk(unsigned long start_pfn,
215-
unsigned long end_pfn, unsigned long nr_pages)
218+
unsigned long end_pfn)
216219
{
217220
unsigned long pfn, end;
218221
int ret;
219222

220223
WARN_ON(start_pfn > end_pfn);
221224

222225
/* Release pages first. */
223-
end = min(end_pfn, nr_pages);
226+
end = min(end_pfn, ini_nr_pages);
224227
for (pfn = start_pfn; pfn < end; pfn++) {
225228
unsigned long mfn = pfn_to_mfn(pfn);
226229

@@ -341,15 +344,14 @@ static void __init xen_do_set_identity_and_remap_chunk(
341344
* to Xen and not remapped.
342345
*/
343346
static unsigned long __init xen_set_identity_and_remap_chunk(
344-
unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages,
345-
unsigned long remap_pfn)
347+
unsigned long start_pfn, unsigned long end_pfn, unsigned long remap_pfn)
346348
{
347349
unsigned long pfn;
348350
unsigned long i = 0;
349351
unsigned long n = end_pfn - start_pfn;
350352

351353
if (remap_pfn == 0)
352-
remap_pfn = nr_pages;
354+
remap_pfn = ini_nr_pages;
353355

354356
while (i < n) {
355357
unsigned long cur_pfn = start_pfn + i;
@@ -358,19 +360,19 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
358360
unsigned long remap_range_size;
359361

360362
/* Do not remap pages beyond the current allocation */
361-
if (cur_pfn >= nr_pages) {
363+
if (cur_pfn >= ini_nr_pages) {
362364
/* Identity map remaining pages */
363365
set_phys_range_identity(cur_pfn, cur_pfn + size);
364366
break;
365367
}
366-
if (cur_pfn + size > nr_pages)
367-
size = nr_pages - cur_pfn;
368+
if (cur_pfn + size > ini_nr_pages)
369+
size = ini_nr_pages - cur_pfn;
368370

369371
remap_range_size = xen_find_pfn_range(&remap_pfn);
370372
if (!remap_range_size) {
371373
pr_warn("Unable to find available pfn range, not remapping identity pages\n");
372374
xen_set_identity_and_release_chunk(cur_pfn,
373-
cur_pfn + left, nr_pages);
375+
cur_pfn + left);
374376
break;
375377
}
376378
/* Adjust size to fit in current e820 RAM region */
@@ -397,18 +399,18 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
397399
}
398400

399401
static unsigned long __init xen_count_remap_pages(
400-
unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages,
402+
unsigned long start_pfn, unsigned long end_pfn,
401403
unsigned long remap_pages)
402404
{
403-
if (start_pfn >= nr_pages)
405+
if (start_pfn >= ini_nr_pages)
404406
return remap_pages;
405407

406-
return remap_pages + min(end_pfn, nr_pages) - start_pfn;
408+
return remap_pages + min(end_pfn, ini_nr_pages) - start_pfn;
407409
}
408410

409-
static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
411+
static unsigned long __init xen_foreach_remap_area(
410412
unsigned long (*func)(unsigned long start_pfn, unsigned long end_pfn,
411-
unsigned long nr_pages, unsigned long last_val))
413+
unsigned long last_val))
412414
{
413415
phys_addr_t start = 0;
414416
unsigned long ret_val = 0;
@@ -436,8 +438,7 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
436438
end_pfn = PFN_UP(entry->addr);
437439

438440
if (start_pfn < end_pfn)
439-
ret_val = func(start_pfn, end_pfn, nr_pages,
440-
ret_val);
441+
ret_val = func(start_pfn, end_pfn, ret_val);
441442
start = end;
442443
}
443444
}
@@ -700,7 +701,7 @@ static void __init xen_reserve_xen_mfnlist(void)
700701
**/
701702
char * __init xen_memory_setup(void)
702703
{
703-
unsigned long max_pfn, pfn_s, n_pfns;
704+
unsigned long pfn_s, n_pfns;
704705
phys_addr_t mem_end, addr, size, chunk_size;
705706
u32 type;
706707
int rc;
@@ -712,9 +713,8 @@ char * __init xen_memory_setup(void)
712713
int op;
713714

714715
xen_parse_512gb();
715-
max_pfn = xen_get_pages_limit();
716-
max_pfn = min(max_pfn, xen_start_info->nr_pages);
717-
mem_end = PFN_PHYS(max_pfn);
716+
ini_nr_pages = min(xen_get_pages_limit(), xen_start_info->nr_pages);
717+
mem_end = PFN_PHYS(ini_nr_pages);
718718

719719
memmap.nr_entries = ARRAY_SIZE(xen_e820_table.entries);
720720
set_xen_guest_handle(memmap.buffer, xen_e820_table.entries);
@@ -789,10 +789,10 @@ char * __init xen_memory_setup(void)
789789
max_pages = xen_get_max_pages();
790790

791791
/* How many extra pages do we need due to remapping? */
792-
max_pages += xen_foreach_remap_area(max_pfn, xen_count_remap_pages);
792+
max_pages += xen_foreach_remap_area(xen_count_remap_pages);
793793

794-
if (max_pages > max_pfn)
795-
extra_pages += max_pages - max_pfn;
794+
if (max_pages > ini_nr_pages)
795+
extra_pages += max_pages - ini_nr_pages;
796796

797797
/*
798798
* Clamp the amount of extra memory to a EXTRA_MEM_RATIO
@@ -801,8 +801,8 @@ char * __init xen_memory_setup(void)
801801
* Make sure we have no memory above max_pages, as this area
802802
* isn't handled by the p2m management.
803803
*/
804-
maxmem_pages = EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM));
805-
extra_pages = min3(maxmem_pages, extra_pages, max_pages - max_pfn);
804+
maxmem_pages = EXTRA_MEM_RATIO * min(ini_nr_pages, PFN_DOWN(MAXMEM));
805+
extra_pages = min3(maxmem_pages, extra_pages, max_pages - ini_nr_pages);
806806
i = 0;
807807
addr = xen_e820_table.entries[0].addr;
808808
size = xen_e820_table.entries[0].size;
@@ -885,7 +885,7 @@ char * __init xen_memory_setup(void)
885885
* Set identity map on non-RAM pages and prepare remapping the
886886
* underlying RAM.
887887
*/
888-
xen_foreach_remap_area(max_pfn, xen_set_identity_and_remap_chunk);
888+
xen_foreach_remap_area(xen_set_identity_and_remap_chunk);
889889

890890
pr_info("Released %ld page(s)\n", xen_released_pages);
891891

0 commit comments

Comments
 (0)