From patchwork Mon Mar 25 10:15:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Kotov X-Patchwork-Id: 10868769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3ED7513B5 for ; Mon, 25 Mar 2019 10:17:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 276BA2909F for ; Mon, 25 Mar 2019 10:17:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B49D2915F; Mon, 25 Mar 2019 10:17:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F2E12909F for ; Mon, 25 Mar 2019 10:17:17 +0000 (UTC) Received: from localhost ([127.0.0.1]:39949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8MfM-0006uS-G7 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Mar 2019 06:17:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8MeN-0006TR-2Y for qemu-devel@nongnu.org; Mon, 25 Mar 2019 06:16:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h8MeK-00015q-U1 for qemu-devel@nongnu.org; Mon, 25 Mar 2019 06:16:15 -0400 Received: from forwardcorp1j.cmail.yandex.net ([2a02:6b8:0:1630::190]:41177) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h8MeK-00013J-0o for qemu-devel@nongnu.org; Mon, 25 Mar 2019 06:16:12 -0400 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id 755C4206FB; Mon, 25 Mar 2019 13:16:06 +0300 (MSK) Received: from smtpcorp1j.mail.yandex.net (smtpcorp1j.mail.yandex.net [2a02:6b8:0:1619::137]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id VWeRC08Tlg-G5t8sWnI; Mon, 25 Mar 2019 13:16:06 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1553508966; bh=dqWVg7OE7S4CwdelgxG4+cj8l87mzxxDvmlqxxsGYuU=; h=Message-Id:Date:Subject:To:From:Cc; b=LSA8iycQ/JmMngTG5RZyA0H2Vo7vg9HqVJHyB8+fFhprfZH+qlT1tRb9EeWtWzGN0 DUXj4iFBd8dTzAEBQ4l2p+4rKyBmzWnD5h/W/8D1tpuUaWra3g/VzAGYzl89mBYZFn X229Hcjwtg6cr7aZrRCX4opNfqNYqXWpEbWy6w84= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:e931:e4ac:e2d2:8090]) by smtpcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id E19btZGPlm-G5B40RWO; Mon, 25 Mar 2019 13:16:05 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Yury Kotov To: Eduardo Habkost , Igor Mammedov , Juan Quintela , "Dr . David Alan Gilbert" Date: Mon, 25 Mar 2019 13:15:56 +0300 Message-Id: <20190325101556.30227-1-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:6b8:0:1630::190 Subject: [Qemu-devel] [PATCH] hostmem: Disable add/del memory during migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhanghailiang , qemu-devel@nongnu.org, wrfsh@yandex-team.ru, =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP I found a bug in QEMU 2.12 with adding memory-backend while live migration thread is running. But it seems that this bug was implicitly fixed in this commit (QEMU 3.0): b895de50: migration: discard non-migratable RAMBlocks I think it's better to disallow add/del memory backends during migration to to prevent other possible problems. Anyway, user can't use this memory because of disabled hotplug/hotunplug devs. The idea of this commit is the same as that: b06424de: migration: Disable hotplug/unplug memory during migration Backtrace of this bug in QEMU 2.12: 0 find_next_bit (addr=addr@entry=0x0, size=size@entry=262144, offset=offset@entry=0) at util/bitops.c:46 1 migration_bitmap_find_dirty (rs=0x7f58f80008c0, start=0, rb=0x5557e66e3200) at migration/ram.c:816 2 find_dirty_block (again=, pss=, rs=0x7f58f80008c0) at migration/ram.c:1243 3 ram_find_and_save_block (rs=rs@entry=0x7f58f80008c0, last_stage=last_stage@entry=false) at migration/ram.c:1592 4 ram_find_and_save_block (last_stage=false, rs=0x7f58f80008c0) at migration/ram.c:2335 5 ram_save_iterate (f=0x5557e69f1000, opaque=) at migration/ram.c:2338 6 qemu_savevm_state_iterate (f=0x5557e69f1000, postcopy=false) at migration/savevm.c:1191 7 migration_iteration_run (s=0x5557e666b030) at migration/migration.c:2301 8 migration_thread (opaque=0x5557e666b030) at migration/migration.c:2409 9 start_thread (arg=0x7f59055d5700) at pthread_create.c:333 10 clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109 Signed-off-by: Yury Kotov --- backends/hostmem.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index f61093654e..5c71bd3f6b 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -18,6 +18,7 @@ #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qom/object_interfaces.h" +#include "migration/misc.h" #ifdef CONFIG_NUMA #include @@ -271,6 +272,11 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) void *ptr; uint64_t sz; + if (!migration_is_idle()) { + error_setg(errp, "Adding memory-backend isn't allowed while migrating"); + goto out; + } + if (bc->alloc) { bc->alloc(backend, &local_err); if (local_err) { @@ -344,7 +350,8 @@ out: static bool host_memory_backend_can_be_deleted(UserCreatable *uc) { - if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc))) { + if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc)) || + !migration_is_idle()) { return false; } else { return true;