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

Re: [PATCH v2 06/13] xen/arm: Avoid code duplication in find_unallocated_memory


  • To: Luca Fancellu <luca.fancellu@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Tue, 9 Apr 2024 15:38:12 +0200
  • 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 (0)
  • 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=1S5gcepFEut6mWo0Vqg5/fAfmi2CGeyyFjQ/NZPEUJM=; b=IrFiZmO8NSfe9VjZ+nh6OSR5AoU9xfiyubvmNWlDAyw0/+vNCzzw9ZtQIJ/gX13uyWa/BU/NxYoe/8VW/QFUKTGQyIHIpnZbCZPSg5XGyEfW9cTXJKtIm5B+27heZO33ffNms0QhwwI8mSH68fZAXjjRYoZ0Ht8OmrGX7bz7L4yUTuSlkNJjtUskE6MCBIicRt7FGaKhell91EJfl1ZiuVgiPiouAocKyfukLL/e/hBk59of0tINBlv/x19YRL0nkZERDc3Ewbcl2SArpLMIbm2WAuzYdOXuGvg6uvSuTXPqoxtwMrH6HjJbmFY5YJPF90IHUg9+PAHLLWtSiMkKUA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gpV4NrEq+lV8KuEBy98T8ksphJ6E/c32YgIIh9t4TyC/K7Lyu8qzttF1jIlyFJOYYFBvUH6YsnooDxAvFko0XIr9+TVGQapNk2teZ72SjMC8eI5Dig3eGLxLXJog0fUrG7eCIlsMVfVZx8QPFKT3XkUh/ykvQ6OAsRxsAFL+3WszXukxnoqEd91UdwOC+dDU/yAKOAWqatGc64kWQ+vKeqfudL5rqnFW0aRGsxnRF4SPbDtSDGzXLhJkfFpVFoxYxadq+C7GxsPVIbpxx2v0LiMMAdZjSjOiZZcbS+y7FxdDKFZzLHLVHOdd9LI0ig0RuIOTAHxXgvJJ7tuoC26x0A==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, "Volodymyr Babchuk" <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 09 Apr 2024 13:38:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Luca,

On 09/04/2024 13:45, Luca Fancellu wrote:
> 
> 
> The function find_unallocated_memory is using the same code to
> loop through 3 structure of the same type, in order to avoid
> code duplication, rework the code to have only one loop that
> goes through all the structures.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
> ---
> v2:
>  - Add comment in the loop inside find_unallocated_memory to
>    improve readability
> v1:
>  - new patch
> ---
> ---
>  xen/arch/arm/domain_build.c | 70 +++++++++++++------------------------
>  1 file changed, 25 insertions(+), 45 deletions(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 57cf92668ae6..269aaff4d067 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -869,12 +869,14 @@ static int __init add_ext_regions(unsigned long s_gfn, 
> unsigned long e_gfn,
>  static int __init find_unallocated_memory(const struct kernel_info *kinfo,
>                                            struct membanks *ext_regions)
>  {
> -    const struct membanks *kinfo_mem = kernel_info_get_mem_const(kinfo);
> -    const struct membanks *mem = bootinfo_get_mem();
> -    const struct membanks *reserved_mem = bootinfo_get_reserved_mem();
> +    const struct membanks *mem_banks[] = {
> +        bootinfo_get_mem(),
> +        kernel_info_get_mem_const(kinfo),
> +        bootinfo_get_reserved_mem(),
> +    };
>      struct rangeset *unalloc_mem;
>      paddr_t start, end;
> -    unsigned int i;
> +    unsigned int i, j;
>      int res;
> 
>      dt_dprintk("Find unallocated memory for extended regions\n");
> @@ -883,50 +885,28 @@ static int __init find_unallocated_memory(const struct 
> kernel_info *kinfo,
>      if ( !unalloc_mem )
>          return -ENOMEM;
> 
> -    /* Start with all available RAM */
> -    for ( i = 0; i < mem->nr_banks; i++ )
> -    {
> -        start = mem->bank[i].start;
> -        end = mem->bank[i].start + mem->bank[i].size;
> -        res = rangeset_add_range(unalloc_mem, PFN_DOWN(start),
> -                                 PFN_DOWN(end - 1));
> -        if ( res )
> +    /*
> +     * Exclude the following regions, in order:
> +     * 1) Start with all available RAM
> +     * 2) Remove RAM assigned to Dom0
> +     * 3) Remove reserved memory
Given this commit and the previous code, I expect one call to 
rangeset_add_range() and
3 calls to rangeset_remove_range(). However ...
> +     * The order comes from the initialization of the variable "mem_banks"
> +     * above
> +     */
> +    for ( i = 0; i < ARRAY_SIZE(mem_banks); i++ )
> +        for ( j = 0; j < mem_banks[i]->nr_banks; j++ )
>          {
> -            printk(XENLOG_ERR "Failed to add: %#"PRIpaddr"->%#"PRIpaddr"\n",
> -                   start, end);
> -            goto out;
> -        }
> -    }
> -
> -    /* Remove RAM assigned to Dom0 */
> -    for ( i = 0; i < kinfo_mem->nr_banks; i++ )
> -    {
> -        start = kinfo_mem->bank[i].start;
> -        end = kinfo_mem->bank[i].start + kinfo_mem->bank[i].size;
> -        res = rangeset_remove_range(unalloc_mem, PFN_DOWN(start),
> +            start = mem_banks[i]->bank[j].start;
> +            end = mem_banks[i]->bank[j].start + mem_banks[i]->bank[j].size;
> +            res = rangeset_add_range(unalloc_mem, PFN_DOWN(start),
... here you always call rangeset_add_range() which is wrong. For direct mapped 
domain
you would e.g. register its RAM region as extended region.

~Michal



 


Rackspace

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