@@ -46,6 +46,9 @@ bool xen_pv_pci_possible;
46
46
/* E820 map used during setting up memory. */
47
47
static struct e820_table xen_e820_table __initdata ;
48
48
49
+ /* Number of initially usable memory pages. */
50
+ static unsigned long ini_nr_pages __initdata ;
51
+
49
52
/*
50
53
* Buffer used to remap identity mapped pages. We only need the virtual space.
51
54
* 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)
212
215
* as a fallback if the remapping fails.
213
216
*/
214
217
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 )
216
219
{
217
220
unsigned long pfn , end ;
218
221
int ret ;
219
222
220
223
WARN_ON (start_pfn > end_pfn );
221
224
222
225
/* Release pages first. */
223
- end = min (end_pfn , nr_pages );
226
+ end = min (end_pfn , ini_nr_pages );
224
227
for (pfn = start_pfn ; pfn < end ; pfn ++ ) {
225
228
unsigned long mfn = pfn_to_mfn (pfn );
226
229
@@ -341,15 +344,14 @@ static void __init xen_do_set_identity_and_remap_chunk(
341
344
* to Xen and not remapped.
342
345
*/
343
346
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 )
346
348
{
347
349
unsigned long pfn ;
348
350
unsigned long i = 0 ;
349
351
unsigned long n = end_pfn - start_pfn ;
350
352
351
353
if (remap_pfn == 0 )
352
- remap_pfn = nr_pages ;
354
+ remap_pfn = ini_nr_pages ;
353
355
354
356
while (i < n ) {
355
357
unsigned long cur_pfn = start_pfn + i ;
@@ -358,19 +360,19 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
358
360
unsigned long remap_range_size ;
359
361
360
362
/* Do not remap pages beyond the current allocation */
361
- if (cur_pfn >= nr_pages ) {
363
+ if (cur_pfn >= ini_nr_pages ) {
362
364
/* Identity map remaining pages */
363
365
set_phys_range_identity (cur_pfn , cur_pfn + size );
364
366
break ;
365
367
}
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 ;
368
370
369
371
remap_range_size = xen_find_pfn_range (& remap_pfn );
370
372
if (!remap_range_size ) {
371
373
pr_warn ("Unable to find available pfn range, not remapping identity pages\n" );
372
374
xen_set_identity_and_release_chunk (cur_pfn ,
373
- cur_pfn + left , nr_pages );
375
+ cur_pfn + left );
374
376
break ;
375
377
}
376
378
/* Adjust size to fit in current e820 RAM region */
@@ -397,18 +399,18 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
397
399
}
398
400
399
401
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 ,
401
403
unsigned long remap_pages )
402
404
{
403
- if (start_pfn >= nr_pages )
405
+ if (start_pfn >= ini_nr_pages )
404
406
return remap_pages ;
405
407
406
- return remap_pages + min (end_pfn , nr_pages ) - start_pfn ;
408
+ return remap_pages + min (end_pfn , ini_nr_pages ) - start_pfn ;
407
409
}
408
410
409
- static unsigned long __init xen_foreach_remap_area (unsigned long nr_pages ,
411
+ static unsigned long __init xen_foreach_remap_area (
410
412
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 ))
412
414
{
413
415
phys_addr_t start = 0 ;
414
416
unsigned long ret_val = 0 ;
@@ -436,8 +438,7 @@ static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
436
438
end_pfn = PFN_UP (entry -> addr );
437
439
438
440
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 );
441
442
start = end ;
442
443
}
443
444
}
@@ -700,7 +701,7 @@ static void __init xen_reserve_xen_mfnlist(void)
700
701
**/
701
702
char * __init xen_memory_setup (void )
702
703
{
703
- unsigned long max_pfn , pfn_s , n_pfns ;
704
+ unsigned long pfn_s , n_pfns ;
704
705
phys_addr_t mem_end , addr , size , chunk_size ;
705
706
u32 type ;
706
707
int rc ;
@@ -712,9 +713,8 @@ char * __init xen_memory_setup(void)
712
713
int op ;
713
714
714
715
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 );
718
718
719
719
memmap .nr_entries = ARRAY_SIZE (xen_e820_table .entries );
720
720
set_xen_guest_handle (memmap .buffer , xen_e820_table .entries );
@@ -789,10 +789,10 @@ char * __init xen_memory_setup(void)
789
789
max_pages = xen_get_max_pages ();
790
790
791
791
/* 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 );
793
793
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 ;
796
796
797
797
/*
798
798
* Clamp the amount of extra memory to a EXTRA_MEM_RATIO
@@ -801,8 +801,8 @@ char * __init xen_memory_setup(void)
801
801
* Make sure we have no memory above max_pages, as this area
802
802
* isn't handled by the p2m management.
803
803
*/
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 );
806
806
i = 0 ;
807
807
addr = xen_e820_table .entries [0 ].addr ;
808
808
size = xen_e820_table .entries [0 ].size ;
@@ -885,7 +885,7 @@ char * __init xen_memory_setup(void)
885
885
* Set identity map on non-RAM pages and prepare remapping the
886
886
* underlying RAM.
887
887
*/
888
- xen_foreach_remap_area (max_pfn , xen_set_identity_and_remap_chunk );
888
+ xen_foreach_remap_area (xen_set_identity_and_remap_chunk );
889
889
890
890
pr_info ("Released %ld page(s)\n" , xen_released_pages );
891
891
0 commit comments