[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: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Wed, 15 Apr 2026 15:36:03 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=amd.com 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=arm.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=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=V30waawHWtz8KtOq537okWU7QDZkzMvpmsGajsBBg08=; b=q8W44l22SHK8BxtmmaSzXoJ8EgRdiH/fOS6b/FrfpXBvDlWBiwe8LmKQsHcvw7hcHG01Nf2y4/W9RVssW6ZQuu1T9srjEGJqqI2m+WTETtI7PS54FSIejVlmBVCnvf4Y5lzLMd7YqlsAMK8SfurGKayvqmKcCVzMoUNTm+lOgdMcAd575fgYGX9arGqdapluLyAU7qlUkB0SfvFeNAeK8SUYppPpG55WpS9oA7QJj91zOSPWMTswIS89BDUaQ7aGSEwYQ2D1z2K4bUi8+dyN+Gj1EQFwQp0JDEoCz8zbXy6xHk6tP0Ttl0MDXgyZ6vTxWR6iAnEdKxkzih/87nHy2A==
  • 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=V30waawHWtz8KtOq537okWU7QDZkzMvpmsGajsBBg08=; b=rxnKH1kJe9JMCQ1Dek7e0hC4RZKS5mPAKf4di8drdk5MSv9dYR8vx8Dc/+EBGBAK+KPi3r+4q2X702grjc53bq56zjmozCq4N+pehHEjh8xHhbjmLwqMgilxOl3/u9JnqY6v9Byv97kOwmAfRrAQ4GBDiKxIElSEa9u01SxHYui6PvdE0Uw1CuZMS0Kor6DVpjOkaEnqwPQ7U9WmirItoKjYuKRoZNH8em0xFFb2q+/Z4iBcuzxVfWefn9JOgaIiFyYUXVnoESoZW74z48Xazvc58LEZjw+mMtFiajlO5LMzSYGaQNr6mFRvV0YQXJoqUhe/KG/it2UW9F1wnGw+hA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=ei5P0W6U2WHq2t1SjuYItEMXYguP5Q3ymWws7Fkd1VSIwvU3+Snw7dLws7482u2/99ORBEGG+Y6J5YUNQ4p+Ql2i7DOm5+A5nn8TfRDjlo1XDMpXBUXQAJpjfRcqLs4uMRpRhSJafVO4OWAGJ2ctpRoBVpO/jMmZu4bRqMxQlsTnkHGNkZEEH2LAPzgB5YZwx5z8r2x+1uJh3dxFE4AWUQ6xeqcPwy/Nm+oLM0D6d6uRBCtBpS5Oe7Y65xNrEWLP7NSpuyt9NNUAm6BWADzLBn9ciEO4YMV2Aqcs557Rlos+JxfJQxZi5LNH0V7QBNuIlA/ljL+z9RmT/kLhKeEmyA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vwNIiXcghd6Cl/99F7YsYgDVN8IYiiGPoGZbQFoAx7bnbqQ8eHRJ09CcAuDG6oHjSspnUasAoBGiONVwBqNWuYfMSpN/FNWXeYa6BqhFuy3gXca3MsTFeLqpewcjDVPNHQ8rGZCrssIqL4SLV+08nCtkSVT4dGbxa1Z2ztccV3zJt2U2WAEZSw2OzY244BUbV5ChWNUPeNHywZxSvogG8AJFa9Hby6vLjYjSNQrHYY8lh+irFRGLfgPldASgKQJrDtORzO5T6j50UWWKcF8ze09tTJBZVq7MExIcW5QqqEKn7dJwi9QTksiCBUIcVA2iLQ5LoXndtcPQfZ5EJBA7uQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Wed, 15 Apr 2026 15:37:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHczMxJn1pwTu5+sUmN2MgYtFAQK7XgQWaA
  • Thread-topic: [PATCH 5/6] xen/dt-overlay: support phandle-based targeting in overlay_get_nodes_info

Hi Michal,

> On 15 Apr 2026, at 12:36, Michal Orzel <michal.orzel@xxxxxxx> wrote:
> 
> overlay_get_nodes_info() is called before fdt_overlay_apply() to extract
> target paths from the overlay. This fails for overlays using phandle-based
> targeting (target = <&label>) because DTC compiles these as unresolved
> fixups (target = <0xffffffff>), causing fdt_overlay_target_offset() to
> return -FDT_ERR_BADPHANDLE. Prior to this change users were forced to
> manually modify the dtbo (even for hwdom) to switch from target to
> target-phandle by manually inspecting also the host DTB.
> 
> Introduce overlay_get_target_path() which directly handles the two
> targeting cases that occur before fixup resolution:
> - target-path: the string property is returned directly.
> - target = <&label>: the label is found in the overlay's __fixups__
>   node, then resolved to a path via the base DTB's __symbols__ node.
> 
> Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
> ---
> xen/common/device-tree/dt-overlay.c | 65 ++++++++++++++++++++++++++---
> 1 file changed, 59 insertions(+), 6 deletions(-)
> 
> 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?

> +            if ( p[0] == '/' &&
> +                 !strncmp(p + 1, fragment_name, fragment_name_len) &&
> +                 !strcmp(p + 1 + fragment_name_len, ":target:0") )
> +                return fdt_getprop(fdt, symbols_off, label, NULL);
> +    }
> +
> +    return NULL;
> +}
> +
> /*
>  * overlay_get_nodes_info gets full name with path for all the nodes which
>  * are in one level of __overlay__ tag. This is useful when checking node for
> @@ -298,7 +355,6 @@ static int overlay_get_nodes_info(const void *fdto, char 
> **nodes_full_path)
> 
>     fdt_for_each_subnode(fragment, fdto, 0)
>     {
> -        int target;
>         int overlay;
>         int subnode;
>         const char *target_path;
> @@ -307,11 +363,8 @@ static int overlay_get_nodes_info(const void *fdto, char 
> **nodes_full_path)
>         if ( overlay < 0 )
>             continue;
> 
> -        target = fdt_overlay_target_offset(device_tree_flattened, fdto,
> -                                           fragment, &target_path);
> -        if ( target < 0 )
> -            return target;
> -
> +        target_path = overlay_get_target_path(device_tree_flattened, fdto,
> +                                              fragment);
>         if ( target_path == NULL )
>             return -EINVAL;
> 
> -- 
> 2.43.0
> 
> 

Cheers,
Luca





 


Rackspace

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