diff options
Diffstat (limited to 'arch/x86/xen/p2m.c')
-rw-r--r-- | arch/x86/xen/p2m.c | 83 |
1 files changed, 25 insertions, 58 deletions
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 9f5983b01ed9..b456b048eca9 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c | |||
@@ -163,6 +163,7 @@ | |||
163 | #include <linux/hash.h> | 163 | #include <linux/hash.h> |
164 | #include <linux/sched.h> | 164 | #include <linux/sched.h> |
165 | #include <linux/seq_file.h> | 165 | #include <linux/seq_file.h> |
166 | #include <linux/bootmem.h> | ||
166 | 167 | ||
167 | #include <asm/cache.h> | 168 | #include <asm/cache.h> |
168 | #include <asm/setup.h> | 169 | #include <asm/setup.h> |
@@ -181,21 +182,20 @@ static void __init m2p_override_init(void); | |||
181 | 182 | ||
182 | unsigned long xen_max_p2m_pfn __read_mostly; | 183 | unsigned long xen_max_p2m_pfn __read_mostly; |
183 | 184 | ||
185 | static unsigned long *p2m_mid_missing_mfn; | ||
186 | static unsigned long *p2m_top_mfn; | ||
187 | static unsigned long **p2m_top_mfn_p; | ||
188 | |||
184 | /* Placeholders for holes in the address space */ | 189 | /* Placeholders for holes in the address space */ |
185 | static RESERVE_BRK_ARRAY(unsigned long, p2m_missing, P2M_PER_PAGE); | 190 | static RESERVE_BRK_ARRAY(unsigned long, p2m_missing, P2M_PER_PAGE); |
186 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_mid_missing, P2M_MID_PER_PAGE); | 191 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_mid_missing, P2M_MID_PER_PAGE); |
187 | static RESERVE_BRK_ARRAY(unsigned long, p2m_mid_missing_mfn, P2M_MID_PER_PAGE); | ||
188 | 192 | ||
189 | static RESERVE_BRK_ARRAY(unsigned long **, p2m_top, P2M_TOP_PER_PAGE); | 193 | static RESERVE_BRK_ARRAY(unsigned long **, p2m_top, P2M_TOP_PER_PAGE); |
190 | static RESERVE_BRK_ARRAY(unsigned long, p2m_top_mfn, P2M_TOP_PER_PAGE); | ||
191 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_top_mfn_p, P2M_TOP_PER_PAGE); | ||
192 | 194 | ||
193 | static RESERVE_BRK_ARRAY(unsigned long, p2m_identity, P2M_PER_PAGE); | 195 | static RESERVE_BRK_ARRAY(unsigned long, p2m_identity, P2M_PER_PAGE); |
194 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_mid_identity, P2M_MID_PER_PAGE); | 196 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_mid_identity, P2M_MID_PER_PAGE); |
195 | static RESERVE_BRK_ARRAY(unsigned long, p2m_mid_identity_mfn, P2M_MID_PER_PAGE); | ||
196 | 197 | ||
197 | RESERVE_BRK(p2m_mid, PAGE_SIZE * (MAX_DOMAIN_PAGES / (P2M_PER_PAGE * P2M_MID_PER_PAGE))); | 198 | RESERVE_BRK(p2m_mid, PAGE_SIZE * (MAX_DOMAIN_PAGES / (P2M_PER_PAGE * P2M_MID_PER_PAGE))); |
198 | RESERVE_BRK(p2m_mid_mfn, PAGE_SIZE * (MAX_DOMAIN_PAGES / (P2M_PER_PAGE * P2M_MID_PER_PAGE))); | ||
199 | 199 | ||
200 | /* For each I/O range remapped we may lose up to two leaf pages for the boundary | 200 | /* For each I/O range remapped we may lose up to two leaf pages for the boundary |
201 | * violations and three mid pages to cover up to 3GB. With | 201 | * violations and three mid pages to cover up to 3GB. With |
@@ -272,11 +272,11 @@ static void p2m_init(unsigned long *p2m) | |||
272 | * Build the parallel p2m_top_mfn and p2m_mid_mfn structures | 272 | * Build the parallel p2m_top_mfn and p2m_mid_mfn structures |
273 | * | 273 | * |
274 | * This is called both at boot time, and after resuming from suspend: | 274 | * This is called both at boot time, and after resuming from suspend: |
275 | * - At boot time we're called very early, and must use extend_brk() | 275 | * - At boot time we're called rather early, and must use alloc_bootmem*() |
276 | * to allocate memory. | 276 | * to allocate memory. |
277 | * | 277 | * |
278 | * - After resume we're called from within stop_machine, but the mfn | 278 | * - After resume we're called from within stop_machine, but the mfn |
279 | * tree should alreay be completely allocated. | 279 | * tree should already be completely allocated. |
280 | */ | 280 | */ |
281 | void __ref xen_build_mfn_list_list(void) | 281 | void __ref xen_build_mfn_list_list(void) |
282 | { | 282 | { |
@@ -287,20 +287,17 @@ void __ref xen_build_mfn_list_list(void) | |||
287 | 287 | ||
288 | /* Pre-initialize p2m_top_mfn to be completely missing */ | 288 | /* Pre-initialize p2m_top_mfn to be completely missing */ |
289 | if (p2m_top_mfn == NULL) { | 289 | if (p2m_top_mfn == NULL) { |
290 | p2m_mid_missing_mfn = extend_brk(PAGE_SIZE, PAGE_SIZE); | 290 | p2m_mid_missing_mfn = alloc_bootmem_align(PAGE_SIZE, PAGE_SIZE); |
291 | p2m_mid_mfn_init(p2m_mid_missing_mfn, p2m_missing); | 291 | p2m_mid_mfn_init(p2m_mid_missing_mfn, p2m_missing); |
292 | p2m_mid_identity_mfn = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
293 | p2m_mid_mfn_init(p2m_mid_identity_mfn, p2m_identity); | ||
294 | 292 | ||
295 | p2m_top_mfn_p = extend_brk(PAGE_SIZE, PAGE_SIZE); | 293 | p2m_top_mfn_p = alloc_bootmem_align(PAGE_SIZE, PAGE_SIZE); |
296 | p2m_top_mfn_p_init(p2m_top_mfn_p); | 294 | p2m_top_mfn_p_init(p2m_top_mfn_p); |
297 | 295 | ||
298 | p2m_top_mfn = extend_brk(PAGE_SIZE, PAGE_SIZE); | 296 | p2m_top_mfn = alloc_bootmem_align(PAGE_SIZE, PAGE_SIZE); |
299 | p2m_top_mfn_init(p2m_top_mfn); | 297 | p2m_top_mfn_init(p2m_top_mfn); |
300 | } else { | 298 | } else { |
301 | /* Reinitialise, mfn's all change after migration */ | 299 | /* Reinitialise, mfn's all change after migration */ |
302 | p2m_mid_mfn_init(p2m_mid_missing_mfn, p2m_missing); | 300 | p2m_mid_mfn_init(p2m_mid_missing_mfn, p2m_missing); |
303 | p2m_mid_mfn_init(p2m_mid_identity_mfn, p2m_identity); | ||
304 | } | 301 | } |
305 | 302 | ||
306 | for (pfn = 0; pfn < xen_max_p2m_pfn; pfn += P2M_PER_PAGE) { | 303 | for (pfn = 0; pfn < xen_max_p2m_pfn; pfn += P2M_PER_PAGE) { |
@@ -328,10 +325,9 @@ void __ref xen_build_mfn_list_list(void) | |||
328 | /* | 325 | /* |
329 | * XXX boot-time only! We should never find | 326 | * XXX boot-time only! We should never find |
330 | * missing parts of the mfn tree after | 327 | * missing parts of the mfn tree after |
331 | * runtime. extend_brk() will BUG if we call | 328 | * runtime. |
332 | * it too late. | ||
333 | */ | 329 | */ |
334 | mid_mfn_p = extend_brk(PAGE_SIZE, PAGE_SIZE); | 330 | mid_mfn_p = alloc_bootmem_align(PAGE_SIZE, PAGE_SIZE); |
335 | p2m_mid_mfn_init(mid_mfn_p, p2m_missing); | 331 | p2m_mid_mfn_init(mid_mfn_p, p2m_missing); |
336 | 332 | ||
337 | p2m_top_mfn_p[topidx] = mid_mfn_p; | 333 | p2m_top_mfn_p[topidx] = mid_mfn_p; |
@@ -415,7 +411,6 @@ void __init xen_build_dynamic_phys_to_machine(void) | |||
415 | m2p_override_init(); | 411 | m2p_override_init(); |
416 | } | 412 | } |
417 | #ifdef CONFIG_X86_64 | 413 | #ifdef CONFIG_X86_64 |
418 | #include <linux/bootmem.h> | ||
419 | unsigned long __init xen_revector_p2m_tree(void) | 414 | unsigned long __init xen_revector_p2m_tree(void) |
420 | { | 415 | { |
421 | unsigned long va_start; | 416 | unsigned long va_start; |
@@ -477,7 +472,6 @@ unsigned long __init xen_revector_p2m_tree(void) | |||
477 | 472 | ||
478 | copy_page(new, mid_p); | 473 | copy_page(new, mid_p); |
479 | p2m_top[topidx][mididx] = &mfn_list[pfn_free]; | 474 | p2m_top[topidx][mididx] = &mfn_list[pfn_free]; |
480 | p2m_top_mfn_p[topidx][mididx] = virt_to_mfn(&mfn_list[pfn_free]); | ||
481 | 475 | ||
482 | pfn_free += P2M_PER_PAGE; | 476 | pfn_free += P2M_PER_PAGE; |
483 | 477 | ||
@@ -538,12 +532,13 @@ static bool alloc_p2m(unsigned long pfn) | |||
538 | unsigned topidx, mididx; | 532 | unsigned topidx, mididx; |
539 | unsigned long ***top_p, **mid; | 533 | unsigned long ***top_p, **mid; |
540 | unsigned long *top_mfn_p, *mid_mfn; | 534 | unsigned long *top_mfn_p, *mid_mfn; |
535 | unsigned long *p2m_orig; | ||
541 | 536 | ||
542 | topidx = p2m_top_index(pfn); | 537 | topidx = p2m_top_index(pfn); |
543 | mididx = p2m_mid_index(pfn); | 538 | mididx = p2m_mid_index(pfn); |
544 | 539 | ||
545 | top_p = &p2m_top[topidx]; | 540 | top_p = &p2m_top[topidx]; |
546 | mid = *top_p; | 541 | mid = ACCESS_ONCE(*top_p); |
547 | 542 | ||
548 | if (mid == p2m_mid_missing) { | 543 | if (mid == p2m_mid_missing) { |
549 | /* Mid level is missing, allocate a new one */ | 544 | /* Mid level is missing, allocate a new one */ |
@@ -558,7 +553,7 @@ static bool alloc_p2m(unsigned long pfn) | |||
558 | } | 553 | } |
559 | 554 | ||
560 | top_mfn_p = &p2m_top_mfn[topidx]; | 555 | top_mfn_p = &p2m_top_mfn[topidx]; |
561 | mid_mfn = p2m_top_mfn_p[topidx]; | 556 | mid_mfn = ACCESS_ONCE(p2m_top_mfn_p[topidx]); |
562 | 557 | ||
563 | BUG_ON(virt_to_mfn(mid_mfn) != *top_mfn_p); | 558 | BUG_ON(virt_to_mfn(mid_mfn) != *top_mfn_p); |
564 | 559 | ||
@@ -566,6 +561,7 @@ static bool alloc_p2m(unsigned long pfn) | |||
566 | /* Separately check the mid mfn level */ | 561 | /* Separately check the mid mfn level */ |
567 | unsigned long missing_mfn; | 562 | unsigned long missing_mfn; |
568 | unsigned long mid_mfn_mfn; | 563 | unsigned long mid_mfn_mfn; |
564 | unsigned long old_mfn; | ||
569 | 565 | ||
570 | mid_mfn = alloc_p2m_page(); | 566 | mid_mfn = alloc_p2m_page(); |
571 | if (!mid_mfn) | 567 | if (!mid_mfn) |
@@ -575,17 +571,19 @@ static bool alloc_p2m(unsigned long pfn) | |||
575 | 571 | ||
576 | missing_mfn = virt_to_mfn(p2m_mid_missing_mfn); | 572 | missing_mfn = virt_to_mfn(p2m_mid_missing_mfn); |
577 | mid_mfn_mfn = virt_to_mfn(mid_mfn); | 573 | mid_mfn_mfn = virt_to_mfn(mid_mfn); |
578 | if (cmpxchg(top_mfn_p, missing_mfn, mid_mfn_mfn) != missing_mfn) | 574 | old_mfn = cmpxchg(top_mfn_p, missing_mfn, mid_mfn_mfn); |
575 | if (old_mfn != missing_mfn) { | ||
579 | free_p2m_page(mid_mfn); | 576 | free_p2m_page(mid_mfn); |
580 | else | 577 | mid_mfn = mfn_to_virt(old_mfn); |
578 | } else { | ||
581 | p2m_top_mfn_p[topidx] = mid_mfn; | 579 | p2m_top_mfn_p[topidx] = mid_mfn; |
580 | } | ||
582 | } | 581 | } |
583 | 582 | ||
584 | if (p2m_top[topidx][mididx] == p2m_identity || | 583 | p2m_orig = ACCESS_ONCE(p2m_top[topidx][mididx]); |
585 | p2m_top[topidx][mididx] == p2m_missing) { | 584 | if (p2m_orig == p2m_identity || p2m_orig == p2m_missing) { |
586 | /* p2m leaf page is missing */ | 585 | /* p2m leaf page is missing */ |
587 | unsigned long *p2m; | 586 | unsigned long *p2m; |
588 | unsigned long *p2m_orig = p2m_top[topidx][mididx]; | ||
589 | 587 | ||
590 | p2m = alloc_p2m_page(); | 588 | p2m = alloc_p2m_page(); |
591 | if (!p2m) | 589 | if (!p2m) |
@@ -606,7 +604,6 @@ static bool __init early_alloc_p2m(unsigned long pfn, bool check_boundary) | |||
606 | { | 604 | { |
607 | unsigned topidx, mididx, idx; | 605 | unsigned topidx, mididx, idx; |
608 | unsigned long *p2m; | 606 | unsigned long *p2m; |
609 | unsigned long *mid_mfn_p; | ||
610 | 607 | ||
611 | topidx = p2m_top_index(pfn); | 608 | topidx = p2m_top_index(pfn); |
612 | mididx = p2m_mid_index(pfn); | 609 | mididx = p2m_mid_index(pfn); |
@@ -633,43 +630,21 @@ static bool __init early_alloc_p2m(unsigned long pfn, bool check_boundary) | |||
633 | 630 | ||
634 | p2m_top[topidx][mididx] = p2m; | 631 | p2m_top[topidx][mididx] = p2m; |
635 | 632 | ||
636 | /* For save/restore we need to MFN of the P2M saved */ | ||
637 | |||
638 | mid_mfn_p = p2m_top_mfn_p[topidx]; | ||
639 | WARN(mid_mfn_p[mididx] != virt_to_mfn(p2m_missing), | ||
640 | "P2M_TOP_P[%d][%d] != MFN of p2m_missing!\n", | ||
641 | topidx, mididx); | ||
642 | mid_mfn_p[mididx] = virt_to_mfn(p2m); | ||
643 | |||
644 | return true; | 633 | return true; |
645 | } | 634 | } |
646 | 635 | ||
647 | static bool __init early_alloc_p2m_middle(unsigned long pfn) | 636 | static bool __init early_alloc_p2m_middle(unsigned long pfn) |
648 | { | 637 | { |
649 | unsigned topidx = p2m_top_index(pfn); | 638 | unsigned topidx = p2m_top_index(pfn); |
650 | unsigned long *mid_mfn_p; | ||
651 | unsigned long **mid; | 639 | unsigned long **mid; |
652 | 640 | ||
653 | mid = p2m_top[topidx]; | 641 | mid = p2m_top[topidx]; |
654 | mid_mfn_p = p2m_top_mfn_p[topidx]; | ||
655 | if (mid == p2m_mid_missing) { | 642 | if (mid == p2m_mid_missing) { |
656 | mid = extend_brk(PAGE_SIZE, PAGE_SIZE); | 643 | mid = extend_brk(PAGE_SIZE, PAGE_SIZE); |
657 | 644 | ||
658 | p2m_mid_init(mid, p2m_missing); | 645 | p2m_mid_init(mid, p2m_missing); |
659 | 646 | ||
660 | p2m_top[topidx] = mid; | 647 | p2m_top[topidx] = mid; |
661 | |||
662 | BUG_ON(mid_mfn_p != p2m_mid_missing_mfn); | ||
663 | } | ||
664 | /* And the save/restore P2M tables.. */ | ||
665 | if (mid_mfn_p == p2m_mid_missing_mfn) { | ||
666 | mid_mfn_p = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
667 | p2m_mid_mfn_init(mid_mfn_p, p2m_missing); | ||
668 | |||
669 | p2m_top_mfn_p[topidx] = mid_mfn_p; | ||
670 | p2m_top_mfn[topidx] = virt_to_mfn(mid_mfn_p); | ||
671 | /* Note: we don't set mid_mfn_p[midix] here, | ||
672 | * look in early_alloc_p2m() */ | ||
673 | } | 648 | } |
674 | return true; | 649 | return true; |
675 | } | 650 | } |
@@ -680,14 +655,13 @@ static bool __init early_alloc_p2m_middle(unsigned long pfn) | |||
680 | * replace the P2M leaf with a p2m_missing or p2m_identity. | 655 | * replace the P2M leaf with a p2m_missing or p2m_identity. |
681 | * Stick the old page in the new P2M tree location. | 656 | * Stick the old page in the new P2M tree location. |
682 | */ | 657 | */ |
683 | bool __init early_can_reuse_p2m_middle(unsigned long set_pfn, unsigned long set_mfn) | 658 | static bool __init early_can_reuse_p2m_middle(unsigned long set_pfn) |
684 | { | 659 | { |
685 | unsigned topidx; | 660 | unsigned topidx; |
686 | unsigned mididx; | 661 | unsigned mididx; |
687 | unsigned ident_pfns; | 662 | unsigned ident_pfns; |
688 | unsigned inv_pfns; | 663 | unsigned inv_pfns; |
689 | unsigned long *p2m; | 664 | unsigned long *p2m; |
690 | unsigned long *mid_mfn_p; | ||
691 | unsigned idx; | 665 | unsigned idx; |
692 | unsigned long pfn; | 666 | unsigned long pfn; |
693 | 667 | ||
@@ -733,11 +707,6 @@ bool __init early_can_reuse_p2m_middle(unsigned long set_pfn, unsigned long set_ | |||
733 | found: | 707 | found: |
734 | /* Found one, replace old with p2m_identity or p2m_missing */ | 708 | /* Found one, replace old with p2m_identity or p2m_missing */ |
735 | p2m_top[topidx][mididx] = (ident_pfns ? p2m_identity : p2m_missing); | 709 | p2m_top[topidx][mididx] = (ident_pfns ? p2m_identity : p2m_missing); |
736 | /* And the other for save/restore.. */ | ||
737 | mid_mfn_p = p2m_top_mfn_p[topidx]; | ||
738 | /* NOTE: Even if it is a p2m_identity it should still be point to | ||
739 | * a page filled with INVALID_P2M_ENTRY entries. */ | ||
740 | mid_mfn_p[mididx] = virt_to_mfn(p2m_missing); | ||
741 | 710 | ||
742 | /* Reset where we want to stick the old page in. */ | 711 | /* Reset where we want to stick the old page in. */ |
743 | topidx = p2m_top_index(set_pfn); | 712 | topidx = p2m_top_index(set_pfn); |
@@ -752,8 +721,6 @@ found: | |||
752 | 721 | ||
753 | p2m_init(p2m); | 722 | p2m_init(p2m); |
754 | p2m_top[topidx][mididx] = p2m; | 723 | p2m_top[topidx][mididx] = p2m; |
755 | mid_mfn_p = p2m_top_mfn_p[topidx]; | ||
756 | mid_mfn_p[mididx] = virt_to_mfn(p2m); | ||
757 | 724 | ||
758 | return true; | 725 | return true; |
759 | } | 726 | } |
@@ -763,7 +730,7 @@ bool __init early_set_phys_to_machine(unsigned long pfn, unsigned long mfn) | |||
763 | if (!early_alloc_p2m_middle(pfn)) | 730 | if (!early_alloc_p2m_middle(pfn)) |
764 | return false; | 731 | return false; |
765 | 732 | ||
766 | if (early_can_reuse_p2m_middle(pfn, mfn)) | 733 | if (early_can_reuse_p2m_middle(pfn)) |
767 | return __set_phys_to_machine(pfn, mfn); | 734 | return __set_phys_to_machine(pfn, mfn); |
768 | 735 | ||
769 | if (!early_alloc_p2m(pfn, false /* boundary crossover OK!*/)) | 736 | if (!early_alloc_p2m(pfn, false /* boundary crossover OK!*/)) |