From patchwork Fri Oct 2 19:09:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 525755 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 0FEF81402F0 for ; Sat, 3 Oct 2015 05:36:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=mw/v9T0E; dkim-atps=neutral Received: from localhost ([::1]:34711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi67l-0003CU-TE for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 15:36:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5j3-0007c6-PJ for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi5j2-0007fc-6i for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:10:37 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:37842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5j1-0007dD-IF for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:10:35 -0400 Received: by wicfx3 with SMTP id fx3so43187684wic.0 for ; Fri, 02 Oct 2015 12:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=aJpH4FlXcgjD+Y57fY4aZQcr5G10XSjyHhXVLuLaqqc=; b=mw/v9T0EvIYhTBTZb37JASR5uEiR4zA8Cbu5iyXTE3jP4yoiMUW1vQ6L1eu9gavdPq DM8BVga94gpFMQ62OD3/lijGNMS12gajMvofm3a1SAvJWIFJnLl/wZcvq+0CECCFRW8c C8pUNsw+5lt8qwUX/SXSthWpB31bIrVBDSX4t+XvYS3DliebBunwCqsCUvOMVJuNh+e6 AxCijvFEPDJtzTEW9va7zjyl68fQIjisZF+xxuY7Ld8tXpygmw0u6jABeuenz0jQGrcS qp/bkLoAOX9d3OW3ysakWyXf3wbz8d1yqzCpnozeNzvsHtK26woRs0F1UkLWpg9i0QeJ 5RUQ== X-Received: by 10.194.77.240 with SMTP id v16mr17199502wjw.109.1443813034973; Fri, 02 Oct 2015 12:10:34 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id q1sm12701911wje.39.2015.10.02.12.10.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 12:10:34 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 21:09:26 +0200 Message-Id: <1443812991-17356-24-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> References: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::235 Cc: drjones@redhat.com, claudio.fontana@huawei.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, cam@cs.ualberta.ca Subject: [Qemu-devel] [PATCH v5 23/48] ivshmem: migrate with VMStateDescription 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: Marc-André Lureau load_state_old() is used to keep compatibility with version 0. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- hw/misc/ivshmem.c | 142 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 53 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index e678b18..0ccf932 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -651,56 +651,6 @@ static int ivshmem_setup_msi(IVShmemState * s) return 0; } -static void ivshmem_save(QEMUFile* f, void *opaque) -{ - IVShmemState *proxy = opaque; - PCIDevice *pci_dev = PCI_DEVICE(proxy); - - IVSHMEM_DPRINTF("ivshmem_save\n"); - pci_device_save(pci_dev, f); - - if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { - msix_save(pci_dev, f); - } else { - qemu_put_be32(f, proxy->intrstatus); - qemu_put_be32(f, proxy->intrmask); - } - -} - -static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) -{ - IVSHMEM_DPRINTF("ivshmem_load\n"); - - IVShmemState *proxy = opaque; - PCIDevice *pci_dev = PCI_DEVICE(proxy); - int ret; - - if (version_id > 0) { - return -EINVAL; - } - - if (proxy->role_val == IVSHMEM_PEER) { - error_report("'peer' devices are not migratable"); - return -EINVAL; - } - - ret = pci_device_load(pci_dev, f); - if (ret) { - return ret; - } - - if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { - msix_load(pci_dev, f); - ivshmem_use_msix(proxy); - } else { - proxy->intrstatus = qemu_get_be32(f); - proxy->intrmask = qemu_get_be32(f); - } - - return 0; -} - static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val, int len) { @@ -726,8 +676,7 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) } fifo8_create(&s->incoming_fifo, sizeof(long)); - register_savevm(DEVICE(dev), "ivshmem", 0, 0, ivshmem_save, ivshmem_load, - dev); + /* IRQFD requires MSI */ if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) && !ivshmem_has_feature(s, IVSHMEM_MSI)) { @@ -853,10 +802,96 @@ static void pci_ivshmem_exit(PCIDevice *dev) memory_region_del_subregion(&s->bar, &s->ivshmem); vmstate_unregister_ram(&s->ivshmem, DEVICE(dev)); - unregister_savevm(DEVICE(dev), "ivshmem", s); fifo8_destroy(&s->incoming_fifo); } +static bool test_msix(void *opaque, int version_id) +{ + IVShmemState *s = opaque; + + return ivshmem_has_feature(s, IVSHMEM_MSI); +} + +static bool test_no_msix(void *opaque, int version_id) +{ + return !test_msix(opaque, version_id); +} + +static int ivshmem_pre_load(void *opaque) +{ + IVShmemState *s = opaque; + + if (s->role_val == IVSHMEM_PEER) { + error_report("'peer' devices are not migratable"); + return -EINVAL; + } + + return 0; +} + +static int ivshmem_post_load(void *opaque, int version_id) +{ + IVShmemState *s = opaque; + + if (ivshmem_has_feature(s, IVSHMEM_MSI)) { + ivshmem_use_msix(s); + } + + return 0; +} + +static int ivshmem_load_old(QEMUFile *f, void *opaque, int version_id) +{ + IVShmemState *s = opaque; + PCIDevice *pdev = PCI_DEVICE(s); + int ret; + + IVSHMEM_DPRINTF("ivshmem_load_old\n"); + + if (version_id != 0) { + return -EINVAL; + } + + if (s->role_val == IVSHMEM_PEER) { + error_report("'peer' devices are not migratable"); + return -EINVAL; + } + + ret = pci_device_load(pdev, f); + if (ret) { + return ret; + } + + if (ivshmem_has_feature(s, IVSHMEM_MSI)) { + msix_load(pdev, f); + ivshmem_use_msix(s); + } else { + s->intrstatus = qemu_get_be32(f); + s->intrmask = qemu_get_be32(f); + } + + return 0; +} + +static const VMStateDescription ivshmem_vmsd = { + .name = "ivshmem", + .version_id = 1, + .minimum_version_id = 1, + .pre_load = ivshmem_pre_load, + .post_load = ivshmem_post_load, + .fields = (VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_obj, IVShmemState), + + VMSTATE_MSIX_TEST(parent_obj, IVShmemState, test_msix), + VMSTATE_UINT32_TEST(intrstatus, IVShmemState, test_no_msix), + VMSTATE_UINT32_TEST(intrmask, IVShmemState, test_no_msix), + + VMSTATE_END_OF_LIST() + }, + .load_state_old = ivshmem_load_old, + .minimum_version_id_old = 0 +}; + static Property ivshmem_properties[] = { DEFINE_PROP_CHR("chardev", IVShmemState, server_chr), DEFINE_PROP_STRING("size", IVShmemState, sizearg), @@ -882,6 +917,7 @@ static void ivshmem_class_init(ObjectClass *klass, void *data) k->class_id = PCI_CLASS_MEMORY_RAM; dc->reset = ivshmem_reset; dc->props = ivshmem_properties; + dc->vmsd = &ivshmem_vmsd; set_bit(DEVICE_CATEGORY_MISC, dc->categories); }