Skip to contentSkip to conversation

softmmu/physmem: fix wrong assertion in qemu_ram_alloc_internal()

PATCH Superseded David Hildenbrand 3 participants 5 messages Aug 2, 2021 – Aug 3, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 softmmu/physmem: fix wrong assertion in qemu_ram_alloc_internal()

When adding RAM_NORESERVE, we forgot to remove the old assertion when adding the updated one, most probably when reworking the patches or rebasing. We can easily crash QEMU by adding
-object memory-backend-ram,id=mem0,size=500G,reserve=off
to the QEMU cmdline:
qemu-system-x86_64: ../softmmu/physmem.c:2146: qemu_ram_alloc_internal:
Assertion `(ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0' failed.

Fix it by removing the old assertion.

Fixes 8dbe22c6868b ("memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()")
Cc Paolo Bonzini <[email protected]>
Cc Peter Xu <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
---
 softmmu/physmem.c | 1 -
 1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -1
index 3c1912a1a0..2e18947598 100644
@@ -2143,7 +2143,6 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
     RAMBlock *new_block;
     Error *local_err = NULL;
 
-    assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0);
     assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
                           RAM_NORESERVE)) == 0);
     assert(!host ^ (ram_flags & RAM_PREALLOC));
Signature · 1 line
2.31.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · David Hildenbrand

When adding RAM_NORESERVE, we forgot to remove the old assertion when adding the updated one, most probably when reworking the patches or rebasing. We can easily crash QEMU by adding
-object memory-backend-ram,id=mem0,size=500G,reserve=off
to the QEMU cmdline:
qemu-system-x86_64: ../softmmu/physmem.c:2146: qemu_ram_alloc_internal:
Assertion `(ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0' failed.

Oops.

Quoted 7 lines

Fix it by removing the old assertion.

Fixes 8dbe22c6868b ("memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()")
Cc Paolo Bonzini <[email protected]>
Cc Peter Xu <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
---
 softmmu/physmem.c | 1 -
 1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -1
index 3c1912a1a0..2e18947598 100644
@@ -2143,7 +2143,6 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
     RAMBlock *new_block;
     Error *local_err = NULL;
 
-    assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0);
     assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
                           RAM_NORESERVE)) == 0);
     assert(!host ^ (ram_flags & RAM_PREALLOC));
#2 lore raw

6.1 material btw.

Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 8 lines · David Hildenbrand

When adding RAM_NORESERVE, we forgot to remove the old assertion when adding the updated one, most probably when reworking the patches or rebasing. We can easily crash QEMU by adding
-object memory-backend-ram,id=mem0,size=500G,reserve=off
to the QEMU cmdline:
qemu-system-x86_64: ../softmmu/physmem.c:2146: qemu_ram_alloc_internal:
Assertion `(ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0' failed.

Oops.

Quoted 7 lines

Fix it by removing the old assertion.

Fixes 8dbe22c6868b ("memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()")
Cc Paolo Bonzini <[email protected]>
Cc Peter Xu <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
---
 softmmu/physmem.c | 1 -
 1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -1
index 3c1912a1a0..2e18947598 100644
@@ -2143,7 +2143,6 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
     RAMBlock *new_block;
     Error *local_err = NULL;
 
-    assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0);
     assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
                           RAM_NORESERVE)) == 0);
     assert(!host ^ (ram_flags & RAM_PREALLOC));
#3 lore raw
Quoted 1 line · Philippe Mathieu-Daudé

6.1 material btw.

Indeed, should have tagged that right away. thanks!

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/1
#4 lore raw
In reply to David Hildenbrand
Quoted 9 lines · David Hildenbrand

When adding RAM_NORESERVE, we forgot to remove the old assertion when adding the updated one, most probably when reworking the patches or rebasing. We can easily crash QEMU by adding
-object memory-backend-ram,id=mem0,size=500G,reserve=off
to the QEMU cmdline:
qemu-system-x86_64: ../softmmu/physmem.c:2146: qemu_ram_alloc_internal:
Assertion `(ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0' failed.

Quoted 7 lines

Fix it by removing the old assertion.

Fixes 8dbe22c6868b ("memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap()")
Cc Paolo Bonzini <[email protected]>
Cc Peter Xu <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu