Skip to contentSkip to conversation

Remove the 1GB limitation on Rasberry Pi 4

PATCH In review Julien Grall 2 participants 5 messages May 19, 2020 – May 21, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover Remove the 1GB limitation on Rasberry Pi 4

From: Julien Grall <[email protected]>

Hi all,

At the moment, a user who wants to boot Xen on the Raspberry Pi 4 can only use the first GB of memory.

This is because several devices cannot DMA above 1GB but Xen doesn't necessarily allocate memory for Dom0 below 1GB.

This small series is trying to address the problem by allowing a platform to restrict where Dom0 banks are allocated.

This is also a candidate for Xen 4.14. Without it, a user will not be able to use all the RAM on the Raspberry Pi 4.

This series has only be slighlty tested. I would appreciate more test on the Rasbperry Pi 4 to confirm this removing the restriction.

Cheers,

Julien Grall (3):
xen/arm: Allow a platform to override the DMA width xen/arm: Take into account the DMA width when allocating Dom0 memory
banks
xen/arm: plat: Allocate as much as possible memory below 1GB for dom0
for RPI

 xen/arch/arm/domain_build.c                | 33 +++++++++++++---------
 xen/arch/arm/platform.c                    |  5 ++++
 xen/arch/arm/platforms/brcm-raspberry-pi.c |  1 +
 xen/include/asm-arm/mm.h                   |  2 ++
 xen/include/asm-arm/numa.h                 |  5 ----
 xen/include/asm-arm/platform.h             |  2 ++
 6 files changed, 29 insertions(+), 19 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 xen/arm: Allow a platform to override the DMA width

From: Julien Grall <[email protected]>

At the moment, Xen is assuming that all the devices are at least 32-bit DMA capable. However, some SoC have devices that may be able to access a much restricted range. For instance, the RPI has devices that can only access the first 1GB of RAM.

The structure platform_desc is now extended to allow a platform to override the DMA width. The new is used to implement arch_get_dma_bit_size().

The prototype is now moved in asm-arm/mm.h as the function is not NUMA specific. The implementation is done in platform.c so we don't have to include platform.h everywhere. This should be fine as the function is not expected to be called in hotpath.

---

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>

Changes in v2:
- Add Corey's tested-by
- Add Volodymyr's reviewed-by

I noticed that arch_get_dma_bit_size() is only called when there is more than one NUMA node. I am a bit unsure what is the reason behind it.

The goal for Arm is to use arch_get_dma_bit_size() when deciding how low the first Dom0 bank should be allocated.

---
 xen/arch/arm/platform.c        | 5 +++++
 xen/include/asm-arm/mm.h       | 2 ++
 xen/include/asm-arm/numa.h     | 5 -----
 xen/include/asm-arm/platform.h | 2 ++
 4 files changed, 9 insertions(+), 5 deletions(-)
xen/arch/arm/platform.c +5 -0
index 8eb0b6e57a5a..4db5bbb4c51d 100644
@@ -155,6 +155,11 @@ bool platform_device_is_blacklisted(const struct dt_device_node *node)
     return (dt_match_node(blacklist, node) != NULL);
 }
 
+unsigned int arch_get_dma_bitsize(void)
+{
+    return ( platform && platform->dma_bitsize ) ? platform->dma_bitsize : 32;
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/mm.h +2 -0
index 7df91280bc77..f8ba49b1188f 100644
@@ -366,6 +366,8 @@ int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id,
     return -EOPNOTSUPP;
 }
 
+unsigned int arch_get_dma_bitsize(void);
+
 #endif /*  __ARCH_ARM_MM__ */
 /*
  * Local variables:
xen/include/asm-arm/numa.h +0 -5
index 490d1f31aa14..31a6de4e2346 100644
@@ -25,11 +25,6 @@ extern mfn_t first_valid_mfn;
 #define node_start_pfn(nid) (mfn_x(first_valid_mfn))
 #define __node_distance(a, b) (20)
 
-static inline unsigned int arch_get_dma_bitsize(void)
-{
-    return 32;
-}
-
 #endif /* __ARCH_ARM_NUMA_H */
 /*
  * Local variables:
xen/include/asm-arm/platform.h +2 -0
index ed4d30a1be7c..997eb2521631 100644
@@ -38,6 +38,8 @@ struct platform_desc {
      * List of devices which must not pass-through to a guest
      */
     const struct dt_device_match *blacklist_dev;
