xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
@ 2013-10-22 10:51 Julien Grall
  2013-10-22 11:26 ` Ian Campbell
  0 siblings, 1 reply; 5+ messages in thread
From: Julien Grall @ 2013-10-22 10:51 UTC (permalink / raw)
  To: xen-devel; +Cc: stefano.stabellini, tim, ian.campbell, Julien Grall, patches

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).

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/domain_build.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 0698f83..69ea6a0 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -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");
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
  2013-10-22 10:51 [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround Julien Grall
@ 2013-10-22 11:26 ` Ian Campbell
  2013-10-22 13:58   ` Julien Grall
  2013-10-24 14:05   ` Ian Campbell
  0 siblings, 2 replies; 5+ messages in thread
From: Ian Campbell @ 2013-10-22 11:26 UTC (permalink / raw)
  To: Julien Grall; +Cc: patches, tim, stefano.stabellini, xen-devel

On Tue, 2013-10-22 at 11:51 +0100, Julien Grall wrote:
> 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).
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

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?

> ---
>  xen/arch/arm/domain_build.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 0698f83..69ea6a0 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -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");
>  

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
  2013-10-22 11:26 ` Ian Campbell
@ 2013-10-22 13:58   ` Julien Grall
  2013-10-22 14:01     ` Ian Campbell
  2013-10-24 14:05   ` Ian Campbell
  1 sibling, 1 reply; 5+ messages in thread
From: Julien Grall @ 2013-10-22 13:58 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Patch Tracking, tim, Stefano Stabellini, xen-devel@lists.xen.org

On 22 October 2013 12:26, Ian Campbell <ian.campbell@citrix.com> wrote:
> On Tue, 2013-10-22 at 11:51 +0100, Julien Grall wrote:
>> 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).
>>
>> Signed-off-by: Julien Grall <julien.grall@linaro.org>
>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>
>
> 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.

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
  2013-10-22 13:58   ` Julien Grall
@ 2013-10-22 14:01     ` Ian Campbell
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Campbell @ 2013-10-22 14:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel@lists.xen.org, Stefano Stabellini, tim, Patch Tracking

On Tue, 2013-10-22 at 14:58 +0100, Julien Grall wrote:
> On 22 October 2013 12:26, Ian Campbell <ian.campbell@citrix.com> wrote:
> > On Tue, 2013-10-22 at 11:51 +0100, Julien Grall wrote:
> >> 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).
> >>
> >> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> >
> > Acked-by: Ian Campbell <ian.campbell@citrix.com>
> >
> > 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround
  2013-10-22 11:26 ` Ian Campbell
  2013-10-22 13:58   ` Julien Grall
@ 2013-10-24 14:05   ` Ian Campbell
  1 sibling, 0 replies; 5+ messages in thread
From: Ian Campbell @ 2013-10-24 14:05 UTC (permalink / raw)
  To: Julien Grall; +Cc: xen-devel, stefano.stabellini, tim, patches

On Tue, 2013-10-22 at 12:26 +0100, Ian Campbell wrote:
> On Tue, 2013-10-22 at 11:51 +0100, Julien Grall wrote:
> > 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).
> > 
> > Signed-off-by: Julien Grall <julien.grall@linaro.org>
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

Applied.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-24 14:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-22 10:51 [PATCH] xen/arm: Allocate memory for dom0 from the bottom with the 1:1 Workaround Julien Grall
2013-10-22 11:26 ` Ian Campbell
2013-10-22 13:58   ` Julien Grall
2013-10-22 14:01     ` Ian Campbell
2013-10-24 14:05   ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).