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: add capability to remap non-RAM pages to different PFNs

When running as a Xen PV dom0 it can happen that the kernel is being
loaded to a guest physical address conflicting with the host memory
map.

In order to be able to resolve this conflict, add the capability to
remap non-RAM areas to different guest PFNs. A function to use this
remapping information for other purposes than doing the remap will be
added when needed.

As the number of conflicts should be rather low (currently only
machines with max. 1 conflict are known), save the remap data in a
small statically allocated array.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>

+66
+63
arch/x86/xen/p2m.c
··· 80 80 #include <asm/xen/hypervisor.h> 81 81 #include <xen/balloon.h> 82 82 #include <xen/grant_table.h> 83 + #include <xen/hvc-console.h> 83 84 84 85 #include "xen-ops.h" 85 86 ··· 791 790 kunmap_ops, count) ?: ret; 792 791 793 792 return ret; 793 + } 794 + 795 + /* Remapped non-RAM areas */ 796 + #define NR_NONRAM_REMAP 4 797 + static struct nonram_remap { 798 + phys_addr_t maddr; 799 + phys_addr_t paddr; 800 + size_t size; 801 + } xen_nonram_remap[NR_NONRAM_REMAP] __ro_after_init; 802 + static unsigned int nr_nonram_remap __ro_after_init; 803 + 804 + /* 805 + * Do the real remapping of non-RAM regions as specified in the 806 + * xen_nonram_remap[] array. 807 + * In case of an error just crash the system. 808 + */ 809 + void __init xen_do_remap_nonram(void) 810 + { 811 + unsigned int i; 812 + unsigned int remapped = 0; 813 + const struct nonram_remap *remap = xen_nonram_remap; 814 + unsigned long pfn, mfn, end_pfn; 815 + 816 + for (i = 0; i < nr_nonram_remap; i++) { 817 + end_pfn = PFN_UP(remap->paddr + remap->size); 818 + pfn = PFN_DOWN(remap->paddr); 819 + mfn = PFN_DOWN(remap->maddr); 820 + while (pfn < end_pfn) { 821 + if (!set_phys_to_machine(pfn, mfn)) 822 + panic("Failed to set p2m mapping for pfn=%lx mfn=%lx\n", 823 + pfn, mfn); 824 + 825 + pfn++; 826 + mfn++; 827 + remapped++; 828 + } 829 + 830 + remap++; 831 + } 832 + 833 + pr_info("Remapped %u non-RAM page(s)\n", remapped); 834 + } 835 + 836 + /* 837 + * Add a new non-RAM remap entry. 838 + * In case of no free entry found, just crash the system. 839 + */ 840 + void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr, 841 + unsigned long size) 842 + { 843 + BUG_ON((maddr & ~PAGE_MASK) != (paddr & ~PAGE_MASK)); 844 + 845 + if (nr_nonram_remap == NR_NONRAM_REMAP) { 846 + xen_raw_console_write("Number of required E820 entry remapping actions exceed maximum value\n"); 847 + BUG(); 848 + } 849 + 850 + xen_nonram_remap[nr_nonram_remap].maddr = maddr; 851 + xen_nonram_remap[nr_nonram_remap].paddr = paddr; 852 + xen_nonram_remap[nr_nonram_remap].size = size; 853 + 854 + nr_nonram_remap++; 794 855 } 795 856 796 857 #ifdef CONFIG_XEN_DEBUG_FS
+3
arch/x86/xen/xen-ops.h
··· 47 47 #ifdef CONFIG_X86_64 48 48 void __init xen_relocate_p2m(void); 49 49 #endif 50 + void __init xen_do_remap_nonram(void); 51 + void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr, 52 + unsigned long size); 50 53 51 54 void __init xen_chk_is_e820_usable(phys_addr_t start, phys_addr_t size, 52 55 const char *component);