From patchwork Wed Oct 16 02:29:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1177499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 ozlabs.org (Postfix) with ESMTPS id 46tGWG0kjJz9sPK for ; Wed, 16 Oct 2019 13:31:06 +1100 (AEDT) Received: from localhost ([::1]:35220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ5b-0000nv-Jd for incoming@patchwork.ozlabs.org; Tue, 15 Oct 2019 22:31:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59377) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ4U-0000kt-Rz for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:29:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKZ4T-0004hH-7o for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:29:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKZ4S-0004hA-VO for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:29:53 -0400 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B52712C9700 for ; Wed, 16 Oct 2019 02:29:51 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id s24so13302485plp.3 for ; Tue, 15 Oct 2019 19:29:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WsB6+GPp+fmFBmq7NgMarqLazoY9GUczfYpg6g7hXPI=; b=osc5N1PZ98AbC9SJbrASLsoulRWATIZ7g5aL3JZYcW1J7kQEKoZR8K2WPvqytQ40VT 0DYGdaz2YlM/8surQsoeDIdBoGinsb4j9TQwybSk9+WSg6agZm4m2L21J+peibyNQPfL KdSPpR54YAa0S8e6nrwLMqelDeIidT9BEJjRm8cmq+Z35m4lhURkQGBph0uujNfERxIV lbZYQKrtnSxrqe9GqDwPhHkvr6+3Y2DWN6QwzA0XI5gbxE5fithlasfQe42rDMDWx68F VVW5i9X13Ld6/TJKZlQimthc8ZGvfcjs+hvNpu+LcINZgx143Sk6weD4qmiSS6ubkxjy oMaA== X-Gm-Message-State: APjAAAUbTWgMgmA7OM3KddGnJguptRQa6EG+y4gGPHyZ8rwE6buABgXX bMDAvQtNvKme3aaCod8nDjgq1Ny6AU3FU/myoSCK/OJGdYpRbrV6aFuzdmec6NR6Mo+sKmGA18g ZcvSu0nha9wQfjr0= X-Received: by 2002:a17:902:d891:: with SMTP id b17mr39173397plz.310.1571192990486; Tue, 15 Oct 2019 19:29:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEtRPWlaxsx1N0MiSPhOHtnz5iVjmKOMf0zeDKW5ZspoDFtqflapK17LeBGXtEtzgKDPMvKA== X-Received: by 2002:a17:902:d891:: with SMTP id b17mr39173362plz.310.1571192990058; Tue, 15 Oct 2019 19:29:50 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b5sm26175722pfp.38.2019.10.15.19.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 19:29:48 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 1/4] migration: Define VMSTATE_INSTANCE_ID_ANY Date: Wed, 16 Oct 2019 10:29:30 +0800 Message-Id: <20191016022933.7276-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191016022933.7276-1-peterx@redhat.com> References: <20191016022933.7276-1-peterx@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: Eduardo Habkost , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Define the new macro VMSTATE_INSTANCE_ID_ANY for callers who wants to auto-generate the vmstate instance ID. Previously it was hard coded as -1 instead of this macro. It helps to change this default value in the follow up patches. No functional change. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- hw/arm/stellaris.c | 2 +- hw/core/qdev.c | 3 ++- hw/display/ads7846.c | 2 +- hw/i2c/core.c | 2 +- hw/input/stellaris_input.c | 3 ++- hw/intc/apic_common.c | 2 +- hw/misc/max111x.c | 2 +- hw/net/eepro100.c | 2 +- hw/pci/pci.c | 2 +- hw/ppc/spapr.c | 2 +- hw/timer/arm_timer.c | 2 +- hw/tpm/tpm_emulator.c | 3 ++- include/migration/vmstate.h | 2 ++ migration/savevm.c | 8 ++++---- 14 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index b198066b54..bb025e0bd0 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -708,7 +708,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq, memory_region_init_io(&s->iomem, NULL, &ssys_ops, s, "ssys", 0x00001000); memory_region_add_subregion(get_system_memory(), base, &s->iomem); ssys_reset(s); - vmstate_register(NULL, -1, &vmstate_stellaris_sys, s); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_stellaris_sys, s); return 0; } diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cbad6c1d55..86031f961d 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -866,7 +866,8 @@ static void device_set_realized(Object *obj, bool value, Error **errp) dev->canonical_path = object_get_canonical_path(OBJECT(dev)); if (qdev_get_vmsd(dev)) { - if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev, + if (vmstate_register_with_alias_id(dev, VMSTATE_INSTANCE_ID_ANY, + qdev_get_vmsd(dev), dev, dev->instance_id_alias, dev->alias_required_for_version, &local_err) < 0) { diff --git a/hw/display/ads7846.c b/hw/display/ads7846.c index c12272ae72..9228b40b1a 100644 --- a/hw/display/ads7846.c +++ b/hw/display/ads7846.c @@ -154,7 +154,7 @@ static void ads7846_realize(SSISlave *d, Error **errp) ads7846_int_update(s); - vmstate_register(NULL, -1, &vmstate_ads7846, s); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_ads7846, s); } static void ads7846_class_init(ObjectClass *klass, void *data) diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 92cd489069..d770035ba0 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -61,7 +61,7 @@ I2CBus *i2c_init_bus(DeviceState *parent, const char *name) bus = I2C_BUS(qbus_create(TYPE_I2C_BUS, parent, name)); QLIST_INIT(&bus->current_devs); - vmstate_register(NULL, -1, &vmstate_i2c_bus, bus); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_i2c_bus, bus); return bus; } diff --git a/hw/input/stellaris_input.c b/hw/input/stellaris_input.c index 59892b07fc..e6ee5e11f1 100644 --- a/hw/input/stellaris_input.c +++ b/hw/input/stellaris_input.c @@ -88,5 +88,6 @@ void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode) } s->num_buttons = n; qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s); - vmstate_register(NULL, -1, &vmstate_stellaris_gamepad, s); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, + &vmstate_stellaris_gamepad, s); } diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index aafd8e0e33..22da53ce8a 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -331,7 +331,7 @@ static void apic_common_realize(DeviceState *dev, Error **errp) } if (s->legacy_instance_id) { - instance_id = -1; + instance_id = VMSTATE_INSTANCE_ID_ANY; } vmstate_register_with_alias_id(NULL, instance_id, &vmstate_apic_common, s, -1, 0, NULL); diff --git a/hw/misc/max111x.c b/hw/misc/max111x.c index a713149f16..81ee73e0da 100644 --- a/hw/misc/max111x.c +++ b/hw/misc/max111x.c @@ -146,7 +146,7 @@ static int max111x_init(SSISlave *d, int inputs) s->input[7] = 0x80; s->com = 0; - vmstate_register(dev, -1, &vmstate_max111x, s); + vmstate_register(dev, VMSTATE_INSTANCE_ID_ANY, &vmstate_max111x, s); return 0; } diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index cc2dd8b1c9..39920c6dc5 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1874,7 +1874,7 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp) s->vmstate = g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100)); s->vmstate->name = qemu_get_queue(s->nic)->model; - vmstate_register(&pci_dev->qdev, -1, s->vmstate, s); + vmstate_register(&pci_dev->qdev, VMSTATE_INSTANCE_ID_ANY, s->vmstate, s); } static void eepro100_instance_init(Object *obj) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index aa05c2b9b2..708f66aac3 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -122,7 +122,7 @@ static void pci_bus_realize(BusState *qbus, Error **errp) bus->machine_done.notify = pcibus_machine_done; qemu_add_machine_init_done_notifier(&bus->machine_done); - vmstate_register(NULL, -1, &vmstate_pcibus, bus); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus); } static void pcie_bus_realize(BusState *qbus, Error **errp) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 514a17ae74..a316399ae9 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3029,7 +3029,7 @@ static void spapr_machine_init(MachineState *machine) * interface, this is a legacy from the sPAPREnvironment structure * which predated MachineState but had a similar function */ vmstate_register(NULL, 0, &vmstate_spapr, spapr); - register_savevm_live("spapr/htab", -1, 1, + register_savevm_live("spapr/htab", VMSTATE_INSTANCE_ID_ANY, 1, &savevm_htab_handlers, spapr); qbus_set_hotplug_handler(sysbus_get_default(), OBJECT(machine), diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c index c2e6211188..1e9dea451a 100644 --- a/hw/timer/arm_timer.c +++ b/hw/timer/arm_timer.c @@ -174,7 +174,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq) bh = qemu_bh_new(arm_timer_tick, s); s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT); - vmstate_register(NULL, -1, &vmstate_arm_timer, s); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_arm_timer, s); return s; } diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 22f9113432..da7b490489 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -914,7 +914,8 @@ static void tpm_emulator_inst_init(Object *obj) tpm_emu->cur_locty_number = ~0; qemu_mutex_init(&tpm_emu->mutex); - vmstate_register(NULL, -1, &vmstate_tpm_emulator, obj); + vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, + &vmstate_tpm_emulator, obj); } /* diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1fbfd099dd..c551470299 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1113,6 +1113,8 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); +#define VMSTATE_INSTANCE_ID_ANY -1 + /* Returns: 0 on success, -1 on failure */ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, diff --git a/migration/savevm.c b/migration/savevm.c index bb9462a54d..0074572a52 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -750,7 +750,7 @@ int register_savevm_live(const char *idstr, pstrcat(se->idstr, sizeof(se->idstr), idstr); - if (instance_id == -1) { + if (instance_id == VMSTATE_INSTANCE_ID_ANY) { se->instance_id = calculate_new_instance_id(se->idstr); } else { se->instance_id = instance_id; @@ -817,14 +817,14 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, se->compat = g_new0(CompatEntry, 1); pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), vmsd->name); - se->compat->instance_id = instance_id == -1 ? + se->compat->instance_id = instance_id == VMSTATE_INSTANCE_ID_ANY ? calculate_compat_instance_id(vmsd->name) : instance_id; - instance_id = -1; + instance_id = VMSTATE_INSTANCE_ID_ANY; } } pstrcat(se->idstr, sizeof(se->idstr), vmsd->name); - if (instance_id == -1) { + if (instance_id == VMSTATE_INSTANCE_ID_ANY) { se->instance_id = calculate_new_instance_id(se->idstr); } else { se->instance_id = instance_id; From patchwork Wed Oct 16 02:29:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1177500 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 ozlabs.org (Postfix) with ESMTPS id 46tGWM6ynsz9sPK for ; Wed, 16 Oct 2019 13:31:11 +1100 (AEDT) Received: from localhost ([::1]:35230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ5h-0000u7-Kv for incoming@patchwork.ozlabs.org; Tue, 15 Oct 2019 22:31:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59388) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ4Z-0000pN-2D for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKZ4X-0004hi-LR for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:29:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41594) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKZ4X-0004hb-DV for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:29:57 -0400 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 769B3C053B34 for ; Wed, 16 Oct 2019 02:29:55 +0000 (UTC) Received: by mail-pl1-f200.google.com with SMTP id g20so13272467plj.15 for ; Tue, 15 Oct 2019 19:29:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K5cy6JJY+zB2GpBFbTkVr/75+7PfK1teCD0nP9Cqyf4=; b=fM5aqNJ+ICy4Pedb5PZz+xyc5ntg2KFbRt4EXIBl1zAqESQDa82ozRqX7P+6V8iIZr jYCp8HytU1q90sF8mg8NyBnm4APctXhQmz/6wgxAh5ZplT/zNxEN1JKU6MVnC8IR76Vl TWIFnsn1bbBjlePTf43CnKxZaR63sMQBHTkEQgwrHtpzP/Szr3O1bkp5tbprdtndQLSM wkClELq/idxpEnCEu4OGjiMUN/LdLH2vG1pxwWSy8CVws/27DQFsWjWdJ6vygXgQ7dbI g0AGBdxSyU71lJAoR6QQZFrTNlkZ9yWAngknDmMGnX7TplKi1a3WPFj8diYmOd8FYeWl K+Pg== X-Gm-Message-State: APjAAAWS6a1rHwSjBEmvDir02CRQCjy9WhAiHTha1c4QDJQ9kzw65xjW 4zqzrBZ/RW2Rf9nQSToW5ZiTKQIsp4rPCt8lbkkM3fzpYZnsdU2nvuOTQS3abhwznqskJyxp0lj 230On8Kfa2V8f8R0= X-Received: by 2002:a62:5ec6:: with SMTP id s189mr41559756pfb.169.1571192994297; Tue, 15 Oct 2019 19:29:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPfhT63lhjF4WZBKeGg7GND0dSlS5Nz15qwL/MFr7hzgwLu+ua+hCx1RERpERXGxL8BBrA0w== X-Received: by 2002:a62:5ec6:: with SMTP id s189mr41559726pfb.169.1571192993983; Tue, 15 Oct 2019 19:29:53 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b5sm26175722pfp.38.2019.10.15.19.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 19:29:53 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 2/4] migration: Change SaveStateEntry.instance_id into uint32_t Date: Wed, 16 Oct 2019 10:29:31 +0800 Message-Id: <20191016022933.7276-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191016022933.7276-1-peterx@redhat.com> References: <20191016022933.7276-1-peterx@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: Eduardo Habkost , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It was always used as 32bit, so define it as used to be clear. Instead of using -1 as the auto-gen magic value, we switch to UINT32_MAX. We also make sure that we don't auto-gen this value to avoid overflowed instance IDs without being noticed. Suggested-by: Juan Quintela Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- hw/intc/apic_common.c | 2 +- include/migration/register.h | 2 +- include/migration/vmstate.h | 6 +++--- migration/savevm.c | 18 ++++++++++-------- stubs/vmstate.c | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 22da53ce8a..fabfa7320b 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -315,7 +315,7 @@ static void apic_common_realize(DeviceState *dev, Error **errp) APICCommonState *s = APIC_COMMON(dev); APICCommonClass *info; static DeviceState *vapic; - int instance_id = s->id; + uint32_t instance_id = s->id; info = APIC_COMMON_GET_CLASS(s); info->realize(dev, errp); diff --git a/include/migration/register.h b/include/migration/register.h index a13359a08d..f3ba10b6ef 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -69,7 +69,7 @@ typedef struct SaveVMHandlers { } SaveVMHandlers; int register_savevm_live(const char *idstr, - int instance_id, + uint32_t instance_id, int version_id, const SaveVMHandlers *ops, void *opaque); diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index c551470299..67bc63e30e 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1113,17 +1113,17 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); -#define VMSTATE_INSTANCE_ID_ANY -1 +#define VMSTATE_INSTANCE_ID_ANY UINT32_MAX /* Returns: 0 on success, -1 on failure */ -int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, +int vmstate_register_with_alias_id(DeviceState *dev, uint32_t instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, Error **errp); /* Returns: 0 on success, -1 on failure */ -static inline int vmstate_register(DeviceState *dev, int instance_id, +static inline int vmstate_register(DeviceState *dev, uint32_t instance_id, const VMStateDescription *vmsd, void *opaque) { diff --git a/migration/savevm.c b/migration/savevm.c index 0074572a52..1e44f06d7a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -233,7 +233,7 @@ typedef struct CompatEntry { typedef struct SaveStateEntry { QTAILQ_ENTRY(SaveStateEntry) entry; char idstr[256]; - int instance_id; + uint32_t instance_id; int alias_id; int version_id; /* version id read from the stream */ @@ -665,10 +665,10 @@ void dump_vmstate_json_to_file(FILE *out_file) fclose(out_file); } -static int calculate_new_instance_id(const char *idstr) +static uint32_t calculate_new_instance_id(const char *idstr) { SaveStateEntry *se; - int instance_id = 0; + uint32_t instance_id = 0; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (strcmp(idstr, se->idstr) == 0 @@ -676,6 +676,8 @@ static int calculate_new_instance_id(const char *idstr) instance_id = se->instance_id + 1; } } + /* Make sure we never loop over without being noticed */ + assert(instance_id != VMSTATE_INSTANCE_ID_ANY); return instance_id; } @@ -730,7 +732,7 @@ static void savevm_state_handler_insert(SaveStateEntry *nse) Meanwhile pass -1 as instance_id if you do not already have a clearly distinguishing id for all instances of your device class. */ int register_savevm_live(const char *idstr, - int instance_id, + uint32_t instance_id, int version_id, const SaveVMHandlers *ops, void *opaque) @@ -784,7 +786,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) } } -int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, +int vmstate_register_with_alias_id(DeviceState *dev, uint32_t instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, int required_for_version, @@ -1566,7 +1568,7 @@ int qemu_save_device_state(QEMUFile *f) return qemu_file_get_error(f); } -static SaveStateEntry *find_se(const char *idstr, int instance_id) +static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id) { SaveStateEntry *se; @@ -2235,7 +2237,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) /* Find savevm section */ se = find_se(idstr, instance_id); if (se == NULL) { - error_report("Unknown savevm section or instance '%s' %d. " + error_report("Unknown savevm section or instance '%s' %"PRIu32". " "Make sure that your current VM setup matches your " "saved VM setup, including any hotplugged devices", idstr, instance_id); @@ -2259,7 +2261,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) ret = vmstate_load(f, se); if (ret < 0) { - error_report("error while loading state for instance 0x%x of" + error_report("error while loading state for instance 0x%"PRIx32" of" " device '%s'", instance_id, idstr); return ret; } diff --git a/stubs/vmstate.c b/stubs/vmstate.c index e1e89b87f0..4ed5cc6e9e 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -4,7 +4,7 @@ const VMStateDescription vmstate_dummy = {}; int vmstate_register_with_alias_id(DeviceState *dev, - int instance_id, + uint32_t instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, From patchwork Wed Oct 16 02:29:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1177501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 ozlabs.org (Postfix) with ESMTPS id 46tGZN6Rbkz9sPT for ; Wed, 16 Oct 2019 13:33:48 +1100 (AEDT) Received: from localhost ([::1]:35258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ8E-0003i4-Od for incoming@patchwork.ozlabs.org; Tue, 15 Oct 2019 22:33:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59399) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ4b-0000tg-Qu for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKZ4a-0004iC-QA for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51202) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKZ4a-0004hz-IR for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:00 -0400 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B73DE2C9700 for ; Wed, 16 Oct 2019 02:29:59 +0000 (UTC) Received: by mail-pl1-f199.google.com with SMTP id p15so13282660plq.4 for ; Tue, 15 Oct 2019 19:29:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/iRm9HUr6JYJw4fy1c/Q5gUGngMsEsoru2kz/1lERVE=; b=Dbs/gEHWzHKZd1r8WEJ6DwzJxxfTB5VqRlS0YeTTQZLdr6P4kdt71m+P/S32R8+vva vsaulv8rziKJqqlUYHcsRlbnPswLHqJwF4SgEiRziYnImdmPZuHNUI2T66d4VbZXSUl6 3QtmaE8oCVImabvcqNSqMJwQoxb0A6st0uZgLBcUiVcJ1669WbaXAvJu2adLsDtX6FaO BtcyzOkjenCM6UYd8m+q4F2yuIqGkC9p9p1dh9E00d8ik+8OoRo9mZOzPJho1L57dxnC JICILnaDXQU6FeFMabrxUMzglT9PBpJkSPPA6J022ua+DZxLcIbItvZaapqq6KznXF9a +YEw== X-Gm-Message-State: APjAAAXJ0FNuXMeRRHHuJOXSeDSHVaqg8b3QnQprNC+8OPa7ztaNvTYh 1Qnww1N5bgprc0GdkA/zfSdbP12c/zCUR1+wyVseDTTYiuQSKAuElmwvJzi4hupEbza+ogY7fdO syhu4qyE6p8qd2hs= X-Received: by 2002:a63:709:: with SMTP id 9mr42039213pgh.445.1571192998330; Tue, 15 Oct 2019 19:29:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYCK/aIuxM4vkBbYw/XDl8N67HeBje9kTQLAGWe6y8mdMpudqkDrupZ0HeUETXWWeBEbWjTg== X-Received: by 2002:a63:709:: with SMTP id 9mr42039179pgh.445.1571192998031; Tue, 15 Oct 2019 19:29:58 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b5sm26175722pfp.38.2019.10.15.19.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 19:29:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 3/4] apic: Use 32bit APIC ID for migration instance ID Date: Wed, 16 Oct 2019 10:29:32 +0800 Message-Id: <20191016022933.7276-4-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191016022933.7276-1-peterx@redhat.com> References: <20191016022933.7276-1-peterx@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: Eduardo Habkost , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Migration is silently broken now with x2apic config like this: -smp 200,maxcpus=288,sockets=2,cores=72,threads=2 \ -device intel-iommu,intremap=on,eim=on After migration, the guest kernel could hang at anything, due to x2apic bit not migrated correctly in IA32_APIC_BASE on some vcpus, so any operations related to x2apic could be broken then (e.g., RDMSR on x2apic MSRs could fail because KVM would think that the vcpu hasn't enabled x2apic at all). The issue is that the x2apic bit was never applied correctly for vcpus whose ID > 255 when migrate completes, and that's because when we migrate APIC we use the APICCommonState.id as instance ID of the migration stream, while that's too short for x2apic. Let's use the newly introduced initial_apic_id for that. Signed-off-by: Peter Xu Reviewed-by: Eduardo Habkost Reviewed-by: Juan Quintela --- hw/intc/apic_common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index fabfa7320b..f0d88a1b14 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -315,7 +315,10 @@ static void apic_common_realize(DeviceState *dev, Error **errp) APICCommonState *s = APIC_COMMON(dev); APICCommonClass *info; static DeviceState *vapic; - uint32_t instance_id = s->id; + uint32_t instance_id = s->initial_apic_id; + + /* Normally initial APIC ID should be no more than hundreds */ + assert(instance_id != VMSTATE_INSTANCE_ID_ANY); info = APIC_COMMON_GET_CLASS(s); info->realize(dev, errp); From patchwork Wed Oct 16 02:29:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1177503 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 ozlabs.org (Postfix) with ESMTPS id 46tGb33qQyz9sPK for ; Wed, 16 Oct 2019 13:34:23 +1100 (AEDT) Received: from localhost ([::1]:35270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ8n-0004X2-Cz for incoming@patchwork.ozlabs.org; Tue, 15 Oct 2019 22:34:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59411) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKZ4f-0000yt-Hm for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKZ4e-0004kj-DM for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKZ4e-0004kb-4w for qemu-devel@nongnu.org; Tue, 15 Oct 2019 22:30:04 -0400 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F44E2A09AE for ; Wed, 16 Oct 2019 02:30:03 +0000 (UTC) Received: by mail-pf1-f198.google.com with SMTP id 194so17518956pfu.3 for ; Tue, 15 Oct 2019 19:30:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7bd+lVFSE5RnEgJZXIACTVDkbxanzqoTb19QHbkBI5s=; b=mqs0iMiKIPQF2+Xhv8GIerVyJjeg+8MkMu08cgo+uq/CH/r5sKUVJKy9gbtipFqcT1 cdXGzrYddig0BXIkiaKp77DNJcUbhC2YhQqKea7aTqV+cp/QmhMP2ZAbLrvog8qgwDk/ pBQbs3fZ5Jzsj0KisOf5bC9PvgMBQ0hfgtZNKtSpgx/hf1airoE82us7vlnqQxZ2TNdk ld6Z9BLBGpbgAqFUnQvicpcyCenVxGMhMsLFWoHrV55DTH4tQUqwKDRF/Y8CT3iQm3xv UvA9Wgvc3ltx9YROqee1/O4FiGP48NHUseej8oR0TGcpobxgcPYZBcr74Z7kXWtE+C6z R6BA== X-Gm-Message-State: APjAAAU0NqGaSxNrb4yXOKyvkxXnuQAcG/dTxTJIZXHBYLMxvKoGzepx cQpa3iJ+w9iG8P+0ka/imQ1a+1a2/V2hjSgBBIvNDCOj75r8SN82rG7nhtr5P4QzJgdkV0pLwkx Bewik0Dm0oy3r800= X-Received: by 2002:a17:90b:288:: with SMTP id az8mr1980584pjb.18.1571193002355; Tue, 15 Oct 2019 19:30:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdkpSdsV62EU9GADl1SOVDSbmhziF/4LpFB6fp9yUchi9Ia/Pd3Yfewl5GU9xHcClA3ln5Uw== X-Received: by 2002:a17:90b:288:: with SMTP id az8mr1980563pjb.18.1571193002133; Tue, 15 Oct 2019 19:30:02 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b5sm26175722pfp.38.2019.10.15.19.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 19:30:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 4/4] migration: Check in savevm_state_handler_insert for dups Date: Wed, 16 Oct 2019 10:29:33 +0800 Message-Id: <20191016022933.7276-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191016022933.7276-1-peterx@redhat.com> References: <20191016022933.7276-1-peterx@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: Eduardo Habkost , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Before finally register one SaveStateEntry, we detect for duplicated entries. This could be helpful to notify us asap instead of get silent migration failures which could be hard to diagnose. For example, this patch will generate a message like this (if without previous fixes on x2apic) as long as we wants to boot a VM instance with "-smp 200,maxcpus=288,sockets=2,cores=72,threads=2" and QEMU will bail out even before VM starts: savevm_state_handler_insert: Detected duplicate SaveStateEntry: id=apic, instance_id=0x0 Suggested-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- migration/savevm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 1e44f06d7a..83e91ddafa 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -264,6 +264,8 @@ static SaveState savevm_state = { .global_section_id = 0, }; +static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id); + static bool should_validate_capability(int capability) { assert(capability >= 0 && capability < MIGRATION_CAPABILITY__MAX); @@ -714,6 +716,18 @@ static void savevm_state_handler_insert(SaveStateEntry *nse) assert(priority <= MIG_PRI_MAX); + /* + * This should never happen otherwise migration will probably fail + * silently somewhere because we can be wrongly applying one + * object properties upon another one. Bail out ASAP. + */ + if (find_se(nse->idstr, nse->instance_id)) { + error_report("%s: Detected duplicate SaveStateEntry: " + "id=%s, instance_id=0x%"PRIx32, __func__, + nse->idstr, nse->instance_id); + exit(EXIT_FAILURE); + } + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (save_state_priority(se) < priority) { break;