diff mbox series

[for-4.0] hw/arm/raspi: Diagnose requests for too much RAM

Message ID 20190328095736.4480-1-peter.maydell@linaro.org
State Superseded
Headers show
Series [for-4.0] hw/arm/raspi: Diagnose requests for too much RAM | expand

Commit Message

Peter Maydell March 28, 2019, 9:57 a.m. UTC
The Raspberry Pi boards have a physical memory map which does
not allow for more than 1GB of RAM. Currently if the user tries
to ask for more then we fail in a confusing way:

$ qemu-system-aarch64 --machine raspi3 -m 8G
Unexpected error in visit_type_uintN() at qapi/qapi-visit-core.c:164:
qemu-system-aarch64: Parameter 'vcram-base' expects uint32_t
Aborted (core dumped)

Catch this earlier and diagnose it with a more friendly message:
$ qemu-system-aarch64 --machine raspi3 -m 8G
qemu-system-aarch64: Requested ram size is too large for this machine: maximum is 1GB

Fixes: https://bugs.launchpad.net/qemu/+bug/1794187
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 hw/arm/raspi.c | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
2.20.1

Comments

Philippe Mathieu-Daudé March 28, 2019, 10 a.m. UTC | #1
Le jeu. 28 mars 2019 10:57, Peter Maydell <peter.maydell@linaro.org> a
écrit :

> The Raspberry Pi boards have a physical memory map which does

> not allow for more than 1GB of RAM. Currently if the user tries

> to ask for more then we fail in a confusing way:

>

> $ qemu-system-aarch64 --machine raspi3 -m 8G

> Unexpected error in visit_type_uintN() at qapi/qapi-visit-core.c:164:

> qemu-system-aarch64: Parameter 'vcram-base' expects uint32_t

> Aborted (core dumped)

>

> Catch this earlier and diagnose it with a more friendly message:

> $ qemu-system-aarch64 --machine raspi3 -m 8G

> qemu-system-aarch64: Requested ram size is too large for this machine:

> maximum is 1GB

>

> Fixes: https://bugs.launchpad.net/qemu/+bug/1794187

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

> ---

>  hw/arm/raspi.c | 7 +++++++

>  1 file changed, 7 insertions(+)

>

> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c

> index 66899c28dc1..c7a18a319bc 100644

> --- a/hw/arm/raspi.c

> +++ b/hw/arm/raspi.c

> @@ -12,6 +12,7 @@

>   */

>

>  #include "qemu/osdep.h"

> +#include "qemu/units.h"

>  #include "qapi/error.h"

>  #include "qemu-common.h"

>  #include "cpu.h"

> @@ -175,6 +176,12 @@ static void raspi_init(MachineState *machine, int

> version)

>      BusState *bus;

>      DeviceState *carddev;

>

> +    if (machine->ram_size >= 1 * GiB) {

> +        error_report("Requested ram size is too large for this machine: "

> +                     "maximum is 1GB");

> +        exit(1);

> +    }

> +

>      object_initialize(&s->soc, sizeof(s->soc),

>                        version == 3 ? TYPE_BCM2837 : TYPE_BCM2836);

>      object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc),

> --

> 2.20.1

>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


>
<div dir="auto"><div><br><div class="gmail_quote"><div dir="ltr">Le jeu. 28 mars 2019 10:57, Peter Maydell &lt;<a href="mailto:peter.maydell@linaro.org">peter.maydell@linaro.org</a>&gt; a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The Raspberry Pi boards have a physical memory map which does<br>
not allow for more than 1GB of RAM. Currently if the user tries<br>
to ask for more then we fail in a confusing way:<br>
<br>
$ qemu-system-aarch64 --machine raspi3 -m 8G<br>
Unexpected error in visit_type_uintN() at qapi/qapi-visit-core.c:164:<br>
qemu-system-aarch64: Parameter &#39;vcram-base&#39; expects uint32_t<br>
Aborted (core dumped)<br>
<br>
Catch this earlier and diagnose it with a more friendly message:<br>
$ qemu-system-aarch64 --machine raspi3 -m 8G<br>
qemu-system-aarch64: Requested ram size is too large for this machine: maximum is 1GB<br>
<br>
Fixes: <a href="https://bugs.launchpad.net/qemu/+bug/1794187" rel="noreferrer noreferrer" target="_blank">https://bugs.launchpad.net/qemu/+bug/1794187</a><br>
Signed-off-by: Peter Maydell &lt;<a href="mailto:peter.maydell@linaro.org" target="_blank" rel="noreferrer">peter.maydell@linaro.org</a>&gt;<br>

