All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: Shawn Anastasio <sanastasio@raptorengineering.com>,
	xen-devel@lists.xenproject.org
Cc: Timothy Pearson <tpearson@raptorengineering.com>,
	Jan Beulich <jbeulich@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v2 4/7] xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions
Date: Tue, 9 Jan 2024 18:14:56 +0000	[thread overview]
Message-ID: <c1c6ee29-7fa1-4b39-aa7a-1b8f750cd893@xen.org> (raw)
In-Reply-To: <1c6f0f94f4ea2b773f960d88bd02e2168ac28abb.1702607884.git.sanastasio@raptorengineering.com>

(+ Stefano)

Hi Shawn,

On 15/12/2023 02:43, Shawn Anastasio wrote:
> The early_print_info routine in bootfdt.c incorrectly stores the result
> of a call to fdt_num_mem_rsv() in an unsigned int, which results in the
> negative error code being interpreted incorrectly in a subsequent loop
> in the case where the device tree does not contain any memory reserve
> map entries.

I have some trouble to reconciliate the code with your explanation. 
Looking at the implementation fdt_num_mem_rsv() should return 0 if there 
are no reserved regions. A negative value would only be returned if the 
device-tree is malformated.

Do you have a Device-Tree where the issue occurs?

That said, I agree that the code could be hardened.

> 
> Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
> ---
>   xen/common/device-tree/bootfdt.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/bootfdt.c
> index ae9fa1e3d6..796ac01c18 100644
> --- a/xen/common/device-tree/bootfdt.c
> +++ b/xen/common/device-tree/bootfdt.c
> @@ -466,7 +466,8 @@ static void __init early_print_info(void)
>       struct meminfo *mem_resv = &bootinfo.reserved_mem;
>       struct bootmodules *mods = &bootinfo.modules;
>       struct bootcmdlines *cmds = &bootinfo.cmdlines;
> -    unsigned int i, j, nr_rsvd;
> +    unsigned int i, j;
> +    int nr_rsvd;
>   
>       for ( i = 0; i < mi->nr_banks; i++ )
>           printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",
> @@ -481,7 +482,7 @@ static void __init early_print_info(void)
>                   boot_module_kind_as_string(mods->module[i].kind));
>   
>       nr_rsvd = fdt_num_mem_rsv(device_tree_flattened);

If I am correct above, then I think we should panic() rather than trying 
to continue with a buggy DT.

> -    for ( i = 0; i < nr_rsvd; i++ )
> +    for ( i = 0; nr_rsvd > 0 && i < nr_rsvd; i++ )
>       {
>           paddr_t s, e;
>   

Cheers,

-- 
Julien Grall


  reply	other threads:[~2024-01-09 18:15 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  2:43 [PATCH v2 0/7] Early Boot Allocation on Power Shawn Anastasio
2023-12-15  2:43 ` [PATCH v2 1/7] xen/asm-generic: Introduce generic static-shmem.h Shawn Anastasio
2023-12-19 17:07   ` Jan Beulich
2023-12-15  2:43 ` [PATCH v2 2/7] xen/asm-generic: Introduce generic setup.h Shawn Anastasio
2023-12-20  7:23   ` Jan Beulich
2023-12-20 11:09   ` Jan Beulich
2023-12-20 18:51     ` Shawn Anastasio
2023-12-15  2:43 ` [PATCH v2 3/7] xen/common: Move Arm's bootfdt to common Shawn Anastasio
2023-12-19 17:03   ` Jan Beulich
2023-12-19 18:29     ` Julien Grall
2023-12-20  8:09       ` Jan Beulich
2023-12-20 20:58         ` Shawn Anastasio
2023-12-20 22:08           ` Julien Grall
2023-12-20 22:10             ` Timothy Pearson
2023-12-21  7:11             ` Jan Beulich
2023-12-20 13:53   ` Julien Grall
2023-12-15  2:43 ` [PATCH v2 4/7] xen/device-tree: Fix bootfdt.c to tolerate 0 reserved regions Shawn Anastasio
2024-01-09 18:14   ` Julien Grall [this message]
2024-01-10  8:15     ` Michal Orzel
2024-01-11 22:56     ` Shawn Anastasio
2023-12-15  2:44 ` [PATCH v2 5/7] xen/ppc: Enable bootfdt and boot allocator Shawn Anastasio
2023-12-20 11:44   ` Jan Beulich
2023-12-20 13:23   ` Julien Grall
2023-12-20 16:07     ` Julien Grall
2023-12-20 13:49   ` Julien Grall
2024-01-18  1:36     ` Shawn Anastasio
2024-01-18  9:21       ` Julien Grall
2023-12-15  2:44 ` [PATCH v2 6/7] xen/ppc: mm-radix: Replace debug printing code with printk Shawn Anastasio
2023-12-20 11:48   ` Jan Beulich
2024-01-18  1:37     ` Shawn Anastasio
2023-12-15  2:44 ` [PATCH v2 7/7] xen/ppc: mm-radix: Allocate Partition and Process Tables at runtime Shawn Anastasio
2023-12-21  7:06   ` Jan Beulich
2024-03-14 18:29     ` Shawn Anastasio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c1c6ee29-7fa1-4b39-aa7a-1b8f750cd893@xen.org \
    --to=julien@xen.org \
    --cc=jbeulich@suse.com \
    --cc=sanastasio@raptorengineering.com \
    --cc=sstabellini@kernel.org \
    --cc=tpearson@raptorengineering.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.