From nobody Sat Feb 7 06:55:37 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1583746560; cv=none; d=zohomail.com; s=zohoarc; b=kvxzzf/KQXw2180P6xsextBWQjOlcMd/kWdnFbWk+F9m8lL8uYzngPuW/m9ny5Lt4A44vQ9gNWBr3Rvs5FX1Ng7wzA7le9h1ShQuypIkrzqrKF+x3L5KUxc0ySBLnRBtMDJ5QjkcHjpPZvXjlhEnixxV+XiBaoLSNY6xk78aDmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583746560; h=Content-Type: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=reXeYrCnRwPUKtqEQeV87w8ia6ELPZZXST7V+tY/yy4=; b=R3IKh0b55ZCRREkMA9QOZgmqfSXxtBsN9CSGORGMQzW0V5o8/r0Y8qN3vDS8lTMGjuvVKzFIzQEkvZTrwh/LVdTQE63d9cHu1a7G1j0HJOzDf+7tB6rZIBoea0Babk+JImBS9FE+yZ6wDscJJKq6DBAdbHwr916UY5/HUdE98ug= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) 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 158374656010085.1351251208498; Mon, 9 Mar 2020 02:36:00 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jBEol-00034z-3f; Mon, 09 Mar 2020 09:35:23 +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.89) (envelope-from ) id 1jBEoj-000349-Da for xen-devel@lists.xenproject.org; Mon, 09 Mar 2020 09:35:21 +0000 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4ad5526a-61e9-11ea-abf0-12813bfff9fa; Mon, 09 Mar 2020 09:35:19 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 09 Mar 2020 09:35:19 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (Postfix) with ESMTPS id B0462A2C22; Mon, 9 Mar 2020 09:35:17 +0000 (UTC) Received: from EX13D32EUC004.ant.amazon.com (10.43.164.121) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Mon, 9 Mar 2020 09:35:17 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D32EUC004.ant.amazon.com (10.43.164.121) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 9 Mar 2020 09:35:16 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 9 Mar 2020 09:35:13 +0000 X-Inumbo-ID: 4ad5526a-61e9-11ea-abf0-12813bfff9fa IronPort-SDR: k0A7pjFHbbhd5B74oR5CJEUMxigD8cEmkKNciBC9aPgMPzWkXtRng/6HJMrGFNNcYRwD4MSMHl R4zWwVqgQWmw== X-IronPort-AV: E=Sophos;i="5.70,532,1574121600"; d="scan'208";a="20373418" From: To: Date: Mon, 9 Mar 2020 09:35:06 +0000 Message-ID: <20200309093511.1727-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200309093511.1727-1-paul@xen.org> References: <20200309093511.1727-1-paul@xen.org> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v4 1/6] domain: introduce alloc/free_shared_info() helpers... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Paul Durrant , Andrew Cooper , Paul Durrant , Konrad Rzeszutek Wilk , Ian Jackson , George Dunlap , Hongyan Xia , Jan Beulich , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Durrant ... and save the MFN. This patch modifies the 'shared_info' field of struct domain to be a structure comprising an MFN and a virtual address. Allocations are still done from xenheap, so the virtual address still equates to virt_to_mfn() called on the MFN but subsequent patch will change this. Hence the need to save the MFN. NOTE: Whist defining the new helpers, virt_to_mfn() in common/domain.c is made type safe. The definition of nmi_reason() in asm-x86/shared.h is also re- flowed to avoid overly long lines. Signed-off-by: Paul Durrant Reviewed-by: Julien Grall Reviewed-by: Hongyan Xia Acked-by: Jan Beulich --- Cc: Stefano Stabellini Cc: Volodymyr Babchuk Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Konrad Rzeszutek Wilk Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" --- xen/arch/arm/domain.c | 8 ++------ xen/arch/arm/mm.c | 2 +- xen/arch/x86/domain.c | 11 ++++------- xen/arch/x86/mm.c | 2 +- xen/arch/x86/pv/dom0_build.c | 2 +- xen/arch/x86/pv/shim.c | 2 +- xen/common/domain.c | 26 ++++++++++++++++++++++++++ xen/common/domctl.c | 2 +- xen/common/time.c | 4 ++-- xen/include/asm-x86/shared.h | 15 ++++++++------- xen/include/xen/domain.h | 3 +++ xen/include/xen/sched.h | 5 ++++- xen/include/xen/shared.h | 2 +- 13 files changed, 55 insertions(+), 29 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 6627be2922..5298d80bd2 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -689,13 +689,9 @@ int arch_domain_create(struct domain *d, if ( (rc =3D p2m_init(d)) !=3D 0 ) goto fail; =20 - rc =3D -ENOMEM; - if ( (d->shared_info =3D alloc_xenheap_pages(0, 0)) =3D=3D NULL ) + if ( (rc =3D alloc_shared_info(d, 0)) !=3D 0 ) goto fail; =20 - clear_page(d->shared_info); - share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw); - switch ( config->arch.gic_version ) { case XEN_DOMCTL_CONFIG_GIC_V2: @@ -766,7 +762,7 @@ void arch_domain_destroy(struct domain *d) p2m_teardown(d); domain_vgic_free(d); domain_vuart_free(d); - free_xenheap_page(d->shared_info); + free_shared_info(d); #ifdef CONFIG_ACPI free_xenheap_pages(d->arch.efi_acpi_table, get_order_from_bytes(d->arch.efi_acpi_len)); diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 727107eefa..2bb592101d 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1424,7 +1424,7 @@ int xenmem_add_to_physmap_one( if ( idx !=3D 0 ) return -EINVAL; =20 - mfn =3D virt_to_mfn(d->shared_info); + mfn =3D d->shared_info.mfn; t =3D p2m_ram_rw; =20 break; diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index caf2ecad7e..bdcc0d972a 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -611,12 +611,9 @@ int arch_domain_create(struct domain *d, * The shared_info machine address must fit in a 32-bit field within a * 32-bit guest's start_info structure. Hence we specify MEMF_bits(32). */ - if ( (d->shared_info =3D alloc_xenheap_pages(0, MEMF_bits(32))) =3D=3D= NULL ) + if ( (rc =3D alloc_shared_info(d, MEMF_bits(32))) !=3D 0 ) goto fail; =20 - clear_page(d->shared_info); - share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw); - if ( (rc =3D init_domain_irq_mapping(d)) !=3D 0 ) goto fail; =20 @@ -664,7 +661,7 @@ int arch_domain_create(struct domain *d, psr_domain_free(d); iommu_domain_destroy(d); cleanup_domain_irq_mapping(d); - free_xenheap_page(d->shared_info); + free_shared_info(d); xfree(d->arch.cpuid); xfree(d->arch.msr); if ( paging_initialised ) @@ -693,7 +690,7 @@ void arch_domain_destroy(struct domain *d) pv_domain_destroy(d); free_perdomain_mappings(d); =20 - free_xenheap_page(d->shared_info); + free_shared_info(d); cleanup_domain_irq_mapping(d); =20 psr_domain_free(d); @@ -719,7 +716,7 @@ void arch_domain_unpause(struct domain *d) =20 int arch_domain_soft_reset(struct domain *d) { - struct page_info *page =3D virt_to_page(d->shared_info), *new_page; + struct page_info *page =3D mfn_to_page(d->shared_info.mfn), *new_page; int ret =3D 0; struct domain *owner; mfn_t mfn; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 62507ca651..ba7563ed3c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4540,7 +4540,7 @@ int xenmem_add_to_physmap_one( { case XENMAPSPACE_shared_info: if ( idx =3D=3D 0 ) - mfn =3D virt_to_mfn(d->shared_info); + mfn =3D d->shared_info.mfn; break; case XENMAPSPACE_grant_table: rc =3D gnttab_map_frame(d, idx, gpfn, &mfn); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 5678da782d..dc16ef2e79 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -743,7 +743,7 @@ int __init dom0_construct_pv(struct domain *d, clear_page(si); si->nr_pages =3D nr_pages; =20 - si->shared_info =3D virt_to_maddr(d->shared_info); + si->shared_info =3D mfn_to_maddr(d->shared_info.mfn); =20 if ( !pv_shim ) si->flags =3D SIF_PRIVILEGED | SIF_INITDOMAIN; diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index d86e2de118..f512809dad 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -282,7 +282,7 @@ static void write_start_info(struct domain *d) snprintf(si->magic, sizeof(si->magic), "xen-3.0-x86_%s", is_pv_32bit_domain(d) ? "32p" : "64"); si->nr_pages =3D domain_tot_pages(d); - si->shared_info =3D virt_to_maddr(d->shared_info); + si->shared_info =3D mfn_to_maddr(d->shared_info.mfn); si->flags =3D 0; BUG_ON(xen_hypercall_hvm_get_param(HVM_PARAM_STORE_PFN, &si->store_mfn= )); BUG_ON(xen_hypercall_hvm_get_param(HVM_PARAM_STORE_EVTCHN, ¶m)); diff --git a/xen/common/domain.c b/xen/common/domain.c index 6ad458fa6b..ba7a905258 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -47,6 +47,10 @@ #include #endif =20 +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn(v) _mfn(__virt_to_mfn(v)) + /* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */ unsigned int xen_processor_pmbits =3D XEN_PROCESSOR_PM_PX; @@ -1644,6 +1648,28 @@ int continue_hypercall_on_cpu( return 0; } =20 +int alloc_shared_info(struct domain *d, unsigned int memflags) +{ + if ( (d->shared_info.virt =3D alloc_xenheap_pages(0, memflags)) =3D=3D= NULL ) + return -ENOMEM; + + d->shared_info.mfn =3D virt_to_mfn(d->shared_info.virt); + + clear_page(d->shared_info.virt); + share_xen_page_with_guest(mfn_to_page(d->shared_info.mfn), d, SHARE_rw= ); + + return 0; +} + +void free_shared_info(struct domain *d) +{ + if ( !d->shared_info.virt ) + return; + + free_xenheap_page(d->shared_info.virt); + d->shared_info.virt =3D NULL; +} + /* * Local variables: * mode: C diff --git a/xen/common/domctl.c b/xen/common/domctl.c index a69b3b59a8..81f18e63a7 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -196,7 +196,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_= getdomaininfo *info) info->outstanding_pages =3D d->outstanding_pages; info->shr_pages =3D atomic_read(&d->shr_pages); info->paged_pages =3D atomic_read(&d->paged_pages); - info->shared_info_frame =3D mfn_to_gmfn(d, virt_to_mfn(d->shared_info)= ); + info->shared_info_frame =3D mfn_to_gmfn(d, mfn_x(d->shared_info.mfn)); BUG_ON(SHARED_M2P(info->shared_info_frame)); =20 info->cpupool =3D cpupool_get_id(d); diff --git a/xen/common/time.c b/xen/common/time.c index 82336e2d5a..58fa9abc40 100644 --- a/xen/common/time.c +++ b/xen/common/time.c @@ -110,9 +110,9 @@ void update_domain_wallclock_time(struct domain *d) shared_info(d, wc_nsec) =3D wc_nsec; #ifdef CONFIG_X86 if ( likely(!has_32bit_shinfo(d)) ) - d->shared_info->native.wc_sec_hi =3D sec >> 32; + d->shared_info.virt->native.wc_sec_hi =3D sec >> 32; else - d->shared_info->compat.arch.wc_sec_hi =3D sec >> 32; + d->shared_info.virt->compat.arch.wc_sec_hi =3D sec >> 32; #else shared_info(d, wc_sec_hi) =3D sec >> 32; #endif diff --git a/xen/include/asm-x86/shared.h b/xen/include/asm-x86/shared.h index af5d959d04..d4588e08a6 100644 --- a/xen/include/asm-x86/shared.h +++ b/xen/include/asm-x86/shared.h @@ -1,24 +1,25 @@ #ifndef __XEN_X86_SHARED_H__ #define __XEN_X86_SHARED_H__ =20 -#define nmi_reason(d) (!has_32bit_shinfo(d) ? \ - (u32 *)&(d)->shared_info->native.arch.nmi_reason : \ - (u32 *)&(d)->shared_info->compat.arch.nmi_reason) +#define nmi_reason(d) \ + (!has_32bit_shinfo(d) ? \ + (u32 *)&(d)->shared_info.virt->native.arch.nmi_reason : \ + (u32 *)&(d)->shared_info.virt->compat.arch.nmi_reason) =20 #define GET_SET_SHARED(type, field) \ static inline type arch_get_##field(const struct domain *d) \ { \ return !has_32bit_shinfo(d) ? \ - d->shared_info->native.arch.field : \ - d->shared_info->compat.arch.field; \ + d->shared_info.virt->native.arch.field : \ + d->shared_info.virt->compat.arch.field; \ } \ static inline void arch_set_##field(struct domain *d, \ type val) \ { \ if ( !has_32bit_shinfo(d) ) \ - d->shared_info->native.arch.field =3D val; \ + d->shared_info.virt->native.arch.field =3D val; \ else \ - d->shared_info->compat.arch.field =3D val; \ + d->shared_info.virt->compat.arch.field =3D val; \ } =20 #define GET_SET_VCPU(type, field) \ diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 7e51d361de..740e2032ad 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -130,4 +130,7 @@ struct vnuma_info { =20 void vnuma_destroy(struct vnuma_info *vnuma); =20 +int alloc_shared_info(struct domain *d, unsigned int memflags); +void free_shared_info(struct domain *d); + #endif /* __XEN_DOMAIN_H__ */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3a4f43098c..f41d0ad2a0 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -346,7 +346,10 @@ struct domain unsigned int max_vcpus; struct vcpu **vcpu; =20 - shared_info_t *shared_info; /* shared data area */ + struct { + mfn_t mfn; + shared_info_t *virt; + } shared_info; /* shared data area */ =20 spinlock_t domain_lock; =20 diff --git a/xen/include/xen/shared.h b/xen/include/xen/shared.h index a411a8a3e3..57b2ff1e34 100644 --- a/xen/include/xen/shared.h +++ b/xen/include/xen/shared.h @@ -43,7 +43,7 @@ typedef struct vcpu_info vcpu_info_t; =20 extern vcpu_info_t dummy_vcpu_info; =20 -#define shared_info(d, field) __shared_info(d, (d)->shared_info, fiel= d) +#define shared_info(d, field) __shared_info(d, (d)->shared_info.virt,= field) #define vcpu_info(v, field) __vcpu_info(v, (v)->vcpu_info, field) =20 #endif /* __XEN_SHARED_H__ */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel