From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB8B0C4338F for ; Wed, 25 Aug 2021 07:38:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 53AF760FD8 for ; Wed, 25 Aug 2021 07:38:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 53AF760FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:38384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mInUw-0000f2-DH for qemu-devel@archiver.kernel.org; Wed, 25 Aug 2021 03:38:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mInSV-0002h9-Tx for qemu-devel@nongnu.org; Wed, 25 Aug 2021 03:36:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mInST-0005QG-Po for qemu-devel@nongnu.org; Wed, 25 Aug 2021 03:36:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629876984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=N9N1ZgNFrW6y6Q0ytNeshhJJC0AGKCdoZJO5Yb2kuS8=; b=MCSIBIiB3ltzRxkXaNU6/9ykQr9B6bJ6MB2cPHvZXUF08juotviyuzVdfbIodbRa1coV2r spOW648z2ZjR1AonHuk1wlNt0vwaAsGQrv2q/xWhMYLsB31zCEWayVVbCe0vacnwYjWHVW 3ldAId/lZslNT/9kjq/W1YGdnD7647U= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-118-HQBS6H_9MEyPJDXEe4s4WA-1; Wed, 25 Aug 2021 03:36:21 -0400 X-MC-Unique: HQBS6H_9MEyPJDXEe4s4WA-1 Received: by mail-pl1-f200.google.com with SMTP id f17-20020a170902ab91b029012c3bac8d81so6753982plr.23 for ; Wed, 25 Aug 2021 00:36:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=N9N1ZgNFrW6y6Q0ytNeshhJJC0AGKCdoZJO5Yb2kuS8=; b=UL90OPu8YUV6AJGU3p608p1S2PPHC/U8wWRXe8ClCpNgc5JAMXX4xByk97/lqPfegT 4FP5CgtwnnYEdk5pVnFajai5GS/4XolKPEQNolmanZzoOfI1pt3+QoE5b5O89V5mTevH n48rQ7MGkZ6SiZEd/AgIZFJg+YpbSPnJmdDE5eHukIU438PwAwh5QDdhgX381Tp3zZQ7 //eimUTPvtSbf46GnQJ+zUKhhdViKpnkqKhAhXmCwsTWlK1YbAVu5TJK47+avy83dGb0 as9TNtYfpdxlx0KbOxhsdhXWVnYwD7pbkNivsBPkQSk6+lT8NYYF6+npsy0RhRO7H+s/ Vd5Q== X-Gm-Message-State: AOAM532AO5rWrFAOC89oehNpQnP75jOCSACIo2IQUsOYSfbfaMGw91ny ETLk8URwulj3IBKYu2Oy5CW7pgsF0lhePPX1wpbzMqI6Zvpk9hGKnqFOrlNILlNYbJ9qZVK8E0h DNEwap17MMTvslb1BvMCZVKL6MCW4w7A= X-Received: by 2002:a17:90a:c798:: with SMTP id gn24mr8805894pjb.97.1629876979905; Wed, 25 Aug 2021 00:36:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy9TYjapnnC9o6aywF7kLmB174EJVkU+6Ntw+tR4emsIjAWC/hoVVnRf3Zu/83NegPxKvq30T6iHNbrkstT4Y= X-Received: by 2002:a17:90a:c798:: with SMTP id gn24mr8805879pjb.97.1629876979676; Wed, 25 Aug 2021 00:36:19 -0700 (PDT) MIME-Version: 1.0 References: <20210824152721.79747-1-peterx@redhat.com> <20210824152721.79747-3-peterx@redhat.com> In-Reply-To: <20210824152721.79747-3-peterx@redhat.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Wed, 25 Aug 2021 11:36:08 +0400 Message-ID: Subject: Re: [PATCH 2/2] dump-guest-memory: Block live migration To: Peter Xu Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mlureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="00000000000066d12705ca5d4e6e" Received-SPF: pass client-ip=170.10.133.124; envelope-from=mlureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , Juan Quintela , qemu-devel , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --00000000000066d12705ca5d4e6e Content-Type: text/plain; charset="UTF-8" Hi On Tue, Aug 24, 2021 at 7:27 PM Peter Xu wrote: > Both dump-guest-memory and live migration caches vm state at the beginning. > Either of them entering the other one will cause race on the vm state, and > even > more severe on that (please refer to the crash report in the bug link). > > Let's block live migration in dump-guest-memory, and that'll also block > dump-guest-memory if it detected that we're during a live migration. > > Side note: migrate_del_blocker() can be called even if the blocker is not > inserted yet, so it's safe to unconditionally delete that blocker in > dump_cleanup (g_slist_remove allows no-entry-found case). > > Suggested-by: Dr. David Alan Gilbert > Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1996609 > Signed-off-by: Peter Xu > --- > dump/dump.c | 20 +++++++++++++++----- > include/sysemu/dump.h | 1 + > 2 files changed, 16 insertions(+), 5 deletions(-) > > diff --git a/dump/dump.c b/dump/dump.c > index ab625909f3..7996d7a6c5 100644 > --- a/dump/dump.c > +++ b/dump/dump.c > @@ -29,6 +29,7 @@ > #include "qemu/error-report.h" > #include "qemu/main-loop.h" > #include "hw/misc/vmcoreinfo.h" > +#include "migration/blocker.h" > > #ifdef TARGET_X86_64 > #include "win_dump.h" > @@ -101,6 +102,7 @@ static int dump_cleanup(DumpState *s) > qemu_mutex_unlock_iothread(); > } > } > + migrate_del_blocker(s->dump_migration_blocker); > > return 0; > } > @@ -1857,6 +1859,19 @@ static void dump_init(DumpState *s, int fd, bool > has_format, > } > } > > + if (!s->dump_migration_blocker) { > + error_setg(&s->dump_migration_blocker, > + "Live migration disabled: dump-guest-memory in > progress"); > + } > + > + /* > + * Allows even for -only-migratable, but forbid migration during the > + * process of dump guest memory. > + */ > + if (migrate_add_blocker_internal(s->dump_migration_blocker, errp)) { > + goto cleanup; > + } > + > Shouldn't this be placed earlier in the function, before runstate_is_running() and vm_stop() ? return; > > cleanup: > @@ -1927,11 +1942,6 @@ void qmp_dump_guest_memory(bool paging, const char > *file, > Error *local_err = NULL; > bool detach_p = false; > > - if (runstate_check(RUN_STATE_INMIGRATE)) { > - error_setg(errp, "Dump not allowed during incoming migration."); > - return; > - } > - > /* if there is a dump in background, we should wait until the dump > * finished */ > if (dump_in_progress()) { > diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h > index 250143cb5a..7b619c2a43 100644 > --- a/include/sysemu/dump.h > +++ b/include/sysemu/dump.h > @@ -195,6 +195,7 @@ typedef struct DumpState { > * finished. */ > uint8_t *guest_note; /* ELF note content */ > size_t guest_note_size; > + Error *dump_migration_blocker; /* Blocker for live migration */ > } DumpState; > > uint16_t cpu_to_dump16(DumpState *s, uint16_t val); > -- > 2.31.1 > > --00000000000066d12705ca5d4e6e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

