From nobody Mon Feb 9 17:05:14 2026 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; 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=1598627333; cv=none; d=zohomail.com; s=zohoarc; b=lgt/crnxvcIoS3n0cfLY5fjyfQkx/qJUv9QBWW/1T2E0n7KOsDjL4IkhR7kJMrYEZdVSj5V4wW84KLqlELIGTMgXHc+i0Y1mtw5P3Vb+4vlVl4iEqGR/s/5HNUEemln9oWJ6hVVK3AGu1r4azIKic72p3AKIr7L1NHU91wgU3sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598627333; 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=wCEpeePgjATYvqlRp4ToSFv/2KAlJ4rpx56kjWkHYLc=; b=GGthmZ1600S4PNiuME+ydOXFj6fC9Fa4kfBmqggOREwE9s8P0MLBqh9frrpjiFuXe3zOVt415LnZMv1Rg0+nkESP9OtTcUg9+K2LGQQCicfRsUt9JQewvC6s02DGxD2UILaDYCSUUXnK2GDYvaTxMriBQQemXhSGG3msNOEhk8w= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1598627333147738.9344351856461; Fri, 28 Aug 2020 08:08:53 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kBfzX-0005BZ-H2; Fri, 28 Aug 2020 15:08:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kBfzW-0004eL-If for xen-devel@lists.xenproject.org; Fri, 28 Aug 2020 15:08:34 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9c285ca6-7a91-4841-8dbb-a225b154761e; Fri, 28 Aug 2020 15:07:55 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AE626AF6E; Fri, 28 Aug 2020 15:08:24 +0000 (UTC) X-Inumbo-ID: 9c285ca6-7a91-4841-8dbb-a225b154761e X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v4 11/31] tools/libxc: move xc_[un]map_domain_meminfo() into new source xg_domain.c Date: Fri, 28 Aug 2020 17:07:27 +0200 Message-Id: <20200828150747.25305-12-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200828150747.25305-1-jgross@suse.com> References: <20200828150747.25305-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" Move xc_[un]map_domain_meminfo() functions to new source xg_domain.c as they are defined in include/xenguest.h and should be in libxenguest. Signed-off-by: Juergen Gross Acked-by: Wei Liu --- tools/libxc/Makefile | 4 +- tools/libxc/xc_domain.c | 126 --------------------------------- tools/libxc/xg_domain.c | 149 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 127 deletions(-) create mode 100644 tools/libxc/xg_domain.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 763231065c..7b81f8c193 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -52,7 +52,9 @@ CTRL_SRCS-y +=3D xc_gnttab_compat.c CTRL_SRCS-y +=3D xc_devicemodel_compat.c =20 GUEST_SRCS-y :=3D -GUEST_SRCS-y +=3D xg_private.c xc_suspend.c +GUEST_SRCS-y +=3D xg_private.c +GUEST_SRCS-y +=3D xg_domain.c +GUEST_SRCS-y +=3D xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y +=3D xc_sr_common.c GUEST_SRCS-$(CONFIG_X86) +=3D xc_sr_common_x86.c diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 71829c2bce..fbc22c4df6 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1892,132 +1892,6 @@ int xc_domain_unbind_pt_spi_irq(xc_interface *xch, PT_IRQ_TYPE_SPI, 0, 0, 0, 0, spi)); } =20 -int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *m= info) -{ - struct domain_info_context _di =3D { .guest_width =3D minfo->guest_wid= th, - .p2m_size =3D minfo->p2m_size}; - struct domain_info_context *dinfo =3D &_di; - - free(minfo->pfn_type); - if ( minfo->p2m_table ) - munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE); - minfo->p2m_table =3D NULL; - - return 0; -} - -int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid, - struct xc_domain_meminfo *minfo) -{ - struct domain_info_context _di; - struct domain_info_context *dinfo =3D &_di; - - xc_dominfo_t info; - shared_info_any_t *live_shinfo; - xen_capabilities_info_t xen_caps =3D ""; - int i; - - /* Only be initialized once */ - if ( minfo->pfn_type || minfo->p2m_table ) - { - errno =3D EINVAL; - return -1; - } - - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 ) - { - PERROR("Could not get domain info"); - return -1; - } - - if ( xc_domain_get_guest_width(xch, domid, &minfo->guest_width) ) - { - PERROR("Could not get domain address size"); - return -1; - } - _di.guest_width =3D minfo->guest_width; - - /* Get page table levels (see get_platform_info() in xg_save_restore.h= */ - if ( xc_version(xch, XENVER_capabilities, &xen_caps) ) - { - PERROR("Could not get Xen capabilities (for page table levels)"); - return -1; - } - if ( strstr(xen_caps, "xen-3.0-x86_64") ) - /* Depends on whether it's a compat 32-on-64 guest */ - minfo->pt_levels =3D ( (minfo->guest_width =3D=3D 8) ? 4 : 3 ); - else if ( strstr(xen_caps, "xen-3.0-x86_32p") ) - minfo->pt_levels =3D 3; - else if ( strstr(xen_caps, "xen-3.0-x86_32") ) - minfo->pt_levels =3D 2; - else - { - errno =3D EFAULT; - return -1; - } - - /* We need the shared info page for mapping the P2M */ - live_shinfo =3D xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ, - info.shared_info_frame); - if ( !live_shinfo ) - { - PERROR("Could not map the shared info frame (MFN 0x%lx)", - info.shared_info_frame); - return -1; - } - - if ( xc_core_arch_map_p2m_writable(xch, minfo->guest_width, &info, - live_shinfo, &minfo->p2m_table, - &minfo->p2m_size) ) - { - PERROR("Could not map the P2M table"); - munmap(live_shinfo, PAGE_SIZE); - return -1; - } - munmap(live_shinfo, PAGE_SIZE); - _di.p2m_size =3D minfo->p2m_size; - - /* Make space and prepare for getting the PFN types */ - minfo->pfn_type =3D calloc(sizeof(*minfo->pfn_type), minfo->p2m_size); - if ( !minfo->pfn_type ) - { - PERROR("Could not allocate memory for the PFN types"); - goto failed; - } - for ( i =3D 0; i < minfo->p2m_size; i++ ) - minfo->pfn_type[i] =3D xc_pfn_to_mfn(i, minfo->p2m_table, - minfo->guest_width); - - /* Retrieve PFN types in batches */ - for ( i =3D 0; i < minfo->p2m_size ; i+=3D1024 ) - { - int count =3D ((minfo->p2m_size - i ) > 1024 ) ? - 1024: (minfo->p2m_size - i); - - if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i)= ) - { - PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024); - goto failed; - } - } - - return 0; - -failed: - if ( minfo->pfn_type ) - { - free(minfo->pfn_type); - minfo->pfn_type =3D NULL; - } - if ( minfo->p2m_table ) - { - munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE); - minfo->p2m_table =3D NULL; - } - - return -1; -} - int xc_domain_memory_mapping( xc_interface *xch, uint32_t domid, diff --git a/tools/libxc/xg_domain.c b/tools/libxc/xg_domain.c new file mode 100644 index 0000000000..58713cd35d --- /dev/null +++ b/tools/libxc/xg_domain.c @@ -0,0 +1,149 @@ +/*************************************************************************= ***** + * xg_domain.c + * + * API for manipulating and obtaining information on domains. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + * + * Copyright (c) 2003, K A Fraser. + */ + +#include "xg_private.h" +#include "xc_core.h" + +int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *m= info) +{ + struct domain_info_context _di =3D { .guest_width =3D minfo->guest_wid= th, + .p2m_size =3D minfo->p2m_size}; + struct domain_info_context *dinfo =3D &_di; + + free(minfo->pfn_type); + if ( minfo->p2m_table ) + munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE); + minfo->p2m_table =3D NULL; + + return 0; +} + +int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid, + struct xc_domain_meminfo *minfo) +{ + struct domain_info_context _di; + struct domain_info_context *dinfo =3D &_di; + + xc_dominfo_t info; + shared_info_any_t *live_shinfo; + xen_capabilities_info_t xen_caps =3D ""; + int i; + + /* Only be initialized once */ + if ( minfo->pfn_type || minfo->p2m_table ) + { + errno =3D EINVAL; + return -1; + } + + if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 ) + { + PERROR("Could not get domain info"); + return -1; + } + + if ( xc_domain_get_guest_width(xch, domid, &minfo->guest_width) ) + { + PERROR("Could not get domain address size"); + return -1; + } + _di.guest_width =3D minfo->guest_width; + + /* Get page table levels (see get_platform_info() in xg_save_restore.h= */ + if ( xc_version(xch, XENVER_capabilities, &xen_caps) ) + { + PERROR("Could not get Xen capabilities (for page table levels)"); + return -1; + } + if ( strstr(xen_caps, "xen-3.0-x86_64") ) + /* Depends on whether it's a compat 32-on-64 guest */ + minfo->pt_levels =3D ( (minfo->guest_width =3D=3D 8) ? 4 : 3 ); + else if ( strstr(xen_caps, "xen-3.0-x86_32p") ) + minfo->pt_levels =3D 3; + else if ( strstr(xen_caps, "xen-3.0-x86_32") ) + minfo->pt_levels =3D 2; + else + { + errno =3D EFAULT; + return -1; + } + + /* We need the shared info page for mapping the P2M */ + live_shinfo =3D xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ, + info.shared_info_frame); + if ( !live_shinfo ) + { + PERROR("Could not map the shared info frame (MFN 0x%lx)", + info.shared_info_frame); + return -1; + } + + if ( xc_core_arch_map_p2m_writable(xch, minfo->guest_width, &info, + live_shinfo, &minfo->p2m_table, + &minfo->p2m_size) ) + { + PERROR("Could not map the P2M table"); + munmap(live_shinfo, PAGE_SIZE); + return -1; + } + munmap(live_shinfo, PAGE_SIZE); + _di.p2m_size =3D minfo->p2m_size; + + /* Make space and prepare for getting the PFN types */ + minfo->pfn_type =3D calloc(sizeof(*minfo->pfn_type), minfo->p2m_size); + if ( !minfo->pfn_type ) + { + PERROR("Could not allocate memory for the PFN types"); + goto failed; + } + for ( i =3D 0; i < minfo->p2m_size; i++ ) + minfo->pfn_type[i] =3D xc_pfn_to_mfn(i, minfo->p2m_table, + minfo->guest_width); + + /* Retrieve PFN types in batches */ + for ( i =3D 0; i < minfo->p2m_size ; i+=3D1024 ) + { + int count =3D ((minfo->p2m_size - i ) > 1024 ) ? + 1024: (minfo->p2m_size - i); + + if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i)= ) + { + PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024); + goto failed; + } + } + + return 0; + +failed: + if ( minfo->pfn_type ) + { + free(minfo->pfn_type); + minfo->pfn_type =3D NULL; + } + if ( minfo->p2m_table ) + { + munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE); + minfo->p2m_table =3D NULL; + } + + return -1; +} --=20 2.26.2