Patchwork [1/2] vl: Round argument of -m up to multiple of 8KiB

login
register
mail settings
Submitter Markus Armbruster
Date Aug. 14, 2012, 11:58 a.m.
Message ID <1344945535-2774-2-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/177239/
State New
Headers show

Comments

Markus Armbruster - Aug. 14, 2012, 11:58 a.m.
Partial pages make little sense and don't work.  Ensure the RAM size
is a multiple of any possible target's page size.

Fixes

$ qemu-system-x86_64 -nodefaults -S -vnc :0 -monitor stdio -m 0.8
QEMU 1.1.50 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: /work/armbru/qemu/exec.c:2255: register_subpage: Assertion `existing->mr->subpage || existing->mr == &io_mem_unassigned' failed

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
See also
http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg02813.html

 vl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Avi Kivity - Aug. 14, 2012, 12:42 p.m.
On 08/14/2012 02:58 PM, Markus Armbruster wrote:
> Partial pages make little sense and don't work.  Ensure the RAM size
> is a multiple of any possible target's page size.
> 
> index d01256a..b411d45 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2708,11 +2708,13 @@ int main(int argc, char **argv, char **envp)
>                      fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
>                      exit(1);
>                  }
> -
>                  if (value != (uint64_t)(ram_addr_t)value) {
>                      fprintf(stderr, "qemu: ram size too large\n");
>                      exit(1);
>                  }
> +                if (value & 0x1fff) {
> +                    value = (value + 0x1fff) & ~0x1fff;
> +                }

value = QEMU_ALIGN_UP(value, 8192);
Markus Armbruster - Aug. 14, 2012, 12:55 p.m.
Avi Kivity <avi@redhat.com> writes:

> On 08/14/2012 02:58 PM, Markus Armbruster wrote:
>> Partial pages make little sense and don't work.  Ensure the RAM size
>> is a multiple of any possible target's page size.
>> 
>> index d01256a..b411d45 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -2708,11 +2708,13 @@ int main(int argc, char **argv, char **envp)
>>                      fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
>>                      exit(1);
>>                  }
>> -
>>                  if (value != (uint64_t)(ram_addr_t)value) {
>>                      fprintf(stderr, "qemu: ram size too large\n");
>>                      exit(1);
>>                  }
>> +                if (value & 0x1fff) {
>> +                    value = (value + 0x1fff) & ~0x1fff;
>> +                }
>
> value = QEMU_ALIGN_UP(value, 8192);

I looked for such a macro, but my greps missed.  Thanks!

Patch

diff --git a/vl.c b/vl.c
index d01256a..b411d45 100644
--- a/vl.c
+++ b/vl.c
@@ -2708,11 +2708,13 @@  int main(int argc, char **argv, char **envp)
                     fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
                     exit(1);
                 }
-
                 if (value != (uint64_t)(ram_addr_t)value) {
                     fprintf(stderr, "qemu: ram size too large\n");
                     exit(1);
                 }
+                if (value & 0x1fff) {
+                    value = (value + 0x1fff) & ~0x1fff;
+                }
                 ram_size = value;
                 break;
             }