On Tue, Aug 24, 2021 at 7:27 PM Pet= er Xu <peterx@redhat.com> wr= ote:
Both dump-g= uest-memory and live migration caches vm state at the beginning.
Either of them entering the other one will cause race on the vm state, and = even
more severe on that (please refer to the crash report in the bug link).

Let's block live migration in dump-guest-memory, and that'll also b= lock
dump-guest-memory if it detected that we're during a live migration.
Side note: migrate_del_blocker() can be called even if the blocker is not inserted yet, so it's safe to unconditionally delete that blocker in dump_cleanup (g_slist_remove allows no-entry-found case).

Suggested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.= cgi?id=3D1996609
Signed-off-by: Peter Xu <peterx@redhat.com>
---
=C2=A0dump/dump.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 20 ++++++++++++= +++-----
=C2=A0include/sysemu/dump.h |=C2=A0 1 +
=C2=A02 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index ab625909f3..7996d7a6c5 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -29,6 +29,7 @@
=C2=A0#include "qemu/error-report.h"
=C2=A0#include "qemu/main-loop.h"
=C2=A0#include "hw/misc/vmcoreinfo.h"
+#include "migration/blocker.h"

=C2=A0#ifdef TARGET_X86_64
=C2=A0#include "win_dump.h"
@@ -101,6 +102,7 @@ static int dump_cleanup(DumpState *s)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_mutex_unlock_iothread(= );
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 migrate_del_blocker(s->dump_migration_blocker);

=C2=A0 =C2=A0 =C2=A0return 0;
=C2=A0}
@@ -1857,6 +1859,19 @@ static void dump_init(DumpState *s, int fd, bool has= _format,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0}

+=C2=A0 =C2=A0 if (!s->dump_migration_blocker) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(&s->dump_migration_blocker,<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"= ;Live migration disabled: dump-guest-memory in progress");
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 /*
+=C2=A0 =C2=A0 =C2=A0* Allows even for -only-migratable, but forbid migrati= on during the
+=C2=A0 =C2=A0 =C2=A0* process of dump guest memory.
+=C2=A0 =C2=A0 =C2=A0*/
+=C2=A0 =C2=A0 if (migrate_add_blocker_internal(s->dump_migration_blocke= r, errp)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 goto cleanup;
+=C2=A0 =C2=A0 }
+

Shouldn't this be placed earlier = in the function, before runstate_is_running() and vm_stop() ?

=C2=A0 =C2=A0 =C2=A0return;

=C2=A0cleanup:
@@ -1927,11 +1942,6 @@ void qmp_dump_guest_memory(bool paging, const char *= file,
=C2=A0 =C2=A0 =C2=A0Error *local_err =3D NULL;
=C2=A0 =C2=A0 =C2=A0bool detach_p =3D false;

-=C2=A0 =C2=A0 if (runstate_check(RUN_STATE_INMIGRATE)) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "Dump not allowed during= incoming migration.");
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
-=C2=A0 =C2=A0 }
-
=C2=A0 =C2=A0 =C2=A0/* if there is a dump in background, we should wait unt= il the dump
=C2=A0 =C2=A0 =C2=A0 * finished */
=C2=A0 =C2=A0 =C2=A0if (dump_in_progress()) {
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index 250143cb5a..7b619c2a43 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -195,6 +195,7 @@ typedef struct DumpState {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* finished. */
=C2=A0 =C2=A0 =C2=A0uint8_t *guest_note;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/= * ELF note content */
=C2=A0 =C2=A0 =C2=A0size_t guest_note_size;
+=C2=A0 =C2=A0 Error *dump_migration_blocker; /* Blocker for live migration= */
=C2=A0} DumpState;

=C2=A0uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
--
2.31.1

--00000000000066d12705ca5d4e6e--