Skip to contentSkip to conversation

lib: utils: Fix fdt_parse_aclint_node() for non-contiguous hartid

PATCH Applied Anup Patel 2 participants 2 messages Jun 6, 2025 – Jun 16, 2025

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 lib: utils: Fix fdt_parse_aclint_node() for non-contiguous hartid

Currently, the fdt_parse_aclint_node() does not handle non-contiguous hartid correctly and returns incorrect first_hartid and hart_count. This is because the for-loop in fdt_parse_aclint_node() skips a hartid for which hartindex is not available (aka corresponding CPU DT node is disabled).

For example, on a platform with 4 HARTs (hartid 0, 1, 2, and 3) where CPU DT nodes with hartid 0 and 2 are disabled, the fdt_parse_aclint_node() returns first_hartid = 1 and hart_count = 3 which is incorrect.

To address the above issue, drop the sbi_hartid_to_hartindex() check from the for-loop of fdt_parse_aclint_node().

Fixes 5e90e54a1a53 ("lib: utils:Check that hartid is valid")
---
 lib/utils/fdt/fdt_helper.c | 3 ---
 1 file changed, 3 deletions(-)
lib/utils/fdt/fdt_helper.c +0 -3
index b2d91fdf..4c0e8221 100644
@@ -1013,9 +1013,6 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,
 		if (rc)
 			continue;
 
-		if (SBI_HARTMASK_MAX_BITS <= sbi_hartid_to_hartindex(hartid))
-			continue;
-
 		if (match_hwirq == hwirq) {
 			if (hartid < first_hartid)
 				first_hartid = hartid;
Signature · 7 lines
2.43.0


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#1 lore raw
Quoted 11 lines · Anup Patel

Currently, the fdt_parse_aclint_node() does not handle non-contiguous hartid correctly and returns incorrect first_hartid and hart_count. This is because the for-loop in fdt_parse_aclint_node() skips a hartid for which hartindex is not available (aka corresponding CPU DT node is disabled).

For example, on a platform with 4 HARTs (hartid 0, 1, 2, and 3) where CPU DT nodes with hartid 0 and 2 are disabled, the fdt_parse_aclint_node() returns first_hartid = 1 and hart_count = 3 which is incorrect.

Quoted 6 lines

To address the above issue, drop the sbi_hartid_to_hartindex() check from the for-loop of fdt_parse_aclint_node().

Fixes 5e90e54a1a53 ("lib: utils:Check that hartid is valid")

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 21 lines
---
 lib/utils/fdt/fdt_helper.c | 3 ---
 1 file changed, 3 deletions(-)
lib/utils/fdt/fdt_helper.c +0 -4
index b2d91fdf..4c0e8221 100644
@@ -1013,9 +1013,6 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,
                if (rc)
                        continue;
 
-               if (SBI_HARTMASK_MAX_BITS <= sbi_hartid_to_hartindex(hartid))
-                       continue;
-
                if (match_hwirq == hwirq) {
                        if (hartid < first_hartid)
                                first_hartid = hartid;
--

2.43.0

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi