From nobody Fri Apr 26 10:20:53 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 1668480809640590.3965259512001; Mon, 14 Nov 2022 18:53:29 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443635.698306 (Exim 4.92) (envelope-from ) id 1oum4I-0000Km-8P; Tue, 15 Nov 2022 02:52:58 +0000 Received: by outflank-mailman (output) from mailman id 443635.698306; Tue, 15 Nov 2022 02:52:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4I-0000Kf-4I; Tue, 15 Nov 2022 02:52:58 +0000 Received: by outflank-mailman (input) for mailman id 443635; Tue, 15 Nov 2022 02:52:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4G-0000BJ-RK for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:52:56 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 99feff1e-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:52:55 +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 D1B9913D5; Mon, 14 Nov 2022 18:52:59 -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 F37B13F73B; Mon, 14 Nov 2022 18:52:50 -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: 99feff1e-6490-11ed-91b6-6bf2151ebd3b 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 01/13] xen/arm: re-arrange the static shared memory region Date: Tue, 15 Nov 2022 10:52:23 +0800 Message-Id: <20221115025235.1378931-2-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: 1668480810941100003 Content-Type: text/plain; charset="utf-8" This commit re-arranges the static shared memory regions into a separate ar= ray shm_meminfo. And static shared memory region now would have its own structu= re 'shm_membank' to hold all shm-related members, like shm_id, etc, and a poin= ter to the normal memory bank 'membank'. This will avoid continuing to grow 'membank'. Signed-off-by: Penny Zheng --- xen/arch/arm/bootfdt.c | 40 +++++++++++++++++++------------ xen/arch/arm/domain_build.c | 35 ++++++++++++++++----------- xen/arch/arm/include/asm/kernel.h | 2 +- xen/arch/arm/include/asm/setup.h | 16 +++++++++---- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 6014c0f852..ccf281cd37 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -384,6 +384,7 @@ static int __init process_shm_node(const void *fdt, int= node, const __be32 *cell; paddr_t paddr, gaddr, size; struct meminfo *mem =3D &bootinfo.reserved_mem; + struct shm_meminfo *shm_mem =3D &bootinfo.shm_mem; unsigned int i; int len; bool owner =3D false; @@ -455,17 +456,21 @@ static int __init process_shm_node(const void *fdt, i= nt node, return -EINVAL; } =20 - for ( i =3D 0; i < mem->nr_banks; i++ ) + for ( i =3D 0; i < shm_mem->nr_banks; i++ ) { + paddr_t bank_start =3D shm_mem->bank[i].membank->start; + paddr_t bank_size =3D shm_mem->bank[i].membank->size; + /* * Meet the following check: * 1) The shm ID matches and the region exactly match * 2) The shm ID doesn't match and the region doesn't overlap * with an existing one */ - if ( paddr =3D=3D mem->bank[i].start && size =3D=3D mem->bank[i].s= ize ) + if ( paddr =3D=3D bank_start && size =3D=3D bank_size ) { - if ( strncmp(shm_id, mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) = =3D=3D 0 ) + if ( strncmp(shm_id, + shm_mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) =3D= =3D 0 ) break; else { @@ -477,17 +482,17 @@ static int __init process_shm_node(const void *fdt, i= nt node, else { paddr_t end =3D paddr + size; - paddr_t bank_end =3D mem->bank[i].start + mem->bank[i].size; + paddr_t bank_end =3D bank_start + bank_size; =20 - if ( (end <=3D paddr) || (bank_end <=3D mem->bank[i].start) ) + if ( (end <=3D paddr) || (bank_end <=3D bank_start) ) { printk("fdt: static shared memory region %s overflow\n", s= hm_id); return -EINVAL; } =20 - if ( (end <=3D mem->bank[i].start) || (paddr >=3D bank_end) ) + if ( (end <=3D bank_start) || (paddr >=3D bank_end) ) { - if ( strcmp(shm_id, mem->bank[i].shm_id) !=3D 0 ) + if ( strcmp(shm_id, shm_mem->bank[i].shm_id) !=3D 0 ) continue; else { @@ -499,22 +504,27 @@ static int __init process_shm_node(const void *fdt, i= nt node, else { printk("fdt: shared memory region overlap with an existing= entry %#"PRIpaddr" - %#"PRIpaddr"\n", - mem->bank[i].start, bank_end); + bank_start, bank_end); return -EINVAL; } } } =20 - if ( i =3D=3D mem->nr_banks ) + if ( i =3D=3D shm_mem->nr_banks ) { - if ( i < NR_MEM_BANKS ) + if ( (i < NR_MEM_BANKS) && (mem->nr_banks < NR_MEM_BANKS) ) { /* Static shared memory shall be reserved from any other use. = */ - safe_strcpy(mem->bank[mem->nr_banks].shm_id, shm_id); - mem->bank[mem->nr_banks].start =3D paddr; - mem->bank[mem->nr_banks].size =3D size; - mem->bank[mem->nr_banks].type =3D MEMBANK_STATIC_DOMAIN; + struct membank *membank =3D &mem->bank[mem->nr_banks]; + + membank->start =3D paddr; + membank->size =3D size; + membank->type =3D MEMBANK_STATIC_DOMAIN; mem->nr_banks++; + + safe_strcpy(shm_mem->bank[i].shm_id, shm_id); + shm_mem->bank[i].membank =3D membank; + shm_mem->nr_banks++; } else { @@ -527,7 +537,7 @@ static int __init process_shm_node(const void *fdt, int= node, * to calculate the reference count. */ if ( !owner ) - mem->bank[i].nr_shm_borrowers++; + shm_mem->bank[i].nr_shm_borrowers++; =20 return 0; } diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index bd30d3798c..c0fd13f6ed 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -757,20 +757,20 @@ static int __init acquire_nr_borrower_domain(struct d= omain *d, { unsigned int bank; =20 - /* Iterate reserved memory to find requested shm bank. */ - for ( bank =3D 0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) + /* 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.reserved_mem.bank[bank].start; - paddr_t bank_size =3D bootinfo.reserved_mem.bank[bank].size; + paddr_t bank_start =3D bootinfo.shm_mem.bank[bank].membank->start; + paddr_t bank_size =3D bootinfo.shm_mem.bank[bank].membank->size; =20 if ( (pbase =3D=3D bank_start) && (psize =3D=3D bank_size) ) break; } =20 - if ( bank =3D=3D bootinfo.reserved_mem.nr_banks ) + if ( bank =3D=3D bootinfo.shm_mem.nr_banks ) return -ENOENT; =20 - *nr_borrowers =3D bootinfo.reserved_mem.bank[bank].nr_shm_borrowers; + *nr_borrowers =3D bootinfo.shm_mem.bank[bank].nr_shm_borrowers; =20 return 0; } @@ -907,11 +907,18 @@ static int __init append_shm_bank_to_domain(struct ke= rnel_info *kinfo, paddr_t start, paddr_t size, const char *shm_id) { + struct membank *membank; + if ( kinfo->shm_mem.nr_banks >=3D NR_MEM_BANKS ) return -ENOMEM; =20 - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].start =3D start; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].size =3D size; + membank =3D xmalloc_bytes(sizeof(struct membank)); + if ( membank =3D=3D NULL ) + return -ENOMEM; + + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].membank =3D membank; + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].membank->start =3D start; + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].membank->size =3D size; safe_strcpy(kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].shm_id, shm_i= d); kinfo->shm_mem.nr_banks++; =20 @@ -1355,7 +1362,7 @@ static int __init make_memory_node(const struct domai= n *d, static int __init make_shm_memory_node(const struct domain *d, void *fdt, int addrcells, int sizecells, - const struct meminfo *mem) + const struct shm_meminfo *mem) { unsigned int i =3D 0; int res =3D 0; @@ -1372,8 +1379,8 @@ static int __init make_shm_memory_node(const struct d= omain *d, =20 for ( ; i < mem->nr_banks; i++ ) { - uint64_t start =3D mem->bank[i].start; - uint64_t size =3D mem->bank[i].size; + uint64_t start =3D mem->bank[i].membank->start; + uint64_t size =3D mem->bank[i].membank->size; /* Placeholder for xen-shmem@ + a 64-bit number + \0 */ char buf[27]; const char compat[] =3D "xen,shared-memory-v1"; @@ -1382,7 +1389,7 @@ static int __init make_shm_memory_node(const struct d= omain *d, __be32 *cells; unsigned int len =3D (addrcells + sizecells) * sizeof(__be32); =20 - snprintf(buf, sizeof(buf), "xen-shmem@%"PRIx64, mem->bank[i].start= ); + snprintf(buf, sizeof(buf), "xen-shmem@%"PRIx64, start); res =3D fdt_begin_node(fdt, buf); if ( res ) return res; @@ -1426,7 +1433,7 @@ static int __init make_shm_memory_node(const struct d= omain *d, static int __init make_shm_memory_node(const struct domain *d, void *fdt, int addrcells, int sizecells, - const struct meminfo *mem) + const struct shm_meminfo *mem) { ASSERT_UNREACHABLE(); return -EOPNOTSUPP; @@ -1436,7 +1443,7 @@ static int __init make_shm_memory_node(const struct d= omain *d, static int __init make_resv_memory_node(const struct domain *d, void *fdt, int addrcells, int sizecells, - const struct meminfo *mem) + const struct shm_meminfo *mem) { int res =3D 0; /* Placeholder for reserved-memory\0 */ diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index 5bb30c3f2f..f47ba9d619 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -38,7 +38,7 @@ struct kernel_info { void *fdt; /* flat device tree */ paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */ struct meminfo mem; - struct meminfo shm_mem; + struct shm_meminfo shm_mem; =20 /* kernel entry point */ paddr_t entry; diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index fdbf68aadc..2d4ae0f00a 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -50,10 +50,6 @@ struct membank { paddr_t start; paddr_t size; enum membank_type type; -#ifdef CONFIG_STATIC_SHM - char shm_id[MAX_SHM_ID_LENGTH]; - unsigned int nr_shm_borrowers; -#endif }; =20 struct meminfo { @@ -61,6 +57,17 @@ struct meminfo { struct membank bank[NR_MEM_BANKS]; }; =20 +struct shm_membank { + char shm_id[MAX_SHM_ID_LENGTH]; + unsigned int nr_shm_borrowers; + struct membank *membank; +}; + +struct shm_meminfo { + unsigned int nr_banks; + struct shm_membank bank[NR_MEM_BANKS]; +}; + /* * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. * The purpose of the domU flag is to avoid getting confused in @@ -105,6 +112,7 @@ struct bootinfo { struct meminfo acpi; #endif bool static_heap; + struct shm_meminfo shm_mem; }; =20 struct map_range_data --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 From nobody Fri Apr 26 10:20:53 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 1668480809435649.841622258262; Mon, 14 Nov 2022 18:53:29 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443637.698327 (Exim 4.92) (envelope-from ) id 1oum4M-0000se-Rs; Tue, 15 Nov 2022 02:53:02 +0000 Received: by outflank-mailman (output) from mailman id 443637.698327; Tue, 15 Nov 2022 02:53:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4M-0000sV-Oi; Tue, 15 Nov 2022 02:53:02 +0000 Received: by outflank-mailman (input) for mailman id 443637; Tue, 15 Nov 2022 02:53:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4L-0000BJ-F9 for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:01 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 9da6ccbd-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:53:00 +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 0F65211FB; Mon, 14 Nov 2022 18:53:06 -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 2E60E3F73B; Mon, 14 Nov 2022 18:52:56 -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: 9da6ccbd-6490-11ed-91b6-6bf2151ebd3b 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 03/13] xen/arm: introduce allocate_domheap_memory and guest_physmap_memory Date: Tue, 15 Nov 2022 10:52:25 +0800 Message-Id: <20221115025235.1378931-4-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: 1668480810858100001 Content-Type: text/plain; charset="utf-8" We split the codes of allocate_bank_memory into two parts, allocate_domheap_memory and guest_physmap_memory. One is about allocating guest RAM from heap, which could be re-used later f= or allocating static shared memory from heap when host address is not provided. The other is building up guest P2M mapping. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 93 +++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d2b9e60b5c..92763e96fc 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -390,34 +390,18 @@ static void __init allocate_memory_11(struct domain *= d, } } =20 -static bool __init allocate_bank_memory(struct domain *d, - struct kernel_info *kinfo, - gfn_t sgfn, - paddr_t tot_size) +static bool __init allocate_domheap_memory(struct domain *d, + paddr_t tot_size, + struct meminfo *mem) { - int res; struct page_info *pg; - struct membank *bank; unsigned int max_order =3D ~0; =20 - /* - * allocate_bank_memory can be called with a tot_size of zero for - * the second memory bank. It is not an error and we can safely - * avoid creating a zero-size memory bank. - */ - if ( tot_size =3D=3D 0 ) - return true; - - bank =3D &kinfo->mem.bank[kinfo->mem.nr_banks]; - bank->start =3D gfn_to_gaddr(sgfn); - bank->size =3D tot_size; - while ( tot_size > 0 ) { unsigned int order =3D get_allocation_size(tot_size); =20 order =3D min(max_order, order); - pg =3D alloc_domheap_pages(d, order, 0); if ( !pg ) { @@ -437,15 +421,74 @@ static bool __init allocate_bank_memory(struct domain= *d, continue; } =20 - res =3D guest_physmap_add_page(d, sgfn, page_to_mfn(pg), order); - if ( res ) - { - dprintk(XENLOG_ERR, "Failed map pages to DOMU: %d", res); + if ( mem->nr_banks =3D=3D NR_MEM_BANKS ) return false; - } + + mem->bank[mem->nr_banks].start =3D mfn_to_maddr(page_to_mfn(pg)); + mem->bank[mem->nr_banks].size =3D 1UL << (PAGE_SHIFT + order); + mem->nr_banks++; + tot_size -=3D (1UL << (PAGE_SHIFT + order)); + } + + return true; +} + +static int __init guest_physmap_memory(struct domain *d, + const struct meminfo *mem, gfn_t sg= fn) +{ + unsigned int i; + int res; + + for ( i =3D 0; i < mem->nr_banks; i++ ) + { + paddr_t size =3D mem->bank[i].size; + unsigned int order =3D get_order_from_bytes(size); + + /* Size must be power of two */ + BUG_ON(!size || (size & (size - 1))); + res =3D guest_physmap_add_page(d, sgfn, maddr_to_mfn(mem->bank[i].= start), + order); + if ( res ) + return res; =20 sgfn =3D gfn_add(sgfn, 1UL << order); - tot_size -=3D (1ULL << (PAGE_SHIFT + order)); + } + + return 0; +} + +static bool __init allocate_bank_memory(struct domain *d, + struct kernel_info *kinfo, + gfn_t sgfn, + paddr_t total_size) +{ + struct membank *bank; + struct meminfo host =3D {0}; + + /* + * allocate_bank_memory can be called with a total_size of zero for + * the second memory bank. It is not an error and we can safely + * avoid creating a zero-size memory bank. + */ + if ( total_size =3D=3D 0 ) + return true; + + bank =3D &kinfo->mem.bank[kinfo->mem.nr_banks]; + bank->start =3D gfn_to_gaddr(sgfn); + bank->size =3D total_size; + + if ( !allocate_domheap_memory(d, total_size, &host) ) + { + printk(XENLOG_ERR "Failed to allocate (%"PRIpaddr"MB) pages to %pd= \n", + total_size >> 20, d); + return false; + } + + if ( guest_physmap_memory(d, &host, sgfn) ) + { + printk(XENLOG_ERR "Failed to map (%"PRIpaddr"MB) pages to %pd\n", + total_size >> 20, d); + return false; } =20 kinfo->mem.nr_banks++; --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668480810299522.3838831857594; Mon, 14 Nov 2022 18:53:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443638.698339 (Exim 4.92) (envelope-from ) id 1oum4Q-0001CE-3q; Tue, 15 Nov 2022 02:53:06 +0000 Received: by outflank-mailman (output) from mailman id 443638.698339; Tue, 15 Nov 2022 02:53:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4Q-0001C3-0W; Tue, 15 Nov 2022 02:53:06 +0000 Received: by outflank-mailman (input) for mailman id 443638; Tue, 15 Nov 2022 02:53:04 +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 1oum4O-0008Vs-GT for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:04 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 9f775f60-6490-11ed-8fd2-01056ac49cbb; Tue, 15 Nov 2022 03:53:03 +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 2473F11FB; Mon, 14 Nov 2022 18:53:09 -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 460DE3F73B; Mon, 14 Nov 2022 18:53:00 -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: 9f775f60-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 04/13] xen/arm: expand shm_membank for unprovided host address Date: Tue, 15 Nov 2022 10:52:26 +0800 Message-Id: <20221115025235.1378931-5-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: 1668480812440100007 Content-Type: text/plain; charset="utf-8" When host address is not provided in "xen,shared-mem", we let Xen automatically allocate requested static shared memory from heap, and it stands good chance of having multiple host memory banks allocated for the requested static shared memory as a result. Therefore current membank is not going to cover it. This commit introduces a new field "mem" to cover both scenarios. "struct membank" is used when host address is provided, whereas "struct meminfo" shall be used when host address not provided. Signed-off-by: Penny Zheng --- xen/arch/arm/bootfdt.c | 6 +++--- xen/arch/arm/domain_build.c | 16 ++++++++-------- xen/arch/arm/include/asm/setup.h | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index ccf281cd37..2f34a8ea83 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -458,8 +458,8 @@ static int __init process_shm_node(const void *fdt, int= node, =20 for ( i =3D 0; i < shm_mem->nr_banks; i++ ) { - paddr_t bank_start =3D shm_mem->bank[i].membank->start; - paddr_t bank_size =3D shm_mem->bank[i].membank->size; + paddr_t bank_start =3D shm_mem->bank[i].mem.bank->start; + paddr_t bank_size =3D shm_mem->bank[i].mem.bank->size; =20 /* * Meet the following check: @@ -523,7 +523,7 @@ static int __init process_shm_node(const void *fdt, int= node, mem->nr_banks++; =20 safe_strcpy(shm_mem->bank[i].shm_id, shm_id); - shm_mem->bank[i].membank =3D membank; + shm_mem->bank[i].mem.bank =3D membank; shm_mem->nr_banks++; } else diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 92763e96fc..fbb196d8a4 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -818,7 +818,7 @@ static bool __init is_shm_allocated_to_domio(struct shm= _membank *shm_membank) struct page_info *page; struct domain *d; =20 - page =3D maddr_to_page(shm_membank->membank->start); + page =3D maddr_to_page(shm_membank->mem.bank->start); d =3D page_get_owner_and_reference(page); if ( d =3D=3D NULL ) return false; @@ -878,8 +878,8 @@ static int __init assign_shared_memory(struct domain *d, struct page_info *page; paddr_t pbase, psize; =20 - pbase =3D shm_membank->membank->start; - psize =3D shm_membank->membank->size; + pbase =3D shm_membank->mem.bank->start; + psize =3D shm_membank->mem.bank->size; =20 printk("%pd: allocate static shared memory BANK %#"PRIpaddr"-%#"PRIpad= dr".\n", d, pbase, pbase + psize); @@ -951,9 +951,9 @@ static int __init append_shm_bank_to_domain(struct kern= el_info *kinfo, if ( membank =3D=3D NULL ) return -ENOMEM; =20 - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].membank =3D membank; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].membank->start =3D start; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].membank->size =3D size; + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank =3D membank; + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->start =3D start; + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->size =3D size; safe_strcpy(kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].shm_id, shm_i= d); kinfo->shm_mem.nr_banks++; =20 @@ -1422,8 +1422,8 @@ static int __init make_shm_memory_node(const struct d= omain *d, =20 for ( ; i < mem->nr_banks; i++ ) { - uint64_t start =3D mem->bank[i].membank->start; - uint64_t size =3D mem->bank[i].membank->size; + uint64_t start =3D mem->bank[i].mem.bank->start; + uint64_t size =3D mem->bank[i].mem.bank->size; /* Placeholder for xen-shmem@ + a 64-bit number + \0 */ char buf[27]; const char compat[] =3D "xen,shared-memory-v1"; diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 2d4ae0f00a..c54ffc8a5b 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -60,7 +60,22 @@ struct meminfo { struct shm_membank { char shm_id[MAX_SHM_ID_LENGTH]; unsigned int nr_shm_borrowers; - struct membank *membank; + struct { + /* + * When host address is provided in "xen,shared-mem", then only one + * consistent host memory bank is behind each shared memory node. + */ + struct membank *bank; + struct { + /* + * When host address is not provided in "xen,shared-mem", then + * we let Xen allocate requested memory from heap, and a shared + * memory bank could be consisted of multiple host memory bank= s. + */ + struct meminfo *meminfo; + unsigned long total_size; + } banks; + } mem; }; =20 struct shm_meminfo { --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668480810351529.431088209718; Mon, 14 Nov 2022 18:53:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443639.698350 (Exim 4.92) (envelope-from ) id 1oum4S-0001WB-FT; Tue, 15 Nov 2022 02:53:08 +0000 Received: by outflank-mailman (output) from mailman id 443639.698350; Tue, 15 Nov 2022 02:53:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4S-0001Vm-B3; Tue, 15 Nov 2022 02:53:08 +0000 Received: by outflank-mailman (input) for mailman id 443639; Tue, 15 Nov 2022 02:53:07 +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 1oum4R-0008Vs-Mu for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:07 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a15477b6-6490-11ed-8fd2-01056ac49cbb; Tue, 15 Nov 2022 03:53:06 +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 3B75611FB; Mon, 14 Nov 2022 18:53:12 -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 5DBA03F73B; Mon, 14 Nov 2022 18:53:03 -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: a15477b6-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 05/13] xen/arm: allocate shared memory from heap when host address not provided Date: Tue, 15 Nov 2022 10:52:27 +0800 Message-Id: <20221115025235.1378931-6-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: 1668480812431100006 Content-Type: text/plain; charset="utf-8" when host address is not provided in "xen,shared-mem", we let Xen allocate requested shared memory from heap, and once the shared memory is allocated, it will be marked as static(PGC_static), which means that it wil= l be reserved as static memory, and will not go back to heap even on freeing. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 83 ++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index fbb196d8a4..3de96882a5 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -835,6 +835,72 @@ static bool __init is_shm_allocated_to_domio(struct sh= m_membank *shm_membank) return true; } =20 +static int __init mark_shared_memory_static(struct shm_membank *shm_memban= k) +{ + unsigned int bank; + unsigned long i, nr_mfns; + struct page_info *pg; + struct meminfo *meminfo; + + BUG_ON(!shm_membank->mem.banks.meminfo); + meminfo =3D shm_membank->mem.banks.meminfo; + for ( bank =3D 0; bank < meminfo->nr_banks; bank++ ) + { + pg =3D mfn_to_page(maddr_to_mfn(meminfo->bank[bank].start)); + nr_mfns =3D PFN_DOWN(meminfo->bank[bank].size); + + for ( i =3D 0; i < nr_mfns; i++ ) + { + /* The page should be already allocated from heap. */ + if ( !pg[i].count_info & PGC_state_inuse ) + { + printk(XENLOG_ERR + "pg[%lu] MFN %"PRI_mfn" c=3D%#lx\n", + i, mfn_x(page_to_mfn(pg)) + i, pg[i].count_info); + goto fail; + } + + pg[i].count_info |=3D PGC_static; + } + } + + return 0; + + fail: + while ( bank >=3D 0 ) + { + while ( --i >=3D 0 ) + pg[i].count_info &=3D ~PGC_static; + i =3D PFN_DOWN(meminfo->bank[--bank].size); + } + + return -EINVAL; +} + +static int __init allocate_shared_memory(struct shm_membank *shm_membank, + paddr_t psize) +{ + struct meminfo *banks; + int ret; + + BUG_ON(shm_membank->mem.banks.meminfo !=3D NULL); + + banks =3D xmalloc_bytes(sizeof(struct meminfo)); + if ( banks =3D=3D NULL ) + return -ENOMEM; + shm_membank->mem.banks.meminfo =3D banks; + memset(shm_membank->mem.banks.meminfo, 0, sizeof(struct meminfo)); + + if ( !allocate_domheap_memory(NULL, psize, shm_membank->mem.banks.memi= nfo) ) + return -EINVAL; + + ret =3D mark_shared_memory_static(shm_membank); + if ( ret ) + return ret; + + return 0; +} + static mfn_t __init acquire_shared_memory_bank(struct domain *d, paddr_t pbase, paddr_t psiz= e) { @@ -975,7 +1041,7 @@ static int __init process_shm(struct domain *d, struct= kernel_info *kinfo, unsigned int i; const char *role_str; const char *shm_id; - bool owner_dom_io =3D true; + bool owner_dom_io =3D true, paddr_assigned =3D true; struct shm_membank *shm_membank; =20 if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-= v1") ) @@ -1035,6 +1101,21 @@ static int __init process_shm(struct domain *d, stru= ct kernel_info *kinfo, return -ENOENT; } =20 + /* + * When host address is not provided in "xen,shared-mem", + * we let Xen allocate requested memory from heap at first domain. + */ + if ( !paddr_assigned && !shm_membank->mem.banks.meminfo ) + { + ret =3D allocate_shared_memory(shm_membank, psize); + if ( ret ) + { + printk("%pd: failed to allocate shared memory bank(%"PRIpa= ddr"MB) from heap: %d\n", + d, psize >> 20, ret); + return ret; + } + } + /* * 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 --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668480812236151.51254479693307; Mon, 14 Nov 2022 18:53:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443640.698361 (Exim 4.92) (envelope-from ) id 1oum4V-0001tq-OQ; Tue, 15 Nov 2022 02:53:11 +0000 Received: by outflank-mailman (output) from mailman id 443640.698361; Tue, 15 Nov 2022 02:53:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4V-0001te-Kp; Tue, 15 Nov 2022 02:53:11 +0000 Received: by outflank-mailman (input) for mailman id 443640; Tue, 15 Nov 2022 02:53:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4U-0000BJ-PQ for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:10 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id a323f596-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:53:09 +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 5309D11FB; Mon, 14 Nov 2022 18:53:15 -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 74C063F73B; Mon, 14 Nov 2022 18:53:06 -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: a323f596-6490-11ed-91b6-6bf2151ebd3b 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 06/13] xen/arm: assign shared memory to owner when host address not provided Date: Tue, 15 Nov 2022 10:52:28 +0800 Message-Id: <20221115025235.1378931-7-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: 1668480814264100013 Content-Type: text/plain; charset="utf-8" With the introduction of new scenario where host address is not provided in "xen,shared-mem", the function "assign_shared_memory" shall be adapted to it too. Shared memory will already be allocated from heap, when calling "assign_shared_memory" with unprovided host address. So in "assign_shared_memory", we just need to assign these static shared pa= ges to its owner domain using function "assign_pages", and add as many additional reference as the number of borrowers. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 160 ++++++++++++++++++++++++++++++------ 1 file changed, 133 insertions(+), 27 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 3de96882a5..faf0784bb0 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -817,8 +817,12 @@ static bool __init is_shm_allocated_to_domio(struct sh= m_membank *shm_membank) { struct page_info *page; struct domain *d; + paddr_t pbase; =20 - page =3D maddr_to_page(shm_membank->mem.bank->start); + pbase =3D shm_membank->mem.banks.meminfo ? + shm_membank->mem.banks.meminfo->bank[0].start : + shm_membank->mem.bank->start; + page =3D maddr_to_page(pbase); d =3D page_get_owner_and_reference(page); if ( d =3D=3D NULL ) return false; @@ -907,6 +911,7 @@ static mfn_t __init acquire_shared_memory_bank(struct d= omain *d, mfn_t smfn; unsigned long nr_pfns; int res; + struct page_info *page; =20 /* * Pages of statically shared memory shall be included @@ -922,33 +927,82 @@ static mfn_t __init acquire_shared_memory_bank(struct= domain *d, d->max_pages +=3D nr_pfns; =20 smfn =3D maddr_to_mfn(pbase); - res =3D acquire_domstatic_pages(d, smfn, nr_pfns, 0); - if ( res ) + page =3D mfn_to_page(smfn); + /* + * If page is allocated from heap as static shared memory, then we just + * assign it to the owner domain + */ + if ( page->count_info =3D=3D (PGC_state_inuse | PGC_static) ) { - printk(XENLOG_ERR - "%pd: failed to acquire static memory: %d.\n", d, res); - d->max_pages -=3D nr_pfns; - return INVALID_MFN; + res =3D assign_pages(page, nr_pfns, d, 0); + if ( res ) + { + printk(XENLOG_ERR + "%pd: failed to assign static memory: %d.\n", d, res); + return INVALID_MFN; + } + } + else + { + res =3D acquire_domstatic_pages(d, smfn, nr_pfns, 0); + if ( res ) + { + printk(XENLOG_ERR + "%pd: failed to acquire static memory: %d.\n", d, res); + d->max_pages -=3D nr_pfns; + return INVALID_MFN; + } } =20 return smfn; } =20 -static int __init assign_shared_memory(struct domain *d, - struct shm_membank *shm_membank, - paddr_t gbase) +static void __init remove_shared_memory_ref(struct page_info *page, + unsigned long nr_pages, + unsigned long nr_borrowers) { - mfn_t smfn; - int ret =3D 0; - unsigned long nr_pages, nr_borrowers, i; - struct page_info *page; - paddr_t pbase, psize; + while ( --nr_pages >=3D 0 ) + put_page_nr(page + nr_pages, nr_borrowers); +} =20 - pbase =3D shm_membank->mem.bank->start; - psize =3D shm_membank->mem.bank->size; +static int __init add_shared_memory_ref(struct domain *d, struct page_info= *page, + unsigned long nr_pages, + unsigned long nr_borrowers) +{ + unsigned int i; =20 - printk("%pd: allocate static shared memory BANK %#"PRIpaddr"-%#"PRIpad= dr".\n", - d, pbase, pbase + psize); + /* + * Instead of letting borrower domain get a page ref, we add as many + * additional reference as the number of borrowers when the owner + * is allocated, since there is a chance that owner is created + * after borrower. + * So if the borrower is created first, it will cause adding pages + * in the P2M without reference. + */ + for ( i =3D 0; i < nr_pages; i++ ) + { + if ( !get_page_nr(page + i, d, nr_borrowers) ) + { + printk(XENLOG_ERR + "Failed to add %lu references to page %"PRI_mfn".\n", + nr_borrowers, mfn_x(page_to_mfn(page)) + i); + goto fail; + } + } + return 0; + + fail: + remove_shared_memory_ref(page, i, nr_borrowers); + return -EINVAL; +} + +static int __init acquire_shared_memory(struct domain *d, + paddr_t pbase, paddr_t psize, + paddr_t gbase) +{ + mfn_t smfn; + int ret =3D 0; + unsigned long nr_pages; =20 smfn =3D acquire_shared_memory_bank(d, pbase, psize); if ( mfn_eq(smfn, INVALID_MFN) ) @@ -970,6 +1024,44 @@ static int __init assign_shared_memory(struct domain = *d, } } =20 + return 0; +} + +static int __init assign_shared_memory(struct domain *d, + struct shm_membank *shm_membank, + paddr_t gbase) +{ + int ret =3D 0; + unsigned long nr_pages, nr_borrowers; + struct page_info *page; + unsigned int i; + struct meminfo *meminfo; + + /* Host address is not provided in "xen,shared-mem" */ + if ( shm_membank->mem.banks.meminfo ) + { + meminfo =3D shm_membank->mem.banks.meminfo; + for ( i =3D 0; i < meminfo->nr_banks; i++ ) + { + ret =3D acquire_shared_memory(d, + meminfo->bank[i].start, + meminfo->bank[i].size, + gbase); + if ( ret ) + return ret; + + gbase +=3D meminfo->bank[i].size; + } + } + else + { + ret =3D acquire_shared_memory(d, + shm_membank->mem.bank->start, + shm_membank->mem.bank->size, gbase); + if ( ret ) + return ret; + } + /* * Get the right amount of references per page, which is the number of * borrower domains. @@ -984,23 +1076,37 @@ static int __init assign_shared_memory(struct domain= *d, * So if the borrower is created first, it will cause adding pages * in the P2M without reference. */ - page =3D mfn_to_page(smfn); - for ( i =3D 0; i < nr_pages; i++ ) + if ( shm_membank->mem.banks.meminfo ) { - if ( !get_page_nr(page + i, d, nr_borrowers) ) + meminfo =3D shm_membank->mem.banks.meminfo; + for ( i =3D 0; i < meminfo->nr_banks; i++ ) { - printk(XENLOG_ERR - "Failed to add %lu references to page %"PRI_mfn".\n", - nr_borrowers, mfn_x(smfn) + i); - goto fail; + page =3D mfn_to_page(maddr_to_mfn(meminfo->bank[i].start)); + nr_pages =3D PFN_DOWN(meminfo->bank[i].size); + ret =3D add_shared_memory_ref(d, page, nr_pages, nr_borrowers); + if ( ret ) + goto fail; } } + else + { + page =3D mfn_to_page( + maddr_to_mfn(shm_membank->mem.bank->start)); + nr_pages =3D shm_membank->mem.bank->size >> PAGE_SHIFT; + ret =3D add_shared_memory_ref(d, page, nr_pages, nr_borrowers); + if ( ret ) + return ret; + } =20 return 0; =20 fail: while ( --i >=3D 0 ) - put_page_nr(page + i, nr_borrowers); + { + page =3D mfn_to_page(maddr_to_mfn(meminfo->bank[i].start)); + nr_pages =3D PFN_DOWN(meminfo->bank[i].size); + remove_shared_memory_ref(page, nr_pages, nr_borrowers); + } return ret; } =20 --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668480815147465.622664052035; Mon, 14 Nov 2022 18:53:35 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443642.698372 (Exim 4.92) (envelope-from ) id 1oum4Z-0002Q4-9I; Tue, 15 Nov 2022 02:53:15 +0000 Received: by outflank-mailman (output) from mailman id 443642.698372; Tue, 15 Nov 2022 02:53:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4Z-0002Pl-4T; Tue, 15 Nov 2022 02:53:15 +0000 Received: by outflank-mailman (input) for mailman id 443642; Tue, 15 Nov 2022 02:53:13 +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 1oum4X-0008Vs-QU for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:13 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a509e63a-6490-11ed-8fd2-01056ac49cbb; Tue, 15 Nov 2022 03:53:12 +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 69FF711FB; Mon, 14 Nov 2022 18:53:18 -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 8C2373F73B; Mon, 14 Nov 2022 18:53:09 -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: a509e63a-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 07/13] xen/arm: map shared memory to borrower when host address not provided Date: Tue, 15 Nov 2022 10:52:29 +0800 Message-Id: <20221115025235.1378931-8-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: 1668480816226100015 Content-Type: text/plain; charset="utf-8" With the introduction of new scenario where host address is not provided in "xen,shared-mem", the function "map_regions_p2mt" for setting up P2M foreign mapping for borrower domain shall be adapted to it too. Here we implement a new helper "borrower_physmap_add_memory" to cover both scenarios. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 54 ++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index faf0784bb0..d0f7fc8fd7 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1110,6 +1110,51 @@ static int __init assign_shared_memory(struct domain= *d, return ret; } =20 +static int __init borrower_physmap_add_memory(struct domain *d, + struct shm_membank *shm_memb= ank, + paddr_t gbase) +{ + int ret; + unsigned int i; + paddr_t start, size; + gfn_t sgfn; + struct meminfo *meminfo; + + /* Host address is not provided in "xen,shared-mem" */ + if ( shm_membank->mem.banks.meminfo ) + { + meminfo =3D shm_membank->mem.banks.meminfo; + for ( i =3D 0; i < meminfo->nr_banks; i++ ) + { + start =3D meminfo->bank[i].start; + size =3D meminfo->bank[i].size; + sgfn =3D _gfn(PFN_UP(gbase)); + + /* Set up P2M foreign mapping for borrower domain. */ + ret =3D map_regions_p2mt(d, sgfn, PFN_DOWN(size), _mfn(PFN_UP(= start)), + p2m_map_foreign_rw); + if ( ret ) + return ret; + + sgfn =3D gfn_add(sgfn, PFN_DOWN(size)); + } + } + else + { + start =3D shm_membank->mem.bank->start; + size =3D shm_membank->mem.bank->size; + sgfn =3D _gfn(PFN_UP(gbase)); + + /* Set up P2M foreign mapping for borrower domain. */ + ret =3D map_regions_p2mt(d, sgfn, PFN_DOWN(size), _mfn(PFN_UP(star= t)), + p2m_map_foreign_rw); + if ( ret ) + return ret; + } + + return 0; +} + static int __init append_shm_bank_to_domain(struct kernel_info *kinfo, paddr_t start, paddr_t size, const char *shm_id) @@ -1242,11 +1287,14 @@ static int __init process_shm(struct domain *d, str= uct kernel_info *kinfo, =20 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= ); + ret =3D borrower_physmap_add_memory(d, shm_membank, gbase); if ( ret ) + { + printk(XENLOG_ERR + "%pd: Failed to map foreign memory to borrower doma= in: %d", + d, ret); return ret; + } } =20 /* --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668480818987522.3851200244312; Mon, 14 Nov 2022 18:53:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443646.698383 (Exim 4.92) (envelope-from ) id 1oum4c-000336-Mq; Tue, 15 Nov 2022 02:53:18 +0000 Received: by outflank-mailman (output) from mailman id 443646.698383; Tue, 15 Nov 2022 02:53:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4c-000324-IE; Tue, 15 Nov 2022 02:53:18 +0000 Received: by outflank-mailman (input) for mailman id 443646; Tue, 15 Nov 2022 02:53:17 +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 1oum4b-0008Vs-5K for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:17 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a6e108b4-6490-11ed-8fd2-01056ac49cbb; Tue, 15 Nov 2022 03:53:15 +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 81CFD13D5; Mon, 14 Nov 2022 18:53:21 -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 A383D3F73B; Mon, 14 Nov 2022 18:53:12 -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: a6e108b4-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 08/13] xen/arm: use paddr_assigned to indicate whether host address is provided Date: Tue, 15 Nov 2022 10:52:30 +0800 Message-Id: <20221115025235.1378931-9-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: 1668480820548100001 Content-Type: text/plain; charset="utf-8" We use paddr_assigned to indicate whether host address is provided, by checking the length of "xen,shared-mem" property. And the shm matching criteria shall also be adapt to the new scenario, by adding when host address is not provided, if SHMID matches, the region size must exactly match too. Also, to make codes tidy and clear, we extract codes about parsing "xen,shared-mem" property from function "process_shm" and move them into a new helper "parse_shm_property". Signed-off-by: Penny Zheng --- xen/arch/arm/bootfdt.c | 87 +++++++++++++++++++-------- xen/arch/arm/domain_build.c | 114 +++++++++++++++++++++++++----------- 2 files changed, 141 insertions(+), 60 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 2f34a8ea83..efaf49fd56 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -387,7 +387,7 @@ static int __init process_shm_node(const void *fdt, int= node, struct shm_meminfo *shm_mem =3D &bootinfo.shm_mem; unsigned int i; int len; - bool owner =3D false; + bool owner =3D false, paddr_assigned =3D true; const char *shm_id; =20 if ( address_cells < 1 || size_cells < 1 ) @@ -428,7 +428,7 @@ static int __init process_shm_node(const void *fdt, int= node, } =20 /* - * xen,shared-mem =3D ; + * xen,shared-mem =3D , and paddr could be optional * Memory region starting from physical address #paddr of #size shall * be mapped to guest physical address #gaddr as static shared memory * region. @@ -439,16 +439,24 @@ static int __init process_shm_node(const void *fdt, i= nt node, =20 if ( len !=3D dt_cells_to_size(address_cells + size_cells + address_ce= lls) ) { + /* paddr is not provided in "xen,shared-mem" */ if ( len =3D=3D dt_cells_to_size(size_cells + address_cells) ) - printk("fdt: host physical address must be chosen by users at = the moment.\n"); - - printk("fdt: invalid `xen,shared-mem` property.\n"); - return -EINVAL; + paddr_assigned =3D false; + else + { + printk("fdt: invalid `xen,shared-mem` property.\n"); + return -EINVAL; + } } =20 cell =3D (const __be32 *)prop->data; - device_tree_get_reg(&cell, address_cells, address_cells, &paddr, &gadd= r); - size =3D dt_next_cell(size_cells, &cell); + if ( !paddr_assigned ) + device_tree_get_reg(&cell, address_cells, size_cells, &gaddr, &siz= e); + else + { + device_tree_get_reg(&cell, address_cells, address_cells, &paddr, &= gaddr); + size =3D dt_next_cell(size_cells, &cell); + } =20 if ( !size ) { @@ -458,29 +466,45 @@ static int __init process_shm_node(const void *fdt, i= nt node, =20 for ( i =3D 0; i < shm_mem->nr_banks; i++ ) { - paddr_t bank_start =3D shm_mem->bank[i].mem.bank->start; - paddr_t bank_size =3D shm_mem->bank[i].mem.bank->size; - /* * Meet the following check: + * when host address is provided: * 1) The shm ID matches and the region exactly match * 2) The shm ID doesn't match and the region doesn't overlap * with an existing one + * when host address is not provided: + * 1) The shm ID matches and the region size exactly match */ - if ( paddr =3D=3D bank_start && size =3D=3D bank_size ) + if ( !paddr_assigned || (paddr =3D=3D shm_mem->bank[i].mem.bank->s= tart && + size =3D=3D shm_mem->bank[i].mem.bank->si= ze) ) { if ( strncmp(shm_id, shm_mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) =3D= =3D 0 ) + { + if ( !paddr_assigned && + (size !=3D shm_mem->bank[i].mem.banks.total_size) ) + { + printk("fdt: when host address is not provided, if xen= ,shm-id %s matches, size must stay the same too.\n", + shm_id); + return -EINVAL; + } + break; - else + } + else if ( paddr_assigned ) { printk("fdt: xen,shm-id %s does not match for all the node= s using the same region.\n", shm_id); return -EINVAL; } + + /* host address is not provided, and with different SHMID. */ + continue; } else { + paddr_t bank_start =3D shm_mem->bank[i].mem.bank->start; + paddr_t bank_size =3D shm_mem->bank[i].mem.bank->size; paddr_t end =3D paddr + size; paddr_t bank_end =3D bank_start + bank_size; =20 @@ -512,26 +536,35 @@ static int __init process_shm_node(const void *fdt, i= nt node, =20 if ( i =3D=3D shm_mem->nr_banks ) { - if ( (i < NR_MEM_BANKS) && (mem->nr_banks < NR_MEM_BANKS) ) + if ( i < NR_MEM_BANKS ) { - /* Static shared memory shall be reserved from any other use. = */ - struct membank *membank =3D &mem->bank[mem->nr_banks]; + if ( !paddr_assigned ) + { + shm_mem->bank[i].mem.banks.total_size =3D size; + goto out; + } + else if ( mem->nr_banks < NR_MEM_BANKS ) + { + /* Static shared memory shall be reserved from any other u= se. */ + struct membank *membank =3D &mem->bank[mem->nr_banks]; =20 - membank->start =3D paddr; - membank->size =3D size; - membank->type =3D MEMBANK_STATIC_DOMAIN; - mem->nr_banks++; + membank->start =3D paddr; + membank->size =3D size; + membank->type =3D MEMBANK_STATIC_DOMAIN; + mem->nr_banks++; =20 + shm_mem->bank[i].mem.bank =3D membank; + } + else + goto fail; + out: safe_strcpy(shm_mem->bank[i].shm_id, shm_id); - shm_mem->bank[i].mem.bank =3D membank; shm_mem->nr_banks++; } else - { - printk("Warning: Max number of supported memory regions reache= d.\n"); - return -ENOSPC; - } + goto fail; } + /* * keep a count of the number of borrowers, which later may be used * to calculate the reference count. @@ -540,6 +573,10 @@ static int __init process_shm_node(const void *fdt, in= t node, shm_mem->bank[i].nr_shm_borrowers++; =20 return 0; + + fail: + printk("Warning: Max number of supported memory regions reached.\n"); + return -ENOSPC; } #else static int __init process_shm_node(const void *fdt, int node, diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d0f7fc8fd7..80d37245a8 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1177,6 +1177,81 @@ static int __init append_shm_bank_to_domain(struct k= ernel_info *kinfo, return 0; } =20 +static int __init parse_shm_property(struct domain *d, + const struct dt_device_node *shm_node, + bool *paddr_assigned, paddr_t *pbase, + paddr_t *gbase, paddr_t *psize) +{ + const struct dt_property *prop; + const __be32 *cells; + uint32_t len; + unsigned int i; + uint32_t addr_cells, size_cells; + + addr_cells =3D dt_n_addr_cells(shm_node); + size_cells =3D dt_n_size_cells(shm_node); + + /* xen,shared-mem =3D ; And pbase could be optiona= l. */ + prop =3D dt_find_property(shm_node, "xen,shared-mem", &len); + BUG_ON(!prop); + cells =3D (const __be32 *)prop->value; + + if ( len !=3D dt_cells_to_size(addr_cells + size_cells + addr_cells) ) + { + /* pbase is not provided in "xen,shared-mem" */ + if ( len =3D=3D dt_cells_to_size(size_cells + addr_cells) ) + *paddr_assigned =3D false; + else + { + printk("fdt: invalid `xen,shared-mem` property.\n"); + return -EINVAL; + } + } + + if ( !*paddr_assigned ) + { + device_tree_get_reg(&cells, addr_cells, size_cells, gbase, psize); + goto out; + } + else + { + device_tree_get_reg(&cells, addr_cells, addr_cells, pbase, gbase); + *psize =3D dt_read_number(cells, size_cells); + } + + if ( !IS_ALIGNED(*pbase, PAGE_SIZE) ) + { + printk("%pd: physical address 0x%"PRIpaddr" is not suitably aligne= d.\n", + d, *pbase); + return -EINVAL; + } + + for ( i =3D 0; i < PFN_DOWN(*psize); i++ ) + if ( !mfn_valid(mfn_add(maddr_to_mfn(*pbase), i)) ) + { + printk("%pd: invalid physical address 0x%"PRI_mfn"\n", + d, mfn_x(mfn_add(maddr_to_mfn(*pbase), i))); + return -EINVAL; + } + + out: + if ( !IS_ALIGNED(*psize, PAGE_SIZE) ) + { + printk("%pd: size 0x%"PRIpaddr" is not suitably aligned\n", + d, *psize); + return -EINVAL; + } + + if ( !IS_ALIGNED(*gbase, PAGE_SIZE) ) + { + printk("%pd: guest address 0x%"PRIpaddr" is not suitably aligned.\= n", + d, *gbase); + return -EINVAL; + } + + return 0; +} + static int __init process_shm(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) { @@ -1184,12 +1259,8 @@ static int __init process_shm(struct domain *d, stru= ct kernel_info *kinfo, =20 dt_for_each_child_node(node, shm_node) { - const struct dt_property *prop; - const __be32 *cells; - uint32_t addr_cells, size_cells; paddr_t gbase, pbase, psize; int ret =3D 0; - unsigned int i; const char *role_str; const char *shm_id; bool owner_dom_io =3D true, paddr_assigned =3D true; @@ -1198,37 +1269,10 @@ static int __init process_shm(struct domain *d, str= uct kernel_info *kinfo, if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-= v1") ) continue; =20 - /* - * xen,shared-mem =3D ; - * TODO: pbase is optional. - */ - addr_cells =3D dt_n_addr_cells(shm_node); - size_cells =3D dt_n_size_cells(shm_node); - prop =3D dt_find_property(shm_node, "xen,shared-mem", NULL); - BUG_ON(!prop); - cells =3D (const __be32 *)prop->value; - device_tree_get_reg(&cells, addr_cells, addr_cells, &pbase, &gbase= ); - psize =3D dt_read_number(cells, size_cells); - if ( !IS_ALIGNED(pbase, PAGE_SIZE) || !IS_ALIGNED(gbase, PAGE_SIZE= ) ) - { - printk("%pd: physical address 0x%"PRIpaddr", or guest address = 0x%"PRIpaddr" is not suitably aligned.\n", - d, pbase, gbase); - return -EINVAL; - } - if ( !IS_ALIGNED(psize, PAGE_SIZE) ) - { - printk("%pd: size 0x%"PRIpaddr" is not suitably aligned\n", - d, psize); - return -EINVAL; - } - - for ( i =3D 0; i < PFN_DOWN(psize); i++ ) - if ( !mfn_valid(mfn_add(maddr_to_mfn(pbase), i)) ) - { - printk("%pd: invalid physical address 0x%"PRI_mfn"\n", - d, mfn_x(mfn_add(maddr_to_mfn(pbase), i))); - return -EINVAL; - } + ret =3D parse_shm_property(d, shm_node, &paddr_assigned, + &pbase, &gbase, &psize); + if ( ret ) + return ret; =20 /* * "role" property is optional and if it is defined explicitly, --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668480820216206.18163384507864; Mon, 14 Nov 2022 18:53:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443651.698394 (Exim 4.92) (envelope-from ) id 1oum4f-0003Uk-V2; Tue, 15 Nov 2022 02:53:21 +0000 Received: by outflank-mailman (output) from mailman id 443651.698394; Tue, 15 Nov 2022 02:53:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4f-0003UZ-Rm; Tue, 15 Nov 2022 02:53:21 +0000 Received: by outflank-mailman (input) for mailman id 443651; Tue, 15 Nov 2022 02:53:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4e-0000BJ-Lj for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:20 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id a8baf10a-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:53:19 +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 98F4013D5; Mon, 14 Nov 2022 18:53:24 -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 BB42C3F73B; Mon, 14 Nov 2022 18:53:15 -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: a8baf10a-6490-11ed-91b6-6bf2151ebd3b 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 09/13] xen/arm: refine docs about static shared memory Date: Tue, 15 Nov 2022 10:52:31 +0800 Message-Id: <20221115025235.1378931-10-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: 1668480822254100003 Content-Type: text/plain; charset="utf-8" This commit amends docs(booting.txt) to include the new scenario where host address is not provided in "xen,shared-mem" property, and we also add a new example to explain in details. We also fix some buggy info in the docs, like SHMID is "my-shared-mem-1", not "0x1". Signed-off-by: Penny Zheng --- docs/misc/arm/device-tree/booting.txt | 52 ++++++++++++++++++++------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index 87eaa3e254..287898ef03 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -553,7 +553,7 @@ communication. An array takes a physical address, which is the base address of the shared memory region in host physical address space, a size, and a gue= st physical address, as the target address of the mapping. - e.g. xen,shared-mem =3D < [host physical address] [guest address] [siz= e] > + e.g. xen,shared-mem =3D < [host physical address] [guest address] [siz= e] >; =20 It shall also meet the following criteria: 1) If the SHM ID matches with an existing region, the address range of= the @@ -564,8 +564,8 @@ communication. The number of cells for the host address (and size) is the same as the guest pseudo-physical address and they are inherited from the parent n= ode. =20 - Host physical address is optional, when missing Xen decides the locati= on - (currently unimplemented). + Host physical address is optional, when missing Xen decides the locati= on. + e.g. xen,shared-mem =3D < [guest address] [size] > =20 - role (Optional) =20 @@ -592,7 +592,7 @@ chosen { role =3D "owner"; xen,shm-id =3D "my-shared-mem-0"; xen,shared-mem =3D <0x10000000 0x10000000 0x10000000>; - } + }; =20 domU1 { compatible =3D "xen,domain"; @@ -603,25 +603,36 @@ chosen { vpl011; =20 /* - * shared memory region identified as 0x0(xen,shm-id =3D <0x0>) - * is shared between Dom0 and DomU1. + * shared memory region "my-shared-mem-0" is shared + * between Dom0 and DomU1. */ domU1-shared-mem@10000000 { compatible =3D "xen,domain-shared-memory-v1"; role =3D "borrower"; xen,shm-id =3D "my-shared-mem-0"; xen,shared-mem =3D <0x10000000 0x50000000 0x10000000>; - } + }; =20 /* - * shared memory region identified as 0x1(xen,shm-id =3D <0x1>) - * is shared between DomU1 and DomU2. + * shared memory region "my-shared-mem-1" is shared between + * DomU1 and DomU2. */ domU1-shared-mem@50000000 { compatible =3D "xen,domain-shared-memory-v1"; xen,shm-id =3D "my-shared-mem-1"; xen,shared-mem =3D <0x50000000 0x60000000 0x20000000>; - } + }; + + /* + * shared memory region "my-shared-mem-2" is shared between + * DomU1 and DomU2. + */ + domU1-shared-mem-2 { + compatible =3D "xen,domain-shared-memory-v1"; + xen,shm-id =3D "my-shared-mem-2"; + role =3D "owner"; + xen,shared-mem =3D <0x80000000 0x20000000>; + }; =20 ...... =20 @@ -635,14 +646,21 @@ chosen { cpus =3D <1>; =20 /* - * shared memory region identified as 0x1(xen,shm-id =3D <0x1>) - * is shared between domU1 and domU2. + * shared memory region "my-shared-mem-1" is shared between + * domU1 and domU2. */ domU2-shared-mem@50000000 { compatible =3D "xen,domain-shared-memory-v1"; xen,shm-id =3D "my-shared-mem-1"; xen,shared-mem =3D <0x50000000 0x70000000 0x20000000>; - } + }; + + domU2-shared-mem-2 { + compatible =3D "xen,domain-shared-memory-v1"; + xen,shm-id =3D "my-shared-mem-2"; + role =3D "borrower"; + xen,shared-mem =3D <0x90000000 0x20000000>; + }; =20 ...... }; @@ -662,3 +680,11 @@ shared between DomU1 and DomU2. It will get mapped at = 0x60000000 in DomU1 guest physical address space, and at 0x70000000 in DomU2 guest physical address = space. DomU1 and DomU2 are both the borrower domain, the owner domain is the defa= ult owner domain DOMID_IO. + +For the static shared memory region "my-shared-mem-2", since host physical +address is not provided by user, Xen will automatically allocate 512MB +from heap as static shared memory to be shared between DomU1 and DomU2. +The automatically allocated static shared memory will get mapped at +0x80000000 in DomU1 guest physical address space, and at 0x90000000 in Dom= U2 +guest physical address space. DomU1 is explicitly defined as the owner dom= ain, +and DomU2 is the borrower domain. --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 166848082293844.90014973853488; Mon, 14 Nov 2022 18:53:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443653.698405 (Exim 4.92) (envelope-from ) id 1oum4j-00045g-9d; Tue, 15 Nov 2022 02:53:25 +0000 Received: by outflank-mailman (output) from mailman id 443653.698405; Tue, 15 Nov 2022 02:53:25 +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-00045W-61; Tue, 15 Nov 2022 02:53:25 +0000 Received: by outflank-mailman (input) for mailman id 443653; Tue, 15 Nov 2022 02:53:24 +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-1f for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:24 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id aa98c8b3-6490-11ed-8fd2-01056ac49cbb; Tue, 15 Nov 2022 03:53:22 +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 B0A2111FB; Mon, 14 Nov 2022 18:53:27 -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 D27413F73B; Mon, 14 Nov 2022 18:53:18 -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: aa98c8b3-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 10/13] xen/arm: introduce "xen,offset" feature Date: Tue, 15 Nov 2022 10:52:32 +0800 Message-Id: <20221115025235.1378931-11-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: 1668480824275100005 Content-Type: text/plain; charset="utf-8" We introduce "xen,offset" to handle the case where memory from the owner is shared with multiple borrowers. Each borrower would have its own offset wit= hin the region shared by the owner. Add relative check when parsing static shared memory node, to make sure that "xen,offset" could be only provided in borrower domain, and the value must be smaller than size. And include according docs in booting.txt. Signed-off-by: Penny Zheng --- docs/misc/arm/device-tree/booting.txt | 19 ++++++++++++++-- xen/arch/arm/bootfdt.c | 32 ++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index 287898ef03..183c41e3c2 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -577,6 +577,16 @@ communication. If not specified, the default value is "borrower" and owner is DOMID_IO, a system domain. =20 +- xen,offset (Optional) + + A 64-bit integer specifying the offset within a shared memory region. + When "xen,offset" is provided, only partial shared memory will be + mapped to the borrower domain, starting at the offset and the size + being "size - offset". + + "xen,offset" could be only provided in borrower domain, and the value + must be smaller than size. + As an example: =20 chosen { @@ -660,6 +670,7 @@ chosen { xen,shm-id =3D "my-shared-mem-2"; role =3D "borrower"; xen,shared-mem =3D <0x90000000 0x20000000>; + xen,offset =3D <0x0 0x10000000>; }; =20 ...... @@ -686,5 +697,9 @@ address is not provided by user, Xen will automatically= allocate 512MB from heap as static shared memory to be shared between DomU1 and DomU2. The automatically allocated static shared memory will get mapped at 0x80000000 in DomU1 guest physical address space, and at 0x90000000 in Dom= U2 -guest physical address space. DomU1 is explicitly defined as the owner dom= ain, -and DomU2 is the borrower domain. +guest physical address space. +For borrower domain DomU2, only partial static shared memory region +"my-shared-mem-2" gets mapped, starting at offset 0x10000000 with size of +256MB. +DomU1 is explicitly defined as the owner domain, and DomU2 is the borrower +domain. diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index efaf49fd56..e642e72f30 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -380,7 +380,7 @@ static int __init process_domain_node(const void *fdt, = int node, static int __init process_shm_node(const void *fdt, int node, uint32_t address_cells, uint32_t size_c= ells) { - const struct fdt_property *prop, *prop_id, *prop_role; + const struct fdt_property *prop, *prop_id, *prop_role, *prop_offset; const __be32 *cell; paddr_t paddr, gaddr, size; struct meminfo *mem =3D &bootinfo.reserved_mem; @@ -389,6 +389,7 @@ static int __init process_shm_node(const void *fdt, int= node, int len; bool owner =3D false, paddr_assigned =3D true; const char *shm_id; + uint64_t offset; =20 if ( address_cells < 1 || size_cells < 1 ) { @@ -464,6 +465,35 @@ static int __init process_shm_node(const void *fdt, in= t node, return -EINVAL; } =20 + /* + * If "xen,offset" is provided, then only partial shared memory + * shall be mapped to borrower domain. The size will be + * "psize - offset". + * "xen,offset" is a 64-bit integer and an optional property + */ + prop_offset =3D fdt_get_property(fdt, node, "xen,offset", NULL); + if ( prop_offset ) + { + /* + * "xen,offset" could be only provided in borrower domain, + * and the offset must be smaller than size. + */ + if ( prop_role && !strcmp(prop_role->data, "owner") ) + { + printk("fdt: \"xen,offset\" could not be provided in owner dom= ain\n"); + return -EINVAL; + } + + cell =3D (const __be32 *)prop_offset->data; + offset =3D dt_next_cell(2, &cell); + + if ( offset >=3D size ) + { + printk("fdt: invalid \"xen,offset\" value\n"); + return -EINVAL; + } + } + for ( i =3D 0; i < shm_mem->nr_banks; i++ ) { /* --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 166848125578278.17116711968413; Mon, 14 Nov 2022 19:00:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443684.698416 (Exim 4.92) (envelope-from ) id 1oumBf-0007Vd-Aj; Tue, 15 Nov 2022 03:00:35 +0000 Received: by outflank-mailman (output) from mailman id 443684.698416; Tue, 15 Nov 2022 03:00:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oumBf-0007VQ-6k; Tue, 15 Nov 2022 03:00:35 +0000 Received: by outflank-mailman (input) for mailman id 443684; Tue, 15 Nov 2022 03:00:34 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4k-0000BJ-TG for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:27 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id ac712f45-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:53:25 +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 C902C11FB; Mon, 14 Nov 2022 18:53:30 -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 EA06A3F73B; Mon, 14 Nov 2022 18:53:21 -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: ac712f45-6490-11ed-91b6-6bf2151ebd3b 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 11/13] xen/arm: implement "xen,offset" feature when host address provided Date: Tue, 15 Nov 2022 10:52:33 +0800 Message-Id: <20221115025235.1378931-12-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: 1668481256204100001 Content-Type: text/plain; charset="utf-8" When host address is provided in "xen,shared-mem" property([pbase, gbase, psize]), it is easy to decide where to map to the borrower domain if "xen,offset" is also provided. The partially-shared region shall be starting at pbase + offset, and ending at pbase + size. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 80d37245a8..95600c640c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1112,7 +1112,7 @@ static int __init assign_shared_memory(struct domain = *d, =20 static int __init borrower_physmap_add_memory(struct domain *d, struct shm_membank *shm_memb= ank, - paddr_t gbase) + paddr_t gbase, paddr_t offse= t) { int ret; unsigned int i; @@ -1141,8 +1141,8 @@ static int __init borrower_physmap_add_memory(struct = domain *d, } else { - start =3D shm_membank->mem.bank->start; - size =3D shm_membank->mem.bank->size; + start =3D shm_membank->mem.bank->start + offset; + size =3D shm_membank->mem.bank->size - offset; sgfn =3D _gfn(PFN_UP(gbase)); =20 /* Set up P2M foreign mapping for borrower domain. */ @@ -1157,7 +1157,7 @@ static int __init borrower_physmap_add_memory(struct = domain *d, =20 static int __init append_shm_bank_to_domain(struct kernel_info *kinfo, paddr_t start, paddr_t size, - const char *shm_id) + const char *shm_id, paddr_t of= fset) { struct membank *membank; =20 @@ -1170,7 +1170,7 @@ static int __init append_shm_bank_to_domain(struct ke= rnel_info *kinfo, =20 kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank =3D membank; kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->start =3D start; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->size =3D size; + kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].mem.bank->size =3D size -= offset; safe_strcpy(kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].shm_id, shm_i= d); kinfo->shm_mem.nr_banks++; =20 @@ -1265,6 +1265,7 @@ static int __init process_shm(struct domain *d, struc= t kernel_info *kinfo, const char *shm_id; bool owner_dom_io =3D true, paddr_assigned =3D true; struct shm_membank *shm_membank; + uint64_t offset =3D 0UL; =20 if ( !dt_device_is_compatible(shm_node, "xen,domain-shared-memory-= v1") ) continue; @@ -1288,6 +1289,19 @@ static int __init process_shm(struct domain *d, stru= ct kernel_info *kinfo, } BUG_ON((strlen(shm_id) <=3D 0) || (strlen(shm_id) >=3D MAX_SHM_ID_= LENGTH)); =20 + /* + * If "xen,offset" is provided, then only partial shared memory + * shall be mapped to borrower domain. + * "xen,offset" is a 64-bit integer and an optional property + */ + dt_property_read_u64(shm_node, "xen,offset", &offset); + if ( !IS_ALIGNED(offset, PAGE_SIZE) ) + { + printk("%pd: \"xen,offset\" 0x%lx is not suitably aligned\n", + d, offset); + return -EINVAL; + } + shm_membank =3D acquire_shm_membank(shm_id); if ( !shm_membank ) { @@ -1331,7 +1345,8 @@ static int __init process_shm(struct domain *d, struc= t kernel_info *kinfo, =20 if ( owner_dom_io || (strcmp(role_str, "borrower") =3D=3D 0) ) { - ret =3D borrower_physmap_add_memory(d, shm_membank, gbase); + ret =3D borrower_physmap_add_memory(d, shm_membank, gbase, + (paddr_t)offset); if ( ret ) { printk(XENLOG_ERR @@ -1345,7 +1360,8 @@ static int __init process_shm(struct domain *d, struc= t kernel_info *kinfo, * Record static shared memory region info for later setting * up shm-node in guest device tree. */ - ret =3D append_shm_bank_to_domain(kinfo, gbase, psize, shm_id); + ret =3D append_shm_bank_to_domain(kinfo, gbase, psize, shm_id, + (paddr_t)offset); if ( ret ) return ret; } --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668481258116975.0046536100898; Mon, 14 Nov 2022 19:00:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443689.698427 (Exim 4.92) (envelope-from ) id 1oumBg-0007mQ-Hv; Tue, 15 Nov 2022 03:00:36 +0000 Received: by outflank-mailman (output) from mailman id 443689.698427; Tue, 15 Nov 2022 03:00:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oumBg-0007mH-EC; Tue, 15 Nov 2022 03:00:36 +0000 Received: by outflank-mailman (input) for mailman id 443689; Tue, 15 Nov 2022 03:00:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4p-0000BJ-U2 for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:31 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id ae41efa1-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:53:28 +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 E07E911FB; Mon, 14 Nov 2022 18:53:33 -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 0E26B3F73B; Mon, 14 Nov 2022 18:53:24 -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: ae41efa1-6490-11ed-91b6-6bf2151ebd3b 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 12/13] xen/arm: implement "xen,offset" feature when host address not provided Date: Tue, 15 Nov 2022 10:52:34 +0800 Message-Id: <20221115025235.1378931-13-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: 1668481260104100001 Content-Type: text/plain; charset="utf-8" When host address is not provided in "xen,shared-mem" property, shared memory region is allocated from heap by Xen. It is normally not contiguous and consisted of multiple memory blocks. Under above scenario, when "xen,offset" is also offered, we need to find at which memory block the offset locates, and the borrower memory map shall st= art at this block offset. Signed-off-by: Penny Zheng --- xen/arch/arm/domain_build.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 95600c640c..494f6aff2e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -48,6 +48,10 @@ boolean_param("ext_regions", opt_ext_regions); static u64 __initdata dom0_mem; static bool __initdata dom0_mem_set; =20 +#ifdef CONFIG_STATIC_SHM +static uint64_t __initdata allocated =3D 0UL; +#endif + static int __init parse_dom0_mem(const char *s) { dom0_mem_set =3D true; @@ -1110,6 +1114,26 @@ static int __init assign_shared_memory(struct domain= *d, return ret; } =20 +static bool __init find_anchor_offset(paddr_t *bank_start, paddr_t *bank_s= ize, + uint64_t offset) +{ + uint64_t bank_offset; + + allocated +=3D *bank_size; + if ( allocated <=3D offset ) + return false; + + /* Find the bank when offset locates */ + bank_offset =3D *bank_size - (allocated - offset); + *bank_start +=3D bank_offset; + *bank_size =3D allocated - offset; + + /* Reset after finding the anchor */ + allocated =3D 0UL; + + return true; +} + static int __init borrower_physmap_add_memory(struct domain *d, struct shm_membank *shm_memb= ank, paddr_t gbase, paddr_t offse= t) @@ -1123,12 +1147,17 @@ static int __init borrower_physmap_add_memory(struc= t domain *d, /* Host address is not provided in "xen,shared-mem" */ if ( shm_membank->mem.banks.meminfo ) { + bool found =3D false; meminfo =3D shm_membank->mem.banks.meminfo; + sgfn =3D _gfn(PFN_UP(gbase)); + for ( i =3D 0; i < meminfo->nr_banks; i++ ) { start =3D meminfo->bank[i].start; size =3D meminfo->bank[i].size; - sgfn =3D _gfn(PFN_UP(gbase)); + + if ( offset && !found ) + found =3D find_anchor_offset(&start, &size, offset); =20 /* Set up P2M foreign mapping for borrower domain. */ ret =3D map_regions_p2mt(d, sgfn, PFN_DOWN(size), _mfn(PFN_UP(= start)), --=20 2.25.1 From nobody Fri Apr 26 10:20:53 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 1668481260364956.7539657143601; Mon, 14 Nov 2022 19:01:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.443690.698433 (Exim 4.92) (envelope-from ) id 1oumBg-0007q7-Un; Tue, 15 Nov 2022 03:00:36 +0000 Received: by outflank-mailman (output) from mailman id 443690.698433; Tue, 15 Nov 2022 03:00:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oumBg-0007pv-O6; Tue, 15 Nov 2022 03:00:36 +0000 Received: by outflank-mailman (input) for mailman id 443690; Tue, 15 Nov 2022 03:00:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oum4s-0000BJ-UM for xen-devel@lists.xenproject.org; Tue, 15 Nov 2022 02:53:34 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id b0baba22-6490-11ed-91b6-6bf2151ebd3b; Tue, 15 Nov 2022 03:53:32 +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 146CE11FB; Mon, 14 Nov 2022 18:53:38 -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 25DE13F73B; Mon, 14 Nov 2022 18:53:27 -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: b0baba22-6490-11ed-91b6-6bf2151ebd3b From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: wei.chen@arm.com, Penny Zheng , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v1 13/13] xen: make static shared memory supported in SUPPORT.md Date: Tue, 15 Nov 2022 10:52:35 +0800 Message-Id: <20221115025235.1378931-14-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: 1668481262148100001 Content-Type: text/plain; charset="utf-8" After patching previous commits, we could make feature of "static shared me= mory" supported in SUPPORT.md. Signed-off-by: Penny Zheng --- SUPPORT.md | 2 +- xen/arch/arm/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SUPPORT.md b/SUPPORT.md index ab71464cf6..c9fe7daf56 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -316,7 +316,7 @@ Allow sharing of identical pages between guests Allow to statically set up shared memory on dom0less system, enabling domains to do shm-based communication =20 - Status, ARM: Tech Preview + Status, ARM: Supported =20 ### Memory Paging =20 diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 52a05f704d..e0ea6e1762 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -141,7 +141,7 @@ config TEE source "arch/arm/tee/Kconfig" =20 config STATIC_SHM - bool "Statically shared memory on a dom0less system" if UNSUPPORTED + bool "Statically shared memory on a dom0less system" depends on STATIC_MEMORY help This option enables statically shared memory on a dom0less system. --=20 2.25.1