Skip to contentSkip to conversation

hostmem: Apply merge property after the memory region is initialized

PATCH In review Gavin Shan 3 participants 3 messages Sep 15, 2024 – Sep 17, 2024 Arm STM32

lore
Share & tools
lore

Gavin Shan

author
#0 lore raw

PATCH 1/1 hostmem: Apply merge property after the memory region is initialized

The semantic change has been introduced by commit 5becdc0ab0 ("hostmem:
simplify the code for merge and dump properties") even it clarifies that no senmatic change has been introduced. After the commit, the merge property can be applied even the corresponding memory region isn't initialized yet. This leads to crash dump by the following command lines.

  # /home/gavin/sandbox/qemu.main/build/qemu-system-aarch64  \
    -accel kvm  -machine virt -cpu host                      \
    -object memory-backend-ram,id=mem-memN0,size=4096M,merge=off
    :
    qemu-system-aarch64: ../system/memory.c:2419: memory_region_get_ram_ptr: \
    Assertion `mr->ram_block' failed.

Fix it by applying the merge property only when the memory region is initialized.

Fixes 5becdc0ab083 ("hostmem: simplify the code for merge and dump properties")
---
 backends/hostmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
backends/hostmem.c +1 -1
index 4e5576a4ad..181446626a 100644
@@ -178,7 +178,7 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
         return;
     }
 
-    if (!host_memory_backend_mr_inited(backend) &&
+    if (host_memory_backend_mr_inited(backend) &&
         value != backend->merge) {
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
Signature · 1 line
2.45.2
Tested-by on v1 1/1
#1 lore raw

[PATCH] hostmem: Apply merge property after the memory region is initialized

Test on 4k and 64k basic page size aarch64
The patches work well on my Ampere host.
The test results are as expected.

# /home/test/qemu.main/build/qemu-system-aarch64  \
   -accel kvm  -machine virt -cpu host                           \
   -object memory-backend-ram,id=mem-memN0,size=4096M,merge=off
Quoted 41 lines · Gavin Shan

The semantic change has been introduced by commit 5becdc0ab0 ("hostmem:
simplify the code for merge and dump properties") even it clarifies that no senmatic change has been introduced. After the commit, the merge property can be applied even the corresponding memory region isn't initialized yet. This leads to crash dump by the following command lines.

  # /home/gavin/sandbox/qemu.main/build/qemu-system-aarch64  \
    -accel kvm  -machine virt -cpu host                      \
    -object memory-backend-ram,id=mem-memN0,size=4096M,merge=off
    :
    qemu-system-aarch64: ../system/memory.c:2419: memory_region_get_ram_ptr: \
    Assertion `mr->ram_block' failed.

Fix it by applying the merge property only when the memory region is initialized.

Fixes 5becdc0ab083 ("hostmem: simplify the code for merge and dump properties")
---
 backends/hostmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
backends/hostmem.c +1 -2
index 4e5576a4ad..181446626a 100644
@@ -178,7 +178,7 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
         return;
     }
 
-    if (!host_memory_backend_mr_inited(backend) &&
+    if (host_memory_backend_mr_inited(backend) &&
         value != backend->merge) {
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
--

2.45.2

#2 lore raw
In reply to Gavin Shan
Quoted 29 lines · Gavin Shan

The semantic change has been introduced by commit 5becdc0ab0 ("hostmem:
simplify the code for merge and dump properties") even it clarifies that no senmatic change has been introduced. After the commit, the merge property can be applied even the corresponding memory region isn't initialized yet. This leads to crash dump by the following command lines.

   # /home/gavin/sandbox/qemu.main/build/qemu-system-aarch64  \
     -accel kvm  -machine virt -cpu host                      \
     -object memory-backend-ram,id=mem-memN0,size=4096M,merge=off
     :
     qemu-system-aarch64: ../system/memory.c:2419: memory_region_get_ram_ptr: \
     Assertion `mr->ram_block' failed.

Fix it by applying the merge property only when the memory region is initialized.

Fixes 5becdc0ab083 ("hostmem: simplify the code for merge and dump properties")
---
  backends/hostmem.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
backends/hostmem.c +0 -0
index 4e5576a4ad..181446626a 100644

backends/hostmem.c static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp) · line 184

Quoted 8 lines
backends/hostmem.c +1 -1
@@ -178,7 +178,7 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
          return;
      }
 
-    if (!host_memory_backend_mr_inited(backend) &&
+    if (host_memory_backend_mr_inited(backend) &&
          value != backend->merge) {
          void *ptr = memory_region_get_ram_ptr(&backend->mr);
          uint64_t sz = memory_region_size(&backend->mr);

Thanks, queued to

https://github.com/davidhildenbrand/qemu.git mem-next

Signature · 3 lines
Cheers,

David / dhildenb