qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] KVM: dirty ring: check if vcpu is created before dirty_ring_reap_one
@ 2023-02-05  6:45 Weinan Liu
  2023-02-05 23:00 ` Peter Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Weinan Liu @ 2023-02-05  6:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: peterx, dgilbert, Weinan Liu

Failed to assert '(dirty_gfns && ring_size)' in kvm_dirty_ring_reap_one if
the vcpu has not been finished to create yet. This bug occasionally occurs
when I open 200+ qemu instances on my 16G 6-cores x86 machine. And it must
be triggered if inserting a 'sleep(10)' into kvm_vcpu_thread_fn as below--

 static void *kvm_vcpu_thread_fn(void *arg)
 {
     CPUState *cpu = arg;
     int r;

     rcu_register_thread();

+    sleep(10);
     qemu_mutex_lock_iothread();
     qemu_thread_get_self(cpu->thread);
     cpu->thread_id = qemu_get_thread_id();
     cpu->can_do_io = 1;

where dirty ring reaper will wakeup but then a vcpu has not been finished
to create.

Signed-off-by: Weinan Liu <liu-weinan@qq.com>
---
 accel/kvm/kvm-all.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 7e6a6076b1..0070ad72b8 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1416,6 +1416,11 @@ static void *kvm_dirty_ring_reaper_thread(void *data)
          */
         sleep(1);
 
+        /* ensure kvm_init_vcpu is finished, so cpu->kvm_dirty_gfns is ok */
+        if (!phase_check(PHASE_MACHINE_READY)) {
+            continue;
+        }
+
         /* keep sleeping so that dirtylimit not be interfered by reaper */
         if (dirtylimit_in_service()) {
             continue;
-- 
2.25.1



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

* Re: [PATCH v2] KVM: dirty ring: check if vcpu is created before dirty_ring_reap_one
  2023-02-05  6:45 [PATCH v2] KVM: dirty ring: check if vcpu is created before dirty_ring_reap_one Weinan Liu
@ 2023-02-05 23:00 ` Peter Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Xu @ 2023-02-05 23:00 UTC (permalink / raw)
  To: Weinan Liu; +Cc: qemu-devel, dgilbert, Paolo Bonzini

Hi, Weinan,

On Sun, Feb 05, 2023 at 06:45:45AM +0000, Weinan Liu wrote:
> Failed to assert '(dirty_gfns && ring_size)' in kvm_dirty_ring_reap_one if
> the vcpu has not been finished to create yet. This bug occasionally occurs
> when I open 200+ qemu instances on my 16G 6-cores x86 machine. And it must
> be triggered if inserting a 'sleep(10)' into kvm_vcpu_thread_fn as below--
> 
>  static void *kvm_vcpu_thread_fn(void *arg)
>  {
>      CPUState *cpu = arg;
>      int r;
> 
>      rcu_register_thread();
> 
> +    sleep(10);
>      qemu_mutex_lock_iothread();
>      qemu_thread_get_self(cpu->thread);
>      cpu->thread_id = qemu_get_thread_id();
>      cpu->can_do_io = 1;
> 
> where dirty ring reaper will wakeup but then a vcpu has not been finished
> to create.
> 
> Signed-off-by: Weinan Liu <liu-weinan@qq.com>
> ---
>  accel/kvm/kvm-all.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 7e6a6076b1..0070ad72b8 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -1416,6 +1416,11 @@ static void *kvm_dirty_ring_reaper_thread(void *data)
>           */
>          sleep(1);
>  
> +        /* ensure kvm_init_vcpu is finished, so cpu->kvm_dirty_gfns is ok */
> +        if (!phase_check(PHASE_MACHINE_READY)) {
> +            continue;
> +        }
> +

Here's an old patch for this:

https://lore.kernel.org/all/20220927154653.77296-1-peterx@redhat.com/

IMHO that one will be more straightforward and self contained than this
one.  What do you think?

When posting new patches, please also remember to copy maintainers.  For
this one, it's:

$ ./scripts/get_maintainer.pl -f accel/kvm/kvm-all.c 
Paolo Bonzini <pbonzini@redhat.com> (supporter:Overall KVM CPUs)

Thanks,

-- 
Peter Xu



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

* Re: [PATCH v2] KVM: dirty ring: check if vcpu is created before dirty_ring_reap_one
@ 2023-02-06  3:54 =?gb18030?B?V2VpbmFuIExpdaOowfXsv+mqo6k=?=
  0 siblings, 0 replies; 3+ messages in thread
From: =?gb18030?B?V2VpbmFuIExpdaOowfXsv+mqo6k=?= @ 2023-02-06  3:54 UTC (permalink / raw)
  To: =?gb18030?B?UGV0ZXIgWHU=?=
  Cc: =?gb18030?B?cWVtdS1kZXZlbA==?=, =?gb18030?B?ZGdpbGJlcnQ=?=,
	=?gb18030?B?UGFvbG8gQm9uemluaQ==?=

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 270 bytes --]

Hi, Peter,

&gt; IMHO that one will be more straightforward and self contained than this
&gt; one.  What do you think?
Yes, it is.

&gt; When posting new patches, please also remember to copy maintainers.  For
&gt; this one, it's:
Thanks for your suggestion.

Weinan Liu

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

end of thread, other threads:[~2023-02-06  3:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-05  6:45 [PATCH v2] KVM: dirty ring: check if vcpu is created before dirty_ring_reap_one Weinan Liu
2023-02-05 23:00 ` Peter Xu
  -- strict thread matches above, loose matches on Subject: below --
2023-02-06  3:54 =?gb18030?B?V2VpbmFuIExpdaOowfXsv+mqo6k=?=

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