---<br>
 hw/arm/raspi.c | 7 +++++++<br>
 1 file changed, 7 insertions(+)<br>
<br>
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c<br>
index 66899c28dc1..c7a18a319bc 100644<br>
--- a/hw/arm/raspi.c<br>
+++ b/hw/arm/raspi.c<br>
@@ -12,6 +12,7 @@<br>
  */<br>
<br>
 #include &quot;qemu/osdep.h&quot;<br>
+#include &quot;qemu/units.h&quot;<br>
 #include &quot;qapi/error.h&quot;<br>
 #include &quot;qemu-common.h&quot;<br>
 #include &quot;cpu.h&quot;<br>
@@ -175,6 +176,12 @@ static void raspi_init(MachineState *machine, int version)<br>
     BusState *bus;<br>
     DeviceState *carddev;<br>
<br>
+    if (machine-&gt;ram_size &gt;= 1 * GiB) {<br>
+        error_report(&quot;Requested ram size is too large for this machine: &quot;<br>
+                     &quot;maximum is 1GB&quot;);<br>
+        exit(1);<br>
+    }<br>
+<br>
     object_initialize(&amp;s-&gt;soc, sizeof(s-&gt;soc),<br>
                       version == 3 ? TYPE_BCM2837 : TYPE_BCM2836);<br>
     object_property_add_child(OBJECT(machine), &quot;soc&quot;, OBJECT(&amp;s-&gt;soc),<br>
-- <br>
2.20.1<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Reviewed-by: Philippe Mathieu-Daudé &lt;<a href="mailto:f4bug@amsat.org">f4bug@amsat.org</a>&gt;<br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>
Peter Maydell March 28, 2019, 3:15 p.m. UTC | #2
On Thu, 28 Mar 2019 at 09:57, Peter Maydell <peter.maydell@linaro.org> wrote:
>

> The Raspberry Pi boards have a physical memory map which does

> not allow for more than 1GB of RAM. Currently if the user tries

> to ask for more then we fail in a confusing way:

>

> $ qemu-system-aarch64 --machine raspi3 -m 8G

> Unexpected error in visit_type_uintN() at qapi/qapi-visit-core.c:164:

> qemu-system-aarch64: Parameter 'vcram-base' expects uint32_t

> Aborted (core dumped)

>

> Catch this earlier and diagnose it with a more friendly message:

> $ qemu-system-aarch64 --machine raspi3 -m 8G

> qemu-system-aarch64: Requested ram size is too large for this machine: maximum is 1GB

>

> Fixes: https://bugs.launchpad.net/qemu/+bug/1794187

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

> ---

>  hw/arm/raspi.c | 7 +++++++

>  1 file changed, 7 insertions(+)

>

> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c

> index 66899c28dc1..c7a18a319bc 100644

> --- a/hw/arm/raspi.c

> +++ b/hw/arm/raspi.c

> @@ -12,6 +12,7 @@

>   */

>

>  #include "qemu/osdep.h"

> +#include "qemu/units.h"

>  #include "qapi/error.h"

>  #include "qemu-common.h"

>  #include "cpu.h"

> @@ -175,6 +176,12 @@ static void raspi_init(MachineState *machine, int version)

>      BusState *bus;

>      DeviceState *carddev;

>

> +    if (machine->ram_size >= 1 * GiB) {

> +        error_report("Requested ram size is too large for this machine: "

> +                     "maximum is 1GB");

> +        exit(1);

> +    }


No patch is so simple that it can't have a bug or that it's
not necessary to run 'make check'. The condition in the if()
should be ">", not ">=", as 1GB is both valid and the default...

thanks
-- PMM
diff mbox series

Patch

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 66899c28dc1..c7a18a319bc 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -12,6 +12,7 @@ 
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -175,6 +176,12 @@  static void raspi_init(MachineState *machine, int version)
     BusState *bus;
     DeviceState *carddev;
 
+    if (machine->ram_size >= 1 * GiB) {
+        error_report("Requested ram size is too large for this machine: "
+                     "maximum is 1GB");
+        exit(1);
+    }
+
     object_initialize(&s->soc, sizeof(s->soc),
                       version == 3 ? TYPE_BCM2837 : TYPE_BCM2836);
     object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc),