From nobody Mon Nov 25 07:49:04 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; 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 1715783222356897.1713314596269; Wed, 15 May 2024 07:27:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.722424.1126369 (Exim 4.92) (envelope-from ) id 1s7Fad-0002aA-1b; Wed, 15 May 2024 14:26:43 +0000 Received: by outflank-mailman (output) from mailman id 722424.1126369; Wed, 15 May 2024 14:26: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 1s7Fac-0002a3-TH; Wed, 15 May 2024 14:26:42 +0000 Received: by outflank-mailman (input) for mailman id 722424; Wed, 15 May 2024 14:26:41 +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 1s7Fab-0002KG-3F for xen-devel@lists.xenproject.org; Wed, 15 May 2024 14:26:41 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 2438264b-12c7-11ef-b4bb-af5377834399; Wed, 15 May 2024 16:26:38 +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 0FEB81516; Wed, 15 May 2024 07:27:03 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 97A8B3F7A6; Wed, 15 May 2024 07:26:37 -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: 2438264b-12c7-11ef-b4bb-af5377834399 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v2 2/7] xen/arm: Wrap shared memory mapping code in one function Date: Wed, 15 May 2024 15:26:20 +0100 Message-Id: <20240515142626.3480640-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515142626.3480640-1-luca.fancellu@arm.com> References: <20240515142626.3480640-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1715783224324100003 Content-Type: text/plain; charset="utf-8" Wrap the code and logic that is calling assign_shared_memory and map_regions_p2mt into a new function 'handle_shared_mem_bank', it will become useful later when the code will allow the user to don't pass the host physical address. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v2 changes: - add blank line, move owner_dom_io computation inside handle_shared_mem_bank in order to reduce args count, remove not needed BUGON(). (Michal) --- xen/arch/arm/static-shmem.c | 87 ++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 0afc86c43f85..8a14d120690c 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -181,6 +181,53 @@ append_shm_bank_to_domain(struct kernel_info *kinfo, p= addr_t start, return 0; } =20 +static int __init handle_shared_mem_bank(struct domain *d, paddr_t gbase, + const char *role_str, + const struct membank *shm_bank) +{ + bool owner_dom_io =3D true; + paddr_t pbase, psize; + int ret; + + pbase =3D shm_bank->start; + psize =3D shm_bank->size; + + /* + * "role" property is optional and if it is defined explicitly, + * then the owner domain is not the default "dom_io" domain. + */ + if ( role_str !=3D NULL ) + owner_dom_io =3D false; + + /* + * DOMID_IO is a fake domain and is not described in the Device-Tree. + * Therefore when the owner of the shared region is DOMID_IO, we will + * only find the borrowers. + */ + if ( (owner_dom_io && !is_shm_allocated_to_domio(pbase)) || + (!owner_dom_io && strcmp(role_str, "owner") =3D=3D 0) ) + { + /* + * We found the first borrower of the region, the owner was not + * specified, so they should be assigned to dom_io. + */ + ret =3D assign_shared_memory(owner_dom_io ? dom_io : d, gbase, shm= _bank); + if ( ret ) + return ret; + } + + if ( owner_dom_io || (strcmp(role_str, "borrower") =3D=3D 0) ) + { + /* Set up P2M foreign mapping for borrower domain. */ + ret =3D map_regions_p2mt(d, _gfn(PFN_UP(gbase)), PFN_DOWN(psize), + _mfn(PFN_UP(pbase)), p2m_map_foreign_rw); + if ( ret ) + return ret; + } + + return 0; +} + int __init process_shm(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) { @@ -195,9 +242,8 @@ int __init process_shm(struct domain *d, struct kernel_= info *kinfo, paddr_t gbase, pbase, psize; int ret =3D 0; unsigned int i; - const char *role_str; + const char *role_str =3D NULL; const char *shm_id; - bool owner_dom_io =3D true; =20 if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-= v1") ) continue; @@ -238,39 +284,12 @@ int __init process_shm(struct domain *d, struct kerne= l_info *kinfo, return -EINVAL; } =20 - /* - * "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; + /* "role" property is optional */ + dt_property_read_string(shm_node, "role", &role_str); =20 - /* - * DOMID_IO is a fake domain and is not described in the Device-Tr= ee. - * Therefore when the owner of the shared region is DOMID_IO, we w= ill - * only find the borrowers. - */ - if ( (owner_dom_io && !is_shm_allocated_to_domio(pbase)) || - (!owner_dom_io && strcmp(role_str, "owner") =3D=3D 0) ) - { - /* - * We found the first borrower of the region, the owner was not - * specified, so they should be assigned to dom_io. - */ - ret =3D assign_shared_memory(owner_dom_io ? dom_io : d, gbase, - boot_shm_bank); - if ( ret ) - return ret; - } - - if ( owner_dom_io || (strcmp(role_str, "borrower") =3D=3D 0) ) - { - /* Set up P2M foreign mapping for borrower domain. */ - ret =3D map_regions_p2mt(d, _gfn(PFN_UP(gbase)), PFN_DOWN(psiz= e), - _mfn(PFN_UP(pbase)), p2m_map_foreign_rw= ); - if ( ret ) - return ret; - } + ret =3D handle_shared_mem_bank(d, gbase, role_str, boot_shm_bank); + if ( ret ) + return ret; =20 /* * Record static shared memory region info for later setting --=20 2.34.1