qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Weinan Liu <liu-weinan@qq.com>
Cc: qemu-devel@nongnu.org, dgilbert@redhat.com,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2] KVM: dirty ring: check if vcpu is created before dirty_ring_reap_one
Date: Sun, 5 Feb 2023 18:00:12 -0500	[thread overview]
Message-ID: <Y+A0/GhNplVb5Mnj@x1n> (raw)
In-Reply-To: <tencent_C41A2B79E7EEC277A95730BB7B1C94EDEB06@qq.com>

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



  reply	other threads:[~2023-02-05 23:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-02-06  3:54 =?gb18030?B?V2VpbmFuIExpdaOowfXsv+mqo6k=?=

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y+A0/GhNplVb5Mnj@x1n \
    --to=peterx@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=liu-weinan@qq.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).