From nobody Sat Apr 20 11:22:37 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 1668480810856856.0066373177651; Mon, 14 Nov 2022 18:53:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443636.698317 (Exim 4.92) (envelope-from ) id 1oum4J-0000aP-K4; Tue, 15 Nov 2022 02:52:59 +0000 Received: by outflank-mailman (output) from mailman id 443636.698317; Tue, 15 Nov 2022 02:52:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4J-0000aI-Gp; Tue, 15 Nov 2022 02:52:59 +0000 Received: by outflank-mailman (input) for mailman id 443636; Tue, 15 Nov 2022 02:52:58 +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 1oum4I-0008Vs-A3 for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:52:58 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 9bc7c197-6490-11ed-8fd2-01056ac49cbb; Tue, 15 Nov 2022 03:52:57 +0100 (CET) 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 E92E411FB; Mon, 14 Nov 2022 18:53:02 -0800 (PST) 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 1700F3F73B; Mon, 14 Nov 2022 18:52:53 -0800 (PST) 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: 9bc7c197-6490-11ed-8fd2-01056ac49cbb From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v1 02/13] xen/arm: switch to use shm_membank as function parameter Date: Tue, 15 Nov 2022 10:52:24 +0800 Message-Id: <20221115025235.1378931-3-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115025235.1378931-1-Penny.Zheng@arm.com> References: <20221115025235.1378931-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1668480812451100008 Content-Type: text/plain; charset="utf-8" Instead of using multiple function parameters to deliver various shm-related info, like host physical address, SHMID, etc, and with the introduction of new struct "shm_membank", we could switch to use "shm_membank" as function parameter to replace them all, to make codes more clear and tidy. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index c0fd13f6ed..d2b9e60b5c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -751,40 +751,31 @@ static void __init assign_static_memory_11(struct dom= ain *d, } =20 #ifdef CONFIG_STATIC_SHM -static int __init acquire_nr_borrower_domain(struct domain *d, - paddr_t pbase, paddr_t psize, - unsigned long *nr_borrowers) +static struct shm_membank * __init acquire_shm_membank(const char *shm_id) { unsigned int bank; =20 /* Iterate static shared memory to find requested shm bank. */ for ( bank =3D 0 ; bank < bootinfo.shm_mem.nr_banks; bank++ ) - { - paddr_t bank_start =3D bootinfo.shm_mem.bank[bank].membank->start; - paddr_t bank_size =3D bootinfo.shm_mem.bank[bank].membank->size; - - if ( (pbase =3D=3D bank_start) && (psize =3D=3D bank_size) ) + if ( strcmp(shm_id, bootinfo.shm_mem.bank[bank].shm_id) =3D=3D 0 ) break; - } =20 if ( bank =3D=3D bootinfo.shm_mem.nr_banks ) - return -ENOENT; - - *nr_borrowers =3D bootinfo.shm_mem.bank[bank].nr_shm_borrowers; + return NULL; =20 - return 0; + return &bootinfo.shm_mem.bank[bank]; } =20 /* * This function checks whether the static shared memory region is * already allocated to dom_io. */ -static bool __init is_shm_allocated_to_domio(paddr_t pbase) +static bool __init is_shm_allocated_to_domio(struct shm_membank *shm_memba= nk) { struct page_info *page; struct domain *d; =20 - page =3D maddr_to_page(pbase); + page =3D maddr_to_page(shm_membank->membank->start); d =3D page_get_owner_and_reference(page); if ( d =3D=3D NULL ) return false; @@ -835,14 +826,17 @@ static mfn_t __init acquire_shared_memory_bank(struct= domain *d, } =20 static int __init assign_shared_memory(struct domain *d, - uint32_t addr_cells, uint32_t size_= cells, - paddr_t pbase, paddr_t psize, + struct shm_membank *shm_membank, paddr_t gbase) { mfn_t smfn; int ret =3D 0; unsigned long nr_pages, nr_borrowers, i; struct page_info *page; + paddr_t pbase, psize; + + pbase =3D shm_membank->membank->start; + psize =3D shm_membank->membank->size; =20 printk("%pd: allocate static shared memory BANK %#"PRIpaddr"-%#"PRIpad= dr".\n", d, pbase, pbase + psize); @@ -871,9 +865,7 @@ static int __init assign_shared_memory(struct domain *d, * Get the right amount of references per page, which is the number of * borrower domains. */ - ret =3D acquire_nr_borrower_domain(d, pbase, psize, &nr_borrowers); - if ( ret ) - return ret; + nr_borrowers =3D shm_membank->nr_shm_borrowers; =20 /* * Instead of letting borrower domain get a page ref, we add as many @@ -941,6 +933,7 @@ static int __init process_shm(struct domain *d, struct = kernel_info *kinfo, const char *role_str; const char *shm_id; bool owner_dom_io =3D true; + struct shm_membank *shm_membank; =20 if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-= v1") ) continue; @@ -991,12 +984,20 @@ static int __init process_shm(struct domain *d, struc= t kernel_info *kinfo, } BUG_ON((strlen(shm_id) <=3D 0) || (strlen(shm_id) >=3D MAX_SHM_ID_= LENGTH)); =20 + shm_membank =3D acquire_shm_membank(shm_id); + if ( !shm_membank ) + { + printk("%pd: failed to acquire %s shared memory bank\n", + d, shm_id); + return -ENOENT; + } + /* * 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)) || + if ( (owner_dom_io && !is_shm_allocated_to_domio(shm_membank)) || (!owner_dom_io && strcmp(role_str, "owner") =3D=3D 0) ) { /* @@ -1004,8 +1005,7 @@ static int __init process_shm(struct domain *d, struc= t kernel_info *kinfo, * specified, so they should be assigned to dom_io. */ ret =3D assign_shared_memory(owner_dom_io ? dom_io : d, - addr_cells, size_cells, - pbase, psize, gbase); + shm_membank, gbase); if ( ret ) return ret; } --=20 2.25.1