Skip to contentSkip to conversation

Validate device tree node in SCMI/Power/IOMMU

PATCH New Peng Fan (OSS) 1 participant 4 messages Feb 10 IOMMU

lore
Share & tools
lore
#0 lore raw

cover Validate device tree node in SCMI/Power/IOMMU

commit 0535e46d55d ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c"), causes i.MX9 SCMI based platforms boot failure.
SPL panic in fdt_check_node_offset_()->fdt_next_tag(), because offset is -1 and SPL_OF_LIBFDT_ASSUME_MASK is 0xFF.

fdt_check_node_offset_()

       |->fdt_next_tag()
             |->tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);  #tagp is NULL
	            |->tag = fdt32_to_cpu(*tagp);                 #panic here

In [1], Ye report the issue, but per Tom:
"In SPL we must assume a perfect device tree has been passed to us, both for design reasons (it's not a user interactively, we built it, or it came from some other firmware stack) as well as practical (performing the sanity tests would grow all platforms by several kilobytes and overflow size constraints). I think the SCMI code needs to be reworked, in short"

So we need to add a check in scmi transport driver, also need to add a check in dev_power_domain_ctrl and iommu. Similar to the check in pinctrl_select_state and the check before call into clk_set_defaults, if ofnode is not valid, directly bypass. With this change, we could still keep SPL_OF_LIBFDT_ASSUME_MASK as 0xFF.

https://lore.kernel.org/u-boot/20260207141750.GB2603314@bill-the-cat/

---
Peng Fan (3):
firmware: scmi: Validate device tree node before setup channel
power: domain: Validate device tree node in dev_power_domain_ctrl
iommu: Validate device tree node in dev_iommu_enable

 drivers/firmware/scmi/mailbox_agent.c      | 2 +-
 drivers/firmware/scmi/optee_agent.c        | 3 ++-
 drivers/iommu/iommu-uclass.c               | 3 +++
 drivers/power/domain/power-domain-uclass.c | 3 +++
 4 files changed, 9 insertions(+), 2 deletions(-)

---
base-commit: b99da05e1538b8fa153322da82917af2aa27e1d6
change-id: 20260210-scmi-fix-8f8ae5f6abce

Best regards,

Signature · 1 line
Peng Fan <[email protected]>
#1 lore raw

PATCH 1/3 firmware: scmi: Validate device tree node before setup channel

From: Peng Fan <[email protected]>

SCMI base protocol device does not have a device tree, it should use and need to use the agent base channel.

For scmi_base.[x], there is no real device tree node for it. ofnode_null() is assigned as the device tree node for scmi base protocol device:
commit 7eb4eb541c14 ("firmware: scmi: install base protocol to SCMI agent")

However with recent update in commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c"), SPL panic in fdt_check_node_offset_()->fdt_next_tag(), because offset is -1 and SPL_OF_LIBFDT_ASSUME_MASK is 0xFF.

So add a check in x_get_channel() to validate the protocol devices' ofnode.

---
 drivers/firmware/scmi/mailbox_agent.c | 2 +-
 drivers/firmware/scmi/optee_agent.c   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/firmware/scmi/mailbox_agent.c +1 -1
index 16a82f55ab7..cda94565de5 100644
@@ -101,7 +101,7 @@ static int scmi_mbox_get_channel(struct udevice *dev,
 	struct scmi_mbox_channel *chan;
 	int ret;
 
-	if (!dev_read_prop(protocol, "shmem", NULL)) {
+	if (!dev_has_ofnode(protocol) || !dev_read_prop(protocol, "shmem", NULL)) {
 		/* Uses agent base channel */
 		*channel = container_of(base_chan, struct scmi_channel, ref);
 
drivers/firmware/scmi/optee_agent.c +2 -1
index 631625d715b..7170bd1e682 100644
@@ -331,7 +331,8 @@ static int scmi_optee_get_channel(struct udevice *dev,
 	u32 channel_id;
 	int ret;
 
-	if (dev_read_u32(protocol, "linaro,optee-channel-id", &channel_id)) {
+	if (!dev_has_ofnode(protocol) ||
+	    dev_read_u32(protocol, "linaro,optee-channel-id", &channel_id)) {
 		/* Uses agent base channel */
 		*channel = container_of(base_chan, struct scmi_channel, ref);
 
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/3 power: domain: Validate device tree node in dev_power_domain_ctrl

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Similar to pinctrl_select_state(), add dev_has_ofnode() check before doing the real work. Device(scmi_base.0) does not have a real device node, ofnode_null() is assigned as the device tree node for scmi base protocol device:
'commit 7eb4eb541c14 ("firmware: scmi: install base protocol to SCMI agent")'

However with recent update in
'commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")', SPL panic in fdt_check_node_offset_()->fdt_next_tag(), because offset is -1 and SPL_OF_LIBFDT_ASSUME_MASK is 0xFF.

So need to validate device tree node.

---
 drivers/power/domain/power-domain-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/power/domain/power-domain-uclass.c +3 -0
index d9fa8ad4bd2..cea68945cbd 100644
@@ -180,6 +180,9 @@ static int dev_power_domain_ctrl(struct udevice *dev, bool on)
 	struct power_domain pd;
 	int i, count, ret = 0;
 
+	if (!dev_has_ofnode(dev))
+		return 0;
+
 	count = dev_count_phandle_with_args(dev, "power-domains",
 					    "#power-domain-cells", 0);
 	for (i = 0; i < count; i++) {
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/3 iommu: Validate device tree node in dev_iommu_enable

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Similar to pinctrl_select_state(), add dev_has_ofnode() check before doing the real work. Device(scmi_base.0) does not have a real device node, ofnode_null() is assigned as the device tree node for scmi base protocol device:
'commit 7eb4eb541c14 ("firmware: scmi: install base protocol to SCMI agent")'

However with recent update in
'commit 0535e46d55d7 ("scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c")', SPL panic in fdt_check_node_offset_()->fdt_next_tag(), because offset is -1 and SPL_OF_LIBFDT_ASSUME_MASK is 0xFF.

So need to validate device tree node.

---
 drivers/iommu/iommu-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/iommu-uclass.c +3 -0
index bb31cd519d2..31b40e5713a 100644
@@ -79,6 +79,9 @@ int dev_iommu_enable(struct udevice *dev)
 	const struct iommu_ops *ops;
 	int i, count, ret = 0;
 
+	if (!dev_has_ofnode(dev))
+		return 0;
+
 	count = dev_count_phandle_with_args(dev, "iommus",
 					    "#iommu-cells", 0);
 	for (i = 0; i < count; i++) {
Signature · 1 line
2.51.0