From nobody Fri Oct 23 15:33:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790853418; cv=none; d=zohomail.com; s=zohoarc; b=Dj4F8Qzqh8MZ2xDzEt3lnh+UbpINGH5hNe3RQvK1cMoF36tR8s9CYUUHJ2DOeW6VIjnSPg/hZwku5kzzBfHCY0XUzH5wCEXVzZ9+yKFGJkMQAwze8CVMoce728aurRdfGImqZjJ1zG2Qoz6tF1klAYUJt1JgZB+v76415x6riSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790853418; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6moSCjWJjNEFzqSKa0SKXJwMyyg6GCB49Pw7Ja5Krs8=; b=fypApHfJEoSx08cZNaCIjuZ6vKkAr+yVJLkQn1kFvhj++1wQyitBDXCxcZiJMUAVZvZ8CnvrOqFgyHEf9MgLgTYPoGppM8LCktBJ8ccKiR+ZjatEsTePF+kzrADcflAbE1Gf175jk4+6rBI4ms70AeGR+LrkEunCnHWZ048JOtg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1790853418419971.9309104713594; Thu, 1 Oct 2026 04:16:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1438174.1657050 (Exim 4.92) (envelope-from ) id 1xCEmJ-0000Ew-8u; Thu, 01 Oct 2026 11:16:43 +0000 Received: by outflank-mailman (output) from mailman id 1438174.1657050; Thu, 01 Oct 2026 11:16:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xCEmJ-0000Ep-3r; Thu, 01 Oct 2026 11:16:43 +0000 Received: by outflank-mailman (input) for mailman id 1438174; Thu, 01 Oct 2026 11:16:41 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xCEmH-0008T1-HB for xen-devel@lists.xenproject.org; Thu, 01 Oct 2026 11:16:41 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xCEmG-002bSU-AJ for xen-devel@lists.xenproject.org; Thu, 01 Oct 2026 13:16:40 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6abe4115-e002-0a2a0a5209dd-0a2a4505aa14-8 for ; Thu, 01 Oct 2026 13:16:40 +0200 Received: from [74.125.225.141] (helo=mail-wm2-f13.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6abe4117-4cb1-0a2a45050019-4a7de18d9870-3 for ; Thu, 01 Oct 2026 13:16:40 +0200 Received: by mail-wm2-f13.google.com with SMTP id 5b1f17b1804b1-49e721b5503so60140115e9.0 for ; Thu, 01 Oct 2026 04:16:40 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48b068ff994sm5610427f8f.6.2026.10.01.04.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2026 04:16:38 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790853399; x=1791458199; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6moSCjWJjNEFzqSKa0SKXJwMyyg6GCB49Pw7Ja5Krs8=; b=tLnF5bFYyg4Vb+k89UHScL8W2sP1reieWzP5+H1wXSAgEGAVVlAy+uvmcDIfRo15nH gB61uHzG5c0GNZLqmY2R1nRVXfKKaVnON6k+Xi8UM61OiGnsy+/UlCJE3ML1LsIlWIsw gApd39kJr6UQCrIbKGEAW//4G4UTroDlSzbrQkEVyJif9bO6xz189VDTylmJSpVgvn4l PqTZ8gteUaU2geHiT18ZR2y4NzP84uhSSxbofY8s2Lbh4XXcsC2Nr7GO1n25ajsAITTL BL/gfIGAao1vPnoK7hctLArhv6B5kWO9Kb+p1/JnTknbZJBQE927xIAFXIHq3crr+qm5 pkrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790853399; x=1791458199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6moSCjWJjNEFzqSKa0SKXJwMyyg6GCB49Pw7Ja5Krs8=; b=Izyc5/weUXNYPZh2oz/Y0B4vSRzdQ88XaJCZZTvcsMuw7fId6WzIIvggAJnSMXi48D ATfAdlZCQcYzb5hw9TUrdIpsQPn7GGx0nXhOWEYqlYMdN1rPYdgmklW/hyXAhCeQa+70 S1SSJ0g4/PmXRZ5uNftFCMSH8BluGo0PF/VOYnqQ04FiWBryPyDMWWjsjIV0SLy7Dkbq fBSJsP1xuz6MvSDieqRiF1tEIIVXfMNfObBt1IsfMIrVzOBGh7LLZB2t6CNq+3aPRrxs 2Zzexp+efEbfHcm7nelhootUpccLKeuxgcoNl7XZzpnRmOLpuNTRFWKIVrdXG27hwAi3 EnIw== X-Gm-Message-State: AFuF++kiBjNPu5NEcvzin5+omYYY43+d6vudKAmuuzGjLGeULEFQe4go n1kOhD32uMvkBTPSLHDcjfLngbHX0zilAQYd/j9L5tBd1kz81whyqkW+Nf/lww== X-Gm-Gg: AYBFou1UGonglzZhqcPl68NqrWM85iSdDd/E0vb53SXK6hEfcOZrDX8j7yHkuMnorG6 vtnNOhWyQ3wqenHbh9QXIw975obDRErEaiL7shVU6jgQ1o91+VVv1f4ea2qb5wbnuxrxx7TqtIy 5/8Okdzo3PKjpmBmWOj1t763bJ91W8hgQMlAjZby7tfsTZQ4/ZPiiFJ+odymnsT8GihwcH/n+PE 0b2+mrs4BQu2V8+Nkx7rrXSlUcxEOTDMYR28h/qQVU1GFmfX/3VvPSL+Ho+n8nUix6811ta8ixG Q0F6Y5iD+lhmUaZRF+6GdUX6fCjsil/fU/IB4ADCWD4c4SxJPF1rgGIXJAhW635bUSsYROptWR8 ejhAdYscZkSGKduMpDvDhNyCgXFuDo+CsQLw+m+xwUyZDIgfJ/nBvy3kqcOE8MgroHfnRi6ByOs 4dVOBO5EpF9sWRpxem8cFYS/s6GSXiP89Br3xeSszqb0wyHrxlO2DSygikRT0RUReTdBXpGQ/HK Yg4fJBeyvD/jFgZA8EIjfz22kNj793sgcD/bVGj X-Received: by 2002:a05:600c:3144:b0:4a0:1c0e:b136 with SMTP id 5b1f17b1804b1-4a01c0ec65fmr64496175e9.29.1790853399202; Thu, 01 Oct 2026 04:16:39 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Bertrand Marquis Subject: [PATCH 1/2] xen/device-tree: add a helper to dump an FDT in DTS-like format Date: Thu, 1 Oct 2026 13:16:29 +0200 Message-ID: <20261001111630.112472-2-oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261001111630.112472-1-oleksii.kurochko@gmail.com> References: <20261001111630.112472-1-oleksii.kurochko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1790853400-243112A1-97988D2D/10/73395122804 X-purgate-type: spam X-purgate-size: 9391 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790853420696158500 Content-Type: text/plain; charset="utf-8" The device tree Xen builds for a dom0less domain is only ever consumed by the guest, so a mistake in it surfaces as an obscure failure inside the domain, far away from the code which produced the tree. Add device_tree_dump(). The output follows dtc's format so that a dump can be diffed against the source DTS or fed back to dtc; the value formatting heuristics are ported from dtc's utilfdt_print_data() for that reason. The walk itself goes through libfdt rather than decoding the tag stream by hand as dtc's fdtdump does. Dumping a whole tree is only useful while debugging and costs both code size and a lot of console output, hence CONFIG_DEVICE_TREE_DEBUG. Mention the dump in the help text of the option. Signed-off-by: Oleksii Kurochko --- xen/Kconfig.debug | 3 +- xen/common/device-tree/Makefile | 1 + xen/common/device-tree/dom0less-build.c | 4 + xen/common/device-tree/fdt-dump.c | 180 ++++++++++++++++++++++++ xen/include/xen/bootfdt.h | 13 ++ 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 xen/common/device-tree/fdt-dump.c diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index d900d926c555..664f50bf8a96 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -95,7 +95,8 @@ config DEVICE_TREE_DEBUG depends on DEVICE_TREE_PARSE help Device tree parsing and DOM0 device tree building messages are - logged in the Xen ring buffer. + logged in the Xen ring buffer. The device tree generated for each + dom0less domU is dumped there as well, in a DTS-like format. If unsure, say N here. =20 config SCRUB_DEBUG diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makef= ile index 9036e455d66a..959dd2a9fd30 100644 --- a/xen/common/device-tree/Makefile +++ b/xen/common/device-tree/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_DOMAIN_BUILD_HELPERS) +=3D domain-build.init.o obj-$(filter $(CONFIG_DOM0LESS_BOOT),$(CONFIG_HAS_DEVICE_TREE_DISCOVERY)) = +=3D dom0less-build.init.o obj-$(CONFIG_DOM0LESS_BOOT) +=3D dom0less-bindings.init.o obj-$(CONFIG_OVERLAY_DTB) +=3D dt-overlay.o +obj-$(CONFIG_DEVICE_TREE_DEBUG) +=3D fdt-dump.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) +=3D intc.o obj-$(CONFIG_DOMAIN_BUILD_HELPERS) +=3D kernel.o obj-$(CONFIG_STATIC_EVTCHN) +=3D static-evtchn.init.o diff --git a/xen/common/device-tree/dom0less-build.c b/xen/common/device-tr= ee/dom0less-build.c index fcbeb8adbd73..182201384faf 100644 --- a/xen/common/device-tree/dom0less-build.c +++ b/xen/common/device-tree/dom0less-build.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include #include @@ -587,6 +588,9 @@ static int __init prepare_dtb_domU(struct domain *d, st= ruct kernel_info *kinfo) if ( ret < 0 ) goto err; =20 + dt_dprintk("Device tree for %pd:\n", d); + device_tree_dump(kinfo->fdt); + return 0; =20 err: diff --git a/xen/common/device-tree/fdt-dump.c b/xen/common/device-tree/fdt= -dump.c new file mode 100644 index 000000000000..fc3d9eca5891 --- /dev/null +++ b/xen/common/device-tree/fdt-dump.c @@ -0,0 +1,180 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Dump a flattened device tree blob in a DTS-like format. + * + * is_printable_string() and print_value() are derived from + * util_is_printable_string() and utilfdt_print_data() in the device tree + * compiler (dtc). + * + * Copyright 2011 The Chromium Authors, All Rights Reserved. + * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc. + * util_is_printable_string contributed by + * Pantelis Antoniou + */ + +#include +#include +#include +#include +#include +#include + +/* Deeper nodes are still printed, but not indented any further. */ +#define DUMP_MAX_INDENT_DEPTH 32 + +/* Indentation, in characters, of a node at depth @depth. */ +static int __init indent_of(int depth) +{ + return 2 * min(depth, DUMP_MAX_INDENT_DEPTH); +} + +static bool __init is_printable_string(const void *data, unsigned int len) +{ + const char *s =3D data; + const char *se =3D s + len; + + /* A zero length property, or one which isn't NUL terminated, isn't on= e. */ + if ( (len =3D=3D 0) || (s[len - 1] !=3D '\0') ) + return false; + + while ( s < se ) + { + const char *ss =3D s; + + while ( (s < se) && *s && isprint(*s) ) + s++; + + /* Stopped on a non printable character, or the string is empty. */ + if ( (*s !=3D '\0') || (s =3D=3D ss) ) + return false; + + s++; + } + + return true; +} + +/* + * Print the value of a property, using the same heuristics as dtc: a list= of + * NUL terminated printable strings is printed as such, a value which is a + * multiple of 4 bytes as a list of cells, anything else as a byte string. + * + * The caller has already started the line (and with it selected the log + * level), so no XENLOG_* prefix may be used here. + */ +static void __init print_value(const void *data, unsigned int len) +{ + unsigned int i; + + /* Empty property, nothing to print. */ + if ( len =3D=3D 0 ) + return; + + if ( is_printable_string(data, len) ) + { + const char *s =3D data; + const char *end =3D data + len; + + printk(" =3D "); + while ( s < end ) + { + printk("\"%s\"", s); + s +=3D strlen(s) + 1; + if ( s < end ) + printk(", "); + } + } + else if ( IS_ALIGNED(len, sizeof(fdt32_t)) ) + { + const fdt32_t *cell =3D data; + + printk(" =3D <"); + for ( i =3D 0; i < len / sizeof(*cell); i++ ) + printk("%s0x%08x", i ? " " : "", fdt32_ld(&cell[i])); + printk(">"); + } + else + { + const uint8_t *byte =3D data; + + printk(" =3D ["); + for ( i =3D 0; i < len; i++ ) + printk("%s%02x", i ? " " : "", byte[i]); + printk("]"); + } +} + +static void __init print_properties(const void *fdt, int node, int indent) +{ + int prop; + + fdt_for_each_property_offset ( prop, fdt, node ) + { + const char *name; + const void *data; + int len; + + data =3D fdt_getprop_by_offset(fdt, prop, &name, &len); + if ( !data ) + { + printk(XENLOG_DEBUG "%*scouldn't read property at offset %d: %= s\n", + indent, "", prop, fdt_strerror(len)); + return; + } + + printk(XENLOG_DEBUG "%*s%s", indent, "", name); + print_value(data, len); + printk(";\n"); + } + + if ( (prop < 0) && (prop !=3D -FDT_ERR_NOTFOUND) ) + printk(XENLOG_DEBUG "%*scouldn't walk the properties: %s\n", + indent, "", fdt_strerror(prop)); +} + +void __init device_tree_dump(const void *fdt) +{ + int node, depth =3D 0; + /* Depth up to which nodes are open and still have to be closed. */ + int open_depth =3D 0; + + printk(XENLOG_DEBUG "/dts-v1/;\n"); + + /* + * fdt_next_node() signals the end of the subtree it was started on by + * making the depth negative, and only returns an error when the blob + * itself is malformed. + */ + for ( node =3D 0; (node >=3D 0) && (depth >=3D 0); + node =3D fdt_next_node(fdt, node, &depth) ) + { + const char *name =3D fdt_get_name(fdt, node, NULL); + + /* Close the nodes which aren't a parent of the current one. */ + while ( open_depth > depth ) + printk(XENLOG_DEBUG "%*s};\n", indent_of(--open_depth), ""); + + printk(XENLOG_DEBUG "%*s%s {\n", indent_of(depth), "", + (depth =3D=3D 0) ? "/" : (name ?: "")); + print_properties(fdt, node, indent_of(depth) + 2); + + open_depth =3D depth + 1; + } + + while ( open_depth > 0 ) + printk(XENLOG_DEBUG "%*s};\n", indent_of(--open_depth), ""); + + if ( node < 0 ) + printk(XENLOG_DEBUG "The device tree dump is incomplete: %s\n", + fdt_strerror(node)); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index 0e82ccea2f84..08983375209b 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -99,6 +99,19 @@ int device_tree_for_each_node(const void *fdt, int node, device_tree_node_func func, void *data); =20 +/* + * device_tree_dump - print a device tree blob in a DTS-like format + * @fdt: flat device tree. + * + * The tree is printed at debug log level and is only meant to be used for + * debugging, so it is a no-op unless CONFIG_DEVICE_TREE_DEBUG is enabled. + */ +#ifdef CONFIG_DEVICE_TREE_DEBUG +void device_tree_dump(const void *fdt); +#else +static inline void device_tree_dump(const void *fdt) {} +#endif + typedef enum { BOOTMOD_XEN, BOOTMOD_FDT, --=20 2.55.0 From nobody Fri Oct 23 15:33:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790853424; cv=none; d=zohomail.com; s=zohoarc; b=EfNK3lSR6tiDXFGdyu7h/eU9tGTMo90QFq/6YdtRvot1gNitYe4yckj2uf0Wf+AxqOsBJT60Rxab2sE7BYcUtbYjI3yO5EcHe0oIOt1J9QfMK+l+BFn9vvy8JX6VoPfSK5MHNKLVhJYf/JA5a5u9U9OUqOabPE1s7PIZtHGCDFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790853424; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kbE4+gPC0KovURIfC+5IoRX/rbVyUI3fgwu1ICNzI/c=; b=ixnO9EC/azRXzxDxaz6dp89E1tTDlgDAVHoqAGk7rVwo+yG+HgmNgndk9kJOjf6LujoulnMlOJAIWGFeky8fhb96HD9ZW5MiGbtZKygCzJaqD1Ar4j8I3K0NjZplmFszQojYaSuWDO3Exajys8aie9RgVvKMknHqs0a/+ifFa6k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1790853424818196.64803145774954; Thu, 1 Oct 2026 04:17:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1438175.1657056 (Exim 4.92) (envelope-from ) id 1xCEmJ-0000Gi-K6; Thu, 01 Oct 2026 11:16:43 +0000 Received: by outflank-mailman (output) from mailman id 1438175.1657056; Thu, 01 Oct 2026 11:16:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xCEmJ-0000GG-Bu; Thu, 01 Oct 2026 11:16:43 +0000 Received: by outflank-mailman (input) for mailman id 1438175; Thu, 01 Oct 2026 11:16:42 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xCEmI-0008T2-02 for xen-devel@lists.xenproject.org; Thu, 01 Oct 2026 11:16:42 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xCEmG-00Ha1J-Ti for xen-devel@lists.xenproject.org; Thu, 01 Oct 2026 13:16:40 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6abe4111-8faa-0a2a0a5109dd-0a2a45079d0c-22 for ; Thu, 01 Oct 2026 13:16:40 +0200 Received: from [74.125.225.140] (helo=mail-wm2-f12.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6abe4118-b4ea-0a2a45070019-4a7de18c93e1-3 for ; Thu, 01 Oct 2026 13:16:40 +0200 Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-4a003bd18e5so24167325e9.0 for ; Thu, 01 Oct 2026 04:16:40 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48b068ff994sm5610427f8f.6.2026.10.01.04.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2026 04:16:39 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790853400; x=1791458200; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kbE4+gPC0KovURIfC+5IoRX/rbVyUI3fgwu1ICNzI/c=; b=cguSkl/aUkY3mzj0CR7s9c4XPcJ/zwky962U6mF1PLoewmjit9Mt6mCUFkTOZGe76r 53EThSmC9DwaahT7AfX6Fou2/zV0bRJsxJTQ/+X4G3KLQhpxRdLdgdvVUHnJpevuOchJ l3j+eFAdil/qdgY+1qI5oNWZ3yWRr3AJqbdBWHd47YQ99FeIEOi1ZE4h9j9jDWTB1fy5 L01R3z4YT3rmy3VCD8ulTnwpef8MAnXjGgGUN99FLkRkyDSYvai/InznDKB7rn+n6DVu gcCBhCOqZmbhG4v5NCV26o63F2uBX1B5OrJURBHAtuA5HnlUpVI2UGsjnY2ga8hrZ0T9 vB3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790853400; x=1791458200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kbE4+gPC0KovURIfC+5IoRX/rbVyUI3fgwu1ICNzI/c=; b=Qc7i70ZTZxqWA9SdSPYZqghnqBNLPBbIrpDHYYTkUq/Vg5BALjzD+sPg1wL6IKqwSI pnFtiXBldU2Um0drAmGhfi0MfK0e78qtn1WmQuxLAg4yMjp9enQ24hBKDvrFD1Oua5CY Sw//a4PQkkdVMzrZpP68zpSw1wt0RiZjrxl7hrta7yoXdJpZWpql8Yyz5/id+f8d0Zii YZkDcuG+u/+xD1uVdSaPP0vl6TaGRZ0WYjtMqXj2Xp10yWU43sguU2q0X3NoaS/wR+KT 6tNOLC2w2qtuiJKspq6NfYw8IrWwaSQZ2CXmcOXdjNTPnMmUnqaoB/5C5f1Zdbh2wQIn GtVA== X-Gm-Message-State: AFuF++m6miZt9P7BhVI8ETQbiupi31V23h40LbbSnDsBhMZSXx6ZLVWn x7uWGSi5AxI+NhoNpfK1duJ3jdbYrgrYirQwSV2KLldwoF3UEk0kmC8539eyrA== X-Gm-Gg: AYBFou22/6nLOUyNwvVqdR5LOCgNvqoi7WowxDU61cY6cZa0gVfiY5O/6QKh/DL3yz5 riPncbkdiHCIeJUHaI6sOxW2K38HM7em50yxLEevqAQubsyukpMMPzvhSJQHbcc9wDaaOhPJfyG DDHvvmYmVS3ODTugObJknU3XBk/fmy0chhgjcaRZvbNrR9alArxiJhCn8uTumqMBLUaJT2tsqpr alS+hCOewjV3aswnVHl9ucOCr978VjJGwqLyNDn1MS4EUxStI2ytwzmZ6hbL4up82L0Y3tRfMFO Q0p44Q4Y3F23KJKoim3L36DJkKsjqS86DZ0bmUhTCr8KNIJyStd2QxOgxVQZxlEAD6ecuY9cRc8 XkZo8gyP92JPTtd6XZsVR0iuhH/QWd1+a/EdQ46N3wnn5wTBhPb2SOktQKwmdskZEdTM0Bfdhme 2rbJp6I6t4pKfmqAsODExRo2Agsyra8SBCjdUsnTfHNsvx8AErRolh+CBM41Qz1g27NbcnHhM3l 9LxbOM2EHQVx/hsshCrLczW9p8UkOcFOF0tB63wmiSkqXDCw+M= X-Received: by 2002:a05:600c:c1c8:20b0:4a0:2488:71cc with SMTP id 5b1f17b1804b1-4a0248872a5mr11942715e9.32.1790853400220; Thu, 01 Oct 2026 04:16:40 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 2/2] xen/device-tree: move discard_initial_modules() to common code Date: Thu, 1 Oct 2026 13:16:30 +0200 Message-ID: <20261001111630.112472-3-oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261001111630.112472-1-oleksii.kurochko@gmail.com> References: <20261001111630.112472-1-oleksii.kurochko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1790853400-36EDEAE4-BB1535DB/10/73395122804 X-purgate-type: spam X-purgate-size: 4822 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790853426666158500 Content-Type: text/plain; charset="utf-8" Everything discard_initial_modules() touches is already common code: bootinfo.modules, using_static_heap and fw_unreserved_regions(). Move it out of Arm into common/device-tree/bootinfo.c, next to the boot allocator handling of the same memory, and declare it in xen/bootinfo.h, so that other device-tree based architectures can reuse it instead of growing a copy of their own. The arch-specific remove_early_mappings() is not moved along with it: how the early FDT mapping is torn down is up to the architecture. As the DTB is one of the boot modules being released, the mapping has to go once they are discarded, so call it from start_xen() right after discard_initial_modules(), which keeps the common function free of any arch dependency. While moving it, use unsigned int for the loop counter and replace the "goto out" by a plain return, as there is nothing left to do at the label. No functional change. Signed-off-by: Oleksii Kurochko Reviewed-by: Michal Orzel --- xen/arch/arm/include/asm/setup.h | 2 -- xen/arch/arm/setup.c | 35 ++----------------------------- xen/common/device-tree/bootinfo.c | 30 ++++++++++++++++++++++++++ xen/include/xen/bootinfo.h | 8 +++++++ 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index c491c567298f..02fdf2b56c9c 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -40,8 +40,6 @@ int acpi_make_efi_nodes(void *fdt, struct membank tbl_add= []); =20 void create_dom0(void); =20 -void discard_initial_modules(void); - void init_pdx(void); void setup_mm(void); =20 diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 16f899dff57b..a65c3d2a655e 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -210,39 +210,6 @@ static void __init processor_id(void) processor_setup(); } =20 -void __init discard_initial_modules(void) -{ - struct boot_modules *mi =3D &bootinfo.modules; - int i; - - /* - * When using static heap feature, don't give boot_modules memory back= to - * the heap allocator - */ - if ( using_static_heap ) - goto out; - - for ( i =3D 0; i < mi->nr_mods; i++ ) - { - paddr_t s =3D mi->module[i].start; - paddr_t e =3D s + PAGE_ALIGN(mi->module[i].size); - - if ( mi->module[i].kind =3D=3D BOOTMOD_XEN ) - continue; - - if ( !mfn_valid(maddr_to_mfn(s)) || - !mfn_valid(maddr_to_mfn(e)) ) - continue; - - fw_unreserved_regions(s, e, init_domheap_pages, 0); - } - - mi->nr_mods =3D 0; - - out: - remove_early_mappings(); -} - /* Relocate the FDT in Xen heap */ static void __init relocate_fdt(const void **dtb_vaddr, size_t dtb_size) { @@ -509,6 +476,8 @@ void asmlinkage __init noreturn start_xen(unsigned long= fdt_paddr) */ discard_initial_modules(); =20 + remove_early_mappings(); + heap_init_late(); =20 init_constructors(); diff --git a/xen/common/device-tree/bootinfo.c b/xen/common/device-tree/boo= tinfo.c index c637c45ad594..6772bf2df002 100644 --- a/xen/common/device-tree/bootinfo.c +++ b/xen/common/device-tree/bootinfo.c @@ -471,6 +471,36 @@ void __init populate_boot_allocator(void) } } =20 +void __init discard_initial_modules(void) +{ + struct boot_modules *mi =3D &bootinfo.modules; + unsigned int i; + + /* + * When using static heap feature, don't give boot_modules memory back= to + * the heap allocator + */ + if ( using_static_heap ) + return; + + for ( i =3D 0; i < mi->nr_mods; i++ ) + { + paddr_t s =3D mi->module[i].start; + paddr_t e =3D s + PAGE_ALIGN(mi->module[i].size); + + if ( mi->module[i].kind =3D=3D BOOTMOD_XEN ) + continue; + + if ( !mfn_valid(maddr_to_mfn(s)) || + !mfn_valid(maddr_to_mfn(e)) ) + continue; + + fw_unreserved_regions(s, e, init_domheap_pages, 0); + } + + mi->nr_mods =3D 0; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index dbf492c2e36e..60ef25f3cf83 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -214,4 +214,12 @@ void fw_unreserved_regions(paddr_t s, paddr_t e, void (*cb)(paddr_t ps, paddr_t pe), unsigned int first); =20 +/* + * Return the memory occupied by the boot modules to the heap allocator. + * + * It needs to be called **before** heap_init_late() so that the released + * modules are scrubbed (unless suppressed). + */ +void discard_initial_modules(void); + #endif /* XEN_BOOTINFO_H */ --=20 2.55.0