x86-64: guest directed placement of initial p->m map
Subsystems (3)
PATCH 1/1 x86-64: guest directed placement of initial p->m map
By adding another ELF note, the kernel can now direct the hypervisor (for Dom0) and in the future also the tools (for DomU-s) to place the initial phys->mach translation table at other than an address immediately above the kernel/initrd images. This eliminates the size restriction imposed on this table by Linux (the kernel loads above the -2Gb boundary, and hence the entire initial mapping cannot reach or even exceed 2Gb).
There are a few items in this patch I'm not particularly happy with, but couldn't think of a better solution:
- there is a hidden assumption that pages allocated for the domain are put on the domain's page list sequentially
- the way backward compatibility is maintained is placing requirements on the kernel side that make the code somewhat convoluted (because it needs to check where the map is actually placed in quite a few places)
- code is there to use 1Gb mappings for the hypervisor created table, but lacking a machine with 512G+ memory for immediate testing I can't verify this works; I know that 2Mb mappings work, and hence imply that 1Gb ones would too (of course, if the kernel replaces the table
- like Linux does -, it cannot use 2Mb/1Gb mappings or even try to re-use the page table entries, but I don't consider this a problem)
Also I'm uncertain whether any version number needs to be bumped due to the start_info addition.
For reference, I'm attaching our Linux side patch - it doesn't seem reasonable to port it to the 2.6.18 tree, both because it alone only bumps the supportable memory amount from (presumably) somewhere around 500G to somewhere below 1T (to drop all limitations beyond those also found in native kernels a second patch eliminating extend_init_mapping() in favor of a fully scalable approach is needed), and because it (from what I can tell) uses some constructs only available in newer kernels.
tools/include/xen-foreign/reference.size +1 -1
@@ -1,7 +1,7 @@ structs | x86_32 x86_64 ia64 -start_info | 1104 1152 1152 +start_info | 1112 1168 1168 trap_info | 8 16 - pt_fpreg | - - 16 cpu_user_regs | 68 200 -
xen/arch/x86/domain_build.c +135 -1
167 lines not on this page · raw message
xen/arch/x86/mm.c +22 -7
@@ -1013,7 +1013,8 @@ static int put_page_from_l2e(l2_pgentry_ {unsigned long mfn =l2e_get_pfn (l2e), m = mfn;int writeable =l2e_get_flags (l2e) & _PAGE_RW; -ASSERT (opt_allow_hugepage && !(mfn & (L1_PAGETABLE_ENTRIES -1 ))); + +ASSERT (!(mfn & (L1_PAGETABLE_ENTRIES -1 )));do {put_data_page (mfn_to_page (m), writeable); }while ( m++ < (mfn + (L1_PAGETABLE_ENTRIES -1 )) );
@@ -1031,14 +1032,28 @@ static int __put_page_type(struct page_istatic int put_page_from_l3e (l3_pgentry_t l3e,unsigned long pfn,int partial,int preemptible) { -if ( (l3e_get_flags (l3e) & _PAGE_PRESENT) && - (l3e_get_pfn (l3e) != pfn) ) +if ( !(l3e_get_flags (l3e) & _PAGE_PRESENT) || (l3e_get_pfn (l3e) == pfn) ) +return 1 ; + +#ifdef __x86_64__ +if (unlikely (l3e_get_flags (l3e) & _PAGE_PSE) ) { -if (unlikely (partial >0 ) ) -return __put_page_type (l3e_get_page (l3e), preemptible); -return put_page_and_type_preemptible (l3e_get_page (l3e), preemptible); +unsigned long mfn =l3e_get_pfn (l3e); +int writeable =l3e_get_flags (l3e) & _PAGE_RW; + +ASSERT (!(mfn & ((1UL << (L3_PAGETABLE_SHIFT -PAGE_SHIFT )) -1 ))); +do { +put_data_page (mfn_to_page (mfn), writeable); + }while ( ++mfn & ((1UL << (L3_PAGETABLE_SHIFT -PAGE_SHIFT )) -1 ) ); + +return 0 ; } -return 1 ; +#endif + +if (unlikely (partial >0 ) ) +return __put_page_type (l3e_get_page (l3e), preemptible); + +return put_page_and_type_preemptible (l3e_get_page (l3e), preemptible); }#if CONFIG_PAGING_LEVELS >=4
xen/common/libelf/libelf-dominfo.c +15 -0
@@ -90,6 +90,7 @@ int elf_xen_parse_note(struct elf_binary [XEN_ELFNOTE_ENTRY] = { "ENTRY", 0}, [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", 0}, [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", 0}, + [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", 0}, [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", 0}, [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", 0}, [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", 1},
@@ -164,6 +165,9 @@ int elf_xen_parse_note(struct elf_binarycase XEN_ELFNOTE_ENTRY : parms->virt_entry = val;break ; +case XEN_ELFNOTE_INIT_P2M : + parms->p2m_base = val; +break ;case XEN_ELFNOTE_PADDR_OFFSET : parms->elf_paddr_offset = val;break ;
@@ -392,6 +396,7 @@ static int elf_xen_addr_calc_check(strucelf_msg (elf," virt_kstart = 0x%" PRIx64"\n" , parms->virt_kstart);elf_msg (elf," virt_kend = 0x%" PRIx64"\n" , parms->virt_kend);elf_msg (elf," virt_entry = 0x%" PRIx64"\n" , parms->virt_entry); +elf_msg (elf," p2m_base = 0x%" PRIx64"\n" , parms->p2m_base); if ( (parms->virt_kstart > parms->virt_kend) || (parms->virt_entry < parms->virt_kstart) ||
@@ -403,6 +408,15 @@ static int elf_xen_addr_calc_check(strucreturn -1 ; } +if ( (parms->p2m_base !=UNSET_ADDR ) && + (parms->p2m_base >= parms->virt_kstart) && + (parms->p2m_base < parms->virt_kend) ) + { +elf_err (elf,"%s: ERROR: P->M table base is out of bounds.\n" , + __FUNCTION__); +return -1 ; + } +return 0 ; }
@@ -422,6 +436,7 @@ int elf_xen_parse(struct elf_binary *elf parms->virt_entry =UNSET_ADDR ; parms->virt_hypercall =UNSET_ADDR ; parms->virt_hv_start_low =UNSET_ADDR ; + parms->p2m_base =UNSET_ADDR ; parms->elf_paddr_offset =UNSET_ADDR ;/* Find and parse elf notes. */
xen/include/public/elfnote.h +12 -1
@@ -162,9 +162,20 @@#define XEN_ELFNOTE_SUSPEND_CANCEL 14/* +* The (non-default) location the initial phys-to-machine map should be +* placed at by the hypervisor (Dom0) or the tools (DomU). +* The kernel must be prepared for this mapping to be established using +* large pages, despite such otherwise not being available to guests. +* The kernel must also be able to handle the page table pages used for +* this mapping not being accessible through the initial mapping. +* (Only x86-64 supports this at present.) +*/ +#define XEN_ELFNOTE_INIT_P2M 15 + +/* * The number of the highest elfnote defined. */ -#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUSPEND_CANCEL +#define XEN_ELFNOTE_MAX XEN_ELFNOTE_INIT_P2M/* * System information exported through crash notes.
xen/include/public/libelf.h +1 -0
@@ -232,6 +232,7 @@ struct elf_dom_parms {uint64_t virt_entry;uint64_t virt_hypercall;uint64_t virt_hv_start_low; +uint64_t p2m_base;uint64_t elf_paddr_offset;uint32_t f_supported[XENFEAT_NR_SUBMAPS ];uint32_t f_required[XENFEAT_NR_SUBMAPS ];
xen/include/public/xen.h +4 -0
@@ -513,6 +513,7 @@ typedef struct shared_info shared_info_t* a. relocated kernel image * b. initial ram disk [mod_start, mod_len] * c. list of allocated page frames [mfn_list, nr_pages] +* (unless relocated due to XEN_ELFNOTE_INIT_P2M) * d. start_info_t structure [register ESI (x86)] * e. bootstrap page tables [pt_base, CR3 (x86)] * f. bootstrap stack [register ESP (x86)]
@@ -554,6 +555,9 @@ struct start_info {unsigned long mod_start;/* VIRTUAL address of pre-loaded module. */ unsigned long mod_len;/* Size (bytes) of pre-loaded module. */ int8_t cmd_line[MAX_GUEST_CMDLINE ]; +/* The pfn range here covers both page table and p->m table frames. */ +unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */ +unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */ };typedef struct start_info start_info_t ;
From: [email protected]
Subject: eliminate scalability issues from initial mapping setup
Patch-mainline: obsolete
References: bnc#417417
Direct Xen to place the initial P->M table outside of the initial mapping, as otherwise the 1G (implementation) / 2G (theoretical) restriction on the size of the initial mapping limits the amount of memory a domain can be handed initially.
arch/x86/kernel/head64-xen.c +8 -0
@@ -171,6 +171,14 @@ void __init x86_64_start_reservations(ch + (xen_start_info->nr_pt_frames <<PAGE_SHIFT ), "Xen provided"); +if (xen_feature (XENFEAT_auto_translated_physmap)) + xen_start_info->mfn_list = ~0UL ; +else if (xen_start_info->mfn_list < __START_KERNEL_map) +reserve_early (xen_start_info->first_p2m_pfn <<PAGE_SHIFT , + (xen_start_info->first_p2m_pfn + + xen_start_info->nr_p2m_frames) <<PAGE_SHIFT , +"INITP2M" ); +/* * At this point everything still needed from the boot loader * or BIOS or kernel text should be early reserved or marked not
arch/x86/kernel/head_64-xen.S +2 -0
@@ -18,6 +18,7 @@ #include <asm/desc.h> #include <asm/segment.h> #include <asm/page.h> +#include <asm/pgtable.h> #include <asm/msr.h> #include <asm/cache.h> #include <asm/dwarf2.h>
@@ -135,6 +136,7 @@ ENTRY(empty_zero_page) ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, .quad startup_64) ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .quad hypercall_page) ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID, .quad _PAGE_PRESENT, _PAGE_PRESENT) + ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M, .quad VMEMMAP_START) ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .asciz "writable_page_tables|writable_descriptor_tables|auto_translated_physmap|pae_pgdir_above_4gb|supervisor_mode_kernel") ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic") ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long 1)
arch/x86/kernel/setup-xen.c +78 -6
99 lines not on this page · raw message
arch/x86/mm/init_64-xen.c +59 -12
132 lines not on this page · raw message
arch/x86/mm/pgtable-xen.c +2 -2
@@ -323,7 +323,7 @@ void __init xen_init_pgd_pin(void)if (PTRS_PER_PUD >1 )/* not folded */ SetPagePinned (virt_to_page (pud));for (u =0 ; u <PTRS_PER_PUD ; u++, pud++) { -if (!pud_present (*pud)) +if (!pud_present (*pud) ||pud_large (*pud))continue ; pmd =pmd_offset (pud,0 );if (PTRS_PER_PMD >1 )/* not folded */
@@ -334,7 +334,7 @@ void __init xen_init_pgd_pin(void) && m >= pmd_index(HYPERVISOR_VIRT_START))continue ;#endif -if (!pmd_present (*pmd)) +if (!pmd_present (*pmd) ||pmd_large (*pmd))continue ;SetPagePinned (pmd_page (*pmd)); }
include/xen/interface/elfnote.h +12 -1
@@ -162,9 +162,20 @@#define XEN_ELFNOTE_SUSPEND_CANCEL 14/* +* The (non-default) location the initial phys-to-machine map should be +* placed at by the hypervisor (Dom0) or the tools (DomU). +* The kernel must be prepared for this mapping to be established using +* large pages, despite such otherwise not being available to guests. +* The kernel must also be prepared that the page table pages used for +* this mapping may not be accessible through the initial mapping. +* (Only x86-64 supports this at present.) +*/ +#define XEN_ELFNOTE_INIT_P2M 15 + +/* * The number of the highest elfnote defined. */ -#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUSPEND_CANCEL +#define XEN_ELFNOTE_MAX XEN_ELFNOTE_INIT_P2M/* * System information exported through crash notes.
include/xen/interface/xen.h +4 -0
@@ -534,6 +534,7 @@ typedef struct shared_info shared_info_t* a. relocated kernel image * b. initial ram disk [mod_start, mod_len] * c. list of allocated page frames [mfn_list, nr_pages] +* (unless relocated due to XEN_ELFNOTE_INIT_P2M) * d. start_info_t structure [register ESI (x86)] * e. bootstrap page tables [pt_base, CR3 (x86)] * f. bootstrap stack [register ESP (x86)]
@@ -575,6 +576,9 @@ struct start_info {unsigned long mod_start;/* VIRTUAL address of pre-loaded module. */ unsigned long mod_len;/* Size (bytes) of pre-loaded module. */ int8_t cmd_line[MAX_GUEST_CMDLINE ]; +/* The pfn range here covers both page table and p->m table frames. */ +unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */ +unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */ };typedef struct start_info start_info_t ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel