From patchwork Mon Jul 28 15:35:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 374258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1BA0D14009E for ; Tue, 29 Jul 2014 01:39:39 +1000 (EST) Received: from localhost ([::1]:40359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XBn1V-0001gQ-2U for incoming@patchwork.ozlabs.org; Mon, 28 Jul 2014 11:39:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XBmxE-0003Qp-1Q for qemu-devel@nongnu.org; Mon, 28 Jul 2014 11:35:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XBmx6-0006cJ-Gg for qemu-devel@nongnu.org; Mon, 28 Jul 2014 11:35:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XBmx6-0006ZL-7A for qemu-devel@nongnu.org; Mon, 28 Jul 2014 11:35:04 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6SFYvTe020259 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jul 2014 11:34:57 -0400 Received: from redhat.com (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id s6SFYqxe032333; Mon, 28 Jul 2014 11:34:53 -0400 Date: Mon, 28 Jul 2014 17:35:11 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1406561650-29995-2-git-send-email-mst@redhat.com> References: <1406561650-29995-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1406561650-29995-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Juan Quintela , Alexey Kardashevskiy , Alexander Graf , Markus Armbruster , Orit Wasserman , Gonglei , Gerd Hoffmann , imammedo@redhat.com, pbonzini@redhat.com, Laszlo Ersek , =?us-ascii?B?PT9VVEYtOD9xP0FuZHJlYXM9MjBGPUMzPUE0cmJlcj89?= , "Dr. David Alan Gilbert" Subject: [Qemu-devel] [PATCH 2/3] migration: load smaller RAMBlock to a bigger one if permitted X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Igor Mammedov Add API to mark memory region as extend-able on migration, to allow migration code to load smaller RAMBlock into a bigger one on destination QEMU instance. This will allow to fix broken migration from QEMU 1.7/2.0 to QEMU 2.1 due to ACPI tables size changes across 1.7/2.0/2.1 versions by marking ACPI tables ROM blob as extend-able. So that smaller tables from previous version could be always migrated to a bigger rom blob on new version. Credits-for-idea: Michael S. Tsirkin Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 11 +++++++++++ include/exec/ram_addr.h | 3 +++ arch_init.c | 22 +++++++++++++++++----- exec.c | 8 ++++++++ memory.c | 5 +++++ 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index e2c8e3e..f96ddbb 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -894,6 +894,17 @@ bool memory_region_present(MemoryRegion *container, hwaddr addr); bool memory_region_is_mapped(MemoryRegion *mr); /** + * memory_region_permit_extendable_migration: marks #MemoryRegion + * as extendable on migration, allowing the migration code to load + * source memory block of smaller size than destination memory block + * at migration time + * + * @mr: a #MemoryRegion whose #RAMBlock should be marked as + * extendable on migration + */ +void memory_region_permit_extendable_migration(MemoryRegion *mr); + +/** * memory_region_find: translate an address/size relative to a * MemoryRegion into a #MemoryRegionSection. * diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 6593be1..7a6b782 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -34,6 +34,9 @@ void *qemu_get_ram_ptr(ram_addr_t addr); void qemu_ram_free(ram_addr_t addr); void qemu_ram_free_from_ptr(ram_addr_t addr); +#define RAM_EXTENDABLE_ON_MIGRATE (1U << 31) +void qemu_ram_set_extendable_on_migration(ram_addr_t addr); + static inline bool cpu_physical_memory_get_dirty(ram_addr_t start, ram_addr_t length, unsigned client) diff --git a/arch_init.c b/arch_init.c index 8ddaf35..2c0c238 100644 --- a/arch_init.c +++ b/arch_init.c @@ -1071,11 +1071,23 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (!strncmp(id, block->idstr, sizeof(id))) { - if (block->length != length) { - error_report("Length mismatch: %s: " RAM_ADDR_FMT - " in != " RAM_ADDR_FMT, id, length, - block->length); - ret = -EINVAL; + if (block->flags & RAM_EXTENDABLE_ON_MIGRATE) { + if (block->length < length) { + error_report("Length too big: %s: " RAM_ADDR_FMT + " in > " RAM_ADDR_FMT, id, length, + block->length); + ret = -EINVAL; + } else { + memset(block->host, 0, block->length); + } + } else { + if (block->length != length) { + error_report("Length mismatch: %s: " + RAM_ADDR_FMT " in != " + RAM_ADDR_FMT, + id, length, block->length); + ret = -EINVAL; + } } break; } diff --git a/exec.c b/exec.c index 765bd94..02536f8e 100644 --- a/exec.c +++ b/exec.c @@ -1214,6 +1214,14 @@ void qemu_ram_unset_idstr(ram_addr_t addr) } } +void qemu_ram_set_extendable_on_migration(ram_addr_t addr) +{ + RAMBlock *block = find_ram_block(addr); + + assert(block != NULL); + block->flags |= RAM_EXTENDABLE_ON_MIGRATE; +} + static int memory_try_enable_merging(void *addr, size_t len) { if (!qemu_opt_get_bool(qemu_get_machine_opts(), "mem-merge", true)) { diff --git a/memory.c b/memory.c index 64d7176..744c746 100644 --- a/memory.c +++ b/memory.c @@ -1791,6 +1791,11 @@ bool memory_region_is_mapped(MemoryRegion *mr) return mr->container ? true : false; } +void memory_region_permit_extendable_migration(MemoryRegion *mr) +{ + qemu_ram_set_extendable_on_migration(mr->ram_addr); +} + MemoryRegionSection memory_region_find(MemoryRegion *mr, hwaddr addr, uint64_t size) {