diff mbox series

[v3,3/4] hw/riscv: virt: Limit RAM size in a 32-bit system

Message ID 20210220144807.819-4-bmeng.cn@gmail.com
State New
Headers show
Series hw/riscv: Clean-ups and map high mmio for PCIe of 'virt' machine | expand

Commit Message

Bin Meng Feb. 20, 2021, 2:48 p.m. UTC
From: Bin Meng <bin.meng@windriver.com>

RV32 supports 34-bit physical address hence the maximum RAM size
should be limited. Limit the RAM size to 10 GiB, which leaves
some room for PCIe high mmio space.

For 32-bit host, this is not needed as machine->ram_size cannot
represent a RAM size that big. Use a #if size test to only do
the size limitation for the 64-bit host.

Signed-off-by: Bin Meng <bin.meng@windriver.com>

---

Changes in v3:
- Fix the typo (limit) in the commit message and codes

Changes in v2:
- Use a #if size test to only do the size limitation for the 64-bit host

 hw/riscv/virt.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Alistair Francis March 3, 2021, 7:05 p.m. UTC | #1
On Sat, Feb 20, 2021 at 9:52 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> From: Bin Meng <bin.meng@windriver.com>
>
> RV32 supports 34-bit physical address hence the maximum RAM size
> should be limited. Limit the RAM size to 10 GiB, which leaves
> some room for PCIe high mmio space.
>
> For 32-bit host, this is not needed as machine->ram_size cannot
> represent a RAM size that big. Use a #if size test to only do
> the size limitation for the 64-bit host.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

>
> ---
>
> Changes in v3:
> - Fix the typo (limit) in the commit message and codes
>
> Changes in v2:
> - Use a #if size test to only do the size limitation for the 64-bit host
>
>  hw/riscv/virt.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 1d05bb3ef9..c4b8f455f8 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -590,6 +590,16 @@ static void virt_machine_init(MachineState *machine)
>          }
>      }
>
> +    if (riscv_is_32bit(&s->soc[0])) {
> +#if HOST_LONG_BITS == 64
> +        /* limit RAM size in a 32-bit system */
> +        if (machine->ram_size > 10 * GiB) {
> +            machine->ram_size = 10 * GiB;
> +            error_report("Limiting RAM size to 10 GiB");
> +        }
> +#endif
> +    }
> +
>      /* register system main memory (actual RAM) */
>      memory_region_init_ram(main_mem, NULL, "riscv_virt_board.ram",
>                             machine->ram_size, &error_fatal);
> --
> 2.25.1
>
>
diff mbox series

Patch

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 1d05bb3ef9..c4b8f455f8 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -590,6 +590,16 @@  static void virt_machine_init(MachineState *machine)
         }
     }
 
+    if (riscv_is_32bit(&s->soc[0])) {
+#if HOST_LONG_BITS == 64
+        /* limit RAM size in a 32-bit system */
+        if (machine->ram_size > 10 * GiB) {
+            machine->ram_size = 10 * GiB;
+            error_report("Limiting RAM size to 10 GiB");
+        }
+#endif
+    }
+
     /* register system main memory (actual RAM) */
     memory_region_init_ram(main_mem, NULL, "riscv_virt_board.ram",
                            machine->ram_size, &error_fatal);