From 61dac58c6a08fac80882fb47809d909731cac036 Mon Sep 17 00:00:00 2001 From: Yureka Date: Sat, 29 Aug 2026 14:58:47 +0200 Subject: [PATCH 1/2] kboot: disable wfi/wfit if wfi loses state Signed-off-by: Yureka (cherry picked from commit 3a69c73f59332b7b617835fd9a1c49dc89edcfd2) --- src/kboot.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/kboot.c b/src/kboot.c index eec8fa20..1a7532d5 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -313,8 +313,37 @@ static int dt_set_chosen(void) if (fdt_setprop(dt, node, "asahi,m1n1-stage2-version", m1n1_version, strlen(m1n1_version) + 1)) bail("FDT: couldn't set asahi,m1n1-stage2-version\n"); - if (dt_set_rng_seed_sep(node)) - return dt_set_rng_seed_adt(node); + if (dt_set_rng_seed_sep(node)) { + if (dt_set_rng_seed_adt(node)) + bail("FDT: couldn't set random seed"); + } + + if (cpu_features->apple_sysregs_unlocked) { + /* + * M4 and later lose architectural state in WFI and WFIT. Add the + * bootargs to prevent Linux from crashing in the idle loop and delay + * function. + */ + const char to_append[] = " idle=nop arm64.nowfxt"; + printf("FDT: appending to bootargs:%s\n", to_append); + + /* + * fdt_appendprop_string would create another property value: + * "a", "b". But we want "ab", so manually create or grow the prop, + * then overwrite the \0 of the existing string. + */ + int oldlen, newlen; + void *prop_data; + + if (!fdt_get_property(dt, node, "bootargs", &oldlen) || oldlen < 1) + oldlen = 1; + newlen = oldlen + sizeof(to_append) - 1; + + if (fdt_setprop_placeholder(dt, node, "bootargs", newlen, &prop_data)) + bail("FDT: failed to append to 'bootargs' property\n"); + + strncpy(prop_data + oldlen - 1, to_append, sizeof(to_append)); + } return 0; } From 9fc2bf1c8d6b1a74d3f89a35f8b7d4e03000c57c Mon Sep 17 00:00:00 2001 From: Yureka Date: Wed, 30 Sep 2026 09:07:16 +0200 Subject: [PATCH 2/2] kboot: fix inverted wfi bootargs condition Signed-off-by: Yureka (cherry picked from commit 9095a5ee70bf7ad970d9759ebc6fb6842b7def32) --- src/kboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kboot.c b/src/kboot.c index 1a7532d5..9e2dba7c 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -318,7 +318,7 @@ static int dt_set_chosen(void) bail("FDT: couldn't set random seed"); } - if (cpu_features->apple_sysregs_unlocked) { + if (!cpu_features->apple_sysregs_unlocked) { /* * M4 and later lose architectural state in WFI and WFIT. Add the * bootargs to prevent Linux from crashing in the idle loop and delay