From nobody Sat Jun 13 20:27:50 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BE4A48B390 for ; Tue, 5 May 2026 15:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996688; cv=none; b=ZV5mXrVE6f4HfJnpFSFKOJ/YZA41UjZ9kKvmfFs8qoA1LbLc7o7yna+Szb182FIQ5yal5vOKUwcXI8LZD17XqocuDiBZ7XZVI8A27Sgp81JPxEH8QXD83jKPcoAntGdQySnkXbfY4bll/f2hswPUCoI2hWUHl0taWgEWXPAIOIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996688; c=relaxed/simple; bh=QG4JdoJ8gVRAl1RcSXRXbbQEwZLV4EXdU4fRp4bpQG0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dl3SPxW1doBjVd6jIHMqSTsuVf+AhNBS64JtdTcbc2QoW2fRkNUYkiQfhwEOf3Iby7/gK8ztRezhQi3vnAV6O3dmGv6wOBcaC3HhDEAE+P6eN1Il+Rbf+ZkHM2gCQCVirqoD9BtQR7YZ69KW4/lCwlEtC+i3WAy0iYVZuZZOjBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=tK+S0Hpt; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="tK+S0Hpt" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1E5283029; Tue, 5 May 2026 08:58:01 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 992383F905; Tue, 5 May 2026 08:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1777996686; bh=QG4JdoJ8gVRAl1RcSXRXbbQEwZLV4EXdU4fRp4bpQG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tK+S0HptRxYBIPqzbPMMjDrex7fPSRi+n603/d4H3wAURmxODK5NXDxVNuE0cJOaO LVhMjpI2q94lr1DJU1J9/2Au5xGwQmtBsrmB3jaj0b7lGsIbyNNnPMjDhdsVuxUmr9 HzO0+P+xxtaV9n+OuoeRHkBC75iYwx7zyHQ0YeaA= From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, lpieralisi@kernel.org, mark.rutland@arm.com, steven.price@arm.com, aneesh.kumar@kernel.org, sudeep.holla@arm.com, robh@kernel.org, maz@kernel.org, Suzuki K Poulose Subject: [RFC PATCH v2 1/4] arm64: acpi: Refactor FADT table verification Date: Tue, 5 May 2026 16:57:39 +0100 Message-ID: <20260505155742.623287-2-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505155742.623287-1-suzuki.poulose@arm.com> References: <20260429103535.266728-1-suzuki.poulose@arm.com> <20260505155742.623287-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor the FADT sanity check, such that this could be reused. We are soon going to consume the FADT early at boot for probing the PSCI conduit, and t= his will be of use. Signed-off-by: Suzuki K Poulose --- arch/arm64/kernel/acpi.c | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 5891f92c2035..d6050e9cde89 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -118,6 +118,34 @@ bool acpi_psci_use_hvc(void) return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC; } =20 +static int __init __acpi_fadt_sanity_check(struct acpi_table_fadt *fadt) +{ + struct acpi_table_header *table =3D (struct acpi_table_header *)fadt; + + /* + * Revision in table header is the FADT Major revision, and there + * is a minor revision of FADT which was introduced by ACPI 5.1, + * we only deal with ACPI 5.1 or newer revision to get GIC and SMP + * boot protocol configuration data. + */ + if (table->revision < 5 || + (table->revision =3D=3D 5 && fadt->minor_revision < 1)) { + pr_err(FW_BUG "Unsupported FADT revision %d.%d, should be 5.1+\n", + table->revision, fadt->minor_revision); + + if (!fadt->arm_boot_flags) { + return -EINVAL; + } + pr_err("FADT has ARM boot flags set, assuming 5.1\n"); + } + + if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) { + pr_err("FADT not ACPI hardware reduced compliant\n"); + return -EINVAL; + } + return 0; +} + /* * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity * checks on it @@ -127,7 +155,6 @@ bool acpi_psci_use_hvc(void) static int __init acpi_fadt_sanity_check(void) { struct acpi_table_header *table; - struct acpi_table_fadt *fadt; acpi_status status; int ret =3D 0; =20 @@ -143,32 +170,8 @@ static int __init acpi_fadt_sanity_check(void) return -ENODEV; } =20 - fadt =3D (struct acpi_table_fadt *)table; + ret =3D __acpi_fadt_sanity_check((struct acpi_table_fadt *)table); =20 - /* - * Revision in table header is the FADT Major revision, and there - * is a minor revision of FADT which was introduced by ACPI 5.1, - * we only deal with ACPI 5.1 or newer revision to get GIC and SMP - * boot protocol configuration data. - */ - if (table->revision < 5 || - (table->revision =3D=3D 5 && fadt->minor_revision < 1)) { - pr_err(FW_BUG "Unsupported FADT revision %d.%d, should be 5.1+\n", - table->revision, fadt->minor_revision); - - if (!fadt->arm_boot_flags) { - ret =3D -EINVAL; - goto out; - } - pr_err("FADT has ARM boot flags set, assuming 5.1\n"); - } - - if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) { - pr_err("FADT not ACPI hardware reduced compliant\n"); - ret =3D -EINVAL; - } - -out: /* * acpi_get_table() creates FADT table mapping that * should be released after parsing and before resuming boot --=20 2.43.0 From nobody Sat Jun 13 20:27:50 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1685D48BD2A for ; Tue, 5 May 2026 15:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996690; cv=none; b=dO/8KtSsPjkO6E8fnmB23JzTAaRNWQDryD2xF40xSvu8pf1xUwWIhVUQbmtwx1tyYrpSUEFO1BHvxnxvsVWFSJNArU1EXq5BmXHhKJuA+IbX3d4Fo4dCg6pJDl25+r/iC+eTxE8ADPVsLgRL4Mt/6igMU4AL76OSG25QMZCOexk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996690; c=relaxed/simple; bh=Xuvp4LNkPrZpjDlqGpQ4sGF4Ii5mNXQnM6ZUP+x7rAw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VuVOYjlXM80ANZEUkP8SaV4TLp7OZ+l0Yp2XQUeFMwdvDMqZBlOdSN+kRtCGcCvIoKgoJlImcUi7l4DQX+W+O8J/+KIvZH8x+z7rYaKwCdF8dOVQ2o7yiLQCavJvD6VOekxS8MNVdhgv339DvmRvxUTi0iwAX3usffVvlrfbkks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=E8Xvr1s1; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="E8Xvr1s1" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4E337307A; Tue, 5 May 2026 08:58:03 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C72E73F905; Tue, 5 May 2026 08:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1777996688; bh=Xuvp4LNkPrZpjDlqGpQ4sGF4Ii5mNXQnM6ZUP+x7rAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8Xvr1s1w0Vw41RrUKGBrRUY7pIvIlsrk73D9zWIG+d69xQKqsVd5yl/LCnCIBqxp p+u8xqJUWpy3y3qtWaLfJSfOjTn1JS/L9B8sCTm9ypNsYEbt9ZJntArqiglm5ndNk3 C4wFq6k8grXog9iAg1ZyAFaXhJXzD6UIZUijl4xQ= From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, lpieralisi@kernel.org, mark.rutland@arm.com, steven.price@arm.com, aneesh.kumar@kernel.org, sudeep.holla@arm.com, robh@kernel.org, maz@kernel.org, Suzuki K Poulose Subject: [RFC PATCH v2 2/4] psci: Add support for Early detection and init Date: Tue, 5 May 2026 16:57:40 +0100 Message-ID: <20260505155742.623287-3-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505155742.623287-1-suzuki.poulose@arm.com> References: <20260429103535.266728-1-suzuki.poulose@arm.com> <20260505155742.623287-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow early detection of the PSCI conduit and presence of SMCCC. Primary mo= tive is to detect if we are a Realm as early as possible to make better decisions 1. For mapping the memory without BBML2_NOABORT 2. Making use of the earlycon, to be able to debug problems at early boot. Add a new psci_early_init_conduit() which can probe the PSCI and SMCCC. Thi= s is optional, and could really fallback to the normal if the architecture cannot reliably detect the conduit. Later patches will make use of this. Signed-off-by: Suzuki K Poulose --- drivers/firmware/psci/psci.c | 49 ++++++++++++++++++++++++++++++++++-- include/linux/psci.h | 2 ++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 38ca190d4a22..fa0839513d64 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -80,6 +80,11 @@ static u32 psci_cpu_suspend_feature; static bool psci_system_reset2_supported; static bool psci_system_off2_hibernate_supported; =20 +static inline bool psci_probed(void) +{ + return psci_ops.get_version !=3D NULL; +} + static inline bool psci_has_ext_power_state(void) { return psci_cpu_suspend_feature & @@ -270,6 +275,15 @@ static unsigned long psci_migrate_info_up_cpu(void) =20 static void set_conduit(enum arm_smccc_conduit conduit) { + /* + * If we have set the conduit already, make sure + * it is the same as we have found. + */ + if (psci_conduit !=3D SMCCC_CONDUIT_NONE) { + WARN_ON(conduit !=3D psci_conduit); + return; + } + switch (conduit) { case SMCCC_CONDUIT_HVC: invoke_psci_fn =3D __invoke_psci_fn_hvc; @@ -679,7 +693,16 @@ static void __init psci_0_2_set_functions(void) */ static int __init psci_probe(void) { - u32 ver =3D psci_0_2_get_version(); + u32 ver; + + /* Make sure we have a set CONDUIT */ + if (WARN_ON(psci_conduit =3D=3D SMCCC_CONDUIT_NONE)) + return -ENODEV; + + if (WARN_ON(psci_probed())) + return 0; + + ver =3D psci_0_2_get_version(); =20 pr_info("PSCIv%d.%d detected in firmware.\n", PSCI_VERSION_MAJOR(ver), @@ -717,10 +740,12 @@ static int __init psci_0_2_init(const struct device_n= ode *np) { int err; =20 + if (psci_probed()) + return 0; + err =3D get_set_conduit_method(np); if (err) return err; - /* * Starting with v0.2, the PSCI specification introduced a call * (PSCI_VERSION) that allows probing the firmware version, so @@ -739,6 +764,9 @@ static int __init psci_0_1_init(const struct device_nod= e *np) u32 id; int err; =20 + if (psci_probed()) + return 0; + err =3D get_set_conduit_method(np); if (err) return err; @@ -816,6 +844,20 @@ int __init psci_dt_init(void) return ret; } =20 +int __init psci_early_init_conduit(enum arm_smccc_conduit conduit) +{ + switch (conduit) { + case SMCCC_CONDUIT_HVC: + case SMCCC_CONDUIT_SMC: + set_conduit(conduit); + break; + default: + WARN_ON(1); + return -EINVAL; + } + return psci_probe(); +} + #ifdef CONFIG_ACPI /* * We use PSCI 0.2+ when ACPI is deployed on ARM64 and it's @@ -823,6 +865,9 @@ int __init psci_dt_init(void) */ int __init psci_acpi_init(void) { + if (psci_probed()) + return 0; + if (!acpi_psci_present()) { pr_info("is not implemented in ACPI.\n"); return -EOPNOTSUPP; diff --git a/include/linux/psci.h b/include/linux/psci.h index 4ca0060a3fc4..8f98d61a69e4 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -59,4 +59,6 @@ static inline bool acpi_psci_present(void) { return false= ; } static inline bool acpi_psci_use_hvc(void) {return false; } #endif =20 +int __init psci_early_init_conduit(enum arm_smccc_conduit); + #endif /* __LINUX_PSCI_H */ --=20 2.43.0 From nobody Sat Jun 13 20:27:50 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 201DC48BD55 for ; Tue, 5 May 2026 15:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996692; cv=none; b=CjFGu0vdLGk59qZO1t9N1eadfIxD/NXNrs/Oc2wttarK16BYaOU3ivSgsfRPrNg4HxMto61D49X3YhYwykx+CQ/v4bswoNzmpvzXPRspNyeK/+JaL9DLW8vxhE2gorldIh+Q86K0G/rDsLHp6tatelD9HrHktsHbmhErsJzSKac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996692; c=relaxed/simple; bh=5PnC7v96/dj1I65TZK5GmbsyqX2pUyuny4YHlaetBJ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=biuGdhvA4M0edi8YTcZICWGqPj3bRIVwNI9sWSauFgmkzvWfddvJST0wtR5573TveC4+VM5sLS1+Zg2w4vDqXBjVwUFj4YZfDJQuP8APX0TU20kKnJSwOwoVfyRfXCLM02WHZUzeRWNSnsZ+g/xCiHYeS/y6GZ8gdZrkX8VNXkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=V1QFyosW; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="V1QFyosW" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7B3E53105; Tue, 5 May 2026 08:58:05 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 017973F905; Tue, 5 May 2026 08:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1777996690; bh=5PnC7v96/dj1I65TZK5GmbsyqX2pUyuny4YHlaetBJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1QFyosWyHQnyBmdtkaCySHfS2bbgBGjKm0ZeGuqRBx/pVJJrIyOmpPagzlYQjS84 ttJBt2ngHB9DP8nXfovfe01vcaYzzbwAPUv7+/DJo8tbU7DistyeHIsc/arSQXvO9b wrM1I+J+duMxdObJule86wwel8CSeo77jFcuXbEs= From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, lpieralisi@kernel.org, mark.rutland@arm.com, steven.price@arm.com, aneesh.kumar@kernel.org, sudeep.holla@arm.com, robh@kernel.org, maz@kernel.org, Suzuki K Poulose Subject: [RFC PATCH v2 3/4] arm64: psci: Move detection and SMCCC probe earlier Date: Tue, 5 May 2026 16:57:41 +0100 Message-ID: <20260505155742.623287-4-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505155742.623287-1-suzuki.poulose@arm.com> References: <20260429103535.266728-1-suzuki.poulose@arm.com> <20260505155742.623287-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We parse the ACPI/DT for the PSCI conduit after the linear map is created v= ia paging_init(). This implies that we do not have all the information require= d to decide whether block mappings are safe for the linear map. e.g., With Realms, we cannot use Block mappings without BBML2_NOABORT suppo= rt. See [0] for more discussion. This patch moves the detection of PSCI and SMCCC probing, before paging_ini= t(), after the efi_init(). We scan the ACPI and the DT (unflattened) for the con= duit. If we both have conduit set, we proceed only if they match. Otherwise, we c= an't be sure what gets used eventually by the OS. e.g., if the ACPI table is cor= rupt, DT may be used. We do minimal validations on the ACPI tables (e.g. revision checks, FADT checks etc.). TODO: Verify the checksum ? (acpi_table_checksum()) [0] https://lore.kernel.org/all/20260330161705.3349825-2-ryan.roberts@arm.c= om/ Cc: Catalin Marinas Cc: Mark Rutland Cc: Steven Price Cc: Will Deacon Cc: Ard Biesheuvel Cc: Lorenzo Pieralisi Signed-off-by: Suzuki K Poulose --- arch/arm64/include/asm/acpi.h | 1 + arch/arm64/kernel/acpi.c | 96 +++++++++++++++++++++++++++++++++++ arch/arm64/kernel/setup.c | 78 ++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 8a54ca6ba602..448320ffba98 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -173,4 +173,5 @@ static inline void acpi_map_cpus_to_nodes(void) { } =20 #define ACPI_TABLE_UPGRADE_MAX_PHYS MEMBLOCK_ALLOC_ACCESSIBLE =20 +enum arm_smccc_conduit __init acpi_early_psci_conduit(void); #endif /*_ASM_ACPI_H*/ diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index d6050e9cde89..a36a9881a4f7 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -180,6 +180,102 @@ static int __init acpi_fadt_sanity_check(void) return ret; } =20 +/* + * Find the PSCI conduit from ACPI FADT table. We only proceed with the pa= rsing + * if acpi *may be* used. i.e, acpi=3Dforce or acpi=3Don or DT is stub. + * + * FADT table is located as below: + * + * RSDP -> XSDT ptr -> array of pointers to different Tables + * + * Note: Arm64 requires ACPI v5.1+, thus we always use XSDT (not RSDT, for= < 2.0) + * from RSDP. + * + * Returns : Conduit if system is PSCI compliant. + * Otherwise returns SMCCC_CONDUIT_NONE. + */ +enum arm_smccc_conduit __init acpi_early_psci_conduit(void) +{ + enum arm_smccc_conduit c =3D SMCCC_CONDUIT_NONE; + struct acpi_table_rsdp *rsdp; + struct acpi_table_xsdt *xsdt; + u64 *ptr, *end; + u64 xsdt_pa, xsdt_len, xsdt_map_len; + bool found =3D false; + + if (param_acpi_off || + (!param_acpi_on && !param_acpi_force && !dt_is_stub())) + return SMCCC_CONDUIT_NONE; + + if (efi.acpi20 =3D=3D EFI_INVALID_TABLE_ADDR) + return SMCCC_CONDUIT_NONE; + + rsdp =3D early_memremap(efi.acpi20, sizeof(*rsdp)); + if (!rsdp) + return SMCCC_CONDUIT_NONE; + + if (!ACPI_VALIDATE_RSDP_SIG(rsdp->signature) || rsdp->revision < 2 || + rsdp->xsdt_physical_address =3D=3D 0) { + early_memunmap(rsdp, sizeof(*rsdp)); + return SMCCC_CONDUIT_NONE; + } + + xsdt_pa =3D rsdp->xsdt_physical_address; + + /* Now that XSDT is found, unmap the RSDP */ + early_memunmap(rsdp, sizeof(*rsdp)); + + /* + * XSDT is mainly an array of table pointers, with standard header. + * So we map upto a PAGE_SIZE (and more with alignment) and check + * the length. If the current mapping doesn't cover the full table, + * we remap it upto the actual length. + */ + xsdt_map_len =3D PAGE_SIZE; + xsdt =3D early_memremap(xsdt_pa, xsdt_map_len); + if (!xsdt) + return SMCCC_CONDUIT_NONE; + + /* Length of the mapped region */ + xsdt_len =3D ALIGN(xsdt_pa + xsdt_map_len, PAGE_SIZE) - xsdt_pa; + + if (xsdt_len < ((struct acpi_table_header*)xsdt)->length) { + xsdt_len =3D ((struct acpi_table_header*)xsdt)->length; + early_memunmap(xsdt, xsdt_map_len); + xsdt_map_len =3D xsdt_len; + xsdt =3D early_memremap(xsdt_pa, xsdt_map_len); + if (!xsdt) + return SMCCC_CONDUIT_NONE; + } else { + xsdt_len =3D ((struct acpi_table_header*)xsdt)->length; + } + + /* Find FADT table from the XSDT */ + ptr =3D &xsdt->table_offset_entry[0]; + end =3D (u64*)((void *)xsdt + xsdt_len); + for (; ptr < end && !found; ptr++) { + struct acpi_table_fadt *fadt =3D early_memremap(*ptr, sizeof(*fadt)); + + if (!fadt) { + pr_warn("Unable to map ACPI table at 0x%llx\n", *ptr); + continue; + } + if (ACPI_COMPARE_NAMESEG(&fadt->header.signature, ACPI_SIG_FADT) && + __acpi_fadt_sanity_check(fadt) =3D=3D 0) { + u16 arm_boot_flags =3D fadt->arm_boot_flags; + + if (arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT) { + c =3D arm_boot_flags & ACPI_FADT_PSCI_USE_HVC ? + SMCCC_CONDUIT_HVC : SMCCC_CONDUIT_SMC; + } + found =3D true; + } + early_memunmap(fadt, sizeof(*fadt)); + } + early_memunmap(xsdt, xsdt_map_len); + return c; +} + /* * acpi_boot_table_init() called from setup_arch(), always. * 1. find RSDP and get its address, and then find XSDT diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 23c05dc7a8f2..af35a0f3b7d0 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -278,6 +278,81 @@ u64 cpu_logical_map(unsigned int cpu) return __cpu_logical_map[cpu]; } =20 +static enum arm_smccc_conduit early_dt_probe_psci_conduit(void) +{ + int len =3D 0; + int psci_node; + const char *method, *status; + enum arm_smccc_conduit conduit =3D SMCCC_CONDUIT_NONE; + unsigned long dt_root; + + /* DT hasn't been unflattened yet, we have to work with the flat blob */ + dt_root =3D of_get_flat_dt_root(); + psci_node =3D of_get_flat_dt_subnode_by_name(dt_root, "psci"); + if (psci_node <=3D 0) + return conduit; + + if (!of_flat_dt_is_compatible(psci_node, "arm,psci-0.2") && + !of_flat_dt_is_compatible(psci_node, "arm,psci-1.0")) + return conduit; + + status =3D of_get_flat_dt_prop(psci_node, "status", &len); + if (status) { + if (strncmp(status, "ok", len) && strncmp(status, "okay", len)) + return conduit; + } + + method =3D of_get_flat_dt_prop(psci_node, "method", &len); + if (!method) + return conduit; + + if (strncmp(method, "smc", len) =3D=3D 0) { + conduit =3D SMCCC_CONDUIT_SMC; + } else if (strncmp(method, "hvc", len) =3D=3D 0) { + conduit =3D SMCCC_CONDUIT_HVC; + } + return conduit; +} + +/* + * Detect the PSCI conduit from both ACPI and DT, and probe the PSCI/SMCCC + * early if we can. + * + * Given both ACPI and DT could have valid configurations, we go forward w= ith + * the early detection only if there is a valid conduit and both of them m= atch. + */ +static void __init early_psci_init(void) +{ + enum arm_smccc_conduit dt_conduit =3D SMCCC_CONDUIT_NONE; + enum arm_smccc_conduit acpi_conduit =3D SMCCC_CONDUIT_NONE; + enum arm_smccc_conduit conduit =3D SMCCC_CONDUIT_NONE; + + dt_conduit =3D early_dt_probe_psci_conduit(); + +#ifdef CONFIG_ACPI + if (efi_enabled(EFI_BOOT)) + acpi_conduit =3D acpi_early_psci_conduit(); +#endif + if (dt_conduit =3D=3D SMCCC_CONDUIT_NONE && + acpi_conduit =3D=3D SMCCC_CONDUIT_NONE) { + pr_crit("PSCI: Early probe: no conduit found\n"); + return; + } + + if (acpi_conduit =3D=3D SMCCC_CONDUIT_NONE) { + conduit =3D dt_conduit; + } else if (dt_conduit =3D=3D SMCCC_CONDUIT_NONE) { + conduit =3D acpi_conduit; + } else if (dt_conduit =3D=3D acpi_conduit) { + conduit =3D acpi_conduit; + } else { + WARN(1, "PSCI: Early probe: Mismatched PSCI conduit, skipping\n"); + return; + } + + psci_early_init_conduit(conduit); +} + void __init __no_sanitize_address setup_arch(char **cmdline_p) { setup_initial_init_mm(_text, _etext, _edata, _end); @@ -322,6 +397,9 @@ void __init __no_sanitize_address setup_arch(char **cmd= line_p) xen_early_init(); efi_init(); =20 + /* Probe the PSCI early after the efi_init() */ + early_psci_init(); + if (!efi_enabled(EFI_BOOT)) { if ((u64)_text % MIN_KIMG_ALIGN) pr_warn(FW_BUG "Kernel image misaligned at boot, please fix your bootlo= ader!"); --=20 2.43.0 From nobody Sat Jun 13 20:27:50 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4E8548C8A2 for ; Tue, 5 May 2026 15:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996695; cv=none; b=Fz33bzqkPMDtLynCViP4Aa5Bc7JbadhjA9vZWFvXwm2207dX/G64+jp2Gqxpie412DfyHYe+7F10SPjkMRcCFtECIMd6VltMUhvAly1P/RQ5B4giIbGjRhJSkjq/hwJtBuDbZ3rysmCHc9lYJvjDOEHdHW8Khe3rMa1pTBNAlQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777996695; c=relaxed/simple; bh=Ls6VVCiSdimyAeYtLpdKHdocbp6FzZGGNr/1wlhA6Js=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tAxj9+ojndVVwgJ3JvDOif9hfK6u2qi8XS0wk2M2mFNuTGzivbwELQqp8dNEaRpKXtOlEOxyxpczPBlBeVMj0lA+cBlrjokHf+ugeuPsG4bc/VTwzKgWo7QwV+qLLIjIsV+ZZ8fey0H+wv0uNdgEhvs+WmMtEkIaW6LNCAhKuxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=BKY19ffL; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="BKY19ffL" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA175307A; Tue, 5 May 2026 08:58:07 -0700 (PDT) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2FED13F836; Tue, 5 May 2026 08:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1777996693; bh=Ls6VVCiSdimyAeYtLpdKHdocbp6FzZGGNr/1wlhA6Js=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BKY19ffLrlPHLSJjXkWN2iZVtajQVun7tIPzgLCnj7OqJufFce9t8Nav6pjNgz5W2 6LqKEjIX+15CEhJplRkmUJkMey+t7pJtcFS7E3HiISPJ2XCWcJfl5dR/jH98Mp/Jo9 k0S8HscxxCNj+TToTgE5o+y/ZRCmZJuNEjzKyLOc= From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, lpieralisi@kernel.org, mark.rutland@arm.com, steven.price@arm.com, aneesh.kumar@kernel.org, sudeep.holla@arm.com, robh@kernel.org, maz@kernel.org, Suzuki K Poulose Subject: [RFC PATCH v2 4/4] arm64: realm: Move RSI detection earlier Date: Tue, 5 May 2026 16:57:42 +0100 Message-ID: <20260505155742.623287-5-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260505155742.623287-1-suzuki.poulose@arm.com> References: <20260429103535.266728-1-suzuki.poulose@arm.com> <20260505155742.623287-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 earl= ier. 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=3Dfull. [0] https://lore.kernel.org/all/20260330161705.3349825-2-ryan.roberts@arm.c= om/ Signed-off-by: Suzuki K Poulose --- 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 @@ =20 DECLARE_STATIC_KEY_FALSE(rsi_present); =20 +void __init arm64_early_rsi_init(void); void __init arm64_rsi_init(void); =20 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 92160f2e57ff..f0fd0922609d 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -139,10 +139,14 @@ static int realm_ioremap_hook(phys_addr_t phys, size_= t size, pgprot_t *prot) return 0; } =20 -void __init arm64_rsi_init(void) +static bool rsi_probed =3D 0; + +static void __init rsi_probe(void) { if (arm_smccc_1_1_get_conduit() !=3D SMCCC_CONDUIT_SMC) return; + + rsi_probed =3D true; if (!rsi_version_matches()) return; if (WARN_ON(rsi_get_realm_config(lm_alias(&config)))) @@ -160,6 +164,23 @@ void __init arm64_rsi_init(void) static_branch_enable(&rsi_present); } =20 +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 =3D { .name =3D RSI_PDEV_NAME, .id =3D PLATFORM_DEVID_NONE diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index af35a0f3b7d0..0b530a090150 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -350,7 +350,8 @@ static void __init early_psci_init(void) return; } =20 - psci_early_init_conduit(conduit); + if (!psci_early_init_conduit(conduit)) + arm64_early_rsi_init(); } =20 void __init __no_sanitize_address setup_arch(char **cmdline_p) --=20 2.43.0