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

Re: [PATCH 5/6] xen/dt-overlay: support phandle-based targeting in overlay_get_nodes_info


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Thu, 16 Apr 2026 10:36:56 +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=arcselector10001; 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=2MRUbZqKdvZ4HtnafZuZfQfVQ21MvGwlzSggyh3dnjQ=; b=dVU1rsL9K96LZBFDMA9HtX9Wbmo7oXf55QzH1iPyiUTRwpK6dmk6/U5AQ7XQh2aXfK/TLEmt4+6hwESkZSItdVBgHSXGFbTVUndhCq8r8hegTJl0ddnPQqK/4CBA0rwwNyaXQ/6qWtIbri6DQDZMwGg5gqjXOLZulyukJh5boynbj7mLXed8a6Qnh3cNeOilUjgm2rquGHtABwCqV0BdGx7l8/ntfv2LZubme2eVxpw741J2RP/wcA+gBDVtOYImX/ieyxbpEy5DgLZj6KdhwsizgG8xhdHqu0X6VN98xvJ34MHoezur2cTb73OJ0VVaaUB6xeS9czZuywmrx49+bg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l2LPIpibjWeo7+C0hwUXALvLgA3+gKBnN6bvOuEBzgL0F8lxU5d/mDA9qa7OQ0frsV+Xy5nbn4S23SW9kUh52D02QuBFMweIKf1ShB7GaRF57NBCV5H5zEoYnI1AQCmeOUzzIiZ3eVEH9t5X3hqx1HgcFsFtntowWoHICPY+8ZhXE9OUJ6l9f/3RAio7EEOjHsQIg86nzF/SGAa15CiehPkpdzbqVP+kcO+iPpZGPQJDJeMJc5fRte21LXre4JG7jlQMi7DYCtcztbuAJgYJGQw0/m0A5zgx615U5ynoB9zDXsMokhQwhSO6CdqssnkRL2kMqhlm0hdyXhxb+ZK8Uw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Bertrand Marquis" <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Thu, 16 Apr 2026 08:37:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 16/04/2026 10:21, Luca Fancellu wrote:
>>>>
>>>> diff --git a/xen/common/device-tree/dt-overlay.c 
>>>> b/xen/common/device-tree/dt-overlay.c
>>>> index d3d4669718ac..a0dee7edb7e5 100644
>>>> --- a/xen/common/device-tree/dt-overlay.c
>>>> +++ b/xen/common/device-tree/dt-overlay.c
>>>> @@ -286,6 +286,63 @@ static unsigned int overlay_node_count(const void 
>>>> *overlay_fdt)
>>>>    return num_overlay_nodes;
>>>> }
>>>>
>>>> +/*
>>>> + * Resolve the target path for an overlay fragment.
>>>> + *
>>>> + * This is called before fdt_overlay_apply(), so phandle-based targets
>>>> + * (target = <&label>) are still unresolved (compiled as 0xffffffff by 
>>>> DTC).
>>>> + * Handle the two cases that actually occur:
>>>> + *  - target-path property: the path string is used directly,
>>>> + *  - target = <&label>: the label is looked up in the overlay's 
>>>> __fixups__
>>>> + *    node, then resolved to a path via the base DTB's __symbols__ node.
>>>> + *
>>>> + * Returns a pointer into the FDT on success, NULL on failure.
>>>> + */
>>>> +static const char *overlay_get_target_path(const void *fdt, const void 
>>>> *fdto,
>>>> +                                           int fragment)
>>>> +{
>>>> +    const char *path, *fragment_name;
>>>> +    int fixups_off, symbols_off, property;
>>>> +    int fragment_name_len;
>>>> +
>>>> +    /* Try target-path first (string-based targeting) */
>>>> +    path = fdt_getprop(fdto, fragment, "target-path", NULL);
>>>> +    if ( path )
>>>> +        return path;
>>>> +
>>>> +    /* Phandle-based target: resolve via __fixups__ and __symbols__ */
>>>> +    fixups_off = fdt_path_offset(fdto, "/__fixups__");
>>>> +    if ( fixups_off < 0 )
>>>> +        return NULL;
>>>> +
>>>> +    symbols_off = fdt_path_offset(fdt, "/__symbols__");
>>>> +    if ( symbols_off < 0 )
>>>> +        return NULL;
>>>> +
>>>> +    fragment_name = fdt_get_name(fdto, fragment, &fragment_name_len);
>>>> +    if ( !fragment_name )
>>>> +        return NULL;
>>>> +
>>>> +    fdt_for_each_property_offset(property, fdto, fixups_off)
>>>> +    {
>>>> +        const char *val, *label, *p;
>>>> +        int val_len;
>>>> +
>>>> +        val = fdt_getprop_by_offset(fdto, property, &label, &val_len);
>>>> +        if ( !val )
>>>> +            continue;
>>>> +
>>>> +        /* Match entries of the form "/<fragment_name>:target:0" */
>>>> +        for ( p = val; p < (val + val_len); p += (strlen(p) + 1) )
>>>
>>> what guarantees us that p will be null terminated, if a malformed overlay
>>> is passed this strlen can read past the string, we can use strnlen having as
>>> upper bound a counter=val_len? decreasing counter each iteration.
>>>
>>> Or do you think it can never happen?
>> In theory it can happen, in practice this is something not usually taken into
>> account. But we can surely stay on the defensive side and do a single check
>> right after fdt_getprop_by_offset to catch not-NUL terminated stringlist:
>> if ( !val || !val_len || val[val_len - 1] != '\0' )
> 
> Ok, do we also want to print a warning in case of malformed properties instead
> of ignoring and continue?
That's really a matter of taste. I would not do it unless you really want to.

~Michal




 


Rackspace

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