[RFC PATCH 4/4] arm64: realm: Move RSI detection earlier

Suzuki K Poulose
2026-04-29T10:36:20Z

As discussed in [0], Realm world detection happens too late for making the
decision for the Linear map granularity for Arm64. If the boot CPU doesn't support
BBML2_NOABORT, it is difficult to break the mapping to PTE level. To solve this
try probing the Realm world earlier, now that we probe the PSCI/SMCCC earlier.
Like the PSCI probe, if we fall back to the later point if the SMCCC probe
wasn't successful. We should probably add a WARNING/panic the system if the
BBML2_NOABORT is not supported on the boot CPU and linear map was created
with block mappings. This may case avoided by using rodata=full.

[0] https://lore.kernel.org/all/20260330161705.3349825-2-ryan.roberts@arm.com/

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
arch/arm64/include/asm/rsi.h | 1 +
arch/arm64/kernel/rsi.c | 23 ++++++++++++++++++++++-
arch/arm64/kernel/setup.c | 3 ++-
3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/rsi.h b/arch/arm64/include/asm/rsi.h
index 88b50d660e85..4456bf0a1f23 100644
--- a/arch/arm64/include/asm/rsi.h
+++ b/arch/arm64/include/asm/rsi.h
@@ -14,6 +14,7 @@

DECLARE_STATIC_KEY_FALSE(rsi_present);

+void __init arm64_early_rsi_init(void);
void __init arm64_rsi_init(void);

bool arm64_rsi_is_protected(phys_addr_t base, size_t size);
diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c
index c64a06f58c0b..2d2befae2c75 100644
--- a/arch/arm64/kernel/rsi.c
+++ b/arch/arm64/kernel/rsi.c
@@ -138,10 +138,14 @@ static int realm_ioremap_hook(phys_addr_t phys, size_t size, pgprot_t *prot)
return 0;
}

-void __init arm64_rsi_init(void)
+static bool rsi_probed = 0;
+
+static void __init rsi_probe(void)
{
if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_SMC)
return;
+
+ rsi_probed = true;
if (!rsi_version_matches())
return;
if (WARN_ON(rsi_get_realm_config(&config)))
@@ -159,6 +163,23 @@ void __init arm64_rsi_init(void)
static_branch_enable(&rsi_present);
}

+void __init arm64_early_rsi_init(void)
+{
+ rsi_probe();
+}
+
+void __init arm64_rsi_init(void)
+{
+ if (rsi_probed)
+ return;
+
+ rsi_probe();
+ /*
+ * TODO: Warn if we don't have BBML2_NOABORT and page mapping is
+ * not used.
+ */
+}
+
static struct platform_device rsi_dev = {
.name = RSI_PDEV_NAME,
.id = PLATFORM_DEVID_NONE
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 595aff6f17d5..0664130dd791 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -340,7 +340,8 @@ static void __init early_psci_init(void)
return;
}

- psci_early_init_conduit(conduit);
+ if (!psci_early_init_conduit(conduit))
+ arm64_early_rsi_init();
}

void __init __no_sanitize_address setup_arch(char **cmdline_p)
--
2.43.0