Skip to contentSkip to conversation

softmmu/physmem: fix wrong assertion in qemu_ram_alloc_internal()

PATCH In review David Hildenbrand 4 participants 6 messages Aug 5, 2021 – Aug 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 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]>

---

v1 -> v2:
- Added rbs
- Tagged for 6.1 inclusion

---
 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 on v2 1/1
#1 lore raw
Quoted 42 lines

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]>

---

v1 -> v2:
- Added rbs
- Tagged for 6.1 inclusion

---
 softmmu/physmem.c | 1 -
 1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -2
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));
--
Quoted 1 line

2.31.1

Quoted 2 lines
#2 lore raw
In reply to David Hildenbrand
Quoted 44 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.

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]>

---

v1 -> v2:
- Added rbs
- Tagged for 6.1 inclusion

---
 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

Today I just noticed this patch is still missing for 6.1. How many users are there with reserve=off? Would it be worth rc4 or not?

Signature · 1 line
Peter Xu
#3 lore raw
Quoted 38 lines · Peter Xu
Quoted 37 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.

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]>

---

v1 -> v2:
- Added rbs
- Tagged for 6.1 inclusion

---
  softmmu/physmem.c | 1 -
  1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -0
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;
 
Quoted 11 lines
Quoted 7 lines
softmmu/physmem.c +0 -1
-    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

Today I just noticed this patch is still missing for 6.1. How many users are there with reserve=off? Would it be worth rc4 or not?

Indeed, I forgot to follow up, thanks for bringing this up.

Libvirt does not support virtio-mem yet and consequently doesn't support reserve=off yet. (there are use cases without virtio-mem, but I don't think anybody is using it yet)

It's an easy way to crash QEMU, but we could also fix in the -stable tree instead.

(most probably you and me should also be doing PULL requests for "Memory API", we'll have to discuss with Paolo)

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
Quoted 6 lines · David Hildenbrand

Libvirt does not support virtio-mem yet and consequently doesn't support reserve=off yet. (there are use cases without virtio-mem, but I don't think anybody is using it yet)

It's an easy way to crash QEMU, but we could also fix in the -stable tree instead.

I hit this when trying with some extreme bitmap tests then I remembered this patch, but that shouldn't really be used by any real customer for sure.

Sounds good then, thanks.

Signature · 1 line
Peter Xu
#5 lore raw
In reply to David Hildenbrand
Quoted 52 lines · David Hildenbrand
Quoted 38 lines · Peter Xu
Quoted 37 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.

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]>

---

v1 -> v2:
- Added rbs
- Tagged for 6.1 inclusion

---
  softmmu/physmem.c | 1 -
  1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -0
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;
 
Quoted 11 lines
Quoted 7 lines
softmmu/physmem.c +0 -2
-    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.31.1

Today I just noticed this patch is still missing for 6.1. How many users are there with reserve=off? Would it be worth rc4 or not?

Quoted 8 lines

Indeed, I forgot to follow up, thanks for bringing this up.

Libvirt does not support virtio-mem yet and consequently doesn't support reserve=off yet. (there are use cases without virtio-mem, but I don't think anybody is using it yet)

It's an easy way to crash QEMU, but we could also fix in the -stable tree instead.

It is a really obvious right fix, though, so I'm going to apply it for rc4 anyway.

thanks
-- PMM