From: "Jan Beulich" Subject: [PATCH 0/7] x86: improve handling of sparse physical memory maps Date: Mon, 21 Sep 2009 13:03:39 +0100 Message-ID: <4AB787BB0200007800015F1E@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part755E858B.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. --=__Part755E858B.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Significant holes in the physical memory map weren't handled gracefully so far in Xen: The overhead of setting up a fully linear 1:1 mapping as well as a fully linear frame table could so high that Xen wouldn't boot on extreme systems. The following adjustments are being made in each patch of this series: 1) For x86-64, the virtual range reserved for the 1:1 mapping gets extended to cover 5Tb, and the virtual size of the frame table gets changed to match whatever the 1:1 table can cover. 2) The largest range of contiguous bits which are zero for all valid MFNs gets removed from the MFN representation used to index into the 1:1 mapping and frame table, thereby cutting the virtual range these tables must cover approximately by half with each bit removed. 3) The reduced in size frame table gets mapped sparsely, i.e. holes of MFN ranges spanning a sufficiently large range will no longer have struct page_info instances allocated for them. 4) The non-reducible (in virtual size) M2P table gets allocated sparsely in the same manner (just requiring larger holes for a table chunk to be omitted). This ends the portion of the patch series that deal with overhead reduction. On a partner system with suitable memory layout, this patch series has been shown to reduce Xen memory overhead from 14.2% of total memory to 1.8%, thus getting reasonably close to the theoretically minimal overhead of 1.3% (counting just frame table, 1:1 mapping, and M->P tables). Since the more complex calculations resulted in not insignificant code bloat, the following non-essential patches represent possible attempts to reduce the code size overhead, and should be considered RFC: 5) Introduce a variant of map_domain_page() directly getting passed a struct page_info * argument, based on the observation that in many places the argument to this function so far simply was the result of page_to_mfn(). This is meaningful for the x86-64 case where map_domain_page() really just is an invocation of mfn_to_virt(), and hence the combined mfn_to_virt(page_to_mfn()) now represents a needless roundtrip conversion compressed -> uncompressed -> compressed of the MFN representation. 6) The grant table code had some particularly frequent repetitions of mfn_to_page() on each time the same input arguments. To help the compiler (which can do only a limited job on CSE), this adds explicit caching of the transformation result in a few places. 7) This one is likely the most questionable part: Realizing that the compiler can do a much better job in terms of CSE when the variables needed are constant, this introduces and extension to the read-mostly variables, allowing variables to be marked as being written just during boot initialization. In the event of transmission problems with the patches (our IS&T folks, while now being aware of the patch corruption issues seen in the past, refuse to address the root cause of the problem for the time being), the full set of patches is attached here. Signed-off-by: Jan Beulich --=__Part755E858B.0__= Content-Type: text/plain; name="xen-x86_64-5Tb.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-x86_64-5Tb.patch" Extend the virtual range reserved for the 1:1 mapping to cover 5Tb, = and=0Amake the virtual size of the frame table gets match whatever the = 1:1=0Atable can cover.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- 2009-09-10.orig/xen/arch/x86/boot/head.S 2009-05-20 = 08:46:00.000000000 +0200=0A+++ 2009-09-10/xen/arch/x86/boot/head.S = 2009-09-10 15:27:09.000000000 +0200=0A@@ -33,7 +33,7 @@ ENTRY(start)=0A = /* Checksum: must be the negated sum of the first two fields. */=0A = .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)=0A =0A- = .section .init.text=0A+ .section .init.text, "ax"=0A =0A = .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"=0A .Lbad_ldr_msg: .asciz = "ERR: Not a Multiboot bootloader!"=0A@@ -128,13 +128,13 @@ __start:=0A = loop 1b=0A /* Initialise L3 xen-map page directory entry. = */=0A mov $(sym_phys(l2_xenmap)+7),%eax=0A- mov = %eax,sym_phys(l3_xenmap) + (50*8)=0A+ mov %eax,sym_phys(l3_xenma= p) + l3_table_offset(XEN_VIRT_START)*8=0A /* Hook identity-map and = xen-map L3 tables into PML4. */=0A mov $(sym_phys(l3_identmap)+= 7),%eax=0A mov %eax,sym_phys(idle_pg_table) + ( 0*8) /* PML4[ = 0]: 1:1 map */=0A- mov %eax,sym_phys(idle_pg_table) + (262*8) = /* PML4[262]: 1:1 map */=0A+ mov %eax,sym_phys(idle_pg_table) + = l4_table_offset(DIRECTMAP_VIRT_START)*8=0A mov $(sym_phys(l3_xe= nmap)+7),%eax=0A- mov %eax,sym_phys(idle_pg_table) + (261*8) /* = PML4[261]: xen map */=0A+ mov %eax,sym_phys(idle_pg_table) + = l4_table_offset(XEN_VIRT_START)*8=0A #else=0A /* Initialize low = and high mappings of memory with 2MB pages */=0A mov $sym_phys(= idle_pg_table_l2),%edi=0A--- 2009-09-10.orig/xen/arch/x86/e820.c = 2009-09-10 15:26:52.000000000 +0200=0A+++ 2009-09-10/xen/arch/x86/e820.c = 2009-09-10 15:27:09.000000000 +0200=0A@@ -500,15 +500,19 @@ static void = __init machine_specific_memo=0A "can be accessed by Xen = in 32-bit mode.");=0A #else=0A {=0A- unsigned long limit, = mpt_limit, pft_limit;=0A+ unsigned long limit, mpt_limit, ro_mpt_lim= it, pft_limit;=0A =0A limit =3D DIRECTMAP_VIRT_END - DIRECTMAP_VIRT= _START;=0A mpt_limit =3D ((RDWR_MPT_VIRT_END - RDWR_MPT_VIRT_START)= =0A / sizeof(unsigned long)) << PAGE_SHIFT;=0A+ = ro_mpt_limit =3D ((RO_MPT_VIRT_END - RO_MPT_VIRT_START)=0A+ = / sizeof(unsigned long)) << PAGE_SHIFT;=0A pft_limit =3D = ((FRAMETABLE_VIRT_END - FRAMETABLE_VIRT_START)=0A / = sizeof(struct page_info)) << PAGE_SHIFT;=0A if ( limit > mpt_limit = )=0A limit =3D mpt_limit;=0A+ if ( limit > ro_mpt_limit = )=0A+ limit =3D ro_mpt_limit;=0A if ( limit > pft_limit = )=0A limit =3D pft_limit;=0A clip_to_limit(limit,=0A---= 2009-09-10.orig/xen/arch/x86/mm.c 2009-09-10 15:26:52.000000000 = +0200=0A+++ 2009-09-10/xen/arch/x86/mm.c 2009-09-10 15:27:09.0000000= 00 +0200=0A@@ -166,6 +166,13 @@ void __init init_frametable(void)=0A {=0A = unsigned long nr_pages, page_step, i, mfn;=0A =0A+#ifdef __x86_64__=0A+ = BUILD_BUG_ON(FRAMETABLE_VIRT_START & ((1UL << L3_PAGETABLE_SHIFT) - = 1));=0A+ BUILD_BUG_ON(XEN_VIRT_END > FRAMETABLE_VIRT_END);=0A+#else=0A+ = BUILD_BUG_ON(FRAMETABLE_VIRT_START & ((1UL << L2_PAGETABLE_SHIFT) - = 1));=0A+#endif=0A+=0A nr_pages =3D PFN_UP(max_page * sizeof(*frame_tab= le));=0A page_step =3D 1 << (cpu_has_page1gb ? L3_PAGETABLE_SHIFT - = PAGE_SHIFT=0A : L2_PAGETABLE_SHIFT - = PAGE_SHIFT);=0A--- 2009-09-10.orig/xen/include/asm-x86/config.h 2009-09-10 = 15:26:52.000000000 +0200=0A+++ 2009-09-10/xen/include/asm-x86/config.h = 2009-09-10 15:27:09.000000000 +0200=0A@@ -148,21 +148,19 @@ extern = unsigned int video_mode, video_fl=0A * 0xffff828000000000 - 0xffff8283fff= fffff [16GB, 2^34 bytes, PML4:261]=0A * Machine-to-phys translation = table.=0A * 0xffff828400000000 - 0xffff8287ffffffff [16GB, 2^34 bytes, = PML4:261]=0A- * Page-frame information array.=0A- * 0xffff828800000000 = - 0xffff828bffffffff [16GB, 2^34 bytes, PML4:261]=0A * ioremap()/fixma= p area.=0A- * 0xffff828c00000000 - 0xffff828c3fffffff [1GB, 2^30 bytes, = PML4:261]=0A+ * 0xffff828800000000 - 0xffff82883fffffff [1GB, 2^30 = bytes, PML4:261]=0A * Compatibility machine-to-phys translation = table.=0A- * 0xffff828c40000000 - 0xffff828c7fffffff [1GB, 2^30 bytes, = PML4:261]=0A+ * 0xffff828840000000 - 0xffff82887fffffff [1GB, 2^30 = bytes, PML4:261]=0A * High read-only compatibility machine-to-phys = translation table.=0A- * 0xffff828c80000000 - 0xffff828cbfffffff [1GB, = 2^30 bytes, PML4:261]=0A+ * 0xffff828880000000 - 0xffff8288bfffffff [1GB, = 2^30 bytes, PML4:261]=0A * Xen text, static data, bss.=0A- * = 0xffff828cc0000000 - 0xffff82ffffffffff [461GB, PML4:261]=0A+ = * 0xffff8288c0000000 - 0xffff82f5ffffffff [437GB, PML4:261]=0A= * Reserved for future use.=0A- * 0xffff830000000000 - 0xffff83fffffff= fff [1TB, 2^40 bytes, PML4:262-263]=0A+ * 0xffff82f600000000 - = 0xffff82ffffffffff [40GB, 2^38 bytes, PML4:261]=0A+ * Page-frame = information array.=0A+ * 0xffff830000000000 - 0xffff87ffffffffff [5TB, = 5*2^40 bytes, PML4:262-271]=0A * 1:1 direct mapping of all physical = memory.=0A- * 0xffff840000000000 - 0xffff87ffffffffff [4TB, 2^42 bytes, = PML4:264-271]=0A- * Reserved for future use.=0A * 0xffff880000000000 = - 0xffffffffffffffff [120TB, PML4:272-511]=0A * Guest-defined use.=0A = *=0A@@ -210,11 +208,8 @@ extern unsigned int video_mode, video_fl=0A /* = Slot 261: machine-to-phys conversion table (16GB). */=0A #define RDWR_MPT_V= IRT_START (PML4_ADDR(261))=0A #define RDWR_MPT_VIRT_END = (RDWR_MPT_VIRT_START + GB(16))=0A-/* Slot 261: page-frame information = array (16GB). */=0A-#define FRAMETABLE_VIRT_START (RDWR_MPT_VIRT_END)=0A-= #define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START + GB(16))=0A /* = Slot 261: ioremap()/fixmap area (16GB). */=0A-#define IOREMAP_VIRT_START = (FRAMETABLE_VIRT_END)=0A+#define IOREMAP_VIRT_START RDWR_MPT_VIRT_E= ND=0A #define IOREMAP_VIRT_END (IOREMAP_VIRT_START + GB(16))=0A /* = Slot 261: compatibility machine-to-phys conversion table (1GB). */=0A = #define RDWR_COMPAT_MPT_VIRT_START IOREMAP_VIRT_END=0A@@ -225,9 +220,15 @@ = extern unsigned int video_mode, video_fl=0A /* Slot 261: xen text, static = data and bss (1GB). */=0A #define XEN_VIRT_START (HIRO_COMPAT_MPT_= VIRT_END)=0A #define XEN_VIRT_END (XEN_VIRT_START + GB(1))=0A-/*= Slot 262-263: A direct 1:1 mapping of all of physical memory. */=0A+/* = Slot 261: page-frame information array (40GB). */=0A+#define FRAMETABLE_VIR= T_END DIRECTMAP_VIRT_START=0A+#define FRAMETABLE_SIZE = ((DIRECTMAP_SIZE >> PAGE_SHIFT) * \=0A+ = sizeof(struct page_info))=0A+#define FRAMETABLE_VIRT_START (FRAMETABLE_VI= RT_END - FRAMETABLE_SIZE)=0A+/* Slot 262-271: A direct 1:1 mapping of all = of physical memory. */=0A #define DIRECTMAP_VIRT_START (PML4_ADDR(262))= =0A-#define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + PML4_ENTRY_BYTE= S*2)=0A+#define DIRECTMAP_SIZE (PML4_ENTRY_BYTES*10)=0A+#define = DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE)=0A =0A = #ifndef __ASSEMBLY__=0A =0A--- 2009-09-10.orig/xen/include/asm-x86/x86_64/p= age.h 2009-09-10 15:26:52.000000000 +0200=0A+++ 2009-09-10/xen/include/as= m-x86/x86_64/page.h 2009-09-10 15:27:09.000000000 +0200=0A@@ -16,8 = +16,8 @@=0A #define L4_PAGETABLE_ENTRIES (1<=0A=0A--- = 2009-09-21.orig/xen/arch/x86/e820.c 2009-09-21 11:12:59.000000000 = +0200=0A+++ 2009-09-21/xen/arch/x86/e820.c 2009-09-21 11:13:02.0000000= 00 +0200=0A@@ -500,22 +500,15 @@ static void __init machine_specific_memo= =0A "can be accessed by Xen in 32-bit mode.");=0A = #else=0A {=0A- unsigned long limit, mpt_limit, ro_mpt_limit, = pft_limit;=0A+ unsigned long mpt_limit, ro_mpt_limit;=0A =0A- = limit =3D DIRECTMAP_VIRT_END - DIRECTMAP_VIRT_START;=0A mpt_limit = =3D ((RDWR_MPT_VIRT_END - RDWR_MPT_VIRT_START)=0A / = sizeof(unsigned long)) << PAGE_SHIFT;=0A ro_mpt_limit =3D = ((RO_MPT_VIRT_END - RO_MPT_VIRT_START)=0A / = sizeof(unsigned long)) << PAGE_SHIFT;=0A- pft_limit =3D ((FRAMETABLE= _VIRT_END - FRAMETABLE_VIRT_START)=0A- / sizeof(struct = page_info)) << PAGE_SHIFT;=0A- if ( limit > mpt_limit )=0A- = limit =3D mpt_limit;=0A- if ( limit > ro_mpt_limit )=0A- = limit =3D ro_mpt_limit;=0A- if ( limit > pft_limit )=0A- = limit =3D pft_limit;=0A- clip_to_limit(limit,=0A+ if ( = mpt_limit > ro_mpt_limit )=0A+ mpt_limit =3D ro_mpt_limit;=0A+ = clip_to_limit(mpt_limit,=0A "Only the first = %lu GB of the physical "=0A "memory map can be = accessed by Xen.");=0A }=0A--- 2009-09-21.orig/xen/arch/x86/mm.c = 2009-09-21 11:12:59.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/mm.c = 2009-09-21 11:13:02.000000000 +0200=0A@@ -173,7 +173,7 @@ void __init = init_frametable(void)=0A BUILD_BUG_ON(FRAMETABLE_VIRT_START & ((1UL << = L2_PAGETABLE_SHIFT) - 1));=0A #endif=0A =0A- nr_pages =3D PFN_UP(max_pa= ge * sizeof(*frame_table));=0A+ nr_pages =3D PFN_UP(max_pdx * = sizeof(*frame_table));=0A page_step =3D 1 << (cpu_has_page1gb ? = L3_PAGETABLE_SHIFT - PAGE_SHIFT=0A : = L2_PAGETABLE_SHIFT - PAGE_SHIFT);=0A =0A@@ -248,10 +248,11 @@ void __init = arch_init_memory(void)=0A * the statically-initialised 1-16MB = mapping area.=0A */=0A iostart_pfn =3D max_t(unsigned = long, pfn, 1UL << (20 - PAGE_SHIFT));=0A- ioend_pfn =3D rstart_pfn;= =0A #if defined(CONFIG_X86_32)=0A- ioend_pfn =3D min_t(unsigned = long, ioend_pfn,=0A+ ioend_pfn =3D min_t(unsigned long, rstart_pfn,= =0A DIRECTMAP_MBYTES << (20 - PAGE_SHIFT));=0A+#e= lse=0A+ ioend_pfn =3D min(rstart_pfn, 16UL << (20 - PAGE_SHIFT));=0A= #endif=0A if ( iostart_pfn < ioend_pfn ) =0A = destroy_xen_mappings((unsigned long)mfn_to_virt(iostart_pfn),=0A@@ = -260,7 +261,8 @@ void __init arch_init_memory(void)=0A /* Mark as = I/O up to next RAM region. */=0A for ( ; pfn < rstart_pfn; pfn++ = )=0A {=0A- BUG_ON(!mfn_valid(pfn));=0A+ if ( = !mfn_valid(pfn) )=0A+ continue;=0A share_xen_pag= e_with_guest(=0A mfn_to_page(pfn), dom_io, XENSHARE_writabl= e);=0A }=0A--- 2009-09-21.orig/xen/arch/x86/mm/shadow/common.c = 2009-08-21 10:28:19.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/mm/shadow= /common.c 2009-09-21 11:13:02.000000000 +0200=0A@@ -1340,7 +1340,7 = @@ static inline void trace_shadow_prealloc=0A /* Convert smfn to = gfn */=0A unsigned long gfn;=0A ASSERT(mfn_valid(smfn));=0A= - gfn =3D mfn_to_gfn(d, _mfn(mfn_to_page(smfn)->v.sh.back));=0A+ = gfn =3D mfn_to_gfn(d, backpointer(mfn_to_page(smfn)));=0A = __trace_var(TRC_SHADOW_PREALLOC_UNPIN, 0/*!tsc*/,=0A = sizeof(gfn), (unsigned char*)&gfn);=0A }=0A@@ -1502,13 +1502,13 @@ = __initcall(shadow_blow_tables_keyhandler=0A static inline struct page_info = *=0A next_shadow(const struct page_info *sp)=0A {=0A- return sp->next_sh= adow ? mfn_to_page(_mfn(sp->next_shadow)) : NULL;=0A+ return sp->next_sh= adow ? pdx_to_page(sp->next_shadow) : NULL;=0A }=0A =0A static inline = void=0A set_next_shadow(struct page_info *sp, struct page_info *next)=0A = {=0A- sp->next_shadow =3D next ? mfn_x(page_to_mfn(next)) : 0;=0A+ = sp->next_shadow =3D next ? page_to_pdx(next) : 0;=0A }=0A =0A /* Allocate = another shadow's worth of (contiguous, aligned) pages,=0A@@ -1554,6 = +1554,17 @@ mfn_t shadow_alloc(struct domain *d, =0A }=0A = d->arch.paging.shadow.free_pages -=3D 1 << order;=0A =0A+ switch = (shadow_type)=0A+ {=0A+ case SH_type_fl1_32_shadow:=0A+ case = SH_type_fl1_pae_shadow:=0A+ case SH_type_fl1_64_shadow:=0A+ = break;=0A+ default:=0A+ backpointer =3D pfn_to_pdx(backpointer);= =0A+ break;=0A+ }=0A+=0A /* Init page info fields and clear = the pages */=0A for ( i =3D 0; i < 1<u.sh.type =3D=3D 0 );=0A BUG_ON( sp->u.sh.type > = SH_type_max_shadow );=0A /* Wrong bucket? */=0A- BUG_ON( = sh_hash(sp->v.sh.back, sp->u.sh.type) !=3D bucket );=0A+ BUG_ON( = sh_hash(__backpointer(sp), sp->u.sh.type) !=3D bucket );=0A /* = Duplicate entry? */=0A for ( x =3D next_shadow(sp); x; x =3D = next_shadow(x) )=0A BUG_ON( x->v.sh.back =3D=3D sp->v.sh.back = &&=0A@@ -1921,7 +1932,7 @@ static void sh_hash_audit_bucket(struct =0A = && sp->u.sh.type !=3D SH_type_fl1_pae_shadow=0A && = sp->u.sh.type !=3D SH_type_fl1_64_shadow )=0A {=0A- = struct page_info *gpg =3D mfn_to_page(_mfn(sp->v.sh.back));=0A+ = struct page_info *gpg =3D mfn_to_page(backpointer(sp));=0A /* = Bad shadow flags on guest page? */=0A BUG_ON( !(gpg->shadow_fla= gs & (1<u.sh.type)) );=0A /* Bad type count on guest = page? */=0A@@ -1935,9 +1946,9 @@ static void sh_hash_audit_bucket(struct = =0A {=0A if ( !page_is_out_of_sync(gpg)= )=0A {=0A- SHADOW_ERROR("MFN = %#"PRpgmfn" shadowed (by %#"PRI_mfn")"=0A+ = SHADOW_ERROR("MFN %#"PRI_mfn" shadowed (by %#"PRI_mfn")"=0A = " and not OOS but has typecount %#lx\n",=0A- = sp->v.sh.back,=0A+ = __backpointer(sp),=0A = mfn_x(page_to_mfn(sp)), =0A gpg->u.inu= se.type_info);=0A BUG();=0A@@ -1949,9 +1960,9 @@ = static void sh_hash_audit_bucket(struct =0A if ( (gpg->u.inuse.= type_info & PGT_type_mask) =3D=3D PGT_writable_page =0A = && (gpg->u.inuse.type_info & PGT_count_mask) !=3D 0 )=0A {=0A- = SHADOW_ERROR("MFN %#"PRpgmfn" shadowed (by %#"PRI_mfn")"=0A+= SHADOW_ERROR("MFN %#"PRI_mfn" shadowed (by %#"PRI_mfn")"=0A= " but has typecount %#lx\n",=0A- = sp->v.sh.back, mfn_x(page_to_mfn(sp)),=0A+ = __backpointer(sp), mfn_x(page_to_mfn(sp)),=0A = gpg->u.inuse.type_info);=0A BUG();=0A = }=0A@@ -2037,7 +2048,7 @@ mfn_t shadow_hash_lookup(struct vcpu *v,=0A = prev =3D NULL;=0A while(sp)=0A {=0A- if ( sp->v.sh.back = =3D=3D n && sp->u.sh.type =3D=3D t )=0A+ if ( __backpointer(sp) = =3D=3D n && sp->u.sh.type =3D=3D t )=0A {=0A /* = Pull-to-front if 'sp' isn't already the head item */=0A if ( = unlikely(sp !=3D d->arch.paging.shadow.hash_table[key]) )=0A@@ -2204,7 = +2215,7 @@ void sh_destroy_shadow(struct vcpu *v, m=0A t =3D=3D = SH_type_fl1_64_shadow || =0A t =3D=3D SH_type_monitor_table = || =0A (is_pv_32on64_vcpu(v) && t =3D=3D SH_type_l4_64_shadow) = ||=0A- (page_get_owner(mfn_to_page(_mfn(sp->v.sh.back)))=0A+ = (page_get_owner(mfn_to_page(backpointer(sp)))=0A =3D=3D = v->domain)); =0A =0A /* The down-shifts here are so that the switch = statement is on nice=0A--- 2009-09-21.orig/xen/arch/x86/mm/shadow/multi.c = 2009-07-14 08:55:23.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/mm/shadow= /multi.c 2009-09-21 11:13:02.000000000 +0200=0A@@ -1010,7 +1010,7 = @@ static int shadow_set_l2e(struct vcpu *v=0A #if (SHADOW_OPTIMIZATIONS & = SHOPT_OUT_OF_SYNC)=0A {=0A struct page_info *sp =3D = mfn_to_page(sl1mfn);=0A- mfn_t gl1mfn =3D _mfn(sp->v.sh.back);= =0A+ mfn_t gl1mfn =3D backpointer(sp);=0A =0A /* If = the shadow is a fl1 then the backpointer contains=0A the = GFN instead of the GMFN, and it's definitely not=0A@@ -1974,7 +1974,7 @@ = void sh_destroy_l4_shadow(struct vcpu *v=0A ASSERT(t =3D=3D SH_type_l4_= shadow);=0A =0A /* Record that the guest page isn't shadowed any more = (in this type) */=0A- gmfn =3D _mfn(mfn_to_page(smfn)->v.sh.back);=0A+ = gmfn =3D backpointer(mfn_to_page(smfn));=0A delete_shadow_status(v, = gmfn, t, smfn);=0A shadow_demote(v, gmfn, t);=0A /* Decrement = refcounts of all the old entries */=0A@@ -2003,7 +2003,7 @@ void sh_destroy= _l3_shadow(struct vcpu *v=0A ASSERT(t =3D=3D SH_type_l3_shadow);=0A = =0A /* Record that the guest page isn't shadowed any more (in this = type) */=0A- gmfn =3D _mfn(mfn_to_page(smfn)->v.sh.back);=0A+ gmfn = =3D backpointer(mfn_to_page(smfn));=0A delete_shadow_status(v, gmfn, = t, smfn);=0A shadow_demote(v, gmfn, t);=0A =0A@@ -2038,7 +2038,7 @@ = void sh_destroy_l2_shadow(struct vcpu *v=0A #endif=0A =0A /* Record = that the guest page isn't shadowed any more (in this type) */=0A- gmfn = =3D _mfn(mfn_to_page(smfn)->v.sh.back);=0A+ gmfn =3D backpointer(mfn_to_= page(smfn));=0A delete_shadow_status(v, gmfn, t, smfn);=0A = shadow_demote(v, gmfn, t);=0A =0A@@ -2073,7 +2073,7 @@ void sh_destroy_l1_s= hadow(struct vcpu *v=0A }=0A else =0A {=0A- mfn_t gmfn = =3D _mfn(mfn_to_page(smfn)->v.sh.back);=0A+ mfn_t gmfn =3D = backpointer(mfn_to_page(smfn));=0A delete_shadow_status(v, gmfn, = t, smfn);=0A shadow_demote(v, gmfn, t);=0A }=0A@@ -2397,7 = +2397,7 @@ static int validate_gl1e(struct vcpu *v,=0A result |=3D = shadow_set_l1e(v, sl1p, new_sl1e, p2mt, sl1mfn);=0A =0A #if (SHADOW_OPTIMIZ= ATIONS & SHOPT_OUT_OF_SYNC)=0A- gl1mfn =3D _mfn(mfn_to_page(sl1mfn)->v.s= h.back);=0A+ gl1mfn =3D backpointer(mfn_to_page(sl1mfn));=0A if ( = mfn_valid(gl1mfn) =0A && mfn_is_out_of_sync(gl1mfn) )=0A = {=0A@@ -3006,8 +3006,8 @@ static int sh_page_fault(struct vcpu *v,=0A = + shadow_l2_linear_offset(va)),=0A = sizeof(sl2e)) !=3D 0)=0A || = !(shadow_l2e_get_flags(sl2e) & _PAGE_PRESENT)=0A- || = !mfn_valid(gl1mfn =3D _mfn(mfn_to_page(=0A- = shadow_l2e_get_mfn(sl2e))->v.sh.back))=0A+ || !mfn_valid(= gl1mfn =3D backpointer(mfn_to_page(=0A+ = shadow_l2e_get_mfn(sl2e))))=0A || unlikely(mfn_is_out_of_s= ync(gl1mfn)) )=0A {=0A /* Hit the slow path as = if there had been no =0A@@ -3582,7 +3582,7 @@ sh_invlpg(struct vcpu *v, = unsigned long =0A #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) =0A = /* Check to see if the SL1 is out of sync. */=0A {=0A- mfn_t = gl1mfn =3D _mfn(mfn_to_page(sl1mfn)->v.sh.back);=0A+ mfn_t gl1mfn = =3D backpointer(mfn_to_page(sl1mfn));=0A struct page_info *pg =3D = mfn_to_page(gl1mfn);=0A if ( mfn_valid(gl1mfn) =0A && = page_is_out_of_sync(pg) )=0A@@ -3612,7 +3612,7 @@ sh_invlpg(struct vcpu = *v, unsigned long =0A }=0A =0A sl1mfn =3D = shadow_l2e_get_mfn(sl2e);=0A- gl1mfn =3D _mfn(mfn_to_page(sl1mfn= )->v.sh.back);=0A+ gl1mfn =3D backpointer(mfn_to_page(sl1mfn));= =0A pg =3D mfn_to_page(gl1mfn);=0A =0A = if ( likely(sh_mfn_is_a_page_table(gl1mfn)=0A@@ -4949,7 +4949,7 @@ int = sh_audit_l1_table(struct vcpu *v, mf=0A int done =3D 0;=0A =0A = /* Follow the backpointer */=0A- gl1mfn =3D _mfn(mfn_to_page(sl1mfn)->v.= sh.back);=0A+ gl1mfn =3D backpointer(mfn_to_page(sl1mfn));=0A =0A #if = (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)=0A /* Out-of-sync l1 = shadows can contain anything: just check the OOS hash */=0A@@ -5042,7 = +5042,7 @@ int sh_audit_l2_table(struct vcpu *v, mf=0A int done =3D = 0;=0A =0A /* Follow the backpointer */=0A- gl2mfn =3D _mfn(mfn_to_pa= ge(sl2mfn)->v.sh.back);=0A+ gl2mfn =3D backpointer(mfn_to_page(sl2mfn));= =0A =0A #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)=0A /* Only L1's = may be out of sync. */=0A@@ -5091,7 +5091,7 @@ int sh_audit_l3_table(struct= vcpu *v, mf=0A int done =3D 0;=0A =0A /* Follow the backpointer = */=0A- gl3mfn =3D _mfn(mfn_to_page(sl3mfn)->v.sh.back);=0A+ gl3mfn = =3D backpointer(mfn_to_page(sl3mfn));=0A =0A #if (SHADOW_OPTIMIZATIONS & = SHOPT_OUT_OF_SYNC) =0A /* Only L1's may be out of sync. */=0A@@ = -5138,7 +5138,7 @@ int sh_audit_l4_table(struct vcpu *v, mf=0A int = done =3D 0;=0A =0A /* Follow the backpointer */=0A- gl4mfn =3D = _mfn(mfn_to_page(sl4mfn)->v.sh.back);=0A+ gl4mfn =3D backpointer(mfn_to_= page(sl4mfn));=0A =0A #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) =0A = /* Only L1's may be out of sync. */=0A--- 2009-09-21.orig/xen/arch/x86/mm= /shadow/private.h 2009-06-05 11:59:48.000000000 +0200=0A+++ = 2009-09-21/xen/arch/x86/mm/shadow/private.h 2009-09-21 11:13:02.0000000= 00 +0200=0A@@ -488,6 +488,19 @@ mfn_t oos_snapshot_lookup(struct vcpu = *v=0A #undef pagetable_from_page=0A #define pagetable_from_page(pg) = pagetable_from_mfn(page_to_mfn(pg))=0A =0A+#define backpointer(sp) = _mfn(pdx_to_pfn((unsigned long)(sp)->v.sh.back))=0A+static inline unsigned = long __backpointer(const struct page_info *sp)=0A+{=0A+ switch = (sp->u.sh.type)=0A+ {=0A+ case SH_type_fl1_32_shadow:=0A+ case = SH_type_fl1_pae_shadow:=0A+ case SH_type_fl1_64_shadow:=0A+ = return sp->v.sh.back;=0A+ }=0A+ return pdx_to_pfn(sp->v.sh.back);=0A+= }=0A+=0A static inline int=0A sh_mfn_is_a_page_table(mfn_t gmfn)=0A {=0A@@ = -610,8 +623,8 @@ static inline int sh_get_ref(struct vcpu=0A =0A if ( = unlikely(nx >=3D 1U<<26) )=0A {=0A- SHADOW_PRINTK("shadow ref = overflow, gmfn=3D%" PRpgmfn " smfn=3D%lx\n",=0A- = sp->v.sh.back, mfn_x(smfn));=0A+ SHADOW_PRINTK("shadow ref = overflow, gmfn=3D%lx smfn=3D%lx\n",=0A+ __backpointer= (sp), mfn_x(smfn));=0A return 0;=0A }=0A =0A--- 2009-09-21.= orig/xen/arch/x86/setup.c 2009-09-16 08:35:05.000000000 +0200=0A+++ = 2009-09-21/xen/arch/x86/setup.c 2009-09-21 11:13:02.000000000 +0200=0A@@ = -297,6 +297,21 @@ static void __init move_memory(=0A src_end - = src_start);=0A }=0A =0A+static void __init setup_max_pdx(void)=0A+{=0A+#ifd= ef __x86_64__=0A+ max_pdx =3D pfn_to_pdx(max_page - 1) + 1;=0A+=0A+ = if ( max_pdx > (DIRECTMAP_SIZE >> PAGE_SHIFT) )=0A+ max_pdx =3D = DIRECTMAP_SIZE >> PAGE_SHIFT;=0A+=0A+ if ( max_pdx > FRAMETABLE_SIZE / = sizeof(*frame_table) )=0A+ max_pdx =3D FRAMETABLE_SIZE / sizeof(*fra= me_table);=0A+=0A+ max_page =3D pdx_to_pfn(max_pdx - 1) + 1;=0A+#endif= =0A+}=0A+=0A /* A temporary copy of the e820 map that we can mess with = during bootstrap. */=0A static struct e820map __initdata boot_e820;=0A = =0A@@ -425,6 +440,7 @@ void __init __start_xen(unsigned long mb=0A = module_t *mod =3D (module_t *)__va(mbi->mods_addr);=0A unsigned long = nr_pages, modules_length, modules_headroom;=0A int i, j, e820_warn =3D = 0, bytes =3D 0;=0A+ bool_t acpi_boot_table_init_done =3D 0;=0A = struct ns16550_defaults ns16550 =3D {=0A .data_bits =3D 8,=0A = .parity =3D 'n',=0A@@ -777,11 +793,13 @@ void __init __start_xen(unsi= gned long mb=0A /* Late kexec reservation (dynamic start address). = */=0A kexec_reserve_area(&boot_e820);=0A =0A+ setup_max_pdx();=0A+= =0A /*=0A * Walk every RAM region and map it in its entirety (on = x86/64, at least)=0A * and notify it to the boot allocator.=0A = */=0A- for ( i =3D 0; i < boot_e820.nr_map; i++ )=0A+ for ( nr_pages = =3D i =3D 0; i < boot_e820.nr_map; i++ )=0A {=0A uint64_t s, = e, map_s, map_e, mask =3D PAGE_SIZE - 1;=0A =0A@@ -796,6 +814,45 @@ void = __init __start_xen(unsigned long mb=0A if ( (boot_e820.map[i].type = !=3D E820_RAM) || (s >=3D e) )=0A continue;=0A =0A+#ifdef = __x86_64__=0A+ if ( !acpi_boot_table_init_done &&=0A+ s = >=3D BOOTSTRAP_DIRECTMAP_END &&=0A+ !acpi_boot_table_init() = )=0A+ {=0A+ acpi_boot_table_init_done =3D 1;=0A+ = srat_parse_regions(s);=0A+ setup_max_pdx();=0A+ = }=0A+=0A+ if ( pfn_to_pdx((e - 1) >> PAGE_SHIFT) >=3D max_pdx )=0A+ = {=0A+ if ( pfn_to_pdx(s >> PAGE_SHIFT) >=3D max_pdx = )=0A+ {=0A+ for ( j =3D i - 1; ; --j )=0A+ = {=0A+ if ( boot_e820.map[j].type =3D=3D = E820_RAM )=0A+ break;=0A+ = ASSERT(j);=0A+ }=0A+ map_e =3D boot_e820.map[= j].addr + boot_e820.map[j].size;=0A+ if ( (map_e >> = PAGE_SHIFT) < max_page )=0A+ {=0A+ = max_page =3D map_e >> PAGE_SHIFT;=0A+ max_pdx =3D = pfn_to_pdx(max_page - 1) + 1;=0A+ }=0A+ = printk(XENLOG_WARNING "Ignoring inaccessible memory range"=0A+ = " %013"PRIx64"-%013"PRIx64"\n",=0A+ = s, e);=0A+ continue;=0A+ }=0A+ = map_e =3D e;=0A+ e =3D (pdx_to_pfn(max_pdx - 1) + 1ULL) << = PAGE_SHIFT;=0A+ printk(XENLOG_WARNING "Ignoring inaccessible = memory range"=0A+ " %013"PRIx64"-%013"PRIx= 64"\n",=0A+ e, map_e);=0A+ }=0A+#endif=0A+=0A = /* Need to create mappings above 16MB. */=0A map_s =3D = max_t(uint64_t, s, 16<<20);=0A map_e =3D e;=0A@@ -815,14 +872,11 = @@ void __init __start_xen(unsigned long mb=0A =0A /* Pass = remainder of this memory chunk to the allocator. */=0A init_boot_pa= ges(map_s, e);=0A+ nr_pages +=3D (e - s) >> PAGE_SHIFT;=0A }=0A = =0A memguard_init();=0A =0A- nr_pages =3D 0;=0A- for ( i =3D 0; = i < e820.nr_map; i++ )=0A- if ( e820.map[i].type =3D=3D E820_RAM = )=0A- nr_pages +=3D e820.map[i].size >> PAGE_SHIFT;=0A = printk("System RAM: %luMB (%lukB)\n",=0A nr_pages >> (20 - = PAGE_SHIFT),=0A nr_pages << (PAGE_SHIFT - 10));=0A@@ -857,7 = +911,8 @@ void __init __start_xen(unsigned long mb=0A =0A init_frametab= le();=0A =0A- acpi_boot_table_init();=0A+ if ( !acpi_boot_table_init_= done )=0A+ acpi_boot_table_init();=0A =0A acpi_numa_init();=0A = =0A--- 2009-09-21.orig/xen/arch/x86/srat.c 2009-08-31 15:09:04.0000000= 00 +0200=0A+++ 2009-09-21/xen/arch/x86/srat.c 2009-09-21 11:13:02.0000000= 00 +0200=0A@@ -286,6 +286,70 @@ static void unparse_node(int node)=0A =0A = void __init acpi_numa_arch_fixup(void) {}=0A =0A+#ifdef __x86_64__=0A+=0A+s= tatic u64 __initdata srat_region_mask;=0A+=0A+static u64 __init fill_mask(u= 64 mask)=0A+{=0A+ while (mask & (mask + 1))=0A+ mask |=3D = mask + 1;=0A+ return mask;=0A+}=0A+=0A+static int __init srat_parse_regio= n(struct acpi_subtable_header *header,=0A+ = const unsigned long end)=0A+{=0A+ struct acpi_srat_mem_affinity = *ma;=0A+=0A+ if (!header)=0A+ return -EINVAL;=0A+=0A+ ma = =3D container_of(header, struct acpi_srat_mem_affinity, header);=0A+=0A+ = if (!ma->length ||=0A+ !(ma->flags & ACPI_SRAT_MEM_ENABLED) ||=0A+ = (ma->flags & ACPI_SRAT_MEM_NON_VOLATILE))=0A+ return 0;=0A+=0A+ = if (numa_off)=0A+ printk(KERN_INFO "SRAT: %013"PRIx64"-%013"P= RIx64"\n",=0A+ ma->base_address, ma->base_address + = ma->length - 1);=0A+=0A+ srat_region_mask |=3D ma->base_address = |=0A+ fill_mask(ma->base_address ^=0A+ = (ma->base_address + ma->length - 1));=0A+=0A+ return = 0;=0A+}=0A+=0A+void __init srat_parse_regions(u64 addr)=0A+{=0A+ = u64 mask;=0A+ unsigned int i;=0A+=0A+ if (acpi_disabled || acpi_numa < 0 = ||=0A+ acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat))=0A+ = return;=0A+=0A+ srat_region_mask =3D fill_mask(addr - 1);=0A+ acpi_table_= parse_srat(ACPI_SRAT_MEMORY_AFFINITY, srat_parse_region, 0);=0A+=0A+ = for (mask =3D srat_region_mask, i =3D 0; mask && i < e820.nr_map; i++) = {=0A+ if (e820.map[i].type !=3D E820_RAM)=0A+ = continue;=0A+=0A+ if (~mask &=0A+ fill_mask(e820.= map[i].addr ^=0A+ (e820.map[i].addr + = e820.map[i].size - 1)))=0A+ mask =3D 0;=0A+ }=0A+=0A+ = pfn_pdx_hole_setup(mask >> PAGE_SHIFT);=0A+}=0A+=0A+#endif /* __x86_64__ = */=0A+=0A /* Use the information discovered above to actually set up the = nodes. */=0A int __init acpi_scan_nodes(u64 start, u64 end)=0A {=0A--- = 2009-09-21.orig/xen/arch/x86/tboot.c 2009-07-10 08:51:30.000000000 = +0200=0A+++ 2009-09-21/xen/arch/x86/tboot.c 2009-09-21 11:13:02.0000000= 00 +0200=0A@@ -175,6 +175,9 @@ static void update_pagetable_mac(vmac_ct=0A = for ( mfn =3D 0; mfn < max_page; mfn++ )=0A {=0A struct = page_info *page =3D mfn_to_page(mfn);=0A+=0A+ if ( !mfn_valid(mfn) = )=0A+ continue;=0A if ( is_page_in_use(page) && = !is_xen_heap_page(page) ) {=0A if ( page->count_info & = PGC_page_table ) {=0A void *pg =3D map_domain_page(mfn);=0A= @@ -237,6 +240,9 @@ static void tboot_gen_xenheap_integrity(=0A for ( = mfn =3D 0; mfn < max_page; mfn++ )=0A {=0A struct page_info = *page =3D __mfn_to_page(mfn);=0A+=0A+ if ( !mfn_valid(mfn) )=0A+ = continue;=0A if ( is_page_in_use(page) && is_xen_heap_page(= page) ) {=0A void *pg =3D mfn_to_virt(mfn);=0A = vmac_update((uint8_t *)pg, PAGE_SIZE, &ctx);=0A@@ -258,7 +264,7 @@ static = void tboot_gen_frametable_integri=0A =0A vmac_set_key((uint8_t *)key, = &ctx);=0A *mac =3D vmac((uint8_t *)frame_table,=0A- = PFN_UP(max_page * sizeof(*frame_table)), nonce, NULL, &ctx);=0A+ = PFN_UP(max_pdx * sizeof(*frame_table)), nonce, NULL, &ctx);=0A =0A = printk("MAC for frametable is: 0x%08"PRIx64"\n", *mac);=0A =0A--- = 2009-09-21.orig/xen/arch/x86/x86_64/mm.c 2009-07-27 09:35:16.0000000= 00 +0200=0A+++ 2009-09-21/xen/arch/x86/x86_64/mm.c 2009-09-21 = 11:13:02.000000000 +0200=0A@@ -33,6 +33,15 @@=0A #include =0A = #include =0A =0A+/* Parameters for PFN/MADDR compression. = */=0A+unsigned long __read_mostly max_pdx;=0A+unsigned long __read_mostly = pfn_pdx_bottom_mask =3D ~0UL;=0A+unsigned long __read_mostly ma_va_bottom_m= ask =3D ~0UL;=0A+unsigned long __read_mostly pfn_top_mask =3D 0;=0A+unsigne= d long __read_mostly ma_top_mask =3D 0;=0A+unsigned long __read_mostly = pfn_hole_mask =3D 0;=0A+unsigned int __read_mostly pfn_pdx_hole_shift =3D = 0;=0A+=0A #ifdef CONFIG_COMPAT=0A unsigned int m2p_compat_vstart =3D = __HYPERVISOR_COMPAT_VIRT_START;=0A #endif=0A@@ -144,6 +153,36 @@ void = *do_page_walk(struct vcpu *v, unsig=0A return mfn_to_virt(mfn) + (addr = & ~PAGE_MASK);=0A }=0A =0A+void __init pfn_pdx_hole_setup(unsigned long = mask)=0A+{=0A+ unsigned int i, j, bottom_shift, hole_shift;=0A+=0A+ = for ( hole_shift =3D bottom_shift =3D j =3D 0; ; )=0A+ {=0A+ i = =3D find_next_zero_bit(&mask, BITS_PER_LONG, j);=0A+ j =3D = find_next_bit(&mask, BITS_PER_LONG, i);=0A+ if ( j >=3D BITS_PER_LON= G )=0A+ break;=0A+ if ( j - i > hole_shift )=0A+ = {=0A+ hole_shift =3D j - i;=0A+ bottom_shift =3D = i;=0A+ }=0A+ }=0A+ if ( !hole_shift )=0A+ return;=0A+= =0A+ printk(KERN_INFO "PFN compression on bits %u...%u\n",=0A+ = bottom_shift, bottom_shift + hole_shift - 1);=0A+=0A+ pfn_pdx_hole_shif= t =3D hole_shift;=0A+ pfn_pdx_bottom_mask =3D (1UL << bottom_shift) - = 1;=0A+ ma_va_bottom_mask =3D (PAGE_SIZE << bottom_shift) - 1;=0A+ = pfn_hole_mask =3D ((1UL << hole_shift) - 1) << bottom_shift;=0A+ = pfn_top_mask =3D ~(pfn_pdx_bottom_mask | pfn_hole_mask);=0A+ = ma_top_mask =3D pfn_top_mask << PAGE_SHIFT;=0A+}=0A+=0A void = __init paging_init(void)=0A {=0A unsigned long i, mpt_size, va;=0A--- = 2009-09-21.orig/xen/drivers/acpi/numa.c 2009-05-27 13:54:07.000000000 = +0200=0A+++ 2009-09-21/xen/drivers/acpi/numa.c 2009-09-21 11:13:02.0000000= 00 +0200=0A@@ -141,7 +141,7 @@ acpi_parse_memory_affinity(struct acpi_s=0A = return 0;=0A }=0A =0A-static int __init acpi_parse_srat(struct = acpi_table_header *table)=0A+int __init acpi_parse_srat(struct acpi_table_h= eader *table)=0A {=0A if (!table)=0A return -EINVAL;=0A--- = 2009-09-21.orig/xen/include/asm-x86/config.h 2009-09-21 11:12:59.0000000= 00 +0200=0A+++ 2009-09-21/xen/include/asm-x86/config.h 2009-09-21 = 11:13:02.000000000 +0200=0A@@ -145,17 +145,17 @@ extern unsigned int = video_mode, video_fl=0A * Shadow linear page table.=0A * 0xffff820000= 000000 - 0xffff827fffffffff [512GB, 2^39 bytes, PML4:260]=0A * = Per-domain mappings (e.g., GDT, LDT).=0A- * 0xffff828000000000 - = 0xffff8283ffffffff [16GB, 2^34 bytes, PML4:261]=0A+ * 0xffff828000000000 = - 0xffff82bfffffffff [256GB, 2^38 bytes, PML4:261]=0A * Machine-to-phys= translation table.=0A- * 0xffff828400000000 - 0xffff8287ffffffff [16GB, = 2^34 bytes, PML4:261]=0A+ * 0xffff82c000000000 - 0xffff82c3ffffffff = [16GB, 2^34 bytes, PML4:261]=0A * ioremap()/fixmap area.=0A- * = 0xffff828800000000 - 0xffff82883fffffff [1GB, 2^30 bytes, PML4:261]=0A+ = * 0xffff82c400000000 - 0xffff82c43fffffff [1GB, 2^30 bytes, PML4:261]=0A= * Compatibility machine-to-phys translation table.=0A- * 0xffff828840= 000000 - 0xffff82887fffffff [1GB, 2^30 bytes, PML4:261]=0A+ * 0xffff82c4= 40000000 - 0xffff82c47fffffff [1GB, 2^30 bytes, PML4:261]=0A * High = read-only compatibility machine-to-phys translation table.=0A- * = 0xffff828880000000 - 0xffff8288bfffffff [1GB, 2^30 bytes, PML4:261]=0A+ = * 0xffff82c480000000 - 0xffff82c4bfffffff [1GB, 2^30 bytes, PML4:261]=0A= * Xen text, static data, bss.=0A- * 0xffff8288c0000000 - 0xffff82f5ff= ffffff [437GB, PML4:261]=0A+ * 0xffff82c4c0000000 - 0xffff82f5= ffffffff [197GB, PML4:261]=0A * Reserved for future = use.=0A * 0xffff82f600000000 - 0xffff82ffffffffff [40GB, 2^38 bytes, = PML4:261]=0A * Page-frame information array.=0A@@ -188,7 +188,8 @@ = extern unsigned int video_mode, video_fl=0A #define HYPERVISOR_VIRT_END = (HYPERVISOR_VIRT_START + PML4_ENTRY_BYTES*16)=0A /* Slot 256: read-only = guest-accessible machine-to-phys translation table. */=0A #define = RO_MPT_VIRT_START (PML4_ADDR(256))=0A-#define RO_MPT_VIRT_END = (RO_MPT_VIRT_START + PML4_ENTRY_BYTES/2)=0A+#define MPT_VIRT_SIZE = (PML4_ENTRY_BYTES / 2)=0A+#define RO_MPT_VIRT_END (RO_MPT_VIRT_ST= ART + MPT_VIRT_SIZE)=0A /* Slot 257: ioremap for PCI mmconfig space for = 2048 segments (512GB)=0A * - full 16-bit segment support needs 44 = bits=0A * - since PML4 slot has 39 bits, we limit segments to 2048 = (11-bits)=0A@@ -205,9 +206,9 @@ extern unsigned int video_mode, video_fl=0A= #define PERDOMAIN_VIRT_START (PML4_ADDR(260))=0A #define PERDOMAIN_VIRT= _END (PERDOMAIN_VIRT_START + (PERDOMAIN_MBYTES<<20))=0A #define = PERDOMAIN_MBYTES (PML4_ENTRY_BYTES >> (20 + PAGETABLE_ORDER))=0A-/* = Slot 261: machine-to-phys conversion table (16GB). */=0A+/* Slot 261: = machine-to-phys conversion table (256GB). */=0A #define RDWR_MPT_VIRT_START= (PML4_ADDR(261))=0A-#define RDWR_MPT_VIRT_END (RDWR_MPT_VIRT_STA= RT + GB(16))=0A+#define RDWR_MPT_VIRT_END (RDWR_MPT_VIRT_START + = MPT_VIRT_SIZE)=0A /* Slot 261: ioremap()/fixmap area (16GB). */=0A #define = IOREMAP_VIRT_START RDWR_MPT_VIRT_END=0A #define IOREMAP_VIRT_END = (IOREMAP_VIRT_START + GB(16))=0A--- 2009-09-21.orig/xen/include/asm-x86/m= m.h 2009-09-07 13:22:47.000000000 +0200=0A+++ 2009-09-21/xen/include/as= m-x86/mm.h 2009-09-21 11:13:02.000000000 +0200=0A@@ -22,13 +22,12 = @@=0A * wants to support more than 16TB.=0A * 'unsigned long' should be = used for MFNs everywhere else.=0A */=0A-#define __mfn_t unsigned = int=0A-#define PRpgmfn "08x"=0A+#define __pdx_t unsigned int=0A =0A #undef = page_list_entry=0A struct page_list_entry=0A {=0A- __mfn_t next, = prev;=0A+ __pdx_t next, prev;=0A };=0A =0A struct page_info=0A@@ -77,14 = +76,14 @@ struct page_info=0A =0A /* Page is in use, but not as a = shadow. */=0A struct {=0A- /* Owner of this page (NULL = if page is anonymous). */=0A- u32 _domain; /* pickled format = */=0A+ /* Owner of this page (zero if page is anonymous). = */=0A+ __pdx_t _domain;=0A } inuse;=0A =0A /* = Page is in use as a shadow. */=0A struct {=0A /* GMFN = of guest page we're a shadow of. */=0A- __mfn_t back;=0A+ = __pdx_t back;=0A } sh;=0A =0A /* Page is on a free = list (including shadow code free lists). */=0A@@ -146,11 +145,11 @@ struct = page_info=0A u32 shadow_flags;=0A =0A /* When in use as a = shadow, next shadow in this hash chain. */=0A- __mfn_t next_shadow;= =0A+ __pdx_t next_shadow;=0A };=0A };=0A =0A-#undef __mfn_t=0A+#= undef __pdx_t=0A =0A #define PG_shift(idx) (BITS_PER_LONG - (idx))=0A = #define PG_mask(x, idx) (x ## UL << PG_shift(idx))=0A@@ -245,9 +244,9 @@ = struct page_info=0A =0A #define page_get_owner(_p) = \=0A ((struct domain *)((_p)->v.inuse._domain ? = \=0A- mfn_to_virt((_p)->v.inus= e._domain) : NULL))=0A+ pdx_to_virt((_p)->v.inuse._do= main) : NULL))=0A #define page_set_owner(_p,_d) = \=0A- ((_p)->v.inuse._domain =3D (_d) ? virt_to_mfn(_d) = : 0)=0A+ ((_p)->v.inuse._domain =3D (_d) ? virt_to_pdx(_d) : 0)=0A =0A = #define maddr_get_owner(ma) (page_get_owner(maddr_to_page((ma))))=0A = #define vaddr_get_owner(va) (page_get_owner(virt_to_page((va))))=0A@@ = -264,6 +263,33 @@ extern unsigned long max_page;=0A extern unsigned long = total_pages;=0A void init_frametable(void);=0A =0A+/* Convert between = Xen-heap virtual addresses and page-info structures. */=0A+static inline = struct page_info *__virt_to_page(const void *v)=0A+{=0A+ unsigned long = va =3D (unsigned long)v;=0A+=0A+#ifdef __x86_64__=0A+ ASSERT(va >=3D = XEN_VIRT_START);=0A+ ASSERT(va < DIRECTMAP_VIRT_END);=0A+ if ( va < = XEN_VIRT_END )=0A+ va +=3D DIRECTMAP_VIRT_START - XEN_VIRT_START + = xen_phys_start;=0A+ else=0A+ ASSERT(va >=3D DIRECTMAP_VIRT_START)= ;=0A+#else=0A+ ASSERT(va - DIRECTMAP_VIRT_START < DIRECTMAP_VIRT_END);= =0A+#endif=0A+ return frame_table + ((va - DIRECTMAP_VIRT_START) >> = PAGE_SHIFT);=0A+}=0A+=0A+static inline void *__page_to_virt(const struct = page_info *pg)=0A+{=0A+ ASSERT((unsigned long)pg - FRAMETABLE_VIRT_START= < FRAMETABLE_VIRT_END);=0A+ return (void *)(DIRECTMAP_VIRT_START +=0A+ = ((unsigned long)pg - FRAMETABLE_VIRT_START) /=0A+ = (sizeof(*pg) / (sizeof(*pg) & -sizeof(*pg))) *=0A+ = (PAGE_SIZE / (sizeof(*pg) & -sizeof(*pg))));=0A+}=0A+=0A int = free_page_type(struct page_info *page, unsigned long type,=0A = int preemptible);=0A int _shadow_mode_refcounts(struct domain = *d);=0A--- 2009-09-21.orig/xen/include/asm-x86/numa.h 2009-05-27 = 13:54:07.000000000 +0200=0A+++ 2009-09-21/xen/include/asm-x86/numa.h = 2009-09-21 11:13:02.000000000 +0200=0A@@ -75,5 +75,6 @@ static inline = __attribute__((pure)) int =0A #define clear_node_cpumask(cpu) do {} while = (0)=0A #endif=0A =0A+void srat_parse_regions(u64 addr);=0A =0A #endif=0A---= 2009-09-21.orig/xen/include/asm-x86/page.h 2009-02-18 17:45:17.0000000= 00 +0100=0A+++ 2009-09-21/xen/include/asm-x86/page.h 2009-09-21 = 11:13:02.000000000 +0200=0A@@ -220,8 +220,6 @@ void copy_page_sse2(void *, = const void *=0A copy_page_sse2(_t, _f) : = \=0A (void)memcpy(_t, _f, = PAGE_SIZE))=0A =0A-#define __mfn_valid(mfn) ((mfn) < max_page)=0A-=0A = /* Convert between Xen-heap virtual addresses and machine addresses. */=0A = #define __pa(x) (virt_to_maddr(x))=0A #define __va(x) = (maddr_to_virt(x))=0A@@ -231,16 +229,12 @@ void copy_page_sse2(void *, = const void *=0A #define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) = << PAGE_SHIFT))=0A =0A /* Convert between machine frame numbers and = page-info structures. */=0A-#define __mfn_to_page(mfn) (frame_table + = (mfn))=0A-#define __page_to_mfn(pg) ((unsigned long)((pg) - frame_table))= =0A+#define __mfn_to_page(mfn) (frame_table + pfn_to_pdx(mfn))=0A+#define = __page_to_mfn(pg) pdx_to_pfn((unsigned long)((pg) - frame_table))=0A =0A = /* Convert between machine addresses and page-info structures. */=0A-#defin= e __maddr_to_page(ma) (frame_table + ((ma) >> PAGE_SHIFT))=0A-#define = __page_to_maddr(pg) ((paddr_t)((pg) - frame_table) << PAGE_SHIFT)=0A-=0A-/*= Convert between Xen-heap virtual addresses and page-info structures. = */=0A-#define __virt_to_page(va) (frame_table + (__pa(va) >> PAGE_SHIFT))= =0A-#define __page_to_virt(pg) (maddr_to_virt(page_to_maddr(pg)))=0A+#defi= ne __maddr_to_page(ma) __mfn_to_page((ma) >> PAGE_SHIFT)=0A+#define = __page_to_maddr(pg) ((paddr_t)__page_to_mfn(pg) << PAGE_SHIFT)=0A =0A /* = Convert between frame number and address formats. */=0A #define __pfn_to_p= addr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)=0A@@ -253,6 +247,8 @@ void = copy_page_sse2(void *, const void *=0A #define mfn_valid(mfn) = __mfn_valid(mfn)=0A #define virt_to_mfn(va) __virt_to_mfn(va)=0A = #define mfn_to_virt(mfn) __mfn_to_virt(mfn)=0A+#define virt_to_maddr(va)= __virt_to_maddr((unsigned long)(va))=0A+#define maddr_to_virt(ma) = __maddr_to_virt((unsigned long)(ma))=0A #define mfn_to_page(mfn) = __mfn_to_page(mfn)=0A #define page_to_mfn(pg) __page_to_mfn(pg)=0A = #define maddr_to_page(ma) __maddr_to_page(ma)=0A--- 2009-09-21.orig/xen/i= nclude/asm-x86/x86_32/page.h 2009-04-09 14:05:36.000000000 +0200=0A+++ = 2009-09-21/xen/include/asm-x86/x86_32/page.h 2009-09-21 11:13:02.0000000= 00 +0200=0A@@ -41,21 +41,25 @@=0A #include =0A #include = =0A =0A+#define __mfn_valid(mfn) ((mfn) < max_page)=0A+= =0A+#define max_pdx max_page=0A+#define pfn_to_pdx(pfn) = (pfn)=0A+#define pdx_to_pfn(pdx) (pdx)=0A+#define virt_to_pdx(= va) virt_to_mfn(va)=0A+#define pdx_to_virt(pdx) mfn_to_virt(= pdx)=0A+=0A static inline unsigned long __virt_to_maddr(unsigned long = va)=0A {=0A ASSERT(va >=3D DIRECTMAP_VIRT_START && va < DIRECTMAP_VIRT_= END);=0A return va - DIRECTMAP_VIRT_START;=0A }=0A-#define virt_to_madd= r(va) \=0A- (__virt_to_maddr((unsigned long)(va)))=0A =0A static = inline void *__maddr_to_virt(unsigned long ma)=0A {=0A ASSERT(ma < = DIRECTMAP_VIRT_END - DIRECTMAP_VIRT_START);=0A return (void *)(ma + = DIRECTMAP_VIRT_START);=0A }=0A-#define maddr_to_virt(ma) \=0A- = (__maddr_to_virt((unsigned long)(ma)))=0A =0A /* read access (should only = be used for debug printk's) */=0A typedef u64 intpte_t;=0A--- 2009-09-21.or= ig/xen/include/asm-x86/x86_64/page.h 2009-09-21 11:12:59.000000000 = +0200=0A+++ 2009-09-21/xen/include/asm-x86/x86_64/page.h 2009-09-21 = 11:13:02.000000000 +0200=0A@@ -35,25 +35,63 @@=0A /* Physical address = where Xen was relocated to. */=0A extern unsigned long xen_phys_start;=0A = =0A+extern unsigned long max_page, max_pdx;=0A+extern unsigned long = pfn_pdx_bottom_mask, ma_va_bottom_mask;=0A+extern unsigned int pfn_pdx_hole= _shift;=0A+extern unsigned long pfn_hole_mask;=0A+extern unsigned long = pfn_top_mask, ma_top_mask;=0A+extern void pfn_pdx_hole_setup(unsigned = long);=0A+=0A+#define page_to_pdx(pg) ((pg) - frame_table)=0A+#define = pdx_to_page(pdx) (frame_table + (pdx))=0A+/*=0A+ * Note: These are solely = for the use by page_{get,set}_owner(), and=0A+ * therefore don't = need to handle the XEN_VIRT_{START,END} range.=0A+ */=0A+#define virt_to_pd= x(va) (((unsigned long)(va) - DIRECTMAP_VIRT_START) >> \=0A+ = PAGE_SHIFT)=0A+#define pdx_to_virt(pdx) ((void *)(DIRECTMAP_VIR= T_START + \=0A+ ((unsigned long)(pdx) << = PAGE_SHIFT)))=0A+=0A+static inline int __mfn_valid(unsigned long = mfn)=0A+{=0A+ return mfn < max_page && !(mfn & pfn_hole_mask);=0A+}=0A+= =0A+static inline unsigned long pfn_to_pdx(unsigned long pfn)=0A+{=0A+ = return (pfn & pfn_pdx_bottom_mask) |=0A+ ((pfn & pfn_top_mask) = >> pfn_pdx_hole_shift);=0A+}=0A+=0A+static inline unsigned long pdx_to_pfn(= unsigned long pdx)=0A+{=0A+ return (pdx & pfn_pdx_bottom_mask) |=0A+ = ((pdx << pfn_pdx_hole_shift) & pfn_top_mask);=0A+}=0A+=0A static = inline unsigned long __virt_to_maddr(unsigned long va)=0A {=0A = ASSERT(va >=3D XEN_VIRT_START);=0A ASSERT(va < DIRECTMAP_VIRT_END);=0A-= ASSERT((va < XEN_VIRT_END) || (va >=3D DIRECTMAP_VIRT_START));=0A = if ( va >=3D DIRECTMAP_VIRT_START )=0A- return va - DIRECTMAP_VIRT_S= TART;=0A- return va - XEN_VIRT_START + xen_phys_start;=0A+ va = -=3D DIRECTMAP_VIRT_START;=0A+ else=0A+ {=0A+ ASSERT(va < = XEN_VIRT_END);=0A+ va +=3D xen_phys_start - XEN_VIRT_START;=0A+ = }=0A+ return (va & ma_va_bottom_mask) |=0A+ ((va << pfn_pdx_ho= le_shift) & ma_top_mask);=0A }=0A-#define virt_to_maddr(va) \=0A- = (__virt_to_maddr((unsigned long)(va)))=0A =0A static inline void *__maddr_t= o_virt(unsigned long ma)=0A {=0A ASSERT(ma < DIRECTMAP_VIRT_END - = DIRECTMAP_VIRT_START);=0A- return (void *)(ma + DIRECTMAP_VIRT_START);= =0A+ return (void *)(DIRECTMAP_VIRT_START +=0A+ ((ma = & ma_va_bottom_mask) |=0A+ ((ma & ma_top_mask) >> = pfn_pdx_hole_shift)));=0A }=0A-#define maddr_to_virt(ma) \=0A- = (__maddr_to_virt((unsigned long)(ma)))=0A =0A /* read access (should only = be used for debug printk's) */=0A typedef u64 intpte_t;=0A--- 2009-09-21.or= ig/xen/include/xen/acpi.h 2009-07-13 13:05:40.000000000 +0200=0A+++ = 2009-09-21/xen/include/xen/acpi.h 2009-09-21 11:13:02.000000000 = +0200=0A@@ -269,6 +269,9 @@ int acpi_table_parse(char *id, acpi_tabl=0A = int acpi_table_parse_entries(char *id, unsigned long table_size,=0A = int entry_id, acpi_table_entry_handler handler, unsigned int max_entries);= =0A int acpi_table_parse_madt(enum acpi_madt_type id, acpi_table_entry_hand= ler handler, unsigned int max_entries);=0A+int acpi_table_parse_srat(enum = acpi_srat_entry_id id,=0A+ acpi_madt_entry_handler handler, unsigned = int max_entries);=0A+int acpi_parse_srat(struct acpi_table_header *);=0A = void acpi_table_print (struct acpi_table_header *header, unsigned long = phys_addr);=0A void acpi_table_print_madt_entry (struct acpi_subtable_heade= r *madt);=0A void acpi_table_print_srat_entry (struct acpi_subtable_header = *srat);=0A--- 2009-09-21.orig/xen/include/xen/mm.h 2009-09-16 = 08:35:05.000000000 +0200=0A+++ 2009-09-21/xen/include/xen/mm.h 2009-09-21 = 11:13:02.000000000 +0200=0A@@ -103,6 +103,16 @@ struct page_list_head=0A = =0A #define PAGE_LIST_NULL (~0)=0A =0A+# if !defined(pdx_to_page) && = !defined(page_to_pdx)=0A+# if defined(__page_to_mfn) || defined(__mfn_to_p= age)=0A+# define page_to_pdx __page_to_mfn=0A+# define pdx_to_page = __mfn_to_page=0A+# else=0A+# define page_to_pdx page_to_mfn=0A+# = define pdx_to_page mfn_to_page=0A+# endif=0A+# endif=0A+=0A # define = PAGE_LIST_HEAD_INIT(name) { NULL, NULL }=0A # define PAGE_LIST_HEAD(name) = \=0A struct page_list_head name =3D PAGE_LIST_HEAD_INIT(name)=0A@@ = -123,21 +133,21 @@ static inline struct page_info *=0A page_list_next(const= struct page_info *page,=0A const struct page_list_head = *head)=0A {=0A- return page !=3D head->tail ? mfn_to_page(page->list.nex= t) : NULL;=0A+ return page !=3D head->tail ? pdx_to_page(page->list.next= ) : NULL;=0A }=0A static inline struct page_info *=0A page_list_prev(const = struct page_info *page,=0A const struct page_list_head = *head)=0A {=0A- return page !=3D head->next ? mfn_to_page(page->list.pre= v) : NULL;=0A+ return page !=3D head->next ? pdx_to_page(page->list.prev= ) : NULL;=0A }=0A static inline void=0A page_list_add(struct page_info = *page, struct page_list_head *head)=0A {=0A if ( head->next )=0A = {=0A- page->list.next =3D page_to_mfn(head->next);=0A- = head->next->list.prev =3D page_to_mfn(page);=0A+ page->list.next = =3D page_to_pdx(head->next);=0A+ head->next->list.prev =3D = page_to_pdx(page);=0A }=0A else=0A {=0A@@ -153,8 +163,8 @@ = page_list_add_tail(struct page_info *pag=0A page->list.next =3D = PAGE_LIST_NULL;=0A if ( head->next )=0A {=0A- page->list.pre= v =3D page_to_mfn(head->tail);=0A- head->tail->list.next =3D = page_to_mfn(page);=0A+ page->list.prev =3D page_to_pdx(head->tail);= =0A+ head->tail->list.next =3D page_to_pdx(page);=0A }=0A = else=0A {=0A@@ -191,8 +201,8 @@ __page_list_del_head(struct page_info = *p=0A static inline void=0A page_list_del(struct page_info *page, struct = page_list_head *head)=0A {=0A- struct page_info *next =3D mfn_to_page(pa= ge->list.next);=0A- struct page_info *prev =3D mfn_to_page(page->list.pr= ev);=0A+ struct page_info *next =3D pdx_to_page(page->list.next);=0A+ = struct page_info *prev =3D pdx_to_page(page->list.prev);=0A =0A if ( = !__page_list_del_head(page, head, next, prev) )=0A {=0A@@ -204,8 = +214,8 @@ static inline void=0A page_list_del2(struct page_info *page, = struct page_list_head *head1,=0A struct page_list_head = *head2)=0A {=0A- struct page_info *next =3D mfn_to_page(page->list.next)= ;=0A- struct page_info *prev =3D mfn_to_page(page->list.prev);=0A+ = struct page_info *next =3D pdx_to_page(page->list.next);=0A+ struct = page_info *prev =3D pdx_to_page(page->list.prev);=0A =0A if ( = !__page_list_del_head(page, head1, next, prev) &&=0A !__page_list_= del_head(page, head2, next, prev) )=0A@@ -252,11 +262,11 @@ page_list_splic= e(struct page_list_head *=0A last =3D list->tail;=0A at =3D = head->next;=0A =0A- first->list.prev =3D page_to_mfn(head->next);=0A+ = first->list.prev =3D page_to_pdx(head->next);=0A head->next =3D = first;=0A =0A- last->list.next =3D page_to_mfn(at);=0A- at->list.prev= =3D page_to_mfn(last);=0A+ last->list.next =3D page_to_pdx(at);=0A+ = at->list.prev =3D page_to_pdx(last);=0A }=0A =0A #define page_list_for_each= (pos, head) \=0A --=__Part755E858B.0__= Content-Type: text/plain; name="xen-x86-sparse-frame-table.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-x86-sparse-frame-table.patch" Avoid backing frame table holes with memory, when those holes are = large=0Aenough to cover an exact multiple of large pages. This is based on = the=0Aintroduction of a bit map, where each bit represents one such = range,=0Athus allowing mfn_valid() checks to easily filter out those MFNs = that=0Anow shouldn't be used to index the frame table.=0A=0AThis allows = for saving a couple of 2M pages even on "normal" systems.=0A=0ASigned-off-b= y: Jan Beulich =0A=0A--- 2009-09-21.orig/xen/arch/x86/= mm.c 2009-09-21 11:13:02.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/m= m.c 2009-09-21 11:14:51.000000000 +0200=0A@@ -141,6 +141,10 @@ struct = domain *dom_xen, *dom_io;=0A unsigned long max_page;=0A unsigned long = total_pages;=0A =0A+unsigned long __read_mostly pdx_group_valid[BITS_TO_LON= GS(=0A+ (FRAMETABLE_SIZE / sizeof(*frame_table) + PDX_GROUP_COUNT - = 1)=0A+ / PDX_GROUP_COUNT)] =3D { [0] =3D 1 };=0A+=0A #define PAGE_CACHE_= ATTRS (_PAGE_PAT|_PAGE_PCD|_PAGE_PWT)=0A =0A int opt_allow_hugepage;=0A@@ = -162,36 +166,58 @@ l2_pgentry_t *compat_idle_pg_table_l2 =3D =0A #define = l3_disallow_mask(d) L3_DISALLOW_MASK=0A #endif=0A =0A+static void __init = init_frametable_chunk(void *start, void *end)=0A+{=0A+ unsigned long s = =3D (unsigned long)start;=0A+ unsigned long e =3D (unsigned long)end;=0A= + unsigned long step, mfn;=0A+=0A+ ASSERT(!(s & ((1 << L2_PAGETABLE_S= HIFT) - 1)));=0A+ for ( ; s < e; s +=3D step << PAGE_SHIFT )=0A+ = {=0A+ step =3D 1UL << (cpu_has_page1gb &&=0A+ = !(s & ((1UL << L3_PAGETABLE_SHIFT) - 1)) ?=0A+ = L3_PAGETABLE_SHIFT - PAGE_SHIFT :=0A+ L2_PAGETABLE_SH= IFT - PAGE_SHIFT);=0A+ /*=0A+ * The hardcoded 4 below is = arbitrary - just pick whatever you think=0A+ * is reasonable to = waste as a trade-off for using a large page.=0A+ */=0A+ = while ( step && s + (step << PAGE_SHIFT) > e + (4 << PAGE_SHIFT) )=0A+ = step >>=3D PAGETABLE_ORDER;=0A+ do {=0A+ mfn =3D = alloc_boot_pages(step, step);=0A+ } while ( !mfn && (step >>=3D = PAGETABLE_ORDER) );=0A+ if ( !mfn )=0A+ panic("Not = enough memory for frame table");=0A+ map_pages_to_xen(s, mfn, step, = PAGE_HYPERVISOR);=0A+ }=0A+=0A+ memset(start, 0, end - start);=0A+ = memset(end, -1, s - (unsigned long)end);=0A+}=0A+=0A void __init = init_frametable(void)=0A {=0A- unsigned long nr_pages, page_step, i, = mfn;=0A+ unsigned int sidx, eidx, nidx;=0A+ unsigned int max_idx =3D = (max_pdx + PDX_GROUP_COUNT - 1) / PDX_GROUP_COUNT;=0A =0A #ifdef __x86_64__= =0A- BUILD_BUG_ON(FRAMETABLE_VIRT_START & ((1UL << L3_PAGETABLE_SHIFT) = - 1));=0A BUILD_BUG_ON(XEN_VIRT_END > FRAMETABLE_VIRT_END);=0A-#else=0A= - BUILD_BUG_ON(FRAMETABLE_VIRT_START & ((1UL << L2_PAGETABLE_SHIFT) - = 1));=0A #endif=0A+ BUILD_BUG_ON(FRAMETABLE_VIRT_START & ((1UL << = L2_PAGETABLE_SHIFT) - 1));=0A =0A- nr_pages =3D PFN_UP(max_pdx * = sizeof(*frame_table));=0A- page_step =3D 1 << (cpu_has_page1gb ? = L3_PAGETABLE_SHIFT - PAGE_SHIFT=0A- : = L2_PAGETABLE_SHIFT - PAGE_SHIFT);=0A-=0A- for ( i =3D 0; i < nr_pages; = i +=3D page_step )=0A+ for ( sidx =3D 0; ; sidx =3D nidx )=0A {=0A- = /*=0A- * The hardcoded 4 below is arbitrary - just pick = whatever you think=0A- * is reasonable to waste as a trade-off for = using a large page.=0A- */=0A- while (nr_pages + 4 - i < = page_step)=0A- page_step >>=3D PAGETABLE_ORDER;=0A- mfn = =3D alloc_boot_pages(page_step, page_step);=0A- map_pages_to_xen(=0A= - FRAMETABLE_VIRT_START + (i << PAGE_SHIFT),=0A- = mfn, page_step, PAGE_HYPERVISOR);=0A+ eidx =3D find_next_zero_bit(pd= x_group_valid, max_idx, sidx);=0A+ nidx =3D find_next_bit(pdx_group_= valid, max_idx, eidx);=0A+ if ( nidx >=3D max_idx )=0A+ = break;=0A+ init_frametable_chunk(pdx_to_page(sidx * PDX_GROUP_COUNT)= ,=0A+ pdx_to_page(eidx * PDX_GROUP_COUNT));=0A= }=0A-=0A- memset(frame_table, 0, nr_pages << PAGE_SHIFT);=0A+ = init_frametable_chunk(pdx_to_page(sidx * PDX_GROUP_COUNT),=0A+ = pdx_to_page(max_pdx - 1) + 1);=0A }=0A =0A void __init = arch_init_memory(void)=0A--- 2009-09-21.orig/xen/arch/x86/setup.c = 2009-09-21 11:13:02.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/setup.c = 2009-09-21 11:14:51.000000000 +0200=0A@@ -312,6 +312,16 @@ static void = __init setup_max_pdx(void)=0A #endif=0A }=0A =0A+static void __init = set_pdx_range(unsigned long smfn, unsigned long emfn)=0A+{=0A+ unsigned = long idx, eidx;=0A+=0A+ idx =3D pfn_to_pdx(smfn) / PDX_GROUP_COUNT;=0A+ = eidx =3D (pfn_to_pdx(emfn - 1) + PDX_GROUP_COUNT) / PDX_GROUP_COUNT;=0A+= for ( ; idx < eidx; ++idx )=0A+ __set_bit(idx, pdx_group_valid);= =0A+}=0A+=0A /* A temporary copy of the e820 map that we can mess with = during bootstrap. */=0A static struct e820map __initdata boot_e820;=0A = =0A@@ -657,6 +667,8 @@ void __init __start_xen(unsigned long mb=0A = if ( (boot_e820.map[i].type !=3D E820_RAM) || (s >=3D e) )=0A = continue;=0A =0A+ set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);= =0A+=0A /* Map the chunk. No memory will need to be allocated to = do this. */=0A map_pages_to_xen(=0A (unsigned = long)maddr_to_bootstrap_virt(s),=0A@@ -853,6 +865,8 @@ void __init = __start_xen(unsigned long mb=0A }=0A #endif=0A =0A+ = set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);=0A+=0A /* Need to = create mappings above 16MB. */=0A map_s =3D max_t(uint64_t, s, = 16<<20);=0A map_e =3D e;=0A--- 2009-09-21.orig/xen/arch/x86/x86_64/= mm.c 2009-09-21 11:13:02.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/x= 86_64/mm.c 2009-09-21 11:14:51.000000000 +0200=0A@@ -64,6 +64,14 @@ = l3_pgentry_t __attribute__ ((__section__=0A l2_pgentry_t __attribute__ = ((__section__ (".bss.page_aligned")))=0A l2_xenmap[L2_PAGETABLE_ENTRIES= ];=0A =0A+int __mfn_valid(unsigned long mfn)=0A+{=0A+ return likely(mfn = < max_page) &&=0A+ likely(!(mfn & pfn_hole_mask)) &&=0A+ = likely(test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT,=0A+ = pdx_group_valid));=0A+}=0A+=0A void *alloc_xen_pagetable(void)=0A = {=0A extern int early_boot;=0A--- 2009-09-21.orig/xen/include/asm-x86/c= onfig.h 2009-09-21 11:13:02.000000000 +0200=0A+++ 2009-09-21/xen/include/as= m-x86/config.h 2009-09-21 11:14:51.000000000 +0200=0A@@ -314,7 +314,8 @@ = extern unsigned int video_mode, video_fl=0A #define RDWR_MPT_VIRT_END = LINEAR_PT_VIRT_START=0A #define RDWR_MPT_VIRT_START (RDWR_MPT_VIRT_END = - (MACHPHYS_MBYTES<<20))=0A #define FRAMETABLE_VIRT_END RDWR_MPT_VIRT_START= =0A-#define FRAMETABLE_VIRT_START (FRAMETABLE_VIRT_END - (FRAMETABLE_= MBYTES<<20))=0A+#define FRAMETABLE_SIZE (FRAMETABLE_MBYTES<<20)=0A+= #define FRAMETABLE_VIRT_START (FRAMETABLE_VIRT_END - FRAMETABLE_SIZE)=0A = #define RO_MPT_VIRT_END FRAMETABLE_VIRT_START=0A #define RO_MPT_VIR= T_START (RO_MPT_VIRT_END - (MACHPHYS_MBYTES<<20))=0A =0A--- 2009-09-21.orig= /xen/include/asm-x86/mm.h 2009-09-21 11:13:02.000000000 +0200=0A+++ = 2009-09-21/xen/include/asm-x86/mm.h 2009-09-21 11:14:51.000000000 = +0200=0A@@ -263,6 +263,10 @@ extern unsigned long max_page;=0A extern = unsigned long total_pages;=0A void init_frametable(void);=0A =0A+#define = PDX_GROUP_COUNT ((1 << L2_PAGETABLE_SHIFT) / \=0A+ = (sizeof(*frame_table) & -sizeof(*frame_table)))=0A+extern unsigned long = pdx_group_valid[];=0A+=0A /* Convert between Xen-heap virtual addresses = and page-info structures. */=0A static inline struct page_info *__virt_to_p= age(const void *v)=0A {=0A--- 2009-09-21.orig/xen/include/asm-x86/x86_32/pa= ge.h 2009-09-21 11:13:02.000000000 +0200=0A+++ 2009-09-21/xen/include/as= m-x86/x86_32/page.h 2009-09-21 11:14:51.000000000 +0200=0A@@ -41,7 = +41,11 @@=0A #include =0A #include =0A = =0A-#define __mfn_valid(mfn) ((mfn) < max_page)=0A+#define = __mfn_valid(mfn) ({ = \=0A+ unsigned long __m_f_n =3D (mfn); = \=0A+ likely(__m_f_n < max_page) && = \=0A+ likely(test_bit(pfn_to_pdx(__m_f_n) / PDX_GROUP_= COUNT, pdx_group_valid)); \=0A+})=0A =0A #define max_pdx = max_page=0A #define pfn_to_pdx(pfn) (pfn)=0A--- 2009-09-21.orig/xen= /include/asm-x86/x86_64/page.h 2009-09-21 11:13:02.000000000 +0200=0A+++ = 2009-09-21/xen/include/asm-x86/x86_64/page.h 2009-09-21 11:14:51.0000000= 00 +0200=0A@@ -35,7 +35,7 @@=0A /* Physical address where Xen was = relocated to. */=0A extern unsigned long xen_phys_start;=0A =0A-extern = unsigned long max_page, max_pdx;=0A+extern unsigned long max_pdx;=0A = extern unsigned long pfn_pdx_bottom_mask, ma_va_bottom_mask;=0A extern = unsigned int pfn_pdx_hole_shift;=0A extern unsigned long pfn_hole_mask;=0A@= @ -53,10 +53,7 @@ extern void pfn_pdx_hole_setup(unsigned =0A #define = pdx_to_virt(pdx) ((void *)(DIRECTMAP_VIRT_START + \=0A = ((unsigned long)(pdx) << PAGE_SHIFT)))=0A =0A-static inline = int __mfn_valid(unsigned long mfn)=0A-{=0A- return mfn < max_page && = !(mfn & pfn_hole_mask);=0A-}=0A+extern int __mfn_valid(unsigned long = mfn);=0A =0A static inline unsigned long pfn_to_pdx(unsigned long pfn)=0A = {=0A --=__Part755E858B.0__= Content-Type: text/plain; name="xen-x86-sparse-m2p-table.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-x86-sparse-m2p-table.patch" Avoid backing M2P table holes with memory, when those holes are large=0Aeno= ugh to cover an exact multiple of large pages.=0A=0AFor the sake of saving = and migrating guests, XENMEM_machphys_mfn_list=0Afills the holes in the = array it returns with the MFN for the previous=0Arange returned (thanks to = Keir pointing out that it really doesn't=0Amatter *what* MFN gets returned = for invalid ranges). Using the most=0Arescently encountered MFN (rather = than e.g. always the first one)=0Arepresents an attempt to cut down on the = number of references these=0Apages will get when they get mapped into a = privileged domain's address=0Aspace.=0A=0AThis also allows for saving a = couple of 2M pages even on certain=0A"normal" systems.=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- 2009-09-10.orig/xen/arch/x86/x86= _32/mm.c 2009-09-17 15:51:43.000000000 +0200=0A+++ 2009-09-10/xen/ar= ch/x86/x86_32/mm.c 2009-09-17 12:06:40.000000000 +0200=0A@@ -72,7 = +72,7 @@ void __init paging_init(void)=0A {=0A unsigned long v;=0A = struct page_info *pg;=0A- int i;=0A+ unsigned int i, n;=0A =0A = if ( cpu_has_pge )=0A {=0A@@ -96,8 +96,18 @@ void __init paging_init(vo= id)=0A */=0A mpt_size =3D (max_page * BYTES_PER_LONG) + (1UL << = L2_PAGETABLE_SHIFT) - 1;=0A mpt_size &=3D ~((1UL << L2_PAGETABLE_SHIFT)= - 1UL);=0A+#define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned = long))=0A+#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / = \=0A+ sizeof(*machine_to_phys_mapping))=0A+ BUILD_BUG_ON((si= zeof(*frame_table) & ~sizeof(*frame_table)) % \=0A+ = sizeof(*machine_to_phys_mapping));=0A for ( i =3D 0; i < (mpt_size >> = L2_PAGETABLE_SHIFT); i++ )=0A {=0A+ for ( n =3D 0; n < CNT; = ++n)=0A+ if ( mfn_valid(MFN(i) + n * PDX_GROUP_COUNT) )=0A+ = break;=0A+ if ( n =3D=3D CNT )=0A+ = continue;=0A if ( (pg =3D alloc_domheap_pages(NULL, PAGETABLE_ORDER= , 0)) =3D=3D NULL )=0A panic("Not enough memory to bootstrap = Xen.\n");=0A l2e_write(&idle_pg_table_l2[l2_linear_offset(RDWR_MPT_= VIRT_START) + i],=0A@@ -106,11 +116,12 @@ void __init paging_init(void)=0A = l2e_write(&idle_pg_table_l2[l2_linear_offset(RO_MPT_VIRT_START) + = i],=0A l2e_from_page(=0A pg, = (__PAGE_HYPERVISOR | _PAGE_PSE) & ~_PAGE_RW));=0A+ /* Fill with an = obvious debug pattern. */=0A+ memset((void *)(RDWR_MPT_VIRT_START + = (i << L2_PAGETABLE_SHIFT)), 0x55,=0A+ 1UL << L2_PAGETABLE_SHI= FT);=0A }=0A-=0A- /* Fill with an obvious debug pattern. */=0A- = for ( i =3D 0; i < (mpt_size / BYTES_PER_LONG); i++)=0A- set_gpfn_fr= om_mfn(i, 0x55555555);=0A+#undef CNT=0A+#undef MFN=0A =0A /* Create = page tables for ioremap()/map_domain_page_global(). */=0A for ( i =3D = 0; i < (IOREMAP_MBYTES >> (L2_PAGETABLE_SHIFT - 20)); i++ )=0A@@ -163,14 = +174,17 @@ void __init subarch_init_memory(void)=0A {=0A unsigned long = m2p_start_mfn;=0A unsigned int i, j;=0A+ l2_pgentry_t l2e;=0A =0A = BUILD_BUG_ON(sizeof(struct page_info) !=3D 24);=0A =0A /* M2P table = is mappable read-only by privileged domains. */=0A for ( i =3D 0; i < = (mpt_size >> L2_PAGETABLE_SHIFT); i++ )=0A {=0A- m2p_start_mfn = =3D l2e_get_pfn(=0A- idle_pg_table_l2[l2_linear_offset(RDWR_MPT_= VIRT_START) + i]);=0A+ l2e =3D idle_pg_table_l2[l2_linear_offset(RDW= R_MPT_VIRT_START) + i];=0A+ if ( !(l2e_get_flags(l2e) & _PAGE_PRESEN= T) )=0A+ continue;=0A+ m2p_start_mfn =3D l2e_get_pfn(l2e)= ;=0A for ( j =3D 0; j < L2_PAGETABLE_ENTRIES; j++ )=0A = {=0A struct page_info *page =3D mfn_to_page(m2p_start_mfn + = j);=0A@@ -191,8 +205,9 @@ void __init subarch_init_memory(void)=0A long = subarch_memory_op(int op, XEN_GUEST_HANDLE(void) arg)=0A {=0A struct = xen_machphys_mfn_list xmml;=0A- unsigned long mfn;=0A+ unsigned long = mfn, last_mfn;=0A unsigned int i, max;=0A+ l2_pgentry_t l2e;=0A = long rc =3D 0;=0A =0A switch ( op )=0A@@ -203,12 +218,18 @@ long = subarch_memory_op(int op, XEN_GUEST=0A =0A max =3D min_t(unsigned = int, xmml.max_extents, mpt_size >> 21);=0A =0A- for ( i =3D 0; i < = max; i++ )=0A+ for ( i =3D 0, last_mfn =3D 0; i < max; i++ )=0A = {=0A- mfn =3D l2e_get_pfn(idle_pg_table_l2[l2_linear_offset(= =0A- RDWR_MPT_VIRT_START + (i << 21))]) + l1_table_offset(i = << 21);=0A+ l2e =3D idle_pg_table_l2[l2_linear_offset(=0A+ = RDWR_MPT_VIRT_START + (i << 21))];=0A+ if ( l2e_get_fl= ags(l2e) & _PAGE_PRESENT )=0A+ mfn =3D l2e_get_pfn(l2e);=0A+= else=0A+ mfn =3D last_mfn;=0A+ = ASSERT(mfn);=0A if ( copy_to_guest_offset(xmml.extent_start, = i, &mfn, 1) )=0A return -EFAULT;=0A+ last_mfn = =3D mfn;=0A }=0A =0A xmml.nr_extents =3D i;=0A--- = 2009-09-10.orig/xen/arch/x86/x86_64/compat/mm.c 2009-09-17 15:51:43.0000000= 00 +0200=0A+++ 2009-09-10/xen/arch/x86/x86_64/compat/mm.c 2009-09-17 = 09:08:28.000000000 +0200=0A@@ -153,19 +153,31 @@ int compat_arch_memory_op(= int op, XEN_GU=0A }=0A =0A case XENMEM_machphys_mfn_list:=0A+ = {=0A+ unsigned long limit;=0A+ compat_pfn_t last_mfn;=0A+=0A = if ( copy_from_guest(&xmml, arg, 1) )=0A return = -EFAULT;=0A =0A- for ( i =3D 0, v =3D RDWR_COMPAT_MPT_VIRT_START;=0A= - (i !=3D xmml.max_extents) && (v !=3D RDWR_COMPAT_MPT_VIRT_EN= D);=0A+ limit =3D (unsigned long)(compat_machine_to_phys_mapping = +=0A+ min_t(unsigned long, max_page,=0A+ = MACH2PHYS_COMPAT_NR_ENTRIES(current->domain)));=0A+ if ( limit > = RDWR_COMPAT_MPT_VIRT_END )=0A+ limit =3D RDWR_COMPAT_MPT_VIRT_EN= D;=0A+ for ( i =3D 0, v =3D RDWR_COMPAT_MPT_VIRT_START, last_mfn = =3D 0;=0A+ (i !=3D xmml.max_extents) && (v < limit);=0A = i++, v +=3D 1 << L2_PAGETABLE_SHIFT )=0A {=0A = l2e =3D compat_idle_pg_table_l2[l2_table_offset(v)];=0A- if ( = !(l2e_get_flags(l2e) & _PAGE_PRESENT) )=0A- break;=0A- = mfn =3D l2e_get_pfn(l2e) + l1_table_offset(v);=0A+ if ( = l2e_get_flags(l2e) & _PAGE_PRESENT )=0A+ mfn =3D l2e_get_pfn= (l2e);=0A+ else=0A+ mfn =3D last_mfn;=0A+ = ASSERT(mfn);=0A if ( copy_to_compat_offset(xmml.extent_star= t, i, &mfn, 1) )=0A return -EFAULT;=0A+ = last_mfn =3D mfn;=0A }=0A =0A xmml.nr_extents =3D i;=0A@@ = -173,6 +185,7 @@ int compat_arch_memory_op(int op, XEN_GU=0A = rc =3D -EFAULT;=0A =0A break;=0A+ }=0A =0A default:=0A = rc =3D -ENOSYS;=0A--- 2009-09-10.orig/xen/arch/x86/x86_64/mm.c = 2009-09-17 15:53:39.000000000 +0200=0A+++ 2009-09-10/xen/arch/x86/x86_64/mm= .c 2009-09-17 15:53:46.000000000 +0200=0A@@ -194,7 +194,7 @@ void = __init pfn_pdx_hole_setup(unsigned =0A void __init paging_init(void)=0A = {=0A unsigned long i, mpt_size, va;=0A- unsigned int memflags;=0A+ = unsigned int n, memflags;=0A l3_pgentry_t *l3_ro_mpt;=0A = l2_pgentry_t *l2_ro_mpt =3D NULL;=0A struct page_info *l1_pg, *l2_pg, = *l3_pg;=0A@@ -213,6 +213,11 @@ void __init paging_init(void)=0A */=0A = mpt_size =3D (max_page * BYTES_PER_LONG) + (1UL << L2_PAGETABLE_SHIFT)= - 1;=0A mpt_size &=3D ~((1UL << L2_PAGETABLE_SHIFT) - 1UL);=0A+#define= MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long))=0A+#define = CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \=0A+ = sizeof(*machine_to_phys_mapping))=0A+ BUILD_BUG_ON((sizeof(*frame_table)= & ~sizeof(*frame_table)) % \=0A+ sizeof(*machine_to_phys_m= apping));=0A for ( i =3D 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++ = )=0A {=0A BUILD_BUG_ON(RO_MPT_VIRT_START & ((1UL << L3_PAGETABL= E_SHIFT) - 1));=0A@@ -222,37 +227,63 @@ void __init paging_init(void)=0A = =0A if ( cpu_has_page1gb &&=0A !((unsigned long)l2_ro_= mpt & ~PAGE_MASK) &&=0A- (mpt_size >> L3_PAGETABLE_SHIFT) > (i = >> PAGETABLE_ORDER) &&=0A- (l1_pg =3D alloc_domheap_pages(NULL,= 2 * PAGETABLE_ORDER,=0A- = memflags)) !=3D NULL )=0A+ (mpt_size >> L3_PAGETABLE_SHIFT) > = (i >> PAGETABLE_ORDER) )=0A+ {=0A+ unsigned int k, = holes;=0A+=0A+ for ( holes =3D k =3D 0; k < 1 << PAGETABLE_ORDER= ; ++k)=0A+ {=0A+ for ( n =3D 0; n < CNT; = ++n)=0A+ if ( mfn_valid(MFN(i + k) + n * PDX_GROUP_COUNT= ) )=0A+ break;=0A+ if ( n =3D=3D CNT = )=0A+ ++holes;=0A+ }=0A+ if ( k = =3D=3D holes )=0A+ {=0A+ i +=3D (1UL << = PAGETABLE_ORDER) - 1;=0A+ continue;=0A+ }=0A+ = if ( holes =3D=3D 0 &&=0A+ (l1_pg =3D alloc_domheap= _pages(NULL, 2 * PAGETABLE_ORDER,=0A+ = memflags)) !=3D NULL )=0A+ {=0A+ = map_pages_to_xen(=0A+ RDWR_MPT_VIRT_START + (i << = L2_PAGETABLE_SHIFT),=0A+ page_to_mfn(l1_pg),=0A+ = 1UL << (2 * PAGETABLE_ORDER),=0A+ PAGE_HYPER= VISOR);=0A+ memset((void *)(RDWR_MPT_VIRT_START + (i << = L2_PAGETABLE_SHIFT)),=0A+ 0x77, 1UL << L3_PAGETABLE_S= HIFT);=0A+=0A+ ASSERT(!l2_table_offset(va));=0A+ = /* NB. Cannot be GLOBAL as shadow_mode_translate reuses this area. = */=0A+ l3e_write(&l3_ro_mpt[l3_table_offset(va)],=0A+ = l3e_from_page(l1_pg,=0A+ /*_PAGE_GLOBAL= |*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT));=0A+ i +=3D (1UL << = PAGETABLE_ORDER) - 1;=0A+ continue;=0A+ }=0A+ = }=0A+=0A+ for ( n =3D 0; n < CNT; ++n)=0A+ if ( = mfn_valid(MFN(i) + n * PDX_GROUP_COUNT) )=0A+ break;=0A+ = if ( n =3D=3D CNT )=0A+ l1_pg =3D NULL;=0A+ else if = ( (l1_pg =3D alloc_domheap_pages(NULL, PAGETABLE_ORDER,=0A+ = memflags)) =3D=3D NULL )=0A+ = goto nomem;=0A+ else=0A {=0A map_pages_to_xen(= =0A RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT),=0A = page_to_mfn(l1_pg),=0A- 1UL << (2 * PAGETABLE_O= RDER),=0A+ 1UL << PAGETABLE_ORDER,=0A = PAGE_HYPERVISOR);=0A memset((void *)(RDWR_MPT_VIRT_START + (i = << L2_PAGETABLE_SHIFT)),=0A- 0x77, 1UL << L3_PAGETABLE_SH= IFT);=0A-=0A- ASSERT(!l2_table_offset(va));=0A- /* = NB. Cannot be GLOBAL as shadow_mode_translate reuses this area. */=0A- = l3e_write(&l3_ro_mpt[l3_table_offset(va)],=0A- = l3e_from_page(l1_pg,=0A- /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAG= E_USER|_PAGE_PRESENT));=0A- i +=3D (1UL << PAGETABLE_ORDER) - = 1;=0A- continue;=0A+ 0x55, 1UL << L2_PAGETABLE= _SHIFT);=0A }=0A-=0A- if ( (l1_pg =3D alloc_domheap_pages(NU= LL, PAGETABLE_ORDER,=0A- = memflags)) =3D=3D NULL )=0A- goto nomem;=0A- map_pages_to= _xen(=0A- RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT),=0A- = page_to_mfn(l1_pg), =0A- 1UL << PAGETABLE_ORDER,=0A- = PAGE_HYPERVISOR);=0A- memset((void *)(RDWR_MPT_VIRT_START = + (i << L2_PAGETABLE_SHIFT)), 0x55,=0A- 1UL << L2_PAGETABLE_S= HIFT);=0A if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) )=0A = {=0A if ( (l2_pg =3D alloc_domheap_page(NULL, memflags)) = =3D=3D NULL )=0A@@ -264,10 +295,13 @@ void __init paging_init(void)=0A = ASSERT(!l2_table_offset(va));=0A }=0A /* NB. = Cannot be GLOBAL as shadow_mode_translate reuses this area. */=0A- = l2e_write(l2_ro_mpt, l2e_from_page(=0A- l1_pg, /*_PAGE_GLOBAL|*/= _PAGE_PSE|_PAGE_USER|_PAGE_PRESENT));=0A+ if ( l1_pg )=0A+ = l2e_write(l2_ro_mpt, l2e_from_page(=0A+ l1_pg, /*_PAGE_GLO= BAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT));=0A l2_ro_mpt++;=0A = }=0A+#undef CNT=0A+#undef MFN=0A =0A /* Create user-accessible L2 = directory to map the MPT for compat guests. */=0A BUILD_BUG_ON(l4_table= _offset(RDWR_MPT_VIRT_START) !=3D=0A@@ -288,12 +322,22 @@ void __init = paging_init(void)=0A mpt_size &=3D ~((1UL << L2_PAGETABLE_SHIFT) - = 1UL);=0A if ( (m2p_compat_vstart + mpt_size) < MACH2PHYS_COMPAT_VIRT_EN= D )=0A m2p_compat_vstart =3D MACH2PHYS_COMPAT_VIRT_END - = mpt_size;=0A- for ( i =3D 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++ = )=0A+#define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned = int))=0A+#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / = \=0A+ sizeof(*compat_machine_to_phys_mapping))=0A+ = BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) % \=0A+ = sizeof(*compat_machine_to_phys_mapping));=0A+ for ( i =3D 0; i = < (mpt_size >> L2_PAGETABLE_SHIFT); i++, l2_ro_mpt++ )=0A {=0A = memflags =3D MEMF_node(phys_to_nid(i <<=0A (L2_PAGETABLE_SHIFT = - 2 + PAGE_SHIFT)));=0A+ for ( n =3D 0; n < CNT; ++n)=0A+ = if ( mfn_valid(MFN(i) + n * PDX_GROUP_COUNT) )=0A+ = break;=0A+ if ( n =3D=3D CNT )=0A+ continue;=0A = if ( (l1_pg =3D alloc_domheap_pages(NULL, PAGETABLE_ORDER,=0A- = memflags)) =3D=3D NULL )=0A+ = memflags)) =3D=3D NULL )=0A goto = nomem;=0A map_pages_to_xen(=0A RDWR_COMPAT_MPT_VIRT_STA= RT + (i << L2_PAGETABLE_SHIFT),=0A@@ -306,8 +350,9 @@ void __init = paging_init(void)=0A 1UL << L2_PAGETABLE_SHIFT);=0A = /* NB. Cannot be GLOBAL as the ptes get copied into per-VM space. */=0A = l2e_write(l2_ro_mpt, l2e_from_page(l1_pg, _PAGE_PSE|_PAGE_PRESENT));= =0A- l2_ro_mpt++;=0A }=0A+#undef CNT=0A+#undef MFN=0A =0A = /* Set up linear page table mapping. */=0A l4e_write(&idle_pg_table[l4_= table_offset(LINEAR_PT_VIRT_START)],=0A@@ -428,7 +473,7 @@ long subarch_mem= ory_op(int op, XEN_GUEST=0A l3_pgentry_t l3e;=0A l2_pgentry_t = l2e;=0A unsigned long v;=0A- xen_pfn_t mfn;=0A+ xen_pfn_t mfn, = last_mfn;=0A unsigned int i;=0A long rc =3D 0;=0A =0A@@ -440,29 = +485,32 @@ long subarch_memory_op(int op, XEN_GUEST=0A =0A = BUILD_BUG_ON(RDWR_MPT_VIRT_START & ((1UL << L3_PAGETABLE_SHIFT) - 1));=0A = BUILD_BUG_ON(RDWR_MPT_VIRT_END & ((1UL << L3_PAGETABLE_SHIFT) - = 1));=0A- for ( i =3D 0, v =3D RDWR_MPT_VIRT_START;=0A- = (i !=3D xmml.max_extents) && (v !=3D RDWR_MPT_VIRT_END);=0A+ for ( = i =3D 0, v =3D RDWR_MPT_VIRT_START, last_mfn =3D 0;=0A+ (i = !=3D xmml.max_extents) &&=0A+ (v < (unsigned long)(machine_to_= phys_mapping + max_page));=0A i++, v +=3D 1UL << L2_PAGETABLE= _SHIFT )=0A {=0A l3e =3D l4e_to_l3e(idle_pg_table[l4_ta= ble_offset(v)])[=0A l3_table_offset(v)];=0A if = ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )=0A- break;=0A- = if ( !(l3e_get_flags(l3e) & _PAGE_PSE) )=0A+ mfn = =3D last_mfn;=0A+ else if ( !(l3e_get_flags(l3e) & _PAGE_PSE) = )=0A {=0A l2e =3D l3e_to_l2e(l3e)[l2_table_offs= et(v)];=0A- if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) = )=0A- break;=0A- mfn =3D l2e_get_pfn(l2e)= ;=0A+ if ( l2e_get_flags(l2e) & _PAGE_PRESENT )=0A+ = mfn =3D l2e_get_pfn(l2e);=0A+ else=0A+ = mfn =3D last_mfn;=0A }=0A else=0A = {=0A mfn =3D l3e_get_pfn(l3e)=0A + = (l2_table_offset(v) << PAGETABLE_ORDER);=0A }=0A- = ASSERT(!l1_table_offset(v));=0A+ ASSERT(mfn);=0A if = ( copy_to_guest_offset(xmml.extent_start, i, &mfn, 1) )=0A = return -EFAULT;=0A+ last_mfn =3D mfn;=0A }=0A =0A = xmml.nr_extents =3D i;=0A --=__Part755E858B.0__= Content-Type: text/plain; name="xen-map-domain-page-page-param.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-map-domain-page-page-param.patch" Introduce a variant of map_domain_page() directly getting passed a=0Astruct= page_info * argument, based on the observation that in many=0Aplaces the = argument to this function so far simply was the result of=0Apage_to_mfn(). = This is meaningful for the x86-64 case where=0Amap_domain_page() really = just is an invocation of mfn_to_virt(), and=0Ahence the combined mfn_to_vir= t(page_to_mfn()) now represents a=0Aneedless roundtrip conversion = compressed -> uncompressed ->=0Acompressed of the MFN representation.=0A=0A= While it might seem more logical to rename map_domain_page() to e.g.=0Amap_= domain_mfn(), this would require touching a lot more code.=0A=0ASigned-off-= by: Jan Beulich =0A=0A--- 2009-09-21.orig/xen/arch/x86= /hvm/stdvga.c 2009-07-14 08:55:22.000000000 +0200=0A+++ 2009-09-21/xen/ar= ch/x86/hvm/stdvga.c 2009-09-21 11:14:58.000000000 +0200=0A@@ -85,14 = +85,14 @@ const uint8_t gr_mask[9] =3D {=0A static uint8_t *vram_getb(struc= t hvm_hw_stdvga *s, unsigned int a)=0A {=0A struct page_info *pg =3D = s->vram_page[(a >> 12) & 0x3f];=0A- uint8_t *p =3D map_domain_page(page_= to_mfn(pg));=0A+ uint8_t *p =3D __map_domain_page(pg);=0A return = &p[a & 0xfff];=0A }=0A =0A static uint32_t *vram_getl(struct hvm_hw_stdvga = *s, unsigned int a)=0A {=0A struct page_info *pg =3D s->vram_page[(a = >> 10) & 0x3f];=0A- uint32_t *p =3D map_domain_page(page_to_mfn(pg));=0A= + uint32_t *p =3D __map_domain_page(pg);=0A return &p[a & 0x3ff];=0A= }=0A =0A@@ -601,7 +601,7 @@ void stdvga_init(struct domain *d)=0A = if ( pg =3D=3D NULL )=0A break;=0A s->vram_page[i] =3D = pg;=0A- p =3D map_domain_page(page_to_mfn(pg));=0A+ p =3D = __map_domain_page(pg);=0A clear_page(p);=0A unmap_domain_pa= ge(p);=0A }=0A--- 2009-09-21.orig/xen/arch/x86/hvm/vlapic.c 2009-09-21 = 08:39:42.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/hvm/vlapic.c = 2009-09-21 11:14:58.000000000 +0200=0A@@ -978,7 +978,7 @@ int vlapic_init(s= truct vcpu *v)=0A }=0A if (vlapic->regs =3D=3D NULL) =0A {=0A- = vlapic->regs =3D map_domain_page_global(page_to_mfn(vlapic->regs_pag= e));=0A+ vlapic->regs =3D __map_domain_page_global(vlapic->regs_page= );=0A if ( vlapic->regs =3D=3D NULL )=0A {=0A = dprintk(XENLOG_ERR, "map vlapic regs error: %d/%d\n",=0A--- 2009-09-21.orig= /xen/arch/x86/mm.c 2009-09-21 11:14:51.000000000 +0200=0A+++ = 2009-09-21/xen/arch/x86/mm.c 2009-09-21 11:14:58.000000000 +0200=0A@@ = -543,7 +543,7 @@ static int alloc_segdesc_page(struct pag=0A struct = desc_struct *descs;=0A int i;=0A =0A- descs =3D map_domain_page(page= _to_mfn(page));=0A+ descs =3D __map_domain_page(page);=0A =0A for ( = i =3D 0; i < 512; i++ )=0A if ( unlikely(!check_descriptor(page_get= _owner(page), &descs[i])) )=0A--- 2009-09-21.orig/xen/arch/x86/mm/hap/hap.c= 2009-06-29 11:58:15.000000000 +0200=0A+++ 2009-09-21/xen/arch/x86/m= m/hap/hap.c 2009-09-21 11:14:58.000000000 +0200=0A@@ -255,7 +255,7 @@ = static struct page_info *hap_alloc(struc=0A =0A d->arch.paging.hap.free= _pages--;=0A =0A- p =3D hap_map_domain_page(page_to_mfn(pg));=0A+ p = =3D __map_domain_page(pg);=0A ASSERT(p !=3D NULL);=0A clear_page(p)= ;=0A hap_unmap_domain_page(p);=0A@@ -293,7 +293,7 @@ static struct = page_info *hap_alloc_p2m_p=0A NULL, MEMF_bits(32) | MEMF_node(d= omain_to_node(d)));=0A if ( likely(pg !=3D NULL) )=0A = {=0A- void *p =3D hap_map_domain_page(page_to_mfn(pg));=0A+ = void *p =3D __map_domain_page(pg);=0A clear_page(p);=0A = hap_unmap_domain_page(p);=0A }=0A--- 2009-09-21.orig/xe= n/arch/x86/mm/p2m.c 2009-09-21 08:39:42.000000000 +0200=0A+++ = 2009-09-21/xen/arch/x86/mm/p2m.c 2009-09-21 11:14:58.000000000 = +0200=0A@@ -200,7 +200,7 @@ p2m_next_level(struct domain *d, mfn_t *=0A = else=0A flags &=3D ~_PAGE_PSE; /* Clear _PAGE_PSE (=3D=3D = _PAGE_PAT) */=0A =0A- l1_entry =3D map_domain_page(mfn_x(pag= e_to_mfn(pg)));=0A+ l1_entry =3D __map_domain_page(pg);=0A = for ( i =3D 0; i < L1_PAGETABLE_ENTRIES; i++ )=0A {=0A = new_entry =3D l1e_from_pfn(pfn + i, flags);=0A--- 2009-09-21.orig/xen/arch/= x86/mm/paging.c 2009-07-14 08:55:23.000000000 +0200=0A+++ 2009-09-21/xen/ar= ch/x86/mm/paging.c 2009-09-21 11:14:58.000000000 +0200=0A@@ -99,7 = +99,6 @@=0A =0A static mfn_t paging_new_log_dirty_page(struct domain *d, = void **mapping_p)=0A {=0A- mfn_t mfn;=0A struct page_info *page;=0A = =0A page =3D alloc_domheap_page(NULL, MEMF_node(domain_to_node(d)));=0A= @@ -110,10 +109,9 @@ static mfn_t paging_new_log_dirty_page(s=0A }=0A = =0A d->arch.paging.log_dirty.allocs++;=0A- mfn =3D page_to_mfn(page)= ;=0A- *mapping_p =3D map_domain_page(mfn_x(mfn));=0A+ *mapping_p =3D = __map_domain_page(page);=0A =0A- return mfn;=0A+ return page_to_mfn(p= age);=0A }=0A =0A static mfn_t paging_new_log_dirty_leaf(=0A--- 2009-09-21.= orig/xen/arch/x86/mm/shadow/common.c 2009-09-21 11:13:02.000000000 = +0200=0A+++ 2009-09-21/xen/arch/x86/mm/shadow/common.c 2009-09-21 = 11:14:58.000000000 +0200=0A@@ -1578,7 +1578,7 @@ mfn_t shadow_alloc(struct = domain *d, =0A flush_tlb_mask(&mask);=0A }=0A = /* Now safe to clear the page for reuse */=0A- p =3D sh_map_domain_p= age(page_to_mfn(sp+i));=0A+ p =3D __map_domain_page(sp+i);=0A = ASSERT(p !=3D NULL);=0A clear_page(p);=0A sh_unmap_domain= _page(p);=0A@@ -3130,7 +3130,7 @@ int shadow_enable(struct domain *d, u32 = =0A }=0A /* Fill it with 32-bit, non-PAE superpage = entries, each mapping 4MB=0A * of virtual address space onto the = same physical address range */ =0A- e =3D sh_map_domain_page(page_to= _mfn(pg));=0A+ e =3D __map_domain_page(pg);=0A for ( i =3D = 0; i < PAGE_SIZE / sizeof(*e); i++ )=0A e[i] =3D ((0x400000U * = i)=0A | _PAGE_PRESENT | _PAGE_RW | _PAGE_USER =0A--- = 2009-09-21.orig/xen/arch/x86/tboot.c 2009-09-21 11:13:02.000000000 = +0200=0A+++ 2009-09-21/xen/arch/x86/tboot.c 2009-09-21 11:14:58.0000000= 00 +0200=0A@@ -205,8 +205,7 @@ static void tboot_gen_domain_integrity(c=0A = =0A page_list_for_each(page, &d->page_list)=0A {=0A- = void *pg;=0A- pg =3D map_domain_page(page_to_mfn(page));=0A= + void *pg =3D __map_domain_page(page);=0A = vmac_update(pg, PAGE_SIZE, &ctx);=0A unmap_domain_page(pg);=0A = }=0A--- 2009-09-21.orig/xen/common/grant_table.c 2009-07-14 = 08:55:23.000000000 +0200=0A+++ 2009-09-21/xen/common/grant_table.c = 2009-09-21 11:14:58.000000000 +0200=0A@@ -1195,7 +1195,7 @@ gnttab_transfer= (=0A }=0A =0A sp =3D map_domain_page(mfn);=0A- = dp =3D map_domain_page(page_to_mfn(new_page));=0A+ dp = =3D __map_domain_page(new_page);=0A memcpy(dp, sp, PAGE_SIZE);= =0A unmap_domain_page(dp);=0A unmap_domain_page(sp)= ;=0A--- 2009-09-21.orig/xen/common/page_alloc.c 2009-09-09 17:57:45.0000000= 00 +0200=0A+++ 2009-09-21/xen/common/page_alloc.c 2009-09-21 = 11:14:58.000000000 +0200=0A@@ -1235,7 +1235,7 @@ __initcall(pagealloc_keyha= ndler_init);=0A =0A void scrub_one_page(struct page_info *pg)=0A {=0A- = void *p =3D map_domain_page(page_to_mfn(pg));=0A+ void *p =3D __map_doma= in_page(pg);=0A =0A #ifndef NDEBUG=0A /* Avoid callers relying on = allocations returning zeroed pages. */=0A--- 2009-09-21.orig/xen/common/tme= m_xen.c 2009-08-17 11:37:45.000000000 +0200=0A+++ 2009-09-21/xen/common/tme= m_xen.c 2009-09-21 11:14:58.000000000 +0200=0A@@ -268,7 +268,7 @@ static = void *tmh_persistent_pool_page_ge=0A if ( (pi =3D _tmh_alloc_page_thisp= ool(d)) =3D=3D NULL )=0A return NULL;=0A ASSERT(IS_VALID_PAGE(p= i));=0A- return map_domain_page(page_to_mfn(pi));=0A+ return = __map_domain_page(pi);=0A }=0A =0A static void tmh_persistent_pool_page_put= (void *page_va)=0A--- 2009-09-21.orig/xen/drivers/passthrough/amd/iommu_map= .c 2009-09-21 08:39:42.000000000 +0200=0A+++ 2009-09-21/xen/drivers/pa= ssthrough/amd/iommu_map.c 2009-09-21 11:14:58.000000000 +0200=0A@@ = -430,7 +430,7 @@ static u64 iommu_l2e_from_pfn(struct pag=0A = (level - IOMMU_PAGING_MODE_LEVEL_1)));=0A offset = &=3D ~PTE_PER_TABLE_MASK;=0A =0A- table_vaddr =3D map_domain_page(pa= ge_to_mfn(table));=0A+ table_vaddr =3D __map_domain_page(table);=0A = pde =3D table_vaddr + (offset * IOMMU_PAGE_TABLE_ENTRY_SIZE);=0A = next_table_maddr =3D amd_iommu_get_next_table_from_pte(pde);=0A = =0A--- 2009-09-21.orig/xen/drivers/passthrough/amd/pci_amd_iommu.c = 2009-09-21 08:39:42.000000000 +0200=0A+++ 2009-09-21/xen/drivers/passthroug= h/amd/pci_amd_iommu.c 2009-09-21 11:14:58.000000000 +0200=0A@@ -335,7 = +335,7 @@ static void deallocate_next_page_table(s=0A u64 next_table_ma= ddr;=0A int index;=0A =0A- table_vaddr =3D map_domain_page(page_to_m= fn(pg));=0A+ table_vaddr =3D __map_domain_page(pg);=0A =0A if ( = level > 1 )=0A {=0A--- 2009-09-21.orig/xen/drivers/passthrough/vtd/iomm= u.c 2009-09-16 08:35:05.000000000 +0200=0A+++ 2009-09-21/xen/drivers/pa= ssthrough/vtd/iommu.c 2009-09-21 11:14:58.000000000 +0200=0A@@ -154,7 = +154,7 @@ u64 alloc_pgtable_maddr(struct acpi_drhd=0A = (node =3D=3D -1 ) ? 0 : MEMF_node(node));=0A if ( !pg )=0A = return 0;=0A- vaddr =3D map_domain_page(page_to_mfn(pg));=0A+ = vaddr =3D __map_domain_page(pg);=0A memset(vaddr, 0, PAGE_SIZE * = npages);=0A =0A iommu_flush_cache_page(vaddr, npages);=0A--- 2009-09-21= .orig/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h 2009-09-21 = 08:39:42.000000000 +0200=0A+++ 2009-09-21/xen/include/asm-x86/hvm/svm/amd-i= ommu-proto.h 2009-09-21 11:14:58.000000000 +0200=0A@@ -131,7 +131,7 @@ = static inline struct page_info* alloc_am=0A pg =3D alloc_domheap_page(N= ULL, 0);=0A if ( pg =3D=3D NULL )=0A return 0;=0A- vaddr = =3D map_domain_page(page_to_mfn(pg));=0A+ vaddr =3D __map_domain_page(pg= );=0A memset(vaddr, 0, PAGE_SIZE);=0A unmap_domain_page(vaddr);=0A = return pg;=0A--- 2009-09-21.orig/xen/include/xen/domain_page.h = 2008-11-05 16:54:22.000000000 +0100=0A+++ 2009-09-21/xen/include/xen/domain= _page.h 2009-09-21 11:14:58.000000000 +0200=0A@@ -34,6 +34,9 @@ void = unmap_domain_page(const void *va);=0A void *map_domain_page_global(unsigned= long mfn);=0A void unmap_domain_page_global(const void *va);=0A =0A+#defin= e __map_domain_page(pg) map_domain_page(__page_to_mfn(pg))=0A+#defin= e __map_domain_page_global(pg) map_domain_page_global(__page_to_mfn(pg))=0A= +=0A #define DMCACHE_ENTRY_VALID 1U=0A #define DMCACHE_ENTRY_HELD 2U=0A = =0A@@ -97,9 +100,11 @@ domain_mmap_cache_destroy(struct domain_=0A #else = /* !CONFIG_DOMAIN_PAGE */=0A =0A #define map_domain_page(mfn) = mfn_to_virt(mfn)=0A+#define __map_domain_page(pg) = page_to_virt(pg)=0A #define unmap_domain_page(va) ((void)(va)= )=0A =0A #define map_domain_page_global(mfn) mfn_to_virt(mfn)=0A+#d= efine __map_domain_page_global(pg) page_to_virt(pg)=0A #define = unmap_domain_page_global(va) ((void)(va))=0A =0A struct domain_mmap_= cache { =0A --=__Part755E858B.0__= Content-Type: text/plain; name="xen-fold-discontig-mem-CSE.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-fold-discontig-mem-CSE.patch" The grant table code had some particularly frequent repetitions of=0Amfn_to= _page() on each time the same input arguments. To help the=0Acompiler = (which can do only a limited job on CSE), this adds explicit=0Acaching of = the transformation result in a few places.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- 2009-09-10.orig/xen/common/grant_table.c = 2009-09-10 15:27:52.000000000 +0200=0A+++ 2009-09-10/xen/common/grant_table= .c 2009-09-10 17:19:24.000000000 +0200=0A@@ -198,6 +198,7 @@ = __gnttab_map_grant_ref(=0A struct vcpu *led;=0A int = handle;=0A unsigned long frame =3D 0, nr_gets =3D 0;=0A+ struct = page_info *pg;=0A int rc =3D GNTST_okay;=0A u32 = old_pin;=0A u32 act_pin;=0A@@ -346,12 +347,13 @@ = __gnttab_map_grant_ref(=0A =0A spin_unlock(&rd->grant_table->lock);=0A = =0A- if ( !mfn_valid(frame) ||=0A- (owner =3D page_get_owner_and= _reference(mfn_to_page(frame))) =3D=3D dom_io )=0A+ pg =3D mfn_valid(fra= me) ? mfn_to_page(frame) : NULL;=0A+=0A+ if ( !pg || (owner =3D = page_get_owner_and_reference(pg)) =3D=3D dom_io )=0A {=0A /* = Only needed the reference to confirm dom_io ownership. */=0A- if ( = mfn_valid(frame) )=0A- put_page(mfn_to_page(frame));=0A+ = if ( pg )=0A+ put_page(pg);=0A =0A if ( paging_mode_exte= rnal(ld) )=0A {=0A@@ -377,7 +379,7 @@ __gnttab_map_grant_ref(=0A = else if ( owner =3D=3D rd )=0A {=0A if ( gnttab_host_mapping_= get_page_type(op, ld, rd) &&=0A- !get_page_type(mfn_to_page(fra= me), PGT_writable_page) )=0A+ !get_page_type(pg, PGT_writable_p= age) )=0A goto could_not_pin;=0A =0A nr_gets++;=0A@@ = -390,9 +392,9 @@ __gnttab_map_grant_ref(=0A if ( op->flags & = GNTMAP_device_map )=0A {=0A nr_gets++;=0A- = (void)get_page(mfn_to_page(frame), rd);=0A+ = (void)get_page(pg, rd);=0A if ( !(op->flags & GNTMAP_readon= ly) )=0A- get_page_type(mfn_to_page(frame), PGT_writable= _page);=0A+ get_page_type(pg, PGT_writable_page);=0A = }=0A }=0A }=0A@@ -403,7 +405,7 @@ __gnttab_map_grant_r= ef(=0A gdprintk(XENLOG_WARNING, "Could not pin grant frame = %lx\n",=0A frame);=0A if ( owner !=3D NULL = )=0A- put_page(mfn_to_page(frame));=0A+ put_page(pg);= =0A rc =3D GNTST_general_error;=0A goto undo_out;=0A = }=0A@@ -442,14 +444,14 @@ __gnttab_map_grant_ref(=0A if ( nr_gets > 1 = )=0A {=0A if ( !(op->flags & GNTMAP_readonly) )=0A- = put_page_type(mfn_to_page(frame));=0A- put_page(mfn_to_page(frame));= =0A+ put_page_type(pg);=0A+ put_page(pg);=0A }=0A = if ( nr_gets > 0 )=0A {=0A if ( gnttab_host_mapping_get_page_t= ype(op, ld, rd) )=0A- put_page_type(mfn_to_page(frame));=0A- = put_page(mfn_to_page(frame));=0A+ put_page_type(pg);=0A+ = put_page(pg);=0A }=0A =0A spin_lock(&rd->grant_table->lock);=0A= @@ -621,6 +623,7 @@ __gnttab_unmap_common_complete(struct gn=0A struct = domain *ld, *rd;=0A struct active_grant_entry *act;=0A grant_entr= y_t *sha;=0A+ struct page_info *pg;=0A =0A rd =3D op->rd;=0A = =0A@@ -651,14 +654,16 @@ __gnttab_unmap_common_complete(struct gn=0A = goto unmap_out;=0A }=0A =0A+ pg =3D mfn_to_page(op->frame);=0A+=0A= if ( op->flags & GNTMAP_device_map ) =0A {=0A if ( = !is_iomem_page(act->frame) )=0A {=0A if ( op->flags & = GNTMAP_readonly )=0A- put_page(mfn_to_page(op->frame));=0A+ = put_page(pg);=0A else=0A- = put_page_and_type(mfn_to_page(op->frame));=0A+ put_page_and_= type(pg);=0A }=0A }=0A =0A@@ -676,8 +681,8 @@ __gnttab_unmap_co= mmon_complete(struct gn=0A if ( !is_iomem_page(op->frame) ) =0A = {=0A if ( gnttab_host_mapping_get_page_type(op, ld, rd) = )=0A- put_page_type(mfn_to_page(op->frame));=0A- = put_page(mfn_to_page(op->frame));=0A+ put_page_type(pg);=0A+= put_page(pg);=0A }=0A }=0A =0A@@ -1745,6 +1750,7 = @@ gnttab_release_mappings(=0A struct domain *rd;=0A struct = active_grant_entry *act;=0A struct grant_entry *sha;=0A+ struct = page_info *pg;=0A =0A BUG_ON(!d->is_dying);=0A =0A@@ -1772,6 = +1778,7 @@ gnttab_release_mappings(=0A =0A act =3D &active_entry(rd= ->grant_table, ref);=0A sha =3D &shared_entry(rd->grant_table, = ref);=0A+ pg =3D mfn_to_page(act->frame);=0A =0A if ( = map->flags & GNTMAP_readonly )=0A {=0A@@ -1780,7 +1787,7 @@ = gnttab_release_mappings(=0A BUG_ON(!(act->pin & GNTPIN_devr= _mask));=0A act->pin -=3D GNTPIN_devr_inc;=0A = if ( !is_iomem_page(act->frame) )=0A- put_page(mfn_to= _page(act->frame));=0A+ put_page(pg);=0A = }=0A =0A if ( map->flags & GNTMAP_host_map )=0A@@ -1789,7 = +1796,7 @@ gnttab_release_mappings(=0A act->pin -=3D = GNTPIN_hstr_inc;=0A if ( gnttab_release_host_mappings(d) = &&=0A !is_iomem_page(act->frame) )=0A- = put_page(mfn_to_page(act->frame));=0A+ put_page(pg);= =0A }=0A }=0A else=0A@@ -1799,7 +1806,7 @@ = gnttab_release_mappings(=0A BUG_ON(!(act->pin & GNTPIN_devw= _mask));=0A act->pin -=3D GNTPIN_devw_inc;=0A = if ( !is_iomem_page(act->frame) )=0A- put_page_and_ty= pe(mfn_to_page(act->frame));=0A+ put_page_and_type(pg);= =0A }=0A =0A if ( map->flags & GNTMAP_host_map = )=0A@@ -1810,8 +1817,8 @@ gnttab_release_mappings(=0A = !is_iomem_page(act->frame) )=0A {=0A = if ( gnttab_host_mapping_get_page_type(map, d, rd) )=0A- = put_page_type(mfn_to_page(act->frame));=0A- = put_page(mfn_to_page(act->frame));=0A+ put_page_type= (pg);=0A+ put_page(pg);=0A }=0A = }=0A =0A --=__Part755E858B.0__= Content-Type: text/plain; name="xen-write-once.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-write-once.patch" This one is likely the most questionable part: Realizing that the=0Acompile= r can do a much better job in terms of CSE when the variables=0Aneeded are = constant, this introduces and extension to the read-mostly=0Avariables, = allowing variables to be marked as being written just=0Aduring boot = initialization.=0A=0AThere is, however, quite a bit of care required, as = it must be ensured=0Athat the compiler will never mix uses of the "real" = and the "aliased"=0Avariable within a function, and that the compiler = never cache the=0Acontents of the read-only representation across those = function calls=0Athat lead to initialization through the writable = representation.=0A=0AThe concept therefore is to have two mechanisms for = initialization:=0AEither through marking a whole translation unit as being = initialization=0Aonly (and hence only ever seeing the writable representati= on), or by=0Amaking sure that in a particular initialization function it = is only the=0Awritable representation that gets accessed (even when = wanting to read=0Aits value). For that latter method, I wasn't able to = think of a=0Amechanism which would enforce this, which is the reason for = the need to=0Abe really careful.=0A=0AThe benefit of the whole contruct is = that for some of the converted=0Avariables the number of accesses to these = variables goes down by over=0A50%, including cases where entire inline = function expansions (accessing=0Aseveral of these variables) can be = eliminated by CSE.=0A=0ASigned-off-by: Jan Beulich =0A= =0A--- 2009-09-10.orig/xen/arch/x86/mm.c 2009-09-17 12:08:27.0000000= 00 +0200=0A+++ 2009-09-10/xen/arch/x86/mm.c 2009-09-17 14:37:46.0000000= 00 +0200=0A@@ -138,12 +138,12 @@ l1_pgentry_t __attribute__ ((__section__= =0A struct domain *dom_xen, *dom_io;=0A =0A /* Frame table size in pages. = */=0A-unsigned long max_page;=0A-unsigned long total_pages;=0A+DEFINE_WRITE= _ONCE(unsigned long, max_page, 0);=0A+DEFINE_WRITE_ONCE(unsigned long, = total_pages, 0);=0A =0A-unsigned long __read_mostly pdx_group_valid[BITS_TO= _LONGS(=0A+DEFINE_WRITE_ONCE(unsigned long[BITS_TO_LONGS(=0A (FRAMETABL= E_SIZE / sizeof(*frame_table) + PDX_GROUP_COUNT - 1)=0A- / PDX_GROUP_COU= NT)] =3D { [0] =3D 1 };=0A+ / PDX_GROUP_COUNT)], pdx_group_valid, { [0] = =3D 1 });=0A =0A #define PAGE_CACHE_ATTRS (_PAGE_PAT|_PAGE_PCD|_PAGE_PWT)= =0A =0A--- 2009-09-10.orig/xen/arch/x86/setup.c 2009-09-17 12:05:47.0000000= 00 +0200=0A+++ 2009-09-10/xen/arch/x86/setup.c 2009-09-17 13:51:21.0000000= 00 +0200=0A@@ -1,3 +1,4 @@=0A+#include =0A #include = =0A #include =0A #include =0A--- = 2009-09-10.orig/xen/arch/x86/x86_64/mm.c 2009-09-17 15:54:05.0000000= 00 +0200=0A+++ 2009-09-10/xen/arch/x86/x86_64/mm.c 2009-09-17 = 16:17:23.000000000 +0200=0A@@ -34,13 +34,13 @@=0A #include =0A =0A /* Parameters for PFN/MADDR compression. */=0A-unsigned long = __read_mostly max_pdx;=0A-unsigned long __read_mostly pfn_pdx_bottom_mask = =3D ~0UL;=0A-unsigned long __read_mostly ma_va_bottom_mask =3D ~0UL;=0A-uns= igned long __read_mostly pfn_top_mask =3D 0;=0A-unsigned long __read_mostly= ma_top_mask =3D 0;=0A-unsigned long __read_mostly pfn_hole_mask =3D = 0;=0A-unsigned int __read_mostly pfn_pdx_hole_shift =3D 0;=0A+DEFINE_WRITE_= ONCE(unsigned long, max_pdx, 0);=0A+DEFINE_WRITE_ONCE(unsigned long, = pfn_pdx_bottom_mask, ~0UL);=0A+DEFINE_WRITE_ONCE(unsigned long, ma_va_botto= m_mask, ~0UL);=0A+DEFINE_WRITE_ONCE(unsigned long, pfn_top_mask, 0);=0A+DEF= INE_WRITE_ONCE(unsigned long, ma_top_mask, 0);=0A+DEFINE_WRITE_ONCE(unsigne= d long, pfn_hole_mask, 0);=0A+DEFINE_WRITE_ONCE(unsigned int, pfn_pdx_hole_= shift, 0);=0A =0A #ifdef CONFIG_COMPAT=0A unsigned int m2p_compat_vstart = =3D __HYPERVISOR_COMPAT_VIRT_START;=0A@@ -183,12 +183,14 @@ void __init = pfn_pdx_hole_setup(unsigned =0A printk(KERN_INFO "PFN compression on = bits %u...%u\n",=0A bottom_shift, bottom_shift + hole_shift - = 1);=0A =0A- pfn_pdx_hole_shift =3D hole_shift;=0A- pfn_pdx_bottom_ma= sk =3D (1UL << bottom_shift) - 1;=0A- ma_va_bottom_mask =3D (PAGE_SIZE= << bottom_shift) - 1;=0A- pfn_hole_mask =3D ((1UL << hole_shift) = - 1) << bottom_shift;=0A- pfn_top_mask =3D ~(pfn_pdx_bottom_mask = | pfn_hole_mask);=0A- ma_top_mask =3D pfn_top_mask << PAGE_SHIFT= ;=0A+ write_once(pfn_pdx_hole_shift) =3D hole_shift;=0A+ write_once(= pfn_pdx_bottom_mask) =3D (1UL << bottom_shift) - 1;=0A+ write_once(ma_va= _bottom_mask) =3D (PAGE_SIZE << bottom_shift) - 1;=0A+ write_once(pfn_= hole_mask) =3D ((1UL << hole_shift) - 1)=0A+ = << bottom_shift;=0A+ write_once(pfn_top_mask) =3D = ~(write_once(pfn_pdx_bottom_mask)=0A+ = | write_once(pfn_hole_mask));=0A+ write_once(ma_top_mask) =3D = write_once(pfn_top_mask) << PAGE_SHIFT;=0A }=0A =0A void __init paging_init= (void)=0A--- 2009-09-10.orig/xen/arch/x86/xen.lds.S 2009-09-17 = 16:14:56.000000000 +0200=0A+++ 2009-09-10/xen/arch/x86/xen.lds.S = 2009-09-17 14:38:19.000000000 +0200=0A@@ -59,6 +59,7 @@ SECTIONS=0A =0A = . =3D ALIGN(128);=0A .data.read_mostly : {=0A+ *(.data.write_once)= =0A *(.data.read_mostly)=0A } :text=0A =0A--- 2009-09-10.orig/xen/= include/asm-x86/mm.h 2009-09-17 15:35:03.000000000 +0200=0A+++ = 2009-09-10/xen/include/asm-x86/mm.h 2009-09-17 15:36:21.000000000 = +0200=0A@@ -4,6 +4,7 @@=0A =0A #include =0A #include = =0A+#include =0A #include =0A = #include =0A =0A@@ -259,13 +260,13 @@ extern void share_xen_= page_with_privileg=0A struct page_info *page, int readonly);=0A =0A = #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)=0A-extern = unsigned long max_page;=0A-extern unsigned long total_pages;=0A+extern = DECLARE_WRITE_ONCE(unsigned long, max_page);=0A+extern DECLARE_WRITE_ONCE(u= nsigned long, total_pages);=0A void init_frametable(void);=0A =0A #define = PDX_GROUP_COUNT ((1 << L2_PAGETABLE_SHIFT) / \=0A = (sizeof(*frame_table) & -sizeof(*frame_table)))=0A-extern unsigned long = pdx_group_valid[];=0A+extern DECLARE_WRITE_ONCE(unsigned long[], pdx_group_= valid);=0A =0A /* Convert between Xen-heap virtual addresses and page-info = structures. */=0A static inline struct page_info *__virt_to_page(const = void *v)=0A--- 2009-09-10.orig/xen/include/asm-x86/x86_64/page.h = 2009-09-17 15:31:15.000000000 +0200=0A+++ 2009-09-10/xen/include/asm-x86/x8= 6_64/page.h 2009-09-17 15:37:28.000000000 +0200=0A@@ -30,16 +30,19 = @@=0A #ifndef __ASSEMBLY__=0A =0A #include =0A+#include = =0A #include =0A =0A /* Physical address = where Xen was relocated to. */=0A extern unsigned long xen_phys_start;=0A = =0A-extern unsigned long max_pdx;=0A-extern unsigned long pfn_pdx_bottom_ma= sk, ma_va_bottom_mask;=0A-extern unsigned int pfn_pdx_hole_shift;=0A-extern= unsigned long pfn_hole_mask;=0A-extern unsigned long pfn_top_mask, = ma_top_mask;=0A+extern DECLARE_WRITE_ONCE(unsigned long, max_pdx);=0A+exter= n DECLARE_WRITE_ONCE(unsigned long, pfn_pdx_bottom_mask);=0A+extern = DECLARE_WRITE_ONCE(unsigned long, ma_va_bottom_mask);=0A+extern DECLARE_WRI= TE_ONCE(unsigned int, pfn_pdx_hole_shift);=0A+extern DECLARE_WRITE_ONCE(uns= igned long, pfn_hole_mask);=0A+extern DECLARE_WRITE_ONCE(unsigned long, = pfn_top_mask);=0A+extern DECLARE_WRITE_ONCE(unsigned long, ma_top_mask);=0A= extern void pfn_pdx_hole_setup(unsigned long);=0A =0A #define page_to_pdx(= pg) ((pg) - frame_table)=0A@@ -53,7 +56,7 @@ extern void pfn_pdx_hole_setu= p(unsigned =0A #define pdx_to_virt(pdx) ((void *)(DIRECTMAP_VIRT_START + = \=0A ((unsigned long)(pdx) << PAGE_SHIFT= )))=0A =0A-extern int __mfn_valid(unsigned long mfn);=0A+extern __attribute= _write_once__ int __mfn_valid(unsigned long mfn);=0A =0A static inline = unsigned long pfn_to_pdx(unsigned long pfn)=0A {=0A--- /dev/null = 1970-01-01 00:00:00.000000000 +0000=0A+++ 2009-09-10/xen/include/xen/no-wri= te-once.h 2009-09-17 15:18:29.000000000 +0200=0A@@ -0,0 +1,11 = @@=0A+#ifdef __XEN_WRITE_ONCE_H__=0A+#error Must not include xen/no-write-o= nce.h after xen/write-once.h.=0A+#endif=0A+#ifndef __XEN_NO_WRITE_ONCE_H__= =0A+#define __XEN_NO_WRITE_ONCE_H__=0A+=0A+#define DECLARE_WRITE_ONCE(type,= name) __typeof__(type) name=0A+=0A+#define __attribute_write_once__=0A+=0A= +#endif /* __XEN_NO_WRITE_ONCE_H__ */=0A--- /dev/null 1970-01-01 = 00:00:00.000000000 +0000=0A+++ 2009-09-10/xen/include/xen/write-once.h = 2009-09-17 16:12:21.000000000 +0200=0A@@ -0,0 +1,15 @@=0A+#if !defined(__XE= N_WRITE_ONCE_H__) && !defined(__XEN_NO_WRITE_ONCE_H__)=0A+#define = __XEN_WRITE_ONCE_H__=0A+=0A+#define DECLARE_WRITE_ONCE(type, name) const = __typeof__(type) name=0A+=0A+#define DEFINE_WRITE_ONCE(type, name, ...) = static __typeof__(type) \=0A+ __attribute_used__ __attribute__((__sectio= n__(".data.write_once"))) \=0A+ __write_once_##name __asm__(#name) =3D = __VA_ARGS__; \=0A+ __asm__(".globl " #name)=0A+=0A+#define write_once(na= me) __write_once_##name=0A+=0A+#define __attribute_write_once__ __attribute= _const__=0A+=0A+#endif /* __XEN_WRITE_ONCE_H__ */=0A --=__Part755E858B.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 --=__Part755E858B.0__=--