From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992038; cv=none; d=zohomail.com; s=zohoarc; b=ZEyiFRSBGL5goenu5Y1CRLxaA5L6038Nv7I54o+8KIjUlHeIWby8sWRgBAQDCGosgHd0gJjUGIsfee1Leoo+GRdIz0SyQIn4oGH2/1Hg+P7VM6jwCPDKPW+Ex9TR4OvgCjlhqr8xbCjs9kxRLc/SDdTjlouRj5/8iUU0BPnYWSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992038; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AJouOKw1M1RuOZDP/M7JpmShmV/UDPt9XmfG61mTqBM=; b=VXjtyZR83H81k/p25OxCQxfs4Swb57HwiJ/Ro/DKzFEvwtigv7QvIJPldl+u1vdPIho+DemYsp4u6SA1jRLasGL5xENXmsUyf8DEjnhUpMsLyGRWFk81onwR0r0870xDyhFyjNuABod2jw9N0nHF7JFVRyN1YQlN0vEBFxpUDlY= ARC-Authentication-Results: i=1; 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 1603992038010954.0368478990284; Thu, 29 Oct 2020 10:20:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14412.35595 (Exim 4.92) (envelope-from ) id 1kYBaz-0003MT-Us; Thu, 29 Oct 2020 17:20:17 +0000 Received: by outflank-mailman (output) from mailman id 14412.35595; Thu, 29 Oct 2020 17:20: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 1kYBaz-0003MM-Ro; Thu, 29 Oct 2020 17:20:17 +0000 Received: by outflank-mailman (input) for mailman id 14412; Thu, 29 Oct 2020 17:20: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 1kYBay-0003MC-Md for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:16 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [85.215.255.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 548caff4-7b70-4619-80c3-5022562d6d8c; Thu, 29 Oct 2020 17:20:15 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK83f6 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:08 +0100 (CET) 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 1kYBay-0003MC-Md for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:16 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [85.215.255.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 548caff4-7b70-4619-80c3-5022562d6d8c; Thu, 29 Oct 2020 17:20:15 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK83f6 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:08 +0100 (CET) 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: 548caff4-7b70-4619-80c3-5022562d6d8c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992014; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=AJouOKw1M1RuOZDP/M7JpmShmV/UDPt9XmfG61mTqBM=; b=b9EoRL0cCnT0G6ceRd2tkuBc8C94KzJHGVcRjuv2TylBtex+NqiUNmZmxZeLdAmS+I HLxXRFQ+GIhEA3CuJh76BvDug7R4wEazub58uzPNLJ3XL6c1fAGEAhPeaIWak+KZXJPr 1uruhvsDVj//YD1r/iOtsJIAhbV4cPcepqNLQmkS2yc6xGYohj+y4KtHYepfSyahTC8L 9ACpw6en5GVPoWxjNvbAbcKlj/KZHo0IrF71LJomAgTD0Vt5YiqsMep/8XiWy45ys3pB Bx8PS9G0bWzx60q3HqhTMVwZmNbMyQJ/DzCtbhVntscZPQdHFBajXslo5LpFD1wJSMEQ iDfQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v1 01/23] tools: add readv_exact to libxenctrl Date: Thu, 29 Oct 2020 18:19:41 +0100 Message-Id: <20201029172004.17219-2-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Read a batch of iovec's. In the common case of short reads, finish individual iov's with read_exact. Signed-off-by: Olaf Hering --- tools/libs/ctrl/xc_private.c | 54 +++++++++++++++++++++++++++++++++++- tools/libs/ctrl/xc_private.h | 1 + 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index d94f846686..a86ed213a5 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -659,8 +659,23 @@ int write_exact(int fd, const void *data, size_t size) =20 #if defined(__MINIOS__) /* - * MiniOS's libc doesn't know about writev(). Implement it as multiple wri= te()s. + * MiniOS's libc doesn't know about readv/writev(). + * Implement it as multiple read/write()s. */ +int readv_exact(int fd, const struct iovec *iov, int iovcnt) +{ + int rc, i; + + for ( i =3D 0; i < iovcnt; ++i ) + { + rc =3D read_exact(fd, iov[i].iov_base, iov[i].iov_len); + if ( rc ) + return rc; + } + + return 0; +} + int writev_exact(int fd, const struct iovec *iov, int iovcnt) { int rc, i; @@ -675,6 +689,44 @@ int writev_exact(int fd, const struct iovec *iov, int = iovcnt) return 0; } #else +int readv_exact(int fd, const struct iovec *iov, int iovcnt) +{ + int rc =3D 0, idx =3D 0; + ssize_t len; + + while ( idx < iovcnt ) + { + len =3D readv(fd, &iov[idx], min(iovcnt - idx, IOV_MAX)); + if ( len =3D=3D -1 && errno =3D=3D EINTR ) + continue; + if ( len <=3D 0 ) + { + rc =3D -1; + goto out; + } + while ( len > 0 && idx < iovcnt ) + { + if ( len >=3D iov[idx].iov_len ) + { + len -=3D iov[idx].iov_len; + } + else + { + void *p =3D iov[idx].iov_base + len; + size_t l =3D iov[idx].iov_len - len; + + rc =3D read_exact(fd, p, l); + if ( rc ) + goto out; + len =3D 0; + } + idx++; + } + } +out: + return rc; +} + int writev_exact(int fd, const struct iovec *iov, int iovcnt) { struct iovec *local_iov =3D NULL; diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index f0b5f83ac8..5d2c7274fb 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -441,6 +441,7 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_m= mu *mmu); =20 /* Return 0 on success; -1 on error setting errno. */ int read_exact(int fd, void *data, size_t size); /* EOF =3D> -1, errno=3D0= */ +int readv_exact(int fd, const struct iovec *iov, int iovcnt); int write_exact(int fd, const void *data, size_t size); int writev_exact(int fd, const struct iovec *iov, int iovcnt); =20 From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992037; cv=none; d=zohomail.com; s=zohoarc; b=SLQM1TVVFkRuu2OrNxHpfPxtmLMaLYaCRsyFw4KFBsDS7ZLu5/DlozAiTpTBDak3i+n6Uy0oFkLmQDXZ9MdyC/D1/aphBTVIe52/aGRp1G5yDi2xUHHcxsdW/k8SOozBcawCZZHQLY0V9p8kqchpglY8trLZZoIlIgaXVGMkqto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992037; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8EOjWvQk239Wp/aWNifZAKC+Sjf+9ZihUrmLiKkJAAc=; b=cRQ/TTRY3mcmrmrmmnUUlZ6tZsb07iisjHozz1YEK9CdH5KUx6pxRXeVrMEMSkn8aC3uap16at6NRdXPENh+iRokbLnTBsE5qtZSArHrTSzUa1kVUjolXBfx3UySlgWuIuK4YhuTFKqFlJ+UPPWCaf1eDekY8ZXb9fHofIvUQ2Y= ARC-Authentication-Results: i=1; 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 1603992036743290.39997716784376; Thu, 29 Oct 2020 10:20:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14413.35600 (Exim 4.92) (envelope-from ) id 1kYBb0-0003Mu-8Z; Thu, 29 Oct 2020 17:20:18 +0000 Received: by outflank-mailman (output) from mailman id 14413.35600; Thu, 29 Oct 2020 17:20: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 1kYBb0-0003Mk-3c; Thu, 29 Oct 2020 17:20:18 +0000 Received: by outflank-mailman (input) for mailman id 14413; Thu, 29 Oct 2020 17:20: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 1kYBay-0003MD-No for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:16 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [85.215.255.20]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aab968a0-fda7-4de8-b9f9-2d4afecf3e0d; Thu, 29 Oct 2020 17:20:15 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK83f7 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:08 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBay-0003MD-No for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:16 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [85.215.255.20]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aab968a0-fda7-4de8-b9f9-2d4afecf3e0d; Thu, 29 Oct 2020 17:20:15 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK83f7 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:08 +0100 (CET) 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: aab968a0-fda7-4de8-b9f9-2d4afecf3e0d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992014; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=8EOjWvQk239Wp/aWNifZAKC+Sjf+9ZihUrmLiKkJAAc=; b=ebHuVvb9I0JhokgnvvB108AaZ3uzxamS+m3vMJQB3RA5DsHUOfuauo7wxMi2aS4Mm+ u8NrCVYpYNNl4wQBZQKlbC26m2VQom6iUaRc7o2x1peL2pOYkLjPiOYcXWPXcVSvm32P qbidfvNSbia/ylUA5ZHdKh/XREycotHAaCU0gU6e3Qldw205+cS9HV+H8gdUzyXflR3v lsFl48ckqEZFQJJxQcMpyKxztdmZksgu7flGhp29CMSn5dl70lZcaPn3IXQMPv2hRDE7 ga0KDPFDWzMqZ/Ly56xc+N7lrn+eZr46INlYT+3+jZGrz6z/eaN6Yv3LvbY8rVgAXSKt qtHQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v1 02/23] tools: add xc_is_known_page_type to libxenctrl Date: Thu, 29 Oct 2020 18:19:42 +0100 Message-Id: <20201029172004.17219-3-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Users of xc_get_pfn_type_batch may want to sanity check the data returned by Xen. Add a simple helper for this purpose. Signed-off-by: Olaf Hering --- tools/libs/ctrl/xc_private.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index 5d2c7274fb..afb08aafe1 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -421,6 +421,39 @@ void *xc_map_foreign_ranges(xc_interface *xch, uint32_= t dom, int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom, unsigned int num, xen_pfn_t *); =20 +/* Sanitiy check for types returned by Xen */ +static inline bool xc_is_known_page_type(xen_pfn_t type) +{ + bool ret; + + switch (type) + { + case XEN_DOMCTL_PFINFO_NOTAB: + + case XEN_DOMCTL_PFINFO_L1TAB: + case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L2TAB: + case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L3TAB: + case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L4TAB: + case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_XTAB: + case XEN_DOMCTL_PFINFO_XALLOC: + case XEN_DOMCTL_PFINFO_BROKEN: + ret =3D true; + break; + default: + ret =3D false; + break; + } + return ret; +} + void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits); void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits); =20 From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992040; cv=none; d=zohomail.com; s=zohoarc; b=UIlBAB1xzoL28qlihWaanEd4cxQN3zpC1YCiyh2HTDYA6HUy8L8rdT+/D5851hgrfk4HIsgpFjmdA5xQS6Fi5+q05KuVwl0AWv0hK6AskvpDITyow0pycIAhvsaZi8kXLVoqHqEMUc/GlZwTCdgv9mUDszgg7qO+HajnfWMN8yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992040; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nOFtdNXlk5HjYyxO1mkGMNqJ+Z1za/MxmXOScJ0HbPg=; b=cQaAGEogHpwV7EA+Zu6pqgzZeYlKguCeUiSA51/XXxFKVBC45ZiGgJULSEAYJ4co7YuW0jdIfk8HB2c5aiVRQG6Uys2s9TF/2a6hnvc44psKY48bmjbgxWLYRYnmLwGWm2/6zEL9qJwzj6U4D52uHHZ/4lFiH1NXZ+r0E70R2Zg= ARC-Authentication-Results: i=1; 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 1603992040745595.3993303956101; Thu, 29 Oct 2020 10:20:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14414.35619 (Exim 4.92) (envelope-from ) id 1kYBb5-0003Qw-Gw; Thu, 29 Oct 2020 17:20:23 +0000 Received: by outflank-mailman (output) from mailman id 14414.35619; Thu, 29 Oct 2020 17:20: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 1kYBb5-0003Qp-DC; Thu, 29 Oct 2020 17:20:23 +0000 Received: by outflank-mailman (input) for mailman id 14414; Thu, 29 Oct 2020 17:20: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 1kYBb3-0003MC-L3 for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:21 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [81.169.146.167]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f2ded997-a0ba-499a-9121-66cb54d56275; Thu, 29 Oct 2020 17:20:16 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK93f8 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:09 +0100 (CET) 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 1kYBb3-0003MC-L3 for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:21 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [81.169.146.167]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f2ded997-a0ba-499a-9121-66cb54d56275; Thu, 29 Oct 2020 17:20:16 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK93f8 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:09 +0100 (CET) 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: f2ded997-a0ba-499a-9121-66cb54d56275 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992015; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=nOFtdNXlk5HjYyxO1mkGMNqJ+Z1za/MxmXOScJ0HbPg=; b=K1on7XABhOD58zqU8Not3Jy8NtNKHxa7+wF/7CEvBGy0Xy50gVK77PKerWSLzU+So9 mHzWJMuN/kN5RrPggT/TH/mZQ78+ern0VAvdGZWDY5IV2fvDrTAiXfwrrrdlvJlujlkQ eT8gpkyVPxNJNNRtQ+oMeJ36NHmS8EdXyNfwXvOMgR62w+fQza04ErpoIRIIAk1QJRsl pSXi1Id9jJK4NCWJkSJ6MXk+OpskfrVo8RhyfN0NObP4+mmVnQ1nxapFNmnWLcgw/FM4 ehXSuTwR0ESHiKYrC3itFRjbE8b1pCFsQbUN1vauqXrs5pgQ1LUJTUosAD3b7q/8FUrR fr3A== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 03/23] tools: use xc_is_known_page_type Date: Thu, 29 Oct 2020 18:19:43 +0100 Message-Id: <20201029172004.17219-4-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_restore.c | 3 +-- tools/libs/guest/xg_sr_save.c | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index b57a787519..f1c3169229 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -406,8 +406,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) } =20 type =3D (pages->pfn[i] & PAGE_DATA_TYPE_MASK) >> 32; - if ( ((type >> XEN_DOMCTL_PFINFO_LTAB_SHIFT) >=3D 5) && - ((type >> XEN_DOMCTL_PFINFO_LTAB_SHIFT) <=3D 8) ) + if ( xc_is_known_page_type(type) =3D=3D false ) { ERROR("Invalid type %#"PRIx32" for pfn %#"PRIpfn" (index %u)", type, pfn, i); diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 2ba7c3200c..044d0ae3aa 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -147,6 +147,12 @@ static int write_batch(struct xc_sr_context *ctx) =20 for ( i =3D 0; i < nr_pfns; ++i ) { + if ( xc_is_known_page_type(types[i]) =3D=3D false ) + { + ERROR("Wrong type %#"PRIpfn" for pfn %#"PRIpfn, types[i], mfns= [i]); + goto err; + } + switch ( types[i] ) { case XEN_DOMCTL_PFINFO_BROKEN: From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992039; cv=none; d=zohomail.com; s=zohoarc; b=kkIohIumglxYb5JLgQGUtdzTCX6Y3vXM99jYPm5LtGsMtKq8vnb1J15sE+fjROAXovyG5earshkFk89zhFxMph9qUNhD50XHZYtxM2p/Jrtnk0Rz6HvCUCepX15N3keIZlxBZhCTV9G9LjkBrB9fuOpG/GrITCyYH9rHlYKKeuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992039; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yv4/vNzbLjhhKaj2O8jZKB9GBNc7GvmmLKVV7dABzFU=; b=UU/t/Y8xhe2XkM8iBfLVxK0iB4wD7o4mh1x8ryfZj8y6wRNpyZAKqQWGii3jSv9tPq65Q5UM/Ft/TwZ2AmZAP5atj6lQNd3pzb7yymYCI6grC2+vyp7kScxoNEnAeLC3fP9oNeXHXJiJDH1RqJlQBqSCCaFwck+SSSFgfhXJZgg= ARC-Authentication-Results: i=1; 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 1603992039995648.2598911953028; Thu, 29 Oct 2020 10:20:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14415.35627 (Exim 4.92) (envelope-from ) id 1kYBb6-0003Rm-1J; Thu, 29 Oct 2020 17:20:24 +0000 Received: by outflank-mailman (output) from mailman id 14415.35627; Thu, 29 Oct 2020 17:20: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 1kYBb5-0003RS-Os; Thu, 29 Oct 2020 17:20:23 +0000 Received: by outflank-mailman (input) for mailman id 14415; Thu, 29 Oct 2020 17:20:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBb3-0003MD-MS for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:21 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.53]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a2754cbc-b397-40ad-98e1-d30c24dfef73; Thu, 29 Oct 2020 17:20:17 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK93f9 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:09 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBb3-0003MD-MS for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:21 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [85.215.255.53]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a2754cbc-b397-40ad-98e1-d30c24dfef73; Thu, 29 Oct 2020 17:20:17 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THK93f9 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:09 +0100 (CET) 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: a2754cbc-b397-40ad-98e1-d30c24dfef73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992016; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=yv4/vNzbLjhhKaj2O8jZKB9GBNc7GvmmLKVV7dABzFU=; b=fd+jqgrBJT5aK88Qi2z21JZDs9LRityC/r22lmSVsVIZ6FbWPBDATcwEeIje6ECCll Vxq6lfCa64Vg2/JdeQEojiDDgKlADOQK/d9CZ8wtrX0vHclBRXwmXoQ8vFarwhKUdr1A QcvAoon4MJHY4kujwQlf7YdJmXVqpmeFnMTuiR5jKNInz1dT+JmafrMnGqOSN1Y01qrX YUefPoCd3tMTCAH95ngRFNgmmdDem0HeqZ0RvrPv7u6sMLEZ7/EBChhJcyiPVmgi8nhe dUcMGPMQxBFsd/xw6tWz3XA1a3PidbsFisvtkxhFn+UwjvL40reNj6JUXG4oOtzjLspa LwhQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 04/23] tools: unify type checking for data pfns in migration stream Date: Thu, 29 Oct 2020 18:19:44 +0100 Message-Id: <20201029172004.17219-5-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Introduce a helper which decides if a given pfn type has data for the migration stream. No change in behavior intended. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 17 ++++++++++++++++ tools/libs/guest/xg_sr_restore.c | 34 +++++--------------------------- tools/libs/guest/xg_sr_save.c | 14 ++----------- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index cc3ad1c394..70e328e951 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -455,6 +455,23 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned = int count, /* Handle a STATIC_DATA_END record. */ int handle_static_data_end(struct xc_sr_context *ctx); =20 +static inline bool page_type_has_stream_data(uint32_t type) +{ + bool ret; + + switch (type) + { + case XEN_DOMCTL_PFINFO_XTAB: + case XEN_DOMCTL_PFINFO_XALLOC: + case XEN_DOMCTL_PFINFO_BROKEN: + ret =3D false; + break; + default: + ret =3D true; + break; + } + return ret; +} #endif /* * Local variables: diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index f1c3169229..0332ae9f32 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -152,9 +152,8 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned i= nt count, =20 for ( i =3D 0; i < count; ++i ) { - if ( (!types || (types && - (types[i] !=3D XEN_DOMCTL_PFINFO_XTAB && - types[i] !=3D XEN_DOMCTL_PFINFO_BROKEN))) && + if ( (!types || + (types && page_type_has_stream_data(types[i]) =3D=3D true)) = && !pfn_is_populated(ctx, original_pfns[i]) ) { rc =3D pfn_set_populated(ctx, original_pfns[i]); @@ -233,25 +232,8 @@ static int process_page_data(struct xc_sr_context *ctx= , unsigned int count, { ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); =20 - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_NOTAB: - - case XEN_DOMCTL_PFINFO_L1TAB: - case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L2TAB: - case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L3TAB: - case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L4TAB: - case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: - + if ( page_type_has_stream_data(types[i]) =3D=3D true ) mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); - break; - } } =20 /* Nothing to do? */ @@ -271,14 +253,8 @@ static int process_page_data(struct xc_sr_context *ctx= , unsigned int count, =20 for ( i =3D 0, j =3D 0; i < count; ++i ) { - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_XTAB: - case XEN_DOMCTL_PFINFO_BROKEN: - case XEN_DOMCTL_PFINFO_XALLOC: - /* No page data to deal with. */ + if ( page_type_has_stream_data(types[i]) =3D=3D false ) continue; - } =20 if ( map_errs[j] ) { @@ -413,7 +389,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) goto err; } =20 - if ( type < XEN_DOMCTL_PFINFO_BROKEN ) + if ( page_type_has_stream_data(type) =3D=3D true ) /* NOTAB and all L1 through L4 tables (including pinned) should * have a page worth of data in the record. */ pages_of_data++; diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 044d0ae3aa..0546d3d9e6 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992049; cv=none; d=zohomail.com; s=zohoarc; b=TLZsu8eYwGOFYmVi/PDPol8YUhNTEdj63EIQIvPZMugzQSEfxCvW8G7HzsRjB7LjhvAkFAqT4tal3uhs9kCZFdqne7v7j5gNYAtZQaewiffpo2aDj9j5V3+PkOLs/C5AyRJkCq6Bl51Yg3ohMq0QDcSuvhmv4YVP3hxcZSfTk+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992049; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aHhooxXlVtScSWow8fmwlUPLQUlpWTQjy90bGrDLuPg=; b=eceXdVi3WcSD/86iJZecBxLDfhjZbfi6cXZxnkWPypJ1qrRhxdGuIvIIJE7MpsI490E0yeHyyURMFkr7uDOGitG8t2QDWVLUhBmXWZVB+Y/qgyLGEVjUG7byPMxktJrngDi1CUGSVjFo8G3V1SU9GqdXEHV86heKuCB6ow8vOhM= ARC-Authentication-Results: i=1; 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 1603992049613224.61488203423164; Thu, 29 Oct 2020 10:20:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14417.35650 (Exim 4.92) (envelope-from ) id 1kYBbB-0003ZV-1p; Thu, 29 Oct 2020 17:20:29 +0000 Received: by outflank-mailman (output) from mailman id 14417.35650; Thu, 29 Oct 2020 17:20: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 1kYBbA-0003Yy-Mp; Thu, 29 Oct 2020 17:20:28 +0000 Received: by outflank-mailman (input) for mailman id 14417; Thu, 29 Oct 2020 17:20:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBb8-0003MD-Mf for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:26 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [81.169.146.167]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 40a0b57d-7dc9-4a68-8ead-9123909cb445; Thu, 29 Oct 2020 17:20:17 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKA3fA (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:10 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBb8-0003MD-Mf for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:26 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [81.169.146.167]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 40a0b57d-7dc9-4a68-8ead-9123909cb445; Thu, 29 Oct 2020 17:20:17 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKA3fA (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:10 +0100 (CET) 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: 40a0b57d-7dc9-4a68-8ead-9123909cb445 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992016; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=aHhooxXlVtScSWow8fmwlUPLQUlpWTQjy90bGrDLuPg=; b=jfXAXmLLWiSnWD9wSRj3VcpPbKP02MIv9DSYJN1AR/tj6RQIJ7LMgiMz0Ul+tUkyqe IznA81YexYkgrNm+pToGKZEKf9WQbVlJbRdjewTT73yFfQC+dzNdrghhAWKFLQ803B4+ 3gyxAez5E1i9SJsJ2PTMslnvDg8WrupjzZ4k8SqusjS6F4HSo5Lfu2pBjr/8VOn6/+8K L0gh+09w3CriRYmKbgpC7RY6DcPnALGjEuwR5BMgRxnnDtg/ln9feJxu0+K2fTFgVhH5 3i+/O49sc+0BRFtozeqMZc14brss4rXu7cro/llkMj1+enpGghxSd8lUrbnINkvfFW6q 3Akw== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 05/23] tools: show migration transfer rate in send_dirty_pages Date: Thu, 29 Oct 2020 18:19:45 +0100 Message-Id: <20201029172004.17219-6-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Show how fast domU pages are transferred in each iteration. The relevant data is how fast the pfns travel, not so much how much protocol overhead exists. So the reported MiB/sec is just for pfns. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 70e328e951..f3a7a29298 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -238,6 +238,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/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 0546d3d9e6..f58a35ddde 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -1,5 +1,6 @@ #include #include +#include =20 #include "xg_sr_common.h" =20 @@ -238,6 +239,8 @@ static int write_batch(struct xc_sr_context *ctx) iov[3].iov_len =3D nr_pfns * sizeof(*rec_pfns); =20 iovcnt =3D 4; + ctx->save.pages_sent +=3D nr_pages; + ctx->save.overhead_sent +=3D sizeof(rec) + sizeof(hdr) + nr_pfns * siz= eof(*rec_pfns); =20 if ( nr_pages ) { @@ -357,6 +360,43 @@ static int suspend_domain(struct xc_sr_context *ctx) return 0; } =20 +static void show_transfer_rate(struct xc_sr_context *ctx, struct timespec = *start) +{ + xc_interface *xch =3D ctx->xch; + struct timespec end =3D {}, diff =3D {}; + size_t ms, MiB_sec =3D ctx->save.pages_sent * PAGE_SIZE; + + if (!MiB_sec) + return; + + if ( clock_gettime(CLOCK_MONOTONIC, &end) ) + PERROR("clock_gettime"); + + if ( (end.tv_nsec - start->tv_nsec) < 0 ) + { + diff.tv_sec =3D end.tv_sec - start->tv_sec - 1; + diff.tv_nsec =3D end.tv_nsec - start->tv_nsec + (1000U*1000U*1000U= ); + } + else + { + diff.tv_sec =3D end.tv_sec - start->tv_sec; + diff.tv_nsec =3D end.tv_nsec - start->tv_nsec; + } + + ms =3D (diff.tv_nsec / (1000U*1000U)); + if (!ms) + ms =3D 1; + ms +=3D (diff.tv_sec * 1000U); + + MiB_sec *=3D 1000U; + MiB_sec /=3D ms; + MiB_sec /=3D 1024U*1024U; + + errno =3D 0; + ERROR("%s: %zu bytes + %zu pages in %ld.%09ld sec, %zu MiB/sec", __fun= c__, + 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 +410,15 @@ static int send_dirty_pages(struct xc_sr_context *ctx, xen_pfn_t p; unsigned long written; int rc; + struct timespec start =3D {}; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); =20 + ctx->save.pages_sent =3D 0; + ctx->save.overhead_sent =3D 0; + if ( clock_gettime(CLOCK_MONOTONIC, &start) ) + PERROR("clock_gettime"); + for ( p =3D 0, written =3D 0; p < ctx->save.p2m_size; ++p ) { if ( !test_bit(p, dirty_bitmap) ) @@ -396,6 +442,7 @@ static int send_dirty_pages(struct xc_sr_context *ctx, if ( written > entries ) DPRINTF("Bitmap contained more entries than expected..."); =20 + show_transfer_rate(ctx, &start); xc_report_progress_step(xch, entries, entries); =20 return ctx->save.ops.check_vm_state(ctx); From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992054; cv=none; d=zohomail.com; s=zohoarc; b=Wq2WlcBx2Z5gKAd+j2m0XXUc7N9DT+rk56WdgFcbc+YJ+1Vv/+Cr0TCgf0wejsqakGjiIjfYuKeskcTfjVxlqEAuHbpzWIfGVPm5xCVlW09IVymzxBiQtwyQlHh3jABcH6zvJufapSxDRRv1h1PINT1eLtAKQdqttwbNHgCDFSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992054; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LTn6Zyyvrx+7UIt94Limr5RoX+Df4LpsEj+n6P0mPjI=; b=iyR701xy3+o7Ytf+Ktzjw75jyNiH2UeNwvfu0bvv21Nq3shaoRxjt5R5G8o8Skm463xEZzsvfjNR7XLspI19cTu0aboF9w8lGnI+33XJIhCheJRXKi+jf9RBlPzPyIfnFPpAjGOIXotJ1bePTX/BTNjaUuX6bZETTurYVChJLQc= ARC-Authentication-Results: i=1; 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 1603992054801706.4103802144405; Thu, 29 Oct 2020 10:20:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14423.35697 (Exim 4.92) (envelope-from ) id 1kYBbK-0003sh-HP; Thu, 29 Oct 2020 17:20:38 +0000 Received: by outflank-mailman (output) from mailman id 14423.35697; Thu, 29 Oct 2020 17:20:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbK-0003sA-3H; Thu, 29 Oct 2020 17:20:38 +0000 Received: by outflank-mailman (input) for mailman id 14423; Thu, 29 Oct 2020 17:20:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbI-0003MD-ND for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:36 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id da89125b-8752-45de-bff5-641a8ac91f59; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKA3fB (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:10 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbI-0003MD-ND for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:36 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id da89125b-8752-45de-bff5-641a8ac91f59; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKA3fB (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:10 +0100 (CET) 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: da89125b-8752-45de-bff5-641a8ac91f59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992017; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=LTn6Zyyvrx+7UIt94Limr5RoX+Df4LpsEj+n6P0mPjI=; b=cyiChVrN7bX7kbJ1XJcd0kh4utBwBfFXspgce7T2qyODlrBf9aVGxzZ9XMD+AK6/mv bkx0vDZIqyZrhkHQqd+NGt5i1M7IIUjM46XuSeQGy3CdJJCs/Nu5mlv1rT/eFY2GBJcZ Lzaz/QieYwv7V/uyX3dXLNs6GYHUJ5zOXG5Jkr+q8TGkE/JZuMbghh15jbeiqTV+bWfh mESHS2Wu+iVmkVZRb3Ez+jrlvw7JQodkJCPqh72/Vmn/J/FWQH6DRYZs1FuZG8AT4i9Q BjKQ/W+HuxmqsXvrnS1ue/YTAp13nb6tW0epcjq6L3LJTkeVS3r5R+MSZh0mpH69Zm8m vP5A== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 06/23] tools/guest: prepare to allocate arrays once Date: Thu, 29 Oct 2020 18:19:46 +0100 Message-Id: <20201029172004.17219-7-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The hotpath 'send_dirty_pages' is supposed to do just one thing: sending. The other end 'handle_page_data' is supposed to do just receiving. But instead both do other costly work like memory allocations and data movi= ng. Do the allocations once, the array sizes are a compiletime constant. Avoid unneeded copying of data by receiving data directly into mapped guest= memory. This patch is just prepartion, subsequent changes will populate the arrays. Once all changes are applied, migration of a busy HVM domU changes like tha= t: Without this series, from sr650 to sr950 (xen-4.15.20201027T173911.16a20963= b3 xen_testing): 2020-10-29 10:23:10.711+0000: xc: show_transfer_rate: 23663128 bytes + 2879= 563 pages in 55.324905335 sec, 203 MiB/sec: Internal error 2020-10-29 10:23:35.115+0000: xc: show_transfer_rate: 16829632 bytes + 2097= 552 pages in 24.401179720 sec, 335 MiB/sec: Internal error 2020-10-29 10:23:59.436+0000: xc: show_transfer_rate: 16829032 bytes + 2097= 478 pages in 24.319025928 sec, 336 MiB/sec: Internal error 2020-10-29 10:24:23.844+0000: xc: show_transfer_rate: 16829024 bytes + 2097= 477 pages in 24.406992500 sec, 335 MiB/sec: Internal error 2020-10-29 10:24:48.292+0000: xc: show_transfer_rate: 16828912 bytes + 2097= 463 pages in 24.446489027 sec, 335 MiB/sec: Internal error 2020-10-29 10:25:01.816+0000: xc: show_transfer_rate: 16836080 bytes + 2098= 356 pages in 13.447091818 sec, 609 MiB/sec: Internal error With this series, from sr650 to sr950 (xen-4.15.20201027T173911.16a20963b3 = xen_unstable): 2020-10-28 21:26:05.074+0000: xc: show_transfer_rate: 23663128 bytes + 2879= 563 pages in 52.564054368 sec, 213 MiB/sec: Internal error 2020-10-28 21:26:23.527+0000: xc: show_transfer_rate: 16830040 bytes + 2097= 603 pages in 18.450592015 sec, 444 MiB/sec: Internal error 2020-10-28 21:26:41.926+0000: xc: show_transfer_rate: 16830944 bytes + 2097= 717 pages in 18.397862306 sec, 445 MiB/sec: Internal error 2020-10-28 21:27:00.339+0000: xc: show_transfer_rate: 16829176 bytes + 2097= 498 pages in 18.411973339 sec, 445 MiB/sec: Internal error 2020-10-28 21:27:18.643+0000: xc: show_transfer_rate: 16828592 bytes + 2097= 425 pages in 18.303326695 sec, 447 MiB/sec: Internal error 2020-10-28 21:27:26.289+0000: xc: show_transfer_rate: 16835952 bytes + 2098= 342 pages in 7.579846749 sec, 1081 MiB/sec: Internal error Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 8 ++++++++ tools/libs/guest/xg_sr_restore.c | 8 ++++++++ tools/libs/guest/xg_sr_save.c | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index f3a7a29298..62bc87b5f4 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -211,6 +211,12 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct xc_sr_save_arrays { +}; + +struct xc_sr_restore_arrays { +}; + struct xc_sr_context { xc_interface *xch; @@ -248,6 +254,7 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct xc_sr_save_arrays *m; } save; =20 struct /* Restore data. */ @@ -299,6 +306,7 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + struct xc_sr_restore_arrays *m; } restore; }; =20 diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 0332ae9f32..4a9ece9681 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -739,6 +739,13 @@ static int setup(struct xc_sr_context *ctx) } ctx->restore.allocated_rec_num =3D DEFAULT_BUF_RECORDS; =20 + ctx->restore.m =3D malloc(sizeof(*ctx->restore.m)); + if ( !ctx->restore.m ) { + ERROR("Unable to allocate memory for arrays"); + rc =3D -1; + goto err; + } + err: return rc; } @@ -757,6 +764,7 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size))= ); =20 + free(ctx->restore.m); free(ctx->restore.buffered_records); free(ctx->restore.populated_pfns); =20 diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index f58a35ddde..1e3c8eff2f 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -853,8 +853,9 @@ static int setup(struct xc_sr_context *ctx) ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); + ctx->save.m =3D malloc(sizeof(*ctx->save.m)); =20 - if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pag= es ) + if ( !ctx->save.m || !ctx->save.batch_pfns || !dirty_bitmap || !ctx->s= ave.deferred_pages ) { ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" " deferred pages"); @@ -886,6 +887,7 @@ static void cleanup(struct xc_sr_context *ctx) NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); free(ctx->save.batch_pfns); + free(ctx->save.m); } =20 /* From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992043; cv=none; d=zohomail.com; s=zohoarc; b=Gv0v3hTAZ/Lb+ejnh+qQ7HiBAG/J2DATiVuOZhuioiwif8ZkqIBxU7LoRUdSnqBRlSd37zYG2qppzxQJZiuWF+ap7cKp6NAGwu+4WBOUhWOdiYGEQUuCShEbKX95tn5YNVCuMlg9mdrd9EA8sV+NE8oQbkXnrn34TOA3MVzj98U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992043; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s6U8mXu6k+6wrCilP+jHEKI7OfSE2V+H39V5VeQDOaY=; b=Oi6fxNFjYMvULYm98GJCIAr5hrJdxLkO+TkItd2Z88hODAZqBIs/ARc3iz/5tttRNm9rsv1QjFDNoJzut3oTyVUShgkxgTWt7VTuAppehET87KM8Guc1scmU82UycLqyyPi3qnKJWr7TawzzEnWx83GaMe20R765vF1bqyFTfNM= ARC-Authentication-Results: i=1; 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 1603992043357284.1344232430432; Thu, 29 Oct 2020 10:20:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14416.35643 (Exim 4.92) (envelope-from ) id 1kYBbA-0003YI-Ec; Thu, 29 Oct 2020 17:20:28 +0000 Received: by outflank-mailman (output) from mailman id 14416.35643; Thu, 29 Oct 2020 17:20: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 1kYBbA-0003Y9-AY; Thu, 29 Oct 2020 17:20:28 +0000 Received: by outflank-mailman (input) for mailman id 14416; Thu, 29 Oct 2020 17:20: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 1kYBb8-0003MC-LG for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:26 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 694b2120-ffda-4093-b495-670ba2163d55; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKA3fC (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:10 +0100 (CET) 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 1kYBb8-0003MC-LG for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:26 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 694b2120-ffda-4093-b495-670ba2163d55; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKA3fC (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:10 +0100 (CET) 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: 694b2120-ffda-4093-b495-670ba2163d55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992017; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=s6U8mXu6k+6wrCilP+jHEKI7OfSE2V+H39V5VeQDOaY=; b=qh2TZXRzZOzPKSr3D4EgM+qiL5MOJM9yXCQmI5+7JzmNbWXfcgswCnujKQLgtnRP4u ZiE6mkGd0FGFAk3zqxXi4njEhwNugU7ZJTjMlkWzARPSNshC3JNeKSRaSMv9zgthSVwv gW06sSBDWgTZtg9Wtc3f8+mnfk7tlX24tvrJ0uYqGMdmLnlT3aItA4WupjhEZAS45E+K 8Ht7fktlshpTQp5FK6614uaCuNo1AlC3ZfaE1R/BYpSePbtL4BPOZ+zn9GXy7jXG4w9x FUvETc8roCyzp/F2GlWiUuINx+o60tlacAMmMQWP97zMtOPxJlkMzMth/+4oZ4FxJjdx xp6w== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 07/23] tools/guest: save: move batch_pfns Date: Thu, 29 Oct 2020 18:19:47 +0100 Message-Id: <20201029172004.17219-8-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The batch_pfns array is already allocated in advance. Move it into the preallocated area. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 2 +- tools/libs/guest/xg_sr_save.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 62bc87b5f4..c78a07b8f8 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -212,6 +212,7 @@ static inline int update_blob(struct xc_sr_blob *blob, } =20 struct xc_sr_save_arrays { + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { @@ -249,7 +250,6 @@ struct xc_sr_context =20 struct precopy_stats stats; =20 - xen_pfn_t *batch_pfns; unsigned int nr_batch_pfns; unsigned long *deferred_pages; unsigned long nr_deferred_pages; diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 1e3c8eff2f..597e638c59 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -77,7 +77,7 @@ static int write_checkpoint_record(struct xc_sr_context *= ctx) =20 /* * Writes a batch of memory as a PAGE_DATA record into the stream. The ba= tch - * is constructed in ctx->save.batch_pfns. + * is constructed in ctx->save.m->batch_pfns. * * This function: * - gets the types for each pfn in the batch. @@ -128,12 +128,12 @@ static int write_batch(struct xc_sr_context *ctx) for ( i =3D 0; i < nr_pfns; ++i ) { types[i] =3D mfns[i] =3D ctx->save.ops.pfn_to_gfn(ctx, - ctx->save.batch_pfns= [i]); + ctx->save.m->batch_p= fns[i]); =20 /* Likely a ballooned page. */ if ( mfns[i] =3D=3D INVALID_MFN ) { - set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pages); + set_bit(ctx->save.m->batch_pfns[i], ctx->save.deferred_pages); ++ctx->save.nr_deferred_pages; } } @@ -179,7 +179,7 @@ static int write_batch(struct xc_sr_context *ctx) if ( errors[p] ) { ERROR("Mapping of pfn %#"PRIpfn" (mfn %#"PRIpfn") failed %= d", - ctx->save.batch_pfns[i], mfns[p], errors[p]); + ctx->save.m->batch_pfns[i], mfns[p], errors[p]); goto err; } =20 @@ -193,7 +193,7 @@ static int write_batch(struct xc_sr_context *ctx) { if ( rc =3D=3D -1 && errno =3D=3D EAGAIN ) { - set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pa= ges); + set_bit(ctx->save.m->batch_pfns[i], ctx->save.deferred= _pages); ++ctx->save.nr_deferred_pages; types[i] =3D XEN_DOMCTL_PFINFO_XTAB; --nr_pages; @@ -224,7 +224,7 @@ static int write_batch(struct xc_sr_context *ctx) rec.length +=3D nr_pages * PAGE_SIZE; =20 for ( i =3D 0; i < nr_pfns; ++i ) - rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; + rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.m->batch_= pfns[i]; =20 iov[0].iov_base =3D &rec.type; iov[0].iov_len =3D sizeof(rec.type); @@ -296,9 +296,9 @@ static int flush_batch(struct xc_sr_context *ctx) =20 if ( !rc ) { - VALGRIND_MAKE_MEM_UNDEFINED(ctx->save.batch_pfns, + VALGRIND_MAKE_MEM_UNDEFINED(ctx->save.m->batch_pfns, MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); + sizeof(*ctx->save.m->batch_pfns)); } =20 return rc; @@ -315,7 +315,7 @@ static int add_to_batch(struct xc_sr_context *ctx, xen_= pfn_t pfn) rc =3D flush_batch(ctx); =20 if ( rc =3D=3D 0 ) - ctx->save.batch_pfns[ctx->save.nr_batch_pfns++] =3D pfn; + ctx->save.m->batch_pfns[ctx->save.nr_batch_pfns++] =3D pfn; =20 return rc; } @@ -850,14 +850,12 @@ static int setup(struct xc_sr_context *ctx) =20 dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); - ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); ctx->save.m =3D malloc(sizeof(*ctx->save.m)); =20 - if ( !ctx->save.m || !ctx->save.batch_pfns || !dirty_bitmap || !ctx->s= ave.deferred_pages ) + if ( !ctx->save.m || !dirty_bitmap || !ctx->save.deferred_pages ) { - ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" + ERROR("Unable to allocate memory for dirty bitmaps and" " deferred pages"); rc =3D -1; errno =3D ENOMEM; @@ -886,7 +884,6 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); - free(ctx->save.batch_pfns); free(ctx->save.m); } =20 From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992051; cv=none; d=zohomail.com; s=zohoarc; b=Y0VtSTQDtOHV8Auy+7re6lSd7QfWcO6BR5P3oAXMVeUAHUZKdB4onCCYlMoRbbpqnK1X3YtbKpQV/2pz3gJP70wjwHjlGdj6Ofs9yf7yYBhaYxUw6e7WPOZydsYHRYUiVNbAjJg4QPi+OGce5JimOlmzi7KEAki4DqNyYF8O1jQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992051; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dcpi0RoPHtdIFCl+PLBz0qXMYWjsEXHpQRt3CZZau4g=; b=ga5qI9wwZeimHdQTIGETZFC83CSfWRNJQuyRoYnAw+8QNebxCn2e3sOUuo6AqSia8MsMyt2JeeTQE8GNkg19Vzf0b9ikOhb1OyWVgkM9wYJAZ6SnCpnodObxMyrEGb0ZWso8JWLFILiVJUe4UQngNYkjQ7Zrhy6aPiMZFxufXG8= ARC-Authentication-Results: i=1; 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 1603992051485160.45760409589764; Thu, 29 Oct 2020 10:20:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14419.35673 (Exim 4.92) (envelope-from ) id 1kYBbG-0003ic-08; Thu, 29 Oct 2020 17:20:34 +0000 Received: by outflank-mailman (output) from mailman id 14419.35673; Thu, 29 Oct 2020 17:20:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbF-0003iE-KZ; Thu, 29 Oct 2020 17:20:33 +0000 Received: by outflank-mailman (input) for mailman id 14419; Thu, 29 Oct 2020 17:20:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbD-0003MD-My for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:31 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 127c0127-9c7d-4b89-ac04-0ef80a5d7e3d; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKB3fD (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:11 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbD-0003MD-My for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:31 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 127c0127-9c7d-4b89-ac04-0ef80a5d7e3d; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKB3fD (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:11 +0100 (CET) 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: 127c0127-9c7d-4b89-ac04-0ef80a5d7e3d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992017; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=dcpi0RoPHtdIFCl+PLBz0qXMYWjsEXHpQRt3CZZau4g=; b=ijoHKnN8B92cG0ZgPu+XVZgFz9yoj6EfYeXfeeqipGOTC7DUSV/ZsxvS0dcUoQdIH/ fSBwyISTh/Aot3bYwGit11QA9Pl/9Vp8ibtLeNxWx3L8zlc0317d/sQtFm/XdF94Dg9P NHSkcedeLi2U/fdgBKfsU5W8EQ2Ik/GGOOOi8/+8xHHXMgFATvfSxvgYvc1CPT2pd1sR JGLquTspeeNgz6TJWQG3sx0/bZL1G4OB5Or0/y/AWd8oSLRfyIm1tgc6GLlz0mj4g/vm kHLpuxTcAywspG3wZ7Z2oeqz0g+YWuXSmD2OuLzHOHmCVL9gRk+pbJkULyA17Q+c338t oL+A== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 08/23] tools/guest: save: move mfns array Date: Thu, 29 Oct 2020 18:19:48 +0100 Message-Id: <20201029172004.17219-9-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index c78a07b8f8..0c2bef8f78 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -213,6 +213,8 @@ static inline int update_blob(struct xc_sr_blob *blob, =20 struct xc_sr_save_arrays { xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; + /* write_batch: Mfns of the batch pfns. */ + xen_pfn_t mfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 597e638c59..cdab288c3f 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992052; cv=none; d=zohomail.com; s=zohoarc; b=fM2wGmTm5DL6lbQWgdBThpIUOUspWN3eqP/90IbGYPy9ap+/51j4g/o804i0Hlq4S/2WbJXN8FAHzns/G58u8naAGGq/QwPOQ5GcmPuQ3oS/CToYy2Aoe0y+F6Qf3n0FzrNCEEUCJ28Gy4uD72V+D1F6UjbX1KfjL78gx9t6OiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992052; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kQfsNVsKk3NxmO3L5ZaWoX8Fyv7MojyLwaUWzvd0rkk=; b=UFsvnpf882fJGDNPk8YviLt3XoXGDVJRFRr9EpumxgoyoPQ2UNTFglJy8qSBD3AYoVJhp2zbT3zlUzD2LTtnIS6k9iYvPtoBIhXUHTjjCdNO7YuQq7mhNXXTFhKPg7otO8sP651pj6tBqjlY/CfDI6oFlpuIWZ2WlgHbRGFemuk= ARC-Authentication-Results: i=1; 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 1603992052563174.40048638936094; Thu, 29 Oct 2020 10:20:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14418.35667 (Exim 4.92) (envelope-from ) id 1kYBbF-0003hR-DM; Thu, 29 Oct 2020 17:20:33 +0000 Received: by outflank-mailman (output) from mailman id 14418.35667; Thu, 29 Oct 2020 17:20:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbF-0003hG-8P; Thu, 29 Oct 2020 17:20:33 +0000 Received: by outflank-mailman (input) for mailman id 14418; Thu, 29 Oct 2020 17:20: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 1kYBbD-0003MC-LT for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:31 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 16a7cb04-a854-45a3-a90c-5042f3c0a328; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKB3fE (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:11 +0100 (CET) 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 1kYBbD-0003MC-LT for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:31 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 16a7cb04-a854-45a3-a90c-5042f3c0a328; Thu, 29 Oct 2020 17:20:18 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKB3fE (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:11 +0100 (CET) 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: 16a7cb04-a854-45a3-a90c-5042f3c0a328 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992018; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=kQfsNVsKk3NxmO3L5ZaWoX8Fyv7MojyLwaUWzvd0rkk=; b=JOaVgOC3U0ye2T8Mnibg30o5Jl8LZLeoDlyFpQLyZUKZFpI1iVDy7YlGuUBHw7k7pJ lEBMhciP8OGN8a5nfrNQk4oCPIgo5zi6pddlxJGdYLZWlDJaEi2Xa8HVMo1rIj9r34w6 MKK6aDe3IpPqQipPLV1/ZVSyXj/+ypvK9Hx1nYvNdDEmaZTzFehzTUQagbUWpLfFIjRh rGmfWtMa4cuprrWipm6rfNzoRwQYolDgKdx76KZC22iwTfhDkWK5dcerSup7q1xAgAAq N0wtO9sckmXzuzqgbrSaKdEmzPeUv+JDqwpRBlsNLjN/LFOAZCOk1dlhf5EWaF3UhfIg tUsA== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 09/23] tools/guest: save: move types array Date: Thu, 29 Oct 2020 18:19:49 +0100 Message-Id: <20201029172004.17219-10-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 0c2bef8f78..3cbadb607b 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -215,6 +215,8 @@ struct xc_sr_save_arrays { xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; /* write_batch: Mfns of the batch pfns. */ xen_pfn_t mfns[MAX_BATCH_SIZE]; + /* write_batch: Types of the batch pfns. */ + xen_pfn_t types[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index cdab288c3f..6678df95b8 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992063; cv=none; d=zohomail.com; s=zohoarc; b=RvP8uT5+EiJNm6dRAVqQIrdxXIVlpKlXI/+DPTF6gEX5YSfy///XedlmrGHeSB6mdowNZJ+UBesAiJwSzmLQVeHt8tB1Vg1HnerrhejJGF40szVrwp2jbWN4ySHMYAsSqMwZ/q4tnqymFZ7cqKrmK62YfjKt0rltsrhkOeqH19I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992063; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zPzB2Ea/XkNgns/5zMr604KMV7uEET1uzQmhUGE8Zl4=; b=XVeZGio+Cw3v6MqPcAOP4IPVTbLcoUVtam+6bIrxmND3PpReRuqYpkl/omZImcycECfcJXexvtfDs9WIMDI6s6lK5qluyFKhXzcsIDJKxAAz0fImlpouzK+VGgGxRvSaewJE8L7lZUvzp68sG/oQWWVkIJhWt8bG5jFnGGuAMrA= ARC-Authentication-Results: i=1; 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 1603992063603125.91827959326588; Thu, 29 Oct 2020 10:21:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14431.35739 (Exim 4.92) (envelope-from ) id 1kYBbU-0004Dt-7r; Thu, 29 Oct 2020 17:20:48 +0000 Received: by outflank-mailman (output) from mailman id 14431.35739; Thu, 29 Oct 2020 17:20:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbU-0004Dd-1a; Thu, 29 Oct 2020 17:20:48 +0000 Received: by outflank-mailman (input) for mailman id 14431; Thu, 29 Oct 2020 17:20:46 +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 1kYBbS-0003MC-Lm for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:46 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1b787c47-ec20-4ce7-921c-3bdab7e6f4a0; Thu, 29 Oct 2020 17:20:19 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKC3fF (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:12 +0100 (CET) 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 1kYBbS-0003MC-Lm for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:46 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1b787c47-ec20-4ce7-921c-3bdab7e6f4a0; Thu, 29 Oct 2020 17:20:19 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKC3fF (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:12 +0100 (CET) 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: 1b787c47-ec20-4ce7-921c-3bdab7e6f4a0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992019; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=zPzB2Ea/XkNgns/5zMr604KMV7uEET1uzQmhUGE8Zl4=; b=Zm9Fxmnh227rnoPh2z1h87SP3mDURpyMdE8IBX/J4SoKhSODhFYo5HRzA/FrCMbYsc 6ghjx1ekd8+VgzU3ASVxKljdQfQWGHH76RCKJLsqq8FWPpPrpPrtNxucdE+1QbSotC+a u6zLoM5tQuXZs+rfR2ivsN6ESu/ViR2Vj4PokMlMEUE91BL8hoRGKKOrw+OraANLaMGS nfq5A0tZzB58TAsZ5KRyhjgRQxET7rs1li0pXSiQXHpffqUzK1lCkKqvEEQ6lfa9ZrAw FYqtoHipBWL7HJWaTVeVop0+vX7AlxlNFlAHr+XUpK+XOHUKsvzqC6LHx9aRoch730vT Zk6Q== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 10/23] tools/guest: save: move errors array Date: Thu, 29 Oct 2020 18:19:50 +0100 Message-Id: <20201029172004.17219-11-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 3cbadb607b..71b676c0e0 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -217,6 +217,8 @@ struct xc_sr_save_arrays { xen_pfn_t mfns[MAX_BATCH_SIZE]; /* write_batch: Types of the batch pfns. */ xen_pfn_t types[MAX_BATCH_SIZE]; + /* write_batch: Errors from attempting to map the gfns. */ + int errors[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 6678df95b8..cdc27a9cde 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992054; cv=none; d=zohomail.com; s=zohoarc; b=CHu0++4PUMLnDu/w2jIuk+f20r0/XwysstXAeUGZDsW/LhQepQxfM4jProBGRdvoHNFpZSARYLhr7+pPtfhTGMxUOTLx4lAtsUeWzkl9TmEfAZjHjNkJ3tOOk7RAxw6wFg2k6DGe59YVCol5GAgzLXE3gr9GRlxnwspPJFqU0PY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992054; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B++RYJANjQEZHzQRb6RRsob3izlvX5G7HJ1Rv0O4H+A=; b=WouZ3t0CGIo/1gMOddT2o22/NjTshk08Xo+eU70a71VX0E/WcrCFSKaLARsEqTQ9tGRImKsi8yRTAnaK2/YRAopS8BtmKmoK3ThtZMig0mO6c+HluPbY71qfOBrjSmulkxaKkyTNsitxRrUsIP6iYCvcYwGgFS0LsN4HbDX2su0= ARC-Authentication-Results: i=1; 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 1603992054157928.5724931808063; Thu, 29 Oct 2020 10:20:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14422.35691 (Exim 4.92) (envelope-from ) id 1kYBbJ-0003rH-Oo; Thu, 29 Oct 2020 17:20:37 +0000 Received: by outflank-mailman (output) from mailman id 14422.35691; Thu, 29 Oct 2020 17:20: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 1kYBbJ-0003r6-Ke; Thu, 29 Oct 2020 17:20:37 +0000 Received: by outflank-mailman (input) for mailman id 14422; Thu, 29 Oct 2020 17:20:36 +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 1kYBbI-0003MC-LV for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:36 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7ebe0a0c-9949-4068-aaaa-4cbe193ab190; Thu, 29 Oct 2020 17:20:19 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKC3fG (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:12 +0100 (CET) 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 1kYBbI-0003MC-LV for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:36 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7ebe0a0c-9949-4068-aaaa-4cbe193ab190; Thu, 29 Oct 2020 17:20:19 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKC3fG (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:12 +0100 (CET) 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: 7ebe0a0c-9949-4068-aaaa-4cbe193ab190 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992018; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=B++RYJANjQEZHzQRb6RRsob3izlvX5G7HJ1Rv0O4H+A=; b=WIz+NE+7xF6vT1cRZSz/As+Y7vlWr2VKQ6uf3nNZG8WvVgAUUTZT7tN/CK97UqIslb dShQsjixmwuLu5ZMK/YCZeDfuEZtOXVgZC0QWtSvXW2PY/zWQ3GL1jQg7YHhBT+mFcA/ f4pN6z29cyCwuxEpRk3Qqnhw9XshKX7KuRzSzU5S22JLyID9gmOHm1He3ku455uoCkV3 jUZ7fAKBG0G8pAZkOQwxg+cAKl5KnbphW/+6/yk/YaNKY/ig5wyy0hof4QQu09GS8DPL HjF5XWtQfMyum2eozgsQjJjs/7dLgJIv2cyQeQ3BtxDzJHdemmzBF6QzIk3Phrj37LhR aCzQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 11/23] tools/guest: save: move iov array Date: Thu, 29 Oct 2020 18:19:51 +0100 Message-Id: <20201029172004.17219-12-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 71b676c0e0..f315b4f526 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -219,6 +219,8 @@ struct xc_sr_save_arrays { xen_pfn_t types[MAX_BATCH_SIZE]; /* write_batch: Errors from attempting to map the gfns. */ int errors[MAX_BATCH_SIZE]; + /* write_batch: iovec[] for writev(). */ + struct iovec iov[MAX_BATCH_SIZE + 4]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index cdc27a9cde..385a591332 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992058; cv=none; d=zohomail.com; s=zohoarc; b=Tuc3iX372LSgPhISPMUmu+CvuKsIp4+BjhXkbLW+wOCz6zN0dF5njR6Shka1ksnJdvxC3+n8JXAM5XH4cBKZYz97tPhWw816Oi8hwOmptXqoNAaA1lZEYGJ4FD981L56ZFotLwfFVviIt5fKPN16zM3toNV1g4nCTtEwGa73kXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992058; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VVfW+oAH1Frox7ej6KApgNQS/Q90zBjaSWimvZM/Rz8=; b=OjaEbtKUBIZXi6I/1c0os/E3oIK2ZYH21+mD3KVJEkVf/7tW2FVLGOm8bqVo2sCItBebbIxzpMyExZjz2i3WwssnXoCQGrEZoLtTk8rT4q7NL4XoeGdtVC49kqf2+LZhy708bJsfMf7sCFLMpZ41JMXdyJwyrWkHkhTokWwMqCI= ARC-Authentication-Results: i=1; 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 1603992058610117.90601307377528; Thu, 29 Oct 2020 10:20:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14427.35715 (Exim 4.92) (envelope-from ) id 1kYBbO-000427-Tz; Thu, 29 Oct 2020 17:20:42 +0000 Received: by outflank-mailman (output) from mailman id 14427.35715; Thu, 29 Oct 2020 17:20: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 1kYBbO-00041n-OI; Thu, 29 Oct 2020 17:20:42 +0000 Received: by outflank-mailman (input) for mailman id 14427; Thu, 29 Oct 2020 17:20: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 1kYBbN-0003MC-Li for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:41 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b1211aba-36a0-4d14-9c12-d0ef84df3695; Thu, 29 Oct 2020 17:20:19 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKD3fH (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:13 +0100 (CET) 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 1kYBbN-0003MC-Li for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:41 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b1211aba-36a0-4d14-9c12-d0ef84df3695; Thu, 29 Oct 2020 17:20:19 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKD3fH (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:13 +0100 (CET) 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: b1211aba-36a0-4d14-9c12-d0ef84df3695 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992018; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=VVfW+oAH1Frox7ej6KApgNQS/Q90zBjaSWimvZM/Rz8=; b=TkkWMSXeFN2eROBRvYQywqH0q0qV5fFJK7u/XrU/lNwp2dPTpeaAsEx2FJNQzWfMC3 NDTxq9YTAmUp6nQDyAHjWRJlTn1XaODMO0lhzm9VrpQjQIRTKfJZCWLEEeD8JXzXaRMn PTOkpnCh0HneHbEaPr0fXD3M1P3rF+rMwSa3EPUWjpv5kBbsu/2i+87lfSaYRGrBcY49 +0wS65vNO5hVmAszhdW8WnhWK2GDZxJb7CmYSu6FgCH6AbHxVvUnhl3kkg+oVru0ibC0 nGJrLNRSvHN2Y/hJ+6ctaCyIuZY/WuIiI+nrjkLctW/dX81kQV6CFfX2nGQLbnkLedsp oLxQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 12/23] tools/guest: save: move rec_pfns array Date: Thu, 29 Oct 2020 18:19:52 +0100 Message-Id: <20201029172004.17219-13-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index f315b4f526..81158a4f4d 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -221,6 +221,8 @@ struct xc_sr_save_arrays { int errors[MAX_BATCH_SIZE]; /* write_batch: iovec[] for writev(). */ struct iovec iov[MAX_BATCH_SIZE + 4]; + /* write_batch */ + uint64_t rec_pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 385a591332..4d7fbe09ed 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992057; cv=none; d=zohomail.com; s=zohoarc; b=XcHdFppSGqGPRgLhCDOf6lW5/WFFXN+MkSwra/DoKN92e32m4lkES9QHLz5NculZwBm+Ii2QngjWxPjup1Of7t0//knfUx3SGiGgIe/TL1tLGlL37lIIdqJuuyReietmfNgymcuX5FGwNFzkkFzMs5YXkM4zc6A/wltYRvP939U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992057; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lkN1X6kUoB//sxPm6COzYhXSiEgr2M3yddCJzpbrAss=; b=Df2d7MhcXtan9Bq5ceyMIzYNKS02CpobP+wqdRgH6YKw20PPuSEMs2Q9L9NHVEI3CCBARs0dDyFYS24qIdE4mm53fFupGL0qZNkgqQt66let/ZpkknbbSOnhURSFIjXEMcfTth/PGlhqBOrXlrJKx2/HMF/JAuTCodwXgHKLVIs= ARC-Authentication-Results: i=1; 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 1603992057384135.18643749831176; Thu, 29 Oct 2020 10:20:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14428.35724 (Exim 4.92) (envelope-from ) id 1kYBbP-00043f-Pd; Thu, 29 Oct 2020 17:20:43 +0000 Received: by outflank-mailman (output) from mailman id 14428.35724; Thu, 29 Oct 2020 17:20:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbP-00042z-B3; Thu, 29 Oct 2020 17:20:43 +0000 Received: by outflank-mailman (input) for mailman id 14428; Thu, 29 Oct 2020 17:20:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbN-0003MD-NO for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:41 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.171]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1223d891-298a-419b-987a-b0e4d644f04c; Thu, 29 Oct 2020 17:20:20 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKD3fI (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:13 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbN-0003MD-NO for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:41 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.171]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1223d891-298a-419b-987a-b0e4d644f04c; Thu, 29 Oct 2020 17:20:20 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKD3fI (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:13 +0100 (CET) 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: 1223d891-298a-419b-987a-b0e4d644f04c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992019; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=lkN1X6kUoB//sxPm6COzYhXSiEgr2M3yddCJzpbrAss=; b=IHBp8bGT+CjzevJ5KObxjBTmwycrPlfQlA8m7+twU1iV2uRqoop2Pgp86SuPb6M/cm kSSc6cIZY/xBaOpru3unK+lnoGDj/kITm2y8d5m0RFzT9mhxW7OYZne+ho5+B3pq6NYC bjOhehhBO1yRDGmmET+BOmVJhifRB0L6+7E5bfset/Q47vIaIvevf7VcQ1SudJeTCrqk DlZ0NfrZOrb+DChRBUnjDC+id6rHlbZl/l9qcXpUPKqiFmwFpTJgIPlBaBKyxvJxmPhv 5NcOZ+s4zN7JyXWCel/K14wpryXivD4jgQ7w+GpA53x6vc7H/KNfaTba6tQ/ORImRsAc N0Gg== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 13/23] tools/guest: save: move guest_data array Date: Thu, 29 Oct 2020 18:19:53 +0100 Message-Id: <20201029172004.17219-14-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 81158a4f4d..33e66678c6 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -223,6 +223,8 @@ struct xc_sr_save_arrays { struct iovec iov[MAX_BATCH_SIZE + 4]; /* write_batch */ uint64_t rec_pfns[MAX_BATCH_SIZE]; + /* write_batch: Pointers to page data to send. Mapped gfns or local al= locations. */ + void *guest_data[MAX_BATCH_SIZE]; }; =20 struct xc_sr_restore_arrays { diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 4d7fbe09ed..658f834ae8 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992065; cv=none; d=zohomail.com; s=zohoarc; b=k68+ZyAzfo6uljHKWzhQq3d8cZ8rShwuBwHDaMfq4Gwpa+2R0e1XNNBExnSkCyME0RdkGL1PA9L8F5nx21g1E3QI54jaMFpTTvxBLXTrSmWER3/oEDdcH29pZQguHQ/ThOo4oCZlO1fqRX3pq42Hr/sCJusWUXTYtVNajeErHCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992065; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N7Hr2VOfOon4RnvyU1vv7pvNigOvHS1qA+Cy9MD8+GQ=; b=X4I7r+CAiPdVKaq/OG7vRjMmU55Ruhx/ACWo2xyIlvKOkjDob/GiIWGHZ7j5QS20eIFqnc42xg1tF9v+a3htOZKDTIw0R3AS+81Q8Q2tQhIdVrP0V/Y/1AWhUuIME4QURh491ETboF3Ug9WEWXxUje8to+Z0J80OpWpW6tZl2W4= ARC-Authentication-Results: i=1; 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 1603992065715913.3442988832395; Thu, 29 Oct 2020 10:21:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14432.35745 (Exim 4.92) (envelope-from ) id 1kYBbU-0004FL-Ut; Thu, 29 Oct 2020 17:20:48 +0000 Received: by outflank-mailman (output) from mailman id 14432.35745; Thu, 29 Oct 2020 17:20:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbU-0004Ey-HD; Thu, 29 Oct 2020 17:20:48 +0000 Received: by outflank-mailman (input) for mailman id 14432; Thu, 29 Oct 2020 17:20:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbS-0003MD-Nd for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:46 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 61498030-9189-4465-82cd-c67210d36d26; Thu, 29 Oct 2020 17:20:20 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKD3fK (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:13 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbS-0003MD-Nd for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:46 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.80]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 61498030-9189-4465-82cd-c67210d36d26; Thu, 29 Oct 2020 17:20:20 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKD3fK (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:13 +0100 (CET) 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: 61498030-9189-4465-82cd-c67210d36d26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992020; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=N7Hr2VOfOon4RnvyU1vv7pvNigOvHS1qA+Cy9MD8+GQ=; b=DWa+kVf573alXYUQYv+wjcgQrPIuU7myRbzKwpdCoRWE9DRENK25z/1AaGfD0aCF85 o8pdJfaRypVXbUERwx4iocR2ikDfsAsc38cr+nddBbATVIQ5sfsq6PGecpaPSzu6Gqng iBSyZjZnoBcmAsxcvym+7scgvaJ2u1eENHTPnuGRF3czC0GJrIfEz6eCrVTlu1jzD/Q6 42LbjhLNBvIhxLniORBCyo4s5VOoN+CX4CaGHOYPPGS4UL5eoNbTt8ionwtiw10WeE5o AqiNkgWfc8Ua5PAZd1L9PH+wCOiJ8Ej9YxI7/gDUvFNLBCPJjyBmXMO9k8t50Cj+5nuK 2jiQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 14/23] tools/guest: save: move local_pages array Date: Thu, 29 Oct 2020 18:19:54 +0100 Message-Id: <20201029172004.17219-15-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move local_pages array into preallocated sp= ace. Adjust the code to use the src page as is in case of HVM. In case of PV the page may need to be normalised, use an private memory area for this purpose. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 22 ++++++++++--------- tools/libs/guest/xg_sr_save.c | 25 +++------------------ tools/libs/guest/xg_sr_save_x86_hvm.c | 5 +++-- tools/libs/guest/xg_sr_save_x86_pv.c | 31 ++++++++++++++++++--------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 33e66678c6..2a020fef5c 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -33,16 +33,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. @@ -50,7 +46,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 @@ -371,6 +367,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/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 658f834ae8..804e4ccb3a 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_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/guest/xg_sr_save_x86_hvm.c b/tools/libs/guest/xg_sr= _save_x86_hvm.c index 1634a7bc43..11232b9f1d 100644 --- a/tools/libs/guest/xg_sr_save_x86_hvm.c +++ b/tools/libs/guest/xg_sr_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/guest/xg_sr_save_x86_pv.c b/tools/libs/guest/xg_sr_= save_x86_pv.c index 4964f1f7b8..8165306354 100644 --- a/tools/libs/guest/xg_sr_save_x86_pv.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992068; cv=none; d=zohomail.com; s=zohoarc; b=Kdn4r6xp9ldQru9O7hVKImxd0AMX4oFzReZg+0dEJacPjjqHkjaoidiCsOauKnHdfp9pR1gdxcjnFM9+Pqk1HEy2pUnaR88aEWRuTgxvZbBy9WJt+3/FUrTOrVF3QSb8S3RqbFEgBMmO6rTCfAdd/D1lMrkBMH8RNhzE8MgAjUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992068; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8HnEje+bi5L28ovh7GxYhMDV/iYGgk+hVnPKuTzQjbY=; b=j6n7Cvi4mW8bvI4JviozerrBsaDqjFW82P4Q2wmNbBoPTRVq0Ht7DFXLLq9s4sigXkgKCKSlOZtLNG65uDd0BNLGkkv8w7ALV8h7S/nzY1arbRPzYqO6dz3pDBMhBX8D/BXCsKGlOj8qjzUdvtMtBB+pdUNHhvFKVLMRU1xjg8k= ARC-Authentication-Results: i=1; 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 1603992068035473.0695871613468; Thu, 29 Oct 2020 10:21:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14438.35763 (Exim 4.92) (envelope-from ) id 1kYBbY-0004P0-Tc; Thu, 29 Oct 2020 17:20:52 +0000 Received: by outflank-mailman (output) from mailman id 14438.35763; Thu, 29 Oct 2020 17:20: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 1kYBbY-0004Ol-NM; Thu, 29 Oct 2020 17:20:52 +0000 Received: by outflank-mailman (input) for mailman id 14438; Thu, 29 Oct 2020 17:20:51 +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 1kYBbX-0003MC-M4 for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:51 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.170]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c87f4a73-4a17-4d15-a0fc-66c914d8e5f4; Thu, 29 Oct 2020 17:20:21 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKE3fM (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:14 +0100 (CET) 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 1kYBbX-0003MC-M4 for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:51 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.170]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c87f4a73-4a17-4d15-a0fc-66c914d8e5f4; Thu, 29 Oct 2020 17:20:21 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKE3fM (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:14 +0100 (CET) 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: c87f4a73-4a17-4d15-a0fc-66c914d8e5f4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992020; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=8HnEje+bi5L28ovh7GxYhMDV/iYGgk+hVnPKuTzQjbY=; b=Tz1p1IUBUd9B3S95popNAy44u2KWyhewJA6OQIaykQVWTfzCZMJK8k9C/YiGeJgmR8 OPtpyy/H7A4kri4DKD/vQScMHpg75ec9ogZuVmsPz95l1LNBhkgBiA32wun1zylBdKrN 1P504CQ3SdNpTjjqh4g8hE9i/FFhAKDTBJRMrII+g3FaNmOLR0rZJ9FF/b2PyC1yTRV9 eoY4RLgSubMDPHbh5iiAWlruR4yuyz4Giz/0p/U4bpxnKdPQtaEDi78kJ3+FFePEhyxi RLd3Z1Fdp/P/ElRsqB3vHP2nqyFmbMa1BHF6hpCMl0EbywMUhgIS41+L8X9Taemqu8KW mVNQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 15/23] tools/guest: restore: move pfns array Date: Thu, 29 Oct 2020 18:19:55 +0100 Message-Id: <20201029172004.17219-16-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove allocation from hotpath, move pfns array into preallocated space. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_restore.c | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 2a020fef5c..516d9b9fb5 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -224,6 +224,8 @@ struct xc_sr_save_arrays { }; =20 struct xc_sr_restore_arrays { + /* handle_page_data */ + xen_pfn_t pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 4a9ece9681..7d1447e86c 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -315,7 +315,7 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) unsigned int i, pages_of_data =3D 0; int rc =3D -1; =20 - xen_pfn_t *pfns =3D NULL, pfn; + xen_pfn_t *pfns =3D ctx->restore.m->pfns, pfn; uint32_t *types =3D NULL, type; =20 /* @@ -363,9 +363,8 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) goto err; } =20 - pfns =3D malloc(pages->count * sizeof(*pfns)); types =3D malloc(pages->count * sizeof(*types)); - if ( !pfns || !types ) + if ( !types ) { ERROR("Unable to allocate enough memory for %u pfns", pages->count); @@ -412,7 +411,6 @@ static int handle_page_data(struct xc_sr_context *ctx, = struct xc_sr_record *rec) &pages->pfn[pages->count]); err: free(types); - free(pfns); =20 return rc; } From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992068; cv=none; d=zohomail.com; s=zohoarc; b=ZqbtuVC4WNX13qyC3KJelAHmWOBGUIM8z/3K0mqr8xJrjYzbiUCqnhdjifQT39F2Gxj9x+qUxyNlCoRKSAyx+zKoF3axv1TJdIQod6C6zHeStlyXIhuWaXUbS+bxR9LsuJEAk2ZNwX+0uy0V+0Q3iFciZc9gk/xkpiuylRR8vXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992068; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+/YrJrdWLFQBmx4Fjz9uQTzJVj46LYQgpP9ngHfsNNY=; b=Zx65qXCd8fmOjRC9v13B2UkRjlPlaSIzpI8cQhTcl/M514RqRITMvUhfIsoCWtcXVKKQ9K5OEZIKLxN33rcqBlL8gAzaq3nH8az10rZy4z1KFz1+QwHIUIFlrUvJ1jbGdaEWbQ7fOzyRkNQ1mw+1fMIAq/bNGVsl9A3uVvU6Vwc= ARC-Authentication-Results: i=1; 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 1603992068720253.76238078030985; Thu, 29 Oct 2020 10:21:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14439.35769 (Exim 4.92) (envelope-from ) id 1kYBbZ-0004Qg-Kb; Thu, 29 Oct 2020 17:20:53 +0000 Received: by outflank-mailman (output) from mailman id 14439.35769; Thu, 29 Oct 2020 17:20:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbZ-0004Q5-8n; Thu, 29 Oct 2020 17:20:53 +0000 Received: by outflank-mailman (input) for mailman id 14439; Thu, 29 Oct 2020 17:20:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbX-0003MD-Nw for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:51 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8acf577a-2151-4411-8110-51fcf5b5d3c3; Thu, 29 Oct 2020 17:20:21 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKE3fO (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:14 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbX-0003MD-Nw for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:51 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.83]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8acf577a-2151-4411-8110-51fcf5b5d3c3; Thu, 29 Oct 2020 17:20:21 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKE3fO (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:14 +0100 (CET) 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: 8acf577a-2151-4411-8110-51fcf5b5d3c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992020; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=+/YrJrdWLFQBmx4Fjz9uQTzJVj46LYQgpP9ngHfsNNY=; b=KgAiCTG6MTTv88AsoblIMcLuAeIHAYJP7vdff65WN3i7lIBdymfh1dFxmBOfxnULbH 9XrbAvJwsQqAwevBUO1V1rtPijyqQZDN1pvm9RCfmDunnbV7ZPjknZuyopbMi823g37e k0u0nDAAmE6c03KnaivQqqL4nvuD53P67c2LhoeoWqIko6wSE96tShAK2NrIWlMnEmY3 5n+PNyTU60TPWdfAwkytJxmBevM+1vXpcJj48p08Rg0jKpaZGT6juwBBfnQivxhGMdUV 2Pd7oGzcugqF7srBMib1aR2QPn/21M+FdvDSd/7Zba5/gXuYv+k+Aru3WjYLO/2NmtwC My3w== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 16/23] tools/guest: restore: move types array Date: Thu, 29 Oct 2020 18:19:56 +0100 Message-Id: <20201029172004.17219-17-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 12 +----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 516d9b9fb5..0ceecb289d 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -226,6 +226,7 @@ struct xc_sr_save_arrays { struct xc_sr_restore_arrays { /* handle_page_data */ xen_pfn_t pfns[MAX_BATCH_SIZE]; + uint32_t types[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 7d1447e86c..7729071e41 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992073; cv=none; d=zohomail.com; s=zohoarc; b=VVOWOUPPrvfOUAqaF7YwvJXApbGORUjMD7ThWZaZL3J9z3BSkaZoxKDlaU0+JLZWSQYFsFjB8LM9X+Fu7mzCD82p8dDVLCzrsjPvWVA4a56P0cWoUaeKzpnLFEmhV9lI4ummGM6/BObOrl6G0xCmA0sM2DWyJIhINbRkmk9UZfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992073; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7yf5VgvfryEVAPtE1hdfDVCjjHFoZWgCpzJbwfomFp0=; b=VSUcCEvyHtZmOvXndNGGfiGcuJB0BrVbvXB4e5fIT1xEYx7SacHnx8l2pgY0HS4R+Zgi2WSz7yekyq5nRSm7diPWs+7HKfiB6h30wJXkcfhOFh32rNedf5Naxw+Tb/Bq37RlbhvRLr6irVA2ZfBEgpV+U2uYcb1Nc8M+U1Lb1ZI= ARC-Authentication-Results: i=1; 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 1603992073129876.2071304348818; Thu, 29 Oct 2020 10:21:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14441.35787 (Exim 4.92) (envelope-from ) id 1kYBbe-0004ba-21; Thu, 29 Oct 2020 17:20:58 +0000 Received: by outflank-mailman (output) from mailman id 14441.35787; Thu, 29 Oct 2020 17:20: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 1kYBbd-0004bN-Rn; Thu, 29 Oct 2020 17:20:57 +0000 Received: by outflank-mailman (input) for mailman id 14441; Thu, 29 Oct 2020 17:20:56 +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 1kYBbc-0003MC-MN for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:56 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3c76ea11-9640-4cc7-aaec-5b32a0503c23; Thu, 29 Oct 2020 17:20:21 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKF3fP (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:15 +0100 (CET) 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 1kYBbc-0003MC-MN for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:56 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [81.169.146.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3c76ea11-9640-4cc7-aaec-5b32a0503c23; Thu, 29 Oct 2020 17:20:21 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKF3fP (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:15 +0100 (CET) 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: 3c76ea11-9640-4cc7-aaec-5b32a0503c23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992020; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=7yf5VgvfryEVAPtE1hdfDVCjjHFoZWgCpzJbwfomFp0=; b=F1zOdzX4p3t36MPCxlIyOJl3UjwfgkUMdjSGnCnrZM1vBjOziZWe4u7r0N1usI9uxI /wAvj56seYsFj6DLNdrq/GRUelq8pKby205Sa/hAl+tLzu5GRZDztj9HqBdh3n1roAja +B0EjX80SKUXiyshn72T84QMG1H8gBxT46K8WQaN534jyMgmID8f/ZMhI10Ur2n83aF9 /xJP6sK3L0YLKjepBC/Nh7fCgdXOwB6PFwNM6ZBKnD3R8fliR+hjj8V3R2KyMATJlaDV Kwwp78xhCIdUKendWi+7nepwG/cW1uya5Lxqbc5BY+w2YiFHPR0suWeeJnonu/5htLRR Dx4A== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 17/23] tools/guest: restore: move mfns array Date: Thu, 29 Oct 2020 18:19:57 +0100 Message-Id: <20201029172004.17219-18-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_restore.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 0ceecb289d..5731a5c186 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -227,6 +227,8 @@ struct xc_sr_restore_arrays { /* handle_page_data */ xen_pfn_t pfns[MAX_BATCH_SIZE]; uint32_t types[MAX_BATCH_SIZE]; + /* process_page_data */ + xen_pfn_t mfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 7729071e41..3ba089f862 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992079; cv=none; d=zohomail.com; s=zohoarc; b=LGefCnN+hPKL5Zm12VtEr6yiiy8ZIcq2WGWTJS3fcSLvOSSg7ztKG5a8F1yhG8sQ0A2vcUOoDnwO3N51n+K2DklSWSX4fyZ3ymmiC+9mF/J54bQDD28tnbzISSOlMzwarFz5xW/LSfBi5tmUseAgEHegnHuxAcWDoB/zJDLI5DA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992079; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hpVNJcvCo1Nci9xkIIy9iyHUvD/MXxHiNddZBiksKp8=; b=HFY+RmhbItqh6SPc67Vch4w8I0jeRDY5GY7xXoK4Fp2y1Y+3FA2BmQZudsVAnbFZ70Sh6HNpRbcmYFRYZiGEiRN2DOZcZ/hrXJNr+FnhdMO3B12p+x59A/fDiJv7XgGMr9HAUftJJkE81iCLlwtBnTxuClOLhdSH8V/SzS6jZvI= ARC-Authentication-Results: i=1; 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 1603992079495387.62649801222744; Thu, 29 Oct 2020 10:21:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14448.35811 (Exim 4.92) (envelope-from ) id 1kYBbj-0004pU-Q6; Thu, 29 Oct 2020 17:21:03 +0000 Received: by outflank-mailman (output) from mailman id 14448.35811; Thu, 29 Oct 2020 17:21:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbj-0004p4-DL; Thu, 29 Oct 2020 17:21:03 +0000 Received: by outflank-mailman (input) for mailman id 14448; Thu, 29 Oct 2020 17:21:01 +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 1kYBbh-0003MC-MZ for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:01 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id eafb4928-96a0-4e13-9bea-3740bdbff561; Thu, 29 Oct 2020 17:20:22 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKF3fQ (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:15 +0100 (CET) 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 1kYBbh-0003MC-MZ for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:01 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.82]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id eafb4928-96a0-4e13-9bea-3740bdbff561; Thu, 29 Oct 2020 17:20:22 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKF3fQ (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:15 +0100 (CET) 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: eafb4928-96a0-4e13-9bea-3740bdbff561 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992021; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=hpVNJcvCo1Nci9xkIIy9iyHUvD/MXxHiNddZBiksKp8=; b=swT6PklD29WD3en/xNHuc35eLb9dBXhbmumKEAYTOnpUMWQteAbTO/RScOoCLtkAsB n/WC1r2RqAabpPe8NXhmWa5jB1B6ovWajEA6u8nVdwLPDb6mvmcLBokWpB2UUcoOFLr6 HtPOrTJbQcwyT3qA9BUyEpdOOmPG4Ep/QsRweYRfHSjmW2PuuD7nm68/rsdoi6GhCmDh pi2QPzqo4gfICjQpI2XDjMlMrChayjBV4GlvaOQu+h85iDz/CJVJYBQwSOSCFWGz3jeN l1IWCjpSqZMKtVd2bUqYYCVE0TYBoW9/m6aruohbX4r2NvtfozlCqLiSkg3J4nEx+Hzh ILEg== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 18/23] tools/guest: restore: move map_errs array Date: Thu, 29 Oct 2020 18:19:58 +0100 Message-Id: <20201029172004.17219-19-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 12 +----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 5731a5c186..eba3a49877 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -229,6 +229,7 @@ struct xc_sr_restore_arrays { uint32_t types[MAX_BATCH_SIZE]; /* process_page_data */ xen_pfn_t mfns[MAX_BATCH_SIZE]; + int map_errs[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 3ba089f862..94c329032f 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992258; cv=none; d=zohomail.com; s=zohoarc; b=SxuxPeL5Ss2RpCNZSBecJdbQUxfKjBK8/Mby54APvsoNJAHERyGnETVufeo7rTkJaEMYu3KSN9t6NW/WS+v1/CHlcVrg5ohrBKiH7wWJej5aRfSo+G5gkk2jYsx5tIUixmRezCFkcphAwbV4W5u163dfLzgQA6VGD+9rfriqndY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992258; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fJgEN/Sdwhd/b4yPCS/UDhsI4V1GTM00uHRSqwAWm0w=; b=ePX0DbJP+6jJ50ozICXygdc8bW/TUYvBenNM7aEcmksKG4v8LuZ7u8CEgEHLQ6zyVeSZrOG7xqrgcJP+aRuWOynYbp006vRzbA4JDN5Ng+y/RDibII322rGU4ehebCSTwF+GZOu8hWsS3Mvjp7YVx5C8COKlfGhSa9FqlVMWWWI= ARC-Authentication-Results: i=1; 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 1603992258415859.4641236196987; Thu, 29 Oct 2020 10:24:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14495.35839 (Exim 4.92) (envelope-from ) id 1kYBeX-0005pA-IQ; Thu, 29 Oct 2020 17:23:57 +0000 Received: by outflank-mailman (output) from mailman id 14495.35839; Thu, 29 Oct 2020 17:23: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 1kYBeX-0005p1-FN; Thu, 29 Oct 2020 17:23:57 +0000 Received: by outflank-mailman (input) for mailman id 14495; Thu, 29 Oct 2020 17:23:56 +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 1kYBbm-0003MC-Mt for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:06 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.84]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6679421a-6802-44fa-a291-31bfe98f6a5f; Thu, 29 Oct 2020 17:20:22 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKG3fR (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:16 +0100 (CET) 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 1kYBbm-0003MC-Mt for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:06 +0000 Received: from mo4-p02-ob.smtp.rzone.de (unknown [85.215.255.84]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6679421a-6802-44fa-a291-31bfe98f6a5f; Thu, 29 Oct 2020 17:20:22 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKG3fR (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:16 +0100 (CET) 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: 6679421a-6802-44fa-a291-31bfe98f6a5f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992021; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=fJgEN/Sdwhd/b4yPCS/UDhsI4V1GTM00uHRSqwAWm0w=; b=IjVk1PEgemRk3g/+LcWdQ9aonZPORdQ2b+s2uZPEM6Hx2TOAe2MuO7Ep+0wSbYj4Km pXjg8y/C7hpw78RY1DYFwKOPZDEdpt6IflhlkLyq/qxx9GcF8YKDoRpWzbaFIlgLV8qM 4+oS9o6+fa7jxZ6IISDEYeBxeFt2tRHHg1/QTXgdpb6yeD5F4cgebDuzponeBSefrjDN rlgNz31WfZ4+fhIWxuT6vkGNkGXAzBA49rYadTHwTG49fmp9QRPnuAhaI2MlmoBSqnL4 ODCYnoMyOLmInMCnUIzzuijTGPS9ph5l8H33XIJ7n6CG3yNnCMIYO0TCe1dxLJIK9FvP B0Yg== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 19/23] tools/guest: restore: move mfns array in populate_pfns Date: Thu, 29 Oct 2020 18:19:59 +0100 Message-Id: <20201029172004.17219-20-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_restore.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index eba3a49877..96a77b5969 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -230,6 +230,8 @@ struct xc_sr_restore_arrays { /* process_page_data */ xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; + /* populate_pfns */ + xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 94c329032f..85a32aaed2 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992074; cv=none; d=zohomail.com; s=zohoarc; b=Hdky4FBo10LJosJ87R2Ne0KAIMH7j1DbN+51PhAZ1HSpyLIpS+2mnxC/+eU4rKkcj/PReQ3+T/hQFXLa8XSxdQ/mG3hdqXEloucPdWpPvN4oyQmboU4w0zptsECjT4/z6/b4dRLZCl2ms34Q8gOnOa3Ls3KnuVYxHzWLrD/8hb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992074; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7l8yhNQOQPrO7fe+7mN7zL3gcTrejyHmlkzb9nVzYkU=; b=EXJez37YGfsqA0nJRJc8Gant8VCqKF0yvTKjlES16G1te1N6o+aRy1YTyuSk8rVXRuGMerYOCcYLTc2sQ7+jIJ+JxmTeQrFt7S3P0WWYHXYfQVc2AeLabGwMqCgt3rkRNfE9PUMjfeFMoXcyW2hX8DlJv1iDf9fNMDXzMqTfppU= ARC-Authentication-Results: i=1; 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 1603992074710858.5001910439074; Thu, 29 Oct 2020 10:21:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14442.35795 (Exim 4.92) (envelope-from ) id 1kYBbf-0004dW-1L; Thu, 29 Oct 2020 17:20:59 +0000 Received: by outflank-mailman (output) from mailman id 14442.35795; Thu, 29 Oct 2020 17:20:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbe-0004ck-HN; Thu, 29 Oct 2020 17:20:58 +0000 Received: by outflank-mailman (input) for mailman id 14442; Thu, 29 Oct 2020 17:20:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbc-0003MD-OD for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:56 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.102]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d042921d-b001-4a70-b3e6-3b7021119e28; Thu, 29 Oct 2020 17:20:23 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKG3fS (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:16 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbc-0003MD-OD for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:20:56 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.102]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d042921d-b001-4a70-b3e6-3b7021119e28; Thu, 29 Oct 2020 17:20:23 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKG3fS (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:16 +0100 (CET) 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: d042921d-b001-4a70-b3e6-3b7021119e28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992022; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=7l8yhNQOQPrO7fe+7mN7zL3gcTrejyHmlkzb9nVzYkU=; b=eeVgrae+rDElAgTheRJNRHdLvU+1Y9cxgOjEh/7sQmhVyGnKV+SkzqBExLqCJTUEN5 m5Qt2FcBn+Z3f8HlDc3U0VdmAWyOPfn3oxnoZYxLY/aOVcEVyok6+ZbG9gdxACo3jHmC yqlxSbSrfSk5UGdRmXwQFnSJ0duUbycF0rDvtpJu5dds46iVZ4CoynWveUN76NNo7M3x YN1O4p1fypXQO5w22lrjhaRLP0qnUe8IyhVhKivzuBpiK6XnpetuHAmRcRp9i7jNGn9p 1dX3SR6rc5Y53frY+5PKJQP/ism4dsT5C8ZYZmGVC/YwhewDYRJu1781hs/ZQn08+J6F 1YMQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 20/23] tools/guest: restore: move pfns array in populate_pfns Date: Thu, 29 Oct 2020 18:20:00 +0100 Message-Id: <20201029172004.17219-21-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 96a77b5969..3fe665b91d 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -232,6 +232,7 @@ struct xc_sr_restore_arrays { int map_errs[MAX_BATCH_SIZE]; /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; + xen_pfn_t pp_pfns[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 85a32aaed2..71b39612ee 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_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 May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992316; cv=none; d=zohomail.com; s=zohoarc; b=Lyt4IWrfPnHRN9cSH4CxnPQVNoDAq/SYlxpyLxxgL8x9txctf8NwcycWUp7HGW3NV3CcJsHoaRlXvC6veDpCiBWsJBd2VWbzZBN0VxrphRdV1TdPyRnI7D1PwboD9nkCyZR8D9/JuuclFR2CK9t97Gs21nOVrVAuZLTE4f9SQnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992316; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vDSMlFXnzPOXkYBGrnj7LwkLFSBsc9LnEOe7WzFsods=; b=atqfbJBHgUtpM/Q1dp8zI0cHxyEMptZi6oozzy8Bj1u5ynf6Wew08T3A2HyM99MdXwgFjVPPdX2kwoAKTyQC34yFI+lWT+dKVW/fWvGbTdy9Dc+bG8yaiCJUaDLDS2Vtgxmm3z1vGQEav+13M9z9u+uHdwDActutfuabFFzXE+U= ARC-Authentication-Results: i=1; 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 1603992316749563.0888776161488; Thu, 29 Oct 2020 10:25:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14512.35875 (Exim 4.92) (envelope-from ) id 1kYBfJ-00068T-Dd; Thu, 29 Oct 2020 17:24:45 +0000 Received: by outflank-mailman (output) from mailman id 14512.35875; Thu, 29 Oct 2020 17:24: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 1kYBfJ-00068L-AL; Thu, 29 Oct 2020 17:24:45 +0000 Received: by outflank-mailman (input) for mailman id 14512; Thu, 29 Oct 2020 17:24:44 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbr-0003MC-N9 for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:11 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b0bcea0f-e8b5-44b9-9aff-c228c6f43efc; Thu, 29 Oct 2020 17:20:24 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKG3fT (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:16 +0100 (CET) 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 1kYBbr-0003MC-N9 for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:11 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [81.169.146.174]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b0bcea0f-e8b5-44b9-9aff-c228c6f43efc; Thu, 29 Oct 2020 17:20:24 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKG3fT (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:16 +0100 (CET) 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: b0bcea0f-e8b5-44b9-9aff-c228c6f43efc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992023; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=vDSMlFXnzPOXkYBGrnj7LwkLFSBsc9LnEOe7WzFsods=; b=pYItbwo0qq88TgAn5HU4aLCh4QxzQogCseTejXzbnL0cbd20RgqH38jj2mJtia1c3v y+yCnu9G1+2TtlSGdgB49SL4/J6gxS1DRNN0byKMgN4bnbzK3+E0IsXVlmvxmoMRMjOQ uxNmi4/LYnJ1hSVdRZg1QtxE59bjusMXx5eye3qcRfuC3cUkRFCF+d3rer9FExlodscC cOx5bWAnf4x4q1jvkSlvEzRNVNfiHIKxigAwCyILxoycLHS3+2RW98Fokt8oTZxqjfga H8GFbybybV4huVmGx05OnrDJdu83Tm9YKgfNI//z4y0nMaaDrxTbmMrRmo74m8dJ4uux ufVw== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 21/23] tools/guest: restore: split record processing Date: Thu, 29 Oct 2020 18:20:01 +0100 Message-Id: <20201029172004.17219-22-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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 --- tools/libs/guest/xg_sr_common.c | 33 ++++++++++++--------- tools/libs/guest/xg_sr_common.h | 4 ++- tools/libs/guest/xg_sr_restore.c | 49 ++++++++++++++++++++++---------- tools/libs/guest/xg_sr_save.c | 7 ++++- 4 files changed, 63 insertions(+), 30 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 17567ab133..cabde4ef74 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_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/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 3fe665b91d..66d1b0dfe6 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -475,7 +475,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/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 71b39612ee..93f69b9ba8 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_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/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 804e4ccb3a..9be5e8c52b 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -590,6 +590,7 @@ static int send_memory_live(struct xc_sr_context *ctx) static int colo_merge_secondary_dirty_bitmap(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; + struct xc_sr_rhdr rhdr; struct xc_sr_record rec; uint64_t *pfns =3D NULL; uint64_t pfn; @@ -598,7 +599,11 @@ static int colo_merge_secondary_dirty_bitmap(struct xc= _sr_context *ctx) DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); =20 - rc =3D read_record(ctx, ctx->save.recv_fd, &rec); + rc =3D read_record_header(ctx, ctx->save.recv_fd, &rhdr); + if ( rc ) + goto err; + + rc =3D read_record_data(ctx, ctx->save.recv_fd, &rhdr, &rec); if ( rc ) goto err; =20 From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992080; cv=none; d=zohomail.com; s=zohoarc; b=JBGWmsf/xpCyvhqoqyucYjASYvXk9i21IV7v+GGR9/Ept5zcgH+6ROVVxV9tmLaTY/KHIWj8tHO/g+jYNmqo1Vw1FKdCs4IyO14oy/rK+2CRFOt1qYvIvGIEjACw12nYYH5aFlFkHWqmWTp07ytA4WE7zZDromgZ91+tefg3UeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992080; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JnSHsGBdE+hUonxO+Hv9VJUmNC+IMHKghPQX1ClFpdo=; b=mGBZu2uLRfPuhRfje2fEUKOVJpD53aEwcnHRerIeuQTY00G/rm5hakG9Ah2dMHjl5O+s9PxXUkb1HIPhhgTHWO3qZpUaT+Pm+Vn7C3W2GhBJclBXT46sXbEQ0J+qcJOMtdIes44jcmpt9UsZKfpggIRce3ivx/d+8Fxp2B+QQd4= ARC-Authentication-Results: i=1; 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 160399208061217.98602240792502; Thu, 29 Oct 2020 10:21:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14449.35817 (Exim 4.92) (envelope-from ) id 1kYBbk-0004rD-HC; Thu, 29 Oct 2020 17:21:04 +0000 Received: by outflank-mailman (output) from mailman id 14449.35817; Thu, 29 Oct 2020 17:21: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 1kYBbk-0004qX-0Z; Thu, 29 Oct 2020 17:21:04 +0000 Received: by outflank-mailman (input) for mailman id 14449; Thu, 29 Oct 2020 17:21:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbh-0003MD-ON for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:01 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.101]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5d291c9d-b52d-4ba4-b80c-2a309346f51a; Thu, 29 Oct 2020 17:20:26 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKH3fU (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:17 +0100 (CET) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbh-0003MD-ON for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:01 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.101]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5d291c9d-b52d-4ba4-b80c-2a309346f51a; Thu, 29 Oct 2020 17:20:26 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKH3fU (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:17 +0100 (CET) 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: 5d291c9d-b52d-4ba4-b80c-2a309346f51a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992025; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=JnSHsGBdE+hUonxO+Hv9VJUmNC+IMHKghPQX1ClFpdo=; b=YRBZ3/NAr7/qOHfTdKRX3rJwf7ZPgs1J+6+i+D+nPgqqX0hAook0mMrH2X8FcI8zoY I2DGeYvBxRHpNe9y2mJkqv8iYTyiPBrZq4SLo3pCctY/G8cTx/clzJX4xJp1g7L5v9tS xgkpZFJeyjIC7KYWtD4Lidl2AJXL7OjkA3HFtv8KzczmNYoONhwZ4exhEJoryapFwGze xTGnDewSHK/lIf+Wor46FA02VtulB2TE8O+SKa5a3F61b5V8fOMV6SigZpXK2NuMzmIX R0OR6Ke2Zrvs9slDpj9NbWo6UDmT/EtBoq8vl+8P/mQumkA8Lwb8QEfYUj5CX8cUAicK PCkA== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 22/23] tools/guest: restore: split handle_page_data Date: Thu, 29 Oct 2020 18:20:02 +0100 Message-Id: <20201029172004.17219-23-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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/guest/xg_sr_common.h | 9 + tools/libs/guest/xg_sr_restore.c | 343 ++++++++++++++++++++----------- 2 files changed, 231 insertions(+), 121 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 66d1b0dfe6..7ec8867b88 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -230,9 +230,14 @@ struct xc_sr_restore_arrays { /* process_page_data */ xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; + void *guest_data[MAX_BATCH_SIZE]; + /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; xen_pfn_t pp_pfns[MAX_BATCH_SIZE]; + + /* Must be the last member */ + struct xc_sr_rec_page_data_header pages; }; =20 struct xc_sr_context @@ -323,7 +328,11 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + void *verify_buf; + struct xc_sr_restore_arrays *m; + void *guest_mapping; + uint32_t nr_mapped_pages; } restore; }; =20 diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 93f69b9ba8..060f3d1f4e 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -186,123 +186,18 @@ int populate_pfns(struct xc_sr_context *ctx, unsigne= d int count, return rc; } =20 -/* - * Given a list of pfns, their types, and a block of page data from the - * stream, populate and record their types, map the relevant subset and co= py - * the data into the guest. - */ -static int process_page_data(struct xc_sr_context *ctx, unsigned int count, - xen_pfn_t *pfns, uint32_t *types, void *page_= data) +static int handle_static_data_end_v2(struct xc_sr_context *ctx) { - xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D ctx->restore.m->mfns; - int *map_errs =3D ctx->restore.m->map_errs; - int rc; - void *mapping =3D NULL, *guest_page =3D NULL; - unsigned int i, /* i indexes the pfns from the record. */ - j, /* j indexes the subset of pfns we decide to map. */ - nr_pages =3D 0; - - rc =3D populate_pfns(ctx, count, pfns, types); - if ( rc ) - { - ERROR("Failed to populate pfns for batch of %u pages", count); - goto err; - } - - for ( i =3D 0; i < count; ++i ) - { - ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); - - if ( page_type_has_stream_data(types[i]) =3D=3D true ) - mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); - } - - /* Nothing to do? */ - if ( nr_pages =3D=3D 0 ) - goto done; - - mapping =3D guest_page =3D xenforeignmemory_map( - xch->fmem, ctx->domid, PROT_READ | PROT_WRITE, - nr_pages, mfns, map_errs); - if ( !mapping ) - { - rc =3D -1; - PERROR("Unable to map %u mfns for %u pages of data", - nr_pages, count); - goto err; - } - - for ( i =3D 0, j =3D 0; i < count; ++i ) - { - if ( page_type_has_stream_data(types[i]) =3D=3D false ) - continue; - - if ( map_errs[j] ) - { - rc =3D -1; - ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[j], types[i], map_errs[j]); - goto err; - } - - /* Undo page normalisation done by the saver. */ - rc =3D ctx->restore.ops.localise_page(ctx, types[i], page_data); - if ( rc ) - { - ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", - pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); - goto err; - } - - if ( ctx->restore.verify ) - { - /* Verify mode - compare incoming data to what we already have= . */ - if ( memcmp(guest_page, page_data, PAGE_SIZE) ) - ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", - pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); - } - else - { - /* Regular mode - copy incoming data into place. */ - memcpy(guest_page, page_data, PAGE_SIZE); - } - - ++j; - guest_page +=3D PAGE_SIZE; - page_data +=3D PAGE_SIZE; - } - - done: - rc =3D 0; - - err: - if ( mapping ) - xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); - - return rc; -} + int rc =3D 0; =20 -/* - * Validate a PAGE_DATA record from the stream, and pass the results to - * process_page_data() to actually perform the legwork. - */ -static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record= *rec) -{ +#if defined(__i386__) || defined(__x86_64__) xc_interface *xch =3D ctx->xch; - struct xc_sr_rec_page_data_header *pages =3D rec->data; - unsigned int i, pages_of_data =3D 0; - int rc =3D -1; - - xen_pfn_t *pfns =3D ctx->restore.m->pfns, pfn; - uint32_t *types =3D ctx->restore.m->types, type; - /* * v2 compatibility only exists for x86 streams. This is a bit of a * bodge, but it is less bad than duplicating handle_page_data() betwe= en * different architectures. */ -#if defined(__i386__) || defined(__x86_64__) + /* v2 compat. Infer the position of STATIC_DATA_END. */ if ( ctx->restore.format_version < 3 && !ctx->restore.seen_static_data= _end ) { @@ -320,12 +215,26 @@ static int handle_page_data(struct xc_sr_context *ctx= , struct xc_sr_record *rec) ERROR("No STATIC_DATA_END seen"); goto err; } + + rc =3D 0; +err: #endif =20 - if ( rec->length < sizeof(*pages) ) + return rc; +} + +static bool verify_rec_page_hdr(struct xc_sr_context *ctx, uint32_t rec_le= ngth, + struct xc_sr_rec_page_data_header *pages) +{ + xc_interface *xch =3D ctx->xch; + bool ret =3D false; + + errno =3D EINVAL; + + if ( rec_length < sizeof(*pages) ) { ERROR("PAGE_DATA record truncated: length %u, min %zu", - rec->length, sizeof(*pages)); + rec_length, sizeof(*pages)); goto err; } =20 @@ -335,13 +244,35 @@ static int handle_page_data(struct xc_sr_context *ctx= , struct xc_sr_record *rec) goto err; } =20 - if ( rec->length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) ) + if ( pages->count > MAX_BATCH_SIZE ) + { + ERROR("pfn count %u in PAGE_DATA record too large", pages->count); + errno =3D E2BIG; + goto err; + } + + if ( rec_length < sizeof(*pages) + (pages->count * sizeof(uint64_t)) ) { ERROR("PAGE_DATA record (length %u) too short to contain %u" - " pfns worth of information", rec->length, pages->count); + " pfns worth of information", rec_length, pages->count); goto err; } =20 + ret =3D true; + +err: + return ret; +} + +static bool verify_rec_page_pfns(struct xc_sr_context *ctx, uint32_t rec_l= ength, + struct xc_sr_rec_page_data_header *pages) +{ + xc_interface *xch =3D ctx->xch; + uint32_t i, pages_of_data =3D 0; + xen_pfn_t pfn; + uint32_t type; + bool ret =3D false; + for ( i =3D 0; i < pages->count; ++i ) { pfn =3D pages->pfn[i] & PAGE_DATA_PFN_MASK; @@ -364,23 +295,183 @@ static int handle_page_data(struct xc_sr_context *ct= x, struct xc_sr_record *rec) * have a page worth of data in the record. */ pages_of_data++; =20 - pfns[i] =3D pfn; - types[i] =3D type; + ctx->restore.m->pfns[i] =3D pfn; + ctx->restore.m->types[i] =3D type; } =20 - if ( rec->length !=3D (sizeof(*pages) + + if ( rec_length !=3D (sizeof(*pages) + (sizeof(uint64_t) * pages->count) + (PAGE_SIZE * pages_of_data)) ) { ERROR("PAGE_DATA record wrong size: length %u, expected " - "%zu + %zu + %lu", rec->length, sizeof(*pages), + "%zu + %zu + %lu", rec_length, sizeof(*pages), (sizeof(uint64_t) * pages->count), (PAGE_SIZE * pages_of_dat= a)); goto err; } =20 - rc =3D process_page_data(ctx, pages->count, pfns, types, - &pages->pfn[pages->count]); + ret =3D true; + +err: + return ret; +} + +/* + * Populate pfns, if required + * Fill m->guest_data with either mapped address or NULL + * The caller must unmap guest_mapping + */ +static int map_guest_pages(struct xc_sr_context *ctx, + struct xc_sr_rec_page_data_header *pages) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + uint32_t i, p; + int rc; + + rc =3D populate_pfns(ctx, pages->count, m->pfns, m->types); + if ( rc ) + { + ERROR("Failed to populate pfns for batch of %u pages", pages->coun= t); + goto err; + } + + ctx->restore.nr_mapped_pages =3D 0; + + for ( i =3D 0; i < pages->count; i++ ) + { + ctx->restore.ops.set_page_type(ctx, m->pfns[i], m->types[i]); + + if ( page_type_has_stream_data(m->types[i]) =3D=3D false ) + { + m->guest_data[i] =3D NULL; + continue; + } + + m->mfns[ctx->restore.nr_mapped_pages++] =3D ctx->restore.ops.pfn_t= o_gfn(ctx, m->pfns[i]); + } + + /* Nothing to do? */ + if ( ctx->restore.nr_mapped_pages =3D=3D 0 ) + goto done; + + ctx->restore.guest_mapping =3D xenforeignmemory_map(xch->fmem, ctx->do= mid, + PROT_READ | PROT_WRITE, ctx->restore.nr_mapped_pages, + m->mfns, m->map_errs); + if ( !ctx->restore.guest_mapping ) + { + rc =3D -1; + PERROR("Unable to map %u mfns for %u pages of data", + ctx->restore.nr_mapped_pages, pages->count); + goto err; + } + + /* Verify mapping, and assign address to pfn data */ + for ( i =3D 0, p =3D 0; i < pages->count; i++ ) + { + if ( page_type_has_stream_data(m->types[i]) =3D=3D false ) + continue; + + if ( m->map_errs[p] =3D=3D 0 ) + { + m->guest_data[i] =3D ctx->restore.guest_mapping + (p * PAGE_SI= ZE); + p++; + continue; + } + + errno =3D m->map_errs[p]; + rc =3D -1; + PERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32") f= ailed", + m->pfns[i], m->mfns[p], m->types[i]); + goto err; + } + +done: + rc =3D 0; + +err: + return rc; +} + +/* + * Handle PAGE_DATA record from an existing buffer + * Given a list of pfns, their types, and a block of page data from the + * stream, populate and record their types, map the relevant subset and co= py + * the data into the guest. + */ +static int handle_buffered_page_data(struct xc_sr_context *ctx, + struct xc_sr_record *rec) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_rec_page_data_header *pages =3D rec->data; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + void *p; + uint32_t i; + int rc =3D -1, idx; + + rc =3D handle_static_data_end_v2(ctx); + if ( rc ) + goto err; + + /* First read and verify the header */ + if ( verify_rec_page_hdr(ctx, rec->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Then read and verify the pfn numbers */ + if ( verify_rec_page_pfns(ctx, rec->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Map the target pfn */ + rc =3D map_guest_pages(ctx, pages); + if ( rc ) + goto err; + + for ( i =3D 0, idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + p =3D &pages->pfn[pages->count] + (idx * PAGE_SIZE); + rc =3D ctx->restore.ops.localise_page(ctx, m->types[i], p); + if ( rc ) + { + ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + goto err; + + } + + if ( ctx->restore.verify ) + { + if ( memcmp(m->guest_data[i], p, PAGE_SIZE) ) + { + errno =3D EIO; + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); + goto err; + } + } + else + { + memcpy(m->guest_data[i], p, PAGE_SIZE); + } + + idx++; + } + + rc =3D 0; + err: + if ( ctx->restore.guest_mapping ) + { + xenforeignmemory_unmap(xch->fmem, ctx->restore.guest_mapping, ctx-= >restore.nr_mapped_pages); + ctx->restore.guest_mapping =3D NULL; + } return rc; } =20 @@ -641,12 +732,21 @@ static int process_buffered_record(struct xc_sr_conte= xt *ctx, struct xc_sr_recor break; =20 case REC_TYPE_PAGE_DATA: - rc =3D handle_page_data(ctx, rec); + rc =3D handle_buffered_page_data(ctx, rec); break; =20 case REC_TYPE_VERIFY: DPRINTF("Verify mode enabled"); ctx->restore.verify =3D true; + if ( !ctx->restore.verify_buf ) + { + ctx->restore.verify_buf =3D malloc(MAX_BATCH_SIZE * PAGE_SIZE); + if ( !ctx->restore.verify_buf ) + { + rc =3D -1; + PERROR("Unable to allocate verify_buf"); + } + } break; =20 case REC_TYPE_CHECKPOINT: @@ -725,7 +825,8 @@ static int setup(struct xc_sr_context *ctx) } ctx->restore.allocated_rec_num =3D DEFAULT_BUF_RECORDS; =20 - ctx->restore.m =3D malloc(sizeof(*ctx->restore.m)); + ctx->restore.m =3D malloc(sizeof(*ctx->restore.m) + + (sizeof(*ctx->restore.m->pages.pfn) * MAX_BATCH_SIZE)); if ( !ctx->restore.m ) { ERROR("Unable to allocate memory for arrays"); rc =3D -1; From nobody Mon May 6 00:36:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992258; cv=none; d=zohomail.com; s=zohoarc; b=bjEqiomWcNAPmuZYNoGWKv0UEYPE3V5E81Xonrz9AoxyVc/jVo1DN0fhM4ZSNzT7XBDZqMAwfgY92aUZLvnSlL5Q/YupK1AJ4jxGWJ6NQ06UkImi67vGBLxAkZBMFZtUkaKg30S56fKk9uNut4S6Y1qmqCpJuYVfVG5nlELjOpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992258; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bBxHDLx7AeMPpHXep28OEFmN0H0Z0pHfYy9VAoYWQzc=; b=J6EykJz93/H3+uRGuPhoc4NSTS1AwmP1YnvAscgYHUNlmY9Y1POorjEl2PttxGmnDuj063Ukk32X/vLZKd9lfQz8tcOXjWhlntDc5X6EJ744XsX4563B6Sufcv10hOgBJ3h3f1/bLQ+hBriDZbP4+cgcWThSUYKPW98zfZ7X+TI= ARC-Authentication-Results: i=1; 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 1603992258670232.3526020343852; Thu, 29 Oct 2020 10:24:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14496.35851 (Exim 4.92) (envelope-from ) id 1kYBea-0005rI-Rh; Thu, 29 Oct 2020 17:24:00 +0000 Received: by outflank-mailman (output) from mailman id 14496.35851; Thu, 29 Oct 2020 17:24:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBea-0005r6-OB; Thu, 29 Oct 2020 17:24:00 +0000 Received: by outflank-mailman (input) for mailman id 14496; Thu, 29 Oct 2020 17:23:59 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbw-0003MC-ND for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:16 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8d6ec06d-e896-4655-b970-ab122dacae12; Thu, 29 Oct 2020 17:20:25 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKH3fV (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:17 +0100 (CET) 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 1kYBbw-0003MC-ND for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:16 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8d6ec06d-e896-4655-b970-ab122dacae12; Thu, 29 Oct 2020 17:20:25 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKH3fV (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:17 +0100 (CET) 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: 8d6ec06d-e896-4655-b970-ab122dacae12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992024; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=bBxHDLx7AeMPpHXep28OEFmN0H0Z0pHfYy9VAoYWQzc=; b=qDoMP6d0d7wEn447iURC/emTuLvga9PR96Ko4Iv7jidNwnAlMoBUAnRGmLKo4HZLGA GHOgirg4mmXFYlap6+tmFd5Ax0PCMpMPTMzUiK29J/IrzDDArLcwmsNHAELVYY7r1ZTE XeoSFGmaiu8nGMKG9l/us2OUAYNWKdnizZuFmnjh4vohK5OWUQ5Psk0IdJ/P++i2UZzL HIIx55HWepCb0R8+J2HVGu0gyxQYcOdu5Qf6HumxN1ZfjMbpg0FamnYRlSSnmskzTIvx gf+hZWMFtprVMiitlaZlIGLimIhY1iIum9npDeoa/wSMzhXEffG/CAI+MYNWt6VI+cRm syTQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 23/23] tools/guest: restore: write data directly into guest Date: Thu, 29 Oct 2020 18:20:03 +0100 Message-Id: <20201029172004.17219-24-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-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/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 132 ++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 7ec8867b88..f76af23bcc 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -231,6 +231,7 @@ struct xc_sr_restore_arrays { xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; void *guest_data[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE]; =20 /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 060f3d1f4e..2f575d7dd9 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -392,6 +392,122 @@ err: return rc; } =20 +/* + * Handle PAGE_DATA record from the stream. + * Given a list of pfns, their types, and a block of page data from the + * stream, populate and record their types, map the relevant subset and co= py + * the data into the guest. + */ +static int handle_incoming_page_data(struct xc_sr_context *ctx, + struct xc_sr_rhdr *rhdr) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + struct xc_sr_rec_page_data_header *pages =3D &m->pages; + uint64_t *pfn_nums =3D m->pages.pfn; + uint32_t i; + int rc, iov_idx; + + rc =3D handle_static_data_end_v2(ctx); + if ( rc ) + goto err; + + /* First read and verify the header */ + rc =3D read_exact(ctx->fd, pages, sizeof(*pages)); + if ( rc ) + { + PERROR("Could not read rec_pfn header"); + goto err; + } + + if ( verify_rec_page_hdr(ctx, rhdr->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Then read and verify the incoming pfn numbers */ + rc =3D read_exact(ctx->fd, pfn_nums, sizeof(*pfn_nums) * pages->count); + if ( rc ) + { + PERROR("Could not read rec_pfn data"); + goto err; + } + + if ( verify_rec_page_pfns(ctx, rhdr->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Finally read and verify the incoming pfn data */ + rc =3D map_guest_pages(ctx, pages); + if ( rc ) + goto err; + + /* Prepare read buffers, either guest or throw away memory */ + for ( i =3D 0, iov_idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + m->iov[iov_idx].iov_len =3D PAGE_SIZE; + if ( ctx->restore.verify ) + m->iov[iov_idx].iov_base =3D ctx->restore.verify_buf + i * PAG= E_SIZE; + else + m->iov[iov_idx].iov_base =3D m->guest_data[i]; + iov_idx++; + } + + if ( !iov_idx ) + goto done; + + rc =3D readv_exact(ctx->fd, m->iov, iov_idx); + if ( rc ) + { + PERROR("read of %d pages failed", iov_idx); + goto err; + } + + /* Post-processing of pfn data */ + for ( i =3D 0, iov_idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + rc =3D ctx->restore.ops.localise_page(ctx, m->types[i], m->iov[iov= _idx].iov_base); + if ( rc ) + { + ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + goto err; + + } + + if ( ctx->restore.verify ) + { + if ( memcmp(m->guest_data[i], m->iov[iov_idx].iov_base, PAGE_S= IZE) ) + { + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); + } + } + + iov_idx++; + } + +done: + rc =3D 0; + +err: + if ( ctx->restore.guest_mapping ) + { + xenforeignmemory_unmap(xch->fmem, ctx->restore.guest_mapping, ctx-= >restore.nr_mapped_pages); + ctx->restore.guest_mapping =3D NULL; + } + return rc; +} + /* * Handle PAGE_DATA record from an existing buffer * Given a list of pfns, their types, and a block of page data from the @@ -773,11 +889,19 @@ static int process_incoming_record_header(struct xc_s= r_context *ctx, struct xc_s struct xc_sr_record rec; int rc; =20 - rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); - if ( rc ) - return rc; + switch ( rhdr->type ) + { + case REC_TYPE_PAGE_DATA: + rc =3D handle_incoming_page_data(ctx, rhdr); + break; + default: + rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); + if ( rc =3D=3D 0 ) + rc =3D process_buffered_record(ctx, &rec);; + break; + } =20 - return process_buffered_record(ctx, &rec); + return rc; } =20 =20