Skip to contentSkip to conversation

x86/32on64: fix physical address restriction

PATCH In review Jan Beulich 2 participants 3 messages Jun 12, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/32on64: fix physical address restriction

The allocation bit size setting wasn't working anymore after the recent fix to properly use PAGE_SHIFT instead of PAGE_SIZE. This was because the bit size implies a power-of-two range that's accessible, but if all memory is accessible anyway (and its upper boundary is not a power of two), the domain would either be needlessly restricted or wouldn't be able to allocate as much memory as was intended for it (specifically the case for Dom0 without dom0_mem= boot parameter). Consequently, don't restrict the bit width if all memory can be accessed.

To avoid needing to adjust this code in two places in the future (it may need further touching when memory hotplug gets supported), fold the logic into a function.

xen/arch/x86/domain.c +1 -5
Index: 2008-06-12/xen/arch/x86/domain.c
===================================================================
@@ -349,11 +349,7 @@ int switch_compat(struct domain *d)
                                  FIRST_RESERVED_GDT_PAGE)] = gdt_l1e;
     }
 
-    d->arch.physaddr_bitsize =
-        /* 2^n entries can be contained in guest's p2m mapping space */
-        fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
-        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
-        + PAGE_SHIFT;
+    domain_set_alloc_bitsize(d);
 
     return 0;
 
xen/arch/x86/domain_build.c +1 -8
Index: 2008-06-12/xen/arch/x86/domain_build.c
===================================================================
@@ -353,14 +353,7 @@ int __init construct_dom0(
 #endif
     }
 
-#if defined(__x86_64__)
-    if ( is_pv_32on64_domain(d) )
-        d->arch.physaddr_bitsize =
-            /* 2^n entries can be contained in guest's p2m mapping space */
-            fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
-            /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
-            + PAGE_SHIFT;
-#endif
+    domain_set_alloc_bitsize(d);
 
     /*
      * Why do we need this? The number of page-table frames depends on the 
xen/arch/x86/x86_64/mm.c +13 -1
Index: 2008-06-12/xen/arch/x86/x86_64/mm.c
===================================================================
@@ -470,9 +470,21 @@ int check_descriptor(const struct domain
     return 0;
 }
 
+void domain_set_alloc_bitsize(struct domain *d)
+{
+    if ( !is_pv_32on64_domain(d)
+         || HYPERVISOR_COMPAT_VIRT_START(d) > __HYPERVISOR_COMPAT_VIRT_START )
+        return;
+    d->arch.physaddr_bitsize =
+        /* 2^n entries can be contained in guest's p2m mapping space */
+        fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
+        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
+        + PAGE_SHIFT;
+}
+
 unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits)
 {
-    if ( (d == NULL) || !is_pv_32on64_domain(d) )
+    if ( d == NULL || d->arch.physaddr_bitsize == 0 )
         return bits;
     return min(d->arch.physaddr_bitsize, bits);
 }
xen/include/asm-x86/mm.h +2 -0
Index: 2008-06-12/xen/include/asm-x86/mm.h
===================================================================
@@ -343,9 +343,11 @@ int map_ldt_shadow_page(unsigned int);
 
 #ifdef CONFIG_COMPAT
 int setup_arg_xlat_area(struct vcpu *, l4_pgentry_t *);
+void domain_set_alloc_bitsize(struct domain *d);
 unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
 #else
 # define setup_arg_xlat_area(vcpu, l4tab) 0
+# define domain_set_alloc_bitsize(d) ((void)0)
 # define domain_clamp_alloc_bitsize(d, b) (b)
 #endif
 
#1 lore raw

I tweaked this before checking in as c/s 17836. Please take a look and see whether it looks okay to you. If so I'll also backport to xen-3.2-testing.

-- Keir

Quoted 107 lines · Jan Beulich

The allocation bit size setting wasn't working anymore after the recent fix to properly use PAGE_SHIFT instead of PAGE_SIZE. This was because the bit size implies a power-of-two range that's accessible, but if all memory is accessible anyway (and its upper boundary is not a power of two), the domain would either be needlessly restricted or wouldn't be able to allocate as much memory as was intended for it (specifically the case for Dom0 without dom0_mem= boot parameter). Consequently, don't restrict the bit width if all memory can be accessed.

To avoid needing to adjust this code in two places in the future (it may need further touching when memory hotplug gets supported), fold the logic into a function.

Index: 2008-06-12/xen/arch/x86/domain.c
===================================================================

