From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133422981548.2196532340549; Thu, 1 Jul 2021 02:57:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148340.274177 (Exim 4.92) (envelope-from ) id 1lytRE-0005A7-3k; Thu, 01 Jul 2021 09:56:52 +0000 Received: by outflank-mailman (output) from mailman id 148340.274177; Thu, 01 Jul 2021 09:56:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRD-00059G-Vx; Thu, 01 Jul 2021 09:56:51 +0000 Received: by outflank-mailman (input) for mailman id 148340; Thu, 01 Jul 2021 09:56:50 +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 1lytRC-0004XT-RV for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:56:50 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [81.169.146.220]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 42f4d1d9-810f-4e51-9cb2-0241aa5f3c98; Thu, 01 Jul 2021 09:56:45 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ud5Mc (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: 42f4d1d9-810f-4e51-9cb2-0241aa5f3c98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133399; 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=fdQxUB5TzFIqwLyw1ED69LqOX2s3AglEWwdkPeuOY77rvPZXAxr7oyaDtElA5HaxG/ wS4anPwPRoe21WhiTF4NF0UDQSEKY7xlfvJw7NXq++Z9tsjtnxn9L+wTxPpvsjWyCYY1 gj6tzo/roDRzABQgRJeCYDoQATMedXnZpQP5EKFKV2vFg6HLn4TUmAmG2veH10UyyQf1 q1TuYC6yjJViUCZYU4mLKxw5Pkx9s1D6mmfKWG79qHBTdITAd+/XNTFo1o8mvrJ28bMV MRN/8q40YmRXsYRxxjPbfVO9tfzSzVT3bz6iZDk/z43VEwtGyk5Wi5AUta6onqy0C4DV QNNg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210701 01/40] hotplug/Linux: fix starting of xenstored with restarting systemd Date: Thu, 1 Jul 2021 11:55:56 +0200 Message-Id: <20210701095635.15648-2-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133420198239.04991482664627; Thu, 1 Jul 2021 02:57:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148338.274154 (Exim 4.92) (envelope-from ) id 1lytR9-0004YZ-Gu; Thu, 01 Jul 2021 09:56:47 +0000 Received: by outflank-mailman (output) from mailman id 148338.274154; Thu, 01 Jul 2021 09:56:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytR9-0004YQ-DP; Thu, 01 Jul 2021 09:56:47 +0000 Received: by outflank-mailman (input) for mailman id 148338; Thu, 01 Jul 2021 09:56:45 +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 1lytR7-0004XT-T6 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:56:45 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.50]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 94438a9c-bd82-4226-aad3-be2c35a408c7; Thu, 01 Jul 2021 09:56:45 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ue5Md (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: 94438a9c-bd82-4226-aad3-be2c35a408c7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133400; 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=DqV9Bza4xh4lmngXwj1J3LSRM3kpJQsPapKBO4Z/YvI=; b=qRRlDNFKwfDufQp5NUYrSrgtwMMfk6ATaFHjiH2amRD/NqCWF8dxxGWit6C8hcwGvg PY3/9ws3knYQO0b3lWTEK/A+csdqAk7ICvmTYNqADEesAA13Ryhnwo+BmJNb5LIzXrPz EKYRdzSJjdYT8BsvqMfD9JPD3+lLP589pKAvCUuKDpgmSUV/JW2P64aAeLvixE6CYdYi U7sPBkFcM9v9OjhSZXzDnc7W70rQIhHTfBrmSVJtviidhqsSSP6FQOLraTibzvWbejf1 Lib5d04DrwkNqIB50v5EgtPSt8d69WXfc30eQ2ehB57NnrZlLuZxPxnveDllsQDjy2sY NMbg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 02/40] tools: add API to work with sevaral bits at once Date: Thu, 1 Jul 2021 11:55:57 +0200 Message-Id: <20210701095635.15648-3-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 multiple 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 v02: - change return type from int to bool (jgross) --- tools/libs/ctrl/xc_bitops.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h index f0bac4a071..8e8c6efb45 100644 --- a/tools/libs/ctrl/xc_bitops.h +++ b/tools/libs/ctrl/xc_bitops.h @@ -3,6 +3,7 @@ =20 /* bitmap operations for single threaded access */ =20 +#include #include #include =20 @@ -77,4 +78,31 @@ static inline void bitmap_or(void *_dst, const void *_ot= her, dst[i] |=3D other[i]; } =20 +static inline bool test_bit_long_set(unsigned long nr_base, const void *_a= ddr) +{ + const unsigned long *addr =3D _addr; + unsigned long val =3D addr[nr_base / BITS_PER_LONG]; + + return val =3D=3D ~0; +} + +static inline bool 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133435208690.2234205299316; Thu, 1 Jul 2021 02:57:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148346.274210 (Exim 4.92) (envelope-from ) id 1lytRO-0006X7-9B; Thu, 01 Jul 2021 09:57:02 +0000 Received: by outflank-mailman (output) from mailman id 148346.274210; Thu, 01 Jul 2021 09:57:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRO-0006Wq-4t; Thu, 01 Jul 2021 09:57:02 +0000 Received: by outflank-mailman (input) for mailman id 148346; Thu, 01 Jul 2021 09:57: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 1lytRM-0004XT-Rr for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:00 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.50]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ef2dd189-357d-4b4a-8416-ff4c5bf7bfa6; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ue5Mg (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: ef2dd189-357d-4b4a-8416-ff4c5bf7bfa6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133400; 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=WwrXv/hX+8hePyd4mOYFfrU0MUgrTtUZ8Gjzx55scrs=; b=X40nb9sxbjnVV1nAwDlmHOrl3IpT3EDdb5MM+s5mXJNeggyrJFdvy4UKL79A3twwkP +GgMYKeLI2azO1neoyTzxlVOnk4/L2Gy7xZCGEEfkoeofS2KIvBh4UFk1X9JGrcFjxW2 45NQz5Q3u3KT+4TDeSyj8jS5AHNlDWtvHGbSorrR8r2ziEFd6zVLf0rxEpnDsEjIBAib 9ktCG0zE9JmsWZSW0RCrX4SrSXe9uf3UfgFfkCzRXivSBfRt8vg/CRdyJSzCJmna5Gks j7aivrJk7fEaB7AbSpFZzedvlaKaj1bNHamNVOGR0IiRVI+wY/CfzsFZnFhxU5bmbseQ DpUQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v20210701 03/40] xl: fix description of migrate --debug Date: Thu, 1 Jul 2021 11:55:58 +0200 Message-Id: <20210701095635.15648-4-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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. The code in xc_domain_save is the consumer of this knob, but it considers it only for the remus and colo case. Adjust the help text to tell what --debug does today: Nothing. Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross v02: - the option has no effect anymore Acked-by: Anthony PERARD --- docs/man/xl.1.pod.in | 2 +- tools/xl/xl_cmdtable.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index e2176bd696..70a6ebf438 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -481,7 +481,7 @@ domain. =20 =3Ditem B<--debug> =20 -Display huge (!) amount of debug information during the migration process. +This option has no effect. It is preserved for compatibility reasons. =20 =3Ditem B<-p> =20 diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 661323d488..ca1dfa3525 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 Ignored.\n" "-p Do not unpause domain after migrating it.\n" "-D Preserve the domain id" }, From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133430332580.9372510547731; Thu, 1 Jul 2021 02:57:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148341.274188 (Exim 4.92) (envelope-from ) id 1lytRG-0005VQ-Ex; Thu, 01 Jul 2021 09:56:54 +0000 Received: by outflank-mailman (output) from mailman id 148341.274188; Thu, 01 Jul 2021 09:56: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 1lytRG-0005V9-Am; Thu, 01 Jul 2021 09:56:54 +0000 Received: by outflank-mailman (input) for mailman id 148341; Thu, 01 Jul 2021 09:56:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRE-0004r4-FY for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:56:52 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.51]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dab754d8-b797-494a-b08a-c551f11e7521; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ue5Mh (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: dab754d8-b797-494a-b08a-c551f11e7521 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133401; 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=7VCnrhtz6PkcA6hU43Dz4SRyiupndGcq7UxNqTELglw=; b=Qn1iK4PuvrSQRmBbDFH3T3UsDMsI+qEEMBs1jKHvz2iCrUS7YTnMSloI4wNLXg9N8K xynwKO4T4U863Sc2tP5Oluf6xC3SY7p41f1WZFwVEqeKgQbNwCjmJLa1lcvXpDxusejM lHflf7IPDlNibxhWELktw0CVFMUwe794DPg32iF/4E2rdXLUAzBJTl7vYWS4efGoDDY8 ae7qn5EG4Z+SKtc0cw4+d5w/z1vdqx6DdwXRL0N9QgWIW/AWl7WLs0he0k5kZ0jmIMJk qyoNWj82+xBpLqYO4UqvAHveEftafbJUjsuFUEesN2p2VbfNiwHpsAWd7GPOcoG+pT5L D9qw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu Subject: [PATCH v20210701 04/40] tools: use integer division in convert-legacy-stream Date: Thu, 1 Jul 2021 11:55:59 +0200 Message-Id: <20210701095635.15648-5-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 single slash gives a float, a double slash gives an int. bitmap =3D unpack_exact("Q" * ((max_id/64) + 1)) TypeError: can't multiply sequence by non-int of type 'float' Signed-off-by: Olaf Hering v02: - import division to remain compatible with python2.7 (andrew) - white space in max_id chunk (andrew) Reviewed-by: Andrew Cooper --- tools/python/scripts/convert-legacy-stream | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/python/scripts/convert-legacy-stream b/tools/python/scri= pts/convert-legacy-stream index ca93a93848..66ee3d2f5d 100755 --- a/tools/python/scripts/convert-legacy-stream +++ b/tools/python/scripts/convert-legacy-stream @@ -6,6 +6,7 @@ Convert a legacy migration stream to a v2 stream. """ =20 from __future__ import print_function +from __future__ import division =20 import sys import os, os.path @@ -163,7 +164,7 @@ def write_libxc_hvm_params(params): raise RuntimeError("Expected even length list of hvm parameters") =20 write_record(libxc.REC_TYPE_hvm_params, - pack(libxc.HVM_PARAMS_FORMAT, len(params) / 2, 0), + pack(libxc.HVM_PARAMS_FORMAT, len(params) // 2, 0), pack("Q" * len(params), *params)) =20 def write_libxc_static_data_end(): @@ -264,8 +265,8 @@ def read_pv_extended_info(vm): (so_far - total_length, )) =20 def read_pv_p2m_frames(vm): - fpp =3D 4096 / vm.width - p2m_frame_len =3D (vm.p2m_size - 1) / fpp + 1 + fpp =3D 4096 // vm.width + p2m_frame_len =3D (vm.p2m_size - 1) // fpp + 1 =20 info("P2M frames: fpp %d, p2m_frame_len %d" % (fpp, p2m_frame_len)) write_libxc_pv_p2m_frames(vm, unpack_ulongs(p2m_frame_len)) @@ -405,7 +406,7 @@ def read_chunks(vm): (max_id, legacy.MAX_VCPU_ID)) =20 vm.max_vcpu_id =3D max_id - bitmap =3D unpack_exact("Q" * ((max_id/64) + 1)) + bitmap =3D unpack_exact("Q" * ((max_id // 64) + 1)) =20 for idx, word in enumerate(bitmap): bit_idx =3D 0 From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162513344965618.164844578000952; Thu, 1 Jul 2021 02:57:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148357.274276 (Exim 4.92) (envelope-from ) id 1lytRd-0001BI-AD; Thu, 01 Jul 2021 09:57:17 +0000 Received: by outflank-mailman (output) from mailman id 148357.274276; Thu, 01 Jul 2021 09:57: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 1lytRd-0001Az-4G; Thu, 01 Jul 2021 09:57:17 +0000 Received: by outflank-mailman (input) for mailman id 148357; Thu, 01 Jul 2021 09:57:15 +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 1lytRb-0004XT-Rv for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:15 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c2f72f25-cc87-4aca-9cb6-6f6e2dcd9778; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uf5Mi (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: c2f72f25-cc87-4aca-9cb6-6f6e2dcd9778 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133401; 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=tMf89Ke5Bo6A5Pju27XJS58XTaKNVAzyOo/JUVzZcLo=; b=nWvRnJWLur55V1tgXMbgxhtwgiY/CRv+DqprRK4PbMxuavZgH5yfVh6Ft1q6K0pILK ukoX/5a8uZ1sWLc2Dl59Eo1P8rfuFG5CeX1tkPuaiO1Yp13sffMDQCoXL9BtIc88MGxC xaewNcFmtlO6jV0QGeHsyjupGZkh3fhdXtuAVgjL9vjObeMtg+zcORScKLD9Q3q0aIG8 mWLyRU+I9vvlWbHwTxEK9ZiwmNdPdaf07uDSeTPf1nAr36mF38LC/W0irQXludbzbgZW 6zJkmdBGWIhWfs1EdSfjDEE9mss+4Zk9z3hGYyssgufhn2QBpe2er1jvzpcmJYqZ+/2W oLhw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu Subject: [PATCH v20210701 05/40] tools: handle libxl__physmap_info.name properly in convert-legacy-stream Date: Thu, 1 Jul 2021 11:56:00 +0200 Message-Id: <20210701095635.15648-6-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 trailing member name[] in libxl__physmap_info is written as a cstring into the stream. The current code does a sanity check if the last byte is zero. This attempt fails with python3.4 because name[-1] returns a type int. As a result the comparison with byte(\00) fails: File "/usr/lib/xen/bin/convert-legacy-stream", line 347, in read_libxl_to= olstack raise StreamError("physmap name not NUL terminated") StreamError: physmap name not NUL terminated To handle both python variants the cstring is unpacked into the actual string and the trailing nil. Signed-off-by: Olaf Hering --- tools/python/scripts/convert-legacy-stream | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/python/scripts/convert-legacy-stream b/tools/python/scri= pts/convert-legacy-stream index 66ee3d2f5d..9003ac4f6d 100755 --- a/tools/python/scripts/convert-legacy-stream +++ b/tools/python/scripts/convert-legacy-stream @@ -336,20 +336,21 @@ def read_libxl_toolstack(vm, data): if len(data) < namelen: raise StreamError("Remaining data too short for physmap name") =20 - name =3D data[:namelen] + c_string =3D data[:namelen] data =3D data[namelen:] =20 # Strip padding off the end of name if twidth =3D=3D 64: - name =3D name[:-4] + c_string =3D c_string[:-4] =20 - if name[-1] !=3D b'\x00': + name, nil =3D unpack("=3D{0}sB".format(len(c_string) - 1), c_strin= g) + if nil !=3D 0: raise StreamError("physmap name not NUL terminated") =20 root =3D b"physmap/%x" % (phys, ) kv =3D [root + b"/start_addr", b"%x" % (start, ), root + b"/size", b"%x" % (size, ), - root + b"/name", name[:-1]] + root + b"/name", name] =20 for key, val in zip(kv[0::2], kv[1::2]): info(" '%s' =3D '%s'" % (key.decode(), val.decode())) From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133427633422.66634162212927; Thu, 1 Jul 2021 02:57:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148342.274199 (Exim 4.92) (envelope-from ) id 1lytRI-0005tF-Ra; Thu, 01 Jul 2021 09:56:56 +0000 Received: by outflank-mailman (output) from mailman id 148342.274199; Thu, 01 Jul 2021 09:56:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRI-0005su-My; Thu, 01 Jul 2021 09:56:56 +0000 Received: by outflank-mailman (input) for mailman id 148342; Thu, 01 Jul 2021 09:56:55 +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 1lytRH-0004XT-RY for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:56:55 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 13d81159-b2fa-4d56-9e43-7e36d5b2af87; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uf5Mk (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: 13d81159-b2fa-4d56-9e43-7e36d5b2af87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133402; 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=w7dbe+kbBj9TSW8hk0eL96KxDDaP2dTnYnGMLgLRSqI=; b=SbESxQvE2mOzRcBik9DJArk5eOy7F3cFOwsCKAO0xVAbzKozcTyr7yCt2b8XIKrhvp Xc/2AXKIaE8g2517el7vNKDDYcoSVXWrA3tjowsgWUtH/OngnWswcKSg8PaSrx+fiR5L 4yRhX2EsZQ1zVKqBbgdpB/vBBHHxtibQuWigSmEEQcykJQG574C3X/NXucFLBMVFwsqc YmInlN/HOO7a0dPfKtyunjZqtkBKWBTw4SEzAX7k8mF5vBlYnW2F98RP+6rORfNVMRwt D8vYCLwcc2rQ3GEa+8HjeB+O4HK5k45zu5fGzCi4mWLTli5Qq/O5mSFVKiO2vLcdVaar aggw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu Subject: [PATCH v20210701 06/40] tools: fix Python3.4 TypeError in format string Date: Thu, 1 Jul 2021 11:56:01 +0200 Message-Id: <20210701095635.15648-7-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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" Using the first element of a tuple for a format specifier fails with python3.4 as included in SLE12: b =3D b"string/%x" % (i, ) TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple' It happens to work with python 2.7 and 3.6. Use a syntax that is handled by all three variants. Signed-off-by: Olaf Hering --- tools/python/scripts/convert-legacy-stream | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/python/scripts/convert-legacy-stream b/tools/python/scri= pts/convert-legacy-stream index 9003ac4f6d..235b922ff5 100755 --- a/tools/python/scripts/convert-legacy-stream +++ b/tools/python/scripts/convert-legacy-stream @@ -347,9 +347,9 @@ def read_libxl_toolstack(vm, data): if nil !=3D 0: raise StreamError("physmap name not NUL terminated") =20 - root =3D b"physmap/%x" % (phys, ) - kv =3D [root + b"/start_addr", b"%x" % (start, ), - root + b"/size", b"%x" % (size, ), + root =3D bytes(("physmap/%x" % phys).encode('utf-8')) + kv =3D [root + b"/start_addr", bytes(("%x" % start).encode('utf-8'= )), + root + b"/size", bytes(("%x" % size).encode('utf-8')), root + b"/name", name] =20 for key, val in zip(kv[0::2], kv[1::2]): From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133749196877.7149055531269; Thu, 1 Jul 2021 03:02:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148463.274479 (Exim 4.92) (envelope-from ) id 1lytWP-00051S-R2; Thu, 01 Jul 2021 10:02:13 +0000 Received: by outflank-mailman (output) from mailman id 148463.274479; Thu, 01 Jul 2021 10:02:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWP-0004zr-Dc; Thu, 01 Jul 2021 10:02:13 +0000 Received: by outflank-mailman (input) for mailman id 148463; Thu, 01 Jul 2021 10:02:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytSW-0004r4-IF for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:12 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 323d7809-47e8-408f-a235-91f0414dce21; Thu, 01 Jul 2021 09:57:03 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ug5Mm (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56: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: 323d7809-47e8-408f-a235-91f0414dce21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133402; 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=NHXITGMwQK1fkhH9Z9SjS8KzA+TTnDL8//gJ5t70QPA=; b=oluRZMKVNr1Zr0vhtJJwgqz8JuGf78CLNRObGsF4RqcuV82oxD1XP1eNN8wAw+CV4M dcN1wT3qh1k2ufVHGmHEIx478TqNCH4DJ4f6bng+a8up24s5qVcFd5l6Y1He0c5J3mre KFeeHmun3oOJ7LlzpeqigPFAFU3zmIJTKBPglniKNsG+Wkp25kjh8r5zve0GlqYOcjqf zC11EWYYjCRHRgzuCBs7Oh2L6QCYoCGHrgN5c3VK9dSaktijG5vsnI1q+FgoAxpyd8ya JQ74oXqHoAsYpHM+/Vyl1lg2VJgkh98zybLEqvyKomHyojbKH024tHzCpCLAPxF+Su52 Ob+Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" 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 , Juergen Gross , Anthony PERARD Subject: [PATCH v20210701 07/40] tools: create libxensaverestore Date: Thu, 1 Jul 2021 11:56:02 +0200 Message-Id: <20210701095635.15648-8-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 redundant xg_sr_ filename prefix. Signed-off-by: Olaf Hering Acked-by: Wei Liu v6: - fix build of nomigrate.c v5: - fix spelling in description 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} | 2 +- .../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, 283 insertions(+), 218 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} (98%) 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 61d0a82f48..7417675b3b 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 2ce92d247e..4cf5459bb1 100644 --- a/tools/libs/guest/Makefile +++ b/tools/libs/guest/Makefile @@ -11,18 +11,7 @@ SRCS-y +=3D xg_domain.c SRCS-y +=3D xg_suspend.c SRCS-y +=3D xg_resume.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 SRCS-y +=3D xg_core.c SRCS-$(CONFIG_X86) +=3D xg_core_x86.c diff --git a/tools/libs/guest/xg_offline_page.c b/tools/libs/guest/xg_offli= ne_page.c index cfe0e2d537..92b65243b1 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 0b4671318c..439c654733 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 e2994e18ac..ca2eb47a4f 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 c0acf00f90..cfe1b24bed 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 98% rename from tools/libs/guest/xg_nomigrate.c rename to tools/libs/saverestore/nomigrate.c index 6795c62ddc..67e58d353a 100644 --- a/tools/libs/guest/xg_nomigrate.c +++ b/tools/libs/saverestore/nomigrate.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include =20 int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t fl= ags, struct save_callbacks *callbacks, 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 2ba7c3200c..ae3e8797d0 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133440094704.3150951560225; Thu, 1 Jul 2021 02:57:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148353.274241 (Exim 4.92) (envelope-from ) id 1lytRU-0007sC-Nc; Thu, 01 Jul 2021 09:57:08 +0000 Received: by outflank-mailman (output) from mailman id 148353.274241; Thu, 01 Jul 2021 09:57:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRU-0007rS-Gg; Thu, 01 Jul 2021 09:57:08 +0000 Received: by outflank-mailman (input) for mailman id 148353; Thu, 01 Jul 2021 09:57:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRT-0004r4-Fz for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:07 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 05bcbd22-3dea-4a3b-a0ca-18bda5380d99; Thu, 01 Jul 2021 09:56:54 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uh5Mn (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:43 +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: 05bcbd22-3dea-4a3b-a0ca-18bda5380d99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133403; 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=+KbVruLtdIEtwG93Soc7D+UJBCIYv9cMILQskmOXes4=; b=D7SisCzfa2rafDqJS+Cmj1d+KIdVX6sD5wo/ADBI8YzE11YqWd4yX3vfLjVoUlZz7t D+JpnF79BDH8B8kztS+G+l95eXmYfQTfZF5WjWSLWJmH/Q0gfRaDOKbbOikCdMgX4yDG 46MaGdrgIep0sk9B/gYuRl/tg0ygFUZuzOUnK/X/4Wgp0fZXtDveil6JgzMfdQtQem8P f+k6PAwPyg+ZJlN1kEJsoWTOzHYhaxQ6SmhcXEFSFMmcPPPPiBLgT58+El2Qb0ZtCU83 taMYjCtjJx8tRQQwNAjSvtc/AYJdDlHRikICCtf/mpzPsNc3z5bLy/4Hy0nqF9Bl0+rt kMJQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v20210701 08/40] MAINTAINERS: add myself as saverestore maintainer Date: Thu, 1 Jul 2021 11:56:03 +0200 Message-Id: <20210701095635.15648-9-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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" I touched it last. Signed-off-by: Olaf Hering --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8a52a03969..36dc634958 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -381,6 +381,12 @@ R: Juergen Gross S: Supported F: tools/libs/ =20 +LIBSAVERESTORE: +M: Olaf Hering +S: Supported +F: tools/include/xensaverestore.h +F: tools/libs/saverestore/ + LIBXENLIGHT M: Ian Jackson M: Wei Liu From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133423894243.60602638434636; Thu, 1 Jul 2021 02:57:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148339.274166 (Exim 4.92) (envelope-from ) id 1lytRC-0004sG-Qj; Thu, 01 Jul 2021 09:56:50 +0000 Received: by outflank-mailman (output) from mailman id 148339.274166; Thu, 01 Jul 2021 09:56:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRC-0004s5-MR; Thu, 01 Jul 2021 09:56:50 +0000 Received: by outflank-mailman (input) for mailman id 148339; Thu, 01 Jul 2021 09:56:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRB-0004r4-QC for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:56:49 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d52abfb2-6848-46b5-b4ea-10d4ede7358d; Thu, 01 Jul 2021 09:56:48 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uh5Mo (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:43 +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: d52abfb2-6848-46b5-b4ea-10d4ede7358d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133403; 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=SltAKnmIMSX68HfayYsjFaeam+P2Dd+kaJUi7g+KP5U=; b=Ac4RxG/KTWjphnMXvXeZe9Akw4GLKnElRV50Qy3tRHtyTCIYoYa4Zj4bN5ByvSjvSy bw21oNTVatYIeDyRIlVEzlXbUChDoKdsc9vk8hSCxguIR/l6q7SgLR9P09GAGOBFo4vI j6nKrYiBc+ORocgKs7brvWg92wxRNwc8TMHrPaFIV5Q3ylbqqfN2oZc/pa3PGhFyOG5X bQTbVug0Qb3oCkcLQPbTqXSkF7EFmkAeKbuP2l4C13yXi5h4zxLBApYT6PCEkflFBs/g RQDw9XHuyoBFp5lu7vhTdIKoqFicS2utbnCiMpvgRaLDJbESEVru0jZYgc1/ajfNzQbB 26dQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 09/40] tools: add readv_exact to libxenctrl Date: Thu, 1 Jul 2021 11:56:04 +0200 Message-Id: <20210701095635.15648-10-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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. Short reads are the common case, finish the trailing iov with read_exact. Signed-off-by: Olaf Hering v2: - add comment to short-read handling --- tools/libs/ctrl/xc_private.c | 57 +++++++++++++++++++++++++++++++++++- tools/libs/ctrl/xc_private.h | 1 + 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index c0422662f0..bab9a31a70 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -698,8 +698,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; @@ -714,6 +729,46 @@ 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; + } + + /* Finish a potential short read in the last iov */ + 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 3e299b943f..66086ef19f 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -410,6 +410,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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133448822476.35548693123826; Thu, 1 Jul 2021 02:57:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148355.274253 (Exim 4.92) (envelope-from ) id 1lytRZ-0000I3-17; Thu, 01 Jul 2021 09:57:13 +0000 Received: by outflank-mailman (output) from mailman id 148355.274253; Thu, 01 Jul 2021 09:57:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRY-0000Hk-S9; Thu, 01 Jul 2021 09:57:12 +0000 Received: by outflank-mailman (input) for mailman id 148355; Thu, 01 Jul 2021 09:57:10 +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 1lytRW-0004XT-Rt for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:10 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c60b6e97-d7a6-4b2a-a322-8cfde3b17073; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ui5Mq (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:44 +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: c60b6e97-d7a6-4b2a-a322-8cfde3b17073 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133404; 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=deA9YRVAOQ9im7B/3eOo3ZnuGujRxb1REyjDaCpxsfY=; b=ArRTIdul3rn/jRUBaAMtWUjGSvhOeN0c6D25JquFZzJlpSlu3P2UqIQYqBDbCGwQAz 4LQUy0Vg4i+wmTHxvFW3F1mxWXSmwNyv4jBz2FdL/n0FQSUrqpwJpGPp0bizAWHIt+vt dMw4APZU8EWIUaL+/xg5WdwEJ1qtIkIMhmqSYLDyBUVBhGziDzlUmEDAwwUsE/cjScCE grgpPzR7B/03fXb8fsN40E+jlWIerDK/UKoGHqjifE64ierjRRJUk3vnT3w/O/yVx9+L 2/46uUjfv/wGpTz9lN4C6WCm9VkWRVKsDTjqgd0C+n0hB/D3mrf56htE97a8wolGbWzs s+gg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 10/40] tools: add xc_is_known_page_type to libxenctrl Date: Thu, 1 Jul 2021 11:56:05 +0200 Message-Id: <20210701095635.15648-11-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 v02: - rename xc_is_known_page_type to sr_is_known_page_type - move from ctrl/xc_private.h to saverestore/common.h (jgross) --- tools/libs/saverestore/common.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index ca2eb47a4f..07c506360c 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -467,6 +467,39 @@ 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 +/* Sanitiy check for types returned by Xen */ +static inline bool sr_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: /* Synthetic type in Xen 4.2 - 4.5 */ + case XEN_DOMCTL_PFINFO_BROKEN: + ret =3D true; + break; + default: + ret =3D false; + break; + } + return ret; +} + #endif /* * Local variables: From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133438898286.1690938893911; Thu, 1 Jul 2021 02:57:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148351.274232 (Exim 4.92) (envelope-from ) id 1lytRT-0007Zx-Bs; Thu, 01 Jul 2021 09:57:07 +0000 Received: by outflank-mailman (output) from mailman id 148351.274232; Thu, 01 Jul 2021 09:57: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 1lytRT-0007ZV-4z; Thu, 01 Jul 2021 09:57:07 +0000 Received: by outflank-mailman (input) for mailman id 148351; Thu, 01 Jul 2021 09:57:05 +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 1lytRR-0004XT-S0 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:05 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.170]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0941045a-39ea-4084-bd5e-22ff734b2a6c; Thu, 01 Jul 2021 09:56:49 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ui5Ms (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:44 +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: 0941045a-39ea-4084-bd5e-22ff734b2a6c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133404; 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=ex4r4d11Mg1k2Zn9qFLItgRI9LdfJn43Y1sVEepvWiU=; b=MINrfXc5iyKU6L0b0y1toSzNvOC3EMNFBf2mAqFKmcHh5kEPrAhRw/niCitYKxPoD3 AowdVRraJeFi3mHit3amy7y4SjQAE+dxJG4R3Nq/bPV+R8iXK8btER1ImH6EO9Bqpkkq U1AgaOznJ0o9KcNiU6NNBxp6wu5AcYQoAYCTooDiCKF7U572lWW117vDDYNKpcYQay6h fOVZS8/EYQ1ggUZDguUR8z3Ap0/M80632/OnVF4Jw81Uy6Dh22jVKkh+KhGZjXAEJlZI tTk33dwwugQ4fd9FTNsqK3od7UFonplaU7wAzYOBL9QzoK3RBWRc6z/L8nqKUco8XBCd KzBA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 11/40] tools: use sr_is_known_page_type Date: Thu, 1 Jul 2021 11:56:06 +0200 Message-Id: <20210701095635.15648-12-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 v02: - use sr_is_known_page_type instead of xc_is_known_page_type --- 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..324b9050e2 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 ( sr_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 ae3e8797d0..6f820ea432 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 ( sr_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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133455012891.4754827928572; Thu, 1 Jul 2021 02:57:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148361.274298 (Exim 4.92) (envelope-from ) id 1lytRj-0002Oa-8u; Thu, 01 Jul 2021 09:57:23 +0000 Received: by outflank-mailman (output) from mailman id 148361.274298; Thu, 01 Jul 2021 09:57:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRj-0002Nz-0W; Thu, 01 Jul 2021 09:57:23 +0000 Received: by outflank-mailman (input) for mailman id 148361; Thu, 01 Jul 2021 09:57:21 +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 1lytRg-0004XT-SM for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:20 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8a889ee9-8a7f-45e2-9550-29b8986b84eb; Thu, 01 Jul 2021 09:56:50 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ui5Mt (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:44 +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: 8a889ee9-8a7f-45e2-9550-29b8986b84eb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133405; 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=ZxRdsP8qr4H2zPhSJi5htgzgprczUQRiHOrKeRY262U=; b=pySoDWwLANK1H+EV2djdxCEct7RE0o92/5MBJbj9uBZ20QaDBrkor4fsJbbwF94Qn9 oF1R0s3ZGgNTnRhVBs2zFr9xUaFrc05L/dLZ9Nzt/Dm8OED46IxiswjcVursv+j1XV33 AoGb2AbwrJHSbv3JRr2z5oLqykleezJJsMFrzc2GynrNFEQuCPjitiAdlsMojAPB7yCD Vm75lhMVX30wiJ8nX34ukRMOo4OMFU9JS0L4jqN62m9qq9MbSqo9C+whOKhmgYkc1nb+ K8s6BcDCbkJD5IEq2RrYG7wuVdlm9mtUdqVg3VuHlqDnCWXxPdwBIkdYWk2BL3NfKV9e 7m2A== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 12/40] tools: unify type checking for data pfns in migration stream Date: Thu, 1 Jul 2021 11:56:07 +0200 Message-Id: <20210701095635.15648-13-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 in the migration stream is backed by memory. This specifically deals with type XEN_DOMCTL_PFINFO_XALLOC, which was a synthetic toolstack-only type used in Xen 4.2 to 4.5. It indicated a dirty page on the sending side for which no data will be send in the initial iteration. No change in behavior intended. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 17 +++++++++++++++++ tools/libs/saverestore/restore.c | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 07c506360c..fa242e808d 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -500,6 +500,23 @@ static inline bool sr_is_known_page_type(xen_pfn_t typ= e) return ret; } =20 +static inline bool page_type_to_populate(uint32_t type) +{ + bool ret; + + switch (type) + { + case XEN_DOMCTL_PFINFO_XTAB: + case XEN_DOMCTL_PFINFO_BROKEN: + ret =3D false; + break; + case XEN_DOMCTL_PFINFO_XALLOC: + 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 324b9050e2..477b7527a1 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_to_populate(types[i]) =3D=3D true)) && !pfn_is_populated(ctx, original_pfns[i]) ) { rc =3D pfn_set_populated(ctx, original_pfns[i]); From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133466246933.0268972806546; Thu, 1 Jul 2021 02:57:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148371.274341 (Exim 4.92) (envelope-from ) id 1lytRs-0004Q7-6I; Thu, 01 Jul 2021 09:57:32 +0000 Received: by outflank-mailman (output) from mailman id 148371.274341; Thu, 01 Jul 2021 09:57:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRr-0004PF-S8; Thu, 01 Jul 2021 09:57:31 +0000 Received: by outflank-mailman (input) for mailman id 148371; Thu, 01 Jul 2021 09:57:31 +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 1lytRq-0004XT-Sn for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:30 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8e4898ce-ebf0-4c88-89ea-58c01de1f9ad; Thu, 01 Jul 2021 09:56:51 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uj5Mv (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:45 +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: 8e4898ce-ebf0-4c88-89ea-58c01de1f9ad DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133405; 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=GgpmM75SuN6FuifeSB8D7d7fIQ+maSMtt/6dbwwV1Ko=; b=fiU5zy87RwXUPFQisX2pONK2at9yvFQtBp4h+9vdYhCJe+SDgRUQXXk+jxeGclFdqd Ev2LkmLKf+hBiwswf4p6m1UocGilzfNq+eBXul8GlnD3tJWgjyH/+kEmDoWYxezduoTK CgAiWo/H73nDfl4vEdBQL/9mwk1YrznITa/wIbO7lEFxg8M4Y2M2MjirFLgVM5KHavnD o6hXDTKFpCQCA1/rR+MXQhWjIDDh4rJFu8I2L2Yj/mnCcTiDu0OVAI+SlScDm0hgsPM1 V0sAhTynfn9HTOUc/kLsT/4Nia9xhWLPZLdRWlwHfM1TNqpUmW8d9jFfjBD7/s7720hk yd6g== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 13/40] tools: unify type checking for data pfns in migration stream Date: Thu, 1 Jul 2021 11:56:08 +0200 Message-Id: <20210701095635.15648-14-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 in the migration stream. No change in behavior intended. Signed-off-by: Olaf Hering --- tools/libs/saverestore/common.h | 18 ++++++++++++++++++ tools/libs/saverestore/restore.c | 29 +++-------------------------- tools/libs/saverestore/save.c | 14 ++------------ 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index fa242e808d..905b4078f6 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -517,6 +517,24 @@ static inline bool page_type_to_populate(uint32_t type) } return ret; } + +static inline bool page_type_has_stream_data(uint32_t type) +{ + bool ret; + + switch (type) + { + case XEN_DOMCTL_PFINFO_BROKEN: + case XEN_DOMCTL_PFINFO_XALLOC: + case XEN_DOMCTL_PFINFO_XTAB: + 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 477b7527a1..799170c7a1 100644 --- a/tools/libs/saverestore/restore.c +++ b/tools/libs/saverestore/restore.c @@ -232,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? */ @@ -270,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] ) { @@ -412,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 6f820ea432..12598bd4e2 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162513346014513.666941587520569; Thu, 1 Jul 2021 02:57:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148367.274319 (Exim 4.92) (envelope-from ) id 1lytRo-0003a5-DY; Thu, 01 Jul 2021 09:57:28 +0000 Received: by outflank-mailman (output) from mailman id 148367.274319; Thu, 01 Jul 2021 09:57:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRo-0003Zp-92; Thu, 01 Jul 2021 09:57:28 +0000 Received: by outflank-mailman (input) for mailman id 148367; Thu, 01 Jul 2021 09:57:26 +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 1lytRl-0004XT-SS for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:25 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 844743a8-e2aa-4a5c-ba0d-5227f666b505; Thu, 01 Jul 2021 09:56:51 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uj5Mz (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:45 +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: 844743a8-e2aa-4a5c-ba0d-5227f666b505 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133406; 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=HjAuQTbWmPJqlcbKtv74PXHy29j5qe7IwbSTeBBg19U=; b=SjBOdI0lSSEEBQqOqmxQDxpMY6Z2JwrcX6hsX0vTDg6IX2qrCx8zFagH0CYUx9FDE+ wJr0ifynv8UbIBIIvZjp5jAtunFRKxNBT/NdyMtv6pYFgu6xgXfTxqfGXFokLeH9Wjca hrpAgUMNdhwAK5C+hRl9w+nJE6i4D9qc2Jnw4yMlgPYR7BOl9GnbamSFM9Yol9wyHafY 13efq1OZf5k4nXDcCviHNuk4ZS8R8tn9vflUVzmcWboXv4iBmVyE07bkJyBpQRuAVFIo fqU88xLfamB95nhRkQ3M07BpcGhEjF2dYq0mNcafBhglJO4zNjXWmwu+7rglBUC5N6kQ 9wPA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 14/40] tools: show migration transfer rate in send_dirty_pages Date: Thu, 1 Jul 2021 11:56:09 +0200 Message-Id: <20210701095635.15648-15-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 v02: - rearrange MiB_sec calculation (jgross) --- tools/libs/saverestore/common.h | 2 ++ tools/libs/saverestore/save.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 905b4078f6..252076cf51 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 12598bd4e2..f8fbe7a742 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,42 @@ 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; + + if (!ctx->save.pages_sent) + 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)); + ms +=3D (diff.tv_sec * 1000U); + if (!ms) + ms =3D 1; + + MiB_sec =3D (ctx->save.pages_sent * PAGE_SIZE * 1000U) / ms / (1024U*1= 024U); + + 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, diff.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 +409,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 +441,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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133445308906.1777393296454; Thu, 1 Jul 2021 02:57:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148356.274258 (Exim 4.92) (envelope-from ) id 1lytRZ-0000Ms-GA; Thu, 01 Jul 2021 09:57:13 +0000 Received: by outflank-mailman (output) from mailman id 148356.274258; Thu, 01 Jul 2021 09:57:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRZ-0000ME-92; Thu, 01 Jul 2021 09:57:13 +0000 Received: by outflank-mailman (input) for mailman id 148356; Thu, 01 Jul 2021 09:57:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRY-0004r4-GD for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:12 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.170]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a52234a9-c9c2-4701-8d14-db772e6547a8; Thu, 01 Jul 2021 09:56:53 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uk5N2 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:46 +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: a52234a9-c9c2-4701-8d14-db772e6547a8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133406; 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=6RnKPQsH20PdbTfVhW2egX9qSzfuCkrvoyMFtE/0GwA=; b=cquN494lrm7ljI6MEKPtT9XjxAa3kyMZOzySwPXws847LMv75F/o/r3Bcv9727yP7h 9I+k2OiyQPa3l0jMlVeudm7hB1ShHv9IygEH4da018Z4/dEr55bbxrEedIQcXpvc3qQX Bvd5Ezbc7s/qvIfQR1dsm9PbM5Z3+0B8zWdcLUR9I5oHUbfffnbfSrLrGkk8W7Wix4cm 3hbzvHBNlHvjHB1M7VWiamhHsXshQi8u7CPBj+2VGjr+OuGj1sTloYnFmhfamf7Hhsxz SLQ0KTybcvu+tan3ojBvYivYKkqJ31UrEhYFXXKB3EslYuxwRJ7GhbWtAZXmKw61HWoV 2a+w== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 15/40] tools: prepare to allocate saverestore arrays once Date: Thu, 1 Jul 2021 11:56:10 +0200 Message-Id: <20210701095635.15648-16-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 Note: the performance improvement depends on the used network cards, wirespeed and the host: - No improvement is expected with a 1G link. - Improvement can be seen as shown above on a 10G link. - Just a slight improvment can be seen on a 100G link. This change also populates sr_save_arrays with "batch_pfns", and sr_restore_arrays with "pfns" to make sure malloc is always called with a non-zero value. Signed-off-by: Olaf Hering v02: - rename xc_sr_save_arrays to sr_save_arrays - rename xc_sr_restore_arrays to sr_restore_arrays - merge handling of "batch_pfns" and "pfns" to make sure malloc is called with a non-zero size value (jgross) --- tools/libs/saverestore/common.h | 12 +++++++++++- tools/libs/saverestore/restore.c | 14 ++++++++++---- tools/libs/saverestore/save.c | 27 +++++++++++++-------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index 252076cf51..968bb8af13 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -223,6 +223,15 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct sr_save_arrays { + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; +}; + +struct sr_restore_arrays { + /* handle_page_data */ + xen_pfn_t pfns[MAX_BATCH_SIZE]; +}; + struct xc_sr_context { xc_interface *xch; @@ -255,11 +264,11 @@ 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; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct sr_save_arrays *m; } save; =20 struct /* Restore data. */ @@ -311,6 +320,7 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + struct sr_restore_arrays *m; } restore; }; =20 diff --git a/tools/libs/saverestore/restore.c b/tools/libs/saverestore/rest= ore.c index 799170c7a1..c203ce503d 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; } @@ -739,6 +737,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 +762,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 f8fbe7a742..e29b6e1d66 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; } @@ -849,13 +849,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.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pag= es ) + 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; @@ -884,7 +883,7 @@ 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133751058229.00737365868713; Thu, 1 Jul 2021 03:02:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148469.274496 (Exim 4.92) (envelope-from ) id 1lytWU-0005wF-R4; Thu, 01 Jul 2021 10:02:18 +0000 Received: by outflank-mailman (output) from mailman id 148469.274496; Thu, 01 Jul 2021 10:02:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWU-0005vl-Jx; Thu, 01 Jul 2021 10:02:18 +0000 Received: by outflank-mailman (input) for mailman id 148469; Thu, 01 Jul 2021 10:02:17 +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 1lytRv-0004XT-Sy for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:35 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a76f642b-8ab8-4845-afd7-b6e202d99543; Thu, 01 Jul 2021 09:56:52 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uk5N3 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:46 +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: a76f642b-8ab8-4845-afd7-b6e202d99543 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133406; 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=KnwsPxLRJB68rPXEArkMW6OSaI/spxXLS3HmgXIKcHw=; b=F9jVJ1N144s3xumrT8kJVbYSY9MfWREIAi4QGQ0tQpX+AHdjKtnEIBCUSYTo8GG9jL RJBHhn5HrnUp5abb3C6hYg4cv2g9tPC6W9JJjWlxGAayaRpmA0+UOC5OvsuTVgjoE+Qg 3UqSMgQq5+gXYGmDjTPoRAf46TSFqrMYWtivGdddA4StQEO5e1HUqD5nSzVE2EvZ79Mx MsiulUUErQpT+YKwx/1BCRmrl9FynwGYNWkxSard0VRpDefefTQMy7e7mNSwOKIJYs70 qQsuXmTYeeN8b0om/Z9fgO7CFd+QHOVUBo47dj4q7AfhkP+Juw8Ci7u5+yiAZpeNjj82 aUuA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 16/40] tools: save: move mfns array Date: Thu, 1 Jul 2021 11:56:11 +0200 Message-Id: <20210701095635.15648-17-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 968bb8af13..1415a182d2 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 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 sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index e29b6e1d66..6b09784be8 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133716847649.4232982948228; Thu, 1 Jul 2021 03:01:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148406.274386 (Exim 4.92) (envelope-from ) id 1lytVw-0001Cn-DO; Thu, 01 Jul 2021 10:01:44 +0000 Received: by outflank-mailman (output) from mailman id 148406.274386; Thu, 01 Jul 2021 10:01: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 1lytVw-0001CU-8P; Thu, 01 Jul 2021 10:01:44 +0000 Received: by outflank-mailman (input) for mailman id 148406; Thu, 01 Jul 2021 10:01:43 +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 1lytS0-0004XT-Su for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:40 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 675c9bdf-ecdf-4f97-98b0-3206d03c9de6; Thu, 01 Jul 2021 09:56:53 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ul5N5 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:47 +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: 675c9bdf-ecdf-4f97-98b0-3206d03c9de6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133407; 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=IfTAu6csmKih3Ul30va1DloKz84aTf69Oy5gDcqna/s=; b=XsemlVKcnJEPbQEhuTh/f1/P0zNwYk0GDD5ZFuuNMui6+I/UoY1e6NDIuYcO19mwvm s/eXT+Fh3UD049CqyU/fJmDpnjQzCe+OQpFcvEcaUeFZSf+A0l9zGa4BMziPLBXkIu09 Su8fRSH5+dNneKXI21FBmwHRoZubAnptMo/D6E0GoSJ1iExRZ+kINd8RCJU6m74/I2XF iO76syePZoRLpr71rO453SjEadeizZOC7cpU9DcxFXrhYuYBQVKvbLrgj3OEayRwWCEp 93dHtlIrraIEWffntlkPa6bGCK+AOa3T05EswFZrM8BMVd6j1+c81mWtqOB4TQi63TGb seUw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 17/40] tools: save: move types array Date: Thu, 1 Jul 2021 11:56:12 +0200 Message-Id: <20210701095635.15648-18-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 1415a182d2..5bd2913cb6 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -227,6 +227,8 @@ struct 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 sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 6b09784be8..0883c1fac0 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133434964976.0000443475554; Thu, 1 Jul 2021 02:57:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148348.274221 (Exim 4.92) (envelope-from ) id 1lytRQ-00072E-U8; Thu, 01 Jul 2021 09:57:04 +0000 Received: by outflank-mailman (output) from mailman id 148348.274221; Thu, 01 Jul 2021 09:57: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 1lytRQ-00071t-LN; Thu, 01 Jul 2021 09:57:04 +0000 Received: by outflank-mailman (input) for mailman id 148348; Thu, 01 Jul 2021 09:57:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRO-0004r4-Fp for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:02 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.102]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c587559b-37c5-434a-b906-25f3b6bdca35; Thu, 01 Jul 2021 09:56:53 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ul5N8 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:47 +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: c587559b-37c5-434a-b906-25f3b6bdca35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133408; 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=JtFmFI89VrmWr2vsArcScvsm4YNWIztizbLrNUj8v3A=; b=KF+/i2w2jn0OOsptwi4M0yyQC9/LaijzHsOLKpPAEf0C//wVSKbRIk+XVjsQX7aMP5 pqFw6zhfu/4rm4fwzY7XBLDKe5PvzWH4M8FtlsYYGhly0yYXTG18oArFTlndqyD+SzzY 8ZflkpY0K5epQ2Ns/L1DGVkdHLE/nD1yHWF3SN+6aerEc29EbxuJYB8XtQJyQUbNdfqo wdVfiAXgkTDLT3ucJ3KGWEczM0iB0VgTqX1LXMoGKL4zS1o+SkqUFfiy1FY+piUdnnfn UbS0/7qxmjisfu+6SzRoywgIDRYJ3L+ACrbYCrQfWlGvW/j+EnHRwjtNSNIcF2olHkCQ CSPw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 18/40] tools: save: move errors array Date: Thu, 1 Jul 2021 11:56:13 +0200 Message-Id: <20210701095635.15648-19-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 5bd2913cb6..25ee8fcb0f 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -229,6 +229,8 @@ struct 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 sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 0883c1fac0..9ebbf00ce7 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133772563398.59940844419395; Thu, 1 Jul 2021 03:02:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148504.274556 (Exim 4.92) (envelope-from ) id 1lytWp-0000rP-P2; Thu, 01 Jul 2021 10:02:39 +0000 Received: by outflank-mailman (output) from mailman id 148504.274556; Thu, 01 Jul 2021 10:02: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 1lytWp-0000qG-Fp; Thu, 01 Jul 2021 10:02:39 +0000 Received: by outflank-mailman (input) for mailman id 148504; Thu, 01 Jul 2021 10:02:37 +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 1lytSA-0004XT-T4 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:50 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 086b66b3-062c-4f5c-b56c-b9cf69dfab2d; Thu, 01 Jul 2021 09:56:54 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619um5N9 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:48 +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: 086b66b3-062c-4f5c-b56c-b9cf69dfab2d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133408; 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=43SvGtyUka0RJRv5k5wfzNrETGLrxHTj64zykGKQL1Q=; b=Vj7qzvDcXM4w4xzTRvoqwCtgS94+Xdcvmq/iAUm6RQQF+XzTP3l2LkKk8uk2ijxQGR FsglZZU0fiNrVk6j4R2pBm5V6iohYwZo28xkOEdvllPaizwYAOe7OvarbDJiE5K84TPD OPLdIoXnQ8D7j/tPK6b3YCbNHVVFQWSraMoZInJO9lJCT/iIxsZvivkAK4T9aoYiRWyQ kxCXCPt4924Mu89+91b9XLjdMdbTWGxQwYMcm+fMHFmYeLHOOESPpq8kbei2RzNSo9H0 T+FH2EnuUm2v0CHLo7qC4yHN/1vnNU2qr9zT/7+ahbg2XliUJk7Z38SsZwAXgsxErdk3 JqwA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 19/40] tools: save: move iov array Date: Thu, 1 Jul 2021 11:56:14 +0200 Message-Id: <20210701095635.15648-20-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 25ee8fcb0f..c8a30acf7b 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -231,6 +231,8 @@ struct 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 sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 9ebbf00ce7..1a5f3d29ea 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133741134399.01686298822665; Thu, 1 Jul 2021 03:02:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148450.274442 (Exim 4.92) (envelope-from ) id 1lytWI-0003fq-EY; Thu, 01 Jul 2021 10:02:06 +0000 Received: by outflank-mailman (output) from mailman id 148450.274442; Thu, 01 Jul 2021 10:02:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWI-0003e4-4A; Thu, 01 Jul 2021 10:02:06 +0000 Received: by outflank-mailman (input) for mailman id 148450; Thu, 01 Jul 2021 10:02: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 1lytSF-0004XT-T9 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:55 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8f5aaa21-467c-4219-8fba-a36d20e9b099; Thu, 01 Jul 2021 09:56:54 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619um5NA (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:48 +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: 8f5aaa21-467c-4219-8fba-a36d20e9b099 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133408; 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=xJ7EM0+9FDIAYOBy0R8s1Qys8qJMuiw+N5Xy4+8lTRo=; b=ecp23n+S6r+4J3vKtWX10SGOt6Su4h9JFji2tuLPVYzQv5MY7bYqyPFuHG0tK9wydu K+2wARe/QyYDm/49/2uQKd5An2WKG5l5LORbdXBW5WK3FMqSkUb/cIb076s16lRmodRN JrxlWRGRFwju9v/xJgdjLsjsp7vKDolsGue95kwLbMUbtQd8LPIZtEOAeaZslf6aC2pA Sw/ZPth5/AqS4Lz5laaV64HIPImMq3W4Pcexyxa4QPra1O8tQhiKM41ym+zRxs8pNo+/ EdAMzXYxblAPDipzbkUjyYm1f9JyxZDInIfzDsVGatH7e+M/2lcKgIm+p0WHbAQSzFVN AUmA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 20/40] tools: save: move rec_pfns array Date: Thu, 1 Jul 2021 11:56:15 +0200 Message-Id: <20210701095635.15648-21-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 c8a30acf7b..3994ab3844 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -233,6 +233,8 @@ struct 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 sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 1a5f3d29ea..0f02988ff9 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133449019994.5838469798232; Thu, 1 Jul 2021 02:57:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148359.274284 (Exim 4.92) (envelope-from ) id 1lytRe-0001Yz-PG; Thu, 01 Jul 2021 09:57:18 +0000 Received: by outflank-mailman (output) from mailman id 148359.274284; Thu, 01 Jul 2021 09:57:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRe-0001Xo-JS; Thu, 01 Jul 2021 09:57:18 +0000 Received: by outflank-mailman (input) for mailman id 148359; Thu, 01 Jul 2021 09:57:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRd-0004r4-Gd for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:17 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d5bf76a4-ed1b-4216-9294-edd5278aaf94; Thu, 01 Jul 2021 09:56:55 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619un5NC (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:49 +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: d5bf76a4-ed1b-4216-9294-edd5278aaf94 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133409; 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=0ENk4UcCha2plreo4qu8AQV+ZCOBGywsK+BeOcrXNEw=; b=hvsGNz2aPTyUlje9u2IN1cqOqVzxnm8zakXYxhY4Dh3rUTNsVHK9vn9sEFbKoLqQrO zabF6S0hEqENSsCUFdqV6+pRBRaSAX9Xh7vdUFlHWHowuAvORi+vCclXXQi6Dv7ePMIH 9KjOwKV6v1TpW4hegVz0r4mxxNUBiFBlYaYCLWWrvXFkR7oVqeNz5dMiuE5QCWmphRoc O9UwdBLMExdfaT/LKBbvXao0iIwni+8tyTBpkFELF7ec4Vrjbzsi3DjkizKlFq1eGFBm 3+sAyGbAF6aMjpoUjwe8iovH4XqJGJI4yBA1O89Lrh2uIZgXvJt7OxE82YUzT/Ryhbi7 uV8Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 21/40] tools: save: move guest_data array Date: Thu, 1 Jul 2021 11:56:16 +0200 Message-Id: <20210701095635.15648-22-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 3994ab3844..c3570e0c9a 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -235,6 +235,8 @@ struct 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 sr_restore_arrays { diff --git a/tools/libs/saverestore/save.c b/tools/libs/saverestore/save.c index 0f02988ff9..ea04cb1a74 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133461109508.8811176409148; Thu, 1 Jul 2021 02:57:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148369.274324 (Exim 4.92) (envelope-from ) id 1lytRp-0003di-2h; Thu, 01 Jul 2021 09:57:29 +0000 Received: by outflank-mailman (output) from mailman id 148369.274324; Thu, 01 Jul 2021 09:57:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRo-0003cV-NY; Thu, 01 Jul 2021 09:57:28 +0000 Received: by outflank-mailman (input) for mailman id 148369; Thu, 01 Jul 2021 09:57:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRn-0004r4-H2 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:27 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.102]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7318a437-6aec-4f53-a2a0-10214f3fbcac; Thu, 01 Jul 2021 09:56:57 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619un5NE (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:49 +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: 7318a437-6aec-4f53-a2a0-10214f3fbcac DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133409; 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=VXXP7tsnRC41xaA88qzwrHhQNrSFmDSbSlav6Il7DHM=; b=nek8SgSXMYp0YyFkVQajq+6uAJthx4pNaB9Z7RNljK3npjfWHTOJMlzeveUeT19Qxh C/fpM2lj2ShtHYL2QqLRL5+Qe7jOSTRRdMFpFspPLIy0nC5Dqcico76IlIqTmOHTTdQ2 xKw2M4fnke3Z4OivG0VsFPM9ddzkhn7LgJhb2K5dcjmMm2ExIl+Ul5F5tG6TyxpS2c0M DIZQu4aL5NWfl2XkGcIukLAwSql3alv6ieqLDsyD87t5zbw9uZv3pZbrZHLI2XqEvire GsMFVQpwxh3d02bJrqCatpgwaFVPsd2R9skFSpklyDUoKVBpx4tonUlnlAM7p/JJZjTs Wsfw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 22/40] tools: save: move local_pages array Date: Thu, 1 Jul 2021 11:56:17 +0200 Message-Id: <20210701095635.15648-23-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 a 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 c3570e0c9a..8089449011 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 @@ -385,6 +381,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 ea04cb1a74..fa83648f9a 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133764820290.3061127824851; Thu, 1 Jul 2021 03:02:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148490.274518 (Exim 4.92) (envelope-from ) id 1lytWh-0007lU-TK; Thu, 01 Jul 2021 10:02:31 +0000 Received: by outflank-mailman (output) from mailman id 148490.274518; Thu, 01 Jul 2021 10:02: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 1lytWh-0007lJ-MX; Thu, 01 Jul 2021 10:02:31 +0000 Received: by outflank-mailman (input) for mailman id 148490; Thu, 01 Jul 2021 10:02:30 +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 1lytSU-0004XT-Tu for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:10 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7ba2abb8-8840-41fd-a5d0-ee4432074b69; Thu, 01 Jul 2021 09:56:56 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619un5NF (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:49 +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: 7ba2abb8-8840-41fd-a5d0-ee4432074b69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133410; 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=SEmlTCun49Bu0J5Hduo4Ou5xOCzHrO1gLgKtshkEibk=; b=leNKNgImZhFpMAUfRvKFT4UTuw7NNJ/AvWciHuO8ximTBy06TMcEBStzALzWRO3rBe H+ej4+CDkSuH0BtA0Sfuxbw1jSA2WpfBjAI+EgLyb/5ECI9CO3bPmHq5vXC3iGBjpihu Sn994HSbXw2wHckqAlMC5FzL2gMQv7wAaOY1B9I3GHZB8kFAV980UQu30b2xaCPlWHue UYLT52fitrn8J6w7JbF1QpSy03aY1an/h9nveX+G+mL04/Y9I9Skq+c5z5+c3fDLhuVR 55Me5xHBvzm6+2jnIMSDcai8W1SaEc1vRc6+RZfdSWShl7Z3sgHxhHWYwKVIZfvgXYta wsyA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 23/40] tools: restore: move types array Date: Thu, 1 Jul 2021 11:56:18 +0200 Message-Id: <20210701095635.15648-24-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 8089449011..d798b79745 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -238,6 +238,7 @@ struct sr_save_arrays { struct 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 c203ce503d..8ea125cf73 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133711756385.25859393569533; Thu, 1 Jul 2021 03:01:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148404.274375 (Exim 4.92) (envelope-from ) id 1lytVp-0000pB-22; Thu, 01 Jul 2021 10:01:37 +0000 Received: by outflank-mailman (output) from mailman id 148404.274375; Thu, 01 Jul 2021 10:01:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytVo-0000p4-Ut; Thu, 01 Jul 2021 10:01:36 +0000 Received: by outflank-mailman (input) for mailman id 148404; Thu, 01 Jul 2021 10:01:35 +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 1lytSP-0004XT-Tc for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:05 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f8574b62-670a-4575-96ac-f040367c0885; Thu, 01 Jul 2021 09:56:56 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uo5NH (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:50 +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: f8574b62-670a-4575-96ac-f040367c0885 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133410; 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=bOrjMbCsuneuqIIJGmLTblCtP85a/JTG2OAkzH1Hjtw=; b=UySDWzQOP77+pL/xjXP2xA3spFqJTyKI8ZU213fh6F8cBA86GlpSiFZxX8QijfCNiw Jfo3XaYQmD3whcWUQshSBLK4zqALkCB4lyYz3Bo1T5nVTNxYygD7FHny+M4MHwX1P8Iy paU6qPJ8lEqBgUoarSRb2cuD4xtDMc5TZdUK99UpSZvbM6gCxi5CXpysGzLtvDFuY60l ogE8q5SN6+rVMh8z4U/iK+rg3FX6AhHwq5kBEYSci+saoI7LuxBgqUFB6YL28x2wKA78 g1FYYIEd8SOTGJW+Q8Zq7QqZy5EjvlO9Katji2gV5+5mRz1AmE+b6g97qYL6rykTniZ2 juEg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 24/40] tools: restore: move mfns array Date: Thu, 1 Jul 2021 11:56:19 +0200 Message-Id: <20210701095635.15648-25-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 d798b79745..9d7efff03d 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -239,6 +239,8 @@ struct 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 8ea125cf73..d7ea52b89e 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133771677721.7055450287814; Thu, 1 Jul 2021 03:02:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148507.274561 (Exim 4.92) (envelope-from ) id 1lytWq-0000z8-9n; Thu, 01 Jul 2021 10:02:40 +0000 Received: by outflank-mailman (output) from mailman id 148507.274561; Thu, 01 Jul 2021 10:02:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWq-0000wq-0h; Thu, 01 Jul 2021 10:02:40 +0000 Received: by outflank-mailman (input) for mailman id 148507; Thu, 01 Jul 2021 10:02:38 +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 1lytSe-0004XT-UD for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:20 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1bd39e47-8d61-453f-8021-3b2516e0ff03; Thu, 01 Jul 2021 09:56:57 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uo5NK (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:50 +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: 1bd39e47-8d61-453f-8021-3b2516e0ff03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133411; 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=fv8u8kOPgs+5gp4rBj+tXUjGXKsfh+8d1IsW+dkfVk4=; b=S+Xl4Z1zszliY0TzkrzXrYIBAHGDew/2RqvBacfbRbmSaLzzwduoKo4x79mMCm/5g/ nDuK2IfnqsEdrhAxeKKyVqZJ2Mhv5EI6ybX2QNeiJypMRtsZUGbvjXJBthCOmhe13XmN lOjt8ppHej1Y/J8H/BBSmEx+9MBpvruf8K7hKVnI2cP0fPOXESbiD/qXoYUNb/+mhW/A xqUUq/CwFuevuGKoDO9vuZsYBvzHrDVFapY3ZH+xnZedCUQQvUK3u97yncGPW5rz7vEJ 8nlvmt+H4eGDZ/ti0AXEwA4ibB7rn7Dg9iiSJ0oJzsLY/y+NoryAToCjPJyYWveR0HPV U7gA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 25/40] tools: restore: move map_errs array Date: Thu, 1 Jul 2021 11:56:20 +0200 Message-Id: <20210701095635.15648-26-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 9d7efff03d..7684c35e22 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -241,6 +241,7 @@ struct 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 d7ea52b89e..578ee1accb 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133456189344.71160774352893; Thu, 1 Jul 2021 02:57:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148362.274303 (Exim 4.92) (envelope-from ) id 1lytRk-0002Xs-3G; Thu, 01 Jul 2021 09:57:24 +0000 Received: by outflank-mailman (output) from mailman id 148362.274303; Thu, 01 Jul 2021 09:57:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRj-0002WF-Ni; Thu, 01 Jul 2021 09:57:23 +0000 Received: by outflank-mailman (input) for mailman id 148362; Thu, 01 Jul 2021 09:57:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRi-0004r4-Gk for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:22 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.101]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b3f38ebc-a56c-4e01-8323-f92017ee84eb; Thu, 01 Jul 2021 09:56:57 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619up5NL (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:51 +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: b3f38ebc-a56c-4e01-8323-f92017ee84eb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133411; 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=6ENQhbtthK4eIjkXxFO8V/gNE/sF6qih6TLZLeOb+b0=; b=tXgf/73seA2ReRIm8D/JvX4Ys0pziOMDW4aurCKsesPhuWp5kqvEKayk+88kKUk4FQ a1798geALsJt37Y5/f/RrZn6uJh2462CYxJwdMIfw8h7sXroDhjML12aaxRwKDgRoytd oQ9hwexHpCtTDxA70biVJOi8pSGynJ4nXJWgoxdOYJchetsXIMdXJioL0B9Y5ujMLWRG eZzZ3aTgGqEIWr0XgQvxepGEPbmx5vntjJEPKZDqHe9ZwHuTfwvgN9hxrxVNJZT/0qMF wnYCEkn4Ao6LrXPnvy4cn5BPloAViOynzk9AmdmLAiXfbZW4gkbxiuuJ2cLmWz8vsH6R ROIw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 26/40] tools: restore: move mfns array in populate_pfns Date: Thu, 1 Jul 2021 11:56:21 +0200 Message-Id: <20210701095635.15648-27-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 7684c35e22..9d2ea96583 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -242,6 +242,8 @@ struct 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 578ee1accb..7418abf1c5 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133764614755.377025086517; Thu, 1 Jul 2021 03:02:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148491.274524 (Exim 4.92) (envelope-from ) id 1lytWi-0007sH-E3; Thu, 01 Jul 2021 10:02:32 +0000 Received: by outflank-mailman (output) from mailman id 148491.274524; Thu, 01 Jul 2021 10:02:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWi-0007qw-5p; Thu, 01 Jul 2021 10:02:32 +0000 Received: by outflank-mailman (input) for mailman id 148491; Thu, 01 Jul 2021 10:02:30 +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 1lytSj-0004XT-UH for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:25 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2bf55f4c-8ccb-4310-b27b-a0a9200a22e3; Thu, 01 Jul 2021 09:56:57 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619up5NN (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:51 +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: 2bf55f4c-8ccb-4310-b27b-a0a9200a22e3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133411; 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=NzRIOkyxxUnksLPgAOMJtNoYSt71bd12f8S/qdAp4ys=; b=E3E63ORgeCjrZTaxjNFk+nyNw7JY0SiH/yHCVGqWhuC+TMeeeO3l/fAfSOgtVCoqjk GQ0o3YUjOVWcNJOMoO/SLpZLuQuE7110MjTbSJ8jSo9wfgkfQvE1z6FBr4+fZT+TK3Wx RNhXmirclaWDaJSgkxd6i/XqP7taUsITGTpjfgqjHXsbD7UxsCLi0o2MkJqQtmiS3pQY GkTWSjv1rNqGPCt1J7CZqv35cj7LRlB8qlC6uBqMkD9Pj1SMoVvEu2GxXwGjj26xvl8O tweDh0TQpuEb86rHI8sma/iiu6EhE03FQLd4yZQLNMr3j079ckgF1POvpg7OjQaU+k7d 2qvg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 27/40] tools: restore: move pfns array in populate_pfns Date: Thu, 1 Jul 2021 11:56:22 +0200 Message-Id: <20210701095635.15648-28-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 9d2ea96583..c319148f8f 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -244,6 +244,7 @@ struct 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 7418abf1c5..2a6ccce847 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133751513443.3102432547281; Thu, 1 Jul 2021 03:02:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148470.274500 (Exim 4.92) (envelope-from ) id 1lytWV-00060W-Af; Thu, 01 Jul 2021 10:02:19 +0000 Received: by outflank-mailman (output) from mailman id 148470.274500; Thu, 01 Jul 2021 10:02: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 1lytWV-0005zS-3L; Thu, 01 Jul 2021 10:02:19 +0000 Received: by outflank-mailman (input) for mailman id 148470; Thu, 01 Jul 2021 10:02:17 +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 1lytSt-0004XT-Ur for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:35 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 54087ce2-f123-4ec4-8ca2-5a6be09f5c48; Thu, 01 Jul 2021 09:56:59 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uq5NO (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:52 +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: 54087ce2-f123-4ec4-8ca2-5a6be09f5c48 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133412; 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=VqP0dtxOpIShGdDn4ROCdSzLaQrNr0I+/+0oMjV5WeY=; b=UFGSIIpkg+JgbdLPDmn3OdvsTFfseQqaPhGrvOXbhe/uB5U7dX2bRe6fm82aOAzv6C X0d6/imN+D3oOuuKMXBdKeWkEpIcXH2zsRr0iuK/+RPwVorJRHLCQn/NCfNfwFkmKjIq m//sv8oBnG17YgVmeqv0zoWAipjIk3umKhJF/9feD4DNSmS1UC4n96jFN5hTrC7B7cZj ygPYoz9+fmXWicc9OmC4Bx/uM3xqKXgKPg3C8/5+QFto54nGXpoVs9pA1URADAM2sk9A IbOlPFO0CkBI1lNXrttEXpVjcbBVapWpol4rMcBUOUQwyKpjDxfS1+bq55V9iDPo1DCM M/fQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v20210701 28/40] tools: restore: split record processing Date: Thu, 1 Jul 2021 11:56:23 +0200 Message-Id: <20210701095635.15648-29-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 c319148f8f..580eafacc8 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 2a6ccce847..e75380155d 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 fa83648f9a..e486bce96f 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -589,6 +589,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; @@ -597,7 +598,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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133775951897.5003261807709; Thu, 1 Jul 2021 03:02:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148501.274551 (Exim 4.92) (envelope-from ) id 1lytWp-0000n1-8S; Thu, 01 Jul 2021 10:02:39 +0000 Received: by outflank-mailman (output) from mailman id 148501.274551; Thu, 01 Jul 2021 10:02: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 1lytWp-0000mW-41; Thu, 01 Jul 2021 10:02:39 +0000 Received: by outflank-mailman (input) for mailman id 148501; Thu, 01 Jul 2021 10:02: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 1lytS7-0004r4-HY for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:47 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8fb93b39-fa31-4fd4-b68b-bf10d2e2264c; Thu, 01 Jul 2021 09:57:00 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uq5NR (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:52 +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: 8fb93b39-fa31-4fd4-b68b-bf10d2e2264c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133412; 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=BF1RLVhIB1BINrph0oGFlHcI4RXAoWr7u8tCO2/nmZw=; b=Cm3516N0bw8SQ/Ki/WWHQi6r4HjWgWgj5xxASFu1AZkoJQIACx2212nqjH5dm0ouAN UvTL56YGB12xLGngtgO7Az7s7a42jOWIGQskDHHUIrFgjpuMeBoaEMSyx1a0VfOGmOMq Z2ub8mBu2XLoZEi8bS6dkMpseRQLeAmSaZMqtUk5T/kPT2foO1GwRkZdXm9yDLcUtva9 x1CEB4cO5XD7bbpMeFKoEfEEjfiq2Sd8jiCdKYPNt68JF7f7/oveqdvlzywL5Y2OcNZu IVRw2HRHEelfUAnd7qpBFvdaJsJVXojGDv3QKlEdlsMXUFEyTEmtGi1kttrzo1ycKubo JbQw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 29/40] tools: restore: split handle_page_data Date: Thu, 1 Jul 2021 11:56:24 +0200 Message-Id: <20210701095635.15648-30-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 580eafacc8..96bd0ab80e 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -242,9 +242,14 @@ struct 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 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 e75380155d..7643de58e0 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 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 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162513374965433.32604450571341; Thu, 1 Jul 2021 03:02:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148461.274473 (Exim 4.92) (envelope-from ) id 1lytWP-0004vl-7L; Thu, 01 Jul 2021 10:02:13 +0000 Received: by outflank-mailman (output) from mailman id 148461.274473; Thu, 01 Jul 2021 10:02:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWP-0004vW-1d; Thu, 01 Jul 2021 10:02:13 +0000 Received: by outflank-mailman (input) for mailman id 148461; Thu, 01 Jul 2021 10:02:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRx-0004r4-H0 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:37 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 290751bb-7f5b-49db-83ad-786e01024b54; Thu, 01 Jul 2021 09:56:58 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ur5NT (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:53 +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: 290751bb-7f5b-49db-83ad-786e01024b54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133413; 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=CECljmMn7PUdmmrOXwMW+tlXTDlbFy0SLwiI5WugPX4=; b=p+92q4HQUSPoR2cRBMqVwfDE0UMRi9sa92T7loltuZ6QafgAURxR0r+r8QcTf+NOJ/ vz9CPzssgi19g8KRpxs0qzc6jNV0mY9LmjjCQ1ydnJmZk9gOOC78BpMIhRY4qBf8dBCe y0AJKW4+155VlDHfKBBd3I25YfcE2psg1x/B/lg+mUQfSg4Xh6464NoX1JNvSmrOa7/d 5okyWBC0JN5DtTCc5GJHFqOKzK4alpCbvtfVGIP5nTFJYuIEC7lOad1yf10WrJ5irDLM Ln+hxBX7pnvM7XrIWxm4ZjcXBxjTTPfXXnvWLipxM0E9246GfFhsMoGa+EdIbxW/6qiA aXHw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 30/40] tools: restore: write data directly into guest Date: Thu, 1 Jul 2021 11:56:25 +0200 Message-Id: <20210701095635.15648-31-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 96bd0ab80e..3adcf2f83f 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -243,6 +243,7 @@ struct 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 7643de58e0..53f05f1b65 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 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133465548449.37824736065716; Thu, 1 Jul 2021 02:57:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148372.274351 (Exim 4.92) (envelope-from ) id 1lytRu-0004xk-8j; Thu, 01 Jul 2021 09:57:34 +0000 Received: by outflank-mailman (output) from mailman id 148372.274351; Thu, 01 Jul 2021 09:57: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 1lytRt-0004vX-Rc; Thu, 01 Jul 2021 09:57:33 +0000 Received: by outflank-mailman (input) for mailman id 148372; Thu, 01 Jul 2021 09:57:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytRs-0004r4-Gv for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:32 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 939893d0-0ec4-4a0f-851d-a8ce2ba947db; Thu, 01 Jul 2021 09:56:58 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ur5NU (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:53 +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: 939893d0-0ec4-4a0f-851d-a8ce2ba947db DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133413; 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=seFXjeMiXQjNm4nJiNtEFRc+qmrE0unG8gUnEIVDqgAeVpEvsTsvGZSg4/4ql9gK8g cdFrWui1BKKNZGYpm40Ag3p60mxyBCejkMlVaK/sVCdOsCK8dMAG2+mHagXV4SI3yqh8 UZsS1DtArQncExBuQWRlMmpBc4oCSmmIDhlT3Fza8Zwpv1GYEXZU7ZuOnyhGYOA3etGI CIg6Y/lHH3UpqRrT45x+1nI6IFWL4RGo4yxOVk0/gvPL+lFDJyOoKwRIK9lUyFiHj9Cn ruKBzH319FojoxPzWwdJxefYUWRPoursepKTRW6/ePrJizBiGdusb6Y7I+DtbZeC45zA 2yNA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v20210701 31/40] tools: recognize LIBXL_API_VERSION for 4.16 Date: Thu, 1 Jul 2021 11:56:26 +0200 Message-Id: <20210701095635.15648-32-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133782203552.9220777051239; Thu, 1 Jul 2021 03:03:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148509.274580 (Exim 4.92) (envelope-from ) id 1lytWs-0001kx-Vt; Thu, 01 Jul 2021 10:02:43 +0000 Received: by outflank-mailman (output) from mailman id 148509.274580; Thu, 01 Jul 2021 10:02:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytWs-0001iZ-Gy; Thu, 01 Jul 2021 10:02:42 +0000 Received: by outflank-mailman (input) for mailman id 148509; Thu, 01 Jul 2021 10:02:41 +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 1lytVZ-0004XT-4H for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 10:01:21 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.100]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ac119f06-72cf-4881-9e7d-d1a78e7b3b1d; Thu, 01 Jul 2021 09:58:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619us5NW (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:54 +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: ac119f06-72cf-4881-9e7d-d1a78e7b3b1d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133414; 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=n0d0gwWXlJ/Ban5eVrK506Di/gOt/MD61K+N2RGQBbA=; b=Gl58uIDpytNCd08vTi0ztylENVBl+fRtA6BJJFBS4K+oAMI4fOQRThcxhH9ZUenr1p LSGgV3d0plPdsJmtYrjw8IErqZWLZk05W83mq33yvMopOnlMNIgywtuHWkA1KMwkk5NX yllcZGagVS2KO3XT/EARqFZoC16c753PHIjD3vlr7pMx6I9WtNVCUUs4Ps75yCOTF/uu 34eLqRIzWxCGH4+2EkcF2cXdzxQdEavqUKZQcZeA0L58nQ2CoMu/NVsYg+ZZ+1SJMEGt IM6PcldeVJJGQx+XoRzBf0Ba9VSNxnbc1IGFRQPAHtxPOuzMD83paaMsrKDQzmKlXmg9 KCwA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" 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 , Juergen Gross , David Scott Subject: [PATCH v20210701 32/40] tools: adjust libxl_domain_suspend to receive a struct props Date: Thu, 1 Jul 2021 11:56:27 +0200 Message-Id: <20210701095635.15648-33-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 c00c36c928..5dbd27900f 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133743865379.733703832326; Thu, 1 Jul 2021 03:02:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148459.274463 (Exim 4.92) (envelope-from ) id 1lytWN-0004bp-RC; Thu, 01 Jul 2021 10:02:11 +0000 Received: by outflank-mailman (output) from mailman id 148459.274463; Thu, 01 Jul 2021 10:02: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 1lytWN-0004bZ-LD; Thu, 01 Jul 2021 10:02:11 +0000 Received: by outflank-mailman (input) for mailman id 148459; Thu, 01 Jul 2021 10:02:11 +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 1lytT3-0004XT-Uz for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:45 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ce866e23-22a8-4ca0-a2a8-b1be12cba45e; Thu, 01 Jul 2021 09:57:01 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619us5NY (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:54 +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: ce866e23-22a8-4ca0-a2a8-b1be12cba45e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133415; 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=yuafVLq2aG35iRtmsU2Mgmytxa4WOaE4NXl9z9jSB2o=; b=Hsg1ND1EL5IMwp88Gl0qTaM2/mCUSaQ17bsPAiq++O+Xz533TUGNCQ3NxadVT/GIIY uLhJnjczyyus/WqAMECiOsPEBr3LTv4pBs/BseMGMUDqadXrkjFsxCRRzD9uNNUSaASc BaxACe1wOrs8ksgFb6aEvc9SA27yse1vqdrBazsAvVDFuHFkeNGRaT7kt/ARBWpVe0KW O7sn9ayndZrsZsEccohssOWkCT5FqkoxS6tPywhCAdfkKxkNKJPalCyHzNrIS3ctgP14 xOVq8qVVtfqTDHqP8ImXwEwTvVFBh0PEm8M/SC7Swoo6zTKFZnypQLhVBPZw0Zno5Lro sq9Q== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 33/40] tools: change struct precopy_stats to precopy_stats_t Date: Thu, 1 Jul 2021 11:56:28 +0200 Message-Id: <20210701095635.15648-34-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 3adcf2f83f..bb7e437291 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 e486bce96f..537b977ba8 100644 --- a/tools/libs/saverestore/save.c +++ b/tools/libs/saverestore/save.c @@ -488,7 +488,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) || @@ -515,13 +515,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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133738209140.42050425576588; Thu, 1 Jul 2021 03:02:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148445.274435 (Exim 4.92) (envelope-from ) id 1lytWH-0003Qx-J7; Thu, 01 Jul 2021 10:02:05 +0000 Received: by outflank-mailman (output) from mailman id 148445.274435; Thu, 01 Jul 2021 10:02: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 1lytWH-0003P2-AU; Thu, 01 Jul 2021 10:02:05 +0000 Received: by outflank-mailman (input) for mailman id 148445; Thu, 01 Jul 2021 10:02:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytSR-0004r4-IA for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:07 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.103]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c67c5005-9db6-4605-a9a1-894bd03374d3; Thu, 01 Jul 2021 09:57:04 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619ut5NZ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:55 +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: c67c5005-9db6-4605-a9a1-894bd03374d3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133416; 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=am1tugVzg71doIb/LdiNWtayiDvPFoCjZNyMmciOrqY=; b=S31S0Jt1lo62PKxR9+Zf+Yg69D9KtTrkK70UgDAz146NRRLagnFrm5ubU1mi6Qkg/q Q2GmvdaoeUv8qexauJe8nt7STm03F5HQ7NsRv++KlTNGUhXly65XZCvY9WmJ4DblKL01 l2FXO2a1tIKUC0XNjvSZsGBQcye/w0Ec2WQiUQCiDE0VGBu0cm4GjYGlak4zXxa6dV4Z YWNhhVHIhlrsyOBFjkKkSlItkPEeHUs2TLaYO6bZACVXFZv2yZ4nk+DN1wD5ArOT9tVl qwBaTla3EyL/J+ttb+EPxMC840ZGALDGTFqS9LCu32ZjbyWEHwjO5IIlNjijU0BufqPj sxFA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v20210701 34/40] tools: add callback to libxl for precopy_policy and precopy_stats_t Date: Thu, 1 Jul 2021 11:56:29 +0200 Message-Id: <20210701095635.15648-35-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 439c654733..57d7e4b4b8 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 1625133730373775.4996319711723; Thu, 1 Jul 2021 03:02:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148427.274419 (Exim 4.92) (envelope-from ) id 1lytW9-0002eA-MT; Thu, 01 Jul 2021 10:01:57 +0000 Received: by outflank-mailman (output) from mailman id 148427.274419; Thu, 01 Jul 2021 10:01:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytW9-0002dt-Ig; Thu, 01 Jul 2021 10:01:57 +0000 Received: by outflank-mailman (input) for mailman id 148427; Thu, 01 Jul 2021 10:01:57 +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 1lytTI-0004XT-VW for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:59:01 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b57223e9-2c81-48e3-9cc3-386dc2e0c882; Thu, 01 Jul 2021 09:57:05 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uu5Nc (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:56 +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: b57223e9-2c81-48e3-9cc3-386dc2e0c882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133416; 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=6LebzrvgpkRPMXPrQvQqUEqJ9oCT3tBlpGnE42P4LCk=; b=KT2oEP6NW3z/fhQra9nm6nrr4OkR+aMBAw2WhNwMdqzOjgFtj+nsKLqMH86Gu9OeWF LlSiZsZfYcSSTGdtpJwmH9jhuSYaI4DNAmpNp7nsDwkHmo5V5bQgQ/px8d5dckC+DVyw TAU1oeCtFoEWkjIvFi+7KJK6by5ZsOTEGJcronSu3U38UPGInxxfvw4LZRSDgMJsmJYw 5HuK9FOnwghE93c8NjAhB4WyPgINB0buk62Cs4AiIkddIWHu7t4K7fAHU3jZGNk7ISMg Ui1ph1RrWR9SXkTLHFXGAjGxsQyUGPBDT7d6F31zGVzX8W2oY4CM1KuZ/Me6ZY5rBazA t+/w== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v20210701 35/40] tools: add --max_iters to libxl_domain_suspend Date: Thu, 1 Jul 2021 11:56:30 +0200 Message-Id: <20210701095635.15648-36-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 70a6ebf438..594387bcf4 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -494,6 +494,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 5dbd27900f..9f98cd7f2b 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 57d7e4b4b8..8cbcc5282c 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3649,6 +3649,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 ca1dfa3525..9b6b3c99aa 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 Ignored.\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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16251337185772.9614311124094; Thu, 1 Jul 2021 03:01:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148414.274397 (Exim 4.92) (envelope-from ) id 1lytVx-0001UF-QN; Thu, 01 Jul 2021 10:01:45 +0000 Received: by outflank-mailman (output) from mailman id 148414.274397; Thu, 01 Jul 2021 10:01: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 1lytVx-0001TK-JF; Thu, 01 Jul 2021 10:01:45 +0000 Received: by outflank-mailman (input) for mailman id 148414; Thu, 01 Jul 2021 10:01:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytSl-0004r4-Iq for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:27 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 93bd6b54-8972-4d8c-89ba-2a118f2d9f0d; Thu, 01 Jul 2021 09:57:05 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uv5Nd (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:57 +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: 93bd6b54-8972-4d8c-89ba-2a118f2d9f0d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133417; 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=qkM58ppJmICGaCKigNV7+3gfD18mpe/eRIOurb3atVw=; b=opoJ9CuscHfKh938XdynCg6vYytGey1HlnnFvP5xY6scsH5sGuFIjFHDgyJ0rG5TzJ IMDQr8WmfR9w13tt5VFtKJhRXJjLQaufI43ltCdjZu1xFaZI3pDQ8ZcBvoDXbsQKGMIV E4/yqUbeaoMIXaru42ILvbuIQ27xrRx8IhLpjOB2sfG83qt2tWBLobXwOk183ZHCKtEU YGzlh7HHR5YZhBVNKvC4jKvazGZUF1Ymp2Llc2ToElFqUZa9LJoxHzDbO7VWxecRsH8U 2udlcuogzyR9SpSWDYUvZvr8I2gXlhpoYFSQj2VGC0efQFSrxZ121c3mDnOT5t8ukWul CPKw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v20210701 36/40] tools: add --min_remaining to libxl_domain_suspend Date: Thu, 1 Jul 2021 11:56:31 +0200 Message-Id: <20210701095635.15648-37-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 594387bcf4..09e866ad87 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -498,6 +498,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 9f98cd7f2b..06ca7a7df6 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 8cbcc5282c..e4bfb34085 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3650,6 +3650,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 9b6b3c99aa..2cb4980c80 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 Ignored.\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 Ignored.\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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133730529833.5796737325103; Thu, 1 Jul 2021 03:02:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148421.274408 (Exim 4.92) (envelope-from ) id 1lytW3-0001zk-AG; Thu, 01 Jul 2021 10:01:51 +0000 Received: by outflank-mailman (output) from mailman id 148421.274408; Thu, 01 Jul 2021 10:01:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytW3-0001zX-6q; Thu, 01 Jul 2021 10:01:51 +0000 Received: by outflank-mailman (input) for mailman id 148421; Thu, 01 Jul 2021 10:01: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 1lytTS-0004XT-W1 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:59:11 +0000 Received: from mo4-p04-ob.smtp.rzone.de (unknown [85.215.255.122]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f973a37b-9f1f-4660-8e4f-726fae1d291d; Thu, 01 Jul 2021 09:57:07 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uv5Nf (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:57 +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: f973a37b-9f1f-4660-8e4f-726fae1d291d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133417; 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=+vXVfBW28MRAf3KK7IPzTuDzNHY/m8g7e2aJIg9hVrs=; b=mQJXm+gETkM4L9PcGKaP0zQZrcAyvvuvqZfXYqF43MKmkyonGJtqflRsmgEpgSEDQM bCgEy8MGNe6QGTsNoy25Jly2+iKZ47dScLpt+ytN+fqTFx6ad8MXve5I7oiYABck4EG9 YwTWFQJc149KIgNCQOz8xP0cK6P/27jc+gIUn3naWAHKfXPedfTScX3X8qPHz3b6d+di mXdeumlqDMz7Q0cYUKJ8n2zB/c1KVBAJXarUesHdXJ+BuIPuIOPb3SFOgEm48Kf4dH7O GCKWGyqMqaKn3g0gUFzFB4bQERGAEr1kXZFFzDHBHOTJwOwyGAu/5g2DJOe1aslur9Un iRPg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v20210701 37/40] tools: add --abort_if_busy to libxl_domain_suspend Date: Thu, 1 Jul 2021 11:56:32 +0200 Message-Id: <20210701095635.15648-38-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 09e866ad87..37267c9171 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -506,6 +506,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 06ca7a7df6..e4740b063e 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 e4bfb34085..905d5179ba 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3648,9 +3648,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 2cb4980c80..322a47c2bc 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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133769047242.72863683808487; Thu, 1 Jul 2021 03:02:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148497.274540 (Exim 4.92) (envelope-from ) id 1lytWl-0000ER-LQ; Thu, 01 Jul 2021 10:02:35 +0000 Received: by outflank-mailman (output) from mailman id 148497.274540; Thu, 01 Jul 2021 10:02: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 1lytWl-0000E6-Ga; Thu, 01 Jul 2021 10:02:35 +0000 Received: by outflank-mailman (input) for mailman id 148497; Thu, 01 Jul 2021 10:02:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytSH-0004r4-Ht for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:57:57 +0000 Received: from mo4-p04-ob.smtp.rzone.de (unknown [85.215.255.123]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0fea3b19-9598-4b0d-8e2a-c7057ee0a005; Thu, 01 Jul 2021 09:57:03 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uv5Nj (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:57 +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: 0fea3b19-9598-4b0d-8e2a-c7057ee0a005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133418; 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=i+CtqX1HY7Q0UrDFSipaIMys+n7R0U7HixGDrxWfeJY=; b=hO+V6Ivo6IqbiuUjPoOD4+qcc8FkwAB9Ci1Ygzs+u7DBYKfrbswow5XDZaZiMnqPDM j4EEfMoB/HMaP2JxuESRHJbw5SNvW8fDAy26jNIE73+Lx5sYncXt2/sYF1wNR9d/Urm0 zhq4gle6Hkg946CQEFSV9rt3g7rOukJXm6yTuhRnkLoEajBapO9Qzo0yW8DI45mw8uTu WR5nk4+xYe6xOloLF0VlHUWVhEij2IQrcKhuUApPZ3w/czVD+Wx5J5IbbwD0RRNNn5Uh RTLOSFZowP0fiHcvjCDqKqihtd7EJmo5NeoPgUNim8sP+XpjZM+npzvS3J8LdYWXjEjD Idbw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 38/40] tools: add API for expandable bitmaps Date: Thu, 1 Jul 2021 11:56:33 +0200 Message-Id: <20210701095635.15648-39-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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, some 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 | 39 +++++++++++++++++++ tools/libs/saverestore/common.h | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/tools/libs/saverestore/common.c b/tools/libs/saverestore/commo= n.c index 7da7fa4e2c..e96173eea2 100644 --- a/tools/libs/saverestore/common.c +++ b/tools/libs/saverestore/common.c @@ -163,6 +163,45 @@ 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 _sr_bitmap_expand(struct 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; + new_max |=3D sizeof(unsigned long) > 4 ? new_max >> 32 : 0; + + /* 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 bb7e437291..e6a269c482 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 sr_bitmap +{ + void *p; + unsigned long bits; +}; + +extern bool _sr_bitmap_expand(struct sr_bitmap *bm, unsigned long bits); + +static inline bool sr_bitmap_expand(struct sr_bitmap *bm, unsigned long bi= ts) +{ + if (bits > bm->bits) + return _sr_bitmap_expand(bm, bits); + return true; +} + +static inline void sr_bitmap_free(struct sr_bitmap *bm) +{ + free(bm->p); + bm->p =3D NULL; +} + +static inline bool sr_set_bit(unsigned long bit, struct sr_bitmap *bm) +{ + if (sr_bitmap_expand(bm, bit) =3D=3D false) + return false; + + set_bit(bit, bm->p); + return true; +} + +static inline bool sr_test_bit(unsigned long bit, struct sr_bitmap *bm) +{ + if (bit > bm->bits) + return false; + return !!test_bit(bit, bm->p); +} + +static inline void sr_clear_bit(unsigned long bit, struct sr_bitmap *bm) +{ + if (bit <=3D bm->bits) + clear_bit(bit, bm->p); +} + +static inline bool sr_test_and_clear_bit(unsigned long bit, struct sr_bitm= ap *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 sr_test_and_set_bit(unsigned long bit, struct sr_bitmap= *bm) +{ + if (bit > bm->bits) + return false; + return !!test_and_set_bit(bit, bm->p); +} + +static inline bool sr_set_long_bit(unsigned long base_bit, struct sr_bitma= p *bm) +{ + if (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 Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133713517891.0611325981527; Thu, 1 Jul 2021 03:01:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148400.274364 (Exim 4.92) (envelope-from ) id 1lytVn-0000Yy-QB; Thu, 01 Jul 2021 10:01:35 +0000 Received: by outflank-mailman (output) from mailman id 148400.274364; Thu, 01 Jul 2021 10:01: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 1lytVn-0000Yr-Ml; Thu, 01 Jul 2021 10:01:35 +0000 Received: by outflank-mailman (input) for mailman id 148400; Thu, 01 Jul 2021 10:01:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lytSM-0004r4-I9 for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:58:02 +0000 Received: from mo4-p04-ob.smtp.rzone.de (unknown [85.215.255.122]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1484be7f-e3e1-4bc4-ab2f-7a05b66e3d57; Thu, 01 Jul 2021 09:57:03 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uw5Nl (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:58 +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: 1484be7f-e3e1-4bc4-ab2f-7a05b66e3d57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133418; 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=Oumv/ZrrKNwjWjAhsQKBr42sudweonBRtwKbyL8SE78=; b=IydUb5tErdauBPAIJFpbM8CuvoK9RaRo2nZFUhcwRrajNbMwvAvcEtGQBd9vJtZec0 Nl0NJfWLBwXaEA3C5u6S3Eh76OlZW8zwH3kxa46UVDGk2icwpahjTyNBEMGIWr7jTYt0 1coCcLp67mgcr+rLn51crUs05ZxIjRuC76I+JfQ9bOdAgfm2LAyXlNTEWNmc0GhDFALa S+19YftOqIvZ2kgYNVz2V+g8UGObGDigiFdmhyeFbTiiBODeqjAmPs3dm34a3jTRLL1m ajm/TWPsmpOy9YwGv8VKD2BVbAy+Zo1X4vH+EDJMeGB2K2CdDhBfHDR4jEm2wsWc4VW5 h+LA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 39/40] tools: use xg_sr_bitmap for populated_pfns Date: Thu, 1 Jul 2021 11:56:34 +0200 Message-Id: <20210701095635.15648-40-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 v02: - remove xg_ prefix from called functions --- 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 e6a269c482..a610483fe7 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 sr_bitmap populated_pfns; =20 /* Sender has invoked verify mode on the stream. */ bool verify; @@ -647,6 +646,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 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 ( 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 53f05f1b65..baf8ea44e5 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..97e7e0f48c 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 ( !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) { + 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..c73a3cd99f 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 ( !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) { + sr_bitmap_free(&ctx->restore.populated_pfns); free(ctx->x86.pv.p2m); free(ctx->x86.pv.p2m_pfns); =20 From nobody Mon Apr 29 10:16:51 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1625133740280937.4497628027552; Thu, 1 Jul 2021 03:02:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.148441.274430 (Exim 4.92) (envelope-from ) id 1lytWH-0003LB-4z; Thu, 01 Jul 2021 10:02:05 +0000 Received: by outflank-mailman (output) from mailman id 148441.274430; Thu, 01 Jul 2021 10:02: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 1lytWG-0003Ky-U4; Thu, 01 Jul 2021 10:02:04 +0000 Received: by outflank-mailman (input) for mailman id 148441; Thu, 01 Jul 2021 10:02:03 +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 1lytTN-0004XT-Vj for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 09:59:06 +0000 Received: from mo4-p04-ob.smtp.rzone.de (unknown [85.215.255.122]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d24312b3-d57c-445e-b1b2-eafe1123a619; Thu, 01 Jul 2021 09:57:05 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.28.1 AUTH) with ESMTPSA id 30791cx619uw5Nm (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 1 Jul 2021 11:56:58 +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: d24312b3-d57c-445e-b1b2-eafe1123a619 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625133419; 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=4BSb6eeDkPifgS8HDSbSVDpKklU68Xf6WI9Hag1dmvM=; b=jBLrRaJpTQvsf6M1Gf2VBUS4pkLKBkyObynQud5Q4/eSVIM/iRSt15fDhO0tHwnAlv 1FKyCbr7cEwRob38K+L9xBwQyGemJtmQDHZW1RGBJFV3r9uh2FchWrUoJmWK/peMHWaY Om7XyUXvaijdTNHWG5kOq0G0K1qv7u2zLFzoAYkDdWIkAbPjXkk9x6WEKk7tzQRtltFK u9snzNkHACAukU58d3VqFGSKIwnXOTNuP7q+2QhWLUBTAS5dUTFQECkZ4GMvuRDQ3KfV zAfJOSNmOWLmxW8r7SHCxOJSGXBfR5kLsYoDK7bb6YOi9NScjR25bpmL09IgfslKHBTl zchA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg5lqlz7EsstGyDcxK3Mbajr+SQKopp1Cb0CyyaZQQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v20210701 40/40] tools/libxc: use superpages during restore of HVM guest Date: Thu, 1 Jul 2021 11:56:35 +0200 Message-Id: <20210701095635.15648-41-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210701095635.15648-1-olaf@aepfle.de> References: <20210701095635.15648-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 v02: - remove xg_ prefix from called functions --- tools/libs/guest/xg_dom_x86.c | 5 - tools/libs/guest/xg_private.h | 5 + tools/libs/saverestore/common.c | 1 - tools/libs/saverestore/common.h | 28 +- tools/libs/saverestore/restore.c | 62 +--- tools/libs/saverestore/restore_x86_hvm.c | 370 ++++++++++++++++++++++- tools/libs/saverestore/restore_x86_pv.c | 61 +++- 7 files changed, 455 insertions(+), 77 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 28441ee13f..b7372e6bd5 100644 --- a/tools/libs/guest/xg_private.h +++ b/tools/libs/guest/xg_private.h @@ -179,4 +179,9 @@ struct xc_cpu_policy { }; #endif /* x86 */ =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 e96173eea2..8dbd516b1b 100644 --- a/tools/libs/saverestore/common.c +++ b/tools/libs/saverestore/common.c @@ -1,5 +1,4 @@ #include - #include "common.h" =20 #include diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/commo= n.h index a610483fe7..3d392f1ac9 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -219,6 +219,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 +376,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 +515,14 @@ struct xc_sr_context { /* HVM context blob. */ struct xc_sr_blob context; + + /* Bitmap of currently allocated PFNs during resto= re. */ + struct sr_bitmap attempted_1g; + struct sr_bitmap attempted_2m; + struct sr_bitmap allocated_pfns; + xen_pfn_t prev_populated_pfn; + xen_pfn_t iteration_tracker_pfn; + unsigned long iteration; } restore; }; } hvm; @@ -567,14 +587,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 baf8ea44e5..5ad3df49ba 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_to_populate(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 97e7e0f48c..f45635613f 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 sr_bitmap *bm; + + bm =3D &ctx->x86.hvm.restore.attempted_1g; + if ( !sr_bitmap_expand(bm, max_pfn >> SUPERPAGE_1GB_SHIFT) ) + return false; + + bm =3D &ctx->x86.hvm.restore.attempted_2m; + if ( !sr_bitmap_expand(bm, max_pfn >> SUPERPAGE_2MB_SHIFT) ) + return false; + + bm =3D &ctx->x86.hvm.restore.allocated_pfns; + if ( !sr_bitmap_expand(bm, max_pfn) ) + return false; + + return true; +} + /* * restore_ops function. Confirms the stream matches the domain. */ @@ -164,12 +183,21 @@ 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 ( !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; + + /* FIXME: distinguish between PVH and HVM */ + /* No superpage in 1st 2MB due to VGA hole */ + sr_set_bit(0, &ctx->x86.hvm.restore.attempted_1g); + 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 +278,9 @@ static int x86_hvm_stream_complete(struct xc_sr_context= *ctx) static int x86_hvm_cleanup(struct xc_sr_context *ctx) { sr_bitmap_free(&ctx->restore.populated_pfns); + sr_bitmap_free(&ctx->x86.hvm.restore.attempted_1g); + sr_bitmap_free(&ctx->x86.hvm.restore.attempted_2m); + 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 +289,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) +{ + 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) +{ + 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 ( 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++ ) + sr_set_bit((sp->base_pfn >> SUPERPAGE_2MB_SHIFT) + i, &ctx->x86.hv= m.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 ( 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 ( 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 + { + 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 + { + 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 ( sr_test_and_clear_bit(pfn, &ctx->x86.hvm.restore.allocated_pf= ns) ) + { + 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) +{ + 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 to_populate, 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]; + + to_populate =3D page_type_to_populate(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 ( to_populate && !populated ) + { + rc =3D x86_hvm_populate_page(ctx, pfn); + } else if ( !to_populate && 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 +627,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 c73a3cd99f..244f1da218 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,