From: "Jan Beulich" Subject: [PATCH] x86-64: guest directed placement of initial p->m map Date: Thu, 08 Jan 2009 11:19:54 +0000 Message-ID: <4965EF6A.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartEFC7CE4A.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartEFC7CE4A.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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. Signed-off-by: Jan Beulich --- 2009-01-08.orig/tools/include/xen-foreign/reference.size 2009-01-08 = 11:44:11.000000000 +0100 +++ 2009-01-08/tools/include/xen-foreign/reference.size 2009-01-08 = 10:56:30.000000000 +0100 @@ -1,7 +1,7 @@ =20 structs | x86_32 x86_64 ia64 =20 -start_info | 1104 1152 1152 +start_info | 1112 1168 1168 trap_info | 8 16 - pt_fpreg | - - 16 cpu_user_regs | 68 200 - --- 2009-01-08.orig/xen/arch/x86/domain_build.c 2009-01-08 10:56:13.0000000= 00 +0100 +++ 2009-01-08/xen/arch/x86/domain_build.c 2009-01-08 11:44:42.0000000= 00 +0100 @@ -341,6 +341,12 @@ int __init construct_dom0( #endif } =20 + if ( (parms.p2m_base !=3D UNSET_ADDR) && elf_32bit(&elf) ) + { + printk(XENLOG_WARNING "P2M table base ignored\n"); + parms.p2m_base =3D UNSET_ADDR; + } + domain_set_alloc_bitsize(d); =20 /* @@ -359,6 +365,8 @@ int __init construct_dom0( vphysmap_end =3D vphysmap_start + (nr_pages * (!is_pv_32on64_domai= n(d) ? sizeof(unsigned = long) : sizeof(unsigned = int))); + if ( parms.p2m_base !=3D UNSET_ADDR ) + vphysmap_end =3D vphysmap_start; vstartinfo_start =3D round_pgup(vphysmap_end); vstartinfo_end =3D (vstartinfo_start + sizeof(struct start_info) + @@ -400,6 +408,11 @@ int __init construct_dom0( /* Ensure that our low-memory 1:1 mapping covers the allocation. */ page =3D alloc_domheap_pages(d, order, MEMF_bits(30)); #else + if ( parms.p2m_base !=3D UNSET_ADDR ) + { + vphysmap_start =3D parms.p2m_base; + vphysmap_end =3D vphysmap_start + nr_pages * sizeof(unsigned = long); + } page =3D alloc_domheap_pages(d, order, 0); #endif if ( page =3D=3D NULL ) @@ -740,8 +753,109 @@ int __init construct_dom0( snprintf(si->magic, sizeof(si->magic), "xen-3.0-x86_%d%s", elf_64bit(&elf) ? 64 : 32, parms.pae ? "p" : ""); =20 + count =3D d->tot_pages; +#ifdef __x86_64__ + /* Set up the phys->machine table if not part of the initial mapping. = */ + if ( parms.p2m_base !=3D UNSET_ADDR ) + { + unsigned long va =3D vphysmap_start; + + if ( v_start <=3D vphysmap_end && vphysmap_start <=3D v_end ) + panic("DOM0 P->M table overlaps initial mapping"); + + while ( va < vphysmap_end ) + { + if ( d->tot_pages + ((round_pgup(vphysmap_end) - va) + >> PAGE_SHIFT) + 3 > nr_pages ) + panic("Dom0 allocation too small for initial P->M = table.\n"); + + l4tab =3D l4start + l4_table_offset(va); + if ( !l4e_get_intpte(*l4tab) ) + { + page =3D alloc_domheap_pages(d, 0, 0); + if ( !page ) + break; + /* No mapping, PGC_allocated + page-table page. */ + page->count_info =3D PGC_allocated | 2; + page->u.inuse.type_info =3D + PGT_l3_page_table | PGT_validated | 1; + clear_page(page_to_virt(page)); + *l4tab =3D l4e_from_page(page, L4_PROT); + } + l3tab =3D page_to_virt(l4e_get_page(*l4tab)); + l3tab +=3D l3_table_offset(va); + if ( !l3e_get_intpte(*l3tab) ) + { + if ( cpu_has_page1gb && + !(va & ((1UL << L3_PAGETABLE_SHIFT) - 1)) && + vphysmap_end >=3D va + (1UL << L3_PAGETABLE_SHIFT) = && + (page =3D alloc_domheap_pages(d, + L3_PAGETABLE_SHIFT - + PAGE_SHIFT, + 0)) !=3D NULL ) + { + *l3tab =3D l3e_from_page(page, + L1_PROT|_PAGE_DIRTY|_PAGE_PSE);= + va +=3D 1UL << L3_PAGETABLE_SHIFT; + continue; + } + if ( (page =3D alloc_domheap_pages(d, 0, 0)) =3D=3D NULL = ) + break; + else + { + /* No mapping, PGC_allocated + page-table page. */ + page->count_info =3D PGC_allocated | 2; + page->u.inuse.type_info =3D + PGT_l2_page_table | PGT_validated | 1; + clear_page(page_to_virt(page)); + *l3tab =3D l3e_from_page(page, L3_PROT); + } + } + l2tab =3D page_to_virt(l3e_get_page(*l3tab)); + l2tab +=3D l2_table_offset(va); + if ( !l2e_get_intpte(*l2tab) ) + { + if ( !(va & ((1UL << L2_PAGETABLE_SHIFT) - 1)) && + vphysmap_end >=3D va + (1UL << L2_PAGETABLE_SHIFT) = && + (page =3D alloc_domheap_pages(d, + L2_PAGETABLE_SHIFT - + PAGE_SHIFT, + 0)) !=3D NULL ) + { + *l2tab =3D l2e_from_page(page, + L1_PROT|_PAGE_DIRTY|_PAGE_PSE);= + va +=3D 1UL << L2_PAGETABLE_SHIFT; + continue; + } + if ( (page =3D alloc_domheap_pages(d, 0, 0)) =3D=3D NULL = ) + break; + else + { + /* No mapping, PGC_allocated + page-table page. */ + page->count_info =3D PGC_allocated | 2; + page->u.inuse.type_info =3D + PGT_l1_page_table | PGT_validated | 1; + clear_page(page_to_virt(page)); + *l2tab =3D l2e_from_page(page, L2_PROT); + } + } + l1tab =3D page_to_virt(l2e_get_page(*l2tab)); + l1tab +=3D l1_table_offset(va); + BUG_ON(l1e_get_intpte(*l1tab)); + page =3D alloc_domheap_pages(d, 0, 0); + if ( !page ) + break; + *l1tab =3D l1e_from_page(page, L1_PROT|_PAGE_DIRTY); + va +=3D PAGE_SIZE; + va &=3D PAGE_MASK; + } + if ( !page ) + panic("Not enough RAM for DOM0 P->M table.\n"); + } +#endif + /* Write the phys->machine and machine->phys table entries. */ - for ( pfn =3D 0; pfn < d->tot_pages; pfn++ ) + for ( pfn =3D 0; pfn < count; pfn++ ) { mfn =3D pfn + alloc_spfn; #ifndef NDEBUG @@ -755,6 +869,26 @@ int __init construct_dom0( ((unsigned int *)vphysmap_start)[pfn] =3D mfn; set_gpfn_from_mfn(mfn, pfn); } + si->first_p2m_pfn =3D pfn; + si->nr_p2m_frames =3D d->tot_pages - count; + list_for_each_entry ( page, &d->page_list, list ) + { + mfn =3D page_to_mfn(page); + if ( get_gpfn_from_mfn(mfn) >=3D count ) + { + BUG_ON(is_pv_32bit_domain(d)); + if ( !page->u.inuse.type_info && + !get_page_and_type(page, d, PGT_writable_page) ) + BUG(); + ((unsigned long *)vphysmap_start)[pfn] =3D mfn; + set_gpfn_from_mfn(mfn, pfn); + ++pfn; +#ifndef NDEBUG + ++alloc_epfn; +#endif + } + } + BUG_ON(pfn !=3D d->tot_pages); while ( pfn < nr_pages ) { if ( (page =3D alloc_chunk(d, nr_pages - d->tot_pages)) =3D=3D = NULL ) --- 2009-01-08.orig/xen/arch/x86/mm.c 2009-01-08 11:44:11.000000000 = +0100 +++ 2009-01-08/xen/arch/x86/mm.c 2009-01-08 10:56:30.000000000 = +0100 @@ -1013,7 +1013,8 @@ static int put_page_from_l2e(l2_pgentry_ { unsigned long mfn =3D l2e_get_pfn(l2e), m =3D mfn; int writeable =3D 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_i static int put_page_from_l3e(l3_pgentry_t l3e, unsigned long pfn, int partial, int preemptible) { - if ( (l3e_get_flags(l3e) & _PAGE_PRESENT) &&=20 - (l3e_get_pfn(l3e) !=3D pfn) ) + if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) || (l3e_get_pfn(l3e) = =3D=3D 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), preemptibl= e); + unsigned long mfn =3D l3e_get_pfn(l3e); + int writeable =3D 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); } =20 #if CONFIG_PAGING_LEVELS >=3D 4 --- 2009-01-08.orig/xen/common/libelf/libelf-dominfo.c 2009-01-08 = 11:44:11.000000000 +0100 +++ 2009-01-08/xen/common/libelf/libelf-dominfo.c 2009-01-08 = 10:56:30.000000000 +0100 @@ -90,6 +90,7 @@ int elf_xen_parse_note(struct elf_binary [XEN_ELFNOTE_ENTRY] =3D { "ENTRY", 0}, [XEN_ELFNOTE_HYPERCALL_PAGE] =3D { "HYPERCALL_PAGE", 0}, [XEN_ELFNOTE_VIRT_BASE] =3D { "VIRT_BASE", 0}, + [XEN_ELFNOTE_INIT_P2M] =3D { "INIT_P2M", 0}, [XEN_ELFNOTE_PADDR_OFFSET] =3D { "PADDR_OFFSET", 0}, [XEN_ELFNOTE_HV_START_LOW] =3D { "HV_START_LOW", 0}, [XEN_ELFNOTE_XEN_VERSION] =3D { "XEN_VERSION", 1}, @@ -164,6 +165,9 @@ int elf_xen_parse_note(struct elf_binary case XEN_ELFNOTE_ENTRY: parms->virt_entry =3D val; break; + case XEN_ELFNOTE_INIT_P2M: + parms->p2m_base =3D val; + break; case XEN_ELFNOTE_PADDR_OFFSET: parms->elf_paddr_offset =3D val; break; @@ -392,6 +396,7 @@ static int elf_xen_addr_calc_check(struc elf_msg(elf, " virt_kstart =3D 0x%" PRIx64 "\n", parms->virt_k= start); elf_msg(elf, " virt_kend =3D 0x%" PRIx64 "\n", parms->virt_k= end); elf_msg(elf, " virt_entry =3D 0x%" PRIx64 "\n", parms->virt_e= ntry); + elf_msg(elf, " p2m_base =3D 0x%" PRIx64 "\n", parms->p2m_ba= se); =20 if ( (parms->virt_kstart > parms->virt_kend) || (parms->virt_entry < parms->virt_kstart) || @@ -403,6 +408,15 @@ static int elf_xen_addr_calc_check(struc return -1; } =20 + if ( (parms->p2m_base !=3D UNSET_ADDR) && + (parms->p2m_base >=3D 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; } =20 @@ -422,6 +436,7 @@ int elf_xen_parse(struct elf_binary *elf parms->virt_entry =3D UNSET_ADDR; parms->virt_hypercall =3D UNSET_ADDR; parms->virt_hv_start_low =3D UNSET_ADDR; + parms->p2m_base =3D UNSET_ADDR; parms->elf_paddr_offset =3D UNSET_ADDR; =20 /* Find and parse elf notes. */ --- 2009-01-08.orig/xen/include/public/elfnote.h 2009-01-08 = 11:44:11.000000000 +0100 +++ 2009-01-08/xen/include/public/elfnote.h 2009-01-08 10:56:30.0000000= 00 +0100 @@ -162,9 +162,20 @@ #define XEN_ELFNOTE_SUSPEND_CANCEL 14 =20 /* + * 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 =20 /* * System information exported through crash notes. --- 2009-01-08.orig/xen/include/public/libelf.h 2009-01-08 11:44:11.0000000= 00 +0100 +++ 2009-01-08/xen/include/public/libelf.h 2009-01-08 10:56:30.0000000= 00 +0100 @@ -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]; --- 2009-01-08.orig/xen/include/public/xen.h 2009-01-08 11:44:11.0000000= 00 +0100 +++ 2009-01-08/xen/include/public/xen.h 2009-01-08 10:56:30.000000000 = +0100 @@ -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; =20 --=__PartEFC7CE4A.0__= Content-Type: text/plain; name="xen-x86_64-note-init-p2m.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-x86_64-note-init-p2m.patch" From: jbeulich@novell.com=0ASubject: eliminate scalability issues from = initial mapping setup=0APatch-mainline: obsolete=0AReferences: bnc#417417= =0A=0ADirect Xen to place the initial P->M table outside of the initial=0Am= apping, as otherwise the 1G (implementation) / 2G (theoretical)=0Arestricti= on on the size of the initial mapping limits the amount=0Aof memory a = domain can be handed initially.=0A=0A--- head-2009-01-06.orig/arch/x86/kern= el/head64-xen.c 2008-12-15 11:28:15.000000000 +0100=0A+++ head-2009-01-06/a= rch/x86/kernel/head64-xen.c 2008-12-23 12:23:58.000000000 +0100=0A@@ = -171,6 +171,14 @@ void __init x86_64_start_reservations(ch=0A = + (xen_start_info->nr_pt_frames << PAGE_SHIFT),=0A "Xen = provided");=0A =0A+ if (xen_feature(XENFEAT_auto_translated_physmap))= =0A+ xen_start_info->mfn_list =3D ~0UL;=0A+ else if (xen_start_= info->mfn_list < __START_KERNEL_map)=0A+ reserve_early(xen_s= tart_info->first_p2m_pfn << PAGE_SHIFT,=0A+ = (xen_start_info->first_p2m_pfn=0A+ + xen_start_= info->nr_p2m_frames) << PAGE_SHIFT,=0A+ "INITP2M");= =0A+=0A /*=0A * At this point everything still needed from the = boot loader=0A * or BIOS or kernel text should be early reserved or = marked not=0A--- head-2009-01-06.orig/arch/x86/kernel/head_64-xen.S = 2008-12-15 11:34:16.000000000 +0100=0A+++ head-2009-01-06/arch/x86/kernel/h= ead_64-xen.S 2008-12-22 12:57:33.000000000 +0100=0A@@ -18,6 +18,7 @@=0A = #include =0A #include =0A #include = =0A+#include =0A #include =0A #include =0A #include =0A@@ -135,6 +136,7 @@ ENTRY(empty_zero_page)= =0A ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, .quad startup_64)=0A = ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .quad hypercall_page)=0A = ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID, .quad _PAGE_PRESENT, _PAGE_PRESENT= )=0A+ ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M, .quad VMEMMAP_START)=0A = ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .asciz "writable_page_tables|writa= ble_descriptor_tables|auto_translated_physmap|pae_pgdir_above_4gb|superviso= r_mode_kernel")=0A ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz = "generic")=0A ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long 1)=0A--- = head-2009-01-06.orig/arch/x86/kernel/setup-xen.c 2008-12-23 = 09:42:42.000000000 +0100=0A+++ head-2009-01-06/arch/x86/kernel/setup-xen.c = 2008-12-23 15:58:43.000000000 +0100=0A@@ -1022,7 +1022,7 @@ void __init = setup_arch(char **cmdline_p)=0A difference =3D xen_start_in= fo->nr_pages - max_pfn;=0A =0A set_xen_guest_handle(reservation.ex= tent_start,=0A- ((unsigned long *)xen_start_in= fo->mfn_list) + max_pfn);=0A+ phys_to_machin= e_mapping + max_pfn);=0A reservation.nr_extents =3D = difference;=0A ret =3D HYPERVISOR_memory_op(XENMEM_decrease_reserv= ation,=0A &reservation);=0A@@ = -1039,14 +1039,86 @@ void __init setup_arch(char **cmdline_p)=0A = phys_to_machine_mapping =3D alloc_bootmem_pages(=0A = max_pfn * sizeof(unsigned long));=0A memcpy(phys_to_machine_mapp= ing,=0A- (unsigned long *)xen_start_info->mfn_list,= =0A+ __va(__pa(xen_start_info->mfn_list)),=0A = p2m_pages * sizeof(unsigned long));=0A memset(phys_to_mach= ine_mapping + p2m_pages, ~0,=0A (max_pfn - = p2m_pages) * sizeof(unsigned long));=0A- free_bootmem(=0A- = __pa(xen_start_info->mfn_list),=0A- = PFN_PHYS(PFN_UP(xen_start_info->nr_pages *=0A- = sizeof(unsigned long))));=0A+=0A+#ifdef CONFIG_X86_64=0A+ if = (xen_start_info->mfn_list =3D=3D VMEMMAP_START) {=0A+ = /*=0A+ * Since it is well isolated we can (and since it = is=0A+ * perhaps large we should) also free the page = tables=0A+ * mapping the initial P->M table.=0A+ = */=0A+ unsigned long va =3D VMEMMAP_START, = pa;=0A+ pgd_t *pgd =3D pgd_offset_k(va);=0A+ = pud_t *pud_page =3D pud_offset(pgd, 0);=0A+=0A+ BUILD_BUG_O= N(VMEMMAP_START & ~PGDIR_MASK);=0A+ xen_l4_entry_update= (pgd, __pgd(0));=0A+ for(;;) {=0A+ = pud_t *pud =3D pud_page + pud_index(va);=0A+=0A+ = if (pud_none(*pud))=0A+ va +=3D = PUD_SIZE;=0A+ else if (pud_large(*pud)) {=0A+ = pa =3D pud_val(*pud) & PHYSICAL_PAGE_MASK;=0A+ = make_pages_writable(__va(pa),=0A+ = PUD_SIZE >> PAGE_SHIFT,=0A+ = XENFEAT_writable_page_tables);=0A+ = free_bootmem(pa, PUD_SIZE);=0A+ va = +=3D PUD_SIZE;=0A+ } else {=0A+ = pmd_t *pmd =3D pmd_offset(pud, va);=0A+=0A+ = if (pmd_large(*pmd)) {=0A+ = pa =3D pmd_val(*pmd) & PHYSICAL_PAGE_MASK;=0A+ = make_pages_writable(__va(pa),=0A+ = PMD_SIZE >> PAGE_SHIFT,=0A+ = XENFEAT_writable_page_tables);=0A+ = free_bootmem(pa, PMD_SIZE);=0A+ = } else if (!pmd_none(*pmd)) {=0A+ = pte_t *pte =3D pte_offset_kernel(pmd, va);=0A+=0A+ = for (i =3D 0; i < PTRS_PER_PTE; ++i) {=0A+ = if (pte_none(pte[i]))=0A+ = break;=0A+ = pa =3D pte_pfn(pte[i]) << PAGE_SHIFT;=0A+ = make_page_writable(__va(pa)= ,=0A+ XENFEAT_wri= table_page_tables);=0A+ = free_bootmem(pa, PAGE_SIZE);=0A+ = }=0A+ ClearPagePinned(virt_to_pag= e(pte));=0A+ make_page_writable(= pte,=0A+ XENFEAT_wri= table_page_tables);=0A+ free_bootme= m(__pa(pte), PAGE_SIZE);=0A+ }=0A+ = va +=3D PMD_SIZE;=0A+ = if (pmd_index(va))=0A+ = continue;=0A+ ClearPagePinned(virt_to_pag= e(pmd));=0A+ make_page_writable(pmd,=0A+= XENFEAT_writable_page_table= s);=0A+ free_bootmem(__pa((unsigned = long)pmd=0A+ & = PAGE_MASK),=0A+ PAGE_SIZE);=0A+ = }=0A+ if (!pud_index(va))=0A+ = break;=0A+ }=0A+ = ClearPagePinned(virt_to_page(pud_page));=0A+ make_page_w= ritable(pud_page,=0A+ XENFEAT_writable_page_table= s);=0A+ free_bootmem(__pa((unsigned long)pud_page & = PAGE_MASK),=0A+ PAGE_SIZE);=0A+ } else if = (!WARN_ON(xen_start_info->mfn_list=0A+ < = __START_KERNEL_map))=0A+#endif=0A+ free_bootmem(__pa(x= en_start_info->mfn_list),=0A+ PFN_PHYS(PFN_UP(xen= _start_info->nr_pages *=0A+ = sizeof(unsigned long))));=0A+=0A =0A /*=0A * = Initialise the list of the frames that specify the list of=0A--- head-2009-= 01-06.orig/arch/x86/mm/init_64-xen.c 2009-01-07 10:57:55.000000000 = +0100=0A+++ head-2009-01-06/arch/x86/mm/init_64-xen.c 2009-01-07 = 10:58:07.000000000 +0100=0A@@ -157,6 +157,17 @@ static unsigned long = __meminitdata table=0A static unsigned long __meminitdata table_cur;=0A = static unsigned long __meminitdata table_top;=0A =0A+static __init = unsigned long get_table_cur(void)=0A+{=0A+ BUG_ON(!table_cur);=0A+ if = (xen_start_info->mfn_list < __START_KERNEL_map=0A+ && table_cur = =3D=3D xen_start_info->first_p2m_pfn) {=0A+ table_cur +=3D = xen_start_info->nr_p2m_frames;=0A+ table_top +=3D xen_start_in= fo->nr_p2m_frames;=0A+ }=0A+ return table_cur++;=0A+}=0A+=0A /*=0A * = NOTE: This function is marked __ref because it calls __init function=0A * = (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem =3D=3D = 0.=0A@@ -168,8 +179,7 @@ static __ref void *spp_getpage(void)=0A if = (after_bootmem)=0A ptr =3D (void *) get_zeroed_page(GFP_ATOMIC= );=0A else if (table_cur < table_top) {=0A- ptr =3D __va(table_= cur << PAGE_SHIFT);=0A- table_cur++;=0A+ ptr =3D = __va(get_table_cur() << PAGE_SHIFT);=0A memset(ptr, 0, = PAGE_SIZE);=0A } else=0A ptr =3D alloc_bootmem_pages(PAGE_SI= ZE);=0A@@ -334,8 +344,7 @@ static __ref void *alloc_low_page(unsign=0A = return adr;=0A }=0A =0A- BUG_ON(!table_cur);=0A- pfn =3D table_cur++= ;=0A+ pfn =3D get_table_cur();=0A if (pfn >=3D table_top)=0A = panic("alloc_low_page: ran out of memory");=0A =0A@@ -361,14 +370,29 @@ = static inline int __meminit make_readonl=0A /* Make new page tables = read-only on the first pass. */=0A if (!xen_feature(XENFEAT_writable_p= age_tables)=0A && !max_pfn_mapped=0A- && (paddr >=3D = (table_start << PAGE_SHIFT))=0A- && (paddr < (table_top << = PAGE_SHIFT)))=0A- readonly =3D 1;=0A+ && (paddr >=3D = (table_start << PAGE_SHIFT))) {=0A+ unsigned long top =3D = table_top;=0A+=0A+ /* Account for the range get_table_cur() = skips. */=0A+ if (xen_start_info->mfn_list < __START_KERNEL_map= =0A+ && table_cur <=3D xen_start_info->first_p2m_pfn=0A+ = && top > xen_start_info->first_p2m_pfn)=0A+ top +=3D = xen_start_info->nr_p2m_frames;=0A+ if (paddr < (top << = PAGE_SHIFT))=0A+ readonly =3D 1;=0A+ }=0A /* = Make old page tables read-only. */=0A if (!xen_feature(XENFEAT_writable_p= age_tables)=0A && (paddr >=3D (xen_start_info->pt_base - __START_KERNE= L_map))=0A && (paddr < (table_cur << PAGE_SHIFT)))=0A = readonly =3D 1;=0A+ /* Make P->M table (and its page tables) read-only.= */=0A+ if (!xen_feature(XENFEAT_writable_page_tables)=0A+ && = xen_start_info->mfn_list < __START_KERNEL_map=0A+ && paddr >=3D = (xen_start_info->first_p2m_pfn << PAGE_SHIFT)=0A+ && paddr < = (xen_start_info->first_p2m_pfn=0A+ + xen_start_info->n= r_p2m_frames) << PAGE_SHIFT)=0A+ readonly =3D 1;=0A =0A = /*=0A * No need for writable mapping of kernel image. This also ensures = that=0A@@ -616,6 +640,12 @@ void __init xen_init_pt(void)=0A = __pud(__pa_symbol(level2_kernel_pgt) | _PAGE_TABLE);=0A memcpy(leve= l2_kernel_pgt, page, PAGE_SIZE);=0A =0A+ /* Copy the initial P->M = table mappings if necessary. */=0A+ addr =3D pgd_index(xen_start_info->= mfn_list);=0A+ if (addr < pgd_index(__START_KERNEL_map))=0A+ = init_level4_pgt[addr] =3D=0A+ ((pgd_t *)xen_start_info->p= t_base)[addr];=0A+=0A /* Do an early initialization of the fixmap area. = */=0A addr =3D __fix_to_virt(FIX_EARLYCON_MEM_BASE);=0A level3_kern= el_pgt[pud_index(addr)] =3D=0A@@ -675,22 +705,28 @@ static void __init = find_early_table_spac=0A static void __init xen_finish_init_mapping(void)= =0A {=0A unsigned long i, start, end;=0A+ struct mmuext_op = mmuext;=0A =0A /* Re-vector virtual addresses pointing into the initial=0A= mapping to the just-established permanent ones. */=0A = xen_start_info =3D __va(__pa(xen_start_info));=0A xen_start_info->pt_= base =3D (unsigned long)=0A __va(__pa(xen_start_info->pt_base))= ;=0A- if (!xen_feature(XENFEAT_auto_translated_physmap)) {=0A+ if = (!xen_feature(XENFEAT_auto_translated_physmap)=0A+ && xen_start_in= fo->mfn_list >=3D __START_KERNEL_map)=0A phys_to_machine_map= ping =3D=0A __va(__pa(xen_start_info->mfn_list));=0A- = xen_start_info->mfn_list =3D (unsigned long)=0A- = phys_to_machine_mapping;=0A- }=0A if (xen_start_info->mod_start)=0A = xen_start_info->mod_start =3D (unsigned long)=0A = __va(__pa(xen_start_info->mod_start));=0A =0A+ /* Unpin the no longer = used Xen provided page tables. */=0A+ mmuext.cmd =3D MMUEXT_UNPIN_TABLE;= =0A+ mmuext.arg1.mfn =3D pfn_to_mfn(__pa(xen_start_info->pt_base)=0A+ = >> PAGE_SHIFT);=0A+ if (HYPERVISOR_mmue= xt_op(&mmuext, 1, NULL, DOMID_SELF))=0A+ BUG();=0A+=0A /* = Destroy the Xen-created mappings beyond the kernel image. */=0A = start =3D PAGE_ALIGN((unsigned long)_end);=0A end =3D __START_KERNEL_ma= p + (table_start << PAGE_SHIFT);=0A@@ -934,9 +970,20 @@ unsigned long = __init_refok init_memory_m=0A =0A __flush_tlb_all();=0A =0A- if = (!after_bootmem && table_top > table_start)=0A+ if (!after_bootmem && = table_top > table_start) {=0A+ if (xen_start_info->mfn_list < = __START_KERNEL_map=0A+ && table_start <=3D xen_start_info->fir= st_p2m_pfn=0A+ && table_top > xen_start_info->first_p2m_pfn) = {=0A+ reserve_early(table_start << PAGE_SHIFT,=0A+ = xen_start_info->first_p2m_pfn=0A+ = << PAGE_SHIFT,=0A+ "PGTABLE");= =0A+ table_start =3D xen_start_info->first_p2m_pfn=0A+ = + xen_start_info->nr_p2m_frames;=0A+ = }=0A reserve_early(table_start << PAGE_SHIFT,=0A = table_top << PAGE_SHIFT, "PGTABLE");=0A+ }=0A =0A printk(KERN= _INFO "last_map_addr: %lx end: %lx\n",=0A last_map_a= ddr, end);=0A--- head-2009-01-06.orig/arch/x86/mm/pgtable-xen.c 2008-12-15 = 11:34:16.000000000 +0100=0A+++ head-2009-01-06/arch/x86/mm/pgtable-xen.c = 2008-12-23 14:38:22.000000000 +0100=0A@@ -323,7 +323,7 @@ void __init = xen_init_pgd_pin(void)=0A if (PTRS_PER_PUD > 1) /* not = folded */=0A SetPagePinned(virt_to_page(pud));=0A = for (u =3D 0; u < PTRS_PER_PUD; u++, pud++) {=0A- if = (!pud_present(*pud))=0A+ if (!pud_present(*pud) || = pud_large(*pud))=0A continue;=0A = pmd =3D pmd_offset(pud, 0);=0A if (PTRS_PER_PMD > 1) /* = not folded */=0A@@ -334,7 +334,7 @@ void __init xen_init_pgd_pin(void)=0A = && m >=3D pmd_index(HYPERVISOR_VIRT_START))=0A = continue;=0A #endif=0A- = if (!pmd_present(*pmd))=0A+ if = (!pmd_present(*pmd) || pmd_large(*pmd))=0A = continue;=0A SetPagePinned(pmd_page(*pmd));=0A = }=0A--- head-2009-01-06.orig/include/xen/interface/elfnote.= h 2008-11-25 12:35:56.000000000 +0100=0A+++ head-2009-01-06/include/x= en/interface/elfnote.h 2008-12-22 12:53:19.000000000 +0100=0A@@ -162,9 = +162,20 @@=0A #define XEN_ELFNOTE_SUSPEND_CANCEL 14=0A =0A /*=0A+ * The = (non-default) location the initial phys-to-machine map should be=0A+ * = placed at by the hypervisor (Dom0) or the tools (DomU).=0A+ * The kernel = must be prepared for this mapping to be established using=0A+ * large = pages, despite such otherwise not being available to guests.=0A+ * The = kernel must also be prepared that the page table pages used for=0A+ * this = mapping may not be accessible through the initial mapping.=0A+ * (Only = x86-64 supports this at present.)=0A+ */=0A+#define XEN_ELFNOTE_INIT_P2M = 15=0A+=0A+/*=0A * The number of the highest elfnote defined.=0A = */=0A-#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUSPEND_CANCEL=0A+#define = XEN_ELFNOTE_MAX XEN_ELFNOTE_INIT_P2M=0A =0A /*=0A * System information = exported through crash notes.=0A--- head-2009-01-06.orig/include/xen/interf= ace/xen.h 2008-12-15 11:27:38.000000000 +0100=0A+++ head-2009-01-06/i= nclude/xen/interface/xen.h 2008-12-23 10:50:00.000000000 +0100=0A@@ = -534,6 +534,7 @@ typedef struct shared_info shared_info_t=0A * a. = relocated kernel image=0A * b. initial ram disk = [mod_start, mod_len]=0A * c. list of allocated page frames [mfn_list,= nr_pages]=0A+ * (unless relocated due to XEN_ELFNOTE_INIT_P2M)=0A = * d. start_info_t structure [register ESI (x86)]=0A * = e. bootstrap page tables [pt_base, CR3 (x86)]=0A * f. = bootstrap stack [register ESP (x86)]=0A@@ -575,6 +576,9 @@ = struct start_info {=0A unsigned long mod_start; /* VIRTUAL address = of pre-loaded module. */=0A unsigned long mod_len; /* Size = (bytes) of pre-loaded module. */=0A int8_t cmd_line[MAX_GUEST_CMDLI= NE];=0A+ /* The pfn range here covers both page table and p->m table = frames. */=0A+ unsigned long first_p2m_pfn;/* 1st pfn forming initial = P->M table. */=0A+ unsigned long nr_p2m_frames;/* # of pfns forming = initial P->M table. */=0A };=0A typedef struct start_info start_info_t;=0A= =0A --=__PartEFC7CE4A.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartEFC7CE4A.0__=--