From nobody Mon Feb 9 23:18:28 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; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1658409723863585.894202589581; Thu, 21 Jul 2022 06:22:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.372755.604712 (Exim 4.92) (envelope-from ) id 1oEW7e-0002as-D5; Thu, 21 Jul 2022 13:21:46 +0000 Received: by outflank-mailman (output) from mailman id 372755.604712; Thu, 21 Jul 2022 13:21:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oEW7e-0002aj-A8; Thu, 21 Jul 2022 13:21:46 +0000 Received: by outflank-mailman (input) for mailman id 372755; Thu, 21 Jul 2022 13:21:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oEW7c-0001je-K1 for xen-devel@lists.xenproject.org; Thu, 21 Jul 2022 13:21:44 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 102246cb-08f8-11ed-924f-1f966e50362f; Thu, 21 Jul 2022 15:21:43 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 883EB23A; Thu, 21 Jul 2022 06:21:43 -0700 (PDT) Received: from a011292.shanghai.arm.com (a011292.shanghai.arm.com [10.169.190.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A4B6E3F73D; Thu, 21 Jul 2022 06:21:40 -0700 (PDT) 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: 102246cb-08f8-11ed-924f-1f966e50362f From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v6 3/9] xen/arm: allocate static shared memory to a specific owner domain Date: Thu, 21 Jul 2022 21:21:09 +0800 Message-Id: <20220721132115.3015761-4-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721132115.3015761-1-Penny.Zheng@arm.com> References: <20220721132115.3015761-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1658409725047100001 Content-Type: text/plain; charset="utf-8" If owner property is defined, then owner domain of a static shared memory region is not the default dom_io anymore, but a specific domain. This commit implements allocating static shared memory to a specific domain when owner property is defined. Coding flow for dealing borrower domain will be introduced later in the following commits. Signed-off-by: Penny Zheng Reviewed-by: Stefano Stabellini --- v6 change: - fix coding-style - role_str and owner_dom_io shall be defined within the loop --- v5 change: - no change --- v4 change: - no changes --- v3 change: - simplify the code since o_gbase is not used if the domain is dom_io --- v2 change: - P2M mapping is restricted to normal domain - in-code comment fix --- xen/arch/arm/domain_build.c | 44 +++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index ff2aebaf28..a7e95c34a7 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -818,9 +818,11 @@ static mfn_t __init acquire_shared_memory_bank(struct = domain *d, =20 static int __init allocate_shared_memory(struct domain *d, u32 addr_cells, u32 size_cells, - paddr_t pbase, paddr_t psize) + paddr_t pbase, paddr_t psize, + paddr_t gbase) { mfn_t smfn; + int ret =3D 0; =20 dprintk(XENLOG_INFO, "%pd: allocate static shared memory BANK %#"PRIpaddr"-%#"PRIpa= ddr".\n", @@ -834,8 +836,18 @@ static int __init allocate_shared_memory(struct domain= *d, * DOMID_IO is the domain, like DOMID_XEN, that is not auto-translated. * It sees RAM 1:1 and we do not need to create P2M mapping for it */ - ASSERT(d =3D=3D dom_io); - return 0; + if ( d !=3D dom_io ) + { + ret =3D guest_physmap_add_pages(d, gaddr_to_gfn(gbase), smfn, + PFN_DOWN(psize)); + if ( ret ) + { + printk(XENLOG_ERR "Failed to map shared memory to %pd.\n", d); + return ret; + } + } + + return ret; } =20 static int __init process_shm(struct domain *d, @@ -851,6 +863,8 @@ static int __init process_shm(struct domain *d, paddr_t gbase, pbase, psize; int ret =3D 0; unsigned int i; + const char *role_str; + bool owner_dom_io =3D true; =20 if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-= v1") ) continue; @@ -887,19 +901,27 @@ static int __init process_shm(struct domain *d, return -EINVAL; } =20 - /* TODO: Consider owner domain is not the default dom_io. */ + /* + * "role" property is optional and if it is defined explicitly, + * then the owner domain is not the default "dom_io" domain. + */ + if ( dt_property_read_string(shm_node, "role", &role_str) =3D=3D 0= ) + owner_dom_io =3D false; + /* * Per static shared memory region could be shared between multiple * domains. - * In case re-allocating the same shared memory region, we check - * if it is already allocated to the default owner dom_io before - * the actual allocation. + * So when owner domain is the default dom_io, in case re-allocati= ng + * the same shared memory region, we check if it is already alloca= ted + * to the default owner dom_io before the actual allocation. */ - if ( !is_shm_allocated_to_domio(pbase) ) + if ( (owner_dom_io && !is_shm_allocated_to_domio(pbase)) || + (!owner_dom_io && strcmp(role_str, "owner") =3D=3D 0) ) { - /* Allocate statically shared pages to the default owner dom_i= o. */ - ret =3D allocate_shared_memory(dom_io, addr_cells, size_cells, - pbase, psize); + /* Allocate statically shared pages to the owner domain. */ + ret =3D allocate_shared_memory(owner_dom_io ? dom_io : d, + addr_cells, size_cells, + pbase, psize, gbase); if ( ret ) return ret; } --=20 2.25.1