All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vikram Garhwal <vikram.garhwal@amd.com>
To: Julien Grall <julien@xen.org>, xen-devel@lists.xenproject.org
Cc: sstabellini@kernel.org
Subject: Re: [XEN][PATCH v5 02/17] common/device_tree: change __unflatten_device_tree()
Date: Fri, 14 Apr 2023 11:28:23 -0700	[thread overview]
Message-ID: <81b7b4ab-1765-67dc-0d0e-8fcf8a8f41d1@amd.com> (raw)
In-Reply-To: <1198aebe-caa7-fefe-8c09-db7a14ec7c34@xen.org>

Hi,

On 4/14/23 11:09 AM, Julien Grall wrote:
> Hi,
>
> On 14/04/2023 18:51, Vikram Garhwal wrote:
>> On 4/13/23 3:03 AM, Julien Grall wrote:
>>> Hi,
>>>
>>> On 11/04/2023 20:16, Vikram Garhwal wrote:
>>>> Following changes are done to __unflatten_device_tree():
>>>>      1. __unflatten_device_tree() is renamed to 
>>>> unflatten_device_tree().
>>>>      2. Remove static function type.
>>>>      3. Add handling of memory allocation. This will be useful in 
>>>> dynamic node
>>>>          programming when we unflatten the dt during runtime memory 
>>>> allocation
>>>>          can fail.
>>>>
>>>> Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
>>>> ---
>>>>   xen/common/device_tree.c      | 10 ++++++----
>>>>   xen/include/xen/device_tree.h |  5 +++++
>>>>   2 files changed, 11 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
>>>> index aed38ff63c..bf847b2584 100644
>>>> --- a/xen/common/device_tree.c
>>>> +++ b/xen/common/device_tree.c
>>>> @@ -2047,7 +2047,7 @@ static unsigned long unflatten_dt_node(const 
>>>> void *fdt,
>>>>   }
>>>>     /**
>>>> - * __unflatten_device_tree - create tree of device_nodes from flat 
>>>> blob
>>>> + * unflatten_device_tree - create tree of device_nodes from flat blob
>>>>    *
>>>>    * unflattens a device-tree, creating the
>>>>    * tree of struct device_node. It also fills the "name" and "type"
>>>> @@ -2056,8 +2056,7 @@ static unsigned long unflatten_dt_node(const 
>>>> void *fdt,
>>>>    * @fdt: The fdt to expand
>>>>    * @mynodes: The device_node tree created by the call
>>>>    */
>>>> -static void __unflatten_device_tree(const void *fdt,
>>>> -                                    struct dt_device_node **mynodes)
>>>> +void unflatten_device_tree(const void *fdt, struct dt_device_node 
>>>> **mynodes)
>>>>   {
>>>>       unsigned long start, mem, size;
>>>>       struct dt_device_node **allnextp = mynodes;
>>>> @@ -2079,6 +2078,9 @@ static void __unflatten_device_tree(const 
>>>> void *fdt,
>>>>       /* Allocate memory for the expanded device tree */
>>>>       mem = (unsigned long)_xmalloc (size + 4, __alignof__(struct 
>>>> dt_device_node));
>>>>   +    if ( !mem )
>>>> +        panic("Cannot allocate memory for unflatten device tree\n");
>>>
>>> After your series, unflatten_device_tree() will be called after 
>>> boot, so we should not unconditionally called panic(). Instead, 
>>> unflatten_device_tree() should return an error and let the caller 
>>> decide what to do.
>> Looks like i misunderstood v4 comments. Will change it to propagate 
>> an error in case of failure here to the handle_add_overlay_nodes() 
>> caller and that will further forward to error to toolstack.
>>>
>>> I suggest to read misc/xen-error-handling.txt to understand when to 
>>> use panic()/BUG() & co. For...
>>>
>>>
>>>> +
>>>>       ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
>>>>         dt_dprintk("  unflattening %lx...\n", mem);
>>>> @@ -2179,7 +2181,7 @@ dt_find_interrupt_controller(const struct 
>>>> dt_device_match *matches)
>>>>     void __init dt_unflatten_host_device_tree(void)
>>>>   {
>>>> -    __unflatten_device_tree(device_tree_flattened, &dt_host);
>>>> +    unflatten_device_tree(device_tree_flattened, &dt_host);
>>>
>>> ... this caller this should be a panic() (this is OK here because it 
>>> is boot code).
>>>
>>> But for your new caller, you should properly report the error back 
>>> the toolstack.
>> Understood, will change it in next version.
>>>
>>> Also, unflatten_dt_node() (called by __unflatten_device_tree()) 
>>> seems to have some failure cases. Can you explain why they are not 
>>> properly propagated in your case? Are you trusting the device-tree 
>>> to always be valid?
>> for dynamic_programming, while adding node(check patch: [XEN][PATCH 
>> v5 14/17] xen/arm: Implement device tree node addition 
>> functionalities), fdt_overlay_apply() is called before 
>> unflatten_device_tree() is called. fdt_overlay_apply() will catch the 
>> invalid device-tree overlay nodes.
>
> I agree that in theory fdt_overlay_apply() will catch invalid 
> device-tree. However, neither of the functions are exempts of bugs and 
> there is no code shared between the two (they are not even coming from 
> the same project).
>
> So we could end up in a situation where fdt_overlay_apply() works but 
> not unflatten_device_tree(). Therefore, I would rather prefer if the 
> latter function properly handle any errors.
>
> Note that unflatten_dt_node() already have check the validity of the 
> DT and will return. We just need to make sure they are treated as 
> error rather than been ignored.
Thanks for explanation. Will add error handling for unflatten_dt_node() 
and unflatten_device_tree() for failures.
>
> Cheers,
>



  reply	other threads:[~2023-04-14 18:28 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 19:16 [XEN][PATCH v5 00/17] dynamic node programming using overlay dtbo Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 01/17] xen/arm/device: Remove __init from function type Vikram Garhwal
2023-04-13  9:19   ` Michal Orzel
2023-04-14 17:28     ` Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 02/17] common/device_tree: change __unflatten_device_tree() Vikram Garhwal
2023-04-13  9:45   ` Michal Orzel
2023-04-13  9:53     ` Julien Grall
2023-04-13 10:03   ` Julien Grall
2023-04-14 17:51     ` Vikram Garhwal
2023-04-14 18:09       ` Julien Grall
2023-04-14 18:28         ` Vikram Garhwal [this message]
2023-04-11 19:16 ` [XEN][PATCH v5 03/17] xen/arm: Add CONFIG_OVERLAY_DTB Vikram Garhwal
2023-04-13  9:58   ` Michal Orzel
2023-04-13 19:27     ` Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 04/17] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 05/17] libfdt: overlay: change overlay_get_target() Vikram Garhwal
2023-04-13 13:11   ` Michal Orzel
2023-04-14 17:54     ` Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 06/17] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Vikram Garhwal
2023-04-13 13:40   ` Michal Orzel
2023-04-14 18:04     ` Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 07/17] xen/smmu: Add remove_device callback for smmu_iommu ops Vikram Garhwal
2023-04-17 10:24   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 08/17] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Vikram Garhwal
2023-04-17  9:14   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 09/17] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Vikram Garhwal
2023-04-17 10:35   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 10/17] xen/iommu: Introduce iommu_remove_dt_device() Vikram Garhwal
2023-04-17 10:49   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 11/17] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Vikram Garhwal
2023-04-14  1:50   ` Henry Wang
2023-04-17  9:41   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 12/17] common/device_tree: Add rwlock for dt_host Vikram Garhwal
2023-04-14  2:09   ` Henry Wang
2023-04-14 17:23     ` Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 13/17] xen/arm: Implement device tree node removal functionalities Vikram Garhwal
2023-04-17  8:08   ` Jan Beulich
2023-04-17 15:06   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 14/17] xen/arm: Implement device tree node addition functionalities Vikram Garhwal
2023-04-18  9:03   ` Michal Orzel
2023-04-11 19:16 ` [XEN][PATCH v5 15/17] tools/libs/ctrl: Implement new xc interfaces for dt overlay Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 16/17] tools/libs/light: Implement new libxl functions for device tree overlay ops Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 17/17] tools/xl: Add new xl command overlay for device tree overlay support Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 00/17] dynamic node programming using overlay dtbo Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 01/17] xen/arm/device: Remove __init from function type Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 02/17] common/device_tree: change __unflatten_device_tree() Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 03/17] xen/arm: Add CONFIG_OVERLAY_DTB Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 04/17] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 05/17] libfdt: overlay: change overlay_get_target() Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 06/17] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 07/17] xen/smmu: Add remove_device callback for smmu_iommu ops Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 08/17] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 09/17] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 10/17] xen/iommu: Introduce iommu_remove_dt_device() Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 11/17] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 12/17] common/device_tree: Add rwlock for dt_host Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 13/17] xen/arm: Implement device tree node removal functionalities Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 14/17] xen/arm: Implement device tree node addition functionalities Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 15/17] tools/libs/ctrl: Implement new xc interfaces for dt overlay Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 16/17] tools/libs/light: Implement new libxl functions for device tree overlay ops Vikram Garhwal
2023-04-11 19:16 ` [XEN][PATCH v5 17/17] tools/xl: Add new xl command overlay for device tree overlay support Vikram Garhwal

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=81b7b4ab-1765-67dc-0d0e-8fcf8a8f41d1@amd.com \
    --to=vikram.garhwal@amd.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --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.