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 B6B4BC433EF for ; Wed, 22 Sep 2021 16:50:25 +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 14851611C9 for ; Wed, 22 Sep 2021 16:50:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 14851611C9 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]:55568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5Rw-0006Al-2p for qemu-devel@archiver.kernel.org; Wed, 22 Sep 2021 12:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT57J-0008N9-TR for qemu-devel@nongnu.org; Wed, 22 Sep 2021 12:29:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55115) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT57G-0007bW-U4 for qemu-devel@nongnu.org; Wed, 22 Sep 2021 12:29:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632328142; 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=sO/TeJZnxXfRGkBMXHoOfx8lihPRYtH3YWmNIWFlnXs=; b=IRg1F8h4d0Q6IGid5JYZCvns0eidPbV2iTsF4gt97mOw6NK9bSj5xAm43ZKb9GuNDVNx/T x+TdMCmLo2FG6rN0dqS2vZa+DiNxwJhEeRpt/+RcK6tAJ9S6k94aFjaQqdroORMfuvoXmn ZsvEzXRdUib7pDWt2axIIR0lJcHdLz8= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-nHoVseUFOmqCq0HNH47K5w-1; Wed, 22 Sep 2021 12:29:00 -0400 X-MC-Unique: nHoVseUFOmqCq0HNH47K5w-1 Received: by mail-pj1-f69.google.com with SMTP id rm6-20020a17090b3ec600b0019ce1db4eaeso5624962pjb.5 for ; Wed, 22 Sep 2021 09:29:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sO/TeJZnxXfRGkBMXHoOfx8lihPRYtH3YWmNIWFlnXs=; b=MEt+RDMVTSwPzASYTn7CzozNwCdpSBL9byI11scpRiINVBBeRXP9ZIOybVe1/etFnQ kPM4pY0HsYvLtjOssCvkwfM+lOfGA0lFms5lFK8C0TGc3vhmsAW133cIoZq/OU9hWGDt dPBHMgGufmCgeEHkhJJfiXv1bWADYiendEXSptvDTL8lALnROkAYAxvXO/Hg0dTkINQD 3m3Rsn4ObHKm8HGDpGf6jeepquxyHBKZVDLPdl+3KqxwK62rgmKyEJFPalaAvOADtSMF +Oa0KXdEO6S0WA/K2T8ehrW+rdfYC/RAZamLJWZRJTsppuSK3CvkfFr5swyddUwNRDiD ut3w== X-Gm-Message-State: AOAM532n72y2ikHdCkfYh7q4W05gDdpryFZnNwC9lFz1gLyhprhODgwF BM6pLLrU0kuOYQhrKS0S9FDRE94CjAtSgD1YmzVwFnOPTLge5JQfEBW2yL4Pn7fcgmCUYibh+nH Ppj90VFIK3AZNC0s5ke3T4FnIsdNKyNg= X-Received: by 2002:a05:6a00:10:b0:43e:ede6:2b7 with SMTP id h16-20020a056a00001000b0043eede602b7mr503300pfk.42.1632328139066; Wed, 22 Sep 2021 09:28:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMIWzmexknIZTdC543wLC9ArNuEbFiRAiL3C1wdygvWN9Tr78+Z6seT1A1zEhb10JeAzGdG7s5d6iRF6PM2pA= X-Received: by 2002:a05:6a00:10:b0:43e:ede6:2b7 with SMTP id h16-20020a056a00001000b0043eede602b7mr503272pfk.42.1632328138732; Wed, 22 Sep 2021 09:28:58 -0700 (PDT) MIME-Version: 1.0 References: <20210922162009.125622-1-peterx@redhat.com> <20210922162009.125622-4-peterx@redhat.com> In-Reply-To: <20210922162009.125622-4-peterx@redhat.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Wed, 22 Sep 2021 20:28:47 +0400 Message-ID: Subject: Re: [PATCH v3 3/3] 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="000000000000ddce4f05cc98028f" 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, 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 , Markus Armbruster , qemu-devel , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000ddce4f05cc98028f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Sep 22, 2021 at 8:20 PM Peter Xu wrote: > Both dump-guest-memory and live migration caches vm state at the beginnin= g. > Either of them entering the other one will cause race on the vm state, an= d > 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=3D1996609 > Signed-off-by: Peter Xu > Reviewed-by: Marc-Andr=C3=A9 Lureau --- > dump/dump.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/dump/dump.c b/dump/dump.c > index ab625909f3..662d0a62cd 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" > @@ -47,6 +48,8 @@ > > #define MAX_GUEST_NOTE_SIZE (1 << 20) /* 1MB should be enough */ > > +static Error *dump_migration_blocker; > + > #define ELF_NOTE_SIZE(hdr_size, name_size, desc_size) \ > ((DIV_ROUND_UP((hdr_size), 4) + \ > DIV_ROUND_UP((name_size), 4) + \ > @@ -101,6 +104,7 @@ static int dump_cleanup(DumpState *s) > qemu_mutex_unlock_iothread(); > } > } > + migrate_del_blocker(dump_migration_blocker); > > return 0; > } > @@ -2005,6 +2009,21 @@ void qmp_dump_guest_memory(bool paging, const char > *file, > return; > } > > + if (!dump_migration_blocker) { > + error_setg(&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(dump_migration_blocker, errp)) { > + /* Remember to release the fd before passing it over to dump > state */ > + close(fd); > + return; > + } > + > s =3D &dump_state_global; > dump_state_prepare(s); > > -- > 2.31.1 > > --000000000000ddce4f05cc98028f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Sep 22, 2021 at 8:20 PM Peter= Xu <peterx@redhat.com> wrot= e:
Both dump-gue= st-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>

Revie= wed-by: Marc-Andr=C3=A9 Lureau <marcandre.lureau@redhat.com>

---
=C2=A0dump/dump.c | 19 +++++++++++++++++++
=C2=A01 file changed, 19 insertions(+)

diff --git a/dump/dump.c b/dump/dump.c
index ab625909f3..662d0a62cd 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"
@@ -47,6 +48,8 @@

=C2=A0#define MAX_GUEST_NOTE_SIZE (1 << 20) /* 1MB should be enough *= /

+static Error *dump_migration_blocker;
+
=C2=A0#define ELF_NOTE_SIZE(hdr_size, name_size, desc_size)=C2=A0 =C2=A0\ =C2=A0 =C2=A0 =C2=A0((DIV_ROUND_UP((hdr_size), 4) +=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=A0DIV_ROUND_UP((name_size), 4) +=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
@@ -101,6 +104,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(dump_migration_blocker);

=C2=A0 =C2=A0 =C2=A0return 0;
=C2=A0}
@@ -2005,6 +2009,21 @@ void qmp_dump_guest_memory(bool paging, const char *= file,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
=C2=A0 =C2=A0 =C2=A0}

+=C2=A0 =C2=A0 if (!dump_migration_blocker) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(&dump_migration_blocker,
+=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(dump_migration_blocker, err= p)) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Remember to release the fd before passing i= t over to dump state */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 close(fd);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
+=C2=A0 =C2=A0 }
+
=C2=A0 =C2=A0 =C2=A0s =3D &dump_state_global;
=C2=A0 =C2=A0 =C2=A0dump_state_prepare(s);

--
2.31.1

--000000000000ddce4f05cc98028f--