[PATCH] mem-prealloc: initialize cond and mutex

Christian Borntraeger posted 1 patch 5 years, 8 months ago
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test checkpatch passed
Test FreeBSD passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200306085014.120669-1-borntraeger@de.ibm.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
util/oslib-posix.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] mem-prealloc: initialize cond and mutex
Posted by Christian Borntraeger 5 years, 8 months ago
Guests with mem-prealloc do fail with
qemu-system-s390x: /home/cborntra/REPOS/qemu/util/qemu-thread-posix.c:76: qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.
qemu-system-s390x: /home/cborntra/REPOS/qemu/util/qemu-thread-posix.c:161: qemu_cond_broadcast: Assertion `cond->initialized' failed.

Let us initialize cond and mutex.

Cc: bauerchen <bauerchen@tencent.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Fixes: 037fb5eb3941 ("mem-prealloc: optimize large guest startup")
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 util/oslib-posix.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 897e8f3ba6..52650183d3 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -470,6 +470,8 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
     char *addr = area;
     int i = 0;
 
+    qemu_cond_init(&page_cond);
+    qemu_mutex_init(&page_mutex);
     memset_thread_failed = false;
     threads_created_flag = false;
     memset_num_threads = get_memset_num_threads(smp_cpus);
-- 
2.25.0


Re: [PATCH] mem-prealloc: initialize cond and mutex
Posted by Paolo Bonzini 5 years, 8 months ago
On 06/03/20 09:50, Christian Borntraeger wrote:
> Guests with mem-prealloc do fail with
> qemu-system-s390x: /home/cborntra/REPOS/qemu/util/qemu-thread-posix.c:76: qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.
> qemu-system-s390x: /home/cborntra/REPOS/qemu/util/qemu-thread-posix.c:161: qemu_cond_broadcast: Assertion `cond->initialized' failed.
> 
> Let us initialize cond and mutex.
> 
> Cc: bauerchen <bauerchen@tencent.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Fixes: 037fb5eb3941 ("mem-prealloc: optimize large guest startup")
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  util/oslib-posix.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 897e8f3ba6..52650183d3 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -470,6 +470,8 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
>      char *addr = area;
>      int i = 0;
>  
> +    qemu_cond_init(&page_cond);
> +    qemu_mutex_init(&page_mutex);
>      memset_thread_failed = false;
>      threads_created_flag = false;
>      memset_num_threads = get_memset_num_threads(smp_cpus);
> 

Thank you very much.  It's my fault, but is it too much to ask that
submitters test their patches???

Paolo


Re: [PATCH] mem-prealloc: initialize cond and mutex
Posted by Igor Mammedov 5 years, 8 months ago
On Fri,  6 Mar 2020 03:50:14 -0500
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> Guests with mem-prealloc do fail with
> qemu-system-s390x: /home/cborntra/REPOS/qemu/util/qemu-thread-posix.c:76: qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.
> qemu-system-s390x: /home/cborntra/REPOS/qemu/util/qemu-thread-posix.c:161: qemu_cond_broadcast: Assertion `cond->initialized' failed.
> 
> Let us initialize cond and mutex.
> 
> Cc: bauerchen <bauerchen@tencent.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Fixes: 037fb5eb3941 ("mem-prealloc: optimize large guest startup")
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  util/oslib-posix.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 897e8f3ba6..52650183d3 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -470,6 +470,8 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
>      char *addr = area;
>      int i = 0;
>  
> +    qemu_cond_init(&page_cond);
> +    qemu_mutex_init(&page_mutex);

Is it possible for touch_all_pages to be called several times?
If it's then it probably needs a guard against that to make
sure it won't explode, something like:

static bool page_mutex_inited;

if(page_mutex_inited)
  page_mutex_inited = true
  qemu_mutex_init(&page_mutex) 
  ...

>      memset_thread_failed = false;
>      threads_created_flag = false;
>      memset_num_threads = get_memset_num_threads(smp_cpus);


Re: [PATCH] mem-prealloc: initialize cond and mutex
Posted by Paolo Bonzini 5 years, 8 months ago
On 09/03/20 11:03, Igor Mammedov wrote:
>> +    qemu_cond_init(&page_cond);
>> +    qemu_mutex_init(&page_mutex);
> Is it possible for touch_all_pages to be called several times?
> If it's then it probably needs a guard against that to make
> sure it won't explode, something like:
> 
> static bool page_mutex_inited;
> 
> if(page_mutex_inited)
>   page_mutex_inited = true
>   qemu_mutex_init(&page_mutex) 
>   ...
> 

Hmm, good idea, it should also use GOnce.

Paolo


Re: [PATCH] mem-prealloc: initialize cond and mutex
Posted by Christian Borntraeger 5 years, 8 months ago

On 09.03.20 11:05, Paolo Bonzini wrote:
> On 09/03/20 11:03, Igor Mammedov wrote:
>>> +    qemu_cond_init(&page_cond);
>>> +    qemu_mutex_init(&page_mutex);
>> Is it possible for touch_all_pages to be called several times?
>> If it's then it probably needs a guard against that to make
>> sure it won't explode, something like:
>>
>> static bool page_mutex_inited;
>>
>> if(page_mutex_inited)
>>   page_mutex_inited = true
>>   qemu_mutex_init(&page_mutex) 
>>   ...
>>
> 
> Hmm, good idea, it should also use GOnce.

Maybe start with a revert and let the original submitter send
a fixed up patch?