From patchwork Tue Jul 12 11:08:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 9225085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7F85604DB for ; Tue, 12 Jul 2016 11:11:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A953827CCB for ; Tue, 12 Jul 2016 11:11:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E27227F7A; Tue, 12 Jul 2016 11:11:15 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2F25A27F46 for ; Tue, 12 Jul 2016 11:11:15 +0000 (UTC) Received: from localhost ([::1]:38996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMvas-0002OA-CV for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Jul 2016 07:11:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMvYg-0000Kj-HP for qemu-devel@nongnu.org; Tue, 12 Jul 2016 07:09:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMvYa-0000d4-Cs for qemu-devel@nongnu.org; Tue, 12 Jul 2016 07:08:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMvYa-0000cl-4Y for qemu-devel@nongnu.org; Tue, 12 Jul 2016 07:08:52 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC7B0C04D280; Tue, 12 Jul 2016 11:08:50 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6CB8l2v010815; Tue, 12 Jul 2016 07:08:48 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 12 Jul 2016 13:08:45 +0200 Message-Id: <1468321726-44455-1-git-send-email-imammedo@redhat.com> In-Reply-To: <20160712070617.GO25522@in.ibm.com> References: <20160712070617.GO25522@in.ibm.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 12 Jul 2016 11:08:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] cpu: add migration_id to allow board to provide migration instance_id 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: marcel@redhat.com, pbonzini@redhat.com, bharata@linux.vnet.ibm.com, ehabkost@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Migration breaks if not the last added CPU is removed due to fact that when target QEMU starts it uses cpu_index - 1 as migration instance_id for all CPUs that where added after the removed CPU. Introduce compat property use-migration-id and CPUState::migration_id field to allow board provide an id that doesn't change regardless of the order CPUs are created so that instance_ids on source and target QEMU will match. By default use-migration-id is enabled however CPUState::migration_id isn't set (-1) which forces cpu_exec_init() to use legacy cpu_index so that we don't have to fix all the targets that doesn't support device_add/device_del for CPUs and/or device compat logic. And only targets that whish to support device_add/del for CPUs will set CPUState::migration_id explicitly allwoing them to use stable migration id. If boards sets CPUState::migration_id explictly then for compatibility with old machine types use-migration-id property should be turned off to force usage of cpu_index as instance_id for machine types that used cpu_index for instance_id. Signed-off-by: Igor Mammedov Signed-off-by: Bharata B Rao --- exec.c | 7 +++++-- include/qom/cpu.h | 8 ++++++++ qom/cpu.c | 13 +++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 0122ef7..0eda24b 100644 --- a/exec.c +++ b/exec.c @@ -670,6 +670,7 @@ void cpu_exec_init(CPUState *cpu, Error **errp) { CPUClass *cc = CPU_GET_CLASS(cpu); Error *local_err = NULL; + int migration_id; cpu->as = NULL; cpu->num_ases = 0; @@ -708,11 +709,13 @@ void cpu_exec_init(CPUState *cpu, Error **errp) (void) cc; cpu_list_unlock(); #else + migration_id = cc->use_migration_id && cpu->migration_id != -1 ? + cpu->migration_id : cpu->cpu_index; if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { - vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); + vmstate_register(NULL, migration_id, &vmstate_cpu_common, cpu); } if (cc->vmsd != NULL) { - vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); + vmstate_register(NULL, migration_id, cc->vmsd, cpu); } #endif } diff --git a/include/qom/cpu.h b/include/qom/cpu.h index cacb100..7058fc4 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -115,6 +115,8 @@ struct TranslationBlock; * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF * note to a 32-bit VM coredump. * @vmsd: State description for migration. + * @use_migration_id: Set to use @migration_id if has been set instead of + * cpu_index during vmstate registration. * @gdb_num_core_regs: Number of core registers accessible to GDB. * @gdb_core_xml_file: File name for core registers GDB XML description. * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop @@ -177,6 +179,8 @@ typedef struct CPUClass { void *opaque); const struct VMStateDescription *vmsd; + bool use_migration_id; + int gdb_num_core_regs; const char *gdb_core_xml_file; gchar * (*gdb_arch_name)(CPUState *cpu); @@ -273,6 +277,9 @@ struct qemu_work_item { * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. + * @migration_id: Use as instance_id argument in cpu vmstate_register calls + * by default -1, which forces fallback to using legacy cpu_index even if + * use_migration_id is true * * State of one CPU core or thread. */ @@ -360,6 +367,7 @@ struct CPUState { (absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ uint32_t tcg_exit_req; + int migration_id; }; QTAILQ_HEAD(CPUTailQ, CPUState); diff --git a/qom/cpu.c b/qom/cpu.c index a9727a1..480e0c6 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -357,11 +357,24 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu) return cpu->cpu_index; } +static void cpu_common_set_use_migration_id(Object *obj, bool value, + Error **err) +{ + CPUClass *cc = CPU_GET_CLASS(obj); + cc->use_migration_id = value; +} + static void cpu_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); CPUClass *k = CPU_CLASS(klass); + k->use_migration_id = true; + object_class_property_add_bool(klass, "use-migration-id", + NULL, + cpu_common_set_use_migration_id, + &error_abort); + k->class_by_name = cpu_common_class_by_name; k->parse_features = cpu_common_parse_features; k->reset = cpu_common_reset;