[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: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Tue, 9 Apr 2024 14:37:46 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=pG+vC1Pu0qLn7IahqeWMalRGteEWL1LJMGbyUbwFqQ0=; b=nlBUnQYLMphaLOT1GtztrGN2P6E/2JxwaGJVad/1w713P68pwTO5dsFeXMp5l4VKpLzdXpJkHRyt2Ry/hPPDiEMzCJ9JmFTveYI5Vo+Ffiv5FCzGfQe4qRUi+PDeQKZ3s/WV2loUReO+cEObrQxaj3GNeWm1A9nEafXkqKpe+HacFGxMumEopB4BXQp32Cq7HBm2eaOp9TvrYehZleT/u339CvU8c4esNpLgR5tbwQUauvYaNvh4PMEkrbQsSyd2dqj+t8k2v7u7+14AijP9tScrO91BtyPyRlAU2ox0M9/Z9nopZuKeHpSLzxi+4YPbDaUNlw75QWezRUUKeZe4Nw==
  • 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=pG+vC1Pu0qLn7IahqeWMalRGteEWL1LJMGbyUbwFqQ0=; b=f8JQwg/zfQppYRFtfcIb26Nz8RTIkMETGxm+IP0vdHs+Pmn0PzDELKS/gwtYI9Yw4hL93VQmTpVAeI9aPSkYm8V8OkpRSPYulcfKF7BY60iZLsCB+xNDKhUbspOScVcOoBBuDdzAbqMZbGFVe012vfyfMLtdCeozIU4WTvDwAVbp0RkOzBfjv8019TwtYE0QLqyCuNHJgl0kJ9Py6dTS34mDm+YBEkbDH7j7Erxas9ALuWBpJdgHrDJq+ngZdnlXwjVl9diRV+wzM1SMQXqA9Oy1JrMzqACqwmtfh1b/k6VEtR2CAxGNkqmD/mJrZ+wbFEwiNB/m/mXFnS6l8BZy/A==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=aj3snASZVxp8X36NmNkNJ4xVDHDuYfh2Kro1stP5KtwkR2hbN9ImQGAhCfso5/5FhmX1srFpXwUMyOBzP/VV2RVvqGNFciPVmZ00+VbKbpSt/dC7IgI8reKeBjVzjUIVIzsI9CcPBaYcfWu20/Pthut4sOeOSSFosxrfENKJXLG/g+WzIfHmfI54KQGb0K6u89jBZ9zbeKzT7Rx9CalZv3dSvGhGU50GFD1O68j6UUS11oQPnbj/mD08FxRRel12yqukdk4DAvqUEm50QClXGSn0QlV5WFuFfQnRnJOABnswMaQbPz3ibVm0c2IACibqwI4qY5RVmW5hcynSojM03g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K6Ciqfe/t98u5g2Devhi8ZjWVbOfZj364IPQn0zuKFeFNjRrCvlpvEE3+zGQASAs13++K2o7Fq9q9eDbrBGDTPFZFJ5JrpGjRJ+b1UHloqQUQAp77SMIJAcXJV00v26QJKzEiEYw3qfJO++I2yzJG2FQeqNkgKST/JLn6h5KmnERJNmRVCCJACVAK7OVRCUFr0KqwClH/S7a7FcUqIN0sqSCKjK5EawcvpdYTN3IOqHjkq8TTqvEDFRWhWP3Ewn0qSr0ouJTJCDnvDoc5OlijImNsA/SsR+Eg8gqq2/0WXSjzUn1nlisbhN7kAmTS/2Mg5zh7MiToqGm3NkBN6zq5g==
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 09 Apr 2024 14:38:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHainOJn9rbiVDC1UmGGgx4oNVl2bFf8W4AgAAQl4A=
  • Thread-topic: [PATCH v2 06/13] xen/arm: Avoid code duplication in find_unallocated_memory


> On 9 Apr 2024, at 14:38, Michal Orzel <michal.orzel@xxxxxxx> wrote:
> 
> 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.

Right, I read it wrong initially, my mistake, here we are adding all available 
ram and later removing the dom0 regions
and reserved regions. Will fix

> 
> ~Michal




 


Rackspace

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