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

Re: [Xen-devel] [PATCH v5 2/7] xen/arm: make process_memory_node a device_tree_node_func


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Thu, 15 Aug 2019 11:20:27 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; 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-SenderADCheck; bh=anuzQ9DMq+cnf8E42+qQpfJ2bVM2kLrhSWBrewCF8hA=; b=XX291B1tBHxTQ/3BYHKpCu96XZYCaDGSTktQBu/6JdboWR2wHTdS+BV3bTetCYHS/XnmsWFfHiUTYeJKBGhZ6p0bxKSz8lZsFqRaKT9IzPBsnLVt229Xy3s2RpWAtHuTsMcXhyzXgYSrX03bUevXU6CkDP4axo1EmUJjX5svHo7tuAzm+JLBaXt5X8jE28endfTBvcEbBUBCQc9EMqOhR4rz4zGzzlaaWwkBu3ZxFBJFGyvpRvGR9HQ2GchX6UNz+oqaLOsuhRTbJLgILw674he+CLBfzP2Y6TQQIJiLfzdf0anuZxJ0R8B/cCITlBKyYLlpqLeaaUS8vYf6wZd0xw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghm7FfF8edtDhgLVYJosdjJNhXH4hpaeDvOyQQfT+/gvpD2vA+Lz7CDvjLJkJ8OaUEbU2DRdeUmueKXj+oe6UyFPqfhtgBp/n/lJp7fvj/LshGV4YB6xm6Vb32BJxevxNhgu17/2bvcrEW6ZwjEL5E68Z/p46Q2JdmGE2LWBOGWgbjbbc0rdPLzBOHFOXR8DsNewYdFl6aHdH6oUaKtIjl7hufS5HpandvZsY1c6//R7Kz+qzORPPDCmuGHEmEoPCgPvZAs65OuP2cycRe4Wo+mvELmreQpcCW/Zvfat6z//8FHdGOvdB4b2RLTmk038ErBb2ZE8mItWX4YqaWv0Lw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@xxxxxxxx;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "julien.grall@xxxxxxx" <julien.grall@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 15 Aug 2019 11:20:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVUV1R/d2bF3zaTUGfbkxrXQjKbab5IAaAgAIeWACAANW8gA==
  • Thread-topic: [PATCH v5 2/7] xen/arm: make process_memory_node a device_tree_node_func

Hi Stefano,

Stefano Stabellini writes:

> On Tue, 13 Aug 2019, Volodymyr Babchuk wrote:
>> > @@ -162,6 +156,10 @@ static void __init process_memory_node(const void 
>> > *fdt, int node,
>> >          bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size;
>> >          bootinfo.mem.nr_banks++;
>> >      }
>> > +
>> > +    if ( bootinfo.mem.nr_banks == NR_MEM_BANKS )
>> > +        return -ENOSPC;
>> Are you sure that this logic is correct?
>>
>> For example, if NR_MEM_BANKS is 1, and we have exactly one memory node
>> in device tree, this function will fail. But it should not. I think you
>> want this condition: bootinfo.mem.nr_banks > NR_MEM_BANKS
>
> You are right, if NR_MEM_BANKS is 1 and we have 1 memory node in device
> tree the code would return an error while actually it is normal.
>
> I think the right check would be:
>
>   if ( i < banks && bootinfo.mem.nr_banks == NR_MEM_BANKS )
>       return -ENOSPC;

Actually, this does not cover all corner cases. Here is the resulting
code:

 150     for ( i = 0; i < banks && bootinfo.mem.nr_banks < NR_MEM_BANKS; i++ )
 151     {
 152         device_tree_get_reg(&cell, address_cells, size_cells, &start, 
&size);
 153         if ( !size )
 154             continue;
 155         bootinfo.mem.bank[bootinfo.mem.nr_banks].start = start;
 156         bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size;
 157         bootinfo.mem.nr_banks++;
 158     }
 159
 160     if ( i < banks && bootinfo.mem.nr_banks == NR_MEM_BANKS )
 161         return -ENOSPC;

Lines 153-154 cause the issue.

Imagine that NR_MEM_BANKS = 1 and we have two memory nodes in device
tree with. Nodes have sizes 0 and 1024. Your code will work as
intended. At the end of loop we will have banks = 2, i = 2 and
bootinfo.mem.nr_banks = 1.

But if we switch order of memory nodes, so first one will be with size
1024 and second one with size 0, your code will return -ENOSPC, because
we'll have banks = 2, i = 1, bootinfo.mem.nr_banks = 1.

I think, right solution will be to scan all nodes to count nodes
with size > 0. And then - either return an error or do second loop to
fill bootinfo.mem.bank[].

>
> (That's because it is impossible to get to nr_banks > NR_MEM_BANKS.)
Yes, this is my mistake.

--
Volodymyr Babchuk at EPAM
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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