xen/arch/x86/domain.c 2008-06-12 09:07:02.000000000 +0200 renamed from xen/arch/x86/domain.c 2008-06-12 09:02:00.000000000 +0200 +1 -5
@@ -349,11 +349,7 @@ int switch_compat(struct domain *d)
                                  FIRST_RESERVED_GDT_PAGE)] = gdt_l1e;
     }
 
-    d->arch.physaddr_bitsize =
-        /* 2^n entries can be contained in guest's p2m mapping space */
-        fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
-        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
-        + PAGE_SHIFT;
+    domain_set_alloc_bitsize(d);
 
     return 0;
 

Index: 2008-06-12/xen/arch/x86/domain_build.c
===================================================================
--- 2008-06-12.orig/xen/arch/x86/domain_build.c 2008-06-10 18:00:41.000000000 +0200
+++ 2008-06-12/xen/arch/x86/domain_build.c 2008-06-12 09:08:19.000000000 +0200

xen/arch/x86/domain.c 2008-06-12 09:07:02.000000000 +0200 renamed from xen/arch/x86/domain.c 2008-06-12 09:02:00.000000000 +0200 +1 -8
@@ -353,14 +353,7 @@ int __init construct_dom0(
 #endif
     }
 
-#if defined(__x86_64__)
-    if ( is_pv_32on64_domain(d) )
-        d->arch.physaddr_bitsize =
-            /* 2^n entries can be contained in guest's p2m mapping space */
-            fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
-            /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
-            + PAGE_SHIFT;
-#endif
+    domain_set_alloc_bitsize(d);
 
     /*
      * Why do we need this? The number of page-table frames depends on the

Index: 2008-06-12/xen/arch/x86/x86_64/mm.c
===================================================================
--- 2008-06-12.orig/xen/arch/x86/x86_64/mm.c 2008-06-10 18:00:41.000000000 +0200
+++ 2008-06-12/xen/arch/x86/x86_64/mm.c 2008-06-12 09:07:42.000000000 +0200

xen/arch/x86/domain.c 2008-06-12 09:07:02.000000000 +0200 renamed from xen/arch/x86/domain.c 2008-06-12 09:02:00.000000000 +0200 +13 -1
@@ -470,9 +470,21 @@ int check_descriptor(const struct domain
     return 0;
 }
 
+void domain_set_alloc_bitsize(struct domain *d)
+{
+    if ( !is_pv_32on64_domain(d)
+         || HYPERVISOR_COMPAT_VIRT_START(d) > __HYPERVISOR_COMPAT_VIRT_START
 )
+        return;
+    d->arch.physaddr_bitsize =
+        /* 2^n entries can be contained in guest's p2m mapping space */
+        fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
+        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
+        + PAGE_SHIFT;
+}
+
 unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits)
 {
-    if ( (d == NULL) || !is_pv_32on64_domain(d) )
+    if ( d == NULL || d->arch.physaddr_bitsize == 0 )
         return bits;
     return min(d->arch.physaddr_bitsize, bits);

}
Index: 2008-06-12/xen/include/asm-x86/mm.h
===================================================================
--- 2008-06-12.orig/xen/include/asm-x86/mm.h 2008-05-09 09:48:32.000000000 +0200
+++ 2008-06-12/xen/include/asm-x86/mm.h 2008-06-12 09:06:20.000000000 +0200

xen/arch/x86/domain.c 2008-06-12 09:07:02.000000000 +0200 renamed from xen/arch/x86/domain.c 2008-06-12 09:02:00.000000000 +0200 +2 -0
@@ -343,9 +343,11 @@ int map_ldt_shadow_page(unsigned int);
 
 #ifdef CONFIG_COMPAT
 int setup_arg_xlat_area(struct vcpu *, l4_pgentry_t *);
+void domain_set_alloc_bitsize(struct domain *d);
 unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
 #else
 # define setup_arg_xlat_area(vcpu, l4tab) 0
+# define domain_set_alloc_bitsize(d) ((void)0)
 # define domain_clamp_alloc_bitsize(d, b) (b)
 #endif
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

Re: [PATCH] x86/32on64: fix physical addressrestriction

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 12.06.08 17:06 >>>

I tweaked this before checking in as c/s 17836. Please take a look and see whether it looks okay to you. If so I'll also backport to xen-3.2-testing.

Looks good - even better, because the calculation is now more correct - I hadn't realized so far that the old calculation didn't account for the 2M hole right below 4G.

Jan