Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

xen: tolerate ACPI NVS memory overlapping with Xen allocated memory

In order to minimize required special handling for running as Xen PV
dom0, the memory layout is modified to match that of the host. This
requires to have only RAM at the locations where Xen allocated memory
is living. Unfortunately there seem to be some machines, where ACPI
NVS is located at 64 MB, resulting in a conflict with the loaded
kernel or the initial page tables built by Xen.

Avoid this conflict by swapping the ACPI NVS area in the memory map
with unused RAM. This is possible via modification of the dom0 P2M map.
Accesses to the ACPI NVS area are done either for saving and restoring
it across suspend operations (this will work the same way as before),
or by ACPI code when NVS memory is referenced from other ACPI tables.
The latter case is handled by a Xen specific indirection of
acpi_os_ioremap().

While the E820 map can (and should) be modified right away, the P2M
map can be updated only after memory allocation is working, as the P2M
map might need to be extended.

Fixes: 808fdb71936c ("xen: check for kernel memory conflicting with memory layout")
Signed-off-by: Juergen Gross <jgross@suse.com>
Tested-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>

+91 -1
+91 -1
arch/x86/xen/setup.c
··· 495 495 set_pte_mfn(buf, mfn_save, PAGE_KERNEL); 496 496 497 497 pr_info("Remapped %ld page(s)\n", remapped); 498 + 499 + xen_do_remap_nonram(); 498 500 } 499 501 500 502 static unsigned long __init xen_get_pages_limit(void) ··· 628 626 } 629 627 630 628 /* 629 + * Swap a non-RAM E820 map entry with RAM above ini_nr_pages. 630 + * Note that the E820 map is modified accordingly, but the P2M map isn't yet. 631 + * The adaption of the P2M must be deferred until page allocation is possible. 632 + */ 633 + static void __init xen_e820_swap_entry_with_ram(struct e820_entry *swap_entry) 634 + { 635 + struct e820_entry *entry; 636 + unsigned int mapcnt; 637 + phys_addr_t mem_end = PFN_PHYS(ini_nr_pages); 638 + phys_addr_t swap_addr, swap_size, entry_end; 639 + 640 + swap_addr = PAGE_ALIGN_DOWN(swap_entry->addr); 641 + swap_size = PAGE_ALIGN(swap_entry->addr - swap_addr + swap_entry->size); 642 + entry = xen_e820_table.entries; 643 + 644 + for (mapcnt = 0; mapcnt < xen_e820_table.nr_entries; mapcnt++) { 645 + entry_end = entry->addr + entry->size; 646 + if (entry->type == E820_TYPE_RAM && entry->size >= swap_size && 647 + entry_end - swap_size >= mem_end) { 648 + /* Reduce RAM entry by needed space (whole pages). */ 649 + entry->size -= swap_size; 650 + 651 + /* Add new entry at the end of E820 map. */ 652 + entry = xen_e820_table.entries + 653 + xen_e820_table.nr_entries; 654 + xen_e820_table.nr_entries++; 655 + 656 + /* Fill new entry (keep size and page offset). */ 657 + entry->type = swap_entry->type; 658 + entry->addr = entry_end - swap_size + 659 + swap_addr - swap_entry->addr; 660 + entry->size = swap_entry->size; 661 + 662 + /* Convert old entry to RAM, align to pages. */ 663 + swap_entry->type = E820_TYPE_RAM; 664 + swap_entry->addr = swap_addr; 665 + swap_entry->size = swap_size; 666 + 667 + /* Remember PFN<->MFN relation for P2M update. */ 668 + xen_add_remap_nonram(swap_addr, entry_end - swap_size, 669 + swap_size); 670 + 671 + /* Order E820 table and merge entries. */ 672 + e820__update_table(&xen_e820_table); 673 + 674 + return; 675 + } 676 + 677 + entry++; 678 + } 679 + 680 + xen_raw_console_write("No suitable area found for required E820 entry remapping action\n"); 681 + BUG(); 682 + } 683 + 684 + /* 685 + * Look for non-RAM memory types in a specific guest physical area and move 686 + * those away if possible (ACPI NVS only for now). 687 + */ 688 + static void __init xen_e820_resolve_conflicts(phys_addr_t start, 689 + phys_addr_t size) 690 + { 691 + struct e820_entry *entry; 692 + unsigned int mapcnt; 693 + phys_addr_t end; 694 + 695 + if (!size) 696 + return; 697 + 698 + end = start + size; 699 + entry = xen_e820_table.entries; 700 + 701 + for (mapcnt = 0; mapcnt < xen_e820_table.nr_entries; mapcnt++) { 702 + if (entry->addr >= end) 703 + return; 704 + 705 + if (entry->addr + entry->size > start && 706 + entry->type == E820_TYPE_NVS) 707 + xen_e820_swap_entry_with_ram(entry); 708 + 709 + entry++; 710 + } 711 + } 712 + 713 + /* 631 714 * Check for an area in physical memory to be usable for non-movable purposes. 632 - * An area is considered to usable if the used E820 map lists it to be RAM. 715 + * An area is considered to usable if the used E820 map lists it to be RAM or 716 + * some other type which can be moved to higher PFNs while keeping the MFNs. 633 717 * In case the area is not usable, crash the system with an error message. 634 718 */ 635 719 void __init xen_chk_is_e820_usable(phys_addr_t start, phys_addr_t size, 636 720 const char *component) 637 721 { 722 + xen_e820_resolve_conflicts(start, size); 723 + 638 724 if (!xen_is_e820_reserved(start, size)) 639 725 return; 640 726