[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 05/13] xen/arm: allocate shared memory from heap when host address not provided


  • To: Penny Zheng <Penny.Zheng@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 7 Feb 2023 15:57:26 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+jYxCp6nCsjb+AHMJH4nWQu9hbmn/AD2c7tuvYBI2Fo=; b=k5OXh7WVluVUNLjwIzYiHbCnK8boIQIQnZf7xjmZDNWXXzEDCKeM/SCoZLFu6dkIlL4p0CiHJdITqjhZJv7l0Awx9Er4b8OC2xnOYbNB2h+p5fYNoxddHFOgOUutxNlhXd1wILiOQTJCjOX3Wgd+rYHd8mzwb02tqpLn6BW73HbAD8U8yDEY8FKFAtG5dqnkrRtl4ROscYM71VdHU8sQ0kmRE6DBJfIseljm311WYM3s2FAzmWZhYSvf6mAcVfYJnrt8Y2iAX4cFSrQMDAqo1wEfX6cAW/1vcnfjx0dhCVctVp7UShqys3SSe6cXsIgr7szX/rPvjN87k9PjsXhtfw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CFi2acilOQyyZ5F0R+S4QIOISzOghcyURqkW2K/UqqaLVLeaKxkMog3GRE1jj3eZyrxJlGi9kGVvUPVEG3wblpCUU8HwewDA0zhbUNioqsducnFGqg1nLN360SG4yKi6nU1O2fFo5YOz0yKZLTHv7XarXysOuCxhOhFb9pS1Q1Bn4wL+QGrJavT+R4PiRQ4fF98KZpQWaeZrXaNAoNndXhZDCKN+oLLoJsC43FtD0jDe2C1lxgMpnWP1HBga9BoR9kh4g6Nd+2lDG7IEdEPwAeg83yNjv1RsRoBu4DW2vas6DCUyiVuMpPhYvrLaELdYa/fu2fs6uPVo2laqGO/fRA==
  • Cc: <wei.chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 07 Feb 2023 20:57:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 11/14/22 21:52, Penny Zheng wrote:
> 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 will 
> be
> reserved as static memory, and will not go back to heap even on freeing.
> 
> Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
> ---
>  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 
> shm_membank *shm_membank)
>      return true;
>  }
> 
> +static int __init mark_shared_memory_static(struct shm_membank *shm_membank)
> +{
> +    unsigned int bank;
> +    unsigned long i, nr_mfns;
> +    struct page_info *pg;
> +    struct meminfo *meminfo;
> +
> +    BUG_ON(!shm_membank->mem.banks.meminfo);
> +    meminfo = shm_membank->mem.banks.meminfo;
> +    for ( bank = 0; bank < meminfo->nr_banks; bank++ )
> +    {
> +        pg = mfn_to_page(maddr_to_mfn(meminfo->bank[bank].start));
> +        nr_mfns = PFN_DOWN(meminfo->bank[bank].size);
> +
> +        for ( i = 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=%#lx\n",
> +                       i, mfn_x(page_to_mfn(pg)) + i, pg[i].count_info);
> +                goto fail;
> +            }
> +
> +           pg[i].count_info |= PGC_static;
> +        }
> +    }
> +
> +    return 0;
> +
> + fail:
> +    while ( bank >= 0 )

When building with EXTRA_CFLAGS_XEN_CORE="-Wtype-limits 
-Wno-error=type-limits", we get the following warning:
arch/arm/domain_build.c: In function ‘mark_shared_memory_static’:
arch/arm/domain_build.c:879:18: warning: comparison of unsigned expression in 
‘>= 0’ is always true [-Wtype-limits]
  879 |     while ( bank >= 0 )
      |                  ^~

> +    {
> +        while ( --i >= 0 )

Similarly here:
arch/arm/domain_build.c:881:21: warning: comparison of unsigned expression in 
‘>= 0’ is always true [-Wtype-limits]
  881 |         while ( --i >= 0 )
      |                     ^~

> +            pg[i].count_info &= ~PGC_static;
> +        i = 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 != NULL);
> +
> +    banks = xmalloc_bytes(sizeof(struct meminfo));
> +    if ( banks == NULL )
> +        return -ENOMEM;
> +    shm_membank->mem.banks.meminfo = banks;
> +    memset(shm_membank->mem.banks.meminfo, 0, sizeof(struct meminfo));
> +
> +    if ( !allocate_domheap_memory(NULL, psize, 
> shm_membank->mem.banks.meminfo) )
> +        return -EINVAL;
> +
> +    ret = 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 psize)
>  {
> @@ -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 = true;
> +        bool owner_dom_io = true, paddr_assigned = true;
>          struct shm_membank *shm_membank;
> 
>          if ( !dt_device_is_compatible(shm_node, 
> "xen,domain-shared-memory-v1") )
> @@ -1035,6 +1101,21 @@ static int __init process_shm(struct domain *d, struct 
> kernel_info *kinfo,
>              return -ENOENT;
>          }
> 
> +        /*
> +         * 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 = allocate_shared_memory(shm_membank, psize);
> +            if ( ret )
> +            {
> +                printk("%pd: failed to allocate shared memory 
> bank(%"PRIpaddr"MB) from heap: %d\n",
> +                       d, psize >> 20, ret);
> +                return ret;
> +            }
> +        }
> +
>          /*
>           * DOMID_IO is a fake domain and is not described in the Device-Tree.
>           * Therefore when the owner of the shared region is DOMID_IO, we will
> --
> 2.25.1
> 
> 



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.