+    /* Override the DMA width (32-bit by default). */
+    unsigned int dma_bitsize;
 };
 
 /*
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/3 xen/arm: Take into account the DMA width when allocating Dom0 memory banks

In reply to Julien Grall

From: Julien Grall <[email protected]>

At the moment, Xen is assuming that all the devices are at least 32-bit DMA capable. However, some SoCs have devices that may be able to access a much restricted range. For instance, the Raspberry PI 4 has devices that can only access the first GB of RAM.

The function arch_get_dma_bit_size() will return the lowest DMA width on the platform. Use it to decide what is the limit for the low memory.

---
Changes in v2:
- Remove left-over in the comment
- Add Corey's tested-by

---
 xen/arch/arm/domain_build.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
xen/arch/arm/domain_build.c +19 -14
index 430708753642..3d7a75c31881 100644
@@ -211,10 +211,12 @@ fail:
  *    the ramdisk and DTB must be placed within a certain proximity of
  *    the kernel within RAM.
  * 3. For dom0 we want to place as much of the RAM as we reasonably can
- *    below 4GB, so that it can be used by non-LPAE enabled kernels (32-bit)
- *    or when a device assigned to dom0 can only do 32-bit DMA access.
- * 4. For 32-bit dom0 the kernel must be located below 4GB.
- * 5. We want to have a few largers banks rather than many smaller ones.
+ *    below 4GB, so that it can be used by non-LPAE enabled kernels (32-bit).
+ * 4. Some devices assigned to dom0 can only do 32-bit DMA access or
+ *    even be more restricted. We want to allocate as much of the RAM
+ *    as we reasonably can that can be accessed from all the devices..
+ * 5. For 32-bit dom0 the kernel must be located below 4GB.
+ * 6. We want to have a few largers banks rather than many smaller ones.
  *
  * For the first two requirements we need to make sure that the lowest
  * bank is sufficiently large.
@@ -245,9 +247,9 @@ fail:
  * we give up.
  *
  * For 32-bit domain we require that the initial allocation for the
- * first bank is under 4G. For 64-bit domain, the first bank is preferred
- * to be allocated under 4G. Then for the subsequent allocations we
- * initially allocate memory only from below 4GB. Once that runs out
+ * first bank is part of the low mem. For 64-bit, the first bank is preferred
+ * to be allocated in the low mem. Then for subsequent allocation, we
+ * initially allocate memory only from low mem. Once that runs out out
  * (as described above) we allow higher allocations and continue until
  * that runs out (or we have allocated sufficient dom0 memory).
  */
@@ -262,6 +264,7 @@ static void __init allocate_memory_11(struct domain *d,
     int i;
 
     bool lowmem = true;
+    unsigned int lowmem_bitsize = min(32U, arch_get_dma_bitsize());
     unsigned int bits;
 
     /*
@@ -282,7 +285,7 @@ static void __init allocate_memory_11(struct domain *d,
      */
     while ( order >= min_low_order )
     {
-        for ( bits = order ; bits <= (lowmem ? 32 : PADDR_BITS); bits++ )
+        for ( bits = order ; bits <= lowmem_bitsize; bits++ )
         {
             pg = alloc_domheap_pages(d, order, MEMF_bits(bits));
             if ( pg != NULL )
@@ -296,24 +299,26 @@ static void __init allocate_memory_11(struct domain *d,
         order--;
     }
 
-    /* Failed to allocate bank0 under 4GB */
+    /* Failed to allocate bank0 in the lowmem region. */
     if ( is_32bit_domain(d) )
         panic("Unable to allocate first memory bank\n");
 
-    /* Try to allocate memory from above 4GB */
-    printk(XENLOG_INFO "No bank has been allocated below 4GB.\n");
+    /* Try to allocate memory from above the lowmem region */
+    printk(XENLOG_INFO "No bank has been allocated below %u-bit.\n",
+           lowmem_bitsize);
     lowmem = false;
 
  got_bank0:
 
     /*
-     * If we failed to allocate bank0 under 4GB, continue allocating
-     * memory from above 4GB and fill in banks.
+     * If we failed to allocate bank0 in the lowmem region,
+     * continue allocating from above the lowmem and fill in banks.
      */
     order = get_allocation_size(kinfo->unassigned_mem);
     while ( kinfo->unassigned_mem && kinfo->mem.nr_banks < NR_MEM_BANKS )
     {
-        pg = alloc_domheap_pages(d, order, lowmem ? MEMF_bits(32) : 0);
+        pg = alloc_domheap_pages(d, order,
+                                 lowmem ? MEMF_bits(lowmem_bitsize) : 0);
         if ( !pg )
         {
             order --;
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/3 xen/arm: plat: Allocate as much as possible memory below 1GB for dom0 for RPI

In reply to Julien Grall

From: Julien Grall <[email protected]>

The raspberry PI 4 has devices that can only DMA into the first GB of the RAM. Therefore we want allocate as much as possible memory below 1GB for dom0.

Use the recently introduced dma_bitsize field to specify the DMA width supported.

---
Changes in v2:
- 1G is 30 bits not 10!
- Add Corey's tested-by

---
 xen/arch/arm/platforms/brcm-raspberry-pi.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/platforms/brcm-raspberry-pi.c +1 -0
index b697fa2c6c0e..f5ae58a7d5f2 100644
@@ -43,6 +43,7 @@ static const struct dt_device_match rpi4_blacklist_dev[] __initconst =
 PLATFORM_START(rpi4, "Raspberry Pi 4")
     .compatible     = rpi4_dt_compat,
     .blacklist_dev  = rpi4_blacklist_dev,
+    .dma_bitsize    = 30,
 PLATFORM_END
 
 /*
Signature · 1 line
2.17.1
#4 lore raw
In reply to Julien Grall
Quoted 10 lines · Julien Grall

From: Julien Grall <[email protected]>

Hi all,

At the moment, a user who wants to boot Xen on the Raspberry Pi 4 can only use the first GB of memory.

This is because several devices cannot DMA above 1GB but Xen doesn't necessarily allocate memory for Dom0 below 1GB.

Quoted 8 lines

This small series is trying to address the problem by allowing a platform to restrict where Dom0 banks are allocated.

This is also a candidate for Xen 4.14. Without it, a user will not be able to use all the RAM on the Raspberry Pi 4.

This series has only be slighlty tested. I would appreciate more test on the Rasbperry Pi 4 to confirm this removing the restriction.

You can add my reviewed-by to all patches in the series.