qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hostmem: Apply merge property after the memory region is initialized
@ 2024-09-15 23:31 Gavin Shan
  2024-09-16 12:13 ` Zhenyu Zhang
  2024-09-17  8:29 ` David Hildenbrand
  0 siblings, 2 replies; 3+ messages in thread
From: Gavin Shan @ 2024-09-15 23:31 UTC (permalink / raw)
  To: qemu-arm
  Cc: qemu-devel, david, imammedo, philmd, pbonzini, peter.maydell,
	zhenyzha, shan.gavin

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")
Reported-by: Zhenyu Zhang <zhenyzha@redhat.com>
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 backends/hostmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 4e5576a4ad..181446626a 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hostmem: Apply merge property after the memory region is initialized
  2024-09-15 23:31 [PATCH] hostmem: Apply merge property after the memory region is initialized Gavin Shan
@ 2024-09-16 12:13 ` Zhenyu Zhang
  2024-09-17  8:29 ` David Hildenbrand
  1 sibling, 0 replies; 3+ messages in thread
From: Zhenyu Zhang @ 2024-09-16 12:13 UTC (permalink / raw)
  To: Gavin Shan
  Cc: qemu-arm, qemu-devel, david, imammedo, philmd, pbonzini,
	peter.maydell, shan.gavin

[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

Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>


On Mon, Sep 16, 2024 at 7:31 AM Gavin Shan <gshan@redhat.com> wrote:
>
> 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")
> Reported-by: Zhenyu Zhang <zhenyzha@redhat.com>
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>  backends/hostmem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 4e5576a4ad..181446626a 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -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
>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hostmem: Apply merge property after the memory region is initialized
  2024-09-15 23:31 [PATCH] hostmem: Apply merge property after the memory region is initialized Gavin Shan
  2024-09-16 12:13 ` Zhenyu Zhang
@ 2024-09-17  8:29 ` David Hildenbrand
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2024-09-17  8:29 UTC (permalink / raw)
  To: Gavin Shan, qemu-arm
  Cc: qemu-devel, imammedo, philmd, pbonzini, peter.maydell, zhenyzha,
	shan.gavin

On 16.09.24 01:31, Gavin Shan wrote:
> 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")
> Reported-by: Zhenyu Zhang <zhenyzha@redhat.com>
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>   backends/hostmem.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 4e5576a4ad..181446626a 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -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

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-17  8:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-15 23:31 [PATCH] hostmem: Apply merge property after the memory region is initialized Gavin Shan
2024-09-16 12:13 ` Zhenyu Zhang
2024-09-17  8:29 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).