From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41BDBECE58E for ; Thu, 10 Oct 2019 12:55:23 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 192C42067B for ; Thu, 10 Oct 2019 12:55:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 192C42067B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIXyU-0002IU-7p for qemu-devel@archiver.kernel.org; Thu, 10 Oct 2019 08:55:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55368) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIXIZ-0005Ur-Vk for qemu-devel@nongnu.org; Thu, 10 Oct 2019 08:12:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIXIX-00022M-8c for qemu-devel@nongnu.org; Thu, 10 Oct 2019 08:12:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIXIW-00022C-W9 for qemu-devel@nongnu.org; Thu, 10 Oct 2019 08:12:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7D4C1DD3; Thu, 10 Oct 2019 12:11:59 +0000 (UTC) Received: from [10.36.116.245] (ovpn-116-245.ams2.redhat.com [10.36.116.245]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA63760A9F; Thu, 10 Oct 2019 12:11:48 +0000 (UTC) Subject: Re: [PATCH v3] migration: Support gtree migration To: Peter Xu References: <20191004112025.28868-1-eric.auger@redhat.com> <20191009062852.GB1039@xz-x1> <27d37e80-31d8-006a-b2a8-c61c5129c7c4@redhat.com> <20191010113541.GG18958@xz-x1> From: Auger Eric Message-ID: Date: Thu, 10 Oct 2019 14:11:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20191010113541.GG18958@xz-x1> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Thu, 10 Oct 2019 12:11:59 +0000 (UTC) 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: quintela@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com, eric.auger.pro@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Hi Peter, On 10/10/19 1:35 PM, Peter Xu wrote: > On Thu, Oct 10, 2019 at 09:57:01AM +0200, Auger Eric wrote: >>>> +static gboolean put_gtree_elem(gpointer key, gpointer value, gpointer data) >>>> +{ >>>> + struct put_gtree_data *capsule = (struct put_gtree_data *)data; >>>> + QEMUFile *f = capsule->f; >>>> + int ret; >>>> + >>>> + qemu_put_byte(f, true); >>>> + >>>> + /* put the key */ >>>> + if (!capsule->key_vmsd) { >>>> + qemu_put_be32(f, GPOINTER_TO_UINT(key)); /* direct key */ >>> >>> This is special code path for direct key case. Can we simply define >>> VMSTATE_GTREE_DIRECT_KEY_V() somehow better so that it just uses the >>> VMSTATE_UINT32_V() as the key vmsd? Then iiuc vmstate_save_state() >>> could work well with that too. >> if the key_vmsd is a VMSTATE_UINT32_V then I understand >> vmstate_save_state(f, capsule->key_vmsd, key, capsule->vmdesc) >> expects key to be a pointer to a uint32. But in that case of direct key, >> it is a uint32. I don't figure out how to use vmstate_save_state in your >> proposal. > > Ah I see the point. And indeed I can't think of a better way now > (e.g., maybe I will always try to use GTrees with malloc()ed keys to > be simple when I want to migrate a gtree, but yeah that's not a reason > to refuse this patch :). > > Though we should be very careful on defining vmsds for GTrees in the > future with the help of this patch, and we must have the type (either > direct or not) to match the real usage of the tree otherwise QEMU can > potentially unreference the constant as a pointer. > >> >>> >>> Also, should we avoid using UINT in all cases? But of course if we >>> start to use VMSTATE_UINT32_V then we don't have this issue. >> Depending on the clarification of above point, maybe I can rename >> VMSTATE_GTREE_DIRECT_KEY_V into VMSTATE_GTREE_DIRECT_UINT_KEY_V >> >> direct keys seem to be more common for hash tables actually. >> https://developer.gnome.org/glib/stable/glib-Hash-Tables.html#g-hash-table-new-full >> >> There are stand conversion macros to/from int, uint, size >> https://developer.gnome.org/glib/stable/glib-Type-Conversion-Macros.html > > Yeh it's fine to use direct keys. Though my question was more about > "unsigned int" - here when we put, we cast a pointer into unsigned > int, which can be 2/4 bytes, IIUC. I'm thinking whether at least we > should use direct cast (e.g., (uint32_t)ptr) to replace > GPOINTER_TO_UINT() to make sure it's 4 bytes. Futher, maybe we should > start with uint64_t here in the migration stream, otherwise we should > probably drop the high 32 bits if we migrate a gtree whose key is 64 > bits long (and since we're working with migration we won't be able to > change that in the future for compatibility reasons...). > > Summary: > > Maybe we can replace: > > qemu_put_be32(f, GPOINTER_TO_UINT(key)); /* direct key */ > > To: > > qemu_put_be64(f, (uint64_t)key); /* direct key */ > > And apply similar thing to get() side? This was my first idea as well but I got stuck with a mingw compilation issues if I remember correctly, trying to cast pointers to a wrong sized uint. This got removed by using the GPOINTER_TO_UINT conversion functions. Thanks Eric > > Thanks, >