Skip to contentSkip to conversation

xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround

PATCH Applied Julien Grall 2 participants 5 messages Oct 22, 2013 – Oct 24, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround

On Linux, the option CONFIG_ARM_PATCH_PHYS_VIRT (by default enabled) allows the Kernel to be loaded anywhere (or nearly) by patching the translation pv<->virt at boot time.

The current solution in Linux assuming that the delta physical address - virtual address is always negative. A positive delta will destroy all the optimisation to modify only a part of the translation instruction (add/sub).

By default, Xen is allocating memory from the top of memory and then goes down. To avoid booting issue with Linux, we must allocate memory from the bottom (ie starting from 0).

---
 xen/arch/arm/domain_build.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +9 -2
index 0698f83..69ea6a0 100644
@@ -70,12 +70,19 @@ static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo,
     int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
     paddr_t start;
     paddr_t size;
-    struct page_info *pg;
+    struct page_info *pg = NULL;
     unsigned int order = get_order_from_bytes(dom0_mem);
     int res;
     paddr_t spfn;
+    unsigned int bits;
+
+    for ( bits = PAGE_SHIFT + 1; bits < PADDR_BITS; bits++ )
+    {
+        pg = alloc_domheap_pages(d, order, MEMF_bits(bits));
+        if ( pg != NULL )
+            break;
+    }
 
-    pg = alloc_domheap_pages(d, order, 0);
     if ( !pg )
         panic("Failed to allocate contiguous memory for dom0\n");
 
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Julien Grall

On Linux, the option CONFIG_ARM_PATCH_PHYS_VIRT (by default enabled) allows the Kernel to be loaded anywhere (or nearly) by patching the translation pv<->virt at boot time.

The current solution in Linux assuming that the delta physical address - virtual address is always negative. A positive delta will destroy all the optimisation to modify only a part of the translation instruction (add/sub).

Quoted 5 lines

By default, Xen is allocating memory from the top of memory and then goes down. To avoid booting issue with Linux, we must allocate memory from the bottom (ie starting from 0).

OOI how low does the memory get allocated in practice? We deliberately load Xen and place xenheap up high so I guess for dom0 we can't get memory from pretty low down?

Quoted 30 lines
---
 xen/arch/arm/domain_build.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +9 -2
index 0698f83..69ea6a0 100644
@@ -70,12 +70,19 @@ static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo,
     int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
     paddr_t start;
     paddr_t size;
-    struct page_info *pg;
+    struct page_info *pg = NULL;
     unsigned int order = get_order_from_bytes(dom0_mem);
     int res;
     paddr_t spfn;
+    unsigned int bits;
+
+    for ( bits = PAGE_SHIFT + 1; bits < PADDR_BITS; bits++ )
+    {
+        pg = alloc_domheap_pages(d, order, MEMF_bits(bits));
+        if ( pg != NULL )
+            break;
+    }
 
-    pg = alloc_domheap_pages(d, order, 0);
     if ( !pg )
         panic("Failed to allocate contiguous memory for dom0\n");
 
#2 lore raw
Quoted 13 lines · Ian Campbell
Quoted 12 lines · Julien Grall

On Linux, the option CONFIG_ARM_PATCH_PHYS_VIRT (by default enabled) allows the Kernel to be loaded anywhere (or nearly) by patching the translation pv<->virt at boot time.

The current solution in Linux assuming that the delta physical address - virtual address is always negative. A positive delta will destroy all the optimisation to modify only a part of the translation instruction (add/sub).

By default, Xen is allocating memory from the top of memory and then goes down. To avoid booting issue with Linux, we must allocate memory from the bottom (ie starting from 0).

Quoted 7 lines
Quoted 1 line

OOI how low does the memory get allocated in practice? We deliberately load Xen and place xenheap up high so I guess for dom0 we can't get memory from pretty low down?

It depends where U-boot has loaded the different modules (kernel, initrd, device tree,...).
If they are not loaded at the bottom of the RAM, Xen is able to use the first address of the first bank.

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 18 lines · Julien Grall
Quoted 17 lines · Ian Campbell
Quoted 8 lines · Julien Grall

On Linux, the option CONFIG_ARM_PATCH_PHYS_VIRT (by default enabled) allows the Kernel to be loaded anywhere (or nearly) by patching the translation pv<->virt at boot time.

The current solution in Linux assuming that the delta physical address - virtual address is always negative. A positive delta will destroy all the optimisation to modify only a part of the translation instruction (add/sub).

Quoted 5 lines

By default, Xen is allocating memory from the top of memory and then goes down. To avoid booting issue with Linux, we must allocate memory from the bottom (ie starting from 0).

Quoted 8 lines
Quoted 3 lines

OOI how low does the memory get allocated in practice? We deliberately load Xen and place xenheap up high so I guess for dom0 we can't get memory from pretty low down?

It depends where U-boot has loaded the different modules (kernel, initrd, device tree,...).
If they are not loaded at the bottom of the RAM, Xen is able to use the first address of the first bank.

Great! That's what I was hoping.

Thanks,
Ian.

Applied
#4 lore raw
In reply to Ian Campbell
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Julien Grall

On Linux, the option CONFIG_ARM_PATCH_PHYS_VIRT (by default enabled) allows the Kernel to be loaded anywhere (or nearly) by patching the translation pv<->virt at boot time.

The current solution in Linux assuming that the delta physical address - virtual address is always negative. A positive delta will destroy all the optimisation to modify only a part of the translation instruction (add/sub).

Quoted 7 lines
Quoted 5 lines

By default, Xen is allocating memory from the top of memory and then goes down. To avoid booting issue with Linux, we must allocate memory from the bottom (ie starting from 0).

Applied.