From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563905772732.047456322644; Tue, 1 Jun 2021 09:11:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134979.250987 (Exim 4.92) (envelope-from ) id 1lo6zO-0005XX-Rk; Tue, 01 Jun 2021 16:11:34 +0000 Received: by outflank-mailman (output) from mailman id 134979.250987; Tue, 01 Jun 2021 16:11:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zO-0005XO-OE; Tue, 01 Jun 2021 16:11:34 +0000 Received: by outflank-mailman (input) for mailman id 134979; Tue, 01 Jun 2021 16:11:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zN-0005Ec-0g for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:33 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [85.215.255.20]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 13ab766b-3fdb-4683-ae05-9169682260c7; Tue, 01 Jun 2021 16:11:31 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBP1B6 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:25 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 13ab766b-3fdb-4683-ae05-9169682260c7 ARC-Seal: i=1; a=rsa-sha256; t=1622563885; cv=none; d=strato.com; s=strato-dkim-0002; b=Q8tN60+RqOha/MCXIQ5n8Okf/eCE4XN4QKhcqJNEH4fZXpfnhdq1Mhn5RraxGGhURH bR2V3bg8mIRVxZhQd9j1M3EBFN4HTux1HLo56QpEB/Gxbo6JOG1f0QcftuzC+MeDRv7i wU77+TyThcRMJ1EdIUcxG4X3nP+Sq8mODjxlYfaeKbwmClPa7woA6uNk3tI6v1hrf4O5 IXwfnpqnCWi6HP6WdFWLjThkI5sNIypXP2ec7UnoBCaAc3Ifuh15qusQ4JMHU/p25Vef dCUcnFHg/OdvfpwLvwXct7TJtQjpbWaoZMQEHXea/r6wj6xn/I1WCc1gmhtDhRybPImn XJPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563885; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=ti7wpap7OKPtBty/ilhF07cZXxS6hyTWcz0abirc9Nk=; b=NlPTluv9dqlH2y81U97VooLLFW933ZhYmDeUIoPU04RBuEqy11hEOu/YqD9RUud8AG 4EmoFn+72H4J0QwM2rqMQ+EB9PxXbwBFfMbqKNQgMh4QkT4SrDhgMoyrDy2bBOTJevK9 8FryrKOg/HxOAfYTCtBtIu+5HzYTMf7tuak3wWU2Lqb3wQ+461DDPpdfr2IyZcllc6hf oN8FNN5l7cEBd3zVMyhJ8yCoUdKYh7HsLXRpiArQbdvtPE+Jqv9M2Y5n2luWdb4VkwOn Wk2S1SfZ2N3FsRTDqx0vi25FVmC6vCvuaZogANWP4q6kjCjw+Ft10E7yupTRpZizgIbb 5zPQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563885; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=ti7wpap7OKPtBty/ilhF07cZXxS6hyTWcz0abirc9Nk=; b=elofRk4c6+a0/b7PP9QcqvXDvSWVEb5gDa8oAMVpm4vMk6jdtWIkhVRdaQG6anPHjs rze8P0ywimL3CGv4VwC2MCHyx5V03dXo6+yaNiNPsEstbtFafrFTBl8btXejoOGbNWQw 4QWm/GibrNHC3k0EwzwNOOl+asl/XaG+4lZkBlOmCD9izIGAth3l2WKT4/3T6k4fMsJT CKDyLDJoVQccGr6oXvtIjFRouK+g7tijGkc2NSnCIOxG2T4PAyQYtjTf1PkxF+z4VDir 0nRHFlteuEjT/O09+DlcuzGLtnr+QcO0sEpeCQhByhMSKQk1JtMsSzqVrN14Wok3nZRq eVxQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 01/38] tools: add API to work with sevaral bits at once Date: Tue, 1 Jun 2021 18:10:41 +0200 Message-Id: <20210601161118.18986-2-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Introduce new API to test if a fixed number of bits is clear or set, and clear or set them all at once. The caller has to make sure the input bitnumber is a multiply of BITS_PER_L= ONG. This API avoids the loop over each bit in a known range just to see if all of them are either clear or set. Signed-off-by: Olaf Hering --- tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h index f0bac4a071..92f38872fb 100644 --- a/tools/libs/ctrl/xc_bitops.h +++ b/tools/libs/ctrl/xc_bitops.h @@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_ot= her, dst[i] |=3D other[i]; } =20 +static inline int test_bit_long_set(unsigned long nr_base, const void *_ad= dr) +{ + const unsigned long *addr =3D _addr; + unsigned long val =3D addr[nr_base / BITS_PER_LONG]; + return val =3D=3D ~0; +} + +static inline int test_bit_long_clear(unsigned long nr_base, const void *_= addr) +{ + const unsigned long *addr =3D _addr; + unsigned long val =3D addr[nr_base / BITS_PER_LONG]; + return val =3D=3D 0; +} + +static inline void clear_bit_long(unsigned long nr_base, void *_addr) +{ + unsigned long *addr =3D _addr; + addr[nr_base / BITS_PER_LONG] =3D 0; +} + +static inline void set_bit_long(unsigned long nr_base, void *_addr) +{ + unsigned long *addr =3D _addr; + addr[nr_base / BITS_PER_LONG] =3D ~0; +} #endif /* XC_BITOPS_H */ From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162256392067982.28823895339781; Tue, 1 Jun 2021 09:12:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134986.251053 (Exim 4.92) (envelope-from ) id 1lo6zd-0007em-C6; Tue, 01 Jun 2021 16:11:49 +0000 Received: by outflank-mailman (output) from mailman id 134986.251053; Tue, 01 Jun 2021 16:11:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zd-0007eD-5s; Tue, 01 Jun 2021 16:11:49 +0000 Received: by outflank-mailman (input) for mailman id 134986; Tue, 01 Jun 2021 16:11:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zc-0005Ec-17 for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:48 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.51]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5f02d3d3-25dd-40bb-a90b-7a56cafa0d5f; Tue, 01 Jun 2021 16:11:32 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBP1B7 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:25 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5f02d3d3-25dd-40bb-a90b-7a56cafa0d5f ARC-Seal: i=1; a=rsa-sha256; t=1622563886; cv=none; d=strato.com; s=strato-dkim-0002; b=rTKxOAkKqYFJL5L7GOducmz8OOO1xHg+Am9DHOVEIThR2y71qgA8qMEqUn3HXCS82l 6D6ABoIHBvhSlR9CZMALQWBO+AfyINY4HR6duXnGenx9CtJEfzShCwFm6yeAQTZvQn2c g+kU9Gd2Yvx4s6lt3K0Cg2PceL4O3nnXhARYRiW0JakF/zr3sGvZONAbwr4IWo9INVep UBs6HD/ro0SeILfjKpBfJdGDqMLRUtJoJ0qXaQOhK4HxVL+VqROjRRzZ7lDuIB3lg6Ba tidqqlXoVMIF1oBi+ICHtlm7C+mDBVv66gCBcaFLpiqMiVZYtAJ1hI22grtrmkBy/UVv EVdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563886; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=q97eEfHeTtV0cDWNiuGMRdoBkuW+It3JWF9KWqcO/JA=; b=SSyySTzshn8kEOHxegJbOF9NyOmyCNKBOlv8OwbvTSmrL+/cA5XWYwmuo5fGxKGULN rfFzd/kXuhwqoHjpEkAEd2d1VG4g5Rhp4lZx7EtSRfe6kvzXwKmSZd4km4fv7KfaN7DD sEWrakTta9mRArnZMZ1GKZHfIzwzYi9sUhfK3dQiJOUfrmlXrpkcKquTDEsuFiYvOwEl muPbLDjBxJtEco8io+KVCxTni03X2HTkMCrRrZokvuuVuVskoIQiVULyxTKIsWDO/a38 ft7okdV922U0qqWng/27ihvkB/cIgRqrX9VZScwkYFft4FXxAKwo+COLidPZkCOesZ/w lSQQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563886; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=q97eEfHeTtV0cDWNiuGMRdoBkuW+It3JWF9KWqcO/JA=; b=lM4O7DGKUfc+l8/uC42qfSOM6h4+DtCfrOtiBAKTdo5MgUSCOy26LhszcdSjhS7kjF 0jCv7eJ3E4IitkJzIJWSv7EjpM29Be1TfA3BPehj8QsuqYXOWS0w+gEYRdHDpNiWQb3P AUTFySO+n0cEo7ORuucXWnkfv9BUSGHmcG2RqcGdrkF2wjcZWcthPVTL5PXEQnjLq6c+ lvu3OXIJ3UIVXLO3Y6Jyrd/xqhW5JSFDGYHZq7xTZ+zUbZa7StjvIqbtr6rCcSWxmqB3 QsEzp7laZa4pu9KbOkU9YcE/ck6oVtv7MGHGf4VNQaNFIesv5b8opTH+l9wjnsCFAOfI finA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v20210601 02/38] xl: fix description of migrate --debug Date: Tue, 1 Jun 2021 18:10:42 +0200 Message-Id: <20210601161118.18986-3-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" xl migrate --debug used to track every pfn in every batch of pages. But these times are gone. Adjust the help text to tell what --debug is supposed to do today. Signed-off-by: Olaf Hering --- docs/man/xl.1.pod.in | 4 +++- tools/libs/guest/xg_sr_save.c | 2 +- tools/xl/xl_cmdtable.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index e2176bd696..ed3f4dee1e 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -481,7 +481,9 @@ domain. =20 =3Ditem B<--debug> =20 -Display huge (!) amount of debug information during the migration process. +Verify transferred domU page data. All memory will be transferred one more +time to the destination host while the domU is paused, and compared with +the result of the inital transfer while the domU was still running. =20 =3Ditem B<-p> =20 diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 2ba7c3200c..51542a98c8 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -752,7 +752,7 @@ static int send_domain_memory_live(struct xc_sr_context= *ctx) if ( rc ) goto out; =20 - if ( ctx->save.debug && ctx->stream_type !=3D XC_STREAM_PLAIN ) + if ( ctx->save.debug ) { rc =3D verify_frames(ctx); if ( rc ) diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 661323d488..6fd18856c0 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -172,7 +172,7 @@ const struct cmd_spec cmd_table[] =3D { " migrate-receive [-d -e]\n" "-e Do not wait in the background (on ) for the d= eath\n" " of the domain.\n" - "--debug Print huge (!) amount of debug during the migration= process.\n" + "--debug Verify transferred domU page data.\n" "-p Do not unpause domain after migrating it.\n" "-D Preserve the domain id" }, From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564023923680.2571105863841; Tue, 1 Jun 2021 09:13:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135025.251223 (Exim 4.92) (envelope-from ) id 1lo71H-0001KR-Ly; Tue, 01 Jun 2021 16:13:31 +0000 Received: by outflank-mailman (output) from mailman id 135025.251223; Tue, 01 Jun 2021 16:13:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71H-0001Iq-D3; Tue, 01 Jun 2021 16:13:31 +0000 Received: by outflank-mailman (input) for mailman id 135025; Tue, 01 Jun 2021 16:13:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70C-0005X1-0f for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:24 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.51]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 02291225-47e5-4fe0-9d54-ab7ebb72cbcf; Tue, 01 Jun 2021 16:11:43 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBQ1B8 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:26 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 02291225-47e5-4fe0-9d54-ab7ebb72cbcf ARC-Seal: i=1; a=rsa-sha256; t=1622563886; cv=none; d=strato.com; s=strato-dkim-0002; b=oRRt7UA8nF/QnQKfNCY4t0quJSyOYnj+ODxgLZQ2JCgIBxG2+Za6QIvOmCKlmrlRrW C3xJQvjGuA38VBNPQI7WIWZx03bBxk4580YNnN0spJmLluTHabYI5ATltxg2/+K4E8yC +immYjEsB3pditQTp57aMeiM1GmKSxaA53uI1Zl8As8Lb7Ph/G7iGqh3DXi3+Hk+TIf7 E2y7crubqCw58rkkI8z6YOLIE3Ne5pk3tOCkWUnVBn6RuKzGg4dImT5vuCIqsjSSVbs8 CjamgFWxeo63DBFnUAIiMz4q/CsT+YJRTIqq/phGYEDuK8X278ISOSh7yZG1cvfIf7bX GKrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563886; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=USuh1vETqHao4YOD0ii6LvSJ55qejRnauMVjBJeZuwA=; b=XEn7q4Y6aeUJkbaKyGb2wZoybokEPdESgQG1nFHXl/sJC5Fw42b4/fb8+lxw4/D9bN AUlQDTtQG+mDW/m6geJZ6qFwEjoJ9axdqk6/331BSJhJ1SXqweo7X98UQExeJI1qQd4U ScpvPVrnceC0ehxXpcJ5DrhdmsF4HxFsp9n1bK+bcZFLz25luXo28v+ZV1juRTW/p2Fx oMpOGD86ahfrbJH3eJacIoL0F2u4r771KKZmjyRNRPT/tmuMF484XzDZ7IJaIv+Mvj+m zPdFtWxGKjt4EEpn0+/O+Ez1fQHIohvT7ZM7uZlQKKYVxyfkinG4lFZ3ge87TmOgJLFc QPTw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563886; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=USuh1vETqHao4YOD0ii6LvSJ55qejRnauMVjBJeZuwA=; b=qJHv/jOe3HQwplaJnIQJkhQT3BlI7ZBVWyBnUcTG9fmhMQAtRM2wRHYlJAvb7ymFsZ hCUCUwXVYRg2lwBiTlKKOzfZMwAiFN9VoceIDKNDynz5HB2VCNlSBjjml0cB73U+4JGR +jz3he+MwfiyQySximUwz5oLHrSSOf1d39E334dRWwwZ4kQG2pk3A7o/hV8rPAOu9Gzn f8+XNHwPAxntKnD7Bv4E3WwN+DTwLbWoRRLdUTmAiJ22h2oSzGVQccBSUAdYB+1MwmQ2 eXxVBz7Pfcu4ajYpvuIcSK9b7Kp6CmRQuiRMPyKoRSej4DVudGtRJVet+edPlIPV3fOI 8AWg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Wei Liu , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Anthony PERARD Subject: [PATCH v20210601 03/38] tools: create libxensaverestore Date: Tue, 1 Jun 2021 18:10:43 +0200 Message-Id: <20210601161118.18986-4-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move all save/restore related code from libxenguest.so into a separate library libxensaverestore.so. The only consumer is libxl-save-helper. There is no need to have the moved code mapped all the time in binaries where libxenguest.so is used. According to size(1) the change is: text data bss dec hex filename 187183 4304 48 191535 2ec2f guest/libxenguest.so.4.15.0 124106 3376 48 127530 1f22a guest/libxenguest.so.4.15.0 67841 1872 8 69721 11059 saverestore/libxensaverestore.so.4.= 15.0 While touching the files anyway, take the opportunity to drop the reduntant xg_sr_ filename prefix. Signed-off-by: Olaf Hering Acked-by: Wei Liu v4: - drop xg_ prefix from filenames (jgross) - drop sr_ prefix from filenames (jbeulich) v3: - repost in time for 4.16 v2: - copy also license header - move xg_nomigrate.c - add size(1) output to commit msg - remove change from libxl_create.c --- .gitignore | 2 + tools/include/xenguest.h | 186 ---------------- tools/include/xensaverestore.h | 208 ++++++++++++++++++ tools/libs/Makefile | 1 + tools/libs/guest/Makefile | 11 - tools/libs/guest/xg_offline_page.c | 1 - tools/libs/light/Makefile | 4 +- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_save_helper.c | 1 + tools/libs/light/libxl_save_msgs_gen.pl | 2 +- tools/libs/saverestore/Makefile | 38 ++++ .../xg_sr_common.c =3D> saverestore/common.c} | 2 +- .../xg_sr_common.h =3D> saverestore/common.h} | 16 +- .../common_x86.c} | 2 +- .../common_x86.h} | 2 +- .../common_x86_pv.c} | 2 +- .../common_x86_pv.h} | 2 +- .../nomigrate.c} | 0 .../xg_sr_restore.c =3D> saverestore/restore.c} | 2 +- .../restore_x86_hvm.c} | 2 +- .../restore_x86_pv.c} | 2 +- .../xg_sr_save.c =3D> saverestore/save.c} | 2 +- .../save_restore.h} | 2 - .../save_x86_hvm.c} | 2 +- .../save_x86_pv.c} | 2 +- .../stream_format.h} | 0 tools/libs/uselibs.mk | 4 +- 27 files changed, 282 insertions(+), 217 deletions(-) create mode 100644 tools/include/xensaverestore.h create mode 100644 tools/libs/saverestore/Makefile rename tools/libs/{guest/xg_sr_common.c =3D> saverestore/common.c} (99%) rename tools/libs/{guest/xg_sr_common.h =3D> saverestore/common.h} (98%) rename tools/libs/{guest/xg_sr_common_x86.c =3D> saverestore/common_x86.c}= (99%) rename tools/libs/{guest/xg_sr_common_x86.h =3D> saverestore/common_x86.h}= (98%) rename tools/libs/{guest/xg_sr_common_x86_pv.c =3D> saverestore/common_x86= _pv.c} (99%) rename tools/libs/{guest/xg_sr_common_x86_pv.h =3D> saverestore/common_x86= _pv.h} (98%) rename tools/libs/{guest/xg_nomigrate.c =3D> saverestore/nomigrate.c} (100= %) rename tools/libs/{guest/xg_sr_restore.c =3D> saverestore/restore.c} (99%) rename tools/libs/{guest/xg_sr_restore_x86_hvm.c =3D> saverestore/restore_= x86_hvm.c} (99%) rename tools/libs/{guest/xg_sr_restore_x86_pv.c =3D> saverestore/restore_x= 86_pv.c} (99%) rename tools/libs/{guest/xg_sr_save.c =3D> saverestore/save.c} (99%) rename tools/libs/{guest/xg_save_restore.h =3D> saverestore/save_restore.h= } (98%) rename tools/libs/{guest/xg_sr_save_x86_hvm.c =3D> saverestore/save_x86_hv= m.c} (99%) rename tools/libs/{guest/xg_sr_save_x86_pv.c =3D> saverestore/save_x86_pv.= c} (99%) rename tools/libs/{guest/xg_sr_stream_format.h =3D> saverestore/stream_for= mat.h} (100%) diff --git a/.gitignore b/.gitignore index 38a085e398..08a321e995 100644 --- a/.gitignore +++ b/.gitignore @@ -147,6 +147,8 @@ tools/libs/light/test_timedereg tools/libs/light/test_fdderegrace tools/libs/light/tmp.* tools/libs/light/xenlight.pc +tools/libs/saverestore/libxensaverestore.map +tools/libs/saverestore/xensaverestore.pc tools/libs/stat/_paths.h tools/libs/stat/headers.chk tools/libs/stat/libxenstat.map diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index a4492038cf..80adf8dc6f 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -24,9 +24,6 @@ =20 #define XC_NUMA_NO_NODE (~0U) =20 -#define XCFLAGS_LIVE (1 << 0) -#define XCFLAGS_DEBUG (1 << 1) - #define X86_64_B_SIZE 64=20 #define X86_32_B_SIZE 32 =20 @@ -433,189 +430,6 @@ static inline xen_pfn_t xc_dom_p2m(struct xc_dom_imag= e *dom, xen_pfn_t pfn) */ struct xenevtchn_handle; =20 -/* For save's precopy_policy(). */ -struct precopy_stats -{ - unsigned int iteration; - unsigned long total_written; - long dirty_count; /* -1 if unknown */ -}; - -/* - * A precopy_policy callback may not be running in the same address - * space as libxc an so precopy_stats is passed by value. - */ -typedef int (*precopy_policy_t)(struct precopy_stats, void *); - -/* callbacks provided by xc_domain_save */ -struct save_callbacks { - /* - * Called after expiration of checkpoint interval, - * to suspend the guest. - */ - int (*suspend)(void *data); - - /* - * Called before and after every batch of page data sent during - * the precopy phase of a live migration to ask the caller what - * to do next based on the current state of the precopy migration. - * - * Should return one of the values listed below: - */ -#define XGS_POLICY_ABORT (-1) /* Abandon the migration entirely - * and tidy up. */ -#define XGS_POLICY_CONTINUE_PRECOPY 0 /* Remain in the precopy phase. */ -#define XGS_POLICY_STOP_AND_COPY 1 /* Immediately suspend and transmit= the - * remaining dirty pages. */ - precopy_policy_t precopy_policy; - - /* - * Called after the guest's dirty pages have been - * copied into an output buffer. - * Callback function resumes the guest & the device model, - * returns to xc_domain_save. - * xc_domain_save then flushes the output buffer, while the - * guest continues to run. - */ - int (*postcopy)(void *data); - - /* - * Called after the memory checkpoint has been flushed - * out into the network. Typical actions performed in this - * callback include: - * (a) send the saved device model state (for HVM guests), - * (b) wait for checkpoint ack - * (c) release the network output buffer pertaining to the acked che= ckpoint. - * (c) sleep for the checkpoint interval. - * - * returns: - * 0: terminate checkpointing gracefully - * 1: take another checkpoint - */ - int (*checkpoint)(void *data); - - /* - * Called after the checkpoint callback. - * - * returns: - * 0: terminate checkpointing gracefully - * 1: take another checkpoint - */ - int (*wait_checkpoint)(void *data); - - /* Enable qemu-dm logging dirty pages to xen */ - int (*switch_qemu_logdirty)(uint32_t domid, unsigned enable, void *dat= a); /* HVM only */ - - /* to be provided as the last argument to each callback function */ - void *data; -}; - -/* Type of stream. Plain, or using a continuous replication protocol? */ -typedef enum { - XC_STREAM_PLAIN, - XC_STREAM_REMUS, - XC_STREAM_COLO, -} xc_stream_type_t; - -/** - * This function will save a running domain. - * - * @param xch a handle to an open hypervisor interface - * @param io_fd the file descriptor to save a domain to - * @param dom the id of the domain - * @param flags XCFLAGS_xxx - * @param stream_type XC_STREAM_PLAIN if the far end of the stream - * doesn't use checkpointing - * @param recv_fd Only used for XC_STREAM_COLO. Contains backchannel from - * the destination side. - * @return 0 on success, -1 on failure - */ -int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, - uint32_t flags, struct save_callbacks *callbacks, - xc_stream_type_t stream_type, int recv_fd); - -/* callbacks provided by xc_domain_restore */ -struct restore_callbacks { - /* - * Called once the STATIC_DATA_END record has been received/inferred. - * - * For compatibility with older streams, provides a list of static data - * expected to be found in the stream, which was missing. A higher le= vel - * toolstack is responsible for providing any necessary compatibiltiy. - */ -#define XGR_SDD_MISSING_CPUID (1 << 0) -#define XGR_SDD_MISSING_MSR (1 << 1) - int (*static_data_done)(unsigned int missing, void *data); - - /* Called after a new checkpoint to suspend the guest. */ - int (*suspend)(void *data); - - /* - * Called after the secondary vm is ready to resume. - * Callback function resumes the guest & the device model, - * returns to xc_domain_restore. - */ - int (*postcopy)(void *data); - - /* - * A checkpoint record has been found in the stream. - * returns: - */ -#define XGR_CHECKPOINT_ERROR 0 /* Terminate processing */ -#define XGR_CHECKPOINT_SUCCESS 1 /* Continue reading more data from the s= tream */ -#define XGR_CHECKPOINT_FAILOVER 2 /* Failover and resume VM */ - int (*checkpoint)(void *data); - - /* - * Called after the checkpoint callback. - * - * returns: - * 0: terminate checkpointing gracefully - * 1: take another checkpoint - */ - int (*wait_checkpoint)(void *data); - - /* - * callback to send store gfn and console gfn to xl - * if we want to resume vm before xc_domain_save() - * exits. - */ - void (*restore_results)(xen_pfn_t store_gfn, xen_pfn_t console_gfn, - void *data); - - /* to be provided as the last argument to each callback function */ - void *data; -}; - -/** - * This function will restore a saved domain. - * - * Domain is restored in a suspended state ready to be unpaused. - * - * @param xch a handle to an open hypervisor interface - * @param io_fd the file descriptor to restore a domain from - * @param dom the id of the domain - * @param store_evtchn the xenstore event channel for this domain to use - * @param store_mfn filled with the gfn of the store page - * @param store_domid the backend domain for xenstore - * @param console_evtchn the console event channel for this domain to use - * @param console_mfn filled with the gfn of the console page - * @param console_domid the backend domain for xenconsole - * @param stream_type XC_STREAM_PLAIN if the far end of the stream is using - * checkpointing - * @param callbacks non-NULL to receive a callback to restore toolstack - * specific data - * @param send_back_fd Only used for XC_STREAM_COLO. Contains backchannel= to - * the source side. - * @return 0 on success, -1 on failure - */ -int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, - unsigned int store_evtchn, unsigned long *store_mfn, - uint32_t store_domid, unsigned int console_evtchn, - unsigned long *console_mfn, uint32_t console_domid, - xc_stream_type_t stream_type, - struct restore_callbacks *callbacks, int send_back_f= d); - /** * This function will create a domain for a paravirtualized Linux * using file names pointing to kernel and ramdisk diff --git a/tools/include/xensaverestore.h b/tools/include/xensaverestore.h new file mode 100644 index 0000000000..0410f0469e --- /dev/null +++ b/tools/include/xensaverestore.h @@ -0,0 +1,208 @@ +/*************************************************************************= ***** + * A library for guest domain save/restore/migration in Xen. + * + * Copyright (c) 2003-2004, K A Fraser. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ +#ifndef XENSAVERESTORE_H +#define XENSAVERESTORE_H + +#define XCFLAGS_LIVE (1 << 0) +#define XCFLAGS_DEBUG (1 << 1) + +/* For save's precopy_policy(). */ +struct precopy_stats +{ + unsigned int iteration; + unsigned long total_written; + long dirty_count; /* -1 if unknown */ +}; + +/* + * A precopy_policy callback may not be running in the same address + * space as libxc an so precopy_stats is passed by value. + */ +typedef int (*precopy_policy_t)(struct precopy_stats, void *); + +/* callbacks provided by xc_domain_save */ +struct save_callbacks { + /* + * Called after expiration of checkpoint interval, + * to suspend the guest. + */ + int (*suspend)(void *data); + + /* + * Called before and after every batch of page data sent during + * the precopy phase of a live migration to ask the caller what + * to do next based on the current state of the precopy migration. + * + * Should return one of the values listed below: + */ +#define XGS_POLICY_ABORT (-1) /* Abandon the migration entirely + * and tidy up. */ +#define XGS_POLICY_CONTINUE_PRECOPY 0 /* Remain in the precopy phase. */ +#define XGS_POLICY_STOP_AND_COPY 1 /* Immediately suspend and transmit= the + * remaining dirty pages. */ + precopy_policy_t precopy_policy; + + /* + * Called after the guest's dirty pages have been + * copied into an output buffer. + * Callback function resumes the guest & the device model, + * returns to xc_domain_save. + * xc_domain_save then flushes the output buffer, while the + * guest continues to run. + */ + int (*postcopy)(void *data); + + /* + * Called after the memory checkpoint has been flushed + * out into the network. Typical actions performed in this + * callback include: + * (a) send the saved device model state (for HVM guests), + * (b) wait for checkpoint ack + * (c) release the network output buffer pertaining to the acked che= ckpoint. + * (c) sleep for the checkpoint interval. + * + * returns: + * 0: terminate checkpointing gracefully + * 1: take another checkpoint + */ + int (*checkpoint)(void *data); + + /* + * Called after the checkpoint callback. + * + * returns: + * 0: terminate checkpointing gracefully + * 1: take another checkpoint + */ + int (*wait_checkpoint)(void *data); + + /* Enable qemu-dm logging dirty pages to xen */ + int (*switch_qemu_logdirty)(uint32_t domid, unsigned enable, void *dat= a); /* HVM only */ + + /* to be provided as the last argument to each callback function */ + void *data; +}; + +/* Type of stream. Plain, or using a continuous replication protocol? */ +typedef enum { + XC_STREAM_PLAIN, + XC_STREAM_REMUS, + XC_STREAM_COLO, +} xc_stream_type_t; + +/** + * This function will save a running domain. + * + * @param xch a handle to an open hypervisor interface + * @param io_fd the file descriptor to save a domain to + * @param dom the id of the domain + * @param flags XCFLAGS_xxx + * @param stream_type XC_STREAM_PLAIN if the far end of the stream + * doesn't use checkpointing + * @param recv_fd Only used for XC_STREAM_COLO. Contains backchannel from + * the destination side. + * @return 0 on success, -1 on failure + */ +int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, + uint32_t flags, struct save_callbacks *callbacks, + xc_stream_type_t stream_type, int recv_fd); + +/* callbacks provided by xc_domain_restore */ +struct restore_callbacks { + /* + * Called once the STATIC_DATA_END record has been received/inferred. + * + * For compatibility with older streams, provides a list of static data + * expected to be found in the stream, which was missing. A higher le= vel + * toolstack is responsible for providing any necessary compatibiltiy. + */ +#define XGR_SDD_MISSING_CPUID (1 << 0) +#define XGR_SDD_MISSING_MSR (1 << 1) + int (*static_data_done)(unsigned int missing, void *data); + + /* Called after a new checkpoint to suspend the guest. */ + int (*suspend)(void *data); + + /* + * Called after the secondary vm is ready to resume. + * Callback function resumes the guest & the device model, + * returns to xc_domain_restore. + */ + int (*postcopy)(void *data); + + /* + * A checkpoint record has been found in the stream. + * returns: + */ +#define XGR_CHECKPOINT_ERROR 0 /* Terminate processing */ +#define XGR_CHECKPOINT_SUCCESS 1 /* Continue reading more data from the s= tream */ +#define XGR_CHECKPOINT_FAILOVER 2 /* Failover and resume VM */ + int (*checkpoint)(void *data); + + /* + * Called after the checkpoint callback. + * + * returns: + * 0: terminate checkpointing gracefully + * 1: take another checkpoint + */ + int (*wait_checkpoint)(void *data); + + /* + * callback to send store gfn and console gfn to xl + * if we want to resume vm before xc_domain_save() + * exits. + */ + void (*restore_results)(xen_pfn_t store_gfn, xen_pfn_t console_gfn, + void *data); + + /* to be provided as the last argument to each callback function */ + void *data; +}; + +/** + * This function will restore a saved domain. + * + * Domain is restored in a suspended state ready to be unpaused. + * + * @param xch a handle to an open hypervisor interface + * @param io_fd the file descriptor to restore a domain from + * @param dom the id of the domain + * @param store_evtchn the xenstore event channel for this domain to use + * @param store_mfn filled with the gfn of the store page + * @param store_domid the backend domain for xenstore + * @param console_evtchn the console event channel for this domain to use + * @param console_mfn filled with the gfn of the console page + * @param console_domid the backend domain for xenconsole + * @param stream_type XC_STREAM_PLAIN if the far end of the stream is using + * checkpointing + * @param callbacks non-NULL to receive a callback to restore toolstack + * specific data + * @param send_back_fd Only used for XC_STREAM_COLO. Contains backchannel= to + * the source side. + * @return 0 on success, -1 on failure + */ +int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, + unsigned int store_evtchn, unsigned long *store_mfn, + uint32_t store_domid, unsigned int console_evtchn, + unsigned long *console_mfn, uint32_t console_domid, + xc_stream_type_t stream_type, + struct restore_callbacks *callbacks, int send_back_f= d); + +#endif /* XENSAVERESTORE_H */ diff --git a/tools/libs/Makefile b/tools/libs/Makefile index 1afcd12e2b..ca43c66777 100644 --- a/tools/libs/Makefile +++ b/tools/libs/Makefile @@ -12,6 +12,7 @@ SUBDIRS-y +=3D devicemodel SUBDIRS-y +=3D ctrl SUBDIRS-y +=3D guest SUBDIRS-y +=3D hypfs +SUBDIRS-y +=3D saverestore SUBDIRS-y +=3D store SUBDIRS-y +=3D stat SUBDIRS-$(CONFIG_Linux) +=3D vchan diff --git a/tools/libs/guest/Makefile b/tools/libs/guest/Makefile index 6d2a1d5bbc..4d99ee1f41 100644 --- a/tools/libs/guest/Makefile +++ b/tools/libs/guest/Makefile @@ -10,18 +10,7 @@ SRCS-y +=3D xg_private.c SRCS-y +=3D xg_domain.c SRCS-y +=3D xg_suspend.c ifeq ($(CONFIG_MIGRATE),y) -SRCS-y +=3D xg_sr_common.c -SRCS-$(CONFIG_X86) +=3D xg_sr_common_x86.c -SRCS-$(CONFIG_X86) +=3D xg_sr_common_x86_pv.c -SRCS-$(CONFIG_X86) +=3D xg_sr_restore_x86_pv.c -SRCS-$(CONFIG_X86) +=3D xg_sr_restore_x86_hvm.c -SRCS-$(CONFIG_X86) +=3D xg_sr_save_x86_pv.c -SRCS-$(CONFIG_X86) +=3D xg_sr_save_x86_hvm.c -SRCS-y +=3D xg_sr_restore.c -SRCS-y +=3D xg_sr_save.c SRCS-y +=3D xg_offline_page.c -else -SRCS-y +=3D xg_nomigrate.c endif =20 CFLAGS +=3D -I$(XEN_libxenctrl) diff --git a/tools/libs/guest/xg_offline_page.c b/tools/libs/guest/xg_offli= ne_page.c index d4722f0e8c..e49ef55887 100644 --- a/tools/libs/guest/xg_offline_page.c +++ b/tools/libs/guest/xg_offline_page.c @@ -29,7 +29,6 @@ =20 #include "xc_private.h" #include "xg_private.h" -#include "xg_save_restore.h" =20 struct pte_backup_entry { diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 7d8c51d492..68e51dd13c 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -179,7 +179,7 @@ $(ACPI_OBJS) $(ACPI_PIC_OBJS): CFLAGS +=3D -I. -DLIBACP= I_STDUTILS=3D\"$(CURDIR)/libx $(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS +=3D $(CFLAGS_libxentoollog= ) $(CFLAGS_libxentoolcore) libxl_dom.o libxl_dom.opic: CFLAGS +=3D -I$(XEN_ROOT)/tools # include lib= acpi/x86.h libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS +=3D -I$(XEN_ROOT)/tools -$(SAVE_HELPER_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtch= n) $(CFLAGS_libxenguest) +$(SAVE_HELPER_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtch= n) $(CFLAGS_libxensaverestore) =20 testidl.o: CFLAGS +=3D $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight) testidl.c: libxl_types.idl gentest.py $(XEN_INCLUDE)/libxl.h $(AUTOINCS) @@ -241,7 +241,7 @@ test_%: test_%.o test_common.o libxenlight_test.so $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenli= ght)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFL= AGS) =20 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so - $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLI= BS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFL= AGS) + $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLI= BS_libxenctrl) $(LDLIBS_libxensaverestore) $(LDLIBS_libxentoolcore) $(APPEN= D_LDFLAGS) =20 testidl: testidl.o libxenlight.so $(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoo= llog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 44a2f3c8fe..8af075291a 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -56,6 +56,7 @@ #define XC_WANT_COMPAT_MAP_FOREIGN_API #include #include +#include #include =20 #include diff --git a/tools/libs/light/libxl_save_helper.c b/tools/libs/light/libxl_= save_helper.c index 65dff389bf..896e845a2f 100644 --- a/tools/libs/light/libxl_save_helper.c +++ b/tools/libs/light/libxl_save_helper.c @@ -48,6 +48,7 @@ =20 #include "xenctrl.h" #include "xenguest.h" +#include "xensaverestore.h" #include "_libxl_save_msgs_helper.h" =20 /*----- logger -----*/ diff --git a/tools/libs/light/libxl_save_msgs_gen.pl b/tools/libs/light/lib= xl_save_msgs_gen.pl index 9d425b1dee..f263ee01bb 100755 --- a/tools/libs/light/libxl_save_msgs_gen.pl +++ b/tools/libs/light/libxl_save_msgs_gen.pl @@ -72,7 +72,7 @@ END_BOTH END_CALLOUT =20 #include -#include +#include #include "_libxl_save_msgs_${ah}.h" =20 END_HELPER diff --git a/tools/libs/saverestore/Makefile b/tools/libs/saverestore/Makef= ile new file mode 100644 index 0000000000..48728b3be2 --- /dev/null +++ b/tools/libs/saverestore/Makefile @@ -0,0 +1,38 @@ +XEN_ROOT =3D $(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +ifeq ($(CONFIG_MIGRATE),y) +SRCS-y +=3D common.c +SRCS-$(CONFIG_X86) +=3D common_x86.c +SRCS-$(CONFIG_X86) +=3D common_x86_pv.c +SRCS-$(CONFIG_X86) +=3D restore_x86_pv.c +SRCS-$(CONFIG_X86) +=3D restore_x86_hvm.c +SRCS-$(CONFIG_X86) +=3D save_x86_pv.c +SRCS-$(CONFIG_X86) +=3D save_x86_hvm.c +SRCS-y +=3D restore.c +SRCS-y +=3D save.c +else +SRCS-y +=3D nomigrate.c +endif + +CFLAGS +=3D -I$(XEN_libxenctrl) +CFLAGS +=3D -I$(XEN_libxenguest) + +-include $(XEN_TARGET_ARCH)/Makefile + +CFLAGS +=3D -Werror -Wmissing-prototypes +CFLAGS +=3D -I. -I./include $(CFLAGS_xeninclude) +CFLAGS +=3D -D__XEN_TOOLS__ +CFLAGS +=3D -include $(XEN_ROOT)/tools/config.h +# Needed for asprintf() +CFLAGS-$(CONFIG_Linux) +=3D -D_GNU_SOURCE + +LIBHEADER :=3D xensaverestore.h + +NO_HEADERS_CHK :=3D y + +include $(XEN_ROOT)/tools/libs/libs.mk + +.PHONY: cleanlocal +cleanlocal: + rm -f libxensaverestore.map diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/saverestore/commo= n.c similarity index 99% rename from tools/libs/guest/xg_sr_common.c rename to tools/libs/saverestore/common.c index 17567ab133..77128bc747 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/saverestore/common.c @@ -1,6 +1,6 @@ #include =20 -#include "xg_sr_common.h" +#include "common.h" =20 #include =20 diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/saverestore/commo= n.h similarity index 98% rename from tools/libs/guest/xg_sr_common.h rename to tools/libs/saverestore/common.h index cc3ad1c394..36946e5d48 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/saverestore/common.h @@ -1,13 +1,25 @@ #ifndef __COMMON__H #define __COMMON__H =20 +#include +#include #include +#include +#include +#include +#include +#include +#include + +#include "xc_private.h" +#include "xenguest.h" +#include "xensaverestore.h" =20 #include "xg_private.h" -#include "xg_save_restore.h" +#include "save_restore.h" #include "xc_bitops.h" =20 -#include "xg_sr_stream_format.h" +#include "stream_format.h" =20 /* String representation of Domain Header types. */ const char *dhdr_type_to_str(uint32_t type); diff --git a/tools/libs/guest/xg_sr_common_x86.c b/tools/libs/saverestore/c= ommon_x86.c similarity index 99% rename from tools/libs/guest/xg_sr_common_x86.c rename to tools/libs/saverestore/common_x86.c index 563b4f0168..f1beb234ae 100644 --- a/tools/libs/guest/xg_sr_common_x86.c +++ b/tools/libs/saverestore/common_x86.c @@ -1,4 +1,4 @@ -#include "xg_sr_common_x86.h" +#include "common_x86.h" =20 int write_x86_tsc_info(struct xc_sr_context *ctx) { diff --git a/tools/libs/guest/xg_sr_common_x86.h b/tools/libs/saverestore/c= ommon_x86.h similarity index 98% rename from tools/libs/guest/xg_sr_common_x86.h rename to tools/libs/saverestore/common_x86.h index b55758c96d..3a2d91dcb8 100644 --- a/tools/libs/guest/xg_sr_common_x86.h +++ b/tools/libs/saverestore/common_x86.h @@ -1,7 +1,7 @@ #ifndef __COMMON_X86__H #define __COMMON_X86__H =20 -#include "xg_sr_common.h" +#include "common.h" =20 /* * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO re= cord diff --git a/tools/libs/guest/xg_sr_common_x86_pv.c b/tools/libs/saverestor= e/common_x86_pv.c similarity index 99% rename from tools/libs/guest/xg_sr_common_x86_pv.c rename to tools/libs/saverestore/common_x86_pv.c index cd33406aab..caf3cc588f 100644 --- a/tools/libs/guest/xg_sr_common_x86_pv.c +++ b/tools/libs/saverestore/common_x86_pv.c @@ -1,6 +1,6 @@ #include =20 -#include "xg_sr_common_x86_pv.h" +#include "common_x86_pv.h" =20 xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn) { diff --git a/tools/libs/guest/xg_sr_common_x86_pv.h b/tools/libs/saverestor= e/common_x86_pv.h similarity index 98% rename from tools/libs/guest/xg_sr_common_x86_pv.h rename to tools/libs/saverestore/common_x86_pv.h index 953b5bfb8d..a9f8c970e3 100644 --- a/tools/libs/guest/xg_sr_common_x86_pv.h +++ b/tools/libs/saverestore/common_x86_pv.h @@ -1,7 +1,7 @@ #ifndef __COMMON_X86_PV_H #define __COMMON_X86_PV_H =20 -#include "xg_sr_common_x86.h" +#include "common_x86.h" =20 /* Virtual address ranges reserved for hypervisor. */ #define HYPERVISOR_VIRT_START_X86_64 0xFFFF800000000000ULL diff --git a/tools/libs/guest/xg_nomigrate.c b/tools/libs/saverestore/nomig= rate.c similarity index 100% rename from tools/libs/guest/xg_nomigrate.c rename to tools/libs/saverestore/nomigrate.c diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/saverestore/rest= ore.c similarity index 99% rename from tools/libs/guest/xg_sr_restore.c rename to tools/libs/saverestore/restore.c index b57a787519..be259a1c6b 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/saverestore/restore.c @@ -2,7 +2,7 @@ =20 #include =20 -#include "xg_sr_common.h" +#include "common.h" =20 /* * Read and validate the Image and Domain headers. diff --git a/tools/libs/guest/xg_sr_restore_x86_hvm.c b/tools/libs/saverest= ore/restore_x86_hvm.c similarity index 99% rename from tools/libs/guest/xg_sr_restore_x86_hvm.c rename to tools/libs/saverestore/restore_x86_hvm.c index d6ea6f3012..bd63bd2818 100644 --- a/tools/libs/guest/xg_sr_restore_x86_hvm.c +++ b/tools/libs/saverestore/restore_x86_hvm.c @@ -1,7 +1,7 @@ #include #include =20 -#include "xg_sr_common_x86.h" +#include "common_x86.h" =20 /* * Process an HVM_CONTEXT record from the stream. diff --git a/tools/libs/guest/xg_sr_restore_x86_pv.c b/tools/libs/saveresto= re/restore_x86_pv.c similarity index 99% rename from tools/libs/guest/xg_sr_restore_x86_pv.c rename to tools/libs/saverestore/restore_x86_pv.c index dc50b0f5a8..96608e5231 100644 --- a/tools/libs/guest/xg_sr_restore_x86_pv.c +++ b/tools/libs/saverestore/restore_x86_pv.c @@ -1,6 +1,6 @@ #include =20 -#include "xg_sr_common_x86_pv.h" +#include "common_x86_pv.h" =20 static xen_pfn_t pfn_to_mfn(const struct xc_sr_context *ctx, xen_pfn_t pfn) { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/saverestore/save.c similarity index 99% rename from tools/libs/guest/xg_sr_save.c rename to tools/libs/saverestore/save.c index 51542a98c8..92d96b0533 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/saverestore/save.c @@ -1,7 +1,7 @@ #include #include =20 -#include "xg_sr_common.h" +#include "common.h" =20 /* * Writes an Image header and Domain header into the stream. diff --git a/tools/libs/guest/xg_save_restore.h b/tools/libs/saverestore/sa= ve_restore.h similarity index 98% rename from tools/libs/guest/xg_save_restore.h rename to tools/libs/saverestore/save_restore.h index 3dbbc8dcd2..20bd3d30a5 100644 --- a/tools/libs/guest/xg_save_restore.h +++ b/tools/libs/saverestore/save_restore.h @@ -15,8 +15,6 @@ * License along with this library; If not, see . */ =20 -#include "xc_private.h" - #include #include =20 diff --git a/tools/libs/guest/xg_sr_save_x86_hvm.c b/tools/libs/saverestore= /save_x86_hvm.c similarity index 99% rename from tools/libs/guest/xg_sr_save_x86_hvm.c rename to tools/libs/saverestore/save_x86_hvm.c index 1634a7bc43..91c2cb99ab 100644 --- a/tools/libs/guest/xg_sr_save_x86_hvm.c +++ b/tools/libs/saverestore/save_x86_hvm.c @@ -1,6 +1,6 @@ #include =20 -#include "xg_sr_common_x86.h" +#include "common_x86.h" =20 #include =20 diff --git a/tools/libs/guest/xg_sr_save_x86_pv.c b/tools/libs/saverestore/= save_x86_pv.c similarity index 99% rename from tools/libs/guest/xg_sr_save_x86_pv.c rename to tools/libs/saverestore/save_x86_pv.c index 4964f1f7b8..92f77fad0f 100644 --- a/tools/libs/guest/xg_sr_save_x86_pv.c +++ b/tools/libs/saverestore/save_x86_pv.c @@ -1,7 +1,7 @@ #include #include =20 -#include "xg_sr_common_x86_pv.h" +#include "common_x86_pv.h" =20 /* Check a 64 bit virtual address for being canonical. */ static inline bool is_canonical_address(xen_vaddr_t vaddr) diff --git a/tools/libs/guest/xg_sr_stream_format.h b/tools/libs/saverestor= e/stream_format.h similarity index 100% rename from tools/libs/guest/xg_sr_stream_format.h rename to tools/libs/saverestore/stream_format.h diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk index efd7a475ba..62a2990b95 100644 --- a/tools/libs/uselibs.mk +++ b/tools/libs/uselibs.mk @@ -20,6 +20,8 @@ LIBS_LIBS +=3D ctrl USELIBS_ctrl :=3D toollog call evtchn gnttab foreignmemory devicemodel LIBS_LIBS +=3D guest USELIBS_guest :=3D evtchn ctrl +LIBS_LIBS +=3D saverestore +USELIBS_saverestore :=3D guest ctrl LIBS_LIBS +=3D store USELIBS_store :=3D toolcore LIBS_LIBS +=3D vchan @@ -27,7 +29,7 @@ USELIBS_vchan :=3D toollog store gnttab evtchn LIBS_LIBS +=3D stat USELIBS_stat :=3D ctrl store LIBS_LIBS +=3D light -USELIBS_light :=3D toollog evtchn toolcore ctrl store hypfs guest +USELIBS_light :=3D toollog evtchn toolcore ctrl store hypfs guest saverest= ore LIBS_LIBS +=3D util USELIBS_util :=3D light FILENAME_util :=3D xlutil From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563911026219.69880296810254; Tue, 1 Jun 2021 09:11:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134981.251009 (Exim 4.92) (envelope-from ) id 1lo6zT-0006Ai-Nf; Tue, 01 Jun 2021 16:11:39 +0000 Received: by outflank-mailman (output) from mailman id 134981.251009; Tue, 01 Jun 2021 16:11:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zT-0006AW-JG; Tue, 01 Jun 2021 16:11:39 +0000 Received: by outflank-mailman (input) for mailman id 134981; Tue, 01 Jun 2021 16:11:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zS-0005Ec-0h for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:38 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.50]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b7821914-ffaa-48dd-966b-98d1e9215484; Tue, 01 Jun 2021 16:11:31 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBR1B9 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:27 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7821914-ffaa-48dd-966b-98d1e9215484 ARC-Seal: i=1; a=rsa-sha256; t=1622563887; cv=none; d=strato.com; s=strato-dkim-0002; b=YjmQDA4/eh3J54LS6IB/jTUMgrucmiljDftMd5EfbbEYqO7565Xc5Z0QceBEhFaguu FA6KyT2U+N//foL6O6GZjxkepQgFvqy94h9RaRNOJKE8hllGOVRcYiJ/1gZgpMJN0j1u VgQUUjwce13nf6EZgmqJK6KcwnfvUHAlH4H4Y3N5qz3wi4OPo51IWmYR46EzUCv9D2Zb J0Xno6qVUBuAcLkG9cqy2w3qDxUkP0/xo3r/9Fb2fiJtxMOXY9X/csSR6c/3dX+sLqfe PzU6L13ebt4VXJrWg9q+EJ23yU8zHk3mMkzf3xoUiUSZLy2VHBDKN0lxxe2MNicJqjgF C9ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563887; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=5m93ctia/WnTzxirdrXBAXbAAhmoz3AnrSBGz7krrzI=; b=hvRDmt8H5FRof7n8T1KREYMwr4EyVRPtnWlsjqHTb/OoQ16P6xmPM9ZnRLnH2d+p7o r9ddcdQUyFSU8Baptt58b+ojz0976r30YMAzDEnUN9I5HIrjnQs2foYO+bpTSWB/kIIT Vc09t2YPC5uRl7zPnBFVp4cSkFq20jDGAAvLT6SjvykWKYLB+tlpeGrzJ/VG1jfxguDe lbNdHU3vJYme5kU8Etm/GNgEpw0KgUNIRPpgwt7zqrXaXThz173ZxZU3JGnAtgazvD4b kqcb/a3P5km9vBa76oDN8tIdori3xicH63GzUqeELh52ycHVBat4pQsFj0/jpU727CDD D91A== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563887; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=5m93ctia/WnTzxirdrXBAXbAAhmoz3AnrSBGz7krrzI=; b=CVYEABEVitHSu0luEGCRyaL9r4GPwpYcPYWWs4a6AYZW1RfpRK/sGrVPWJesz/R8sF 9QnWK/4XTsWBD/kAFUhbW3MXZeOWRzsaKD5HNTr7ieXdVu3jV75j0d4eRrS7rR5W0Af2 1Kb2Wo0QWRv6fTPSgO+bcwnUuG2xXS3vdjokRQZhCOvBKMpKE7SfhKQwwDBaVKROrS+p 6Sk/SI93Px8GL6YfSp+dNq/mQAuj4PdzXqrAWYDOxEYAZVUn8Q+CKdj0aBZ+tLEmqJ9/ Gn8sNYy8+hkoHiYDpH/6RFDPriv0F9CXWOb/OvON1lgjsl+CtRpsv/WXOSLapuRij71v PgdA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 04/38] tools: add readv_exact to libxenctrl Date: Tue, 1 Jun 2021 18:10:44 +0200 Message-Id: <20210601161118.18986-5-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Read a batch of iovec's. In the common case of short reads, finish individual iov's with read_exact. Signed-off-by: Olaf Hering --- tools/libs/ctrl/xc_private.c | 55 +++++++++++++++++++++++++++++++++++- tools/libs/ctrl/xc_private.h | 1 + 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index d94f846686..ea420b9ba8 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -659,8 +659,23 @@ int write_exact(int fd, const void *data, size_t size) =20 #if defined(__MINIOS__) /* - * MiniOS's libc doesn't know about writev(). Implement it as multiple wri= te()s. + * MiniOS's libc doesn't know about readv/writev(). + * Implement it as multiple read/write()s. */ +int readv_exact(int fd, const struct iovec *iov, int iovcnt) +{ + int rc, i; + + for ( i =3D 0; i < iovcnt; ++i ) + { + rc =3D read_exact(fd, iov[i].iov_base, iov[i].iov_len); + if ( rc ) + return rc; + } + + return 0; +} + int writev_exact(int fd, const struct iovec *iov, int iovcnt) { int rc, i; @@ -675,6 +690,44 @@ int writev_exact(int fd, const struct iovec *iov, int = iovcnt) return 0; } #else +int readv_exact(int fd, const struct iovec *iov, int iovcnt) +{ + int rc =3D 0, idx =3D 0; + ssize_t len; + + while ( idx < iovcnt ) + { + len =3D readv(fd, &iov[idx], min(iovcnt - idx, IOV_MAX)); + if ( len =3D=3D -1 && errno =3D=3D EINTR ) + continue; + if ( len <=3D 0 ) + { + rc =3D -1; + goto out; + } + while ( len > 0 && idx < iovcnt ) + { + if ( len >=3D iov[idx].iov_len ) + { + len -=3D iov[idx].iov_len; + } + else + { + void *p =3D iov[idx].iov_base + len; + size_t l =3D iov[idx].iov_len - len; + + rc =3D read_exact(fd, p, l); + if ( rc ) + goto out; + len =3D 0; + } + idx++; + } + } +out: + return rc; +} + int writev_exact(int fd, const struct iovec *iov, int iovcnt) { struct iovec *local_iov =3D NULL; diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index f0b5f83ac8..5d2c7274fb 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -441,6 +441,7 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_m= mu *mmu); =20 /* Return 0 on success; -1 on error setting errno. */ int read_exact(int fd, void *data, size_t size); /* EOF =3D> -1, errno=3D0= */ +int readv_exact(int fd, const struct iovec *iov, int iovcnt); int write_exact(int fd, const void *data, size_t size); int writev_exact(int fd, const struct iovec *iov, int iovcnt); =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563915871368.7936352938125; Tue, 1 Jun 2021 09:11:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134983.251031 (Exim 4.92) (envelope-from ) id 1lo6zZ-0006vt-CI; Tue, 01 Jun 2021 16:11:45 +0000 Received: by outflank-mailman (output) from mailman id 134983.251031; Tue, 01 Jun 2021 16:11:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zZ-0006vi-8T; Tue, 01 Jun 2021 16:11:45 +0000 Received: by outflank-mailman (input) for mailman id 134983; Tue, 01 Jun 2021 16:11:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zX-0005Ec-0s for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:43 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5e280699-7760-4a0f-adfb-a44356807a37; Tue, 01 Jun 2021 16:11:32 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBR1BA (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:27 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5e280699-7760-4a0f-adfb-a44356807a37 ARC-Seal: i=1; a=rsa-sha256; t=1622563887; cv=none; d=strato.com; s=strato-dkim-0002; b=gISW+Gu/ZVcbfMZyUxvVAXMjU8BS7D4pv8ZvtGeCsbYtzWqCA8j3ayIU4wTvSrvgP3 G4bitN66zGnxrgW8IA+Jwhtao7w/EJbsyGyoD7ZuCTKbKuc0SScyaLIYKI/ZJNsqasaD nMg4BSvuJzosmK80Y6psVd6yRFxEIX0xio6kPTuB/Kr3+m7mhwlOCTPG1+HSKpW+3/KI 1yxeDyy8d9vLXeeiJU3WtpqyxVUFPTE42CefxTWO7yo3QvuiH0HpIeY3GlXqNj3dmuxs aR0cmj7G2aabMfEPmyxz2HuerX+b8IBbuPOnefG3/3wnyO59Jg/1MwAuFoqgEtQz9uh6 GrGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563887; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=8EOjWvQk239Wp/aWNifZAKC+Sjf+9ZihUrmLiKkJAAc=; b=jQtdKSlb9FH79dzWoVHsq+ujCn1n/8KRNjKaVo8a5JhPySvEmEgswqcmPRAhLxmZnN rPIrQgwycooC1awY+AEii3QeQOGCQaoAgjlLPa0igEwBv9il2BiI/L0vTkxKTFiud2ed Pt+l/YLilb0RC0KipK0/QP7mbBgDd6aVawfYDz7hUUZBXeA8KWdcxjwvix2IuJViwL7O wvfvpHBeJUCbfvEMqAWFAEAiNUQyOikhs95pEN3ZEXOZR3fpBURQphfQy1usoZu22LeI 3jG9+TzBJLiP7K0phGwU8FqYuVIx/RicY4Tlp/3PU77+JXE7EpQmAILFHJd866+JSQg5 NKYg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563887; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=8EOjWvQk239Wp/aWNifZAKC+Sjf+9ZihUrmLiKkJAAc=; b=eO8dXLOMjMQzUxkYPzl55FUozhW0zM/NyzUQ5Bsb7bzJrJxU2+ycgTzHyD53pMVHkg CtnaH/07//v16yl0yAZ0oDD9Mru5KiGvB8jRPtZXXbqaR97ySCpMFXIz66Agm0fPozmr M6mzR8HMMWFpOexfNKUiJvVJSlgBxui1QDv56AKqJlBV5CAPG7k38+j/M4fwHt/2KfnK zhMD+IKME9f9fgm1oQQYEdADxcZ5P53VoGUz/XKvv3RjIX6x80yKdU7NmJLpRRW5tCyv 01DhK8f0YTK7x/5V0qOBbBit+J/eUSm/TzLLpqFMaFrSg/+fp57Lu7KwzDBWRMzleVrv phFQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 05/38] tools: add xc_is_known_page_type to libxenctrl Date: Tue, 1 Jun 2021 18:10:45 +0200 Message-Id: <20210601161118.18986-6-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Users of xc_get_pfn_type_batch may want to sanity check the data returned by Xen. Add a simple helper for this purpose. Signed-off-by: Olaf Hering --- tools/libs/ctrl/xc_private.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index 5d2c7274fb..afb08aafe1 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -421,6 +421,39 @@ void *xc_map_foreign_ranges(xc_interface *xch, uint32_= t dom, int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom, unsigned int num, xen_pfn_t *); =20 +/* Sanitiy check for types returned by Xen */ +static inline bool xc_is_known_page_type(xen_pfn_t type) +{ + bool ret; + + switch (type) + { + case XEN_DOMCTL_PFINFO_NOTAB: + + case XEN_DOMCTL_PFINFO_L1TAB: + case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L2TAB: + case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L3TAB: + case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L4TAB: + case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_XTAB: + case XEN_DOMCTL_PFINFO_XALLOC: + case XEN_DOMCTL_PFINFO_BROKEN: + ret =3D true; + break; + default: + ret =3D false; + break; + } + return ret; +} + void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits); void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits); =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563907514475.616501135176; Tue, 1 Jun 2021 09:11:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134980.250992 (Exim 4.92) (envelope-from ) id 1lo6zP-0005eM-AZ; Tue, 01 Jun 2021 16:11:35 +0000 Received: by outflank-mailman (output) from mailman id 134980.250992; Tue, 01 Jun 2021 16:11:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zP-0005c3-68; Tue, 01 Jun 2021 16:11:35 +0000 Received: by outflank-mailman (input) for mailman id 134980; Tue, 01 Jun 2021 16:11:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zO-0005X1-0o for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:34 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4413065c-d112-4774-a33b-349495fd5293; Tue, 01 Jun 2021 16:11:32 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBR1BB (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:27 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4413065c-d112-4774-a33b-349495fd5293 ARC-Seal: i=1; a=rsa-sha256; t=1622563888; cv=none; d=strato.com; s=strato-dkim-0002; b=DgU87WsRh140kAE9TWo8r3FrWteINAYMMfUBdn8sMf+WLhlYtnUV+9gTzJ2ZhipOFk +o7WvTY1KoYyCYNg/mvF09j44xxF034sxcTh8r/Coc51YIcmmJVF8i8/CuOarsNGiPvH Ux1To3IUtDs5VAXJ/zrj8S11JEiiJk7Fpe/KNRelscm/lQwXnIwDd2Plpg14qyuW8O6i ewxJT4xHE287ykPD8o09R7p4oJ7IDu+okvS3lTrOXNJuBjhM/XKlPckvaf3cwSJW8a0A sUvK+gQ/5AA3DgjcIJUkVDpus2wG18Uc9U0XqiK44gjdxs+V0ulLGY+EHXOtkbNOQPaf 0QSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563888; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=RFOd7y+e4U6vNTZpXSTmtkhWhMZi9HHw/wrHDQUGpSw=; b=KV23dBncIbEZihTRJbO4NExxqIwqU+zmmb2U04PlPeViIOHVkHmAXuPMjMetbsB+sA 50bEcZHMKh+JzeyPG26RPoFoYAzqfLJYCV2uTAyqBwjQ58ohOl4WXvh6gFsYiUrQvM93 KhDlexcoE06Osg5GCFfnKvqr+8NHWh7ufZU0/E5LvIrEWYlozQGUYu5nU5W82e/DZnum tjDNzGlFdkvbrL7hM0G3YaPSWH/UMPReJQ4e+eRP8ozXqOQinhjXeYaVNjJxfpW+Lybn BujRGqhEU6cxPfqql9XXrPlqPrutr/2zgdK6Uq7/g/LnhGMqMuvI8QlhIL/VCxENTSmt a//w== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563888; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=RFOd7y+e4U6vNTZpXSTmtkhWhMZi9HHw/wrHDQUGpSw=; b=PFT2fniDwBrbJmUSN5yaULUvwdA1DzSIoDeSvoQP27u7KyVOPm000P/xpuaoFuNV5X fVTeojkZrGthq694NBeSn6WM8g4YR6O6fsyZqkScWHepV4egq/E0Tn8gssGa/kKG9Vgv UAh5lL0QbRfWScmkVv75iWzBzhJEosoINZ1CQPOVr+yAYMDfngx8RdcDpmFIIvRAMck/ qrQ1/6A670/1toUPB8t7xu94HbcYqHB9PDK/qCmajSP7a3NK2u4eQjIGpThdAq70OeaD +eb0ZzP8nSnOk/9dIx3DztwVkpptW3jgEEiDjNtsMjhqr7Bv51xjnaEtQ1TraJuJELtf WQjg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 06/38] tools: use xc_is_known_page_type Date: Tue, 1 Jun 2021 18:10:46 +0200 Message-Id: <20210601161118.18986-7-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Verify pfn type on sending side, also verify incoming batch of pfns. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/restore.c | 3 +-- tools/libs/saverestore/save.c | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index be259a1c6b..cccb0dcb71 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -406,8 +406,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) } =20 type =3D (pages->pfn[i] & PAGE_DATA_TYPE_MASK) >> 32; - if ( ((type >> XEN_DOMCTL_PFINFO_LTAB_SHIFT) >=3D 5) && - ((type >> XEN_DOMCTL_PFINFO_LTAB_SHIFT) <=3D 8) ) + if ( xc_is_known_page_type(type) =3D=3D false ) { ERROR("Invalid type %#"PRIx32" for pfn %#"PRIpfn" (index %u)", type, pfn, i); diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 92d96b0533..8d449ee0ae 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -147,6 +147,12 @@ static int write_batch(struct xc_sr_context *ctx) =20 for ( i =3D 0; i < nr_pfns; ++i ) { + if ( xc_is_known_page_type(types[i]) =3D=3D false ) + { + ERROR("Wrong type %#"PRIpfn" for pfn %#"PRIpfn, types[i], mfns= [i]); + goto err; + } + switch ( types[i] ) { case XEN_DOMCTL_PFINFO_BROKEN: From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563911322573.2328780425803; Tue, 1 Jun 2021 09:11:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134982.251020 (Exim 4.92) (envelope-from ) id 1lo6zV-0006TF-32; Tue, 01 Jun 2021 16:11:41 +0000 Received: by outflank-mailman (output) from mailman id 134982.251020; Tue, 01 Jun 2021 16:11:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zU-0006Rp-V4; Tue, 01 Jun 2021 16:11:40 +0000 Received: by outflank-mailman (input) for mailman id 134982; Tue, 01 Jun 2021 16:11:39 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zS-0005X1-VV for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:39 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.81]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 634c5233-a18d-4ebb-9836-a0592a04f72c; Tue, 01 Jun 2021 16:11:33 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBS1BC (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:28 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 634c5233-a18d-4ebb-9836-a0592a04f72c ARC-Seal: i=1; a=rsa-sha256; t=1622563888; cv=none; d=strato.com; s=strato-dkim-0002; b=H8lJPq/K477YKdql0qIATRzz7uyTOc6B28Ae8wq/QXQHwmHhuuI+ZHR1jvElGTWjYV eM7B8be88v9B8z8grOxNUJf2YuyvD4bmjf+XRmHwaEUmMTU1zlbOwz5YLshzxDIcGPLy wIQ1F0eupzLwDA+IhtyK78bixDxiEeAEnmXjV6Y+S/OctdupEY2ejYaf+vYHR3A9RUyq LD8AHSVjS+/veeZV1BbSOS5fr5DfRCTDIkZFr/lSie14xSuTSbX5kRsicP/w5yjQFPRs tS/GWzShpP34YCik9znfhQ2D9QLH81nfeuqpmjfXYhHWRk0nvhbyapxMz1gnqO3Sz1Ov PPBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563888; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=sTwQgwZm9rWRjmRsqDvzAs56CeWxNcqTtl2Vld2f57Q=; b=C6+utwmof9OOi4xjLK2eK3ZNkf7VrIebRVjGqdisVPh9ofzjJpJC56r0cNLUdQp6bP vZNS3sevpo+5eQWncU7OHHrWfY1xGdAIyaaH/PzieZlf1GiVNaB7hGRTr0fcIEyFG2SZ OHXcc2ARFfviE5zwtNi2lY1xmaajinr/MBYZe4kRsOhG+e79zFatl0dcgKZWGmJ6FWYc kdXaqIOa36qjmQkBfBZY0jVHdmCJovzjaHVKRvQIU8CMJFhMzXR2iVirEtFlZb8WTlLr tz3+fQZtM+LcEzagdGuqBxnFmYQgYq6M6CaDJ66VxT7qo5y8SY35vDeXLQJNXuJgS2VW p6lg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563888; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=sTwQgwZm9rWRjmRsqDvzAs56CeWxNcqTtl2Vld2f57Q=; b=KB6pKtR4ZTfiqdk49MNfSbkAa7AWVIrl1ZMbYq/HM7amcx5uEK6E4YI5YovRWFau6m TdnCuuwI7/4YtBtUdZT0XB8pehAwaoY0EPrO7lXtutGIg4aVt653oEtqZbUsjDNgrQhk N2N2aIo7VTgxjbOPX5TMWnLEkVcjv7OeGPNn0pscYMxqk0Vgv5yVkMdxsaIuJui8U/dd ZLaaKBW1Di1H17/05oTLG6M3cD39YDrqz8D0jFnATmqazbBa/v77JIowK1KK4XL9wXUD FkhZaeiLfvvnBtNoV2CFPO8zYPGPWx71Q+Pe8byGRdNYyM+1W8SNxMFyHdqexOTCfw1C YrFQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 07/38] tools: unify type checking for data pfns in migration stream Date: Tue, 1 Jun 2021 18:10:47 +0200 Message-Id: <20210601161118.18986-8-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Introduce a helper which decides if a given pfn type has data for the migration stream. No change in behavior intended. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 17 ++++++++++++++++ tools/libs/saverestore/restore.c | 34 +++++--------------------------- tools/libs/saverestore/save.c | 14 ++----------- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 36946e5d48..50a8479d39 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -467,6 +467,23 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned = int count, /* Handle a STATIC_DATA_END record. */ int handle_static_data_end(struct xc_sr_context *ctx); =20 +static inline bool page_type_has_stream_data(uint32_t type) +{ + bool ret; + + switch (type) + { + case XEN_DOMCTL_PFINFO_XTAB: + case XEN_DOMCTL_PFINFO_XALLOC: + case XEN_DOMCTL_PFINFO_BROKEN: + ret =3D false; + break; + default: + ret =3D true; + break; + } + return ret; +} #endif /* * Local variables: diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index cccb0dcb71..700f9e74b5 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -152,9 +152,8 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned i= nt count, =20 for ( i =3D 0; i < count; ++i ) { - if ( (!types || (types && - (types[i] !=3D XEN_DOMCTL_PFINFO_XTAB && - types[i] !=3D XEN_DOMCTL_PFINFO_BROKEN))) && + if ( (!types || + (types && page_type_has_stream_data(types[i]) =3D=3D true)) = && !pfn_is_populated(ctx, original_pfns[i]) ) { rc =3D pfn_set_populated(ctx, original_pfns[i]); @@ -233,25 +232,8 @@ static int process_page_data(struct xc_sr_context *ctx= , unsigned int count, { ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); =20 - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_NOTAB: - - case XEN_DOMCTL_PFINFO_L1TAB: - case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L2TAB: - case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L3TAB: - case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L4TAB: - case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: - + if ( page_type_has_stream_data(types[i]) =3D=3D true ) mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); - break; - } } =20 /* Nothing to do? */ @@ -271,14 +253,8 @@ static int process_page_data(struct xc_sr_context *ctx= , unsigned int count, =20 for ( i =3D 0, j =3D 0; i < count; ++i ) { - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_XTAB: - case XEN_DOMCTL_PFINFO_BROKEN: - case XEN_DOMCTL_PFINFO_XALLOC: - /* No page data to deal with. */ + if ( page_type_has_stream_data(types[i]) =3D=3D false ) continue; - } =20 if ( map_errs[j] ) { @@ -413,7 +389,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) goto err; } =20 - if ( type < XEN_DOMCTL_PFINFO_BROKEN ) + if ( page_type_has_stream_data(type) =3D=3D true ) /* NOTAB and all L1 through L4 tables (including pinned) should * have a page worth of data in the record. */ pages_of_data++; diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 8d449ee0ae..bcff2d28f5 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -153,13 +153,8 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } =20 - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_BROKEN: - case XEN_DOMCTL_PFINFO_XALLOC: - case XEN_DOMCTL_PFINFO_XTAB: + if ( page_type_has_stream_data(types[i]) =3D=3D false ) continue; - } =20 mfns[nr_pages++] =3D mfns[i]; } @@ -177,13 +172,8 @@ static int write_batch(struct xc_sr_context *ctx) =20 for ( i =3D 0, p =3D 0; i < nr_pfns; ++i ) { - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_BROKEN: - case XEN_DOMCTL_PFINFO_XALLOC: - case XEN_DOMCTL_PFINFO_XTAB: + if ( page_type_has_stream_data(types[i]) =3D=3D false ) continue; - } =20 if ( errors[p] ) { From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563927734394.24368478404574; Tue, 1 Jun 2021 09:12:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134989.251075 (Exim 4.92) (envelope-from ) id 1lo6zi-00009s-DQ; Tue, 01 Jun 2021 16:11:54 +0000 Received: by outflank-mailman (output) from mailman id 134989.251075; Tue, 01 Jun 2021 16:11:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zi-00009U-8h; Tue, 01 Jun 2021 16:11:54 +0000 Received: by outflank-mailman (input) for mailman id 134989; Tue, 01 Jun 2021 16:11:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zh-0005Ec-1H for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:53 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.171]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c2cc1909-2698-480b-8f54-aba8ac30e54e; Tue, 01 Jun 2021 16:11:34 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBS1BD (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:28 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c2cc1909-2698-480b-8f54-aba8ac30e54e ARC-Seal: i=1; a=rsa-sha256; t=1622563889; cv=none; d=strato.com; s=strato-dkim-0002; b=rnJXdhgrXacgywk38aKsQE7O0+NhpB+PxH/eZKPkEcLT/M19R5KSVeg8kCZYBLfUUA AdK8ByK7g8edyjpdC7wtaQdGV+riv8mzN0QZrHHVT5y415uX87SFAHYOCO2DpwLRybAt NKdF1K64VpqL/FYm0MwUhnwW3XpTyYDIxhk5LwO67BI3a1GlxlmTD3UyVn/JVhku7nq4 yZz1zI+OXSZOuaQghShoAUHIL2xfbTZLYn6RsoahVmr9zDdW7DcEZkUg/J1ghXqmdWf7 VSHUg0yFXt2NyvLmiNrYyw9lrF25GKrq6yJpQ55Svxti2YNMGqLcm/bFJ7ViY0af9RY4 bVZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563889; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=cDil57jxI4Z5Z9nbXjVlKKlvOaQMfsb66RRaO8m9ED8=; b=eUW5+lj09D+EqeYYhWwyDOnODC1rQFKFUnFVTvraE2R2lM4Frg5cOvunGY6tW5XPMf 9WNVbsiXm/xvd2/LkVdhmd0GgV2Zqk+k+RZmn81G+4wqIUriS+nslfVg0ZXXRtxtEwm6 NInQxJoQLUvRCR1kxHcrv/otELiU7bcy18W56VhYV/S+dFLXRRWglzVgHUIVYlS3jvfy 6vEmdDhlC6rDuRcC2KiOtsWG02mipc+rj1LX0FjNnoS2mP9I9j1Y0lyYCAR7uZX0r8ij p0WgLa8Alv0NiBcWfDihUQcZUn/kj3PzktUykj5jDeUS8YjDxV9EamF4SZWum1zZCN7K rKDg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563889; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=cDil57jxI4Z5Z9nbXjVlKKlvOaQMfsb66RRaO8m9ED8=; b=hNSJVlEhOJlKLSnCwsYffA1aYwF0tB02Ok2uJ21W3vA/ExnRX0/9xUPLYs1JpLlotg m4vphErILK7zWQwilFZ2DvEgeebVRQ8nouo91ktzb9yHleGt+srZkLPC//+yOXLJN8Rk DkZ1ezBLEGpahNxBOIV5rbPrzAM3hk059Z/0681Th/S+0HoqJvW8Th/S5WtTP2gr1YaU nQ5M+vGShR0Ey+L00f5Q6O2JtU9q5oM2RpJ/MyEXMhM5hbNvU70gf9iVGZ3TYREq26uM KUO2ql8E6ybCmzCisCzTDtByTrYo7v50wxzaCrVHm61HZnag1J95lamGSp6dGIv2e1Pi 3G9Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 08/38] tools: show migration transfer rate in send_dirty_pages Date: Tue, 1 Jun 2021 18:10:48 +0200 Message-Id: <20210601161118.18986-9-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Show how fast domU pages are transferred in each iteration. The relevant data is how fast the pfns travel, not so much how much protocol overhead exists. So the reported MiB/sec is just for pfns. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 50a8479d39..f5fe23caad 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -250,6 +250,8 @@ struct xc_sr_context bool debug; =20 unsigned long p2m_size; + size_t pages_sent; + size_t overhead_sent; =20 struct precopy_stats stats; =20 diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index bcff2d28f5..760ca04a84 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -1,5 +1,6 @@ #include #include +#include =20 #include "common.h" =20 @@ -238,6 +239,8 @@ static int write_batch(struct xc_sr_context *ctx) iov[3].iov_len =3D nr_pfns * sizeof(*rec_pfns); =20 iovcnt =3D 4; + ctx->save.pages_sent +=3D nr_pages; + ctx->save.overhead_sent +=3D sizeof(rec) + sizeof(hdr) + nr_pfns * siz= eof(*rec_pfns); =20 if ( nr_pages ) { @@ -357,6 +360,43 @@ static int suspend_domain(struct xc_sr_context *ctx) return 0; } =20 +static void show_transfer_rate(struct xc_sr_context *ctx, struct timespec = *start) +{ + xc_interface *xch =3D ctx->xch; + struct timespec end =3D {}, diff =3D {}; + size_t ms, MiB_sec =3D ctx->save.pages_sent * PAGE_SIZE; + + if (!MiB_sec) + return; + + if ( clock_gettime(CLOCK_MONOTONIC, &end) ) + PERROR("clock_gettime"); + + if ( (end.tv_nsec - start->tv_nsec) < 0 ) + { + diff.tv_sec =3D end.tv_sec - start->tv_sec - 1; + diff.tv_nsec =3D end.tv_nsec - start->tv_nsec + (1000U*1000U*1000U= ); + } + else + { + diff.tv_sec =3D end.tv_sec - start->tv_sec; + diff.tv_nsec =3D end.tv_nsec - start->tv_nsec; + } + + ms =3D (diff.tv_nsec / (1000U*1000U)); + if (!ms) + ms =3D 1; + ms +=3D (diff.tv_sec * 1000U); + + MiB_sec *=3D 1000U; + MiB_sec /=3D ms; + MiB_sec /=3D 1024U*1024U; + + errno =3D 0; + IPRINTF("%s: %zu bytes + %zu pages in %ld.%09ld sec, %zu MiB/sec", __f= unc__, + ctx->save.overhead_sent, ctx->save.pages_sent, diff.tv_sec, di= ff.tv_nsec, MiB_sec); +} + /* * Send a subset of pages in the guests p2m, according to the dirty bitmap. * Used for each subsequent iteration of the live migration loop. @@ -370,9 +410,15 @@ static int send_dirty_pages(struct xc_sr_context *ctx, xen_pfn_t p; unsigned long written; int rc; + struct timespec start =3D {}; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); =20 + ctx->save.pages_sent =3D 0; + ctx->save.overhead_sent =3D 0; + if ( clock_gettime(CLOCK_MONOTONIC, &start) ) + PERROR("clock_gettime"); + for ( p =3D 0, written =3D 0; p < ctx->save.p2m_size; ++p ) { if ( !test_bit(p, dirty_bitmap) ) @@ -396,6 +442,7 @@ static int send_dirty_pages(struct xc_sr_context *ctx, if ( written > entries ) DPRINTF("Bitmap contained more entries than expected..."); =20 + show_transfer_rate(ctx, &start); xc_report_progress_step(xch, entries, entries); =20 return ctx->save.ops.check_vm_state(ctx); From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563919438704.3011791309953; Tue, 1 Jun 2021 09:11:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134984.251035 (Exim 4.92) (envelope-from ) id 1lo6zZ-0006zH-TP; Tue, 01 Jun 2021 16:11:45 +0000 Received: by outflank-mailman (output) from mailman id 134984.251035; Tue, 01 Jun 2021 16:11:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zZ-0006xx-Io; Tue, 01 Jun 2021 16:11:45 +0000 Received: by outflank-mailman (input) for mailman id 134984; Tue, 01 Jun 2021 16:11:44 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zX-0005X1-Vi for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:44 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.169]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 81fbc3a2-15f3-4487-9727-c00067a00375; Tue, 01 Jun 2021 16:11:35 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBT1BE (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:29 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 81fbc3a2-15f3-4487-9727-c00067a00375 ARC-Seal: i=1; a=rsa-sha256; t=1622563889; cv=none; d=strato.com; s=strato-dkim-0002; b=T9QrHmjHticlOV5jT7XpL4jjdUnulJExOzssvTbvpX60wpSvZyO9ov7fUxpNbmF8BL g07dtudMcsazpJVJFxnAvJ0CbMB9BwB15OtZKb1X8uciw2h0QuJ83AQPlANkVmLb2g4v G33hNxTSFxEdhnjfj02XcSWzxIEUDZ4nGpkAA9rcCFhzkhDZFpwT3WcmiFuoQmuLw3IG 6cWPG3Reu162mWKvFoJxEAa+mkaFdJbX2F5fsdMSfWsKoAZWdQOFH3qJ24V4ZqpdPeE1 7SN4X6IkVg7VThgmhP2BbycjHjK9pACxpySLHLuIgD7ZKeOc4s0i3ESTGfS/Hl1kAdNE evMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563889; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=5ichTSe1XRD84BJzTM12jbhc1IFgz0uXqluaqXpByoA=; b=ZPQOqOMWFGKx8XkLHojU2CYmvcs4NIy2WrFgZEttDQmjmZ4LtbvrlEZ2gqa+pswchB EDzF8134fStSRlndZTWwQGiYJ6V1AmvEPQKY7CkD12JbhcfC1JmGLSTqqFzbVThcwus3 wSu/ety/n3pgDCTEoECb1PysUN94j0nG7++0jomdTJ0IaKCLQKZ6+e1HCdCYNlbZIMVt W+FJRjCSekYJWON/lcwSIxN509pB8KmgkAxhqcrFrqpRnu98S4X0jl7hgM4+3l1HqSks ORk8UFcL16IBOnWz03HzTJw2M4beoz58f/sAx+4h5GmIEe4Y+lN+OouKs6NNp/tgPhwn S4/Q== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563889; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=5ichTSe1XRD84BJzTM12jbhc1IFgz0uXqluaqXpByoA=; b=bEZ+OWbk1tg7oZ5SRTFU6lDhU0LescHmqXSi48yjAbmsag1gAtNFCZ0h6RNNgTIQFy Q3FuZO0dlhzO1Cayc4FQ/UECK8TL/8t88uUSoFtFWFthuQqBYjw3a/v0Oco8p/RFd79y BEP0tptNLxxaHJh4bHYzyXzwjG6xWXS0RX/Y7PaPGdqedIX493aOaSBYlIwfUDilNKww VNFWIGH8zwZT3pJ9Gr68GxZYh3cYncjKM/Vh7k4yndwB57NWvbwsq6D6XG709aAajm7e +otmb88g75ABukbnR7RMSWKCfis0KexEwArRWpWgMLo99Rw+c3spOa5vRzRWouLuiVud IeFQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 09/38] tools/guest: prepare to allocate arrays once Date: Tue, 1 Jun 2021 18:10:49 +0200 Message-Id: <20210601161118.18986-10-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The hotpath 'send_dirty_pages' is supposed to do just one thing: sending. The other end 'handle_page_data' is supposed to do just receiving. But instead both do other costly work like memory allocations and data movi= ng. Do the allocations once, the array sizes are a compiletime constant. Avoid unneeded copying of data by receiving data directly into mapped guest= memory. This patch is just prepartion, subsequent changes will populate the arrays. Once all changes are applied, migration of a busy HVM domU changes like tha= t: Without this series, from sr650 to sr950 (xen-4.15.20201027T173911.16a20963= b3 xen_testing): 2020-10-29 10:23:10.711+0000: xc: show_transfer_rate: 23663128 bytes + 2879= 563 pages in 55.324905335 sec, 203 MiB/sec: Internal error 2020-10-29 10:23:35.115+0000: xc: show_transfer_rate: 16829632 bytes + 2097= 552 pages in 24.401179720 sec, 335 MiB/sec: Internal error 2020-10-29 10:23:59.436+0000: xc: show_transfer_rate: 16829032 bytes + 2097= 478 pages in 24.319025928 sec, 336 MiB/sec: Internal error 2020-10-29 10:24:23.844+0000: xc: show_transfer_rate: 16829024 bytes + 2097= 477 pages in 24.406992500 sec, 335 MiB/sec: Internal error 2020-10-29 10:24:48.292+0000: xc: show_transfer_rate: 16828912 bytes + 2097= 463 pages in 24.446489027 sec, 335 MiB/sec: Internal error 2020-10-29 10:25:01.816+0000: xc: show_transfer_rate: 16836080 bytes + 2098= 356 pages in 13.447091818 sec, 609 MiB/sec: Internal error With this series, from sr650 to sr950 (xen-4.15.20201027T173911.16a20963b3 = xen_unstable): 2020-10-28 21:26:05.074+0000: xc: show_transfer_rate: 23663128 bytes + 2879= 563 pages in 52.564054368 sec, 213 MiB/sec: Internal error 2020-10-28 21:26:23.527+0000: xc: show_transfer_rate: 16830040 bytes + 2097= 603 pages in 18.450592015 sec, 444 MiB/sec: Internal error 2020-10-28 21:26:41.926+0000: xc: show_transfer_rate: 16830944 bytes + 2097= 717 pages in 18.397862306 sec, 445 MiB/sec: Internal error 2020-10-28 21:27:00.339+0000: xc: show_transfer_rate: 16829176 bytes + 2097= 498 pages in 18.411973339 sec, 445 MiB/sec: Internal error 2020-10-28 21:27:18.643+0000: xc: show_transfer_rate: 16828592 bytes + 2097= 425 pages in 18.303326695 sec, 447 MiB/sec: Internal error 2020-10-28 21:27:26.289+0000: xc: show_transfer_rate: 16835952 bytes + 2098= 342 pages in 7.579846749 sec, 1081 MiB/sec: Internal error Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 8 ++++++++ tools/libs/saverestore/restore.c | 8 ++++++++ tools/libs/saverestore/save.c | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index f5fe23caad..80b2e878aa 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -223,6 +223,12 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct xc_sr_save_arrays { +}; + +struct xc_sr_restore_arrays { +}; + struct xc_sr_context { xc_interface *xch; @@ -260,6 +266,7 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct xc_sr_save_arrays *m; } save; =20 struct /* Restore data. */ @@ -311,6 +318,7 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + struct xc_sr_restore_arrays *m; } restore; }; =20 diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 700f9e74b5..a6cf9ee41c 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -739,6 +739,13 @@ static int setup(struct xc_sr_context *ctx) } ctx->restore.allocated_rec_num =3D DEFAULT_BUF_RECORDS; =20 + ctx->restore.m =3D malloc(sizeof(*ctx->restore.m)); + if ( !ctx->restore.m ) { + ERROR("Unable to allocate memory for arrays"); + rc =3D -1; + goto err; + } + err: return rc; } @@ -757,6 +764,7 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size))= ); =20 + free(ctx->restore.m); free(ctx->restore.buffered_records); free(ctx->restore.populated_pfns); =20 diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 760ca04a84..1662e3ee50 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -853,8 +853,9 @@ static int setup(struct xc_sr_context *ctx) ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); + ctx->save.m =3D malloc(sizeof(*ctx->save.m)); =20 - if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pag= es ) + if ( !ctx->save.m || !ctx->save.batch_pfns || !dirty_bitmap || !ctx->s= ave.deferred_pages ) { ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" " deferred pages"); @@ -886,6 +887,7 @@ static void cleanup(struct xc_sr_context *ctx) NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); free(ctx->save.batch_pfns); + free(ctx->save.m); } =20 /* From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563928116610.1129226382147; Tue, 1 Jun 2021 09:12:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134990.251079 (Exim 4.92) (envelope-from ) id 1lo6zj-0000GC-5D; Tue, 01 Jun 2021 16:11:55 +0000 Received: by outflank-mailman (output) from mailman id 134990.251079; Tue, 01 Jun 2021 16:11:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zi-0000ES-Qm; Tue, 01 Jun 2021 16:11:54 +0000 Received: by outflank-mailman (input) for mailman id 134990; Tue, 01 Jun 2021 16:11:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zh-0005X1-Vz for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:54 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 083036e1-0830-4d8b-ad5b-37494827089f; Tue, 01 Jun 2021 16:11:35 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBT1BF (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:29 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 083036e1-0830-4d8b-ad5b-37494827089f ARC-Seal: i=1; a=rsa-sha256; t=1622563889; cv=none; d=strato.com; s=strato-dkim-0002; b=j23TsGK+nbxG3edYgJTv/d8uKBKj6wrHbhV04xpLKdY0XkbgSQOZXCoPHjLAWlM3Pk QonfCPg1lvOQ+Hy1IK2zwotH1I570y4bmoWrDHqw6L4VWs0XnuKvdtgvt5qDq0I+17S5 0Kke+8CmT63dwlYE8S6GVNSlIf6TTGhwqK8reIMvhJevQk5sG7BXpIMe8wmptslDGnp0 imOeMDiupWnNsBUmtDjrT38rRQLotHqptcfcCcmpasdlrsQnTXm1i3/Q26CHAGJfUuaV euTLK+cqnPBiLGlXDxqjxu79d8JRY+kq8rheD1fDXfijG8RyKijsKpG9WYuV9GI8WCcN 45Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563889; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=E7wVU3AYom1qSRf+sliiKc9mzY5OMMBLqGFhTssnmUM=; b=OTb0QjhiXLeVWtHNw8GQlI1+c5r0H2nPn3R+l6SKShj2rIwf+kb4lGnsFLWkHF2LbJ EyVEHbc49qRnZ3wd9FLhGNzanaF/ZLDFSoPAeoA2kTxTZv2vxAEmJn3k29MlzMgYLmIs yN0Y7QnLCKBvQYuEpNhcG0NPSV8RiFVNfV3KFyFxhtkK9/ERFdIecPyq16ep0MHY88YT waayuplCtyhIhoPP/bx3HgI7b5KQU6k57gq6CEtsCpGlfgpSBGuW2r4L6DCOaUhlhjS+ 2QRv7wsTBEv2Js0gWjUWZmOOCRXsRbRO7hyNZfoCAYokV9MDq7cdiucs4TtX+J7e8aLE 8YoA== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563889; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=E7wVU3AYom1qSRf+sliiKc9mzY5OMMBLqGFhTssnmUM=; b=cVcv1Crx7fTfkauGUpNoOIuyaysmjNizIy2vMBgKV15/N5Rh3KQeueIMpvMWtFe3PJ S03OxF0ICFBINoo7HNh5D3xnVEJWfvBLrz6d5hP1RJpL4N5wwdw60OSklwOHdP9Ko53x W9XYO8zNS4E7M7LH1v6mjlYyDhhuBEFqz2QCi5Z0HH4mfl3MkXSeEKXbRdZZJCb1MuVW DLhIL9Bgg/msb0MxWq8xtRAdMwVIkWZvwhJF5zqJgF99GcAQG2Y/c8UcwcuIP4BfFk1s 4JZrkIbElRkzQE12k65ydyhT+/Amxzz+LEkyhBn/jUFkO+Kdp8G//YHk2ze3tsPxhqeb 3Ucg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 10/38] tools/guest: save: move batch_pfns Date: Tue, 1 Jun 2021 18:10:50 +0200 Message-Id: <20210601161118.18986-11-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The batch_pfns array is already allocated in advance. Move it into the preallocated area. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 +- tools/libs/saverestore/save.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 80b2e878aa..0d94a4c01e 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -224,6 +224,7 @@ static inline int update_blob(struct xc_sr_blob *blob, } =20 struct xc_sr_save_arrays { + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { @@ -261,7 +262,6 @@ struct xc_sr_context =20 struct precopy_stats stats; =20 - xen_pfn_t *batch_pfns; unsigned int nr_batch_pfns; unsigned long *deferred_pages; unsigned long nr_deferred_pages; diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 1662e3ee50..b11ce70a11 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -77,7 +77,7 @@ static int write_checkpoint_record(struct xc_sr_context *= ctx) =20 /* * Writes a batch of memory as a PAGE_DATA record into the stream. The ba= tch - * is constructed in ctx->save.batch_pfns. + * is constructed in ctx->save.m->batch_pfns. * * This function: * - gets the types for each pfn in the batch. @@ -128,12 +128,12 @@ static int write_batch(struct xc_sr_context *ctx) for ( i =3D 0; i < nr_pfns; ++i ) { types[i] =3D mfns[i] =3D ctx->save.ops.pfn_to_gfn(ctx, - ctx->save.batch_pfns= [i]); + ctx->save.m->batch_p= fns[i]); =20 /* Likely a ballooned page. */ if ( mfns[i] =3D=3D INVALID_MFN ) { - set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pages); + set_bit(ctx->save.m->batch_pfns[i], ctx->save.deferred_pages); ++ctx->save.nr_deferred_pages; } } @@ -179,7 +179,7 @@ static int write_batch(struct xc_sr_context *ctx) if ( errors[p] ) { ERROR("Mapping of pfn %#"PRIpfn" (mfn %#"PRIpfn") failed %= d", - ctx->save.batch_pfns[i], mfns[p], errors[p]); + ctx->save.m->batch_pfns[i], mfns[p], errors[p]); goto err; } =20 @@ -193,7 +193,7 @@ static int write_batch(struct xc_sr_context *ctx) { if ( rc =3D=3D -1 && errno =3D=3D EAGAIN ) { - set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pa= ges); + set_bit(ctx->save.m->batch_pfns[i], ctx->save.deferred= _pages); ++ctx->save.nr_deferred_pages; types[i] =3D XEN_DOMCTL_PFINFO_XTAB; --nr_pages; @@ -224,7 +224,7 @@ static int write_batch(struct xc_sr_context *ctx) rec.length +=3D nr_pages * PAGE_SIZE; =20 for ( i =3D 0; i < nr_pfns; ++i ) - rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; + rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.m->batch_= pfns[i]; =20 iov[0].iov_base =3D &rec.type; iov[0].iov_len =3D sizeof(rec.type); @@ -296,9 +296,9 @@ static int flush_batch(struct xc_sr_context *ctx) =20 if ( !rc ) { - VALGRIND_MAKE_MEM_UNDEFINED(ctx->save.batch_pfns, + VALGRIND_MAKE_MEM_UNDEFINED(ctx->save.m->batch_pfns, MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); + sizeof(*ctx->save.m->batch_pfns)); } =20 return rc; @@ -315,7 +315,7 @@ static int add_to_batch(struct xc_sr_context *ctx, xen_= pfn_t pfn) rc =3D flush_batch(ctx); =20 if ( rc =3D=3D 0 ) - ctx->save.batch_pfns[ctx->save.nr_batch_pfns++] =3D pfn; + ctx->save.m->batch_pfns[ctx->save.nr_batch_pfns++] =3D pfn; =20 return rc; } @@ -850,14 +850,12 @@ static int setup(struct xc_sr_context *ctx) =20 dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); - ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); ctx->save.m =3D malloc(sizeof(*ctx->save.m)); =20 - if ( !ctx->save.m || !ctx->save.batch_pfns || !dirty_bitmap || !ctx->s= ave.deferred_pages ) + if ( !ctx->save.m || !dirty_bitmap || !ctx->save.deferred_pages ) { - ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" + ERROR("Unable to allocate memory for dirty bitmaps and" " deferred pages"); rc =3D -1; errno =3D ENOMEM; @@ -886,7 +884,6 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); - free(ctx->save.batch_pfns); free(ctx->save.m); } =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563931142126.42340276571883; Tue, 1 Jun 2021 09:12:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134991.251097 (Exim 4.92) (envelope-from ) id 1lo6zn-0001EJ-O0; Tue, 01 Jun 2021 16:11:59 +0000 Received: by outflank-mailman (output) from mailman id 134991.251097; Tue, 01 Jun 2021 16:11:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zn-0001D1-FS; Tue, 01 Jun 2021 16:11:59 +0000 Received: by outflank-mailman (input) for mailman id 134991; Tue, 01 Jun 2021 16:11:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zm-0005Ec-25 for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:58 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.171]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id bc1433c2-08b3-4c9d-af2f-27f9947fd7e2; Tue, 01 Jun 2021 16:11:34 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBU1BG (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:30 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bc1433c2-08b3-4c9d-af2f-27f9947fd7e2 ARC-Seal: i=1; a=rsa-sha256; t=1622563890; cv=none; d=strato.com; s=strato-dkim-0002; b=gfvBK3rm3/R3R8slMSuvIEW5iMFWWgvTDeBPPf/JfLLEDErVU4b0BBhZvlpAl/U1fU 1BEqNyQGG8fNotSFJF+UsE0GVrO0Bd7UTjDks25GmoEhLX1hKqQ7z5ASzb1p3eeODGXO QSOl4D3MKHXHuxCirEVNO9ePwLYTVX4XpDw9JSLwxj6VnnJrE7ULAKtTmplelYsryByD suz7yKUGMFRP/ZYSQ01kuNeSco5XpW01wu1XQv4aEGgvhtifd6kQgSVn/pVVzY9tbNjE +rPo+jQTRNUWxeW+tZbrF1rJ98A6PQVlfjYszv8+h9fbhWn0I+p5Jv7+AK9ZHHyclWAP 3miA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563890; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=vfw3BzaI+AtROP8LqwGXxo+9GSxWRwpN3QZDZ8A0bxw=; b=kn8QxZANHcRrRWn34z0LNNH9t4PefGaDihf6CSyVrGAQGfua+RAJmsDoUjQCiDLTCL SyDdmXXKbZazK7InbtE+Q7kcJzIZABdN7uGqRyq/299EDng8qCsd5dWwshI2k26VxSoO cRJwCzO8e53RwSFx7EsKCeY+qnmBf+mvx4J0qc5o+6A3BEYQKpElDbGo3S/8/7jhzQSF tOrlRiHYpRlSueNf2x4SNC1gWP9hNkU6DruJaB8NYfIPq/xMb0+g3LJITxGHRrTM3Ob0 fxthk/0YHII7n7aPt1dxuZltmy8456ph4Sz5QNdFHuY5pgqXOhneCg37iumSaPTRIu8t 51Yg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563890; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=vfw3BzaI+AtROP8LqwGXxo+9GSxWRwpN3QZDZ8A0bxw=; b=RqAcStaHO1dwd0/znVRGXp/aK8OS5Dj9pZ9TV4CgY6qAnMADhOjX2QgDcD4JKb3PaC fF6oW+ib1BIiloMTwD1N4jdcYn2OTboVBEP91xy7BHGapPA/0kVmgwfJck/bSuJg7XMa PJfJUXF9OHDPnQ2JIZgNKm9KkULXlFIEdeljT+KZI6nCL4y4JfDyHXJEL1CdtsB7BcN/ HZ3hUJ9ebfNx+hB/O2va2d2ptilEqDTZdy2NRlXFpAIDdhgBt52u/IWdR0t3p9OX6dTY HWmFksYWgr81/B5Z1lebvh7Q9LsyGC5yLjN4W84fmXueSElm3udOyAmSF7pQtNH2axV5 +4XQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 11/38] tools/guest: save: move mfns array Date: Tue, 1 Jun 2021 18:10:51 +0200 Message-Id: <20210601161118.18986-12-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move mfns array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 0d94a4c01e..2335e6d27b 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -225,6 +225,8 @@ static inline int update_blob(struct xc_sr_blob *blob, =20 struct xc_sr_save_arrays { xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; + /* write_batch: Mfns of the batch pfns. */ + xen_pfn_t mfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index b11ce70a11..1719ff08ba 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -88,7 +88,7 @@ static int write_checkpoint_record(struct xc_sr_context *= ctx) static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D NULL, *types =3D NULL; + xen_pfn_t *mfns =3D ctx->save.m->mfns, *types =3D NULL; void *guest_mapping =3D NULL; void **guest_data =3D NULL; void **local_pages =3D NULL; @@ -105,8 +105,6 @@ static int write_batch(struct xc_sr_context *ctx) =20 assert(nr_pfns !=3D 0); =20 - /* Mfns of the batch pfns. */ - mfns =3D malloc(nr_pfns * sizeof(*mfns)); /* Types of the batch pfns. */ types =3D malloc(nr_pfns * sizeof(*types)); /* Errors from attempting to map the gfns. */ @@ -118,7 +116,7 @@ static int write_batch(struct xc_sr_context *ctx) /* iovec[] for writev(). */ iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); =20 - if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) + if ( !types || !errors || !guest_data || !local_pages || !iov ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -277,7 +275,6 @@ static int write_batch(struct xc_sr_context *ctx) free(guest_data); free(errors); free(types); - free(mfns); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563922359756.253937004211; Tue, 1 Jun 2021 09:12:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134987.251058 (Exim 4.92) (envelope-from ) id 1lo6ze-0007kS-1E; Tue, 01 Jun 2021 16:11:50 +0000 Received: by outflank-mailman (output) from mailman id 134987.251058; Tue, 01 Jun 2021 16:11:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zd-0007jB-ML; Tue, 01 Jun 2021 16:11:49 +0000 Received: by outflank-mailman (input) for mailman id 134987; Tue, 01 Jun 2021 16:11:49 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zc-0005X1-Vp for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:49 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.169]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d95e56a8-658a-4556-a121-5a0a161d398a; Tue, 01 Jun 2021 16:11:35 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBU1BH (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:30 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d95e56a8-658a-4556-a121-5a0a161d398a ARC-Seal: i=1; a=rsa-sha256; t=1622563890; cv=none; d=strato.com; s=strato-dkim-0002; b=YMR9cnE/7YTMLEsOAkqAaGI/s9hiUMB9XThQFl0NtmytdriDfkpznVZNJ5H9zOIuiq SB8U1oZikyG0GXcnyYvjvaZRxAuL3+gCuMuEmkQaZ1gEb/uQD0mOeMp4hp5vQzR5g4qo M0KlcQlZC7TOpXMC7c4KbAqv78NQVVKI8tPgcuEaQhleMUPT9fGdNWoqvTElzXAtGVhv RjXsCkmW1+AsTMos6fUsYcGOC4Kxc6ej5G806z2FT0lnR2IALlSb3llwuWSBBNR1FAeJ vBFExwNHFwD3xwMx7kxBWkXxq1x/he6LIftLl9Auo+UVXlCrsIBVTQsdthOhqVnAWRPs s5EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563890; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=yKL38YLQb6Sra5wh9hHuxAm/2IobWvLNV1y2lL6e8b0=; b=p4YmyBC9+RbKz2QbG/UltqPdFVcJhVy/agk4dz6I7fPe7w3g6b6vqEe8wxX4sy14pj J4vyp4A1cZLShGuGGjICkoGxWxRFfh4oHKSHJkKY2jbETn+dZof6QF/c6BkAlJcOU2hG XCiORVT+sP7B52ZB4dtFUuf7zk130chphDl/xshi/hocRl9hidJhfzxpUr556VozCdas 3CEOdVaBPMQoIAAZXMbOOwO6ki+kqTeuioRDUJ23Wbq2iqSvrgD/eI05OH/2Q2AHqrel Mx1BHxjZ/I049hSpuB7QSpaZj/1UML+CqyA4WNUIc9CiDNH5LfcjWs3Dvbe6SqEk0CQB DRWQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563890; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=yKL38YLQb6Sra5wh9hHuxAm/2IobWvLNV1y2lL6e8b0=; b=S/4senCq7s40tD0AErAmsIDsxFNOWSmL/5lyhGIVEG0hbn0AEHz82+rBKNT56SRWk0 FJgKATfvzGEbtKO1w5ojKjm0dFnC1PRzjpm3QDphUcTB6qR7Um+HIZIqNex2mCLOCJiB IRC8nSEJNg644oKCgOk6RDlO9QTkYvmkUKodUsUR8xVVzFafNXDBXCNB3aTuKUyoaefD 0Xczd9EvaQbhMSzQ9aBhouWjurTZ2dS/C6ZIOks6z3acGTFR4TqS+kQm6D+25FpGDgrM GsfxPSk+56+oKsmQEaPGLMBAEU9sFT1Nw1xxHVeLCFG0YZ0PrhHsrG+cXSdYlBy7ESdD JM2Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 12/38] tools/guest: save: move types array Date: Tue, 1 Jun 2021 18:10:52 +0200 Message-Id: <20210601161118.18986-13-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move types array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 2335e6d27b..81d4a79b13 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -227,6 +227,8 @@ struct xc_sr_save_arrays { xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; /* write_batch: Mfns of the batch pfns. */ xen_pfn_t mfns[MAX_BATCH_SIZE]; + /* write_batch: Types of the batch pfns. */ + xen_pfn_t types[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 1719ff08ba..be65286570 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -88,7 +88,7 @@ static int write_checkpoint_record(struct xc_sr_context *= ctx) static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D ctx->save.m->mfns, *types =3D NULL; + xen_pfn_t *mfns =3D ctx->save.m->mfns, *types =3D ctx->save.m->types; void *guest_mapping =3D NULL; void **guest_data =3D NULL; void **local_pages =3D NULL; @@ -105,8 +105,6 @@ static int write_batch(struct xc_sr_context *ctx) =20 assert(nr_pfns !=3D 0); =20 - /* Types of the batch pfns. */ - types =3D malloc(nr_pfns * sizeof(*types)); /* Errors from attempting to map the gfns. */ errors =3D malloc(nr_pfns * sizeof(*errors)); /* Pointers to page data to send. Mapped gfns or local allocations. */ @@ -116,7 +114,7 @@ static int write_batch(struct xc_sr_context *ctx) /* iovec[] for writev(). */ iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); =20 - if ( !types || !errors || !guest_data || !local_pages || !iov ) + if ( !errors || !guest_data || !local_pages || !iov ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -274,7 +272,6 @@ static int write_batch(struct xc_sr_context *ctx) free(local_pages); free(guest_data); free(errors); - free(types); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563935537159.47716099230445; Tue, 1 Jun 2021 09:12:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134996.251120 (Exim 4.92) (envelope-from ) id 1lo6zs-0002Gi-C9; Tue, 01 Jun 2021 16:12:04 +0000 Received: by outflank-mailman (output) from mailman id 134996.251120; Tue, 01 Jun 2021 16:12:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zs-0002Fn-0k; Tue, 01 Jun 2021 16:12:04 +0000 Received: by outflank-mailman (input) for mailman id 134996; Tue, 01 Jun 2021 16:12:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zr-0005Ec-1g for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:03 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c456e689-f8e7-4608-a313-5ae1a4025123; Tue, 01 Jun 2021 16:11:35 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBV1BI (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:31 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c456e689-f8e7-4608-a313-5ae1a4025123 ARC-Seal: i=1; a=rsa-sha256; t=1622563891; cv=none; d=strato.com; s=strato-dkim-0002; b=LCJtyMR+Zgd7W9rxsbxtC58x5DfEqpSITeFdBdbnYt4fP5IZM6iO61a5JCg+irtKtN WF8XQtNF/OaWj6lSX7ugEy9guiW6JR4O94cMSSlJUQhDGZ3OP0PTpsPwEdMtZ8VmDI2r Ed9b3gCHYbq3hH1qAhtFLlPuPQVr5A1PrrG66MlKkrH87v3zgeEQOCtBt94mDb3e4jIa hbD+kZNaMF2Ix8BEhjmoe/JyS7jEXSYCrC1o0iWeAnjRp+KhxLidp8JX0PYOSMAgnG9c FyUNV4og2SgLVQj4v211CNDBBsD6N1GDIGABj/Tb3y+IPC5ukaMF4vUP1aKWJ1bKgAAY P6xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563891; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=1Vlq702zoBkp5PCmpnAeHRVWBwGGiYV8RLsu7fpX0qA=; b=jbQ28FbpZshSCLQxBf2YVYZKWlfJQNtSvqQz9GWFU1unQnx11tq3ODYUqT26XjAAC6 +bIyj4IxL0vdH5I/W9uSsG6HIJq4GkqondTs5j12K8ressIjv1boHQ+UxhFXTILZXfNK 3BTnKDb6ntItpXfLrM4PSroAB4dAFWvs6GdlH/7Fvuy3evm+rEmRiD/Aa6UPuPeiYsT9 GvAS/z6VBJzfTkulBz7doXRyhFKtzx4xoJCUGEBrSh4SBPOm15x5VHo4EcMHtHCh9+x+ r0ZBkT8SotrGgADOvN7BzyYUX7MGRquG4xVNvimOOaeF3v3oQNr6Vy/SBuqJU0Bkf3AP 6tJw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563891; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=1Vlq702zoBkp5PCmpnAeHRVWBwGGiYV8RLsu7fpX0qA=; b=NQ3hEjfyFg2Fe5DZfbqXwhRCjwdZDgKX+fBM2hPIRF7TkVeFsAD4FKQ3HANlaDTW3T 9QfHm+knoTz8as5wuOjsn99kFxk4CDLtnmo5W9x26Wn1hq1maCxVDMRwBWvKcC5n47BY Egi/WhJT/ziSg0OXsPqPk5UGsiN89zInoibcmL6ljx/orY+0PLaEqUHz+GoeOL5vO7Mr 2bSdv+MT/NwJC4Ya8a+P9Po3sItrOJQOb3qLUmbv4NfqocohCU/m59PrOAJFT4/5WjiB bE/imqAhGepO8tu6gzdHJHFVUoBT/+CbHYQ6s2x1uRcJYNDkLtNVVqVIx0FrKhZqcXcH en6A== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 13/38] tools/guest: save: move errors array Date: Tue, 1 Jun 2021 18:10:53 +0200 Message-Id: <20210601161118.18986-14-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move errors array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 81d4a79b13..07dfa7d57d 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -229,6 +229,8 @@ struct xc_sr_save_arrays { xen_pfn_t mfns[MAX_BATCH_SIZE]; /* write_batch: Types of the batch pfns. */ xen_pfn_t types[MAX_BATCH_SIZE]; + /* write_batch: Errors from attempting to map the gfns. */ + int errors[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index be65286570..5033f18bef 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -92,7 +92,7 @@ static int write_batch(struct xc_sr_context *ctx) void *guest_mapping =3D NULL; void **guest_data =3D NULL; void **local_pages =3D NULL; - int *errors =3D NULL, rc =3D -1; + int *errors =3D ctx->save.m->errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; void *page, *orig_page; @@ -105,8 +105,6 @@ static int write_batch(struct xc_sr_context *ctx) =20 assert(nr_pfns !=3D 0); =20 - /* Errors from attempting to map the gfns. */ - errors =3D malloc(nr_pfns * sizeof(*errors)); /* Pointers to page data to send. Mapped gfns or local allocations. */ guest_data =3D calloc(nr_pfns, sizeof(*guest_data)); /* Pointers to locally allocated pages. Need freeing. */ @@ -114,7 +112,7 @@ static int write_batch(struct xc_sr_context *ctx) /* iovec[] for writev(). */ iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); =20 - if ( !errors || !guest_data || !local_pages || !iov ) + if ( !guest_data || !local_pages || !iov ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -271,7 +269,6 @@ static int write_batch(struct xc_sr_context *ctx) free(iov); free(local_pages); free(guest_data); - free(errors); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563941471394.2465088631228; Tue, 1 Jun 2021 09:12:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135000.251141 (Exim 4.92) (envelope-from ) id 1lo6zx-0003YT-CL; Tue, 01 Jun 2021 16:12:09 +0000 Received: by outflank-mailman (output) from mailman id 135000.251141; Tue, 01 Jun 2021 16:12:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zx-0003XJ-4O; Tue, 01 Jun 2021 16:12:09 +0000 Received: by outflank-mailman (input) for mailman id 135000; Tue, 01 Jun 2021 16:12:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zw-0005Ec-1n for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:08 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 72e4c8e8-9b99-499b-92c8-dc20ae7426e6; Tue, 01 Jun 2021 16:11:35 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBV1BJ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:31 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 72e4c8e8-9b99-499b-92c8-dc20ae7426e6 ARC-Seal: i=1; a=rsa-sha256; t=1622563891; cv=none; d=strato.com; s=strato-dkim-0002; b=Xd7pOeVIiHYXGHD5gRxZOQBgSiSriTJtjfkH69uEPdEq+Nd1KZVpseWUuk97WuPxI1 qMRegzQl14wS6ijxza1EykXP/NXS714hp2STDA6QpEc6rD5hJuwbl3R7UKHQWH7Azusa C+wtWvtN1St4gDsTIg8KTa9Pi3vrpxL8lH1eSryoVSyDKldVJxGtIG9f78eZdTqOKuEI 8tYccyi/9BvOKkijUOB0irNLd3P/pz8VnqzTMkDNjuVpr7TPAmjtPi89Iknum9aROedD 3QEYjzmx7IZuMlJ9Pzt3ynOhYKKW6k9aNTGAULanPz+gfGYQnqET+TWastQ2rJ/0PRoA q6tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563891; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=kIq3yzkr1orG0VWk81XmidxQ5pZTMt5qbdvFQWlb7zs=; b=UtyPia57fROHf4uKw/IvvaBpuizNrkgb0xR9uBnPu8azM4Y9z+LMDd2yPY9Rv1DqlP dVvfQAv1P37lX8P/lugVi81UjUGredLIj1wrEKzmDrlJnFFjpzfPOovx5KfGHuJf6/Og 1DVdu56tVECjja2o7b/0HusynbosHL5R8qzR+0IfOjbFje+/6E7fMrZhf9SXbNife8pE Kzy7fEh07yg65khvuG+LPfPGZAGeJLj19622yk7b3szhI++W3uFZPcoJS2zqb4vFTL+B HWsaFbVbIKcMMtUyvWlXqUMD9YLFz7scioMxWwZA8B3Kmta3oPwkYeQZtm7sOqcN+OP2 tJPw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563891; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=kIq3yzkr1orG0VWk81XmidxQ5pZTMt5qbdvFQWlb7zs=; b=gDsYGPfPJiR94MM2OVSIHEQY6FxEfWz1Yq9YOXSQ9rDhfFqhTXykv6A1tSFfDcIDVl J2g/szHtGlFD1FTmbZjNTOqwsOpkgwysc8x314SwZDDgF3+B3oYTRbVqE3NYtFU/nnQ0 Ob+gb0DfEk525bhm/NXrkpXo8tpNk4YMjJEempP7HIw5jeC6RqURk1TRCMxqHG6NkINd QQUW5YZUsEIJD/tqdby4ixmx+bwBcMCSSA0V9LbiZX+D7oBpO9KTUMHGVbJjkgM1XNO/ uRMqm6KQ+ymlB5nUrUGDo4DSl/DAxcZZ56QESw/G999enAO9SDxGS7qwyHv/IQ5jvdcv BGsg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 14/38] tools/guest: save: move iov array Date: Tue, 1 Jun 2021 18:10:54 +0200 Message-Id: <20210601161118.18986-15-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move iov array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 07dfa7d57d..b3294e79af 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -231,6 +231,8 @@ struct xc_sr_save_arrays { xen_pfn_t types[MAX_BATCH_SIZE]; /* write_batch: Errors from attempting to map the gfns. */ int errors[MAX_BATCH_SIZE]; + /* write_batch: iovec[] for writev(). */ + struct iovec iov[MAX_BATCH_SIZE + 4]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 5033f18bef..1d9e55afe8 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -97,7 +97,7 @@ static int write_batch(struct xc_sr_context *ctx) unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; void *page, *orig_page; uint64_t *rec_pfns =3D NULL; - struct iovec *iov =3D NULL; int iovcnt =3D 0; + struct iovec *iov =3D ctx->save.m->iov; int iovcnt =3D 0; struct xc_sr_rec_page_data_header hdr =3D { 0 }; struct xc_sr_record rec =3D { .type =3D REC_TYPE_PAGE_DATA, @@ -109,10 +109,8 @@ static int write_batch(struct xc_sr_context *ctx) guest_data =3D calloc(nr_pfns, sizeof(*guest_data)); /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); - /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); =20 - if ( !guest_data || !local_pages || !iov ) + if ( !guest_data || !local_pages ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -266,7 +264,6 @@ static int write_batch(struct xc_sr_context *ctx) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i =3D 0; local_pages && i < nr_pfns; ++i ) free(local_pages[i]); - free(iov); free(local_pages); free(guest_data); =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563946272513.3798276427748; Tue, 1 Jun 2021 09:12:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135004.251163 (Exim 4.92) (envelope-from ) id 1lo702-0004kR-NR; Tue, 01 Jun 2021 16:12:14 +0000 Received: by outflank-mailman (output) from mailman id 135004.251163; Tue, 01 Jun 2021 16:12:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo702-0004jJ-HH; Tue, 01 Jun 2021 16:12:14 +0000 Received: by outflank-mailman (input) for mailman id 135004; Tue, 01 Jun 2021 16:12:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo701-0005Ec-1y for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:13 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.84]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6c478b9f-60b0-4b75-9873-757c55e8a7d0; Tue, 01 Jun 2021 16:11:36 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBV1BK (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:31 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6c478b9f-60b0-4b75-9873-757c55e8a7d0 ARC-Seal: i=1; a=rsa-sha256; t=1622563892; cv=none; d=strato.com; s=strato-dkim-0002; b=PfsEkPMGS+5tPzW4MpLS4b5cQT/mvpFrBoxLm5VNSVORaH7Jw7/RTMsrI2WRYVOtiF y2l8e9TSu1ykKVsd8PLopUW8TJm1oRPVaEIb4Y98rxmjmVHWmN3+YDLPf6mBVmr+gzrM aug2asGY0xM/8T3tEflKxKeKLeICjFCs+gGOU3naJsFTJs7RwvxANiR1pltU2F9hYoXs t+U67JjJ4Djq7ZjUvsYlQPCibe69wnN6nq1jq/oSoT4uXAiKLf3XpxekLghXdwNbB8lA IWyhxl+qrK0LjeVK/fbBOoc+u0EWtO9S8yP9jd8tz3wCPVDmW5n6SxOulL5iBi9t/vP1 qILg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563892; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=3eJ8lfkM75YdRBwLz3IvZoNgnQXSN5j9vpY7FzwJfSQ=; b=PBFVi+mK0hxstPCEJ4VhRAjU21GlGzuN+SL++kGQ/i2BDcF/NfOW2Zsy3wsKFevozm o4kY2J/Avt2CWLPjOaLSDmdm17jyFDcBdbKGaD9WAwcDma/4ho4XGQyMuS6jsvRyaI3N Ta/4iLKMo0NAGLSyEpckb/ZVS1/NcJR0fQwyucnYiAFJL+uAWo063RuwiuV7fCDl9ZwD uKn5K9niilZV6BIkjqvujNtL389HLKKmVH4LyqQ6u6pGqn/MjPKgxIyekIIcd/tYs1WA q7HOMX2DHXg3YZ73w8EIU6oW3VFZkWWgjCKYiOq4or/zygr4dI2BNtWFBdivBL972paw Outw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563892; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=3eJ8lfkM75YdRBwLz3IvZoNgnQXSN5j9vpY7FzwJfSQ=; b=BVfMlPG3S1pF1bPhA5sQHrRPoE/6HsSYf91H0qpFO6TenKzmlcmNlWQZxgoaNC8j0m mcGTbchP62wspXpYSY6OtY9HgOUbsK7KAFsIqy0G7oN6XtECFCwlJ8nF/LxW/mkOg9SL DTqsAlvt7C/Nw3H2fbilYxL9ajdwTKEbKMlJa+esA/8xW492zYZ88HD1eOTOlKtQGGbJ KnRPw1KGLTLI9t2M6BdLUUBUyAvxP7UhmRvHTW2LU5ir+QGfzxt7KwKhWvyUUxwkGMKo Qx8088QqIPSHN96IQBSL7PQgUK04uBGFS7MJHTFftmTa0Z2tWjcQf+LeJzROH1eG/vNp yV0w== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 15/38] tools/guest: save: move rec_pfns array Date: Tue, 1 Jun 2021 18:10:55 +0200 Message-Id: <20210601161118.18986-16-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move rec_pfns array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index b3294e79af..6a2f266469 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -233,6 +233,8 @@ struct xc_sr_save_arrays { int errors[MAX_BATCH_SIZE]; /* write_batch: iovec[] for writev(). */ struct iovec iov[MAX_BATCH_SIZE + 4]; + /* write_batch */ + uint64_t rec_pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 1d9e55afe8..ba8046b530 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -96,7 +96,7 @@ static int write_batch(struct xc_sr_context *ctx) unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; void *page, *orig_page; - uint64_t *rec_pfns =3D NULL; + uint64_t *rec_pfns =3D ctx->save.m->rec_pfns; struct iovec *iov =3D ctx->save.m->iov; int iovcnt =3D 0; struct xc_sr_rec_page_data_header hdr =3D { 0 }; struct xc_sr_record rec =3D { @@ -201,14 +201,6 @@ static int write_batch(struct xc_sr_context *ctx) } } =20 - rec_pfns =3D malloc(nr_pfns * sizeof(*rec_pfns)); - if ( !rec_pfns ) - { - ERROR("Unable to allocate %zu bytes of memory for page data pfn li= st", - nr_pfns * sizeof(*rec_pfns)); - goto err; - } - hdr.count =3D nr_pfns; =20 rec.length =3D sizeof(hdr); @@ -259,7 +251,6 @@ static int write_batch(struct xc_sr_context *ctx) rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: - free(rec_pfns); if ( guest_mapping ) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i =3D 0; local_pages && i < nr_pfns; ++i ) From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564046766840.3852106484309; Tue, 1 Jun 2021 09:14:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135036.251262 (Exim 4.92) (envelope-from ) id 1lo71d-0003RP-Tk; Tue, 01 Jun 2021 16:13:53 +0000 Received: by outflank-mailman (output) from mailman id 135036.251262; Tue, 01 Jun 2021 16:13:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71d-0003RG-Qd; Tue, 01 Jun 2021 16:13:53 +0000 Received: by outflank-mailman (input) for mailman id 135036; Tue, 01 Jun 2021 16:13:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo706-0005Ec-2L for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:18 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id be339adb-dd1c-4964-8c19-30734b5a23c9; Tue, 01 Jun 2021 16:11:36 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBW1BL (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:32 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: be339adb-dd1c-4964-8c19-30734b5a23c9 ARC-Seal: i=1; a=rsa-sha256; t=1622563892; cv=none; d=strato.com; s=strato-dkim-0002; b=nJcQYmO6JnmLStShMuTZQonJW5TWgz38m7lw0d/r/IqhqEV2gKDq9WZAJNkYtU/XSf eYyhmN6HJBIsX724ecE3F0P8Z7koT/VKw+jZQdB4H+n3jUS3o4niHB+jEaBdSbgoi8Yd XC3mC9XKLMMDTsphTsnOw8iA8cZC3upIcCjKn+sKFUs+LYk9nP1YugRuPRIbybwCu3mD nrgGWnwn63YGL0tWo774GMfJAI4C31sBbuRkLCv3FXbfIjouI+GsyeY2l7+T5oWiEBgS Uf39W9IzR88idjE1m2JX/nW1ki9Gd0CZVZqfqc69dnDCzRlGlr+ZXw4D26tYQzzEzUho rsoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563892; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=g1Kh05gVx9V+bsfHm/5UnEfyde3/5C+vW/1l/cFLlB4=; b=s3dv8RdGvOGeCiV5xxKydBo1IbVjzseWzGCzyT8acdVIbcoK7RNzB667vBy2yGDpfp 89BmgTIJ9mPZWdetQoHaQl4SoPgp5u3DWstQkkz6T3m0nVYZkeiD2mm6XSpuZHcFU5SR iNs0CDjf8fv9DT/5u+gWQLILZa4q4DqWT5zSRQ4ua02JcbVZmoC20PlI6pCIyULi7Dvn zJElbnLCraXVAmoFCWhRsfxORfqjLSgS6e+7rxyqLy1mXVPYeeE40v/LbVOr0YSCSfO7 hLmFFvA25HXZwfj7tqoD4ib5b+8m9zbHZ4TeR6OTdSKW+bG5c711hIQ+npu/pp7E7IBf pphQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563892; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=g1Kh05gVx9V+bsfHm/5UnEfyde3/5C+vW/1l/cFLlB4=; b=jhGd+n8lCtV8YEc926r5Ve7N+wO2Yxb2jBOXUezA4E7pFOGtvqMr7tHK0JrDnsGVPB fqGeClsc90b6TzarLUpFj2E6OMw+GKxHjTzSi7+LqGVD6dPmE/fyoAn8oFP3H5897b5f U/fmnS27fNRulyB5izkZH9atT66SUjMyXIp89ylsdI+wGAs5p+Ku4RA+1zESwl8Z1G0u g/vKk/yrmI/QHZYmWmsuG7xrKSFZA2a1AOjAmb370VcTTgO+F4I/MTYYbiYjfmhoITlN iTXrFOtlXuGIgfF1dC3vMscb0r+aS5azW/D7DDOjl0wVRLLyjDNjwGU4AIaCVojNQTGY k6CQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 16/38] tools/guest: save: move guest_data array Date: Tue, 1 Jun 2021 18:10:56 +0200 Message-Id: <20210601161118.18986-17-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move guest_data array into preallocated spa= ce. Because this was allocated with calloc: Adjust the loop to clear unused entries as needed. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 6a2f266469..098aa39667 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -235,6 +235,8 @@ struct xc_sr_save_arrays { struct iovec iov[MAX_BATCH_SIZE + 4]; /* write_batch */ uint64_t rec_pfns[MAX_BATCH_SIZE]; + /* write_batch: Pointers to page data to send. Mapped gfns or local al= locations. */ + void *guest_data[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index ba8046b530..c4fd9a15f0 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -90,7 +90,7 @@ static int write_batch(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns =3D ctx->save.m->mfns, *types =3D ctx->save.m->types; void *guest_mapping =3D NULL; - void **guest_data =3D NULL; + void **guest_data =3D ctx->save.m->guest_data; void **local_pages =3D NULL; int *errors =3D ctx->save.m->errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; @@ -105,12 +105,10 @@ static int write_batch(struct xc_sr_context *ctx) =20 assert(nr_pfns !=3D 0); =20 - /* Pointers to page data to send. Mapped gfns or local allocations. */ - guest_data =3D calloc(nr_pfns, sizeof(*guest_data)); /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); =20 - if ( !guest_data || !local_pages ) + if ( !local_pages ) { ERROR("Unable to allocate arrays for a batch of %u pages", nr_pfns); @@ -166,7 +164,10 @@ static int write_batch(struct xc_sr_context *ctx) for ( i =3D 0, p =3D 0; i < nr_pfns; ++i ) { if ( page_type_has_stream_data(types[i]) =3D=3D false ) + { + guest_data[i] =3D NULL; continue; + } =20 if ( errors[p] ) { @@ -183,6 +184,7 @@ static int write_batch(struct xc_sr_context *ctx) =20 if ( rc ) { + guest_data[i] =3D NULL; if ( rc =3D=3D -1 && errno =3D=3D EAGAIN ) { set_bit(ctx->save.m->batch_pfns[i], ctx->save.deferred= _pages); @@ -256,7 +258,6 @@ static int write_batch(struct xc_sr_context *ctx) for ( i =3D 0; local_pages && i < nr_pfns; ++i ) free(local_pages[i]); free(local_pages); - free(guest_data); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563939707488.9884319706247; Tue, 1 Jun 2021 09:12:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134998.251128 (Exim 4.92) (envelope-from ) id 1lo6zt-0002bQ-Qm; Tue, 01 Jun 2021 16:12:05 +0000 Received: by outflank-mailman (output) from mailman id 134998.251128; Tue, 01 Jun 2021 16:12:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zt-0002Zn-IE; Tue, 01 Jun 2021 16:12:05 +0000 Received: by outflank-mailman (input) for mailman id 134998; Tue, 01 Jun 2021 16:12:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zr-0005X1-WB for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:04 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1163992d-2102-4ff6-ab5b-775defa88b61; Tue, 01 Jun 2021 16:11:38 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBW1BM (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:32 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1163992d-2102-4ff6-ab5b-775defa88b61 ARC-Seal: i=1; a=rsa-sha256; t=1622563893; cv=none; d=strato.com; s=strato-dkim-0002; b=lWWIEL9HC5km8WOt/x3R4+rqn5v1bNFWvkPAbSkrUqYNkp40AlmE6jjiYWVCydo/ob csPuquEqrRfkmBqzA2eOKcigfbX13plTo6qbUGjDiRI4GKM2sgI7cI78zMFo42m/q9CX 6s0EkpCc7ePlmNhxXycWZKTN2DRHoWSNS2/2Ej/YhTGanXeMyP4FO7OlGTrncwoukc5u YZufV3hndVO0e3fWcdoXqwWNQNmfD0tDw8Y/AKVi5AQRnOy9MZ+fsStZIlvZJgzYNR9/ neFvRkC/JRKGOI0Jd7M4pbOdnqmClisEC8v9ruyrOb4GKHSfBOTUTk3EX4+8mrw36AR2 daKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563893; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=Dd4NjKNzHYeI+VwgjA8Sp8NfOu58WGHDpSZRBu7+Wsk=; b=G5Ov9oYy7ggp6gy5d/idYUXaeC4ExsmevB8T8+Tk5hYvfGjjVfWqU9hg5pih+WPZU0 UGGfxm+qTKuIzEXYbk7ZnS4k2cTZzxigRIp6WwHub37qlKRhSfhSiS3xy33pvf+2cRtH K9WYQoZa3WTI5Ka+VX7PLWfRAieXMU6UA3YotYlavahITjflfpyO1Orc/sC1sDvN3xfK ySNUQy3fxfLW3LxQNQvgi/JznZAl/TsSTlPo1K4bQAGSRqxPtk2V4XjMN76VbF+p1+iB U+GkoeB0ngJ02Nu+7FSHlXkNI/VSwwZP7fEFfWrCltKyiXlmzvKexU0P++hfxYLx4lpa qWaw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563893; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=Dd4NjKNzHYeI+VwgjA8Sp8NfOu58WGHDpSZRBu7+Wsk=; b=l5ArMBsKjU3Cb1YbyVURF8KFBTeNuE4kMQPXKk54t54hF8bKl8uN5LntfGydG/oOXT sjjbN7zNm6V+sjUOlxEFhYY5Wowydxq/jH4fHpbS8zrvVRWcXMn/8DX9l/gS3cD9h7K8 4C2uaU6MIHe9c/qQHO6OqvNinsxN7g38ru7a3wM3G3qi1EYxD+D6AUtXVxNGjKeErbVi K0myJDlx3iOOWToTjmcUqVEJb6Z4P1SXAbYvjOU5ROPMfRNw0heamWJ5zde9HcmjWVcx fwSjDvdVkySrA3GUophNuENcxZIwwoBjv6AzQP9iQeeBywPAESZtn31N+0BhWGUY2/OO kmvg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 17/38] tools/guest: save: move local_pages array Date: Tue, 1 Jun 2021 18:10:57 +0200 Message-Id: <20210601161118.18986-18-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move local_pages array into preallocated sp= ace. Adjust the code to use the src page as is in case of HVM. In case of PV the page may need to be normalised, use an private memory area for this purpose. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 22 ++++++++++--------- tools/libs/saverestore/save.c | 25 +++------------------ tools/libs/saverestore/save_x86_hvm.c | 5 +++-- tools/libs/saverestore/save_x86_pv.c | 31 ++++++++++++++++++--------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 098aa39667..0e03b0731c 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -45,16 +45,12 @@ struct xc_sr_save_ops * Optionally transform the contents of a page from being specific to = the * sending environment, to being generic for the stream. * - * The page of data at the end of 'page' may be a read-only mapping of= a - * running guest; it must not be modified. If no transformation is - * required, the callee should leave '*pages' untouched. + * The page of data '*src' may be a read-only mapping of a running gue= st; + * it must not be modified. If no transformation is required, the call= ee + * should leave '*src' untouched, and return it via '**ptr'. * - * If a transformation is required, the callee should allocate themsel= ves - * a local page using malloc() and return it via '*page'. - * - * The caller shall free() '*page' in all cases. In the case that the - * callee encounters an error, it should *NOT* free() the memory it - * allocated for '*page'. + * If a transformation is required, the callee should provide the + * transformed page in a private buffer and return it via '**ptr'. * * It is valid to fail with EAGAIN if the transformation is not able t= o be * completed at this point. The page shall be retried later. @@ -62,7 +58,7 @@ struct xc_sr_save_ops * @returns 0 for success, -1 for failure, with errno appropriately se= t. */ int (*normalise_page)(struct xc_sr_context *ctx, xen_pfn_t type, - void **page); + void *src, unsigned int idx, void **ptr); =20 /** * Set up local environment to save a domain. (Typically querying @@ -383,6 +379,12 @@ struct xc_sr_context =20 union { + struct + { + /* Used by write_batch for modified pages. */ + void *normalised_pages; + } save; + struct { /* State machine for the order of received records= . */ diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index c4fd9a15f0..c4876ba24c 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -91,11 +91,10 @@ static int write_batch(struct xc_sr_context *ctx) xen_pfn_t *mfns =3D ctx->save.m->mfns, *types =3D ctx->save.m->types; void *guest_mapping =3D NULL; void **guest_data =3D ctx->save.m->guest_data; - void **local_pages =3D NULL; int *errors =3D ctx->save.m->errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; - void *page, *orig_page; + void *src; uint64_t *rec_pfns =3D ctx->save.m->rec_pfns; struct iovec *iov =3D ctx->save.m->iov; int iovcnt =3D 0; struct xc_sr_rec_page_data_header hdr =3D { 0 }; @@ -105,16 +104,6 @@ static int write_batch(struct xc_sr_context *ctx) =20 assert(nr_pfns !=3D 0); =20 - /* Pointers to locally allocated pages. Need freeing. */ - local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); - - if ( !local_pages ) - { - ERROR("Unable to allocate arrays for a batch of %u pages", - nr_pfns); - goto err; - } - for ( i =3D 0; i < nr_pfns; ++i ) { types[i] =3D mfns[i] =3D ctx->save.ops.pfn_to_gfn(ctx, @@ -176,11 +165,8 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } =20 - orig_page =3D page =3D guest_mapping + (p * PAGE_SIZE); - rc =3D ctx->save.ops.normalise_page(ctx, types[i], &page); - - if ( orig_page !=3D page ) - local_pages[i] =3D page; + src =3D guest_mapping + (p * PAGE_SIZE); + rc =3D ctx->save.ops.normalise_page(ctx, types[i], src, i, &gu= est_data[i]); =20 if ( rc ) { @@ -195,8 +181,6 @@ static int write_batch(struct xc_sr_context *ctx) else goto err; } - else - guest_data[i] =3D page; =20 rc =3D -1; ++p; @@ -255,9 +239,6 @@ static int write_batch(struct xc_sr_context *ctx) err: if ( guest_mapping ) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); - for ( i =3D 0; local_pages && i < nr_pfns; ++i ) - free(local_pages[i]); - free(local_pages); =20 return rc; } diff --git a/tools/libs/saverestore/save_x86_hvm.c b/tools/libs/saverestore= /save_x86_hvm.c index 91c2cb99ab..26f49ee267 100644 --- a/tools/libs/saverestore/save_x86_hvm.c +++ b/tools/libs/saverestore/save_x86_hvm.c @@ -129,9 +129,10 @@ static xen_pfn_t x86_hvm_pfn_to_gfn(const struct xc_sr= _context *ctx, return pfn; } =20 -static int x86_hvm_normalise_page(struct xc_sr_context *ctx, - xen_pfn_t type, void **page) +static int x86_hvm_normalise_page(struct xc_sr_context *ctx, xen_pfn_t typ= e, + void *src, unsigned int idx, void **ptr) { + *ptr =3D src; return 0; } =20 diff --git a/tools/libs/saverestore/save_x86_pv.c b/tools/libs/saverestore/= save_x86_pv.c index 92f77fad0f..159ff59480 100644 --- a/tools/libs/saverestore/save_x86_pv.c +++ b/tools/libs/saverestore/save_x86_pv.c @@ -999,29 +999,31 @@ static xen_pfn_t x86_pv_pfn_to_gfn(const struct xc_sr= _context *ctx, * save_ops function. Performs pagetable normalisation on appropriate pag= es. */ static int x86_pv_normalise_page(struct xc_sr_context *ctx, xen_pfn_t type, - void **page) + void *src, unsigned int idx, void **ptr) { xc_interface *xch =3D ctx->xch; - void *local_page; int rc; + void *dst; =20 type &=3D XEN_DOMCTL_PFINFO_LTABTYPE_MASK; =20 if ( type < XEN_DOMCTL_PFINFO_L1TAB || type > XEN_DOMCTL_PFINFO_L4TAB ) + { + *ptr =3D src; return 0; + } =20 - local_page =3D malloc(PAGE_SIZE); - if ( !local_page ) + if ( idx >=3D MAX_BATCH_SIZE ) { - ERROR("Unable to allocate scratch page"); - rc =3D -1; - goto out; + ERROR("idx %u out of range", idx); + errno =3D ERANGE; + return -1; } =20 - rc =3D normalise_pagetable(ctx, *page, local_page, type); - *page =3D local_page; + dst =3D ctx->x86.pv.save.normalised_pages + idx * PAGE_SIZE; + rc =3D normalise_pagetable(ctx, src, dst, type); + *ptr =3D dst; =20 - out: return rc; } =20 @@ -1031,8 +1033,16 @@ static int x86_pv_normalise_page(struct xc_sr_contex= t *ctx, xen_pfn_t type, */ static int x86_pv_setup(struct xc_sr_context *ctx) { + xc_interface *xch =3D ctx->xch; int rc; =20 + ctx->x86.pv.save.normalised_pages =3D malloc(MAX_BATCH_SIZE * PAGE_SIZ= E); + if ( !ctx->x86.pv.save.normalised_pages ) + { + PERROR("Failed to allocate normalised_pages"); + return -1; + } + rc =3D x86_pv_domain_info(ctx); if ( rc ) return rc; @@ -1118,6 +1128,7 @@ static int x86_pv_check_vm_state(struct xc_sr_context= *ctx) =20 static int x86_pv_cleanup(struct xc_sr_context *ctx) { + free(ctx->x86.pv.save.normalised_pages); free(ctx->x86.pv.p2m_pfns); =20 if ( ctx->x86.pv.p2m ) From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162256403975832.45951117350137; Tue, 1 Jun 2021 09:13:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135032.251250 (Exim 4.92) (envelope-from ) id 1lo71Y-00030E-LG; Tue, 01 Jun 2021 16:13:48 +0000 Received: by outflank-mailman (output) from mailman id 135032.251250; Tue, 01 Jun 2021 16:13:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71Y-000301-H1; Tue, 01 Jun 2021 16:13:48 +0000 Received: by outflank-mailman (input) for mailman id 135032; Tue, 01 Jun 2021 16:13:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70B-0005Ec-2Z for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:23 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c93f827c-c556-4e0e-b6de-2562934ba459; Tue, 01 Jun 2021 16:11:37 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBX1BN (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:33 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c93f827c-c556-4e0e-b6de-2562934ba459 ARC-Seal: i=1; a=rsa-sha256; t=1622563893; cv=none; d=strato.com; s=strato-dkim-0002; b=NpnnLGqmKCVUQlrMkSAxwv++mpIPTiUMxYC7kJiZVaiJDEP3oT0dtrLAAfd6l4x6di yhfyFRysyH77HR5I0ndRZx0KCYWp97MSEzSl9OAfgCmU9NPbORVZjFWam4ePPSCdKhFx 1KMKXhhrwK7yKcCIhdpn+qLGk01i9XzX5ItSczWj9VgOXGCeJknJMnKcwXpj0mZBj0Dq nj14BTT61TUgHER1aApkp/8UiOo7fyxDmn6hT3gW9YiRSmAMWIqtbFSfTmul/OlvszJE iZuSRbNLn3SRQVOWTrfIVF4TgylKQonKfsc24dk/Hmgcn0wKqpWu5ervz5Btb6CFYzfL 4/qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563893; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=yMk7eA+P/3dbcIUts8vVxsnRdZMI0VGT4aHfrLA5Vm0=; b=pFtNbtmH4REr819pBxs6SzUv+AU/vAJ+tuUsrKPOlVkHmxuV7cwde7Lpc42PrRuqQF hIN/J18CK8/eQ5TyFS5VmoD/R8Si2F15MZJlH882EI+jHL2ZlpcSIYN8NjZwr65ra25l Hehz17AlrVFORkZC5fszCCMlOvgttk3SfMXbCjqBvUXO7tDpyx1iITXjXFqvqizxwJQt ZNSG9vuK3zmOWZ6Kgy6uPwD99y+8Wcsbp8V+2ea+MDTHjTkyHNtbGar3pyM4l1VfhEN/ f2dAV845M6Wwtd5k/knWona6J7AbiKmZl/djct1nIDlTYwLlKb4GSz9tS2Yr5Sy+3i9N sW6A== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563893; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=yMk7eA+P/3dbcIUts8vVxsnRdZMI0VGT4aHfrLA5Vm0=; b=ippzeAWbK2faCr3B2s6o05Bzhj8iWFbH8CU8ygiVTZFHevXTYqUJ/AEMROc72AB1hw lpgjaCdv0xJBRhrq7w020hzQRQ4NzJzsWKrePNmC52lwIlwTAb+9/Q4kcbY7T1rWsWyH uj/2T8xgi28RAm1UkNYKFCGsd47G45abVj8SoISCVbqxwBTBKLeILro5U/7TGl8RykhA mmaPWYes2Vby3pSibNYcjBOl66BwjJ3CCBFtsXuBIfyNpPEw6iRsQkHtjaBy61GWLtSv 7nB1XEB6WmHY69KFTvSfsFsrdQuwAq+QOqXX60+vnSFaNkuUPBS4doabOZ9QxE96BRad BgEQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 18/38] tools/guest: restore: move pfns array Date: Tue, 1 Jun 2021 18:10:58 +0200 Message-Id: <20210601161118.18986-19-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move pfns array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/restore.c | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 0e03b0731c..be6f98af7f 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -236,6 +236,8 @@ struct xc_sr_save_arrays { }; =20 struct xc_sr_restore_arrays { + /* handle_page_data */ + xen_pfn_t pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index a6cf9ee41c..4d8ee19adf 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -315,7 +315,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) unsigned int i, pages_of_data =3D 0; int rc =3D -1; =20 - xen_pfn_t *pfns =3D NULL, pfn; + xen_pfn_t *pfns =3D ctx->restore.m->pfns, pfn; uint32_t *types =3D NULL, type; =20 /* @@ -363,9 +363,8 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) goto err; } =20 - pfns =3D malloc(pages->count * sizeof(*pfns)); types =3D malloc(pages->count * sizeof(*types)); - if ( !pfns || !types ) + if ( !types ) { ERROR("Unable to allocate enough memory for %u pfns", pages->count); @@ -412,7 +411,6 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) &pages->pfn[pages->count]); err: free(types); - free(pfns); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162256402434127.45980450495938; Tue, 1 Jun 2021 09:13:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135026.251239 (Exim 4.92) (envelope-from ) id 1lo71J-0001rW-8Y; Tue, 01 Jun 2021 16:13:33 +0000 Received: by outflank-mailman (output) from mailman id 135026.251239; Tue, 01 Jun 2021 16:13:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71J-0001rA-45; Tue, 01 Jun 2021 16:13:33 +0000 Received: by outflank-mailman (input) for mailman id 135026; Tue, 01 Jun 2021 16:13:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70G-0005Ec-2c for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:28 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.169]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b54d6a0b-382f-48b9-8b14-afc26fd82239; Tue, 01 Jun 2021 16:11:38 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBX1BO (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:33 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b54d6a0b-382f-48b9-8b14-afc26fd82239 ARC-Seal: i=1; a=rsa-sha256; t=1622563893; cv=none; d=strato.com; s=strato-dkim-0002; b=UUM+exyc4Jrd1VjUci/3jYH7JekthyphWT5aBWkhbqXHdikeRhjJciVwYbT6pBKxnQ sCssb14D+0d2l0ieo61vaGv/+gXHHH0EIgc9VlWAxVVaC2JVUuXpooY0PbGOdAlWumq8 RLyO6YzqPa4LgKySXRHvrReFKUokuRTDFPvPRMuV0dVCc9atUNRe3fKHl+WpkYSPVpYb /bXBKI80r82XVNiBFSE9nsa4s3yxbkV5mbnu3D+UmHk4ZYQzsXJdDNYGA6eEmDhRPI4o mohDQD0ZKRxBBq4hWYx24LWbRepKO9i7xRbsPrVxSLnYrDDtpmfVOg4hoSSvmpXU4foG vtcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563893; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=aAGkFwdPcwm3sDiRcDYWvmNyL5GfWbZILOcBD1kChMw=; b=WuaAIM3CKjPaQpNFLkan3sxYrsUWe15VJwwOkRkJvJxFSNzjJkgTaoyqLco1NVrvik rDuEQMjXNbIACUimJfcEG69pNeM6uCtuaQ8Z0EcPFjrWRWCSrNinT7dG9UYinAeNWf+T BRt2KbTc/kkZkoBrjm3c1HZ47YFOhYDghdpchGOrTTPl9UGjY570bg0DwOTkK3qwuaoG SRr2SfNQAWE/7zZD93V39TnKrzPtr5CXXmJuGhizFzZSHqfgaBwO2qLfL2qHvVJGM4VY 6E4qdAfjNY0gfHLFNI//uKFaw6X7WqJD6xWS1UjiDHqpzbst0LQKkDn1mIYkH6rGCAro Ysew== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563893; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=aAGkFwdPcwm3sDiRcDYWvmNyL5GfWbZILOcBD1kChMw=; b=gAzpX16i4/ez6pQcYlrP7qEdVAQ80FBGQ2Dn4f1iV1B3P1h8/2DMCaiMjAm7dN7FBY K4uDxEOZ1lMUiga+eZ8g7zG8XAWxCD8uQQB+VJuPiKTt2RXYjN/Nn9VJSLvWtqnvWyM8 74rtepR3Bi28C+yCKeSQTCT2cbTM3Jt+tP5dwrAi5RuzDyvHI2j+VE8M6NIF8veCY9Vd hEwIi+ZSsOg2+MXoDY/5/O+VF8eftF/xaXmYjhTyQENFIZ/kiMKegjykeiUmmzjEATHJ 2NV34oiv3Aq/xv+TN6oynwFKJ/t0IcuutOZAfKyykRtRW6CKrwrhP4rBNOLCIBnRreE8 qoJA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 19/38] tools/guest: restore: move types array Date: Tue, 1 Jun 2021 18:10:59 +0200 Message-Id: <20210601161118.18986-20-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move types array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 1 + tools/libs/saverestore/restore.c | 12 +----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index be6f98af7f..96cd60e0d6 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -238,6 +238,7 @@ struct xc_sr_save_arrays { struct xc_sr_restore_arrays { /* handle_page_data */ xen_pfn_t pfns[MAX_BATCH_SIZE]; + uint32_t types[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 4d8ee19adf..815a2d5a12 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -316,7 +316,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) int rc =3D -1; =20 xen_pfn_t *pfns =3D ctx->restore.m->pfns, pfn; - uint32_t *types =3D NULL, type; + uint32_t *types =3D ctx->restore.m->types, type; =20 /* * v2 compatibility only exists for x86 streams. This is a bit of a @@ -363,14 +363,6 @@ static int handle_page_data(struct xc_sr_context *ctx,= struct xc_sr_record *rec) goto err; } =20 - types =3D malloc(pages->count * sizeof(*types)); - if ( !types ) - { - ERROR("Unable to allocate enough memory for %u pfns", - pages->count); - goto err; - } - for ( i =3D 0; i < pages->count; ++i ) { pfn =3D pages->pfn[i] & PAGE_DATA_PFN_MASK; @@ -410,8 +402,6 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) rc =3D process_page_data(ctx, pages->count, pfns, types, &pages->pfn[pages->count]); err: - free(types); - return rc; } =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563937582809.90865861947; Tue, 1 Jun 2021 09:12:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.134994.251102 (Exim 4.92) (envelope-from ) id 1lo6zo-0001Nx-KR; Tue, 01 Jun 2021 16:12:00 +0000 Received: by outflank-mailman (output) from mailman id 134994.251102; Tue, 01 Jun 2021 16:12:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zo-0001LY-85; Tue, 01 Jun 2021 16:12:00 +0000 Received: by outflank-mailman (input) for mailman id 134994; Tue, 01 Jun 2021 16:11:59 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zm-0005X1-Vx for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:11:59 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.170]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6934594f-8962-4454-8048-10c9b500185c; Tue, 01 Jun 2021 16:11:38 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBY1BP (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:34 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6934594f-8962-4454-8048-10c9b500185c ARC-Seal: i=1; a=rsa-sha256; t=1622563894; cv=none; d=strato.com; s=strato-dkim-0002; b=ClxwDl0qOSDjoIzNwbzCmJ4ADXloUwbcJ7wlHM4iM61l6JqODFCZZpqcu0/GlNFtlG 5oA2jSfzWBMYdDDzvhd3lnaUbTHRVkTFASjvrgWoXjHxyBLaXavo/dcy3Cl1KKGpfRwa 6t240vWP1WoA+vo0e/qyvLEoJCqXumv1FMIpvN7F6F/xFhtb4lS0FM/Q2dK+bwxgH44M HG4dud/1aqI7dpg0Lp5tO4CYltpEK0jqmgTkRZ3ErK8vc8LRIwB60FsntryBmVe6sRvK DwT9ikobnc+pdygCRehXCwJU2aWA0mpVU+tady/FNC63CQYB2hvwic+r8nmyhQ9xEgz6 9nKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563894; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=z4yh0601yitxQDA4KYzEdbnjeAj2W9nnPiW8js19Yoc=; b=tRhf971bAx8V7lliMKUwnmZnrWq10x1IewtiX9BIroszIi5zpyi9whPdppL+JfkjWh 48m1XweFg1qyXLA++7UWS6rAierRXtXnKrY/0X4250XBEqxd9y13pBuViuPEqz9wc9lv 1GOQh10dVz9lVYEZsR2K2dJA1hU6XoquqN9Pkexf3heRUUqE4rOFndz10ooMqqwKvmXR Yq4Nsc8l0Ne2n6e49UJktQOK+b4qCX6j4IFEBjGdrLJZiI34aw1P2hZHSe7h/FGE+sAl GHGTFexX7BV9by0Xn5jz71OeoBzZbW0BEZSS7mz0xLL9nDgHGNJS631r1ue1yZdQG4Wb 4Hrw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563894; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=z4yh0601yitxQDA4KYzEdbnjeAj2W9nnPiW8js19Yoc=; b=JL0R7wiQcmcqwYI3HwBz4r03ZaCVbE7XBGrVZIHr49HwKasO7txilGAoztHfqC/8Za fbrsr0orj2xYnTaByMb4rQqkb3KnydVeOKdhvFV9xzNVPFM6QoqJowWvTSqPkSq2StxM xKAq3fwBOCVknK6+1S14D3+RLEIwviAlTl+gIYjN3rkj9F/jVOqAeOYSmgBCCwtJEKU9 zTF0zC8IdF+lSl2B17vPfcVeZpwDCqQpjddYhQOZIYDWy9kMkLodPhKjp5KiGSL685WF rnZ5/qcRV1+ptvuhFxLCdaTK14i0Dhu/ZhlRB1p3x137VvJ1p6DOmIqNLI02+9TNx0+2 3RcA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 20/38] tools/guest: restore: move mfns array Date: Tue, 1 Jun 2021 18:11:00 +0200 Message-Id: <20210601161118.18986-21-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move mfns array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/restore.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 96cd60e0d6..c7291bb5ca 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -239,6 +239,8 @@ struct xc_sr_restore_arrays { /* handle_page_data */ xen_pfn_t pfns[MAX_BATCH_SIZE]; uint32_t types[MAX_BATCH_SIZE]; + /* process_page_data */ + xen_pfn_t mfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 815a2d5a12..aadf322428 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -205,7 +205,7 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, xen_pfn_t *pfns, uint32_t *types, void *page_= data) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)); + xen_pfn_t *mfns =3D ctx->restore.m->mfns; int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; void *mapping =3D NULL, *guest_page =3D NULL; @@ -213,7 +213,7 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, j, /* j indexes the subset of pfns we decide to map. */ nr_pages =3D 0; =20 - if ( !mfns || !map_errs ) + if ( !map_errs ) { rc =3D -1; ERROR("Failed to allocate %zu bytes to process page data", @@ -299,7 +299,6 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); =20 free(map_errs); - free(mfns); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564222996768.9079458250854; Tue, 1 Jun 2021 09:17:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135062.251317 (Exim 4.92) (envelope-from ) id 1lo74X-0007YP-4v; Tue, 01 Jun 2021 16:16:53 +0000 Received: by outflank-mailman (output) from mailman id 135062.251317; Tue, 01 Jun 2021 16:16:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo74X-0007YE-1X; Tue, 01 Jun 2021 16:16:53 +0000 Received: by outflank-mailman (input) for mailman id 135062; Tue, 01 Jun 2021 16:16:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70L-0005Ec-2e for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:33 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a3763927-e6a9-4fd4-87dd-f33d389b1d2a; Tue, 01 Jun 2021 16:11:39 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBY1BQ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:34 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a3763927-e6a9-4fd4-87dd-f33d389b1d2a ARC-Seal: i=1; a=rsa-sha256; t=1622563894; cv=none; d=strato.com; s=strato-dkim-0002; b=YjCXDU33U/i7SQqbO4oNdvChTQ9Xikz/PPoCzCeAMh76/S2n131Zgf+Z3JnYi/7NNx KA+HmB0pkoYeKbsmfaN4f0YxSTLKBn4SRn8PyEkfFvZlEfO9zZ1ibzvMgLIWN3Cjep0n rVjyEPF962rtyZUnsGfo9K2TjKD1qr9BR/JNb4JGvbTNijZdz3LQIK7i1yTwovLRDmPA StjdkMifuaqae6kkRjuK11CdQCjRx2uiO/zgWjxwXOzNRj9whi4PZJ010WV6GS0d0JRn oOmrvGAhiQgLLJa1Fof4KZWWHRoCzkfL2twmWO8GKjfto+qZ/8jd4yev5v/PKQJIQC91 e4dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563894; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=2CUXZ/FCQQr/mVtYU8Ymox8qVtJ5RlUVL8AFNCIqE5o=; b=THUtBBqNyXmXwLsoInTEjQ+V9nWHqPDGjuqPAISrGT9lYd7T5q41L8q5B1BLRWTM/I FiS25ENH56Ylj2qC08uGFoG+N4b/DNjRGKPleubnD6k6hHWgi7gQcoqO8AxmOtJUXNvH xA5CJM3d8/wbpx03aRuwm8VsViBPKCOlqvUqo2dyNlO7yoMncczD4BB3JBIN/AV+l1n3 0NOvzBn8jKlMzz/mKgMlBP+rqOBO92pgFz6J6RuKGPyv7hm8Y3HYdZOn5Eum+fOOXHL5 bIucAB9id0d5K0Dx1YHCG6M1oBO0g7MUac2fLh2UEFInYrY1jfsW2fiawKWkK4lorLQo TjuQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563894; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=2CUXZ/FCQQr/mVtYU8Ymox8qVtJ5RlUVL8AFNCIqE5o=; b=RWo97elgVniK6V+b74Q743JkQM6rkfWGvLM8ZCp9/ufrKvHqYbyY6zYv61duUXW4kg zcR3QjEg6a0pfDoKfYCAVgj+k+Ds83eGyMDu0RgbQ7rDFbG2jRup97m+lJrrchp8X6cP Ta1jf2uej1BJd7ajNHqubxbVrpgR43h2CZ7dBuCTK/WIjpdXSLpOFuvo6v1AsZiV/Age ECYdURZB7iJZsHS8/3dPuncfBeJ6MeGK72NH8yDp4jQFs8ZwfYNTIgnvO1YeyppeaZmQ ePsN8GOjb26s8I6E5HSUoQR6TkA3zuXc32CR6XQ0jsLvdhSvKVbVeGjLZkbhChJ5RBCL cdOQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 21/38] tools/guest: restore: move map_errs array Date: Tue, 1 Jun 2021 18:11:01 +0200 Message-Id: <20210601161118.18986-22-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move map_errs array into preallocated space. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 1 + tools/libs/saverestore/restore.c | 12 +----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index c7291bb5ca..cea549d129 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -241,6 +241,7 @@ struct xc_sr_restore_arrays { uint32_t types[MAX_BATCH_SIZE]; /* process_page_data */ xen_pfn_t mfns[MAX_BATCH_SIZE]; + int map_errs[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index aadf322428..b534d80cbc 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -206,21 +206,13 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, { xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns =3D ctx->restore.m->mfns; - int *map_errs =3D malloc(count * sizeof(*map_errs)); + int *map_errs =3D ctx->restore.m->map_errs; int rc; void *mapping =3D NULL, *guest_page =3D NULL; unsigned int i, /* i indexes the pfns from the record. */ j, /* j indexes the subset of pfns we decide to map. */ nr_pages =3D 0; =20 - if ( !map_errs ) - { - rc =3D -1; - ERROR("Failed to allocate %zu bytes to process page data", - count * (sizeof(*mfns) + sizeof(*map_errs))); - goto err; - } - rc =3D populate_pfns(ctx, count, pfns, types); if ( rc ) { @@ -298,8 +290,6 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, if ( mapping ) xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); =20 - free(map_errs); - return rc; } =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563948334904.6507379628083; Tue, 1 Jun 2021 09:12:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135001.251150 (Exim 4.92) (envelope-from ) id 1lo6zz-0003vH-5w; Tue, 01 Jun 2021 16:12:11 +0000 Received: by outflank-mailman (output) from mailman id 135001.251150; Tue, 01 Jun 2021 16:12:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zy-0003ul-Nb; Tue, 01 Jun 2021 16:12:10 +0000 Received: by outflank-mailman (input) for mailman id 135001; Tue, 01 Jun 2021 16:12:09 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo6zw-0005X1-WE for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:09 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f81fd6b4-bf1c-44f2-8abb-fda67d4f1df2; Tue, 01 Jun 2021 16:11:39 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBY1BR (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:34 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f81fd6b4-bf1c-44f2-8abb-fda67d4f1df2 ARC-Seal: i=1; a=rsa-sha256; t=1622563895; cv=none; d=strato.com; s=strato-dkim-0002; b=GO3QMTQt+1PQdk26evIOQmJRuGWZ+32SI2lYkoj8qbRmKkk1NrTUy+wzUpOONFVLnw KkEKVAAInwnepCRZ+sQj8bKk+QyOXZTTXLokE12qjz7M40M38ZRV1uWcYp9QoquE+Agi Qn0sUYrTXR49exLojAW154D6BKGwWFlmNPqBLtelADD+sySIVaUgZjU0lBzYW9HEMUdB OtNZcmogfjxC0gM3+oLY/B1cj+wL+k+L3FBWHcS22PFL3s0BdcjIUvqrSlq+PN8kB2NY ccdHYc5uFS5JOta58Oqwgi8Wa0+54oCzqdZheQXLZz/bi4rtt6Ue7DpUkZPbsvaGOUye Qrsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563895; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=MHTDuRs4KJXGAe1IwzaUM3cPcSsfMCXWpWBD7RHfqcQ=; b=oUujeh3ij71G841X2CbWGKoy44B3T2WnsQeioHkz3PBg3S0PdxQH611aIVujvzrMG0 Jjm1b+Yv6TEPWvjNriLKk1FP1Q0HPpCXu87dXbH3h6DvAEbv9np12AdX/XTWx86KN8Wy SNzZvwOcedVzVQ3G5vSWSl8CEIc+SZcMV3AQ9Z1PqzJXFtU0yYRUGGwO0nxiHiVIr2MT 9cK/1TfRvEtmijw0Cr/9agRs/oa1dPUqPEftRQ8gQ5Wp532nBFF53Iyv0fJur1R5OwB9 +v9KhZCNQFigNBS7kCzLwT9hbobwKZt5EQ2rPzq46AoYfyZtKaNSo+e7hl0bokvuMkoj M9MQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563895; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=MHTDuRs4KJXGAe1IwzaUM3cPcSsfMCXWpWBD7RHfqcQ=; b=d1oxsrIGWxW0vEUGvkWomIQ48mfGtUoieX+YZL23ervAaEs2u+g3opolyICVx+cvs5 jVKNq80IyqWfgXE/ZxU1aYty3h9h0GvJewGqnzwSPTnfu0rkHK14R2frBmNwVgR3vuHk Kj/q/LvmKN/YzJckZhATGyEjzOlsVzGQkrzBthtqdUoeVeJl3JJr1kqhI49wEYvXf/Nm hKva6W1YFgOL6p8Ikbq00Pp+PdUzT3dxopRat/m3yWKh0RJ/o9HgDem8EJIpFbvS1jwA n1/kPRGufXzY3ArMcHxNgYAqLIjMdZj4QKp1OaOnTke5rLXNJ+StHBf6JL6KSaaqj37n tZ4Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 22/38] tools/guest: restore: move mfns array in populate_pfns Date: Tue, 1 Jun 2021 18:11:02 +0200 Message-Id: <20210601161118.18986-23-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move populate_pfns mfns array into prealloc= ated space. Use some prefix to avoid conflict with an array used in handle_page_data. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/restore.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index cea549d129..6ed213e14f 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -242,6 +242,8 @@ struct xc_sr_restore_arrays { /* process_page_data */ xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; + /* populate_pfns */ + xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index b534d80cbc..2ab9f792ef 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -138,12 +138,12 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned= int count, const xen_pfn_t *original_pfns, const uint32_t *types) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)), + xen_pfn_t *mfns =3D ctx->restore.m->pp_mfns, *pfns =3D malloc(count * sizeof(*pfns)); unsigned int i, nr_pfns =3D 0; int rc =3D -1; =20 - if ( !mfns || !pfns ) + if ( !pfns ) { ERROR("Failed to allocate %zu bytes for populating the physmap", 2 * count * sizeof(*mfns)); @@ -191,7 +191,6 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned i= nt count, =20 err: free(pfns); - free(mfns); =20 return rc; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564046389482.3362222309445; Tue, 1 Jun 2021 09:14:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135038.251272 (Exim 4.92) (envelope-from ) id 1lo71f-0003o8-93; Tue, 01 Jun 2021 16:13:55 +0000 Received: by outflank-mailman (output) from mailman id 135038.251272; Tue, 01 Jun 2021 16:13:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71f-0003nG-4B; Tue, 01 Jun 2021 16:13:55 +0000 Received: by outflank-mailman (input) for mailman id 135038; Tue, 01 Jun 2021 16:13:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70V-0005Ec-2v for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:43 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.173]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 81bee282-d57c-4860-a341-5a7dd6617a8c; Tue, 01 Jun 2021 16:11:39 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBZ1BS (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:35 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 81bee282-d57c-4860-a341-5a7dd6617a8c ARC-Seal: i=1; a=rsa-sha256; t=1622563895; cv=none; d=strato.com; s=strato-dkim-0002; b=BhWx2Lzvkn8drrWiY9EL+zi8qGJasAKHBfLwAQ4xsCYXjaeUmkQLcSbxo0/q8HUN0o Em0Ad4PkM3dTa+nIhfXrFfxGvNvQJgOcpVgJMvqNGYUHoVQURkGI/KemvE/s/qb0XJVY 8cjZoUQU7lHTAsarC20/kDl0upgArQ3953JQwn2J6U3v/PvyQ31tWbs8Or3BbCUygqxS YjLw+GSIWihXeRtKlzfb3sHsvBJPjrLPC7A02eaJ3kTovml5Ixp6shM+x/Xy78Yvmg7j JMnr38LrnyujJCWYm87psmkzhjRpwHNmzX7kD21HG36XBHozKhaZh+megSbSMweRR0u+ xe5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563895; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=pHLUvMX7U6lUA9on8DVqvFH+okBXqcoC5FrFwr0VWLE=; b=Mol42r7yOgKyOSeNd6LYWFOCEO41h5/ExFJ3B9CD+Fj/3SFQt1Ml0Ig3yQ/emp1xyz qC/0qjvLV8QoI0WQAjHTCJmch+N3z4JY5BhpxnZcMjatuBZV+CdyAjQGothm9W6JShsB pKTC/8rEREm9FdtGb3YxbmPDAv7QIN3AGZor0jC8uFDmGOGsdehxszPXsxYIRxkhkcFr 3PKsuW+XAQPRmt/Lyxfzn6sy8sm3yISsUGYcWe9Or17DtK6OCZal+kSqJERrrEv2duUY WXloG2LrddUjm0bUwe1TrPEM+ZgiLPBrk64BDNHY6B+As0Eo1FEI9dHgw8HanjKxnLeS WxeQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563895; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=pHLUvMX7U6lUA9on8DVqvFH+okBXqcoC5FrFwr0VWLE=; b=HTQbY5Y4vm6yKSuHhB6y3ow6W7nY8IpOM8WlqG+2UvpGk8r4GabQfKcGkpodR9HsVd 7cL/9R4ayd5znMGMzFR/6ATu8j6CbHWA3RMCyVj+y+XuLANEW6tMBO1Eiu9hlik5vFkR GPI8oT0LODTI6NMYocy9jAcW9tqlqJbIsamBAkjFgkYmrFdhRF8KvGN3IiFJCvD8RNGr RcYtLxLN1nXsJqDSuUaCac+Wh0J646tdaPIEywDcuniaTda78uq77fBgoJwjcSnxZohn XNL5vCFQgIG+FnXCVHOdnsOqUAWgx2nNKxJcA5AtxC3Pr3yV+esMK7/hkFjR2v2Yag8v hYzg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 23/38] tools/guest: restore: move pfns array in populate_pfns Date: Tue, 1 Jun 2021 18:11:03 +0200 Message-Id: <20210601161118.18986-24-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move populate_pfns' pfns array into preallo= cated space. Use some prefix to avoid conflict with an array used in handle_page_data. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.h | 1 + tools/libs/saverestore/restore.c | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 6ed213e14f..9de09ae64a 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -244,6 +244,7 @@ struct xc_sr_restore_arrays { int map_errs[MAX_BATCH_SIZE]; /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; + xen_pfn_t pp_pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 2ab9f792ef..598a4aa06d 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -139,17 +139,10 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned= int count, { xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns =3D ctx->restore.m->pp_mfns, - *pfns =3D malloc(count * sizeof(*pfns)); + *pfns =3D ctx->restore.m->pp_pfns; unsigned int i, nr_pfns =3D 0; int rc =3D -1; =20 - if ( !pfns ) - { - ERROR("Failed to allocate %zu bytes for populating the physmap", - 2 * count * sizeof(*mfns)); - goto err; - } - for ( i =3D 0; i < count; ++i ) { if ( (!types || @@ -190,8 +183,6 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned i= nt count, rc =3D 0; =20 err: - free(pfns); - return rc; } =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564056050168.81542911988583; Tue, 1 Jun 2021 09:14:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135041.251284 (Exim 4.92) (envelope-from ) id 1lo71j-0004N6-Kj; Tue, 01 Jun 2021 16:13:59 +0000 Received: by outflank-mailman (output) from mailman id 135041.251284; Tue, 01 Jun 2021 16:13:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71j-0004Ml-GF; Tue, 01 Jun 2021 16:13:59 +0000 Received: by outflank-mailman (input) for mailman id 135041; Tue, 01 Jun 2021 16:13:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70f-0005Ec-3L for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:53 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7758098d-fefe-4003-bede-ed93932f6711; Tue, 01 Jun 2021 16:11:41 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBZ1BT (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:35 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7758098d-fefe-4003-bede-ed93932f6711 ARC-Seal: i=1; a=rsa-sha256; t=1622563896; cv=none; d=strato.com; s=strato-dkim-0002; b=kc7Yj/zHkuxSkuv91lZrKLFhxicbkhg2PrG0a22bcdRA4EYn0v6h6gKz34AdefHZl+ EJyvTAopM/CfodrzWrb147NRFmFDJz/XfJrO6Jq8f/8Wbdt7UlIKnGzR+ASqGVGf8x+o Rz7bh5z49QsWnCQS4g0icfQs1hIRAxEswdZCD5OpCUhYm+ZXfIg816YZEcpPD4Nfy1V5 zjydUXGqGR2Xj1v26rFjjfsUcSVTbVotBX488J+WaNOEL0GgopJJbfw3cRgLIB4kjtN7 YrcfPsZcDHHS0DNoJzFRcQwLqcZXt7Hl8JOyfEOnr4Ml4duXdfmAVBqzndEfhjvBFOPl Ptkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563896; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=KiB5zmNJWHh3QN6pLulGVrCrsceJ5e3LZlNQkeTmQNs=; b=r7uWJ9iWXTHG6ECfj3bEZt5/Lo06UgF5YH3FHjvxUwYrQJPhrxCFqJHq5oHFNDo97C SOybKMZEGGtKfKZMz3cJsEZV8c3ctBTiklqKuuXHkpSDHUSwgFVW6kCLgA+vstWxE/+F QT2A0zxs/XKEOUwDxzVKMdPYXvjGTaywBIyAgdFXR3y+4/i8kycF+UwZAa1F4IhdwJ1i ujNFtHYD9wk7uVpYoywTP/4H2J3MegGylO+lGdemO9PdYrn/aOivc8An49yyOTuJmqQD ygv2ILdRbdwJYCRJO8K30tLH97nw8PPMCN5TdIjuydQqSc91dgTk2+KMIHi+d4p0pc1T B+HQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563896; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=KiB5zmNJWHh3QN6pLulGVrCrsceJ5e3LZlNQkeTmQNs=; b=naDXOxfkmm5wQsb35m1m/5F9QiDgv5TjkdmqtNiP/cHO0E/XhKL7kQ+OO/+eZQCN89 GMxdCnfgXCAPoEFvvA8CLNwAr8eXorkxeI2UcQCmm1TNdnNqoPIpnYqBsmeSi/gBS9TT sxQAmMKxtGaMvAe2papjTwG9uhxBk8hp7zNQcjqUDEX9331uoZswbOf7DvJ2lmmtm/G9 wTjQizEt0u5TTUcUFcsWjxNOs6/P+GjUkFYzA60hJLufZHtZ2GJcFWx3qw4GvXWdDmNM /jdcYxg0pVu2F14esr9R6Vw0uOMap4adylS5ifs+pwqOsAUjlO2ZZGyTGT4dubU8atdd a0sg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 24/38] tools/guest: restore: split record processing Date: Tue, 1 Jun 2021 18:11:04 +0200 Message-Id: <20210601161118.18986-25-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" handle_page_data must be able to read directly into mapped guest memory. This will avoid unneccesary memcpy calls for data which can be consumed ver= batim. Rearrange the code to allow decisions based on the incoming record. This change is preparation for future changes in handle_page_data, no change in behavior is intended. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/saverestore/common.c | 33 ++++++++++++--------- tools/libs/saverestore/common.h | 4 ++- tools/libs/saverestore/restore.c | 49 ++++++++++++++++++++++---------- tools/libs/saverestore/save.c | 7 ++++- 4 files changed, 63 insertions(+), 30 deletions(-) diff --git a/tools/libs/saverestore/common.c b/tools/libs/saverestore/commo= n.c index 77128bc747..7da7fa4e2c 100644 --- a/tools/libs/saverestore/common.c +++ b/tools/libs/saverestore/common.c @@ -91,26 +91,33 @@ int write_split_record(struct xc_sr_context *ctx, struc= t xc_sr_record *rec, return -1; } =20 -int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *re= c) +int read_record_header(struct xc_sr_context *ctx, int fd, struct xc_sr_rhd= r *rhdr) { xc_interface *xch =3D ctx->xch; - struct xc_sr_rhdr rhdr; - size_t datasz; =20 - if ( read_exact(fd, &rhdr, sizeof(rhdr)) ) + if ( read_exact(fd, rhdr, sizeof(*rhdr)) ) { PERROR("Failed to read Record Header from stream"); return -1; } =20 - if ( rhdr.length > REC_LENGTH_MAX ) + if ( rhdr->length > REC_LENGTH_MAX ) { - ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.typ= e, - rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX); + ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr->ty= pe, + rec_type_to_str(rhdr->type), rhdr->length, REC_LENGTH_MAX); return -1; } =20 - datasz =3D ROUNDUP(rhdr.length, REC_ALIGN_ORDER); + return 0; +} + +int read_record_data(struct xc_sr_context *ctx, int fd, struct xc_sr_rhdr = *rhdr, + struct xc_sr_record *rec) +{ + xc_interface *xch =3D ctx->xch; + size_t datasz; + + datasz =3D ROUNDUP(rhdr->length, REC_ALIGN_ORDER); =20 if ( datasz ) { @@ -119,7 +126,7 @@ int read_record(struct xc_sr_context *ctx, int fd, stru= ct xc_sr_record *rec) if ( !rec->data ) { ERROR("Unable to allocate %zu bytes for record data (0x%08x, %= s)", - datasz, rhdr.type, rec_type_to_str(rhdr.type)); + datasz, rhdr->type, rec_type_to_str(rhdr->type)); return -1; } =20 @@ -128,18 +135,18 @@ int read_record(struct xc_sr_context *ctx, int fd, st= ruct xc_sr_record *rec) free(rec->data); rec->data =3D NULL; PERROR("Failed to read %zu bytes of data for record (0x%08x, %= s)", - datasz, rhdr.type, rec_type_to_str(rhdr.type)); + datasz, rhdr->type, rec_type_to_str(rhdr->type)); return -1; } } else rec->data =3D NULL; =20 - rec->type =3D rhdr.type; - rec->length =3D rhdr.length; + rec->type =3D rhdr->type; + rec->length =3D rhdr->length; =20 return 0; -}; +} =20 static void __attribute__((unused)) build_assertions(void) { diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 9de09ae64a..73256f08ab 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -487,7 +487,9 @@ static inline int write_record(struct xc_sr_context *ct= x, * * On failure, the contents of the record structure are undefined. */ -int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *re= c); +int read_record_header(struct xc_sr_context *ctx, int fd, struct xc_sr_rhd= r *rhdr); +int read_record_data(struct xc_sr_context *ctx, int fd, struct xc_sr_rhdr = *rhdr, + struct xc_sr_record *rec); =20 /* * This would ideally be private in restore.c, but is needed by diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 598a4aa06d..bb1574ed74 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -471,7 +471,7 @@ static int send_checkpoint_dirty_pfn_list(struct xc_sr_= context *ctx) return rc; } =20 -static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *= rec); +static int process_buffered_record(struct xc_sr_context *ctx, struct xc_sr= _record *rec); static int handle_checkpoint(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; @@ -510,7 +510,7 @@ static int handle_checkpoint(struct xc_sr_context *ctx) =20 for ( i =3D 0; i < ctx->restore.buffered_rec_num; i++ ) { - rc =3D process_record(ctx, &ctx->restore.buffered_records[i]); + rc =3D process_buffered_record(ctx, &ctx->restore.buffered_rec= ords[i]); if ( rc ) goto err; } @@ -571,10 +571,11 @@ static int handle_checkpoint(struct xc_sr_context *ct= x) return rc; } =20 -static int buffer_record(struct xc_sr_context *ctx, struct xc_sr_record *r= ec) +static int buffer_record(struct xc_sr_context *ctx, struct xc_sr_rhdr *rhd= r) { xc_interface *xch =3D ctx->xch; unsigned int new_alloc_num; + struct xc_sr_record rec; struct xc_sr_record *p; =20 if ( ctx->restore.buffered_rec_num >=3D ctx->restore.allocated_rec_num= ) @@ -592,8 +593,13 @@ static int buffer_record(struct xc_sr_context *ctx, st= ruct xc_sr_record *rec) ctx->restore.allocated_rec_num =3D new_alloc_num; } =20 + if ( read_record_data(ctx, ctx->fd, rhdr, &rec) ) + { + return -1; + } + memcpy(&ctx->restore.buffered_records[ctx->restore.buffered_rec_num++], - rec, sizeof(*rec)); + &rec, sizeof(rec)); =20 return 0; } @@ -624,7 +630,7 @@ int handle_static_data_end(struct xc_sr_context *ctx) return rc; } =20 -static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *= rec) +static int process_buffered_record(struct xc_sr_context *ctx, struct xc_sr= _record *rec) { xc_interface *xch =3D ctx->xch; int rc =3D 0; @@ -662,6 +668,19 @@ static int process_record(struct xc_sr_context *ctx, s= truct xc_sr_record *rec) return rc; } =20 +static int process_incoming_record_header(struct xc_sr_context *ctx, struc= t xc_sr_rhdr *rhdr) +{ + struct xc_sr_record rec; + int rc; + + rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); + if ( rc ) + return rc; + + return process_buffered_record(ctx, &rec); +} + + static int setup(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; @@ -745,7 +764,7 @@ static void cleanup(struct xc_sr_context *ctx) static int restore(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; - struct xc_sr_record rec; + struct xc_sr_rhdr rhdr; int rc, saved_rc =3D 0, saved_errno =3D 0; =20 IPRINTF("Restoring domain"); @@ -756,7 +775,7 @@ static int restore(struct xc_sr_context *ctx) =20 do { - rc =3D read_record(ctx, ctx->fd, &rec); + rc =3D read_record_header(ctx, ctx->fd, &rhdr); if ( rc ) { if ( ctx->restore.buffer_all_records ) @@ -766,25 +785,25 @@ static int restore(struct xc_sr_context *ctx) } =20 if ( ctx->restore.buffer_all_records && - rec.type !=3D REC_TYPE_END && - rec.type !=3D REC_TYPE_CHECKPOINT ) + rhdr.type !=3D REC_TYPE_END && + rhdr.type !=3D REC_TYPE_CHECKPOINT ) { - rc =3D buffer_record(ctx, &rec); + rc =3D buffer_record(ctx, &rhdr); if ( rc ) goto err; } else { - rc =3D process_record(ctx, &rec); + rc =3D process_incoming_record_header(ctx, &rhdr); if ( rc =3D=3D RECORD_NOT_PROCESSED ) { - if ( rec.type & REC_TYPE_OPTIONAL ) + if ( rhdr.type & REC_TYPE_OPTIONAL ) DPRINTF("Ignoring optional record %#x (%s)", - rec.type, rec_type_to_str(rec.type)); + rhdr.type, rec_type_to_str(rhdr.type)); else { ERROR("Mandatory record %#x (%s) not handled", - rec.type, rec_type_to_str(rec.type)); + rhdr.type, rec_type_to_str(rhdr.type)); rc =3D -1; goto err; } @@ -795,7 +814,7 @@ static int restore(struct xc_sr_context *ctx) goto err; } =20 - } while ( rec.type !=3D REC_TYPE_END ); + } while ( rhdr.type !=3D REC_TYPE_END ); =20 remus_failover: if ( ctx->stream_type =3D=3D XC_STREAM_COLO ) diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index c4876ba24c..b59cb069ed 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -590,6 +590,7 @@ static int send_memory_live(struct xc_sr_context *ctx) static int colo_merge_secondary_dirty_bitmap(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; + struct xc_sr_rhdr rhdr; struct xc_sr_record rec; uint64_t *pfns =3D NULL; uint64_t pfn; @@ -598,7 +599,11 @@ static int colo_merge_secondary_dirty_bitmap(struct xc= _sr_context *ctx) DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); =20 - rc =3D read_record(ctx, ctx->save.recv_fd, &rec); + rc =3D read_record_header(ctx, ctx->save.recv_fd, &rhdr); + if ( rc ) + goto err; + + rc =3D read_record_data(ctx, ctx->save.recv_fd, &rhdr, &rec); if ( rc ) goto err; =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564227103877.5568781657731; Tue, 1 Jun 2021 09:17:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135060.251306 (Exim 4.92) (envelope-from ) id 1lo74O-0007Cn-O4; Tue, 01 Jun 2021 16:16:44 +0000 Received: by outflank-mailman (output) from mailman id 135060.251306; Tue, 01 Jun 2021 16:16:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo74O-0007Cg-KJ; Tue, 01 Jun 2021 16:16:44 +0000 Received: by outflank-mailman (input) for mailman id 135060; Tue, 01 Jun 2021 16:16:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70k-0005Ec-3S for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:58 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1c6e3a17-5e01-451b-b7b0-3bf1394c1a90; Tue, 01 Jun 2021 16:11:42 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBa1BU (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:36 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1c6e3a17-5e01-451b-b7b0-3bf1394c1a90 ARC-Seal: i=1; a=rsa-sha256; t=1622563896; cv=none; d=strato.com; s=strato-dkim-0002; b=oq8uQSOCopC2wqt4KXP/PJIMSsJMeRfwAtBCnP3SPlaTbYuA1whhMGU1X8xDREzu9e im7cg2t8gff2Kv4a6g7CtYM84w/eqeVnXN+Yd9ibLjoT4xtnz1J0vlIo/RdHy3cqyMJh yvSSYNKU2nK133nA9+g/AXOMKXpONKxLZK/jwywNtHYsLsX5Uu/yXP8nOwaYYccTcQnN 9eF4Ezw5eiX6lAR6tnK9IbVLEQ5SLBrn2JINwDFUuQDiEoqkUzluZ4PRFxiHPINO+Oc2 qIdIntXAw7DT948EDP4d7Z9S+zBfvZO6fhgtN2JPekin7o2hK00bCNnLCvIfMZELVYQ2 m4Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563896; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=OehxVYQzQRfrdjC5ERJeiffQghSA59T3Cae/kEPq6Gc=; b=kU3HGacCm+PbjhdqOIrzws0AzFGx9mcS4kLVDRX74SATNRbGwiwV3VTEq/s3OoRzlM I0mN+DvSJhEg8pf7QNfpCnaDUkbAAvzj6SAchEqm5NUsy5rUK4zb7xXLO+awNKUCw+2I r/nxOgZBsZ6ugKbo9JsSOt2srZb/2N2tBaMbRi9h9rBZRZOyUPbY69TRttkrrgUc1Z5t r/BwFiNEN8EB5f50UJK6sm/LX9CcWSpGvlVVujAYZMLGk+dX+0SasXdKguV3XeP7i18O ObcW937mDHj99DT9KumElASHwzWM/H9AoPVGTFZoVKA/7enGluyvr0PpFBxxcQ96y3yu 6gQQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563896; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=OehxVYQzQRfrdjC5ERJeiffQghSA59T3Cae/kEPq6Gc=; b=p7cPHCBZPWH95nUnid7843WoRQ4AbwjwOfNRRCW4BG3VnoV+S24IXBfAtGep5EjypU P+WRTZI0bUUwuMNIFoQ/Nqwkx1tTn7nFjfm7QVX8wDNb9CCIiIEXAo0/uwlTgvJzEygV YaqUm8LFqFh6wzO54oGsgUd6XAfsH+7v01z/tlrqwr5yxaUGz4Dr+7X1ow25TArgpGaS 1LmR+e+HyzwWiBdzj3lZe4Evpwf8JDIVSuG0+c8BeZLarUjnDjK1goBopeNOUeboaviE rjNRsp5r9a6F4+xHh6hykcfMlbQkaKxSZcXkDhfaXabJw34uUIYZnh/zA8HfjEnzQ+o7 If6Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 25/38] tools/guest: restore: split handle_page_data Date: Tue, 1 Jun 2021 18:11:05 +0200 Message-Id: <20210601161118.18986-26-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" handle_page_data must be able to read directly into mapped guest memory. This will avoid unneccesary memcpy calls for data that can be consumed verb= atim. Split the various steps of record processing: - move processing to handle_buffered_page_data - adjust xenforeignmemory_map to set errno in case of failure - adjust verify mode to set errno in case of failure This change is preparation for future changes in handle_page_data, no change in behavior is intended. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 9 + tools/libs/saverestore/restore.c | 343 ++++++++++++++++++++----------- 2 files changed, 231 insertions(+), 121 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 73256f08ab..21fdcf234e 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -242,9 +242,14 @@ struct xc_sr_restore_arrays { /* process_page_data */ xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; + void *guest_data[MAX_BATCH_SIZE]; + /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; xen_pfn_t pp_pfns[MAX_BATCH_SIZE]; + + /* Must be the last member */ + struct xc_sr_rec_page_data_header pages; }; =20 struct xc_sr_context @@ -335,7 +340,11 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + void *verify_buf; + struct xc_sr_restore_arrays *m; + void *guest_mapping; + uint32_t nr_mapped_pages; } restore; }; =20 diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index bb1574ed74..f7b4a7124b 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -186,123 +186,18 @@ int populate_pfns(struct xc_sr_context *ctx, unsigne= d int count, return rc; } =20 -/* - * Given a list of pfns, their types, and a block of page data from the - * stream, populate and record their types, map the relevant subset and co= py - * the data into the guest. - */ -static int process_page_data(struct xc_sr_context *ctx, unsigned int count, - xen_pfn_t *pfns, uint32_t *types, void *page_= data) +static int handle_static_data_end_v2(struct xc_sr_context *ctx) { - xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D ctx->restore.m->mfns; - int *map_errs =3D ctx->restore.m->map_errs; - int rc; - void *mapping =3D NULL, *guest_page =3D NULL; - unsigned int i, /* i indexes the pfns from the record. */ - j, /* j indexes the subset of pfns we decide to map. */ - nr_pages =3D 0; - - rc =3D populate_pfns(ctx, count, pfns, types); - if ( rc ) - { - ERROR("Failed to populate pfns for batch of %u pages", count); - goto err; - } - - for ( i =3D 0; i < count; ++i ) - { - ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); - - if ( page_type_has_stream_data(types[i]) =3D=3D true ) - mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); - } - - /* Nothing to do? */ - if ( nr_pages =3D=3D 0 ) - goto done; - - mapping =3D guest_page =3D xenforeignmemory_map( - xch->fmem, ctx->domid, PROT_READ | PROT_WRITE, - nr_pages, mfns, map_errs); - if ( !mapping ) - { - rc =3D -1; - PERROR("Unable to map %u mfns for %u pages of data", - nr_pages, count); - goto err; - } - - for ( i =3D 0, j =3D 0; i < count; ++i ) - { - if ( page_type_has_stream_data(types[i]) =3D=3D false ) - continue; - - if ( map_errs[j] ) - { - rc =3D -1; - ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[j], types[i], map_errs[j]); - goto err; - } - - /* Undo page normalisation done by the saver. */ - rc =3D ctx->restore.ops.localise_page(ctx, types[i], page_data); - if ( rc ) - { - ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", - pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); - goto err; - } - - if ( ctx->restore.verify ) - { - /* Verify mode - compare incoming data to what we already have= . */ - if ( memcmp(guest_page, page_data, PAGE_SIZE) ) - ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", - pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); - } - else - { - /* Regular mode - copy incoming data into place. */ - memcpy(guest_page, page_data, PAGE_SIZE); - } - - ++j; - guest_page +=3D PAGE_SIZE; - page_data +=3D PAGE_SIZE; - } - - done: - rc =3D 0; - - err: - if ( mapping ) - xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); - - return rc; -} + int rc =3D 0; =20 -/* - * Validate a PAGE_DATA record from the stream, and pass the results to - * process_page_data() to actually perform the legwork. - */ -static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record= *rec) -{ +#if defined(__i386__) || defined(__x86_64__) xc_interface *xch =3D ctx->xch; - struct xc_sr_rec_page_data_header *pages =3D rec->data; - unsigned int i, pages_of_data =3D 0; - int rc =3D -1; - - xen_pfn_t *pfns =3D ctx->restore.m->pfns, pfn; - uint32_t *types =3D ctx->restore.m->types, type; - /* * v2 compatibility only exists for x86 streams. This is a bit of a * bodge, but it is less bad than duplicating handle_page_data() betwe= en * different architectures. */ -#if defined(__i386__) || defined(__x86_64__) + /* v2 compat. Infer the position of STATIC_DATA_END. */ if ( ctx->restore.format_version < 3 && !ctx->restore.seen_static_data= _end ) { @@ -320,12 +215,26 @@ static int handle_page_data(struct xc_sr_context *ctx= , struct xc_sr_record *rec) ERROR("No STATIC_DATA_END seen"); goto err; } + + rc =3D 0; +err: #endif =20 - if ( rec->length < sizeof(*pages) ) + return rc; +} + +static bool verify_rec_page_hdr(struct xc_sr_context *ctx, uint32_t rec_le= ngth, + struct xc_sr_rec_page_data_header *pages) +{ + xc_interface *xch =3D ctx->xch; + bool ret =3D false; + + errno =3D EINVAL; + + if ( rec_length < sizeof(*pages) ) { ERROR("PAGE_DATA record truncated: length %u, min %zu", - rec->length, sizeof(*pages)); + rec_length, sizeof(*pages)); goto err; } =20 @@ -335,13 +244,35 @@ static int handle_page_data(struct xc_sr_context *ctx= , struct xc_sr_record *rec) goto err; } =20 - if ( rec->length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) ) + if ( pages->count > MAX_BATCH_SIZE ) + { + ERROR("pfn count %u in PAGE_DATA record too large", pages->count); + errno =3D E2BIG; + goto err; + } + + if ( rec_length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) ) { ERROR("PAGE_DATA record (length %u) too short to contain %u" - " pfns worth of information", rec->length, pages->count); + " pfns worth of information", rec_length, pages->count); goto err; } =20 + ret =3D true; + +err: + return ret; +} + +static bool verify_rec_page_pfns(struct xc_sr_context *ctx, uint32_t rec_l= ength, + struct xc_sr_rec_page_data_header *pages) +{ + xc_interface *xch =3D ctx->xch; + uint32_t i, pages_of_data =3D 0; + xen_pfn_t pfn; + uint32_t type; + bool ret =3D false; + for ( i =3D 0; i < pages->count; ++i ) { pfn =3D pages->pfn[i] & PAGE_DATA_PFN_MASK; @@ -364,23 +295,183 @@ static int handle_page_data(struct xc_sr_context *ct= x, struct xc_sr_record *rec) * have a page worth of data in the record. */ pages_of_data++; =20 - pfns[i] =3D pfn; - types[i] =3D type; + ctx->restore.m->pfns[i] =3D pfn; + ctx->restore.m->types[i] =3D type; } =20 - if ( rec->length !=3D (sizeof(*pages) + + if ( rec_length !=3D (sizeof(*pages) + (sizeof(uint64_t) * pages->count) + (PAGE_SIZE * pages_of_data)) ) { ERROR("PAGE_DATA record wrong size: length %u, expected " - "%zu + %zu + %lu", rec->length, sizeof(*pages), + "%zu + %zu + %lu", rec_length, sizeof(*pages), (sizeof(uint64_t) * pages->count), (PAGE_SIZE * pages_of_dat= a)); goto err; } =20 - rc =3D process_page_data(ctx, pages->count, pfns, types, - &pages->pfn[pages->count]); + ret =3D true; + +err: + return ret; +} + +/* + * Populate pfns, if required + * Fill m->guest_data with either mapped address or NULL + * The caller must unmap guest_mapping + */ +static int map_guest_pages(struct xc_sr_context *ctx, + struct xc_sr_rec_page_data_header *pages) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + uint32_t i, p; + int rc; + + rc =3D populate_pfns(ctx, pages->count, m->pfns, m->types); + if ( rc ) + { + ERROR("Failed to populate pfns for batch of %u pages", pages->coun= t); + goto err; + } + + ctx->restore.nr_mapped_pages =3D 0; + + for ( i =3D 0; i < pages->count; i++ ) + { + ctx->restore.ops.set_page_type(ctx, m->pfns[i], m->types[i]); + + if ( page_type_has_stream_data(m->types[i]) =3D=3D false ) + { + m->guest_data[i] =3D NULL; + continue; + } + + m->mfns[ctx->restore.nr_mapped_pages++] =3D ctx->restore.ops.pfn_t= o_gfn(ctx, m->pfns[i]); + } + + /* Nothing to do? */ + if ( ctx->restore.nr_mapped_pages =3D=3D 0 ) + goto done; + + ctx->restore.guest_mapping =3D xenforeignmemory_map(xch->fmem, ctx->do= mid, + PROT_READ | PROT_WRITE, ctx->restore.nr_mapped_pages, + m->mfns, m->map_errs); + if ( !ctx->restore.guest_mapping ) + { + rc =3D -1; + PERROR("Unable to map %u mfns for %u pages of data", + ctx->restore.nr_mapped_pages, pages->count); + goto err; + } + + /* Verify mapping, and assign address to pfn data */ + for ( i =3D 0, p =3D 0; i < pages->count; i++ ) + { + if ( page_type_has_stream_data(m->types[i]) =3D=3D false ) + continue; + + if ( m->map_errs[p] =3D=3D 0 ) + { + m->guest_data[i] =3D ctx->restore.guest_mapping + (p * PAGE_SI= ZE); + p++; + continue; + } + + errno =3D m->map_errs[p]; + rc =3D -1; + PERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32") f= ailed", + m->pfns[i], m->mfns[p], m->types[i]); + goto err; + } + +done: + rc =3D 0; + +err: + return rc; +} + +/* + * Handle PAGE_DATA record from an existing buffer + * Given a list of pfns, their types, and a block of page data from the + * stream, populate and record their types, map the relevant subset and co= py + * the data into the guest. + */ +static int handle_buffered_page_data(struct xc_sr_context *ctx, + struct xc_sr_record *rec) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_rec_page_data_header *pages =3D rec->data; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + void *p; + uint32_t i; + int rc =3D -1, idx; + + rc =3D handle_static_data_end_v2(ctx); + if ( rc ) + goto err; + + /* First read and verify the header */ + if ( verify_rec_page_hdr(ctx, rec->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Then read and verify the pfn numbers */ + if ( verify_rec_page_pfns(ctx, rec->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Map the target pfn */ + rc =3D map_guest_pages(ctx, pages); + if ( rc ) + goto err; + + for ( i =3D 0, idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + p =3D &pages->pfn[pages->count] + (idx * PAGE_SIZE); + rc =3D ctx->restore.ops.localise_page(ctx, m->types[i], p); + if ( rc ) + { + ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + goto err; + + } + + if ( ctx->restore.verify ) + { + if ( memcmp(m->guest_data[i], p, PAGE_SIZE) ) + { + errno =3D EIO; + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); + goto err; + } + } + else + { + memcpy(m->guest_data[i], p, PAGE_SIZE); + } + + idx++; + } + + rc =3D 0; + err: + if ( ctx->restore.guest_mapping ) + { + xenforeignmemory_unmap(xch->fmem, ctx->restore.guest_mapping, ctx-= >restore.nr_mapped_pages); + ctx->restore.guest_mapping =3D NULL; + } return rc; } =20 @@ -641,12 +732,21 @@ static int process_buffered_record(struct xc_sr_conte= xt *ctx, struct xc_sr_recor break; =20 case REC_TYPE_PAGE_DATA: - rc =3D handle_page_data(ctx, rec); + rc =3D handle_buffered_page_data(ctx, rec); break; =20 case REC_TYPE_VERIFY: DPRINTF("Verify mode enabled"); ctx->restore.verify =3D true; + if ( !ctx->restore.verify_buf ) + { + ctx->restore.verify_buf =3D malloc(MAX_BATCH_SIZE * PAGE_SIZE); + if ( !ctx->restore.verify_buf ) + { + rc =3D -1; + PERROR("Unable to allocate verify_buf"); + } + } break; =20 case REC_TYPE_CHECKPOINT: @@ -725,7 +825,8 @@ static int setup(struct xc_sr_context *ctx) } ctx->restore.allocated_rec_num =3D DEFAULT_BUF_RECORDS; =20 - ctx->restore.m =3D malloc(sizeof(*ctx->restore.m)); + ctx->restore.m =3D malloc(sizeof(*ctx->restore.m) + + (sizeof(*ctx->restore.m->pages.pfn) * MAX_BATCH_SIZE)); if ( !ctx->restore.m ) { ERROR("Unable to allocate memory for arrays"); rc =3D -1; From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162256424839944.08361575445781; Tue, 1 Jun 2021 09:17:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135067.251328 (Exim 4.92) (envelope-from ) id 1lo74s-0008NV-Dt; Tue, 01 Jun 2021 16:17:14 +0000 Received: by outflank-mailman (output) from mailman id 135067.251328; Tue, 01 Jun 2021 16:17:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo74s-0008NO-Ao; Tue, 01 Jun 2021 16:17:14 +0000 Received: by outflank-mailman (input) for mailman id 135067; Tue, 01 Jun 2021 16:17:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70a-0005Ec-32 for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:48 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 92920130-7184-433e-aa96-fa8bc703aa30; Tue, 01 Jun 2021 16:11:41 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBa1BV (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:36 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 92920130-7184-433e-aa96-fa8bc703aa30 ARC-Seal: i=1; a=rsa-sha256; t=1622563897; cv=none; d=strato.com; s=strato-dkim-0002; b=dudlQMcq6QurLVSYJAZ5weU9gLvgk7ga30PI1ni10/6v6vlW/RpnHiPHc344aQoT5n 2nz6eoXiB/UvOMX5ayAh296N7uv2c6NzJkDR+WJMrih3YAByL9vZjGszF01V7WtxVgfV QHJATJaC2ppHIXC18mXOcO8fRGdVT/ZZkm0tW2YStIJv5Ok/vEcOBtskppeG10WX0pl1 zER3j01QAJf8z25RLfcSf6e5zR7dBrvfE8o6auj+TTE4u3VXi8Xsb2XYg/I2ALhGf8vJ F3JMeO+47uR4o8kEUTblo+Z6kXw5H9UaPLNxYNn/YbCsbbiWlmTZsDh1oRwX4GugPjhC QpzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563897; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=eDLBvLwdNBkdJsm65Hcts+kQfVHtshr8GV54yTNeA1Y=; b=JbEojE7DjUODPQOlO5CTL9kaucbAdMnMgmE0frwsA9qoL0+7NQivopCQV1UYoDI3io Bv4OKH8RLvhWhHozcxfNvNWB0httJNIpTZRT4KZzok7EPnsIeMYkwSi/q8zbQCbw3j// AltqW/84hmVILTF473mnzapNbVfMUmfJ0vZ3EaWLMoykCOdkzUL7zPrCIUsMVG1gY+zu YnyVvu57o/rPpQ46Mq2TXmP++9Vo67ER487wS1y1YZEC77u0hk7KJWirxRBhyHvIO/UV 6glChkY0ZOmKCxYv4spTfEYEYAwrJRrXmUbDY2RGsQiPEDxMwqQn7sFTveRDeYDhDVBZ RxhA== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563897; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=eDLBvLwdNBkdJsm65Hcts+kQfVHtshr8GV54yTNeA1Y=; b=M7R0KO8O/hmI94jXqEKM8+BNsOwtJDTsMT3JBfBJAiidLHe0/pK+fv7NWrqk7fr5es 42Y1ZKKcFIWVjB/9F+GtXKa1vWrVXxKIBhrml9jbsCD3ImanI17KncC2trj677FlC+Ja 6OGVucrVcpzSSpGtUp0UwiNm3x4iBGWpZqkas/bW8X8BQAov7/qkLmjzpGmLdQnt617a Pz39F4JDfz4TU3ldYRFayHtqh6kKdgpBzan401LwdvOzidPKERz6p9UNJl1FKj160qLb AhpS1NyKO2cLtYhyOZnY372E2XK0G+148UGj6Ati25SZjLtxmpAz8bPqEo9+5EBrlHzk 0FAA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 26/38] tools/guest: restore: write data directly into guest Date: Tue, 1 Jun 2021 18:11:06 +0200 Message-Id: <20210601161118.18986-27-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Read incoming migration stream directly into the guest memory. This avoids the memory allocation and copying, and the resulting performance penalty. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 1 + tools/libs/saverestore/restore.c | 132 ++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 21fdcf234e..4218a8ecd6 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -243,6 +243,7 @@ struct xc_sr_restore_arrays { xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; void *guest_data[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE]; =20 /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index f7b4a7124b..722f77b46a 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -392,6 +392,122 @@ err: return rc; } =20 +/* + * Handle PAGE_DATA record from the stream. + * Given a list of pfns, their types, and a block of page data from the + * stream, populate and record their types, map the relevant subset and co= py + * the data into the guest. + */ +static int handle_incoming_page_data(struct xc_sr_context *ctx, + struct xc_sr_rhdr *rhdr) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + struct xc_sr_rec_page_data_header *pages =3D &m->pages; + uint64_t *pfn_nums =3D m->pages.pfn; + uint32_t i; + int rc, iov_idx; + + rc =3D handle_static_data_end_v2(ctx); + if ( rc ) + goto err; + + /* First read and verify the header */ + rc =3D read_exact(ctx->fd, pages, sizeof(*pages)); + if ( rc ) + { + PERROR("Could not read rec_pfn header"); + goto err; + } + + if ( verify_rec_page_hdr(ctx, rhdr->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Then read and verify the incoming pfn numbers */ + rc =3D read_exact(ctx->fd, pfn_nums, sizeof(*pfn_nums) * pages->count); + if ( rc ) + { + PERROR("Could not read rec_pfn data"); + goto err; + } + + if ( verify_rec_page_pfns(ctx, rhdr->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Finally read and verify the incoming pfn data */ + rc =3D map_guest_pages(ctx, pages); + if ( rc ) + goto err; + + /* Prepare read buffers, either guest or throw away memory */ + for ( i =3D 0, iov_idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + m->iov[iov_idx].iov_len =3D PAGE_SIZE; + if ( ctx->restore.verify ) + m->iov[iov_idx].iov_base =3D ctx->restore.verify_buf + i * PAG= E_SIZE; + else + m->iov[iov_idx].iov_base =3D m->guest_data[i]; + iov_idx++; + } + + if ( !iov_idx ) + goto done; + + rc =3D readv_exact(ctx->fd, m->iov, iov_idx); + if ( rc ) + { + PERROR("read of %d pages failed", iov_idx); + goto err; + } + + /* Post-processing of pfn data */ + for ( i =3D 0, iov_idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + rc =3D ctx->restore.ops.localise_page(ctx, m->types[i], m->iov[iov= _idx].iov_base); + if ( rc ) + { + ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + goto err; + + } + + if ( ctx->restore.verify ) + { + if ( memcmp(m->guest_data[i], m->iov[iov_idx].iov_base, PAGE_S= IZE) ) + { + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); + } + } + + iov_idx++; + } + +done: + rc =3D 0; + +err: + if ( ctx->restore.guest_mapping ) + { + xenforeignmemory_unmap(xch->fmem, ctx->restore.guest_mapping, ctx-= >restore.nr_mapped_pages); + ctx->restore.guest_mapping =3D NULL; + } + return rc; +} + /* * Handle PAGE_DATA record from an existing buffer * Given a list of pfns, their types, and a block of page data from the @@ -773,11 +889,19 @@ static int process_incoming_record_header(struct xc_s= r_context *ctx, struct xc_s struct xc_sr_record rec; int rc; =20 - rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); - if ( rc ) - return rc; + switch ( rhdr->type ) + { + case REC_TYPE_PAGE_DATA: + rc =3D handle_incoming_page_data(ctx, rhdr); + break; + default: + rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); + if ( rc =3D=3D 0 ) + rc =3D process_buffered_record(ctx, &rec);; + break; + } =20 - return process_buffered_record(ctx, &rec); + return rc; } =20 =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162256395363242.73760323959959; Tue, 1 Jun 2021 09:12:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135007.251172 (Exim 4.92) (envelope-from ) id 1lo704-00054v-Dc; Tue, 01 Jun 2021 16:12:16 +0000 Received: by outflank-mailman (output) from mailman id 135007.251172; Tue, 01 Jun 2021 16:12:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo703-00052v-Uk; Tue, 01 Jun 2021 16:12:15 +0000 Received: by outflank-mailman (input) for mailman id 135007; Tue, 01 Jun 2021 16:12:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo702-0005X1-0H for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:14 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.103]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9ea60976-470e-41f2-a4d4-de729ddb777a; Tue, 01 Jun 2021 16:11:41 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBb1BW (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:37 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9ea60976-470e-41f2-a4d4-de729ddb777a ARC-Seal: i=1; a=rsa-sha256; t=1622563897; cv=none; d=strato.com; s=strato-dkim-0002; b=DceQnoMD1LPxJK7nDDoI5jY7qyrJO2b8pj9TXL3fxAY8NxT/G8fHE1LT7IyYYEUgsk VC2V36pU/F/9Uu7l/TmVZxOy1inNDMA/+R6ewt/qsmeC2fHkp+rIKrcEItQ1iFVmWhc3 0iG6DTYDmR0dAvQua+fBjIQ3TfjNi2StaB/clALrkHKoHltA84Nqa7Rtso+UMaDDbFpK LoPcnwCPDXbaJFV3H/flgac9SE/CtOTTViWNLD3lwgQXjE7//B/mHqc2dd4XZJVpC5z4 DnhGlj00Hxzs2qKPPyUJBiF2newFmudvMsY0l1LGqvAeYU4rfZEGdSfHErp+bdm8uMuQ 15/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563897; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=0LMXyjqr5dhJU6Kt86LbarPPbfCTtmro+NAOq1cH7Ts=; b=MxhvzI3nXOCmBeAiRJFUchsTY/iiFWK16afmVmO7QesHmwQsU/ZIum/e4kJxpkINwb DC2yJT/j4a7ebhe0H3SdWCI8BR1/pfzoH2YgHWKXGYSbwAmzSE41S0cH1CjToAu4mjNl J0jzndpOI2m9J1AIZ/C17acSy/0DIUf/vHWC/ouT7If9g/tw0CFiUhCZFJtLhJUnUA3W s9N0eYzO8/sClRLqA+zFrpPoR/YVmWRU/FSM5CT3blvk3GedmOYavbHM6XoDULwBqrTF EjUwV+ejaa7rM2+J9SrBAl5U3OvqzxPzQS73GduI0vOOT9GcMpw8d63gqK/BS7AROldV 2umQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563897; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=0LMXyjqr5dhJU6Kt86LbarPPbfCTtmro+NAOq1cH7Ts=; b=a3XGOIo9gK0sthRo1QW/ge3Lkbka6xS371SdjVtTG/iXT5nFIlwa7ngxBPwuIPAr3C L64Vvat9i1dmTDh1iEVYeDmuHVXnSkbiIiKGPChYjogOQug5W4x4lc6QXUX2XKZiwfX+ 6JUCJM2cSA8y0xDAzqKajAnh5WpmMJ+XyglmRTpyi8N0ytP8b8PJ+OYlz4SCxgypjTTs Fi47XB9TJ2M8js49koTSW4cYbjafFJl/itk5QIHxRfl94FgN2AOhU4v/bRkZmvEWY0Gj tjE0HNGOPC4mkzS5VegXe8nbhJuTH0Yc0THPtZe2SGRxYdqZ2kwPYeww6lFrBNGZF7E3 IfVQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 27/38] tools: recognize LIBXL_API_VERSION for 4.16 Date: Tue, 1 Jun 2021 18:11:07 +0200 Message-Id: <20210601161118.18986-28-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is required by upcoming API changes. Signed-off-by: Olaf Hering --- tools/include/libxl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index ae7fe27c1f..29931626a2 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -729,7 +729,8 @@ typedef struct libxl__ctx libxl_ctx; #if LIBXL_API_VERSION !=3D 0x040200 && LIBXL_API_VERSION !=3D 0x040300 && \ LIBXL_API_VERSION !=3D 0x040400 && LIBXL_API_VERSION !=3D 0x040500 && \ LIBXL_API_VERSION !=3D 0x040700 && LIBXL_API_VERSION !=3D 0x040800 && \ - LIBXL_API_VERSION !=3D 0x041300 && LIBXL_API_VERSION !=3D 0x041400 + LIBXL_API_VERSION !=3D 0x041300 && LIBXL_API_VERSION !=3D 0x041400 && \ + LIBXL_API_VERSION !=3D 0x041600 #error Unknown LIBXL_API_VERSION #endif #endif From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564719508485.83397214603553; Tue, 1 Jun 2021 09:25:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135185.251372 (Exim 4.92) (envelope-from ) id 1lo7CV-0003Yq-59; Tue, 01 Jun 2021 16:25:07 +0000 Received: by outflank-mailman (output) from mailman id 135185.251372; Tue, 01 Jun 2021 16:25:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo7CV-0003Yi-23; Tue, 01 Jun 2021 16:25:07 +0000 Received: by outflank-mailman (input) for mailman id 135185; Tue, 01 Jun 2021 16:25:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo714-0005Ec-47 for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:13:18 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.103]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5c75630c-d80a-48a9-99c5-350bb6fde6fb; Tue, 01 Jun 2021 16:11:46 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBb1BX (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:37 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5c75630c-d80a-48a9-99c5-350bb6fde6fb ARC-Seal: i=1; a=rsa-sha256; t=1622563898; cv=none; d=strato.com; s=strato-dkim-0002; b=mLSCEVWIFwr02TVbN1MLeBsQfsvHUlomH4hp7tBnrC/a1zOboNFjxGPvuv0nyJ3Uuk xvl1JVOLX3SUyaesWJJrQcEIyZtT5iUykTLdwsYVgkjEDnJo1pgknKJHt30/NSkxzb2D JjlMMnPGKIECbpLepyJTTCf2u/QCsd+DMDbZ0kxjBiovQ0QvN3vB50mPvZNqYTPsmXe4 AEZRBKZ/aM1q59MH4MgqGu5Ol6UYdOdaHnhFwq5OpwM9WeWT/aBFH3XOH+qrm7ox5xz/ BLxoauPJk/fnQoIOsw91SUv3r0qfknFEl/YRAyARtDcSmh1m03lh5pD+3nkT2MsZdvqb W6Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563898; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=MTSqerw0vG4VSeyAPsATEiIANrLKHzhkpCbX69ppdjs=; b=cDP8SqOs6PbiHTLtkZHJMJO3LZgPhQDqfsDb6YGUlSOpGNWeIcyzOmQt+yB8jr3GCs Pxo9cQa6EVHzmKQteeIRimlg6eTxcV3fjHVqsDfQPYVv6zMvYUQKL4xMtkq477r02SGX rn6gs6q7l9Q1l/3YBy5lcOJOsoI244Drqrw9PPL0xE7+RhKRWsn0v+O+ebI6muqiQTLr 1NemoUBsFyy8Sv4nZUmcC9XIreuZJ6TzUjSwcJHvHFuRVeSKwYap8BN4zbrfzUQqOowN 7CTmqbCWD5IcLg6Mwk9olqqIfLQbSiDIptyGOzE179TbeuN8ChcETaf9RiuCp2AdgQnT uIaQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563898; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=MTSqerw0vG4VSeyAPsATEiIANrLKHzhkpCbX69ppdjs=; b=HIfYIkehMLE0pDA3u3B/kjs+Yufrb7XkJu/LvIJowk/lHA9LfbTCISGFdXYvPh/5xc iyRBvdOctkN5Ml7Oxhb9vNNTWoi64gwJyWZrLIlDHxgGv045Jln9X3cBy7U4JnGNvxKq 7ZpVirnVLOlvrzyvF8xFKwDgH81z+ph+EE6zilrHqwJO0Pbxzv1C+JtoiOZOXcTqT5iY IBIhrmRb763eM2W7rCRv1L0MoGoFO2+h4JoRiyYmV1YGdQ3amma8tIATUmo5GDTqKzTW Nf8lOgxURBOqqS/0akEFZE3/0FC/bz+5Qd1Ny7MnJ0yRtUhJyoUmvDnm4bjU5U1TX5j8 KySw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Christian Lindig , Ian Jackson , Wei Liu , Anthony PERARD , David Scott Subject: [PATCH v20210601 28/38] tools: adjust libxl_domain_suspend to receive a struct props Date: Tue, 1 Jun 2021 18:11:08 +0200 Message-Id: <20210601161118.18986-29-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Upcoming changes will pass more knobs down to xc_domain_save. Adjust the libxl_domain_suspend API to allow easy adding of additional knob= s. No change in behavior intented. Signed-off-by: Olaf Hering Acked-by: Christian Lindig --- tools/include/libxl.h | 26 +++++++++++++++++++++++--- tools/libs/light/libxl_domain.c | 7 ++++--- tools/ocaml/libs/xl/xenlight_stubs.c | 3 ++- tools/xl/xl_migrate.c | 9 ++++++--- tools/xl/xl_saverestore.c | 3 ++- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 29931626a2..9a4d7514ed 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1706,12 +1706,32 @@ static inline int libxl_retrieve_domain_configurati= on_0x041200( libxl_retrieve_domain_configuration_0x041200 #endif =20 +/* + * LIBXL_HAVE_DOMAIN_SUSPEND_PROPS indicates that the + * libxl_domain_suspend_props() function takes a props struct. + */ +#define LIBXL_HAVE_DOMAIN_SUSPEND_PROPS 1 + +typedef struct { + uint32_t flags; /* LIBXL_SUSPEND_* */ +} libxl_domain_suspend_props; +#define LIBXL_SUSPEND_DEBUG 1 +#define LIBXL_SUSPEND_LIVE 2 + int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, - int flags, /* LIBXL_SUSPEND_* */ + libxl_domain_suspend_props *props, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; -#define LIBXL_SUSPEND_DEBUG 1 -#define LIBXL_SUSPEND_LIVE 2 +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041600 +static inline int libxl_domain_suspend_0x041500(libxl_ctx *ctx, uint32_t d= omid, + int fd, int flags, /* LIBXL_SUSPEND_* */ + const libxl_asyncop_how *ao_how) +{ + libxl_domain_suspend_props props =3D { .flags =3D flags, }; + return libxl_domain_suspend(ctx, domid, fd, &props, ao_how); +} +#define libxl_domain_suspend libxl_domain_suspend_0x041500 +#endif =20 /* * Only suspend domain, do not save its state to file, do not destroy it. diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 5d4ec90711..45e0c57c3a 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -505,7 +505,8 @@ static void domain_suspend_cb(libxl__egc *egc, =20 } =20 -int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags, +int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, + libxl_domain_suspend_props *props, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); @@ -526,8 +527,8 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid= , int fd, int flags, dss->domid =3D domid; dss->fd =3D fd; dss->type =3D type; - dss->live =3D flags & LIBXL_SUSPEND_LIVE; - dss->debug =3D flags & LIBXL_SUSPEND_DEBUG; + dss->live =3D props->flags & LIBXL_SUSPEND_LIVE; + dss->debug =3D props->flags & LIBXL_SUSPEND_DEBUG; dss->checkpointed_stream =3D LIBXL_CHECKPOINTED_STREAM_NONE; =20 rc =3D libxl__fd_flags_modify_save(gc, dss->fd, diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 352a00134d..eaf7bce35a 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -614,10 +614,11 @@ value stub_libxl_domain_suspend(value ctx, value domi= d, value fd, value async, v int ret; uint32_t c_domid =3D Int_val(domid); int c_fd =3D Int_val(fd); + libxl_domain_suspend_props props =3D {}; libxl_asyncop_how *ao_how =3D aohow_val(async); =20 caml_enter_blocking_section(); - ret =3D libxl_domain_suspend(CTX, c_domid, c_fd, 0, ao_how); + ret =3D libxl_domain_suspend(CTX, c_domid, c_fd, &props, ao_how); caml_leave_blocking_section(); =20 free(ao_how); diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c index b8594f44a5..144890924f 100644 --- a/tools/xl/xl_migrate.c +++ b/tools/xl/xl_migrate.c @@ -186,7 +186,10 @@ static void migrate_domain(uint32_t domid, int preserv= e_domid, char *away_domname; char rc_buf; uint8_t *config_data; - int config_len, flags =3D LIBXL_SUSPEND_LIVE; + int config_len; + libxl_domain_suspend_props props =3D { + .flags =3D LIBXL_SUSPEND_LIVE, + }; =20 save_domain_core_begin(domid, preserve_domid, override_config_file, &config_data, &config_len); @@ -205,8 +208,8 @@ static void migrate_domain(uint32_t domid, int preserve= _domid, xtl_stdiostream_adjust_flags(logger, XTL_STDIOSTREAM_HIDE_PROGRESS, 0); =20 if (debug) - flags |=3D LIBXL_SUSPEND_DEBUG; - rc =3D libxl_domain_suspend(ctx, domid, send_fd, flags, NULL); + props.flags |=3D LIBXL_SUSPEND_DEBUG; + rc =3D libxl_domain_suspend(ctx, domid, send_fd, &props, NULL); if (rc) { fprintf(stderr, "migration sender: libxl_domain_suspend failed" " (rc=3D%d)\n", rc); diff --git a/tools/xl/xl_saverestore.c b/tools/xl/xl_saverestore.c index 953d791d1a..476d4d9a6a 100644 --- a/tools/xl/xl_saverestore.c +++ b/tools/xl/xl_saverestore.c @@ -130,6 +130,7 @@ static int save_domain(uint32_t domid, int preserve_dom= id, int fd; uint8_t *config_data; int config_len; + libxl_domain_suspend_props props =3D {}; =20 save_domain_core_begin(domid, preserve_domid, override_config_file, &config_data, &config_len); @@ -146,7 +147,7 @@ static int save_domain(uint32_t domid, int preserve_dom= id, =20 save_domain_core_writeconfig(fd, filename, config_data, config_len); =20 - int rc =3D libxl_domain_suspend(ctx, domid, fd, 0, NULL); + int rc =3D libxl_domain_suspend(ctx, domid, fd, &props, NULL); close(fd); =20 if (rc < 0) { From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622563952061104.43069215688195; Tue, 1 Jun 2021 09:12:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135011.251185 (Exim 4.92) (envelope-from ) id 1lo709-00065a-2z; Tue, 01 Jun 2021 16:12:21 +0000 Received: by outflank-mailman (output) from mailman id 135011.251185; Tue, 01 Jun 2021 16:12:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo708-000624-RE; Tue, 01 Jun 2021 16:12:20 +0000 Received: by outflank-mailman (input) for mailman id 135011; Tue, 01 Jun 2021 16:12:19 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo707-0005X1-0T for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:19 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 08fba356-fd76-4932-91f5-08adea71b95f; Tue, 01 Jun 2021 16:11:42 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBc1BZ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:38 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 08fba356-fd76-4932-91f5-08adea71b95f ARC-Seal: i=1; a=rsa-sha256; t=1622563898; cv=none; d=strato.com; s=strato-dkim-0002; b=h/1sE7f735WbI7yPgAA9MGI8Nd6R6y99TEAhwGOGR88axJzA6YQjdLY2jnSRo+J5bh 5VOeSe2YgyrbJpL4PSRovNzBUm7YRtu605kwZlKHaIaSdgEmXhYGXgyb3RWbNy0Auwuv FdeeXRfdfoYPwzZvXldE4kQt4fLYEk/PdDNVUQcP5xIzXDmuVTnPSIGAFYNQ5s/gEn8q Vr5VQIXEQRjHNpuJetYWUytNmm4uxWKX8p9bKZpGh94EAVgIj4+Ik5Z0FpD8o6EVLSGP McWZIDRVmBFeg3yMN9wGHdkbF+NHpQBnUHl2j2EnGzmw+/wKVBozM73uvonXhsvPFWq3 gy5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563898; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=qhG0lw5KlRBNwnqR+lID3/utnVv1YZhnHFw1MeFsVt0=; b=tYY9fiG0VkhKyuGz+oE3vIiS809HD/c+N/9Ys7iBjS+CyGF+CSR4w7D9tHxz+TKhWb pPYUls34Tin16HTrYKaO5CtWJE9ReALQ55d48RaJFgUymUC5wsse8lGzJOQshWAz9ysp pct+EV3Jw3y1iRNgm9+/smZBh8vNSKImwSDUHuVCvXhGMqEkOW2BMqmO3z3UzSv1Uutf VwWnmNu49YTBj/sLJv0N9LtCA5JnaV894ExYxPVaY6vHl/cc7O8p8hV8o23KGwMSOCqs 7aV5MGhUdGIEGQ3epJVuzz4yFXTJVH354AS99TSU+t5Km0CELIxcGtVGjSypQXYKyOop 9d4g== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563898; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=qhG0lw5KlRBNwnqR+lID3/utnVv1YZhnHFw1MeFsVt0=; b=SnLjOEIWOF3dJBgmgSGgEWMsmdoJJAPSwbSuqpWSfrQx5cI/cXBsfmuHABoNfFCDqG Bha0fJhbCqZ6L/LtuapHJxp2SruWGQriEkGQcbQF+KuA6h0/oSJIBz0Gu16RypFC5Ee4 aPk027v/nnOQLxXcg1eJxRm4oPygov9JWZAjZQCvcFa4RVo/2VbavwCnsBf80CqhWCr5 LC+NQ/u8AnnwawGN0czS/Lb0EbU6xTabLihK8peb93nJCOYp9AkW6sJ2W5xAm/QTyIAe u0hGt19MMQyg9bWr3l+6atuSOsj77bUnpWszzGhIvQ82TQGctCo+UlkqvseI34Pt6Egl iozg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 29/38] tools: change struct precopy_stats to precopy_stats_t Date: Tue, 1 Jun 2021 18:11:09 +0200 Message-Id: <20210601161118.18986-30-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This will help libxl_save_msgs_gen.pl to copy the struct as a region of mem= ory. No change in behavior intented. Signed-off-by: Olaf Hering --- tools/include/xensaverestore.h | 7 +++---- tools/libs/saverestore/common.h | 2 +- tools/libs/saverestore/save.c | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/include/xensaverestore.h b/tools/include/xensaverestore.h index 0410f0469e..dca0134605 100644 --- a/tools/include/xensaverestore.h +++ b/tools/include/xensaverestore.h @@ -23,18 +23,17 @@ #define XCFLAGS_DEBUG (1 << 1) =20 /* For save's precopy_policy(). */ -struct precopy_stats -{ +typedef struct { unsigned int iteration; unsigned long total_written; long dirty_count; /* -1 if unknown */ -}; +} precopy_stats_t; =20 /* * A precopy_policy callback may not be running in the same address * space as libxc an so precopy_stats is passed by value. */ -typedef int (*precopy_policy_t)(struct precopy_stats, void *); +typedef int (*precopy_policy_t)(precopy_stats_t, void *); =20 /* callbacks provided by xc_domain_save */ struct save_callbacks { diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 4218a8ecd6..cf8d6545e2 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -283,7 +283,7 @@ struct xc_sr_context size_t pages_sent; size_t overhead_sent; =20 - struct precopy_stats stats; + precopy_stats_t stats; =20 unsigned int nr_batch_pfns; unsigned long *deferred_pages; diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index b59cb069ed..523457eaba 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -489,7 +489,7 @@ static int update_progress_string(struct xc_sr_context = *ctx, char **str) #define SPP_MAX_ITERATIONS 5 #define SPP_TARGET_DIRTY_COUNT 50 =20 -static int simple_precopy_policy(struct precopy_stats stats, void *user) +static int simple_precopy_policy(precopy_stats_t stats, void *user) { return ((stats.dirty_count >=3D 0 && stats.dirty_count < SPP_TARGET_DIRTY_COUNT) || @@ -516,13 +516,13 @@ static int send_memory_live(struct xc_sr_context *ctx) precopy_policy_t precopy_policy =3D ctx->save.callbacks->precopy_polic= y; void *data =3D ctx->save.callbacks->data; =20 - struct precopy_stats *policy_stats; + precopy_stats_t *policy_stats; =20 rc =3D update_progress_string(ctx, &progress_str); if ( rc ) goto out; =20 - ctx->save.stats =3D (struct precopy_stats){ + ctx->save.stats =3D (precopy_stats_t){ .dirty_count =3D ctx->save.p2m_size, }; policy_stats =3D &ctx->save.stats; From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564248563934.5287581749268; Tue, 1 Jun 2021 09:17:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135069.251338 (Exim 4.92) (envelope-from ) id 1lo74v-0000GP-MV; Tue, 01 Jun 2021 16:17:17 +0000 Received: by outflank-mailman (output) from mailman id 135069.251338; Tue, 01 Jun 2021 16:17:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo74v-0000GD-Ip; Tue, 01 Jun 2021 16:17:17 +0000 Received: by outflank-mailman (input) for mailman id 135069; Tue, 01 Jun 2021 16:17:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70u-0005Ec-3o for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:13:08 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 14052265-3ec3-46ef-a819-c5198683c5e4; Tue, 01 Jun 2021 16:11:45 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBc1Ba (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:38 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 14052265-3ec3-46ef-a819-c5198683c5e4 ARC-Seal: i=1; a=rsa-sha256; t=1622563899; cv=none; d=strato.com; s=strato-dkim-0002; b=Nzzt+2JzYgcElHAvvU+QlBQIcLp433Kx2kvRxjzCmaxh4vGLV+IBGWpul7FPjRQgUp ExSTIaImPvhM2qc0wC+fAUm23xlgXu1hT39G2qHii5BTN5lnzbMUWfHQ30wQQ/8ZmSUG gqWRBaqik7yQRBF3K61FpUEOvVYcvMPojhx32fx4JH/by7fbgKOMKU9uj1V9SB54MU6h 7YWBGLbTfbdLg7K51ByMrW1BKqMOA1mKkCKAQHHLR6gvNEuzBwM1WocPsV0vL72MSO7I qoKvd8Sf31ed/pu7Dn1UAkay9MWOdlX8zd9bLNnpZGQ2ABT3ShzY7STxUdMIH1sIMwb3 ihIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563899; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=oEobMmPDeGkR5HKQsTMYf9poCJx2hGJ9mHWfmH/ZeOo=; b=eRlYMUhLv1SFTirRAn5jjC1lo61RJ9Hi2DcTjmEyK0y2Q5LHYpjnNS2P6uOzjvXwk7 LMLKASPuzbAMVBqNj86YpY7yT+LMmWXFgbnIqTWmidpgm+OraykJjVP4uC7xDlx9imwL wQOJjqr4Sgab5kx6cSPTrbIYi/iYyiZG1XUHF36TvypxWkhzvaLPjDC1ljHEtlbk05az GLknIgAM2tquzRUpfT1qgXPGX7TjChnay13sm/W4uuc/sBslxBMKOle6mgscczhQLLEW X4i35d+RcDTX2WTQI0smFTKy7jN1bFpU86VQFD4xrPx0jGw/T+n26IQcWMy4EdBxPOqh LR7Q== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563899; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=oEobMmPDeGkR5HKQsTMYf9poCJx2hGJ9mHWfmH/ZeOo=; b=N4ktv5IxWOYa/s3fjZBqMunV6MlGiILphSiu69DrwtxNOEY3GK+tY8ZxEhQJXjMFge leQvxASgSmHfGRHoHk7ze+m70aYb5Z3Dh71d3krEa4MLzp86ZYCSChmi5ukdjPRnxAr3 +BTml+Z7BUA9ZtAH1Viu2YKaE+qySr/VpgA7lePZLi6ohkKHqm+bN+Yiuiu1dQY2T8y+ qEhSY5pyhSG05pbP/bH/5UvvWKZKEd4q+yV31F176QMqi2cpif6KIUq1YQqSoFSgMyek EvSJXIsW1eZJsnNm+Uq8zgdall5x0mLJl9pVekmR8WxfdOsMKlYD5HJfTJXmaNm1BFIu 6hoQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v20210601 30/38] tools: add callback to libxl for precopy_policy and precopy_stats_t Date: Tue, 1 Jun 2021 18:11:10 +0200 Message-Id: <20210601161118.18986-31-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This duplicates simple_precopy_policy. To recap its purpose: - do up to 5 iterations of copying dirty domU memory to target, including the initial copying of all domU memory, excluding the final copying while the domU is suspended - do fewer iterations in case the domU dirtied less than 50 pages Take the opportunity to also move xen_pfn_t into qw(). Signed-off-by: Olaf Hering --- tools/libs/light/libxl_dom_save.c | 19 +++++++++++++++++++ tools/libs/light/libxl_internal.h | 2 ++ tools/libs/light/libxl_save_msgs_gen.pl | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/libs/light/libxl_dom_save.c b/tools/libs/light/libxl_dom= _save.c index 32e3cb5a13..3f3cff0342 100644 --- a/tools/libs/light/libxl_dom_save.c +++ b/tools/libs/light/libxl_dom_save.c @@ -373,6 +373,24 @@ int libxl__save_emulator_xenstore_data(libxl__domain_s= ave_state *dss, return rc; } =20 +static int libxl__domain_save_precopy_policy(precopy_stats_t stats, void *= user) +{ + libxl__save_helper_state *shs =3D user; + libxl__domain_save_state *dss =3D shs->caller_state; + STATE_AO_GC(dss->ao); + + LOGD(DEBUG, shs->domid, "iteration %u dirty_count %ld total_written %l= u", + stats.iteration, stats.dirty_count, stats.total_written); + if (stats.dirty_count >=3D 0 && stats.dirty_count < LIBXL_XGS_POLICY_T= ARGET_DIRTY_COUNT) + goto stop_copy; + if (stats.iteration >=3D LIBXL_XGS_POLICY_MAX_ITERATIONS) + goto stop_copy; + return XGS_POLICY_CONTINUE_PRECOPY; + +stop_copy: + return XGS_POLICY_STOP_AND_COPY; +} + /*----- main code for saving, in order of execution -----*/ =20 void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss) @@ -430,6 +448,7 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_= save_state *dss) callbacks->suspend =3D libxl__domain_suspend_callback; =20 callbacks->switch_qemu_logdirty =3D libxl__domain_suspend_common_switc= h_qemu_logdirty; + callbacks->precopy_policy =3D libxl__domain_save_precopy_policy; =20 dss->sws.ao =3D dss->ao; dss->sws.dss =3D dss; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 8af075291a..069c35452d 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -125,6 +125,8 @@ #define DOMID_XS_PATH "domid" #define PVSHIM_BASENAME "xen-shim" #define PVSHIM_CMDLINE "pv-shim console=3Dxen,pv" +#define LIBXL_XGS_POLICY_MAX_ITERATIONS 5 +#define LIBXL_XGS_POLICY_TARGET_DIRTY_COUNT 50 =20 /* Size macros. */ #define __AC(X,Y) (X##Y) diff --git a/tools/libs/light/libxl_save_msgs_gen.pl b/tools/libs/light/lib= xl_save_msgs_gen.pl index f263ee01bb..ab55c81644 100755 --- a/tools/libs/light/libxl_save_msgs_gen.pl +++ b/tools/libs/light/libxl_save_msgs_gen.pl @@ -23,6 +23,7 @@ our @msgs =3D ( STRING doing_what), 'unsigned long', 'done', 'unsigned long', 'total'] ], + [ 'scxW', "precopy_policy", ['precopy_stats_t', 'stats'] ], [ 'srcxA', "suspend", [] ], [ 'srcxA', "postcopy", [] ], [ 'srcxA', "checkpoint", [] ], @@ -142,7 +143,7 @@ static void bytes_put(unsigned char *const buf, int *le= n, =20 END =20 -foreach my $simpletype (qw(int uint16_t uint32_t unsigned), 'unsigned long= ', 'xen_pfn_t') { +foreach my $simpletype (qw(int uint16_t uint32_t unsigned precopy_stats_t = xen_pfn_t), 'unsigned long') { my $typeid =3D typeid($simpletype); $out_body{'callout'} .=3D < Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564009947700.0429680181883; Tue, 1 Jun 2021 09:13:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135020.251206 (Exim 4.92) (envelope-from ) id 1lo715-0000iu-NK; Tue, 01 Jun 2021 16:13:19 +0000 Received: by outflank-mailman (output) from mailman id 135020.251206; Tue, 01 Jun 2021 16:13:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo715-0000in-KD; Tue, 01 Jun 2021 16:13:19 +0000 Received: by outflank-mailman (input) for mailman id 135020; Tue, 01 Jun 2021 16:13:18 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70M-0005X1-18 for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:34 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 00302e53-7264-4ccf-be6f-c370c8624d65; Tue, 01 Jun 2021 16:11:45 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBd1Bb (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:39 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 00302e53-7264-4ccf-be6f-c370c8624d65 ARC-Seal: i=1; a=rsa-sha256; t=1622563899; cv=none; d=strato.com; s=strato-dkim-0002; b=hGephZD7UqHQtWANDp+Oel53eEzNAhaUGp/dNZuz4qmGEsyd1ZYeAmPl3I76m99/U6 u9dvxuflsQOFP0vxFTJTRFYRteU++Z5zWY969jj/lCx5Jb6zekj66EvCWDJRjYJU6mj2 +M5mmYTPmUOzu05llwonv1XmKuSrBJXUt/3VFIMXxdd+455/ScYu85BVszO9FVkTJ2tP KdhDpMNHBPaH6Chk8D+BzvDxL6bEuTYH3kC6AuNA0DB5/2UrXwAvJHHbBZqO19Gyv9j7 0G29fv+dPnmTBdoBj23ZBIYI14af/hPmm06m6/uz+FsrXMUoIeedTx0BGTnGPgR3dD9I OwZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563899; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=43lDIDUwBH095VtVkTuqmuE4BK9API0PDHgwKMKg2GQ=; b=ctj7hFOJX3/WbRdkNZt+ZDsuhnBRoNyLVW8TeorpBWEg5JjPfF3jcs3+qLSr8gwHOT EneRoF239La7oXtL/PmQm3z3FjZIjkiC1hlKLScCLBPa0sK8phX5g4tsAL8GMJ8lSqIC nsV9it15egNJ6j+StsqZcbTl24yAFpL1+E22lcqmZZCwtHOLsLlMuuOvR0P6UZBnvNnz KG9/rFBzOrEh23nLVKsrljjhoWo8Ydq6qx5bJ98cLLiKJIj+8zvoyG9e8CIeszSXBf9y BIrIRSdfFVhpXyq39njyS+Cl0jlatZn5idWQOLFsxV/LPb6DJDcms1DSRsMeQX2PBpq+ YOIw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563899; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=43lDIDUwBH095VtVkTuqmuE4BK9API0PDHgwKMKg2GQ=; b=fw03lZoWf6At1jJTOW+AnPunAYfhTFxjvUfl2wHinBUJl1pw6D2/fXloeVmF5b+G8L HgcNoLysmbrYmB6WwmGk0L1qZJs5MHgWr6r+wQuq6TlOH6j60C4OplVLi5uKyr7cVtXm 1hFYKzpR7ATlTbmaW/lI9IpEGZEmb2QTXlNyswZkGeH4taEbULkkFVNOWW29S6ne2OdU o40HKw+//fDWytQLNe4KYveueocVd2fLgJKNTYw+1aC9RsdLL1xpquOEYq/z7evsHppq EtDhz50UKUzbFsqM5bpMYq3lPVLfqXqzk8AtrfkEYCDfB65w1AztK3Bk2uaoUAdypfa6 o8xQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v20210601 31/38] tools: add --max_iters to libxl_domain_suspend Date: Tue, 1 Jun 2021 18:11:11 +0200 Message-Id: <20210601161118.18986-32-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Migrating a large, and potentially busy, domU will take more time than neccessary due to excessive number of copying iterations. Allow to host admin to control the number of iterations which copy cumulated domU dirty pages to the target host. The default remains 5, which means one initial iteration to copy the entire domU memory, and up to 4 additional iterations to copy dirty memory from the still running domU. After the given number of iterations the domU is suspended, remaining dirty memory is copied and the domU is finally moved to the target host. This patch adjusts xl(1) and the libxl API. External users check LIBXL_HAVE_DOMAIN_SUSPEND_PROPS for the availibility of the new .max_iters property. Signed-off-by: Olaf Hering --- docs/man/xl.1.pod.in | 4 ++++ tools/include/libxl.h | 1 + tools/libs/light/libxl_dom_save.c | 2 +- tools/libs/light/libxl_domain.c | 1 + tools/libs/light/libxl_internal.h | 1 + tools/xl/xl_cmdtable.c | 3 ++- tools/xl/xl_migrate.c | 10 +++++++++- 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index ed3f4dee1e..b13e09c0ee 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -496,6 +496,10 @@ such that it will be identical on the destination host= , unless that configuration is overridden using the B<-C> option. Note that it is not possible to use this option for a 'localhost' migration. =20 +=3Ditem B<--max_iters> I + +Number of copy iterations before final suspend+move (default: 5) + =3Dback =20 =3Ditem B [I] I I diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 9a4d7514ed..bf77da0524 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1714,6 +1714,7 @@ static inline int libxl_retrieve_domain_configuration= _0x041200( =20 typedef struct { uint32_t flags; /* LIBXL_SUSPEND_* */ + uint32_t max_iters; } libxl_domain_suspend_props; #define LIBXL_SUSPEND_DEBUG 1 #define LIBXL_SUSPEND_LIVE 2 diff --git a/tools/libs/light/libxl_dom_save.c b/tools/libs/light/libxl_dom= _save.c index 3f3cff0342..938c0127f3 100644 --- a/tools/libs/light/libxl_dom_save.c +++ b/tools/libs/light/libxl_dom_save.c @@ -383,7 +383,7 @@ static int libxl__domain_save_precopy_policy(precopy_st= ats_t stats, void *user) stats.iteration, stats.dirty_count, stats.total_written); if (stats.dirty_count >=3D 0 && stats.dirty_count < LIBXL_XGS_POLICY_T= ARGET_DIRTY_COUNT) goto stop_copy; - if (stats.iteration >=3D LIBXL_XGS_POLICY_MAX_ITERATIONS) + if (stats.iteration >=3D dss->max_iters) goto stop_copy; return XGS_POLICY_CONTINUE_PRECOPY; =20 diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 45e0c57c3a..612d3dc4ea 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -527,6 +527,7 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid= , int fd, dss->domid =3D domid; dss->fd =3D fd; dss->type =3D type; + dss->max_iters =3D props->max_iters ?: LIBXL_XGS_POLICY_MAX_ITERATIONS; dss->live =3D props->flags & LIBXL_SUSPEND_LIVE; dss->debug =3D props->flags & LIBXL_SUSPEND_DEBUG; dss->checkpointed_stream =3D LIBXL_CHECKPOINTED_STREAM_NONE; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 069c35452d..82b9dca5a0 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3641,6 +3641,7 @@ struct libxl__domain_save_state { int live; int debug; int checkpointed_stream; + uint32_t max_iters; const libxl_domain_remus_info *remus; /* private */ int rc; diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 6fd18856c0..8f8fa72760 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -174,7 +174,8 @@ const struct cmd_spec cmd_table[] =3D { " of the domain.\n" "--debug Verify transferred domU page data.\n" "-p Do not unpause domain after migrating it.\n" - "-D Preserve the domain id" + "-D Preserve the domain id\n" + "--max_iters N Number of copy iterations before final stop+move" }, { "restore", &main_restore, 0, 1, diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c index 144890924f..af117d4d56 100644 --- a/tools/xl/xl_migrate.c +++ b/tools/xl/xl_migrate.c @@ -178,6 +178,7 @@ static void migrate_do_preamble(int send_fd, int recv_f= d, pid_t child, =20 static void migrate_domain(uint32_t domid, int preserve_domid, const char *rune, int debug, + uint32_t max_iters, const char *override_config_file) { pid_t child =3D -1; @@ -189,6 +190,7 @@ static void migrate_domain(uint32_t domid, int preserve= _domid, int config_len; libxl_domain_suspend_props props =3D { .flags =3D LIBXL_SUSPEND_LIVE, + .max_iters =3D max_iters, }; =20 save_domain_core_begin(domid, preserve_domid, override_config_file, @@ -542,8 +544,10 @@ int main_migrate(int argc, char **argv) char *host; int opt, daemonize =3D 1, monitor =3D 1, debug =3D 0, pause_after_migr= ation =3D 0; int preserve_domid =3D 0; + uint32_t max_iters =3D 0; static struct option opts[] =3D { {"debug", 0, 0, 0x100}, + {"max_iters", 1, 0, 0x101}, {"live", 0, 0, 0x200}, COMMON_LONG_OPTS }; @@ -571,6 +575,9 @@ int main_migrate(int argc, char **argv) case 0x100: /* --debug */ debug =3D 1; break; + case 0x101: /* --max_iters */ + max_iters =3D atoi(optarg); + break; case 0x200: /* --live */ /* ignored for compatibility with xm */ break; @@ -605,7 +612,8 @@ int main_migrate(int argc, char **argv) pause_after_migration ? " -p" : ""); } =20 - migrate_domain(domid, preserve_domid, rune, debug, config_filename); + migrate_domain(domid, preserve_domid, rune, debug, + max_iters, config_filename); return EXIT_SUCCESS; } =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564693408823.3497959269879; Tue, 1 Jun 2021 09:24:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135150.251350 (Exim 4.92) (envelope-from ) id 1lo7Bt-0002OK-Fp; Tue, 01 Jun 2021 16:24:29 +0000 Received: by outflank-mailman (output) from mailman id 135150.251350; Tue, 01 Jun 2021 16:24:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo7Bt-0002O6-CX; Tue, 01 Jun 2021 16:24:29 +0000 Received: by outflank-mailman (input) for mailman id 135150; Tue, 01 Jun 2021 16:24:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71E-0005Ec-4T for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:13:28 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 48fa1829-73d1-48ce-92c9-cdc6cf16f212; Tue, 01 Jun 2021 16:11:47 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBd1Bc (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:39 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 48fa1829-73d1-48ce-92c9-cdc6cf16f212 ARC-Seal: i=1; a=rsa-sha256; t=1622563900; cv=none; d=strato.com; s=strato-dkim-0002; b=q4QpgJ61zpOybvUvhUr09ZmeltRRHXUJPMawiTvc9JFN5FTIFY5oP+64k6xDO1D0s5 UV04M/mB5Hi/+GidhhR4hIyGNA/HRQvyAdRue4BOPs+/PR96QxUyLbSNHvqdr9hL9GQu EFAU9dhkSJIbLNjkMaPBE1yd4XHuax7yhS5ThiG+xqBgMbjoqQeFFifH43qJSc9HnguL 96nBvelGvVr27kzdU39w7y0s0nQivTOHmVwVKCyPdLi31+n5kgoNSmmJ8BJiJinuvO8x kKMaeAGIvjreAuP2dQogevYgTNgdMN2LH7J6yvucvfDOFNcYkkm+q0sTeUyOYsmv/3Tx qj4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563900; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=z1lmf0xePHwyesyqjBFkPKIgt7yTBfVYJQlZCg92Pig=; b=Ui/N5dcIi30X7j3unjmJJR0yBmG7TDkeBhos7LZDGabwet4KhNstuaiNwJyRVPeV8/ ZHi6YMufr7c1fyUoohYHo9FvJPMmxZGuJSSuWj5u3lv0Bczv5Wc3/max9djUTSJFmIhA uGZnH7y6swi4ePLz9u0JGFnPsz57gvhatxVZygXmuobmmES1YO7MTkBJ5QNuLy+r5MQ2 7KGuss9KN2PMo9FmC9ZU5KXBeuJeWQfxahLi9fQO6d5LSIjwa9xFrEpgIY0HVOUn6Sys 4/2SxEOlLVFKZBJY53UhA8NF4tjlXgCa3w8q7DiUOnHh2rtJ/07fA5UwhsGl97XLpQ/l cQAQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563900; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=z1lmf0xePHwyesyqjBFkPKIgt7yTBfVYJQlZCg92Pig=; b=mIespZvsQbeG2kuTMSr5Pwx4UR6KJeERxOoCrGqGTYDkxK5mYXRlv2tiwqH9WGDvum Xj0bWpAhyLRMl2V9wh58oktUBwOahEDzP8w/bRVe17JVUjVmeBTd59UquYMawBYPnDIn fKaQKDg3ixisNwzc5kwaYSxrT6cY4XSCJ4gQoNGvEQLCDN9qsXhDfTT7+HBO3DIDnlEj BwY7u4lU8/9BHm0yFFzw3WyT6+tDznvZ+sbIWO8KX77uq8oNeSdoV2NeRSLIyOZMGGRT K8br9V/w9fErm11F7lIxS1F+rKYk7t9lcy9iKTtV09hWa/vZioRHQQYNb4aVL8gbnyL/ KGzg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v20210601 32/38] tools: add --min_remaining to libxl_domain_suspend Date: Tue, 1 Jun 2021 18:11:12 +0200 Message-Id: <20210601161118.18986-33-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The decision to stop+move a domU to the new host must be based on two facto= rs: - the available network bandwidth for the migration stream - the maximum time a workload within a domU can be savely suspended Both values define how many dirty pages a workload may produce prior the final stop+move. The default value of 50 pages is much too low with todays network bandwidth= s. On an idle 1GiB link these 200K will be transferred within ~2ms. Give the admin a knob to adjust the point when the final stop+move will be done, so he can base this decision on his own needs. This patch adjusts xl(1) and the libxl API. External users check LIBXL_HAVE_DOMAIN_SUSPEND_PROPS for the availibility of the new .min_remaining property. Signed-off-by: Olaf Hering --- docs/man/xl.1.pod.in | 8 ++++++++ tools/include/libxl.h | 1 + tools/libs/light/libxl_dom_save.c | 2 +- tools/libs/light/libxl_domain.c | 1 + tools/libs/light/libxl_internal.h | 1 + tools/xl/xl_cmdtable.c | 23 ++++++++++++----------- tools/xl/xl_migrate.c | 9 ++++++++- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index b13e09c0ee..43609f6cdd 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -500,6 +500,14 @@ possible to use this option for a 'localhost' migratio= n. =20 Number of copy iterations before final suspend+move (default: 5) =20 +=3Ditem B<--min_remaing> I + +Number of remaining dirty pages. If the number of dirty pages drops that +low, the guest is suspended and the domU will finally be moved to I. + +This allows the host admin to control for how long the domU will likely +be suspended during transit. + =3Dback =20 =3Ditem B [I] I I diff --git a/tools/include/libxl.h b/tools/include/libxl.h index bf77da0524..28d70b1078 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1715,6 +1715,7 @@ static inline int libxl_retrieve_domain_configuration= _0x041200( typedef struct { uint32_t flags; /* LIBXL_SUSPEND_* */ uint32_t max_iters; + uint32_t min_remaining; } libxl_domain_suspend_props; #define LIBXL_SUSPEND_DEBUG 1 #define LIBXL_SUSPEND_LIVE 2 diff --git a/tools/libs/light/libxl_dom_save.c b/tools/libs/light/libxl_dom= _save.c index 938c0127f3..ad5df89b2c 100644 --- a/tools/libs/light/libxl_dom_save.c +++ b/tools/libs/light/libxl_dom_save.c @@ -381,7 +381,7 @@ static int libxl__domain_save_precopy_policy(precopy_st= ats_t stats, void *user) =20 LOGD(DEBUG, shs->domid, "iteration %u dirty_count %ld total_written %l= u", stats.iteration, stats.dirty_count, stats.total_written); - if (stats.dirty_count >=3D 0 && stats.dirty_count < LIBXL_XGS_POLICY_T= ARGET_DIRTY_COUNT) + if (stats.dirty_count >=3D 0 && stats.dirty_count < dss->min_remaining) goto stop_copy; if (stats.iteration >=3D dss->max_iters) goto stop_copy; diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 612d3dc4ea..ae4dc9ad01 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -528,6 +528,7 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid= , int fd, dss->fd =3D fd; dss->type =3D type; dss->max_iters =3D props->max_iters ?: LIBXL_XGS_POLICY_MAX_ITERATIONS; + dss->min_remaining =3D props->min_remaining ?: LIBXL_XGS_POLICY_TARGET= _DIRTY_COUNT; dss->live =3D props->flags & LIBXL_SUSPEND_LIVE; dss->debug =3D props->flags & LIBXL_SUSPEND_DEBUG; dss->checkpointed_stream =3D LIBXL_CHECKPOINTED_STREAM_NONE; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 82b9dca5a0..63028586fe 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3642,6 +3642,7 @@ struct libxl__domain_save_state { int debug; int checkpointed_stream; uint32_t max_iters; + uint32_t min_remaining; const libxl_domain_remus_info *remus; /* private */ int rc; diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 8f8fa72760..acb84e3486 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -165,17 +165,18 @@ const struct cmd_spec cmd_table[] =3D { &main_migrate, 0, 1, "Migrate a domain to another host", "[options] ", - "-h Print this help.\n" - "-C Send instead of config file from creation.= \n" - "-s Use instead of ssh. String will be pa= ssed\n" - " to sh. If empty, run instead of ssh x= l\n" - " migrate-receive [-d -e]\n" - "-e Do not wait in the background (on ) for the d= eath\n" - " of the domain.\n" - "--debug Verify transferred domU page data.\n" - "-p Do not unpause domain after migrating it.\n" - "-D Preserve the domain id\n" - "--max_iters N Number of copy iterations before final stop+move" + "-h Print this help.\n" + "-C Send instead of config file from creatio= n.\n" + "-s Use instead of ssh. String will be = passed\n" + " to sh. If empty, run instead of ssh = xl\n" + " migrate-receive [-d -e]\n" + "-e Do not wait in the background (on ) for the= death\n" + " of the domain.\n" + "--debug Verify transferred domU page data.\n" + "-p Do not unpause domain after migrating it.\n" + "-D Preserve the domain id\n" + "--max_iters N Number of copy iterations before final stop+move\= n" + "--min_remaining N Number of remaining dirty pages before final stop= +move" }, { "restore", &main_restore, 0, 1, diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c index af117d4d56..14feb2b7ec 100644 --- a/tools/xl/xl_migrate.c +++ b/tools/xl/xl_migrate.c @@ -179,6 +179,7 @@ static void migrate_do_preamble(int send_fd, int recv_f= d, pid_t child, static void migrate_domain(uint32_t domid, int preserve_domid, const char *rune, int debug, uint32_t max_iters, + uint32_t min_remaining, const char *override_config_file) { pid_t child =3D -1; @@ -191,6 +192,7 @@ static void migrate_domain(uint32_t domid, int preserve= _domid, libxl_domain_suspend_props props =3D { .flags =3D LIBXL_SUSPEND_LIVE, .max_iters =3D max_iters, + .min_remaining =3D min_remaining, }; =20 save_domain_core_begin(domid, preserve_domid, override_config_file, @@ -545,9 +547,11 @@ int main_migrate(int argc, char **argv) int opt, daemonize =3D 1, monitor =3D 1, debug =3D 0, pause_after_migr= ation =3D 0; int preserve_domid =3D 0; uint32_t max_iters =3D 0; + uint32_t min_remaining =3D 0; static struct option opts[] =3D { {"debug", 0, 0, 0x100}, {"max_iters", 1, 0, 0x101}, + {"min_remaining", 1, 0, 0x102}, {"live", 0, 0, 0x200}, COMMON_LONG_OPTS }; @@ -578,6 +582,9 @@ int main_migrate(int argc, char **argv) case 0x101: /* --max_iters */ max_iters =3D atoi(optarg); break; + case 0x102: /* --min_remaining */ + min_remaining =3D atoi(optarg); + break; case 0x200: /* --live */ /* ignored for compatibility with xm */ break; @@ -613,7 +620,7 @@ int main_migrate(int argc, char **argv) } =20 migrate_domain(domid, preserve_domid, rune, debug, - max_iters, config_filename); + max_iters, min_remaining, config_filename); return EXIT_SUCCESS; } =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564052355827.2545130216346; Tue, 1 Jun 2021 09:14:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135042.251294 (Exim 4.92) (envelope-from ) id 1lo71l-0004iC-5g; Tue, 01 Jun 2021 16:14:01 +0000 Received: by outflank-mailman (output) from mailman id 135042.251294; Tue, 01 Jun 2021 16:14:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71l-0004hX-1K; Tue, 01 Jun 2021 16:14:01 +0000 Received: by outflank-mailman (input) for mailman id 135042; Tue, 01 Jun 2021 16:14:00 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70b-0005X1-1Q for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:49 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b1b21753-71d3-4abf-ae18-17f60e97b2ba; Tue, 01 Jun 2021 16:11:48 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBe1Bd (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:40 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b1b21753-71d3-4abf-ae18-17f60e97b2ba ARC-Seal: i=1; a=rsa-sha256; t=1622563900; cv=none; d=strato.com; s=strato-dkim-0002; b=i+C0lQTgDG0B7xQdUrq1nGARbLlZYl/nskb/IwQqsimOXTONDE4qYhKz0EIZRSeyGI kPOf2EHOxTlezAkGdwnYfP+CeKb91xfiO84YmOpM50zFgiHUGtV+hsATK882h0DXLwVL Lz5Tk+cmXopFFVsMgIm/Eo6fBX+Kl9TK3KIq8gJmN9UhMf/QbRx0ohkD/RPcZlktqw55 AJKU8pNZb3iqoJ4kwXjT8uUMDbVgjQ96UlYBhVEJuCKQq3EjVPUV7JIOiM4sStSNYtbb FcBT8EoTt1xW+IwKuhYnyUEeFgWPhengL+5LXTJLKR+fHmps7fd0gw7B286Z/xm4Jqeb UoVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563900; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=yHDLzQ8w0aK0NM0b+OJIaVk/C7sbn6MbRiUz15zozj8=; b=d1xKl9YT8gYggHF5Kk4WO0b/XgA5dzP7xLE7XBNmgBHFLQ/qTdP3P8ueLlMSgIlP83 MfkfO/b+BqIBN6v9h3/jFtKF/ZEwez+4+Syo5Z12ehaWT2UGRCy09AAwceXPtSCbmQbE ZUbLDjmIOatdcAmz2PD5ytZgvPP4QyZgn3T+BmX4zwmmU25fdRyjfiovRiCH5BJsDNvh MZU6u3k0FiGQLC3OP4XhBqsGG5c+INKdQzfTPJtkEZYhYCY5fplppUeGT2K5/tq9cTvY CTn1l/ETDXRM96seNcMDcfwogR9kAJLfZ6xMvwG0+/tWmi59nP5JxDKhx3wK9bHarIXv ieuQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563900; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=yHDLzQ8w0aK0NM0b+OJIaVk/C7sbn6MbRiUz15zozj8=; b=r9kc6tUP5PACoqGznsVAKLelvJDqMmOq9/jpHmb6tX7eUOR1APn7wPVAzU2spubTo0 d3H6+T7e1lFZP9IqvP+qmaVf0TNRjlImB2OeTyqPORuS0il+wXU/xHUgm6jVCBt9ScCV Q62bdvENTBdIZmNXQbtcD4Ra60HRrl8OaekaFXaL44WxvHOaKn9dWPDJtd230oaVMOTt wtAwWWmhzgM+wHK/0cLRckzTFPK5LOs6lnXuHCihdD0mEI3F/wG7ng8yJ5yhRZO5XeMo R9kR2m0N/Lw4T2cpJ7E2loAmfCBxu92g0MjTltSEHQeC0Gxh5reugUuTa2bwnIyoeGJe D2sA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v20210601 33/38] tools: add --abort_if_busy to libxl_domain_suspend Date: Tue, 1 Jun 2021 18:11:13 +0200 Message-Id: <20210601161118.18986-34-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Provide a knob to the host admin to abort the live migration of a running domU if the downtime during final transit will be too long for the workload within domU. Adjust error reporting. Add ERROR_MIGRATION_ABORTED to allow callers of libxl_domain_suspend to distinguish between errors and the requested constraint. Adjust precopy_policy to simplify reporting of remaining dirty pages. The loop in send_memory_live populates ->dirty_count in a different place than ->iteration. Let it proceeed one more time to provide the desired information before leaving the loop. This patch adjusts xl(1) and the libxl API. External users check LIBXL_HAVE_DOMAIN_SUSPEND_PROPS for the availibility of the new .abort_if_busy property. Signed-off-by: Olaf Hering --- docs/man/xl.1.pod.in | 8 +++++++ tools/include/libxl.h | 1 + tools/libs/light/libxl_dom_save.c | 7 ++++++- tools/libs/light/libxl_domain.c | 1 + tools/libs/light/libxl_internal.h | 2 ++ tools/libs/light/libxl_stream_write.c | 9 +++++++- tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_cmdtable.c | 6 +++++- tools/xl/xl_migrate.c | 30 ++++++++++++++++++++------- 9 files changed, 55 insertions(+), 10 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index 43609f6cdd..b258d56ab6 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -508,6 +508,14 @@ low, the guest is suspended and the domU will finally = be moved to I. This allows the host admin to control for how long the domU will likely be suspended during transit. =20 +=3Ditem B<--abort_if_busy> + +Abort migration instead of doing final suspend/move/resume if the +guest produced more than I dirty pages during th number +of I iterations. +This avoids long periods of time where the guest is suspended, which +may confuse the workload within domU. + =3Dback =20 =3Ditem B [I] I I diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 28d70b1078..cc056ed627 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1719,6 +1719,7 @@ typedef struct { } libxl_domain_suspend_props; #define LIBXL_SUSPEND_DEBUG 1 #define LIBXL_SUSPEND_LIVE 2 +#define LIBXL_SUSPEND_ABORT_IF_BUSY 4 =20 int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, libxl_domain_suspend_props *props, diff --git a/tools/libs/light/libxl_dom_save.c b/tools/libs/light/libxl_dom= _save.c index ad5df89b2c..1999a8997f 100644 --- a/tools/libs/light/libxl_dom_save.c +++ b/tools/libs/light/libxl_dom_save.c @@ -383,11 +383,16 @@ static int libxl__domain_save_precopy_policy(precopy_= stats_t stats, void *user) stats.iteration, stats.dirty_count, stats.total_written); if (stats.dirty_count >=3D 0 && stats.dirty_count < dss->min_remaining) goto stop_copy; - if (stats.iteration >=3D dss->max_iters) + if (stats.dirty_count >=3D 0 && stats.iteration >=3D dss->max_iters) goto stop_copy; return XGS_POLICY_CONTINUE_PRECOPY; =20 stop_copy: + if (dss->abort_if_busy) + { + dss->remaining_dirty_pages =3D stats.dirty_count; + return XGS_POLICY_ABORT; + } return XGS_POLICY_STOP_AND_COPY; } =20 diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index ae4dc9ad01..913653bd76 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -529,6 +529,7 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid= , int fd, dss->type =3D type; dss->max_iters =3D props->max_iters ?: LIBXL_XGS_POLICY_MAX_ITERATIONS; dss->min_remaining =3D props->min_remaining ?: LIBXL_XGS_POLICY_TARGET= _DIRTY_COUNT; + dss->abort_if_busy =3D props->flags & LIBXL_SUSPEND_ABORT_IF_BUSY; dss->live =3D props->flags & LIBXL_SUSPEND_LIVE; dss->debug =3D props->flags & LIBXL_SUSPEND_DEBUG; dss->checkpointed_stream =3D LIBXL_CHECKPOINTED_STREAM_NONE; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 63028586fe..7453a3aa7b 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3640,9 +3640,11 @@ struct libxl__domain_save_state { libxl_domain_type type; int live; int debug; + int abort_if_busy; int checkpointed_stream; uint32_t max_iters; uint32_t min_remaining; + long remaining_dirty_pages; const libxl_domain_remus_info *remus; /* private */ int rc; diff --git a/tools/libs/light/libxl_stream_write.c b/tools/libs/light/libxl= _stream_write.c index 634f3240d1..1ab3943f3e 100644 --- a/tools/libs/light/libxl_stream_write.c +++ b/tools/libs/light/libxl_stream_write.c @@ -344,11 +344,18 @@ void libxl__xc_domain_save_done(libxl__egc *egc, void= *dss_void, goto err; =20 if (retval) { + if (dss->remaining_dirty_pages) { + LOGD(NOTICE, dss->domid, "saving domain: aborted," + " %ld remaining dirty pages.", dss->remaining_dirty_pages= ); + } else { LOGEVD(ERROR, errnoval, dss->domid, "saving domain: %s", dss->dsps.guest_responded ? "domain responded to suspend request" : "domain did not respond to suspend request"); - if (!dss->dsps.guest_responded) + } + if (dss->remaining_dirty_pages) + rc =3D ERROR_MIGRATION_ABORTED; + else if(!dss->dsps.guest_responded) rc =3D ERROR_GUEST_TIMEDOUT; else if (dss->rc) rc =3D dss->rc; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index f45adddab0..b91769ee10 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -76,6 +76,7 @@ libxl_error =3D Enumeration("error", [ (-30, "QMP_DEVICE_NOT_ACTIVE"), # a device has failed to be become act= ive (-31, "QMP_DEVICE_NOT_FOUND"), # the requested device has not been fou= nd (-32, "QEMU_API"), # QEMU's replies don't contains expected members + (-33, "MIGRATION_ABORTED"), ], value_namespace =3D "") =20 libxl_domain_type =3D Enumeration("domain_type", [ diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index acb84e3486..6c9de3bdec 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -176,7 +176,11 @@ const struct cmd_spec cmd_table[] =3D { "-p Do not unpause domain after migrating it.\n" "-D Preserve the domain id\n" "--max_iters N Number of copy iterations before final stop+move\= n" - "--min_remaining N Number of remaining dirty pages before final stop= +move" + "--min_remaining N Number of remaining dirty pages before final stop= +move\n" + "--abort_if_busy Abort migration instead of doing final stop+move,= \n" + " if the number of dirty pages is higher than \n" + " after iterations. Otherwise the amoun= t of memory\n" + " to be transfered would exceed maximum allowed dom= U downtime." }, { "restore", &main_restore, 0, 1, diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c index 14feb2b7ec..f523746e5b 100644 --- a/tools/xl/xl_migrate.c +++ b/tools/xl/xl_migrate.c @@ -177,7 +177,7 @@ static void migrate_do_preamble(int send_fd, int recv_f= d, pid_t child, } =20 static void migrate_domain(uint32_t domid, int preserve_domid, - const char *rune, int debug, + const char *rune, int debug, int abort_if_busy, uint32_t max_iters, uint32_t min_remaining, const char *override_config_file) @@ -213,14 +213,20 @@ static void migrate_domain(uint32_t domid, int preser= ve_domid, =20 if (debug) props.flags |=3D LIBXL_SUSPEND_DEBUG; + if (abort_if_busy) + props.flags |=3D LIBXL_SUSPEND_ABORT_IF_BUSY; rc =3D libxl_domain_suspend(ctx, domid, send_fd, &props, NULL); if (rc) { fprintf(stderr, "migration sender: libxl_domain_suspend failed" " (rc=3D%d)\n", rc); - if (rc =3D=3D ERROR_GUEST_TIMEDOUT) - goto failed_suspend; - else - goto failed_resume; + switch (rc) { + case ERROR_GUEST_TIMEDOUT: + goto failed_suspend; + case ERROR_MIGRATION_ABORTED: + goto failed_busy; + default: + goto failed_resume; + } } =20 //fprintf(stderr, "migration sender: Transfer complete.\n"); @@ -302,6 +308,12 @@ static void migrate_domain(uint32_t domid, int preserv= e_domid, fprintf(stderr, "Migration failed, failed to suspend at sender.\n"); exit(EXIT_FAILURE); =20 + failed_busy: + close(send_fd); + migration_child_report(recv_fd); + fprintf(stderr, "Migration aborted as requested, domain is too busy.\n= "); + exit(EXIT_FAILURE); + failed_resume: close(send_fd); migration_child_report(recv_fd); @@ -545,13 +557,14 @@ int main_migrate(int argc, char **argv) char *rune =3D NULL; char *host; int opt, daemonize =3D 1, monitor =3D 1, debug =3D 0, pause_after_migr= ation =3D 0; - int preserve_domid =3D 0; + int preserve_domid =3D 0, abort_if_busy =3D 0; uint32_t max_iters =3D 0; uint32_t min_remaining =3D 0; static struct option opts[] =3D { {"debug", 0, 0, 0x100}, {"max_iters", 1, 0, 0x101}, {"min_remaining", 1, 0, 0x102}, + {"abort_if_busy", 0, 0, 0x103}, {"live", 0, 0, 0x200}, COMMON_LONG_OPTS }; @@ -585,6 +598,9 @@ int main_migrate(int argc, char **argv) case 0x102: /* --min_remaining */ min_remaining =3D atoi(optarg); break; + case 0x103: /* --abort_if_busy */ + abort_if_busy =3D 1; + break; case 0x200: /* --live */ /* ignored for compatibility with xm */ break; @@ -619,7 +635,7 @@ int main_migrate(int argc, char **argv) pause_after_migration ? " -p" : ""); } =20 - migrate_domain(domid, preserve_domid, rune, debug, + migrate_domain(domid, preserve_domid, rune, debug, abort_if_busy, max_iters, min_remaining, config_filename); return EXIT_SUCCESS; } From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564749299715.1759671272072; Tue, 1 Jun 2021 09:25:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135225.251383 (Exim 4.92) (envelope-from ) id 1lo7D0-0004KE-Fd; Tue, 01 Jun 2021 16:25:38 +0000 Received: by outflank-mailman (output) from mailman id 135225.251383; Tue, 01 Jun 2021 16:25:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo7D0-0004K7-CI; Tue, 01 Jun 2021 16:25:38 +0000 Received: by outflank-mailman (input) for mailman id 135225; Tue, 01 Jun 2021 16:25:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70z-0005Ec-3p for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:13:13 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.103]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8196cfa2-eb0f-448e-8912-37d6a2321964; Tue, 01 Jun 2021 16:11:45 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBe1Be (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:40 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8196cfa2-eb0f-448e-8912-37d6a2321964 ARC-Seal: i=1; a=rsa-sha256; t=1622563900; cv=none; d=strato.com; s=strato-dkim-0002; b=K0Zx3LsjNuvmX6bb/7E8krJY0h3wiRmnd1Iea4Mn7/bvNh47ZNrEJFxkHe2izUzrXe +rwp5gHhr76tMqvWqJqJd0y99aZgsM1/xnRbTcSuzWUJ5v7wOW6hkW1DPvyBbnRHohOj Gytiyp7Ext008MkAWiOs9qNNV1ggeTwyfZfJ4AIIUU2Ui53tNvRSbSXvck/jX6UxB821 DFrU/IziJg6ICyDO8Mzq8XYVk654MmPq0I4es24ug7WoGeG4MHRfCSQLesL9fvbOR064 UyNcAiZhCOwxrVL8iNU5DyrRU6I0eIOBZq2uhCsR7jbJdT+SB1uzngSKYIrNM3zTjI4z kjSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563900; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=aRD7fh9RvdtKI1U0FLi3WzkFwBE/k6ib8HdQNOs79bo=; b=CIv1T1c91pfhV264VbVU4AxCLfH/LvZWqdJQcBFiJCZHW5urMgZuWY1CLjYTyF1NQl O91kPoTN2t3D7GXTRt7aHLpCJ8odBdAuxINJfPGHJ/VlrinYWy6ySdGY9XhN2K0mZGBM dRlYR5Ag5RF1sBEVOSPEfvoXfU9EvRTIO84ARVie5QFWDVZpMhNBJMLsuob7IDFnvMMQ /zaM8SuQ9GjIPS8Cnl1ID47+N4tm3vG+ry3dy9lcW0rDGPkYUzqnGJRx7A1y5fOzlH3j rz56GRF2gcTq2u16zS2IftFX2rjYBhmXbxJpJ5atRMNchqD9OHGOPxoR2FByjaQlBkNY zRyQ== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563900; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=aRD7fh9RvdtKI1U0FLi3WzkFwBE/k6ib8HdQNOs79bo=; b=byQaCNEsLu+pjNRt4QtSeXJBkLjIgjSdqTqKhGGXeKKSvKGK2NJNo3fxUdWoBxNzqJ 1TnNPfO6aE3yRpak2777FoyZJtiRArnz4o65jk+MyqoONsgTAkbQ97sPeKLXxXu1EugD J2Kj//lp0+bIG5No1GIxZrjLRTCOCsGrhE6nx+FqzykSJIESfmxnk5g3t6kp9cDmHfsJ KMuMdSvjOnX98h5HyvvPrbQArAkL65xJnGByHLNtXBY3PmYYgAJMWRfsgtsrlrGVxGzy 1O606WYYHKHlYmtbViFvg+FQOVPJwVnRX5kkEEyG+UfqS4YZWlqAHmObCo66gobFXATs umsw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 34/38] tools: add API for expandable bitmaps Date: Tue, 1 Jun 2021 18:11:14 +0200 Message-Id: <20210601161118.18986-35-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since the incoming migration stream lacks info about what the highest pfn will be, data structures can not be allocated upfront. Add an API for expandable bitmaps, loosely based on pfn_set_populated. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.c | 40 ++++++++++++++++++++ tools/libs/saverestore/common.h | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/tools/libs/saverestore/common.c b/tools/libs/saverestore/commo= n.c index 7da7fa4e2c..9f1af4e671 100644 --- a/tools/libs/saverestore/common.c +++ b/tools/libs/saverestore/common.c @@ -163,6 +163,46 @@ static void __attribute__((unused)) build_assertions(v= oid) BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params) !=3D 8); } =20 +/* + * Expand the tracking structures as needed. + * To avoid realloc()ing too excessively, the size increased to the nearest + * power of two large enough to contain the required number of bits. + */ +bool _xg_sr_bitmap_expand(struct xg_sr_bitmap *bm, unsigned long bits) +{ + size_t new_max; + size_t old_sz, new_sz; + void *p; + + if (bits <=3D bm->bits) + return true; + + /* Round up to the nearest power of two larger than bit, less 1. */ + new_max =3D bits; + new_max |=3D new_max >> 1; + new_max |=3D new_max >> 2; + new_max |=3D new_max >> 4; + new_max |=3D new_max >> 8; + new_max |=3D new_max >> 16; + if ( sizeof(unsigned long) > 4 ) + new_max |=3D new_max >> 32; + + /* Allocate units of unsigned long */ + new_max =3D (new_max + BITS_PER_LONG - 1) & ~(BITS_PER_LONG - 1); + + old_sz =3D bitmap_size(bm->bits); + new_sz =3D bitmap_size(new_max); + p =3D realloc(bm->p, new_sz); + if (!p) + return false; + + memset(p + old_sz, 0, new_sz - old_sz); + bm->p =3D p; + bm->bits =3D new_max; + + return true; +} + /* * Local variables: * mode: C diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index cf8d6545e2..5241e50f5e 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -30,6 +30,73 @@ const char *rec_type_to_str(uint32_t type); struct xc_sr_context; struct xc_sr_record; =20 +struct xg_sr_bitmap +{ + void *p; + unsigned long bits; +}; + +extern bool _xg_sr_bitmap_expand(struct xg_sr_bitmap *bm, unsigned long bi= ts); + +static inline bool xg_sr_bitmap_expand(struct xg_sr_bitmap *bm, unsigned l= ong bits) +{ + if (bits > bm->bits) + return _xg_sr_bitmap_expand(bm, bits); + return true; +} + +static inline void xg_sr_bitmap_free(struct xg_sr_bitmap *bm) +{ + free(bm->p); + bm->p =3D NULL; +} + +static inline bool xg_sr_set_bit(unsigned long bit, struct xg_sr_bitmap *b= m) +{ + if (xg_sr_bitmap_expand(bm, bit) =3D=3D false) + return false; + + set_bit(bit, bm->p); + return true; +} + +static inline bool xg_sr_test_bit(unsigned long bit, struct xg_sr_bitmap *= bm) +{ + if (bit > bm->bits) + return false; + return !!test_bit(bit, bm->p); +} + +static inline void xg_sr_clear_bit(unsigned long bit, struct xg_sr_bitmap = *bm) +{ + if (bit <=3D bm->bits) + clear_bit(bit, bm->p); +} + +static inline bool xg_sr_test_and_clear_bit(unsigned long bit, struct xg_s= r_bitmap *bm) +{ + if (bit > bm->bits) + return false; + return !!test_and_clear_bit(bit, bm->p); +} + +/* No way to report potential allocation error, bitmap must be expanded pr= ior usage */ +static inline bool xg_sr_test_and_set_bit(unsigned long bit, struct xg_sr_= bitmap *bm) +{ + if (bit > bm->bits) + return false; + return !!test_and_set_bit(bit, bm->p); +} + +static inline bool xg_sr_set_long_bit(unsigned long base_bit, struct xg_sr= _bitmap *bm) +{ + if (xg_sr_bitmap_expand(bm, base_bit + BITS_PER_LONG) =3D=3D false) + return false; + + set_bit_long(base_bit, bm->p); + return true; +} + /** * Save operations. To be implemented for each type of guest, for use by = the * common save algorithm. From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564690051968.0163850581772; Tue, 1 Jun 2021 09:24:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135159.251361 (Exim 4.92) (envelope-from ) id 1lo7C3-0002k3-T9; Tue, 01 Jun 2021 16:24:39 +0000 Received: by outflank-mailman (output) from mailman id 135159.251361; Tue, 01 Jun 2021 16:24:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo7C3-0002jv-PI; Tue, 01 Jun 2021 16:24:39 +0000 Received: by outflank-mailman (input) for mailman id 135159; Tue, 01 Jun 2021 16:24:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo719-0005Ec-4B for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:13:23 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 60b9d1c2-9421-440a-ab4c-3ccfa7d0390c; Tue, 01 Jun 2021 16:11:46 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBf1Bf (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:41 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 60b9d1c2-9421-440a-ab4c-3ccfa7d0390c ARC-Seal: i=1; a=rsa-sha256; t=1622563901; cv=none; d=strato.com; s=strato-dkim-0002; b=XQvi/hWgKaEyTgjWvMcvqZqOox101nbYQgaaiAp5SBLHR29ICUoKym8AxgMDY6ieLe sMsvEkhKmXz+9TtBGRkSCrJEXBHt59b3L9NIZkTJDO/tNga/bbXm4Y4tPTOzLRECpfHM 1ouopBa8M/jdhzRnh44V+zVPaqfQXSndaFMdwd15DZ+CPyNg/vezkbvM6OmVA3vHoLXD /lxReH7+2UR881rX4r3oEQzFmsmj+qEarC6ZPQ+BWv6oecW85Fp227gR8vmRs65/wgIR ssbAVSHRyfo8vKWo/Hkzo08UGCOZYUzLUPopuhgLbDKhWZ4POEfLr8kd5j3gwLbuWAYa orIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563901; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=w5x8dKYtaakiRZ5BSlh/86KLwxZ1yLf8VEe49hX7ZHA=; b=ffy6cFrg7UEFmCg3EIpdeyDVdI8S3WfoWVJxTXXMXZCV3ToFqrMv443V8bcOFyFLiM DFzY4kHwziBDuE2AaVmIBMowevy2hp3VHuWUQeq5YqIoPOsjwFh400JrB40XysFAAr7w SlfNejl62jBRZ5TmAo4aRLUSefpljy+VbzBmzH6s71NQlizP4TD/JlFZLD2sJgDtPNkx eJo+4JgrA0jhuFHk31kO+ynk9um5gLJmHIanY23e/O3mhiFu9HINmoTfX5I8+DPTZwqx dLftyE5qV33pmQE4RSHlIgReGD7BUv+OcI2p2zUD7bkOaa/Z+kNeP0J83JN7RIzLh4+6 nNZg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563901; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=w5x8dKYtaakiRZ5BSlh/86KLwxZ1yLf8VEe49hX7ZHA=; b=SseXCMQ9Cv8cqJPYDhT1fW17p7wimEzxvMfFOPxB7C052+05DL6x3oBP4pqUCl0U8B Ky1zKQsRub4kbeyC7vDa9R+OMCdzBBTDhhG8wSYjb/AyfRzvzMo+HDwYZTyZ3FP5JL0B q83sFWdYpOKAhLVsFLW6st0ByOmbDvWGtDaTXPE/ZUVl+TOIxcEuAaI3KYI+wC9MmkxI jDnENx2p9At7sgk4P9YEfPBHNEl+pXrmnFWtQeXmhDQAvnbNypDscIQkCDPa2Xnsf6xN M2n5cqoUR4KJ1cV0nRQmJrXZ/xHyg7NdLlUmlwgNA5IspnndP8cn4QpcDoC7hslJEUjA rOpA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 35/38] tools: use xg_sr_bitmap for populated_pfns Date: Tue, 1 Jun 2021 18:11:15 +0200 Message-Id: <20210601161118.18986-36-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 21 +++++++- tools/libs/saverestore/restore.c | 69 ------------------------ tools/libs/saverestore/restore_x86_hvm.c | 9 ++++ tools/libs/saverestore/restore_x86_pv.c | 7 +++ 4 files changed, 35 insertions(+), 71 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 5241e50f5e..f3ee619844 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -403,8 +403,7 @@ struct xc_sr_context uint32_t xenstore_domid, console_domid; =20 /* Bitmap of currently populated PFNs during restore. */ - unsigned long *populated_pfns; - xen_pfn_t max_populated_pfn; + struct xg_sr_bitmap populated_pfns; =20 /* Sender has invoked verify mode on the stream. */ bool verify; @@ -596,6 +595,24 @@ static inline bool page_type_has_stream_data(uint32_t = type) } return ret; } + +static inline bool pfn_is_populated(struct xc_sr_context *ctx, xen_pfn_t p= fn) +{ + return xg_sr_test_bit(pfn, &ctx->restore.populated_pfns); +} + +static inline int pfn_set_populated(struct xc_sr_context *ctx, xen_pfn_t p= fn) +{ + xc_interface *xch =3D ctx->xch; + + if ( xg_sr_set_bit(pfn, &ctx->restore.populated_pfns) =3D=3D false ) + { + PERROR("Failed to realloc populated_pfns bitmap"); + errno =3D ENOMEM; + return -1; + } + return 0; +} #endif /* * Local variables: diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 722f77b46a..0682616f16 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -71,64 +71,6 @@ static int read_headers(struct xc_sr_context *ctx) return 0; } =20 -/* - * Is a pfn populated? - */ -static bool pfn_is_populated(const struct xc_sr_context *ctx, xen_pfn_t pf= n) -{ - if ( pfn > ctx->restore.max_populated_pfn ) - return false; - return test_bit(pfn, ctx->restore.populated_pfns); -} - -/* - * Set a pfn as populated, expanding the tracking structures if needed. To - * avoid realloc()ing too excessively, the size increased to the nearest p= ower - * of two large enough to contain the required pfn. - */ -static int pfn_set_populated(struct xc_sr_context *ctx, xen_pfn_t pfn) -{ - xc_interface *xch =3D ctx->xch; - - if ( pfn > ctx->restore.max_populated_pfn ) - { - xen_pfn_t new_max; - size_t old_sz, new_sz; - unsigned long *p; - - /* Round up to the nearest power of two larger than pfn, less 1. */ - new_max =3D pfn; - new_max |=3D new_max >> 1; - new_max |=3D new_max >> 2; - new_max |=3D new_max >> 4; - new_max |=3D new_max >> 8; - new_max |=3D new_max >> 16; -#ifdef __x86_64__ - new_max |=3D new_max >> 32; -#endif - - old_sz =3D bitmap_size(ctx->restore.max_populated_pfn + 1); - new_sz =3D bitmap_size(new_max + 1); - p =3D realloc(ctx->restore.populated_pfns, new_sz); - if ( !p ) - { - ERROR("Failed to realloc populated bitmap"); - errno =3D ENOMEM; - return -1; - } - - memset((uint8_t *)p + old_sz, 0x00, new_sz - old_sz); - - ctx->restore.populated_pfns =3D p; - ctx->restore.max_populated_pfn =3D new_max; - } - - assert(!test_bit(pfn, ctx->restore.populated_pfns)); - set_bit(pfn, ctx->restore.populated_pfns); - - return 0; -} - /* * Given a set of pfns, obtain memory from Xen to fill the physmap for the * unpopulated subset. If types is NULL, no page type checking is perform= ed @@ -929,16 +871,6 @@ static int setup(struct xc_sr_context *ctx) if ( rc ) goto err; =20 - ctx->restore.max_populated_pfn =3D (32 * 1024 / 4) - 1; - ctx->restore.populated_pfns =3D bitmap_alloc( - ctx->restore.max_populated_pfn + 1); - if ( !ctx->restore.populated_pfns ) - { - ERROR("Unable to allocate memory for populated_pfns bitmap"); - rc =3D -1; - goto err; - } - ctx->restore.buffered_records =3D malloc( DEFAULT_BUF_RECORDS * sizeof(struct xc_sr_record)); if ( !ctx->restore.buffered_records ) @@ -977,7 +909,6 @@ static void cleanup(struct xc_sr_context *ctx) =20 free(ctx->restore.m); free(ctx->restore.buffered_records); - free(ctx->restore.populated_pfns); =20 if ( ctx->restore.ops.cleanup(ctx) ) PERROR("Failed to clean up"); diff --git a/tools/libs/saverestore/restore_x86_hvm.c b/tools/libs/saverest= ore/restore_x86_hvm.c index bd63bd2818..73f17b7fcb 100644 --- a/tools/libs/saverestore/restore_x86_hvm.c +++ b/tools/libs/saverestore/restore_x86_hvm.c @@ -136,6 +136,7 @@ static int x86_hvm_localise_page(struct xc_sr_context *= ctx, static int x86_hvm_setup(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; + unsigned long max_pfn; =20 if ( ctx->restore.guest_type !=3D DHDR_TYPE_X86_HVM ) { @@ -161,6 +162,13 @@ static int x86_hvm_setup(struct xc_sr_context *ctx) } #endif =20 + max_pfn =3D max(ctx->restore.p2m_size, ctx->dominfo.max_memkb >> (PAGE= _SHIFT-10)); + if ( !xg_sr_bitmap_expand(&ctx->restore.populated_pfns, max_pfn) ) + { + PERROR("Unable to allocate memory for populated_pfns bitmap"); + return -1; + } + return 0; } =20 @@ -241,6 +249,7 @@ static int x86_hvm_stream_complete(struct xc_sr_context= *ctx) =20 static int x86_hvm_cleanup(struct xc_sr_context *ctx) { + xg_sr_bitmap_free(&ctx->restore.populated_pfns); free(ctx->x86.hvm.restore.context.ptr); =20 free(ctx->x86.restore.cpuid.ptr); diff --git a/tools/libs/saverestore/restore_x86_pv.c b/tools/libs/saveresto= re/restore_x86_pv.c index 96608e5231..bdaa0c0e76 100644 --- a/tools/libs/saverestore/restore_x86_pv.c +++ b/tools/libs/saverestore/restore_x86_pv.c @@ -1060,6 +1060,12 @@ static int x86_pv_setup(struct xc_sr_context *ctx) if ( rc ) return rc; =20 + if ( !xg_sr_bitmap_expand(&ctx->restore.populated_pfns, 32 * 1024 / 4)= ) + { + PERROR("Unable to allocate memory for populated_pfns bitmap"); + return -1; + } + ctx->x86.pv.restore.nr_vcpus =3D ctx->dominfo.max_vcpu_id + 1; ctx->x86.pv.restore.vcpus =3D calloc(sizeof(struct xc_sr_x86_pv_restor= e_vcpu), ctx->x86.pv.restore.nr_vcpus); @@ -1153,6 +1159,7 @@ static int x86_pv_stream_complete(struct xc_sr_contex= t *ctx) */ static int x86_pv_cleanup(struct xc_sr_context *ctx) { + xg_sr_bitmap_free(&ctx->restore.populated_pfns); free(ctx->x86.pv.p2m); free(ctx->x86.pv.p2m_pfns); =20 From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564761442232.59352136018674; Tue, 1 Jun 2021 09:26:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135241.251394 (Exim 4.92) (envelope-from ) id 1lo7DA-0004iZ-Ns; Tue, 01 Jun 2021 16:25:48 +0000 Received: by outflank-mailman (output) from mailman id 135241.251394; Tue, 01 Jun 2021 16:25:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo7DA-0004iR-KN; Tue, 01 Jun 2021 16:25:48 +0000 Received: by outflank-mailman (input) for mailman id 135241; Tue, 01 Jun 2021 16:25:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71O-0005Ec-4m for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:13:38 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.103]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8d8b81a0-24c2-445e-8bf5-5522f279730a; Tue, 01 Jun 2021 16:11:48 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBf1Bg (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:41 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8d8b81a0-24c2-445e-8bf5-5522f279730a ARC-Seal: i=1; a=rsa-sha256; t=1622563901; cv=none; d=strato.com; s=strato-dkim-0002; b=G5OeYBgOp4rc5S5+iKFBIEWS9eGrgCUetx3c30jxXTFyLlPt/8S3E7GHAIjEv4nuOe u9KDm2Lh5jjV5HxFnlOSmwc685PVtVzjYSFo8qh1f7ni8HLEGO0SmnJWkAQvFGZ/aK/6 vlW4V9mSThA4t7aKmtzIBgv2JCdcQyuiAQZQcxQ13FsHQ49PjXVYjJq/72QZai+xQ7w+ ci0Yl2iUJjBTrBlySs2QCK3lXqMe11ZKuMtRZF49GCCacmEhqrEFI/kRowwBVR4ihxsG sPCBe4Ehxduhm1vqQT8UE/ksIMEvePcTXzDeXw8B9LdukU0AfyuPzn6oei6fW+Agl+1x KwyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563901; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=99DJGLqeC4gMgdJU+sFS1vBiF6RF3t97LEFxoh+Df5c=; b=UPlmfzGfPdHX7Rpx679A7gEr/Rh5DevSimcqsb7MSgaF2sNDK7GQd1HHqZ4Mra+luv W5FmoVa2v2RTE0xaSuT194uFpMCLhVl+bAR8RdIu9ATCND2VOUVKi5icN+6uqcDVrnrw RvFsL9q/5Gk6aUikqd3KJaW9YIgLyxT0cFKaqHAcvBaYqb/WD8PTBc1UZ+QK/YY4l5kI HkdOCTnxDTMFO30J5SFhV7e7c8VL72uI6AlkUdKkNpY1E1DT8wkPUm7yhgfytUFO5VSs 3TXXYCexthPQSFOzuV0N0GEI1Tr/4+QgLG1m2KT9RBQQX7vFiUWFuqI7OdidW5RgApKH DZCw== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563901; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=99DJGLqeC4gMgdJU+sFS1vBiF6RF3t97LEFxoh+Df5c=; b=BdiS6ICEIgqUof7q6X9Ukl/wsn1WAeEdDuaC8qU4x4FNoezx3JP08F2ex9qfqxsWVJ 3iC4+FLlKkgYhf1FeDz6nGTrzME52DIe0IfoxKakuNqJxOvmuO7zroWfjiVNQ+Av/msO XDWOM4nAtFa5R0FEPYFcZxdAaRA6V068au/gbTda0ZKWmLBAv1xBK2NR/Oyjp9vuaGD6 Uj7p0TrjTbVin+AXEDQZEnmSPNc1uXsV2FP8flVPJIgNcDB6bp27m8QVq4a3i5ae59in KLBn9iESKOeKjfpUiqKq65yuF60AW95yhSWjRmQUpnCA80IVyrGo3z6C63H9BF5T42c2 xaBw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 36/38] tools: use superpages during restore of HVM guest Date: Tue, 1 Jun 2021 18:11:16 +0200 Message-Id: <20210601161118.18986-37-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" During creating of a HVM domU meminit_hvm() tries to map superpages. After save/restore or migration this mapping is lost, everything is allocated in single pages. This causes a performance degradation after migration. Add neccessary code to preallocate a superpage for an incoming chunk of pfns. In case a pfn was not populated on the sending side, it must be freed on the receiving side to avoid over-allocation. The existing code for x86_pv is moved unmodified into its own file. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_dom_x86.c | 5 - tools/libs/guest/xg_private.h | 5 + tools/libs/saverestore/common.c | 2 - tools/libs/saverestore/common.h | 29 +- tools/libs/saverestore/restore.c | 62 +--- tools/libs/saverestore/restore_x86_hvm.c | 369 ++++++++++++++++++++++- tools/libs/saverestore/restore_x86_pv.c | 61 +++- 7 files changed, 455 insertions(+), 78 deletions(-) diff --git a/tools/libs/guest/xg_dom_x86.c b/tools/libs/guest/xg_dom_x86.c index d2eb89ce01..ec0d18fd60 100644 --- a/tools/libs/guest/xg_dom_x86.c +++ b/tools/libs/guest/xg_dom_x86.c @@ -44,11 +44,6 @@ =20 #define SUPERPAGE_BATCH_SIZE 512 =20 -#define SUPERPAGE_2MB_SHIFT 9 -#define SUPERPAGE_2MB_NR_PFNS (1UL << SUPERPAGE_2MB_SHIFT) -#define SUPERPAGE_1GB_SHIFT 18 -#define SUPERPAGE_1GB_NR_PFNS (1UL << SUPERPAGE_1GB_SHIFT) - #define X86_CR0_PE 0x01 #define X86_CR0_ET 0x10 =20 diff --git a/tools/libs/guest/xg_private.h b/tools/libs/guest/xg_private.h index 25e46d7ce1..ad3d108c14 100644 --- a/tools/libs/guest/xg_private.h +++ b/tools/libs/guest/xg_private.h @@ -154,4 +154,9 @@ int pin_table(xc_interface *xch, unsigned int type, uns= igned long mfn, #define M2P_SIZE(_m) ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_SHIFT) #define M2P_CHUNKS(_m) (M2P_SIZE((_m)) >> M2P_SHIFT) =20 +#define SUPERPAGE_2MB_SHIFT 9 +#define SUPERPAGE_2MB_NR_PFNS (1UL << SUPERPAGE_2MB_SHIFT) +#define SUPERPAGE_1GB_SHIFT 18 +#define SUPERPAGE_1GB_NR_PFNS (1UL << SUPERPAGE_1GB_SHIFT) + #endif /* XG_PRIVATE_H */ diff --git a/tools/libs/saverestore/common.c b/tools/libs/saverestore/commo= n.c index 9f1af4e671..09b2983898 100644 --- a/tools/libs/saverestore/common.c +++ b/tools/libs/saverestore/common.c @@ -1,5 +1,3 @@ -#include - #include "common.h" =20 #include diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index f3ee619844..b323c1b71a 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -3,6 +3,7 @@ =20 #include #include +#include #include #include #include @@ -219,6 +220,16 @@ struct xc_sr_restore_ops */ int (*setup)(struct xc_sr_context *ctx); =20 + /** + * Populate PFNs + * + * Given a set of pfns, obtain memory from Xen to fill the physmap for= the + * unpopulated subset. + */ + int (*populate_pfns)(struct xc_sr_context *ctx, unsigned count, + const xen_pfn_t *original_pfns, const uint32_t *t= ypes); + + /** * Process an individual record from the stream. The caller shall take * care of processing common records (e.g. END, PAGE_DATA). @@ -366,6 +377,8 @@ struct xc_sr_context =20 int send_back_fd; unsigned long p2m_size; + unsigned long max_pages; + unsigned long tot_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; =20 /* From Image Header. */ @@ -503,6 +516,14 @@ struct xc_sr_context { /* HVM context blob. */ struct xc_sr_blob context; + + /* Bitmap of currently allocated PFNs during resto= re. */ + struct xg_sr_bitmap attempted_1g; + struct xg_sr_bitmap attempted_2m; + struct xg_sr_bitmap allocated_pfns; + xen_pfn_t prev_populated_pfn; + xen_pfn_t iteration_tracker_pfn; + unsigned long iteration; } restore; }; } hvm; @@ -567,14 +588,6 @@ int read_record_header(struct xc_sr_context *ctx, int = fd, struct xc_sr_rhdr *rhd int read_record_data(struct xc_sr_context *ctx, int fd, struct xc_sr_rhdr = *rhdr, struct xc_sr_record *rec); =20 -/* - * This would ideally be private in restore.c, but is needed by - * x86_pv_localise_page() if we receive pagetables frames ahead of the - * contents of the frames they point at. - */ -int populate_pfns(struct xc_sr_context *ctx, unsigned int count, - const xen_pfn_t *original_pfns, const uint32_t *types); - /* Handle a STATIC_DATA_END record. */ int handle_static_data_end(struct xc_sr_context *ctx); =20 diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 0682616f16..d4657e8e57 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -71,63 +71,6 @@ static int read_headers(struct xc_sr_context *ctx) return 0; } =20 -/* - * Given a set of pfns, obtain memory from Xen to fill the physmap for the - * unpopulated subset. If types is NULL, no page type checking is perform= ed - * and all unpopulated pfns are populated. - */ -int populate_pfns(struct xc_sr_context *ctx, unsigned int count, - const xen_pfn_t *original_pfns, const uint32_t *types) -{ - xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D ctx->restore.m->pp_mfns, - *pfns =3D ctx->restore.m->pp_pfns; - unsigned int i, nr_pfns =3D 0; - int rc =3D -1; - - for ( i =3D 0; i < count; ++i ) - { - if ( (!types || - (types && page_type_has_stream_data(types[i]) =3D=3D true)) = && - !pfn_is_populated(ctx, original_pfns[i]) ) - { - rc =3D pfn_set_populated(ctx, original_pfns[i]); - if ( rc ) - goto err; - pfns[nr_pfns] =3D mfns[nr_pfns] =3D original_pfns[i]; - ++nr_pfns; - } - } - - if ( nr_pfns ) - { - rc =3D xc_domain_populate_physmap_exact( - xch, ctx->domid, nr_pfns, 0, 0, mfns); - if ( rc ) - { - PERROR("Failed to populate physmap"); - goto err; - } - - for ( i =3D 0; i < nr_pfns; ++i ) - { - if ( mfns[i] =3D=3D INVALID_MFN ) - { - ERROR("Populate physmap failed for pfn %u", i); - rc =3D -1; - goto err; - } - - ctx->restore.ops.set_gfn(ctx, pfns[i], mfns[i]); - } - } - - rc =3D 0; - - err: - return rc; -} - static int handle_static_data_end_v2(struct xc_sr_context *ctx) { int rc =3D 0; @@ -270,7 +213,7 @@ static int map_guest_pages(struct xc_sr_context *ctx, uint32_t i, p; int rc; =20 - rc =3D populate_pfns(ctx, pages->count, m->pfns, m->types); + rc =3D ctx->restore.ops.populate_pfns(ctx, pages->count, m->pfns, m->t= ypes); if ( rc ) { ERROR("Failed to populate pfns for batch of %u pages", pages->coun= t); @@ -1077,6 +1020,9 @@ int xc_domain_restore(xc_interface *xch, int io_fd, u= int32_t dom, return -1; } =20 + /* See xc_domain_getinfo */ + ctx.restore.max_pages =3D ctx.dominfo.max_memkb >> (PAGE_SHIFT-10); + ctx.restore.tot_pages =3D ctx.dominfo.nr_pages; ctx.restore.p2m_size =3D nr_pfns; ctx.restore.ops =3D ctx.dominfo.hvm ? restore_ops_x86_hvm : restore_ops_x86_pv; diff --git a/tools/libs/saverestore/restore_x86_hvm.c b/tools/libs/saverest= ore/restore_x86_hvm.c index 73f17b7fcb..79bcf07e04 100644 --- a/tools/libs/saverestore/restore_x86_hvm.c +++ b/tools/libs/saverestore/restore_x86_hvm.c @@ -130,6 +130,25 @@ static int x86_hvm_localise_page(struct xc_sr_context = *ctx, return 0; } =20 +static bool x86_hvm_expand_sp_bitmaps(struct xc_sr_context *ctx, unsigned = long max_pfn) +{ + struct xg_sr_bitmap *bm; + + bm =3D &ctx->x86.hvm.restore.attempted_1g; + if ( !xg_sr_bitmap_expand(bm, max_pfn >> SUPERPAGE_1GB_SHIFT) ) + return false; + + bm =3D &ctx->x86.hvm.restore.attempted_2m; + if ( !xg_sr_bitmap_expand(bm, max_pfn >> SUPERPAGE_2MB_SHIFT) ) + return false; + + bm =3D &ctx->x86.hvm.restore.allocated_pfns; + if ( !xg_sr_bitmap_expand(bm, max_pfn) ) + return false; + + return true; +} + /* * restore_ops function. Confirms the stream matches the domain. */ @@ -164,12 +183,20 @@ static int x86_hvm_setup(struct xc_sr_context *ctx) =20 max_pfn =3D max(ctx->restore.p2m_size, ctx->dominfo.max_memkb >> (PAGE= _SHIFT-10)); if ( !xg_sr_bitmap_expand(&ctx->restore.populated_pfns, max_pfn) ) - { - PERROR("Unable to allocate memory for populated_pfns bitmap"); - return -1; - } + goto out; + + if ( !x86_hvm_expand_sp_bitmaps(ctx, max_pfn) ) + goto out; + + /* No superpage in 1st 2MB due to VGA hole */ + xg_sr_set_bit(0, &ctx->x86.hvm.restore.attempted_1g); + xg_sr_set_bit(0, &ctx->x86.hvm.restore.attempted_2m); =20 return 0; + +out: + PERROR("Unable to allocate memory for pfn bitmaps"); + return -1; } =20 /* @@ -250,6 +277,9 @@ static int x86_hvm_stream_complete(struct xc_sr_context= *ctx) static int x86_hvm_cleanup(struct xc_sr_context *ctx) { xg_sr_bitmap_free(&ctx->restore.populated_pfns); + xg_sr_bitmap_free(&ctx->x86.hvm.restore.attempted_1g); + xg_sr_bitmap_free(&ctx->x86.hvm.restore.attempted_2m); + xg_sr_bitmap_free(&ctx->x86.hvm.restore.allocated_pfns); free(ctx->x86.hvm.restore.context.ptr); =20 free(ctx->x86.restore.cpuid.ptr); @@ -258,6 +288,336 @@ static int x86_hvm_cleanup(struct xc_sr_context *ctx) return 0; } =20 +/* + * Set a range of pfns as allocated + */ +static void pfn_set_long_allocated(struct xc_sr_context *ctx, xen_pfn_t ba= se_pfn) +{ + xg_sr_set_long_bit(base_pfn, &ctx->x86.hvm.restore.allocated_pfns); +} + +static void pfn_set_allocated(struct xc_sr_context *ctx, xen_pfn_t pfn) +{ + xg_sr_set_bit(pfn, &ctx->x86.hvm.restore.allocated_pfns); +} + +struct x86_hvm_sp { + xen_pfn_t pfn; + xen_pfn_t base_pfn; + unsigned long index; + unsigned long count; +}; + +/* + * Try to allocate a 1GB page for this pfn, but avoid Over-allocation. + * If this succeeds, mark the range of 2MB pages as busy. + */ +static bool x86_hvm_alloc_1g(struct xc_sr_context *ctx, struct x86_hvm_sp = *sp) +{ + xc_interface *xch =3D ctx->xch; + unsigned int order; + int i, done; + xen_pfn_t extent; + + /* Only one attempt to avoid overlapping allocation */ + if ( xg_sr_test_and_set_bit(sp->index, &ctx->x86.hvm.restore.attempted= _1g) ) + return false; + + order =3D SUPERPAGE_1GB_SHIFT; + sp->count =3D SUPERPAGE_1GB_NR_PFNS; + + /* Allocate only if there is room for another superpage */ + if ( ctx->restore.tot_pages + sp->count > ctx->restore.max_pages ) + return false; + + extent =3D sp->base_pfn =3D (sp->pfn >> order) << order; + done =3D xc_domain_populate_physmap(xch, ctx->domid, 1, order, 0, &ext= ent); + if ( done < 0 ) { + PERROR("populate_physmap failed."); + return false; + } + if ( done =3D=3D 0 ) + return false; + + DPRINTF("1G %" PRI_xen_pfn "\n", sp->base_pfn); + + /* Mark all 2MB pages as done to avoid overlapping allocation */ + for ( i =3D 0; i < (SUPERPAGE_1GB_NR_PFNS/SUPERPAGE_2MB_NR_PFNS); i++ ) + xg_sr_set_bit((sp->base_pfn >> SUPERPAGE_2MB_SHIFT) + i, &ctx->x86= .hvm.restore.attempted_2m); + + return true; +} + +/* Allocate a 2MB page if x86_hvm_alloc_1g failed, avoid Over-allocation. = */ +static bool x86_hvm_alloc_2m(struct xc_sr_context *ctx, struct x86_hvm_sp = *sp) +{ + xc_interface *xch =3D ctx->xch; + unsigned int order; + int done; + xen_pfn_t extent; + + /* Only one attempt to avoid overlapping allocation */ + if ( xg_sr_test_and_set_bit(sp->index, &ctx->x86.hvm.restore.attempted= _2m) ) + return false; + + order =3D SUPERPAGE_2MB_SHIFT; + sp->count =3D SUPERPAGE_2MB_NR_PFNS; + + /* Allocate only if there is room for another superpage */ + if ( ctx->restore.tot_pages + sp->count > ctx->restore.max_pages ) + return false; + + extent =3D sp->base_pfn =3D (sp->pfn >> order) << order; + done =3D xc_domain_populate_physmap(xch, ctx->domid, 1, order, 0, &ext= ent); + if ( done < 0 ) { + PERROR("populate_physmap failed."); + return false; + } + if ( done =3D=3D 0 ) + return false; + + DPRINTF("2M %" PRI_xen_pfn "\n", sp->base_pfn); + return true; +} + +/* Allocate a single page if x86_hvm_alloc_2m failed. */ +static bool x86_hvm_alloc_4k(struct xc_sr_context *ctx, struct x86_hvm_sp = *sp) +{ + xc_interface *xch =3D ctx->xch; + unsigned int order; + int done; + xen_pfn_t extent; + + order =3D 0; + sp->count =3D 1UL; + + /* Allocate only if there is room for another page */ + if ( ctx->restore.tot_pages + sp->count > ctx->restore.max_pages ) { + errno =3D E2BIG; + return false; + } + + extent =3D sp->base_pfn =3D (sp->pfn >> order) << order; + done =3D xc_domain_populate_physmap(xch, ctx->domid, 1, order, 0, &ext= ent); + if ( done < 0 ) { + PERROR("populate_physmap failed."); + return false; + } + if ( done =3D=3D 0 ) { + errno =3D ENOMEM; + return false; + } + + DPRINTF("4K %" PRI_xen_pfn "\n", sp->base_pfn); + return true; +} +/* + * Attempt to allocate a superpage where the pfn resides. + */ +static int x86_hvm_allocate_pfn(struct xc_sr_context *ctx, xen_pfn_t pfn) +{ + bool success; + unsigned long idx_1g, idx_2m; + struct x86_hvm_sp sp =3D { + .pfn =3D pfn + }; + + if ( xg_sr_test_bit(pfn, &ctx->x86.hvm.restore.allocated_pfns) ) + return 0; + + idx_1g =3D pfn >> SUPERPAGE_1GB_SHIFT; + idx_2m =3D pfn >> SUPERPAGE_2MB_SHIFT; + + sp.index =3D idx_1g; + success =3D x86_hvm_alloc_1g(ctx, &sp); + + if ( success =3D=3D false ) { + sp.index =3D idx_2m; + success =3D x86_hvm_alloc_2m(ctx, &sp); + } + + if ( success =3D=3D false ) { + sp.index =3D 0; + success =3D x86_hvm_alloc_4k(ctx, &sp); + } + + if ( success =3D=3D false ) + return -1; + + do { + if ( sp.count >=3D BITS_PER_LONG ) { + sp.count -=3D BITS_PER_LONG; + ctx->restore.tot_pages +=3D BITS_PER_LONG; + pfn_set_long_allocated(ctx, sp.base_pfn + sp.count); + } else { + sp.count--; + ctx->restore.tot_pages++; + pfn_set_allocated(ctx, sp.base_pfn + sp.count); + } + } while ( sp.count ); + + return 0; +} + +/* + * Deallocate memory. + * There was likely an optimistic superpage allocation. + * This means more pages may have been allocated past gap_end. + * This range is not freed now. Incoming higher pfns will release it. + */ +static int x86_hvm_punch_hole(struct xc_sr_context *ctx, + xen_pfn_t gap_start, xen_pfn_t gap_end) +{ + xc_interface *xch =3D ctx->xch; + xen_pfn_t _pfn, pfn; + uint32_t domid, freed =3D 0; + int rc; + + pfn =3D gap_start >> SUPERPAGE_1GB_SHIFT; + do + { + xg_sr_set_bit(pfn, &ctx->x86.hvm.restore.attempted_1g); + } while (++pfn <=3D gap_end >> SUPERPAGE_1GB_SHIFT); + + pfn =3D gap_start >> SUPERPAGE_2MB_SHIFT; + do + { + xg_sr_set_bit(pfn, &ctx->x86.hvm.restore.attempted_2m); + } while (++pfn <=3D gap_end >> SUPERPAGE_2MB_SHIFT); + + pfn =3D gap_start; + + while ( pfn <=3D gap_end ) + { + if ( xg_sr_test_and_clear_bit(pfn, &ctx->x86.hvm.restore.allocated= _pfns) ) + { + domid =3D ctx->domid; + _pfn =3D pfn; + rc =3D xc_domain_decrease_reservation_exact(xch, domid, 1, 0, = &_pfn); + if ( rc ) + { + PERROR("Failed to release pfn %" PRI_xen_pfn, pfn); + return -1; + } + ctx->restore.tot_pages--; + freed++; + } + pfn++; + } + if ( freed ) + DPRINTF("freed %u between %" PRI_xen_pfn " %" PRI_xen_pfn "\n", + freed, gap_start, gap_end); + return 0; +} + +static int x86_hvm_unpopulate_page(struct xc_sr_context *ctx, xen_pfn_t pf= n) +{ + xg_sr_clear_bit(pfn, &ctx->restore.populated_pfns); + return x86_hvm_punch_hole(ctx, pfn, pfn); +} + +static int x86_hvm_populate_page(struct xc_sr_context *ctx, xen_pfn_t pfn) +{ + xen_pfn_t gap_start, gap_end; + bool has_gap, first_iteration; + int rc; + + /* + * Check for a gap between the previous populated pfn and this pfn. + * In case a gap exists, it is required to punch a hole to release mem= ory, + * starting after the previous pfn and before this pfn. + * + * But: this can be done only during the first iteration, which is the + * only place there superpage allocations are attempted. All following + * iterations lack the info to properly maintain prev_populated_pfn. + */ + has_gap =3D ctx->x86.hvm.restore.prev_populated_pfn + 1 < pfn; + first_iteration =3D ctx->x86.hvm.restore.iteration =3D=3D 0; + if ( has_gap && first_iteration ) + { + gap_start =3D ctx->x86.hvm.restore.prev_populated_pfn + 1; + gap_end =3D pfn - 1; + + rc =3D x86_hvm_punch_hole(ctx, gap_start, gap_end); + if ( rc ) + goto err; + } + + rc =3D x86_hvm_allocate_pfn(ctx, pfn); + if ( rc ) + goto err; + pfn_set_populated(ctx, pfn); + ctx->x86.hvm.restore.prev_populated_pfn =3D pfn; + + rc =3D 0; +err: + return rc; +} + +/* + * Try to allocate superpages. + * This works without memory map because the pfns arrive in incremental or= der. + * All pfn numbers and their type are submitted. + * Only pfns with data will have also pfn content transmitted. + */ +static int x86_hvm_populate_pfns(struct xc_sr_context *ctx, unsigned count, + const xen_pfn_t *original_pfns, + const uint32_t *types) +{ + xc_interface *xch =3D ctx->xch; + xen_pfn_t pfn, min_pfn, max_pfn; + bool has_data, populated; + unsigned i =3D count; + int rc =3D 0; + + min_pfn =3D count ? original_pfns[0] : 0; + max_pfn =3D count ? original_pfns[count - 1] : 0; + DPRINTF("batch of %u pfns between %" PRI_xen_pfn " %" PRI_xen_pfn "\n", + count, min_pfn, max_pfn); + + if ( !x86_hvm_expand_sp_bitmaps(ctx, max_pfn) ) + { + ERROR("Unable to allocate memory for pfn bitmaps"); + return -1; + } + + /* + * There is no indicator for a new iteration. + * Simulate it by checking if a lower pfn is coming in. + * In the end it matters only to know if this iteration is the first o= ne. + */ + if ( min_pfn < ctx->x86.hvm.restore.iteration_tracker_pfn ) + ctx->x86.hvm.restore.iteration++; + ctx->x86.hvm.restore.iteration_tracker_pfn =3D min_pfn; + + for ( i =3D 0; i < count; ++i ) + { + pfn =3D original_pfns[i]; + + has_data =3D page_type_has_stream_data(types[i]); + populated =3D pfn_is_populated(ctx, pfn); + + /* + * page has data, pfn populated: nothing to do + * page has data, pfn not populated: likely never seen before + * page has no data, pfn populated: likely ballooned out during mi= gration + * page has no data, pfn not populated: nothing to do + */ + if ( has_data && !populated ) + { + rc =3D x86_hvm_populate_page(ctx, pfn); + } else if ( !has_data && populated ) + { + rc =3D x86_hvm_unpopulate_page(ctx, pfn); + } + if ( rc ) + break; + } + + return rc; +} + + struct xc_sr_restore_ops restore_ops_x86_hvm =3D { .pfn_is_valid =3D x86_hvm_pfn_is_valid, @@ -266,6 +626,7 @@ struct xc_sr_restore_ops restore_ops_x86_hvm =3D .set_page_type =3D x86_hvm_set_page_type, .localise_page =3D x86_hvm_localise_page, .setup =3D x86_hvm_setup, + .populate_pfns =3D x86_hvm_populate_pfns, .process_record =3D x86_hvm_process_record, .static_data_complete =3D x86_static_data_complete, .stream_complete =3D x86_hvm_stream_complete, diff --git a/tools/libs/saverestore/restore_x86_pv.c b/tools/libs/saveresto= re/restore_x86_pv.c index bdaa0c0e76..f4f0f49dee 100644 --- a/tools/libs/saverestore/restore_x86_pv.c +++ b/tools/libs/saverestore/restore_x86_pv.c @@ -959,6 +959,64 @@ static void x86_pv_set_gfn(struct xc_sr_context *ctx, = xen_pfn_t pfn, ((uint32_t *)ctx->x86.pv.p2m)[pfn] =3D mfn; } =20 +/* + * Given a set of pfns, obtain memory from Xen to fill the physmap for the + * unpopulated subset. If types is NULL, no page type checking is perform= ed + * and all unpopulated pfns are populated. + */ +static int x86_pv_populate_pfns(struct xc_sr_context *ctx, unsigned count, + const xen_pfn_t *original_pfns, + const uint32_t *types) +{ + xc_interface *xch =3D ctx->xch; + xen_pfn_t *mfns =3D ctx->restore.m->pp_mfns, + *pfns =3D ctx->restore.m->pp_pfns; + unsigned int i, nr_pfns =3D 0; + int rc =3D -1; + + for ( i =3D 0; i < count; ++i ) + { + if ( (!types || + (types && page_type_has_stream_data(types[i]) =3D=3D true)) = && + !pfn_is_populated(ctx, original_pfns[i]) ) + { + rc =3D pfn_set_populated(ctx, original_pfns[i]); + if ( rc ) + goto err; + pfns[nr_pfns] =3D mfns[nr_pfns] =3D original_pfns[i]; + ++nr_pfns; + } + } + + if ( nr_pfns ) + { + rc =3D xc_domain_populate_physmap_exact( + xch, ctx->domid, nr_pfns, 0, 0, mfns); + if ( rc ) + { + PERROR("Failed to populate physmap"); + goto err; + } + + for ( i =3D 0; i < nr_pfns; ++i ) + { + if ( mfns[i] =3D=3D INVALID_MFN ) + { + ERROR("Populate physmap failed for pfn %u", i); + rc =3D -1; + goto err; + } + + ctx->restore.ops.set_gfn(ctx, pfns[i], mfns[i]); + } + } + + rc =3D 0; + + err: + return rc; +} + /* * restore_ops function. Convert pfns back to mfns in pagetables. Possib= ly * needs to populate new frames if a PTE is found referring to a frame whi= ch @@ -1003,7 +1061,7 @@ static int x86_pv_localise_page(struct xc_sr_context = *ctx, } } =20 - if ( to_populate && populate_pfns(ctx, to_populate, pfns, NULL) ) + if ( to_populate && x86_pv_populate_pfns(ctx, to_populate, pfns, NULL)= ) return -1; =20 for ( i =3D 0; i < (PAGE_SIZE / sizeof(uint64_t)); ++i ) @@ -1200,6 +1258,7 @@ struct xc_sr_restore_ops restore_ops_x86_pv =3D .set_gfn =3D x86_pv_set_gfn, .localise_page =3D x86_pv_localise_page, .setup =3D x86_pv_setup, + .populate_pfns =3D x86_pv_populate_pfns, .process_record =3D x86_pv_process_record, .static_data_complete =3D x86_static_data_complete, .stream_complete =3D x86_pv_stream_complete, From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1622564023521113.96194752923327; Tue, 1 Jun 2021 09:13:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135023.251218 (Exim 4.92) (envelope-from ) id 1lo71H-0001GP-6i; Tue, 01 Jun 2021 16:13:31 +0000 Received: by outflank-mailman (output) from mailman id 135023.251218; Tue, 01 Jun 2021 16:13:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo71H-0001G5-2d; Tue, 01 Jun 2021 16:13:31 +0000 Received: by outflank-mailman (input) for mailman id 135023; Tue, 01 Jun 2021 16:13:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70W-0005X1-1K for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:44 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.102]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 278042e2-4acd-4f2f-8a00-3bcb9a4b4a4d; Tue, 01 Jun 2021 16:11:47 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBg1Bh (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:42 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 278042e2-4acd-4f2f-8a00-3bcb9a4b4a4d ARC-Seal: i=1; a=rsa-sha256; t=1622563902; cv=none; d=strato.com; s=strato-dkim-0002; b=GeSymt4sBAtamqwu9Qf/zyFLkpCxODm6nO9s0ZiWqB94QdYonpmCondOY39DJhz7ab 2M7Qu2AfX6KGmOO5H4L26EKPFJ4xTciT6GYke96FK3x6yOTCc6jwxMBzay/YP4RB/AS+ nczvhI0gIHZfwKjJxHpPH2jiLTpgLSUmaRyHs3rFbK0TEKbZFb8dreXvElyKslcUoe5m AfyG9O2TsHZCnwIJwpxMLJ0KaAfW3dMgw2YZhSTehyGN7IJLjYq2pu4PuPSe/oXGAtcB 1tcxssT/fo5jwJCEjwNY5ascx/5HesM9L3HQ0QF1n3pyDXmiej6NCkWQaVeSLY/6WUl0 xsFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563902; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=6EezNi5nT36Er9YZKB+7tjmR7V8p17EAGCb3I0QL+5s=; b=UskJ41eWQFyxIqoSJ0UbrO2OZY0O5JRSH8qP2FMg5ktabG6ppN1i4yMHUb9fw7QZ77 r6dV0UWdB16t2j+k94SZBhdhH7wqyWVBXcWjNSdR4kqmeWprjxyUnTYCM0/9jWUBBXTJ 4MQE0HgWaXpQ9VHFxHTydxG6o4SCu4tYb9TJbcss4feKjK4mQiSqfc/BkLBElPYYKP/V 96Fl0XaAmmqUykmd0UJjaSjitivygCRbB5GRQoIJqujhlvJ1x/SCd1+1z2Ev9K14tShO dEr+2jH7f+WKL4IaEKhAfjk2lwlh5MyZ7O9FFbdgJneEVG1g38AFwJLzXLjmp6BIw77k cF4g== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563902; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=6EezNi5nT36Er9YZKB+7tjmR7V8p17EAGCb3I0QL+5s=; b=VYpxfqnSD8t0H6aLBhP5dxoK9sO90LouyqSEYxfqVVwdyE4vcLV6MnyJnAqJ6CxYB2 iwgHF/J1IbQ7JQsfUaaMdOOs18zBBwqsFzp4e5naiSodmW9pGH8KzCZgd6Ylzf3y5Tly gTY15o14NCLZruKyIEwJ57UFGnKF6NPZX2QRzfJMppSrmMfU6NoW+WgSq1Uk+7q+nSaF XoNIQiQXQoiD8+OygNVgWo2teoYUGCvs2T/jfdNqftXE32ARgJGoYOn9R3d1yeYpBaUW 9V5sp/L587S/AAOdyAb2r4le07PGPs+gLKrlsApjmYE+s9I6pM7wGo84vWqzqQRvTzdI 3FEw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 37/38] tools: remove migration stream verify code Date: Tue, 1 Jun 2021 18:11:17 +0200 Message-Id: <20210601161118.18986-38-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The verify code tries to make sure the transferred pages from the paused domU were received correctly in the previous, final iteration. Every page is transferred once again by the sender, the receiver compares the content with what is already mapped into the not-yet started domU. This does unfortunately not work because a domU has also a number of pages in its grant table, so that frondend drivers can communicate with the backend drivers. Since the backend drivers are unaware about the ongoing saving of the domU, they will continue to write into the shared pages. As a result the verification of the domU pages will fail. This is not fixable, so remove the verification code. The sending side will never send a REC_TYPE_VERIFY record again. It will silently accept, and ignore the debug flag. The receiving side will abort an almost complete migration in case it sees a REC_TYPE_VERIFY record from an old sender. That record is sent at the very end, it has no way to know in advance that verification was requested. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 7 ------ tools/libs/saverestore/restore.c | 43 ++++---------------------------- tools/libs/saverestore/save.c | 43 -------------------------------- 3 files changed, 5 insertions(+), 88 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index b323c1b71a..b8ca24e667 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -354,9 +354,6 @@ struct xc_sr_context /* Live migrate vs non live suspend. */ bool live; =20 - /* Further debugging information in the stream. */ - bool debug; - unsigned long p2m_size; size_t pages_sent; size_t overhead_sent; @@ -418,10 +415,6 @@ struct xc_sr_context /* Bitmap of currently populated PFNs during restore. */ struct xg_sr_bitmap populated_pfns; =20 - /* Sender has invoked verify mode on the stream. */ - bool verify; - void *verify_buf; - struct xc_sr_restore_arrays *m; void *guest_mapping; uint32_t nr_mapped_pages; diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index d4657e8e57..9a7253a972 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -337,10 +337,7 @@ static int handle_incoming_page_data(struct xc_sr_cont= ext *ctx, continue; =20 m->iov[iov_idx].iov_len =3D PAGE_SIZE; - if ( ctx->restore.verify ) - m->iov[iov_idx].iov_base =3D ctx->restore.verify_buf + i * PAG= E_SIZE; - else - m->iov[iov_idx].iov_base =3D m->guest_data[i]; + m->iov[iov_idx].iov_base =3D m->guest_data[i]; iov_idx++; } =20 @@ -369,15 +366,6 @@ static int handle_incoming_page_data(struct xc_sr_cont= ext *ctx, =20 } =20 - if ( ctx->restore.verify ) - { - if ( memcmp(m->guest_data[i], m->iov[iov_idx].iov_base, PAGE_S= IZE) ) - { - ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", - m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); - } - } - iov_idx++; } =20 @@ -447,20 +435,7 @@ static int handle_buffered_page_data(struct xc_sr_cont= ext *ctx, =20 } =20 - if ( ctx->restore.verify ) - { - if ( memcmp(m->guest_data[i], p, PAGE_SIZE) ) - { - errno =3D EIO; - ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", - m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); - goto err; - } - } - else - { - memcpy(m->guest_data[i], p, PAGE_SIZE); - } + memcpy(m->guest_data[i], p, PAGE_SIZE); =20 idx++; } @@ -737,17 +712,9 @@ static int process_buffered_record(struct xc_sr_contex= t *ctx, struct xc_sr_recor break; =20 case REC_TYPE_VERIFY: - DPRINTF("Verify mode enabled"); - ctx->restore.verify =3D true; - if ( !ctx->restore.verify_buf ) - { - ctx->restore.verify_buf =3D malloc(MAX_BATCH_SIZE * PAGE_SIZE); - if ( !ctx->restore.verify_buf ) - { - rc =3D -1; - PERROR("Unable to allocate verify_buf"); - } - } + errno =3D EINVAL; + PERROR("Verify mode is obsolete"); + rc =3D -1; break; =20 case REC_TYPE_CHECKPOINT: diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 523457eaba..2d34822509 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -707,41 +707,6 @@ static int suspend_and_send_dirty(struct xc_sr_context= *ctx) return rc; } =20 -static int verify_frames(struct xc_sr_context *ctx) -{ - xc_interface *xch =3D ctx->xch; - xc_shadow_op_stats_t stats =3D { 0, ctx->save.p2m_size }; - int rc; - struct xc_sr_record rec =3D { .type =3D REC_TYPE_VERIFY }; - - DPRINTF("Enabling verify mode"); - - rc =3D write_record(ctx, &rec); - if ( rc ) - goto out; - - xc_set_progress_prefix(xch, "Frames verify"); - rc =3D send_all_pages(ctx); - if ( rc ) - goto out; - - if ( xc_shadow_control( - xch, ctx->domid, XEN_DOMCTL_SHADOW_OP_PEEK, - &ctx->save.dirty_bitmap_hbuf, ctx->save.p2m_size, - NULL, 0, &stats) !=3D ctx->save.p2m_size ) - { - PERROR("Failed to retrieve logdirty bitmap"); - rc =3D -1; - goto out; - } - - DPRINTF(" Further stats: faults %u, dirty %u", - stats.fault_count, stats.dirty_count); - - out: - return rc; -} - /* * Send all domain memory. This is the heart of the live migration loop. */ @@ -761,13 +726,6 @@ static int send_domain_memory_live(struct xc_sr_contex= t *ctx) if ( rc ) goto out; =20 - if ( ctx->save.debug ) - { - rc =3D verify_frames(ctx); - if ( rc ) - goto out; - } - out: return rc; } @@ -1005,7 +963,6 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint3= 2_t dom, /* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions.= */ ctx.save.callbacks =3D callbacks; ctx.save.live =3D !!(flags & XCFLAGS_LIVE); - ctx.save.debug =3D !!(flags & XCFLAGS_DEBUG); ctx.save.recv_fd =3D recv_fd; =20 if ( xc_domain_getinfo(xch, dom, 1, &ctx.dominfo) !=3D 1 ) From nobody Tue May 7 10:55:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162256400415828.92210031290699; Tue, 1 Jun 2021 09:13:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.135019.251196 (Exim 4.92) (envelope-from ) id 1lo70v-0000Jl-Eq; Tue, 01 Jun 2021 16:13:09 +0000 Received: by outflank-mailman (output) from mailman id 135019.251196; Tue, 01 Jun 2021 16:13:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70v-0000Je-Bm; Tue, 01 Jun 2021 16:13:09 +0000 Received: by outflank-mailman (input) for mailman id 135019; Tue, 01 Jun 2021 16:13:08 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lo70R-0005X1-1E for xen-devel@lists.xenproject.org; Tue, 01 Jun 2021 16:12:39 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.173]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c58b872c-705e-46c7-a4aa-94a90b0c6dcb; Tue, 01 Jun 2021 16:11:47 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.27.2 AUTH) with ESMTPSA id j0415bx51GBg1Bi (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 1 Jun 2021 18:11:42 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c58b872c-705e-46c7-a4aa-94a90b0c6dcb ARC-Seal: i=1; a=rsa-sha256; t=1622563902; cv=none; d=strato.com; s=strato-dkim-0002; b=K7MnlPHaXmu4fU5RlfPrsnOzwcPTcmOAWCvSh+ooAre1bwTpwi4eMMGz/5Jv1Ig1ZW JloAzpPSnJnclTW4wr7Ytk8bLdATSBiQRhf3LpoxulBCdjGwn8fEikIu6++kaZ7sPHfq m9GFIxxfgtPMPPVdJKFpa2B/70/RZ3tKv/8obUaj1nj6W5e7me+PNZCLyOUaoqBecAnP C+C45/54baeVovaLeEH1v31apfihBaozH7X9mlU0glNcddolHxmNutWRvmEqNjiEttZy Fojaz3PuVQbehB5xyP8qO3zAvTPyTuNNoFDakouqC8rrm+uP5B2S4r6HMpOWkvv7a9a9 Fklw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563902; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=fttDAmpegUqwpOBB61SFRLpHBJB9wPmVo+V4iKyUqQw=; b=ZKo6xL4wFzjwUtYQMxZLthEnX/2j4XXU+ET8fslQ8JqjAiO9jlMLLDaX7tNV/rIito YSjbAKL+Lgd9rhcCBSKycTE/JI+vMKvhm2LCur4Zyxg0TZeUGyGVDBoeri5jHWzi+v8m 5uGj4AhoMJH1/UpyRd+ABqMeblXCauuk+Qnxu4g4en0FXc8YE536ZPSMNgxEPJ7EA5vB NtOn+kHn36uvexNqpQEWuZkcJfaru5vXOE5Xoup/d/KePoFZOqJoZFV2HxvZehI7SvEX W6W8XvN3C4y2+CfoOWniMWikvjXytRwbvQo80fTUHzxDYBzxgh5qWXM/941Fm3bd1Yeq EMfg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1622563902; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=fttDAmpegUqwpOBB61SFRLpHBJB9wPmVo+V4iKyUqQw=; b=ShTWQZKcQxZ1sfebsNAw3YaYcPQB1WYhFoM850GJhLl8wmQwEfctVTPf+8YlicvXTj VlDW3wj8vaW/oiD6NQm1ua1hkBTsrESScVeGdK9/qnZ6IAKgoLi2QrU71IgL5R7JKqFu SOZBrr9BV/XYgYN2PZBWv8VWy+NnFnwL8tTBdr2BjS8LjSr9CCPjYjQlWHTpZY/Qwz4s uJ6yIZ97QLzsAjNs79CzpqBfvtk8o1P3YfO2jfbA8fkwYPLd4ggLTjuAP2/hUahRWXzu 6mIhBdYVJTtX9k2p+5OPkdMh21UKzH2P1Dk4KdBAkWGepZutG7i3uFqQ9drAKLmYKjln lsCw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210601 38/38] hotplug/Linux: fix starting of xenstored with restarting systemd Date: Tue, 1 Jun 2021 18:11:18 +0200 Message-Id: <20210601161118.18986-39-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210601161118.18986-1-olaf@aepfle.de> References: <20210601161118.18986-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A hard to trigger race with another unrelated systemd service and xenstored.service unveiled a bug in the way how xenstored is launched with systemd. launch-xenstore may start either a daemon or a domain. In case a domain is used, systemd-notify was called. If another service triggered a restart of systemd while xenstored.service was executed, systemd may temporary lose track of services with Type=3Dnotify. As a result, xenstored.service would be marked as failed and units that depend on it will not be started. This breaks the enire Xen toolstack. The chain of events is basically: xenstored.service sends the notification to systemd, this is a one-way event. Then systemd may be restarted by the other unit. During this time, xenstored.service is done and exits. Once systemd is done with its restart, it collects the pending notifications and childs. If it does not find the unit which sent the notification it will declare it as failed. A workaround for this scenario is to leave the child processes running for a short time after sending the "READY=3D1" notification. If systemd happens to restart it will still find the unit it launched. Adjust the callers of launch-xenstore to specifiy the init system: Do not fork xenstored with systemd, preserve pid. This wil also avoid the need for a sleep because the process which sent the "READY=3D1" (the previously forked child) is still alive. Remove the --pid-file in the systemd case because the pid of the child is known, and the file had probably little effect anyway due to lack of PidFile=3D and Type=3Dforking in the unit file. Be verbose about xenstored startup only with sysv to avoid interleaved output in systemd journal. Do the same also for domain case, even if is not strictly needed because init-xenstore-domain has no output. The fix for upstream systemd which is supposed to fix it: 575b300b795b6 ("pid1: rework how we dispatch SIGCHLD and other signals") Signed-off-by: Olaf Hering -- v04: - do mkdir unconditionally because init-xenstore-domain writes the domid to xenstored.pid v03: - remove run_xenstored function, follow style of shell built-in test functi= on v02: - preserve Type=3Dnotify --- tools/hotplug/Linux/init.d/xencommons.in | 2 +- tools/hotplug/Linux/launch-xenstore.in | 40 ++++++++++++++----- .../Linux/systemd/xenstored.service.in | 2 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/tools/hotplug/Linux/init.d/xencommons.in b/tools/hotplug/Linux= /init.d/xencommons.in index 7fd6903b98..dcb0ce4b73 100644 --- a/tools/hotplug/Linux/init.d/xencommons.in +++ b/tools/hotplug/Linux/init.d/xencommons.in @@ -60,7 +60,7 @@ do_start () { mkdir -m700 -p ${XEN_LOCK_DIR} mkdir -p ${XEN_LOG_DIR} =20 - @XEN_SCRIPT_DIR@/launch-xenstore || exit 1 + @XEN_SCRIPT_DIR@/launch-xenstore 'sysv' || exit 1 =20 echo Setting domain 0 name, domid and JSON config... ${LIBEXEC_BIN}/xen-init-dom0 ${XEN_DOM0_UUID} diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/l= aunch-xenstore.in index 019f9d6f4d..d40c66482a 100644 --- a/tools/hotplug/Linux/launch-xenstore.in +++ b/tools/hotplug/Linux/launch-xenstore.in @@ -15,6 +15,17 @@ # License along with this library; If not, see . # =20 +initd=3D$1 + +case "$initd" in + sysv) nonl=3D'-n' ;; + systemd) nonl=3D ;; + *) + echo "first argument must be 'sysv' or 'systemd'" + exit 1 + ;; +esac + XENSTORED=3D@XENSTORED@ =20 . @XEN_SCRIPT_DIR@/hotplugpath.sh @@ -44,14 +55,16 @@ timeout_xenstore () { return 0 } =20 -test_xenstore && exit 0 +mkdir -p @XEN_RUN_DIR@ + +if test "$initd" =3D 'sysv' ; then + test_xenstore && exit 0 +fi =20 test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFI= G_LEAF_DIR@/xencommons =20 [ "$XENSTORETYPE" =3D "" ] && XENSTORETYPE=3Ddaemon =20 -/bin/mkdir -p @XEN_RUN_DIR@ - [ "$XENSTORETYPE" =3D "daemon" ] && { [ -z "$XENSTORED_TRACE" ] || XENSTORED_ARGS=3D"$XENSTORED_ARGS -T @XEN_LO= G_DIR@/xenstored-trace.log" [ -z "$XENSTORED" ] && XENSTORED=3D@XENSTORED@ @@ -59,13 +72,15 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . = @CONFIG_DIR@/@CONFIG_LEAF echo "No xenstored found" exit 1 } + [ "$initd" =3D 'sysv' ] && { + echo $nonl Starting $XENSTORED... + $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS + timeout_xenstore $XENSTORED || exit 1 + exit 0 + } =20 - echo -n Starting $XENSTORED... - $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS - - systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exi= t 1 - - exit 0 + exec $XENSTORED -N $XENSTORED_ARGS + exit 1 } =20 [ "$XENSTORETYPE" =3D "domain" ] && { @@ -75,9 +90,12 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @= CONFIG_DIR@/@CONFIG_LEAF XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_DOMAIN_ARGS --memory $XENSTORE_DOMAIN_S= IZE" [ -z "$XENSTORE_MAX_DOMAIN_SIZE" ] || XENSTORE_DOMAIN_ARGS=3D"$XENSTORE_D= OMAIN_ARGS --maxmem $XENSTORE_MAX_DOMAIN_SIZE" =20 - echo -n Starting $XENSTORE_DOMAIN_KERNEL... + echo $nonl Starting $XENSTORE_DOMAIN_KERNEL... ${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS || exit 1 - systemd-notify --ready 2>/dev/null + [ "$initd" =3D 'systemd' ] && { + systemd-notify --ready + sleep 9 + } =20 exit 0 } diff --git a/tools/hotplug/Linux/systemd/xenstored.service.in b/tools/hotpl= ug/Linux/systemd/xenstored.service.in index 80c1d408a5..c226eb3635 100644 --- a/tools/hotplug/Linux/systemd/xenstored.service.in +++ b/tools/hotplug/Linux/systemd/xenstored.service.in @@ -11,7 +11,7 @@ Type=3Dnotify NotifyAccess=3Dall RemainAfterExit=3Dtrue ExecStartPre=3D/bin/grep -q control_d /proc/xen/capabilities -ExecStart=3D@XEN_SCRIPT_DIR@/launch-xenstore +ExecStart=3D@XEN_SCRIPT_DIR@/launch-xenstore 'systemd' =20 [Install] WantedBy=3Dmulti-user.target