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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,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 EF1C4C432BE for ; Fri, 27 Aug 2021 14:53:57 +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 23F2060EB5 for ; Fri, 27 Aug 2021 14:53:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 23F2060EB5 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]:37798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJdEy-0002zF-1K for qemu-devel@archiver.kernel.org; Fri, 27 Aug 2021 10:53:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJdBv-0007am-96 for qemu-devel@nongnu.org; Fri, 27 Aug 2021 10:50:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJdBq-0008KH-Db for qemu-devel@nongnu.org; Fri, 27 Aug 2021 10:50:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630075837; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RF7S9SZ1Ixc8kiSINQmXoTiSrzLGXF10qJYNWSdDwpQ=; b=CQfvdM9OQUBc1sk31qAJbV46+nd9+uBl9XZIf48tPCPzm1tAr0ekPCtzqWX4/aHJ61nSt+ tT4mAM1kbhUeeMn794ma9/Hf9f6GbVvQAszWCc2o7DlrCGeEQknql7i3QrOSZ7qsvuJ+jL RZuLO/zCFY8YJo5vdp5VkAazHMncWLM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109--KdHVBilPdeySLqWuS1pnw-1; Fri, 27 Aug 2021 10:50:36 -0400 X-MC-Unique: -KdHVBilPdeySLqWuS1pnw-1 Received: by mail-qv1-f71.google.com with SMTP id q2-20020ad45ca2000000b00374fa0dbedfso3112283qvh.1 for ; Fri, 27 Aug 2021 07:50:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=RF7S9SZ1Ixc8kiSINQmXoTiSrzLGXF10qJYNWSdDwpQ=; b=IThhUfnGzdd5OfcpuI3pqIWkmmllnY4/yNguwuqrRwV6JQhIqeSWMbFptozHYkQNA2 KoZnY9yfvOfcUn5nyhGyR2K9//T17S9C0uGZwTKFNnWhx/Z5qABVqwfyIZf2ko2T/1tv nxbAeo8pF3lvmzJH4flJBoYgJ6wYByqQTCQZnb0m0g09nerSzCl/wulRy++98bray/Lz ysXnVCKbfxddF69rinGsZnmpQAj+i2MI972dugsBDk3A2NDip49Z45/8xaKIaml6OBLK +wc3k+DKfZxjA4b5xYuggqqqzmyYKk6Ozm2UfA4eOtr4H92jiSFwufnIG9ci8vvxebXo qcWA== X-Gm-Message-State: AOAM5334eTB9my8UrtZuL767X/1itZBLrod2kbIt8ILOrHIXNjHwf4Cb bJMv+kL+2X+eVale4vYJLBXaTl6uT3vRX7OIW35kTzK2ez6SI4HbOOrJ43TpQmFnCMCGeNXIdYx 561OmmtDhiL+yv5Q= X-Received: by 2002:a0c:b356:: with SMTP id a22mr10201701qvf.7.1630075835758; Fri, 27 Aug 2021 07:50:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOT1VJ7ctzYjJynjVvDMBUSa3fATWjKgj5nKNI7/gcVujYsHWYOjVaAF19w1Eok8hpzck0dA== X-Received: by 2002:a0c:b356:: with SMTP id a22mr10201667qvf.7.1630075835475; Fri, 27 Aug 2021 07:50:35 -0700 (PDT) Received: from t490s ([2607:fea8:56a3:500::d413]) by smtp.gmail.com with ESMTPSA id b7sm1893250qtt.12.2021.08.27.07.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Aug 2021 07:50:34 -0700 (PDT) Date: Fri, 27 Aug 2021 10:50:33 -0400 From: Peter Xu To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Subject: Re: [PATCH v2 3/3] dump-guest-memory: Block live migration Message-ID: References: <20210826185813.248441-1-peterx@redhat.com> <20210826185813.248441-4-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@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.743, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 , "Dr . David Alan Gilbert" , Leonardo Bras Soares Passos , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Fri, Aug 27, 2021 at 11:51:04AM +0400, Marc-André Lureau wrote: > Hi > > On Fri, Aug 27, 2021 at 11:44 AM Marc-André Lureau < > marcandre.lureau@redhat.com> wrote: > > > Hi > > > > On Thu, Aug 26, 2021 at 10:58 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 | 24 +++++++++++++++++++----- > >> 1 file changed, 19 insertions(+), 5 deletions(-) > >> > >> diff --git a/dump/dump.c b/dump/dump.c > >> index ab625909f3..9c1c1fb738 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; > >> } > >> @@ -1927,11 +1931,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()) { > >> @@ -2005,6 +2004,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; > >> + } > >> > > > > I would move it earlier. Why not leave it at the beginning of the > > function as it was? > > > > > Ah I think it's because dump_cleanup() isn't called when returning earlier. > But relying on a cleanup done outside of this function is not obvious. > Either dump_cleanup() should be called from here, or the blocker code > should be moved to dump_init() imho. Note that dump_cleanup() cleans s->fd, however fd has not delievered to s->fd now. I can move it into dump_init() but I need to put it after setting s->fd to make dump_cleanup work. That could look a bit weird (as checking migration blocker shouldn't really be bound to initialize of dump states). There's another way to move add blocker to the entry of dump_in_progress() check, however then all the checks between dump_in_progress() and before opening the fd will not be able to "return" directly but we'll need to del the blocker if any of those check fails. That's how I come up with the current patch, which looks the easiest change and still looks clean. Besides, I think dump_in_progress() can be removed too with patch 1 checks SAVEVM state too, however that's a side effect of migration_is_idle() and dump_in_progres is doing the check in different ways by looking up dump state, so I kept it. Thanks, -- Peter Xu